x2apic_phys.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/cpumask.h>
  3. #include <linux/acpi.h>
  4. #include "local.h"
  5. int x2apic_phys;
  6. static struct apic apic_x2apic_phys;
  7. u32 x2apic_max_apicid __ro_after_init = UINT_MAX;
  8. void __init x2apic_set_max_apicid(u32 apicid)
  9. {
  10. x2apic_max_apicid = apicid;
  11. if (apic->x2apic_set_max_apicid)
  12. apic->max_apic_id = apicid;
  13. }
  14. static int __init set_x2apic_phys_mode(char *arg)
  15. {
  16. x2apic_phys = 1;
  17. return 0;
  18. }
  19. early_param("x2apic_phys", set_x2apic_phys_mode);
  20. static bool x2apic_fadt_phys(void)
  21. {
  22. #ifdef CONFIG_ACPI
  23. if ((acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) &&
  24. (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL)) {
  25. printk(KERN_DEBUG "System requires x2apic physical mode\n");
  26. return true;
  27. }
  28. #endif
  29. return false;
  30. }
  31. static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  32. {
  33. return x2apic_enabled() && (x2apic_phys || x2apic_fadt_phys());
  34. }
  35. static void x2apic_send_IPI(int cpu, int vector)
  36. {
  37. u32 dest = per_cpu(x86_cpu_to_apicid, cpu);
  38. /* x2apic MSRs are special and need a special fence: */
  39. weak_wrmsr_fence();
  40. __x2apic_send_IPI_dest(dest, vector, APIC_DEST_PHYSICAL);
  41. }
  42. static void
  43. __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest)
  44. {
  45. unsigned long query_cpu;
  46. unsigned long this_cpu;
  47. unsigned long flags;
  48. /* x2apic MSRs are special and need a special fence: */
  49. weak_wrmsr_fence();
  50. local_irq_save(flags);
  51. this_cpu = smp_processor_id();
  52. for_each_cpu(query_cpu, mask) {
  53. if (apic_dest == APIC_DEST_ALLBUT && this_cpu == query_cpu)
  54. continue;
  55. __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
  56. vector, APIC_DEST_PHYSICAL);
  57. }
  58. local_irq_restore(flags);
  59. }
  60. static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector)
  61. {
  62. __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLINC);
  63. }
  64. static void
  65. x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
  66. {
  67. __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLBUT);
  68. }
  69. static void __x2apic_send_IPI_shorthand(int vector, u32 which)
  70. {
  71. unsigned long cfg = __prepare_ICR(which, vector, 0);
  72. /* x2apic MSRs are special and need a special fence: */
  73. weak_wrmsr_fence();
  74. native_x2apic_icr_write(cfg, 0);
  75. }
  76. void x2apic_send_IPI_allbutself(int vector)
  77. {
  78. __x2apic_send_IPI_shorthand(vector, APIC_DEST_ALLBUT);
  79. }
  80. void x2apic_send_IPI_all(int vector)
  81. {
  82. __x2apic_send_IPI_shorthand(vector, APIC_DEST_ALLINC);
  83. }
  84. void x2apic_send_IPI_self(int vector)
  85. {
  86. apic_write(APIC_SELF_IPI, vector);
  87. }
  88. void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest)
  89. {
  90. unsigned long cfg = __prepare_ICR(0, vector, dest);
  91. native_x2apic_icr_write(cfg, apicid);
  92. }
  93. static int x2apic_phys_probe(void)
  94. {
  95. if (!x2apic_mode)
  96. return 0;
  97. if (x2apic_phys || x2apic_fadt_phys())
  98. return 1;
  99. return apic == &apic_x2apic_phys;
  100. }
  101. u32 x2apic_get_apic_id(u32 id)
  102. {
  103. return id;
  104. }
  105. static struct apic apic_x2apic_phys __ro_after_init = {
  106. .name = "physical x2apic",
  107. .probe = x2apic_phys_probe,
  108. .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
  109. .dest_mode_logical = false,
  110. .disable_esr = 0,
  111. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  112. .max_apic_id = UINT_MAX,
  113. .x2apic_set_max_apicid = true,
  114. .get_apic_id = x2apic_get_apic_id,
  115. .calc_dest_apicid = apic_default_calc_apicid,
  116. .send_IPI = x2apic_send_IPI,
  117. .send_IPI_mask = x2apic_send_IPI_mask,
  118. .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself,
  119. .send_IPI_allbutself = x2apic_send_IPI_allbutself,
  120. .send_IPI_all = x2apic_send_IPI_all,
  121. .send_IPI_self = x2apic_send_IPI_self,
  122. .nmi_to_offline_cpu = true,
  123. .read = native_apic_msr_read,
  124. .write = native_apic_msr_write,
  125. .eoi = native_apic_msr_eoi,
  126. .icr_read = native_x2apic_icr_read,
  127. .icr_write = native_x2apic_icr_write,
  128. };
  129. apic_driver(apic_x2apic_phys);