init.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #define pr_fmt(fmt) "APIC: " fmt
  3. #include <asm/apic.h>
  4. #include "local.h"
  5. /*
  6. * Use DEFINE_STATIC_CALL_NULL() to avoid having to provide stub functions
  7. * for each callback. The callbacks are setup during boot and all except
  8. * wait_icr_idle() must be initialized before usage. The IPI wrappers
  9. * use static_call() and not static_call_cond() to catch any fails.
  10. */
  11. #define DEFINE_APIC_CALL(__cb) \
  12. DEFINE_STATIC_CALL_NULL(apic_call_##__cb, *apic->__cb)
  13. DEFINE_APIC_CALL(eoi);
  14. DEFINE_APIC_CALL(native_eoi);
  15. DEFINE_APIC_CALL(icr_read);
  16. DEFINE_APIC_CALL(icr_write);
  17. DEFINE_APIC_CALL(read);
  18. DEFINE_APIC_CALL(send_IPI);
  19. DEFINE_APIC_CALL(send_IPI_mask);
  20. DEFINE_APIC_CALL(send_IPI_mask_allbutself);
  21. DEFINE_APIC_CALL(send_IPI_allbutself);
  22. DEFINE_APIC_CALL(send_IPI_all);
  23. DEFINE_APIC_CALL(send_IPI_self);
  24. DEFINE_APIC_CALL(wait_icr_idle);
  25. DEFINE_APIC_CALL(wakeup_secondary_cpu);
  26. DEFINE_APIC_CALL(wakeup_secondary_cpu_64);
  27. DEFINE_APIC_CALL(write);
  28. EXPORT_STATIC_CALL_TRAMP_GPL(apic_call_send_IPI_mask);
  29. EXPORT_STATIC_CALL_TRAMP_GPL(apic_call_send_IPI_self);
  30. /* The container for function call overrides */
  31. struct apic_override __x86_apic_override __initdata;
  32. #define apply_override(__cb) \
  33. if (__x86_apic_override.__cb) \
  34. apic->__cb = __x86_apic_override.__cb
  35. static __init void restore_override_callbacks(void)
  36. {
  37. apply_override(eoi);
  38. apply_override(native_eoi);
  39. apply_override(write);
  40. apply_override(read);
  41. apply_override(send_IPI);
  42. apply_override(send_IPI_mask);
  43. apply_override(send_IPI_mask_allbutself);
  44. apply_override(send_IPI_allbutself);
  45. apply_override(send_IPI_all);
  46. apply_override(send_IPI_self);
  47. apply_override(icr_read);
  48. apply_override(icr_write);
  49. apply_override(wakeup_secondary_cpu);
  50. apply_override(wakeup_secondary_cpu_64);
  51. }
  52. #define update_call(__cb) \
  53. static_call_update(apic_call_##__cb, *apic->__cb)
  54. static __init void update_static_calls(void)
  55. {
  56. update_call(eoi);
  57. update_call(native_eoi);
  58. update_call(write);
  59. update_call(read);
  60. update_call(send_IPI);
  61. update_call(send_IPI_mask);
  62. update_call(send_IPI_mask_allbutself);
  63. update_call(send_IPI_allbutself);
  64. update_call(send_IPI_all);
  65. update_call(send_IPI_self);
  66. update_call(icr_read);
  67. update_call(icr_write);
  68. update_call(wait_icr_idle);
  69. update_call(wakeup_secondary_cpu);
  70. update_call(wakeup_secondary_cpu_64);
  71. }
  72. void __init apic_setup_apic_calls(void)
  73. {
  74. /* Ensure that the default APIC has native_eoi populated */
  75. apic->native_eoi = apic->eoi;
  76. update_static_calls();
  77. pr_info("Static calls initialized\n");
  78. }
  79. void __init apic_install_driver(struct apic *driver)
  80. {
  81. if (apic == driver)
  82. return;
  83. apic = driver;
  84. if (IS_ENABLED(CONFIG_X86_X2APIC) && apic->x2apic_set_max_apicid)
  85. apic->max_apic_id = x2apic_max_apicid;
  86. /* Copy the original eoi() callback as KVM/HyperV might overwrite it */
  87. if (!apic->native_eoi)
  88. apic->native_eoi = apic->eoi;
  89. /* Apply any already installed callback overrides */
  90. restore_override_callbacks();
  91. update_static_calls();
  92. pr_info("Switched APIC routing to: %s\n", driver->name);
  93. }