x2apic_phys.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include <linux/threads.h>
  2. #include <linux/cpumask.h>
  3. #include <linux/string.h>
  4. #include <linux/kernel.h>
  5. #include <linux/ctype.h>
  6. #include <linux/dmar.h>
  7. #include <asm/smp.h>
  8. #include <asm/x2apic.h>
  9. int x2apic_phys;
  10. static struct apic apic_x2apic_phys;
  11. static int set_x2apic_phys_mode(char *arg)
  12. {
  13. x2apic_phys = 1;
  14. return 0;
  15. }
  16. early_param("x2apic_phys", set_x2apic_phys_mode);
  17. static bool x2apic_fadt_phys(void)
  18. {
  19. #ifdef CONFIG_ACPI
  20. if ((acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) &&
  21. (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL)) {
  22. printk(KERN_DEBUG "System requires x2apic physical mode\n");
  23. return true;
  24. }
  25. #endif
  26. return false;
  27. }
  28. static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  29. {
  30. return x2apic_enabled() && (x2apic_phys || x2apic_fadt_phys());
  31. }
  32. static void x2apic_send_IPI(int cpu, int vector)
  33. {
  34. u32 dest = per_cpu(x86_cpu_to_apicid, cpu);
  35. x2apic_wrmsr_fence();
  36. __x2apic_send_IPI_dest(dest, vector, APIC_DEST_PHYSICAL);
  37. }
  38. static void
  39. __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest)
  40. {
  41. unsigned long query_cpu;
  42. unsigned long this_cpu;
  43. unsigned long flags;
  44. x2apic_wrmsr_fence();
  45. local_irq_save(flags);
  46. this_cpu = smp_processor_id();
  47. for_each_cpu(query_cpu, mask) {
  48. if (apic_dest == APIC_DEST_ALLBUT && this_cpu == query_cpu)
  49. continue;
  50. __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
  51. vector, APIC_DEST_PHYSICAL);
  52. }
  53. local_irq_restore(flags);
  54. }
  55. static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector)
  56. {
  57. __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLINC);
  58. }
  59. static void
  60. x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
  61. {
  62. __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLBUT);
  63. }
  64. static void x2apic_send_IPI_allbutself(int vector)
  65. {
  66. __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLBUT);
  67. }
  68. static void x2apic_send_IPI_all(int vector)
  69. {
  70. __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLINC);
  71. }
  72. static void init_x2apic_ldr(void)
  73. {
  74. }
  75. static int x2apic_phys_probe(void)
  76. {
  77. if (x2apic_mode && (x2apic_phys || x2apic_fadt_phys()))
  78. return 1;
  79. return apic == &apic_x2apic_phys;
  80. }
  81. static struct apic apic_x2apic_phys __ro_after_init = {
  82. .name = "physical x2apic",
  83. .probe = x2apic_phys_probe,
  84. .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
  85. .apic_id_valid = x2apic_apic_id_valid,
  86. .apic_id_registered = x2apic_apic_id_registered,
  87. .irq_delivery_mode = dest_Fixed,
  88. .irq_dest_mode = 0, /* physical */
  89. .target_cpus = online_target_cpus,
  90. .disable_esr = 0,
  91. .dest_logical = 0,
  92. .check_apicid_used = NULL,
  93. .vector_allocation_domain = default_vector_allocation_domain,
  94. .init_apic_ldr = init_x2apic_ldr,
  95. .ioapic_phys_id_map = NULL,
  96. .setup_apic_routing = NULL,
  97. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  98. .apicid_to_cpu_present = NULL,
  99. .check_phys_apicid_present = default_check_phys_apicid_present,
  100. .phys_pkg_id = x2apic_phys_pkg_id,
  101. .get_apic_id = x2apic_get_apic_id,
  102. .set_apic_id = x2apic_set_apic_id,
  103. .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
  104. .send_IPI = x2apic_send_IPI,
  105. .send_IPI_mask = x2apic_send_IPI_mask,
  106. .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself,
  107. .send_IPI_allbutself = x2apic_send_IPI_allbutself,
  108. .send_IPI_all = x2apic_send_IPI_all,
  109. .send_IPI_self = x2apic_send_IPI_self,
  110. .inquire_remote_apic = NULL,
  111. .read = native_apic_msr_read,
  112. .write = native_apic_msr_write,
  113. .eoi_write = native_apic_msr_eoi_write,
  114. .icr_read = native_x2apic_icr_read,
  115. .icr_write = native_x2apic_icr_write,
  116. .wait_icr_idle = native_x2apic_wait_icr_idle,
  117. .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle,
  118. };
  119. apic_driver(apic_x2apic_phys);