probe_32.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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/threads.h>
  23. #include <linux/cpumask.h>
  24. #include <asm/mpspec.h>
  25. #include <asm/fixmap.h>
  26. #include <asm/apicdef.h>
  27. #include <linux/kernel.h>
  28. #include <linux/string.h>
  29. #include <linux/smp.h>
  30. #include <linux/init.h>
  31. #include <asm/ipi.h>
  32. #include <linux/smp.h>
  33. #include <linux/init.h>
  34. #include <linux/interrupt.h>
  35. #include <asm/acpi.h>
  36. #include <asm/arch_hooks.h>
  37. #include <asm/e820.h>
  38. #include <asm/setup.h>
  39. #ifdef CONFIG_HOTPLUG_CPU
  40. #define DEFAULT_SEND_IPI (1)
  41. #else
  42. #define DEFAULT_SEND_IPI (0)
  43. #endif
  44. int no_broadcast = DEFAULT_SEND_IPI;
  45. #ifdef CONFIG_X86_LOCAL_APIC
  46. void default_setup_apic_routing(void)
  47. {
  48. #ifdef CONFIG_X86_IO_APIC
  49. printk(KERN_INFO
  50. "Enabling APIC mode: Flat. Using %d I/O APICs\n",
  51. nr_ioapics);
  52. #endif
  53. }
  54. static void default_vector_allocation_domain(int cpu, struct cpumask *retmask)
  55. {
  56. /*
  57. * Careful. Some cpus do not strictly honor the set of cpus
  58. * specified in the interrupt destination when using lowest
  59. * priority interrupt delivery mode.
  60. *
  61. * In particular there was a hyperthreading cpu observed to
  62. * deliver interrupts to the wrong hyperthread when only one
  63. * hyperthread was specified in the interrupt desitination.
  64. */
  65. *retmask = (cpumask_t) { { [0] = APIC_ALL_CPUS } };
  66. }
  67. /* should be called last. */
  68. static int probe_default(void)
  69. {
  70. return 1;
  71. }
  72. struct apic apic_default = {
  73. .name = "default",
  74. .probe = probe_default,
  75. .acpi_madt_oem_check = NULL,
  76. .apic_id_registered = default_apic_id_registered,
  77. .irq_delivery_mode = dest_LowestPrio,
  78. /* logical delivery broadcast to all CPUs: */
  79. .irq_dest_mode = 1,
  80. .target_cpus = default_target_cpus,
  81. .disable_esr = 0,
  82. .dest_logical = APIC_DEST_LOGICAL,
  83. .check_apicid_used = default_check_apicid_used,
  84. .check_apicid_present = default_check_apicid_present,
  85. .vector_allocation_domain = default_vector_allocation_domain,
  86. .init_apic_ldr = default_init_apic_ldr,
  87. .ioapic_phys_id_map = default_ioapic_phys_id_map,
  88. .setup_apic_routing = default_setup_apic_routing,
  89. .multi_timer_check = NULL,
  90. .apicid_to_node = default_apicid_to_node,
  91. .cpu_to_logical_apicid = default_cpu_to_logical_apicid,
  92. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  93. .apicid_to_cpu_present = default_apicid_to_cpu_present,
  94. .setup_portio_remap = NULL,
  95. .check_phys_apicid_present = default_check_phys_apicid_present,
  96. .enable_apic_mode = NULL,
  97. .phys_pkg_id = default_phys_pkg_id,
  98. .mps_oem_check = NULL,
  99. .get_apic_id = default_get_apic_id,
  100. .set_apic_id = NULL,
  101. .apic_id_mask = 0x0F << 24,
  102. .cpu_mask_to_apicid = default_cpu_mask_to_apicid,
  103. .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
  104. .send_IPI_mask = default_send_IPI_mask_logical,
  105. .send_IPI_mask_allbutself = default_send_IPI_mask_allbutself_logical,
  106. .send_IPI_allbutself = default_send_IPI_allbutself,
  107. .send_IPI_all = default_send_IPI_all,
  108. .send_IPI_self = default_send_IPI_self,
  109. .wakeup_cpu = NULL,
  110. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  111. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  112. .wait_for_init_deassert = default_wait_for_init_deassert,
  113. .smp_callin_clear_local_apic = NULL,
  114. .inquire_remote_apic = default_inquire_remote_apic,
  115. .read = native_apic_mem_read,
  116. .write = native_apic_mem_write,
  117. .icr_read = native_apic_icr_read,
  118. .icr_write = native_apic_icr_write,
  119. .wait_icr_idle = native_apic_wait_icr_idle,
  120. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  121. };
  122. extern struct apic apic_numaq;
  123. extern struct apic apic_summit;
  124. extern struct apic apic_bigsmp;
  125. extern struct apic apic_es7000;
  126. extern struct apic apic_default;
  127. struct apic *apic = &apic_default;
  128. EXPORT_SYMBOL_GPL(apic);
  129. static struct apic *apic_probe[] __initdata = {
  130. #ifdef CONFIG_X86_NUMAQ
  131. &apic_numaq,
  132. #endif
  133. #ifdef CONFIG_X86_SUMMIT
  134. &apic_summit,
  135. #endif
  136. #ifdef CONFIG_X86_BIGSMP
  137. &apic_bigsmp,
  138. #endif
  139. #ifdef CONFIG_X86_ES7000
  140. &apic_es7000,
  141. #endif
  142. &apic_default, /* must be last */
  143. NULL,
  144. };
  145. static int cmdline_apic __initdata;
  146. static int __init parse_apic(char *arg)
  147. {
  148. int i;
  149. if (!arg)
  150. return -EINVAL;
  151. for (i = 0; apic_probe[i]; i++) {
  152. if (!strcmp(apic_probe[i]->name, arg)) {
  153. apic = apic_probe[i];
  154. cmdline_apic = 1;
  155. return 0;
  156. }
  157. }
  158. if (x86_quirks->update_apic)
  159. x86_quirks->update_apic();
  160. /* Parsed again by __setup for debug/verbose */
  161. return 0;
  162. }
  163. early_param("apic", parse_apic);
  164. void __init generic_bigsmp_probe(void)
  165. {
  166. #ifdef CONFIG_X86_BIGSMP
  167. /*
  168. * This routine is used to switch to bigsmp mode when
  169. * - There is no apic= option specified by the user
  170. * - generic_apic_probe() has chosen apic_default as the sub_arch
  171. * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
  172. */
  173. if (!cmdline_apic && apic == &apic_default) {
  174. if (apic_bigsmp.probe()) {
  175. apic = &apic_bigsmp;
  176. if (x86_quirks->update_apic)
  177. x86_quirks->update_apic();
  178. printk(KERN_INFO "Overriding APIC driver with %s\n",
  179. apic->name);
  180. }
  181. }
  182. #endif
  183. }
  184. void __init generic_apic_probe(void)
  185. {
  186. if (!cmdline_apic) {
  187. int i;
  188. for (i = 0; apic_probe[i]; i++) {
  189. if (apic_probe[i]->probe()) {
  190. apic = apic_probe[i];
  191. break;
  192. }
  193. }
  194. /* Not visible without early console */
  195. if (!apic_probe[i])
  196. panic("Didn't find an APIC driver");
  197. if (x86_quirks->update_apic)
  198. x86_quirks->update_apic();
  199. }
  200. printk(KERN_INFO "Using APIC driver %s\n", apic->name);
  201. }
  202. /* These functions can switch the APIC even after the initial ->probe() */
  203. int __init
  204. generic_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
  205. {
  206. int i;
  207. for (i = 0; apic_probe[i]; ++i) {
  208. if (!apic_probe[i]->mps_oem_check)
  209. continue;
  210. if (!apic_probe[i]->mps_oem_check(mpc, oem, productid))
  211. continue;
  212. if (!cmdline_apic) {
  213. apic = apic_probe[i];
  214. if (x86_quirks->update_apic)
  215. x86_quirks->update_apic();
  216. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  217. apic->name);
  218. }
  219. return 1;
  220. }
  221. return 0;
  222. }
  223. int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  224. {
  225. int i;
  226. for (i = 0; apic_probe[i]; ++i) {
  227. if (!apic_probe[i]->acpi_madt_oem_check)
  228. continue;
  229. if (!apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id))
  230. continue;
  231. if (!cmdline_apic) {
  232. apic = apic_probe[i];
  233. if (x86_quirks->update_apic)
  234. x86_quirks->update_apic();
  235. printk(KERN_INFO "Switched to APIC driver `%s'.\n",
  236. apic->name);
  237. }
  238. return 1;
  239. }
  240. return 0;
  241. }
  242. #endif /* CONFIG_X86_LOCAL_APIC */
  243. /**
  244. * pre_intr_init_hook - initialisation prior to setting up interrupt vectors
  245. *
  246. * Description:
  247. * Perform any necessary interrupt initialisation prior to setting up
  248. * the "ordinary" interrupt call gates. For legacy reasons, the ISA
  249. * interrupts should be initialised here if the machine emulates a PC
  250. * in any way.
  251. **/
  252. void __init pre_intr_init_hook(void)
  253. {
  254. if (x86_quirks->arch_pre_intr_init) {
  255. if (x86_quirks->arch_pre_intr_init())
  256. return;
  257. }
  258. init_ISA_irqs();
  259. }
  260. /**
  261. * intr_init_hook - post gate setup interrupt initialisation
  262. *
  263. * Description:
  264. * Fill in any interrupts that may have been left out by the general
  265. * init_IRQ() routine. interrupts having to do with the machine rather
  266. * than the devices on the I/O bus (like APIC interrupts in intel MP
  267. * systems) are started here.
  268. **/
  269. void __init intr_init_hook(void)
  270. {
  271. if (x86_quirks->arch_intr_init) {
  272. if (x86_quirks->arch_intr_init())
  273. return;
  274. }
  275. }
  276. /**
  277. * pre_setup_arch_hook - hook called prior to any setup_arch() execution
  278. *
  279. * Description:
  280. * generally used to activate any machine specific identification
  281. * routines that may be needed before setup_arch() runs. On Voyager
  282. * this is used to get the board revision and type.
  283. **/
  284. void __init pre_setup_arch_hook(void)
  285. {
  286. }
  287. /**
  288. * trap_init_hook - initialise system specific traps
  289. *
  290. * Description:
  291. * Called as the final act of trap_init(). Used in VISWS to initialise
  292. * the various board specific APIC traps.
  293. **/
  294. void __init trap_init_hook(void)
  295. {
  296. if (x86_quirks->arch_trap_init) {
  297. if (x86_quirks->arch_trap_init())
  298. return;
  299. }
  300. }
  301. static struct irqaction irq0 = {
  302. .handler = timer_interrupt,
  303. .flags = IRQF_DISABLED | IRQF_NOBALANCING | IRQF_IRQPOLL,
  304. .mask = CPU_MASK_NONE,
  305. .name = "timer"
  306. };
  307. /**
  308. * pre_time_init_hook - do any specific initialisations before.
  309. *
  310. **/
  311. void __init pre_time_init_hook(void)
  312. {
  313. if (x86_quirks->arch_pre_time_init)
  314. x86_quirks->arch_pre_time_init();
  315. }
  316. /**
  317. * time_init_hook - do any specific initialisations for the system timer.
  318. *
  319. * Description:
  320. * Must plug the system timer interrupt source at HZ into the IRQ listed
  321. * in irq_vectors.h:TIMER_IRQ
  322. **/
  323. void __init time_init_hook(void)
  324. {
  325. if (x86_quirks->arch_time_init) {
  326. /*
  327. * A nonzero return code does not mean failure, it means
  328. * that the architecture quirk does not want any
  329. * generic (timer) setup to be performed after this:
  330. */
  331. if (x86_quirks->arch_time_init())
  332. return;
  333. }
  334. irq0.mask = cpumask_of_cpu(0);
  335. setup_irq(0, &irq0);
  336. }
  337. #ifdef CONFIG_MCA
  338. /**
  339. * mca_nmi_hook - hook into MCA specific NMI chain
  340. *
  341. * Description:
  342. * The MCA (Microchannel Architecture) has an NMI chain for NMI sources
  343. * along the MCA bus. Use this to hook into that chain if you will need
  344. * it.
  345. **/
  346. void mca_nmi_hook(void)
  347. {
  348. /*
  349. * If I recall correctly, there's a whole bunch of other things that
  350. * we can do to check for NMI problems, but that's all I know about
  351. * at the moment.
  352. */
  353. pr_warning("NMI generated from unknown source!\n");
  354. }
  355. #endif
  356. static __init int no_ipi_broadcast(char *str)
  357. {
  358. get_option(&str, &no_broadcast);
  359. pr_info("Using %s mode\n",
  360. no_broadcast ? "No IPI Broadcast" : "IPI Broadcast");
  361. return 1;
  362. }
  363. __setup("no_ipi_broadcast=", no_ipi_broadcast);
  364. static int __init print_ipi_mode(void)
  365. {
  366. pr_info("Using IPI %s mode\n",
  367. no_broadcast ? "No-Shortcut" : "Shortcut");
  368. return 0;
  369. }
  370. late_initcall(print_ipi_mode);