probe_32.c 9.8 KB

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