probe_32.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * Default generic APIC driver. This handles up to 8 CPUs.
  3. *
  4. * Copyright 2003 Andi Kleen, SuSE Labs.
  5. * Subject to the GNU Public License, v.2
  6. *
  7. * Generic x86 APIC driver probe layer.
  8. */
  9. #include <linux/threads.h>
  10. #include <linux/cpumask.h>
  11. #include <linux/module.h>
  12. #include <linux/string.h>
  13. #include <linux/kernel.h>
  14. #include <linux/ctype.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <asm/fixmap.h>
  18. #include <asm/mpspec.h>
  19. #include <asm/apicdef.h>
  20. #include <asm/apic.h>
  21. #include <asm/setup.h>
  22. #include <linux/smp.h>
  23. #include <asm/ipi.h>
  24. #include <linux/interrupt.h>
  25. #include <asm/acpi.h>
  26. #include <asm/e820.h>
  27. #ifdef CONFIG_HOTPLUG_CPU
  28. #define DEFAULT_SEND_IPI (1)
  29. #else
  30. #define DEFAULT_SEND_IPI (0)
  31. #endif
  32. int no_broadcast = DEFAULT_SEND_IPI;
  33. static __init int no_ipi_broadcast(char *str)
  34. {
  35. get_option(&str, &no_broadcast);
  36. pr_info("Using %s mode\n",
  37. no_broadcast ? "No IPI Broadcast" : "IPI Broadcast");
  38. return 1;
  39. }
  40. __setup("no_ipi_broadcast=", no_ipi_broadcast);
  41. static int __init print_ipi_mode(void)
  42. {
  43. pr_info("Using IPI %s mode\n",
  44. no_broadcast ? "No-Shortcut" : "Shortcut");
  45. return 0;
  46. }
  47. late_initcall(print_ipi_mode);
  48. void __init default_setup_apic_routing(void)
  49. {
  50. int version = apic_version[boot_cpu_physical_apicid];
  51. if (num_possible_cpus() > 8) {
  52. switch (boot_cpu_data.x86_vendor) {
  53. case X86_VENDOR_INTEL:
  54. if (!APIC_XAPIC(version)) {
  55. def_to_bigsmp = 0;
  56. break;
  57. }
  58. /* If P4 and above fall through */
  59. case X86_VENDOR_AMD:
  60. def_to_bigsmp = 1;
  61. }
  62. }
  63. #ifdef CONFIG_X86_BIGSMP
  64. generic_bigsmp_probe();
  65. #endif
  66. if (apic->setup_apic_routing)
  67. apic->setup_apic_routing();
  68. }
  69. static void setup_apic_flat_routing(void)
  70. {
  71. #ifdef CONFIG_X86_IO_APIC
  72. printk(KERN_INFO
  73. "Enabling APIC mode: Flat. Using %d I/O APICs\n",
  74. nr_ioapics);
  75. #endif
  76. }
  77. static void default_vector_allocation_domain(int cpu, struct cpumask *retmask)
  78. {
  79. /*
  80. * Careful. Some cpus do not strictly honor the set of cpus
  81. * specified in the interrupt destination when using lowest
  82. * priority interrupt delivery mode.
  83. *
  84. * In particular there was a hyperthreading cpu observed to
  85. * deliver interrupts to the wrong hyperthread when only one
  86. * hyperthread was specified in the interrupt desitination.
  87. */
  88. cpumask_clear(retmask);
  89. cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
  90. }
  91. /* should be called last. */
  92. static int probe_default(void)
  93. {
  94. return 1;
  95. }
  96. struct apic apic_default = {
  97. .name = "default",
  98. .probe = probe_default,
  99. .acpi_madt_oem_check = NULL,
  100. .apic_id_registered = default_apic_id_registered,
  101. .irq_delivery_mode = dest_LowestPrio,
  102. /* logical delivery broadcast to all CPUs: */
  103. .irq_dest_mode = 1,
  104. .target_cpus = default_target_cpus,
  105. .disable_esr = 0,
  106. .dest_logical = APIC_DEST_LOGICAL,
  107. .check_apicid_used = default_check_apicid_used,
  108. .check_apicid_present = default_check_apicid_present,
  109. .vector_allocation_domain = default_vector_allocation_domain,
  110. .init_apic_ldr = default_init_apic_ldr,
  111. .ioapic_phys_id_map = default_ioapic_phys_id_map,
  112. .setup_apic_routing = setup_apic_flat_routing,
  113. .multi_timer_check = NULL,
  114. .apicid_to_node = default_apicid_to_node,
  115. .cpu_to_logical_apicid = default_cpu_to_logical_apicid,
  116. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  117. .apicid_to_cpu_present = physid_set_mask_of_physid,
  118. .setup_portio_remap = NULL,
  119. .check_phys_apicid_present = default_check_phys_apicid_present,
  120. .enable_apic_mode = NULL,
  121. .phys_pkg_id = default_phys_pkg_id,
  122. .mps_oem_check = NULL,
  123. .get_apic_id = default_get_apic_id,
  124. .set_apic_id = NULL,
  125. .apic_id_mask = 0x0F << 24,
  126. .cpu_mask_to_apicid = default_cpu_mask_to_apicid,
  127. .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
  128. .send_IPI_mask = default_send_IPI_mask_logical,
  129. .send_IPI_mask_allbutself = default_send_IPI_mask_allbutself_logical,
  130. .send_IPI_allbutself = default_send_IPI_allbutself,
  131. .send_IPI_all = default_send_IPI_all,
  132. .send_IPI_self = default_send_IPI_self,
  133. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  134. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  135. .wait_for_init_deassert = default_wait_for_init_deassert,
  136. .smp_callin_clear_local_apic = NULL,
  137. .inquire_remote_apic = default_inquire_remote_apic,
  138. .read = native_apic_mem_read,
  139. .write = native_apic_mem_write,
  140. .icr_read = native_apic_icr_read,
  141. .icr_write = native_apic_icr_write,
  142. .wait_icr_idle = native_apic_wait_icr_idle,
  143. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  144. };
  145. extern struct apic apic_numaq;
  146. extern struct apic apic_summit;
  147. extern struct apic apic_bigsmp;
  148. extern struct apic apic_es7000;
  149. extern struct apic apic_es7000_cluster;
  150. struct apic *apic = &apic_default;
  151. EXPORT_SYMBOL_GPL(apic);
  152. static struct apic *apic_probe[] __initdata = {
  153. #ifdef CONFIG_X86_NUMAQ
  154. &apic_numaq,
  155. #endif
  156. #ifdef CONFIG_X86_SUMMIT
  157. &apic_summit,
  158. #endif
  159. #ifdef CONFIG_X86_BIGSMP
  160. &apic_bigsmp,
  161. #endif
  162. #ifdef CONFIG_X86_ES7000
  163. &apic_es7000,
  164. &apic_es7000_cluster,
  165. #endif
  166. &apic_default, /* must be last */
  167. NULL,
  168. };
  169. static int cmdline_apic __initdata;
  170. static int __init parse_apic(char *arg)
  171. {
  172. int i;
  173. if (!arg)
  174. return -EINVAL;
  175. for (i = 0; apic_probe[i]; i++) {
  176. if (!strcmp(apic_probe[i]->name, arg)) {
  177. apic = apic_probe[i];
  178. cmdline_apic = 1;
  179. return 0;
  180. }
  181. }
  182. /* Parsed again by __setup for debug/verbose */
  183. return 0;
  184. }
  185. early_param("apic", parse_apic);
  186. void __init generic_bigsmp_probe(void)
  187. {
  188. #ifdef CONFIG_X86_BIGSMP
  189. /*
  190. * This routine is used to switch to bigsmp mode when
  191. * - There is no apic= option specified by the user
  192. * - generic_apic_probe() has chosen apic_default as the sub_arch
  193. * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
  194. */
  195. if (!cmdline_apic && apic == &apic_default) {
  196. if (apic_bigsmp.probe()) {
  197. apic = &apic_bigsmp;
  198. printk(KERN_INFO "Overriding APIC driver with %s\n",
  199. apic->name);
  200. }
  201. }
  202. #endif
  203. }
  204. void __init generic_apic_probe(void)
  205. {
  206. if (!cmdline_apic) {
  207. int i;
  208. for (i = 0; apic_probe[i]; i++) {
  209. if (apic_probe[i]->probe()) {
  210. apic = apic_probe[i];
  211. break;
  212. }
  213. }
  214. /* Not visible without early console */
  215. if (!apic_probe[i])
  216. panic("Didn't find an APIC driver");
  217. }
  218. printk(KERN_INFO "Using APIC driver %s\n", apic->name);
  219. }
  220. /* These functions can switch the APIC even after the initial ->probe() */
  221. int __init
  222. generic_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  223. {
  224. int i;
  225. for (i = 0; apic_probe[i]; ++i) {
  226. if (!apic_probe[i]->mps_oem_check)
  227. continue;
  228. if (!apic_probe[i]->mps_oem_check(mpc, oem, productid))
  229. continue;
  230. if (!cmdline_apic) {
  231. apic = apic_probe[i];
  232. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  233. apic->name);
  234. }
  235. return 1;
  236. }
  237. return 0;
  238. }
  239. int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  240. {
  241. int i;
  242. for (i = 0; apic_probe[i]; ++i) {
  243. if (!apic_probe[i]->acpi_madt_oem_check)
  244. continue;
  245. if (!apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id))
  246. continue;
  247. if (!cmdline_apic) {
  248. apic = apic_probe[i];
  249. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  250. apic->name);
  251. }
  252. return 1;
  253. }
  254. return 0;
  255. }