x2apic_phys.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/init.h>
  7. #include <linux/dmar.h>
  8. #include <asm/smp.h>
  9. #include <asm/x2apic.h>
  10. int x2apic_phys;
  11. static struct apic apic_x2apic_phys;
  12. static int set_x2apic_phys_mode(char *arg)
  13. {
  14. x2apic_phys = 1;
  15. return 0;
  16. }
  17. early_param("x2apic_phys", set_x2apic_phys_mode);
  18. static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  19. {
  20. if (x2apic_phys)
  21. return x2apic_enabled();
  22. else
  23. return 0;
  24. }
  25. static void
  26. __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest)
  27. {
  28. unsigned long query_cpu;
  29. unsigned long this_cpu;
  30. unsigned long flags;
  31. x2apic_wrmsr_fence();
  32. local_irq_save(flags);
  33. this_cpu = smp_processor_id();
  34. for_each_cpu(query_cpu, mask) {
  35. if (apic_dest == APIC_DEST_ALLBUT && this_cpu == query_cpu)
  36. continue;
  37. __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
  38. vector, APIC_DEST_PHYSICAL);
  39. }
  40. local_irq_restore(flags);
  41. }
  42. static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector)
  43. {
  44. __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLINC);
  45. }
  46. static void
  47. x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
  48. {
  49. __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLBUT);
  50. }
  51. static void x2apic_send_IPI_allbutself(int vector)
  52. {
  53. __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLBUT);
  54. }
  55. static void x2apic_send_IPI_all(int vector)
  56. {
  57. __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLINC);
  58. }
  59. static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask)
  60. {
  61. /*
  62. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  63. * May as well be the first.
  64. */
  65. int cpu = cpumask_first(cpumask);
  66. if ((unsigned)cpu < nr_cpu_ids)
  67. return per_cpu(x86_cpu_to_apicid, cpu);
  68. else
  69. return BAD_APICID;
  70. }
  71. static unsigned int
  72. x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  73. const struct cpumask *andmask)
  74. {
  75. int cpu;
  76. /*
  77. * We're using fixed IRQ delivery, can only return one phys APIC ID.
  78. * May as well be the first.
  79. */
  80. for_each_cpu_and(cpu, cpumask, andmask) {
  81. if (cpumask_test_cpu(cpu, cpu_online_mask))
  82. break;
  83. }
  84. return per_cpu(x86_cpu_to_apicid, cpu);
  85. }
  86. static void init_x2apic_ldr(void)
  87. {
  88. }
  89. static int x2apic_phys_probe(void)
  90. {
  91. if (x2apic_mode && x2apic_phys)
  92. return 1;
  93. return apic == &apic_x2apic_phys;
  94. }
  95. static struct apic apic_x2apic_phys = {
  96. .name = "physical x2apic",
  97. .probe = x2apic_phys_probe,
  98. .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
  99. .apic_id_registered = x2apic_apic_id_registered,
  100. .irq_delivery_mode = dest_Fixed,
  101. .irq_dest_mode = 0, /* physical */
  102. .target_cpus = x2apic_target_cpus,
  103. .disable_esr = 0,
  104. .dest_logical = 0,
  105. .check_apicid_used = NULL,
  106. .check_apicid_present = NULL,
  107. .vector_allocation_domain = x2apic_vector_allocation_domain,
  108. .init_apic_ldr = init_x2apic_ldr,
  109. .ioapic_phys_id_map = NULL,
  110. .setup_apic_routing = NULL,
  111. .multi_timer_check = NULL,
  112. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  113. .apicid_to_cpu_present = NULL,
  114. .setup_portio_remap = NULL,
  115. .check_phys_apicid_present = default_check_phys_apicid_present,
  116. .enable_apic_mode = NULL,
  117. .phys_pkg_id = x2apic_phys_pkg_id,
  118. .mps_oem_check = NULL,
  119. .get_apic_id = x2apic_get_apic_id,
  120. .set_apic_id = x2apic_set_apic_id,
  121. .apic_id_mask = 0xFFFFFFFFu,
  122. .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
  123. .cpu_mask_to_apicid_and = x2apic_cpu_mask_to_apicid_and,
  124. .send_IPI_mask = x2apic_send_IPI_mask,
  125. .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself,
  126. .send_IPI_allbutself = x2apic_send_IPI_allbutself,
  127. .send_IPI_all = x2apic_send_IPI_all,
  128. .send_IPI_self = x2apic_send_IPI_self,
  129. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  130. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  131. .wait_for_init_deassert = NULL,
  132. .smp_callin_clear_local_apic = NULL,
  133. .inquire_remote_apic = NULL,
  134. .read = native_apic_msr_read,
  135. .write = native_apic_msr_write,
  136. .icr_read = native_x2apic_icr_read,
  137. .icr_write = native_x2apic_icr_write,
  138. .wait_icr_idle = native_x2apic_wait_icr_idle,
  139. .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle,
  140. };
  141. apic_driver(apic_x2apic_phys);