apic_flat_64.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright 2004 James Cleverdon, IBM.
  3. * Subject to the GNU Public License, v.2
  4. *
  5. * Flat APIC subarch code.
  6. *
  7. * Hacked for x86-64 by James Cleverdon from i386 architecture code by
  8. * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
  9. * James Cleverdon.
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/threads.h>
  13. #include <linux/cpumask.h>
  14. #include <linux/string.h>
  15. #include <linux/kernel.h>
  16. #include <linux/ctype.h>
  17. #include <linux/init.h>
  18. #include <linux/hardirq.h>
  19. #include <linux/module.h>
  20. #include <asm/smp.h>
  21. #include <asm/apic.h>
  22. #include <asm/ipi.h>
  23. #ifdef CONFIG_ACPI
  24. #include <acpi/acpi_bus.h>
  25. #endif
  26. static struct apic apic_physflat;
  27. static struct apic apic_flat;
  28. struct apic __read_mostly *apic = &apic_flat;
  29. EXPORT_SYMBOL_GPL(apic);
  30. static int flat_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  31. {
  32. return 1;
  33. }
  34. /*
  35. * Set up the logical destination ID.
  36. *
  37. * Intel recommends to set DFR, LDR and TPR before enabling
  38. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  39. * document number 292116). So here it goes...
  40. */
  41. void flat_init_apic_ldr(void)
  42. {
  43. unsigned long val;
  44. unsigned long num, id;
  45. num = smp_processor_id();
  46. id = 1UL << num;
  47. apic_write(APIC_DFR, APIC_DFR_FLAT);
  48. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  49. val |= SET_APIC_LOGICAL_ID(id);
  50. apic_write(APIC_LDR, val);
  51. }
  52. static inline void _flat_send_IPI_mask(unsigned long mask, int vector)
  53. {
  54. unsigned long flags;
  55. local_irq_save(flags);
  56. __default_send_IPI_dest_field(mask, vector, apic->dest_logical);
  57. local_irq_restore(flags);
  58. }
  59. static void flat_send_IPI_mask(const struct cpumask *cpumask, int vector)
  60. {
  61. unsigned long mask = cpumask_bits(cpumask)[0];
  62. _flat_send_IPI_mask(mask, vector);
  63. }
  64. static void
  65. flat_send_IPI_mask_allbutself(const struct cpumask *cpumask, int vector)
  66. {
  67. unsigned long mask = cpumask_bits(cpumask)[0];
  68. int cpu = smp_processor_id();
  69. if (cpu < BITS_PER_LONG)
  70. clear_bit(cpu, &mask);
  71. _flat_send_IPI_mask(mask, vector);
  72. }
  73. static void flat_send_IPI_allbutself(int vector)
  74. {
  75. int cpu = smp_processor_id();
  76. #ifdef CONFIG_HOTPLUG_CPU
  77. int hotplug = 1;
  78. #else
  79. int hotplug = 0;
  80. #endif
  81. if (hotplug || vector == NMI_VECTOR) {
  82. if (!cpumask_equal(cpu_online_mask, cpumask_of(cpu))) {
  83. unsigned long mask = cpumask_bits(cpu_online_mask)[0];
  84. if (cpu < BITS_PER_LONG)
  85. clear_bit(cpu, &mask);
  86. _flat_send_IPI_mask(mask, vector);
  87. }
  88. } else if (num_online_cpus() > 1) {
  89. __default_send_IPI_shortcut(APIC_DEST_ALLBUT,
  90. vector, apic->dest_logical);
  91. }
  92. }
  93. static void flat_send_IPI_all(int vector)
  94. {
  95. if (vector == NMI_VECTOR) {
  96. flat_send_IPI_mask(cpu_online_mask, vector);
  97. } else {
  98. __default_send_IPI_shortcut(APIC_DEST_ALLINC,
  99. vector, apic->dest_logical);
  100. }
  101. }
  102. static unsigned int flat_get_apic_id(unsigned long x)
  103. {
  104. unsigned int id;
  105. id = (((x)>>24) & 0xFFu);
  106. return id;
  107. }
  108. static unsigned long set_apic_id(unsigned int id)
  109. {
  110. unsigned long x;
  111. x = ((id & 0xFFu)<<24);
  112. return x;
  113. }
  114. static unsigned int read_xapic_id(void)
  115. {
  116. unsigned int id;
  117. id = flat_get_apic_id(apic_read(APIC_ID));
  118. return id;
  119. }
  120. static int flat_apic_id_registered(void)
  121. {
  122. return physid_isset(read_xapic_id(), phys_cpu_present_map);
  123. }
  124. static int flat_phys_pkg_id(int initial_apic_id, int index_msb)
  125. {
  126. return initial_apic_id >> index_msb;
  127. }
  128. static int flat_probe(void)
  129. {
  130. return 1;
  131. }
  132. static struct apic apic_flat = {
  133. .name = "flat",
  134. .probe = flat_probe,
  135. .acpi_madt_oem_check = flat_acpi_madt_oem_check,
  136. .apic_id_valid = default_apic_id_valid,
  137. .apic_id_registered = flat_apic_id_registered,
  138. .irq_delivery_mode = dest_LowestPrio,
  139. .irq_dest_mode = 1, /* logical */
  140. .target_cpus = online_target_cpus,
  141. .disable_esr = 0,
  142. .dest_logical = APIC_DEST_LOGICAL,
  143. .check_apicid_used = NULL,
  144. .check_apicid_present = NULL,
  145. .vector_allocation_domain = flat_vector_allocation_domain,
  146. .init_apic_ldr = flat_init_apic_ldr,
  147. .ioapic_phys_id_map = NULL,
  148. .setup_apic_routing = NULL,
  149. .multi_timer_check = NULL,
  150. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  151. .apicid_to_cpu_present = NULL,
  152. .setup_portio_remap = NULL,
  153. .check_phys_apicid_present = default_check_phys_apicid_present,
  154. .enable_apic_mode = NULL,
  155. .phys_pkg_id = flat_phys_pkg_id,
  156. .mps_oem_check = NULL,
  157. .get_apic_id = flat_get_apic_id,
  158. .set_apic_id = set_apic_id,
  159. .apic_id_mask = 0xFFu << 24,
  160. .cpu_mask_to_apicid_and = flat_cpu_mask_to_apicid_and,
  161. .send_IPI_mask = flat_send_IPI_mask,
  162. .send_IPI_mask_allbutself = flat_send_IPI_mask_allbutself,
  163. .send_IPI_allbutself = flat_send_IPI_allbutself,
  164. .send_IPI_all = flat_send_IPI_all,
  165. .send_IPI_self = apic_send_IPI_self,
  166. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  167. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  168. .wait_for_init_deassert = NULL,
  169. .smp_callin_clear_local_apic = NULL,
  170. .inquire_remote_apic = default_inquire_remote_apic,
  171. .read = native_apic_mem_read,
  172. .write = native_apic_mem_write,
  173. .eoi_write = native_apic_mem_write,
  174. .icr_read = native_apic_icr_read,
  175. .icr_write = native_apic_icr_write,
  176. .wait_icr_idle = native_apic_wait_icr_idle,
  177. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  178. };
  179. /*
  180. * Physflat mode is used when there are more than 8 CPUs on a system.
  181. * We cannot use logical delivery in this case because the mask
  182. * overflows, so use physical mode.
  183. */
  184. static int physflat_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  185. {
  186. #ifdef CONFIG_ACPI
  187. /*
  188. * Quirk: some x86_64 machines can only use physical APIC mode
  189. * regardless of how many processors are present (x86_64 ES7000
  190. * is an example).
  191. */
  192. if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
  193. (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL)) {
  194. printk(KERN_DEBUG "system APIC only can use physical flat");
  195. return 1;
  196. }
  197. if (!strncmp(oem_id, "IBM", 3) && !strncmp(oem_table_id, "EXA", 3)) {
  198. printk(KERN_DEBUG "IBM Summit detected, will use apic physical");
  199. return 1;
  200. }
  201. #endif
  202. return 0;
  203. }
  204. static void physflat_send_IPI_mask(const struct cpumask *cpumask, int vector)
  205. {
  206. default_send_IPI_mask_sequence_phys(cpumask, vector);
  207. }
  208. static void physflat_send_IPI_mask_allbutself(const struct cpumask *cpumask,
  209. int vector)
  210. {
  211. default_send_IPI_mask_allbutself_phys(cpumask, vector);
  212. }
  213. static void physflat_send_IPI_allbutself(int vector)
  214. {
  215. default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
  216. }
  217. static void physflat_send_IPI_all(int vector)
  218. {
  219. physflat_send_IPI_mask(cpu_online_mask, vector);
  220. }
  221. static int physflat_probe(void)
  222. {
  223. if (apic == &apic_physflat || num_possible_cpus() > 8)
  224. return 1;
  225. return 0;
  226. }
  227. static struct apic apic_physflat = {
  228. .name = "physical flat",
  229. .probe = physflat_probe,
  230. .acpi_madt_oem_check = physflat_acpi_madt_oem_check,
  231. .apic_id_valid = default_apic_id_valid,
  232. .apic_id_registered = flat_apic_id_registered,
  233. .irq_delivery_mode = dest_Fixed,
  234. .irq_dest_mode = 0, /* physical */
  235. .target_cpus = online_target_cpus,
  236. .disable_esr = 0,
  237. .dest_logical = 0,
  238. .check_apicid_used = NULL,
  239. .check_apicid_present = NULL,
  240. .vector_allocation_domain = default_vector_allocation_domain,
  241. /* not needed, but shouldn't hurt: */
  242. .init_apic_ldr = flat_init_apic_ldr,
  243. .ioapic_phys_id_map = NULL,
  244. .setup_apic_routing = NULL,
  245. .multi_timer_check = NULL,
  246. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  247. .apicid_to_cpu_present = NULL,
  248. .setup_portio_remap = NULL,
  249. .check_phys_apicid_present = default_check_phys_apicid_present,
  250. .enable_apic_mode = NULL,
  251. .phys_pkg_id = flat_phys_pkg_id,
  252. .mps_oem_check = NULL,
  253. .get_apic_id = flat_get_apic_id,
  254. .set_apic_id = set_apic_id,
  255. .apic_id_mask = 0xFFu << 24,
  256. .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
  257. .send_IPI_mask = physflat_send_IPI_mask,
  258. .send_IPI_mask_allbutself = physflat_send_IPI_mask_allbutself,
  259. .send_IPI_allbutself = physflat_send_IPI_allbutself,
  260. .send_IPI_all = physflat_send_IPI_all,
  261. .send_IPI_self = apic_send_IPI_self,
  262. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  263. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  264. .wait_for_init_deassert = NULL,
  265. .smp_callin_clear_local_apic = NULL,
  266. .inquire_remote_apic = default_inquire_remote_apic,
  267. .read = native_apic_mem_read,
  268. .write = native_apic_mem_write,
  269. .eoi_write = native_apic_mem_write,
  270. .icr_read = native_apic_icr_read,
  271. .icr_write = native_apic_icr_write,
  272. .wait_icr_idle = native_apic_wait_icr_idle,
  273. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  274. };
  275. /*
  276. * We need to check for physflat first, so this order is important.
  277. */
  278. apic_drivers(apic_physflat, apic_flat);