mpparse.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. /*
  2. * Intel Multiprocessor Specification 1.1 and 1.4
  3. * compliant MP-table parsing routines.
  4. *
  5. * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
  6. * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
  7. * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
  8. */
  9. #include <linux/mm.h>
  10. #include <linux/init.h>
  11. #include <linux/delay.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/mc146818rtc.h>
  15. #include <linux/bitops.h>
  16. #include <linux/acpi.h>
  17. #include <linux/module.h>
  18. #include <asm/smp.h>
  19. #include <asm/mtrr.h>
  20. #include <asm/mpspec.h>
  21. #include <asm/pgalloc.h>
  22. #include <asm/io_apic.h>
  23. #include <asm/proto.h>
  24. #include <asm/acpi.h>
  25. #include <asm/bios_ebda.h>
  26. #include <mach_apic.h>
  27. #ifdef CONFIG_X86_32
  28. #include <mach_apicdef.h>
  29. #include <mach_mpparse.h>
  30. #endif
  31. /* Have we found an MP table */
  32. int smp_found_config;
  33. /*
  34. * Various Linux-internal data structures created from the
  35. * MP-table.
  36. */
  37. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  38. int mp_bus_id_to_type[MAX_MP_BUSSES];
  39. #endif
  40. DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
  41. int mp_bus_id_to_pci_bus[MAX_MP_BUSSES] = {[0 ... MAX_MP_BUSSES - 1] = -1 };
  42. static int mp_current_pci_id;
  43. int pic_mode;
  44. /*
  45. * Intel MP BIOS table parsing routines:
  46. */
  47. /*
  48. * Checksum an MP configuration block.
  49. */
  50. static int __init mpf_checksum(unsigned char *mp, int len)
  51. {
  52. int sum = 0;
  53. while (len--)
  54. sum += *mp++;
  55. return sum & 0xFF;
  56. }
  57. #ifdef CONFIG_X86_NUMAQ
  58. /*
  59. * Have to match translation table entries to main table entries by counter
  60. * hence the mpc_record variable .... can't see a less disgusting way of
  61. * doing this ....
  62. */
  63. static int mpc_record;
  64. static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
  65. __cpuinitdata;
  66. #endif
  67. static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
  68. {
  69. int apicid;
  70. char *bootup_cpu = "";
  71. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  72. disabled_cpus++;
  73. return;
  74. }
  75. #ifdef CONFIG_X86_NUMAQ
  76. apicid = mpc_apic_id(m, translation_table[mpc_record]);
  77. #else
  78. apicid = m->mpc_apicid;
  79. #endif
  80. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  81. bootup_cpu = " (Bootup-CPU)";
  82. boot_cpu_physical_apicid = m->mpc_apicid;
  83. }
  84. printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
  85. generic_processor_info(apicid, m->mpc_apicver);
  86. }
  87. static void __init MP_bus_info(struct mpc_config_bus *m)
  88. {
  89. char str[7];
  90. memcpy(str, m->mpc_bustype, 6);
  91. str[6] = 0;
  92. #ifdef CONFIG_X86_NUMAQ
  93. mpc_oem_bus_info(m, str, translation_table[mpc_record]);
  94. #else
  95. Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
  96. #endif
  97. #if MAX_MP_BUSSES < 256
  98. if (m->mpc_busid >= MAX_MP_BUSSES) {
  99. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  100. " is too large, max. supported is %d\n",
  101. m->mpc_busid, str, MAX_MP_BUSSES - 1);
  102. return;
  103. }
  104. #endif
  105. if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
  106. set_bit(m->mpc_busid, mp_bus_not_pci);
  107. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  108. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
  109. #endif
  110. } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
  111. #ifdef CONFIG_X86_NUMAQ
  112. mpc_oem_pci_bus(m, translation_table[mpc_record]);
  113. #endif
  114. clear_bit(m->mpc_busid, mp_bus_not_pci);
  115. mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
  116. mp_current_pci_id++;
  117. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  118. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
  119. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
  120. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
  121. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
  122. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
  123. #endif
  124. } else
  125. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  126. }
  127. #ifdef CONFIG_X86_IO_APIC
  128. static int bad_ioapic(unsigned long address)
  129. {
  130. if (nr_ioapics >= MAX_IO_APICS) {
  131. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  132. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  133. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  134. }
  135. if (!address) {
  136. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  137. " found in table, skipping!\n");
  138. return 1;
  139. }
  140. return 0;
  141. }
  142. static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
  143. {
  144. if (!(m->mpc_flags & MPC_APIC_USABLE))
  145. return;
  146. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  147. m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
  148. if (bad_ioapic(m->mpc_apicaddr))
  149. return;
  150. mp_ioapics[nr_ioapics] = *m;
  151. nr_ioapics++;
  152. }
  153. static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
  154. {
  155. mp_irqs[mp_irq_entries] = *m;
  156. Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
  157. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  158. m->mpc_irqtype, m->mpc_irqflag & 3,
  159. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  160. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  161. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  162. panic("Max # of irq sources exceeded!!\n");
  163. }
  164. #endif
  165. static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
  166. {
  167. Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
  168. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  169. m->mpc_irqtype, m->mpc_irqflag & 3,
  170. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
  171. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  172. }
  173. #ifdef CONFIG_X86_NUMAQ
  174. static void __init MP_translation_info(struct mpc_config_translation *m)
  175. {
  176. printk(KERN_INFO
  177. "Translation: record %d, type %d, quad %d, global %d, local %d\n",
  178. mpc_record, m->trans_type, m->trans_quad, m->trans_global,
  179. m->trans_local);
  180. if (mpc_record >= MAX_MPC_ENTRY)
  181. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  182. else
  183. translation_table[mpc_record] = m; /* stash this for later */
  184. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  185. node_set_online(m->trans_quad);
  186. }
  187. /*
  188. * Read/parse the MPC oem tables
  189. */
  190. static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
  191. unsigned short oemsize)
  192. {
  193. int count = sizeof(*oemtable); /* the header size */
  194. unsigned char *oemptr = ((unsigned char *)oemtable) + count;
  195. mpc_record = 0;
  196. printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
  197. oemtable);
  198. if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
  199. printk(KERN_WARNING
  200. "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  201. oemtable->oem_signature[0], oemtable->oem_signature[1],
  202. oemtable->oem_signature[2], oemtable->oem_signature[3]);
  203. return;
  204. }
  205. if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
  206. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  207. return;
  208. }
  209. while (count < oemtable->oem_length) {
  210. switch (*oemptr) {
  211. case MP_TRANSLATION:
  212. {
  213. struct mpc_config_translation *m =
  214. (struct mpc_config_translation *)oemptr;
  215. MP_translation_info(m);
  216. oemptr += sizeof(*m);
  217. count += sizeof(*m);
  218. ++mpc_record;
  219. break;
  220. }
  221. default:
  222. {
  223. printk(KERN_WARNING
  224. "Unrecognised OEM table entry type! - %d\n",
  225. (int)*oemptr);
  226. return;
  227. }
  228. }
  229. }
  230. }
  231. static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
  232. char *productid)
  233. {
  234. if (strncmp(oem, "IBM NUMA", 8))
  235. printk("Warning! May not be a NUMA-Q system!\n");
  236. if (mpc->mpc_oemptr)
  237. smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
  238. mpc->mpc_oemsize);
  239. }
  240. #endif /* CONFIG_X86_NUMAQ */
  241. /*
  242. * Read/parse the MPC
  243. */
  244. static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
  245. {
  246. char str[16];
  247. char oem[10];
  248. int count = sizeof(*mpc);
  249. unsigned char *mpt = ((unsigned char *)mpc) + count;
  250. if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
  251. printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
  252. mpc->mpc_signature[0], mpc->mpc_signature[1],
  253. mpc->mpc_signature[2], mpc->mpc_signature[3]);
  254. return 0;
  255. }
  256. if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
  257. printk(KERN_ERR "MPTABLE: checksum error!\n");
  258. return 0;
  259. }
  260. if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
  261. printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
  262. mpc->mpc_spec);
  263. return 0;
  264. }
  265. if (!mpc->mpc_lapic) {
  266. printk(KERN_ERR "MPTABLE: null local APIC address!\n");
  267. return 0;
  268. }
  269. memcpy(oem, mpc->mpc_oem, 8);
  270. oem[8] = 0;
  271. printk(KERN_INFO "MPTABLE: OEM ID: %s ", oem);
  272. memcpy(str, mpc->mpc_productid, 12);
  273. str[12] = 0;
  274. printk("Product ID: %s ", str);
  275. #ifdef CONFIG_X86_32
  276. mps_oem_check(mpc, oem, str);
  277. #endif
  278. printk(KERN_INFO "MPTABLE: Product ID: %s ", str);
  279. printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
  280. /* save the local APIC address, it might be non-default */
  281. if (!acpi_lapic)
  282. mp_lapic_addr = mpc->mpc_lapic;
  283. if (early)
  284. return 1;
  285. /*
  286. * Now process the configuration blocks.
  287. */
  288. #ifdef CONFIG_X86_NUMAQ
  289. mpc_record = 0;
  290. #endif
  291. while (count < mpc->mpc_length) {
  292. switch (*mpt) {
  293. case MP_PROCESSOR:
  294. {
  295. struct mpc_config_processor *m =
  296. (struct mpc_config_processor *)mpt;
  297. /* ACPI may have already provided this data */
  298. if (!acpi_lapic)
  299. MP_processor_info(m);
  300. mpt += sizeof(*m);
  301. count += sizeof(*m);
  302. break;
  303. }
  304. case MP_BUS:
  305. {
  306. struct mpc_config_bus *m =
  307. (struct mpc_config_bus *)mpt;
  308. MP_bus_info(m);
  309. mpt += sizeof(*m);
  310. count += sizeof(*m);
  311. break;
  312. }
  313. case MP_IOAPIC:
  314. {
  315. #ifdef CONFIG_X86_IO_APIC
  316. struct mpc_config_ioapic *m =
  317. (struct mpc_config_ioapic *)mpt;
  318. MP_ioapic_info(m);
  319. #endif
  320. mpt += sizeof(struct mpc_config_ioapic);
  321. count += sizeof(struct mpc_config_ioapic);
  322. break;
  323. }
  324. case MP_INTSRC:
  325. {
  326. #ifdef CONFIG_X86_IO_APIC
  327. struct mpc_config_intsrc *m =
  328. (struct mpc_config_intsrc *)mpt;
  329. MP_intsrc_info(m);
  330. #endif
  331. mpt += sizeof(struct mpc_config_intsrc);
  332. count += sizeof(struct mpc_config_intsrc);
  333. break;
  334. }
  335. case MP_LINTSRC:
  336. {
  337. struct mpc_config_lintsrc *m =
  338. (struct mpc_config_lintsrc *)mpt;
  339. MP_lintsrc_info(m);
  340. mpt += sizeof(*m);
  341. count += sizeof(*m);
  342. break;
  343. }
  344. default:
  345. /* wrong mptable */
  346. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  347. printk(KERN_ERR "type %x\n", *mpt);
  348. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  349. 1, mpc, mpc->mpc_length, 1);
  350. count = mpc->mpc_length;
  351. break;
  352. }
  353. #ifdef CONFIG_X86_NUMAQ
  354. ++mpc_record;
  355. #endif
  356. }
  357. setup_apic_routing();
  358. if (!num_processors)
  359. printk(KERN_ERR "MPTABLE: no processors registered!\n");
  360. return num_processors;
  361. }
  362. #ifdef CONFIG_X86_IO_APIC
  363. static int __init ELCR_trigger(unsigned int irq)
  364. {
  365. unsigned int port;
  366. port = 0x4d0 + (irq >> 3);
  367. return (inb(port) >> (irq & 7)) & 1;
  368. }
  369. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  370. {
  371. struct mpc_config_intsrc intsrc;
  372. int i;
  373. int ELCR_fallback = 0;
  374. intsrc.mpc_type = MP_INTSRC;
  375. intsrc.mpc_irqflag = 0; /* conforming */
  376. intsrc.mpc_srcbus = 0;
  377. intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
  378. intsrc.mpc_irqtype = mp_INT;
  379. /*
  380. * If true, we have an ISA/PCI system with no IRQ entries
  381. * in the MP table. To prevent the PCI interrupts from being set up
  382. * incorrectly, we try to use the ELCR. The sanity check to see if
  383. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  384. * never be level sensitive, so we simply see if the ELCR agrees.
  385. * If it does, we assume it's valid.
  386. */
  387. if (mpc_default_type == 5) {
  388. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
  389. "falling back to ELCR\n");
  390. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
  391. ELCR_trigger(13))
  392. printk(KERN_ERR "ELCR contains invalid data... "
  393. "not using ELCR\n");
  394. else {
  395. printk(KERN_INFO
  396. "Using ELCR to identify PCI interrupts\n");
  397. ELCR_fallback = 1;
  398. }
  399. }
  400. for (i = 0; i < 16; i++) {
  401. switch (mpc_default_type) {
  402. case 2:
  403. if (i == 0 || i == 13)
  404. continue; /* IRQ0 & IRQ13 not connected */
  405. /* fall through */
  406. default:
  407. if (i == 2)
  408. continue; /* IRQ2 is never connected */
  409. }
  410. if (ELCR_fallback) {
  411. /*
  412. * If the ELCR indicates a level-sensitive interrupt, we
  413. * copy that information over to the MP table in the
  414. * irqflag field (level sensitive, active high polarity).
  415. */
  416. if (ELCR_trigger(i))
  417. intsrc.mpc_irqflag = 13;
  418. else
  419. intsrc.mpc_irqflag = 0;
  420. }
  421. intsrc.mpc_srcbusirq = i;
  422. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  423. MP_intsrc_info(&intsrc);
  424. }
  425. intsrc.mpc_irqtype = mp_ExtINT;
  426. intsrc.mpc_srcbusirq = 0;
  427. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  428. MP_intsrc_info(&intsrc);
  429. }
  430. #endif
  431. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  432. {
  433. struct mpc_config_processor processor;
  434. struct mpc_config_bus bus;
  435. #ifdef CONFIG_X86_IO_APIC
  436. struct mpc_config_ioapic ioapic;
  437. #endif
  438. struct mpc_config_lintsrc lintsrc;
  439. int linttypes[2] = { mp_ExtINT, mp_NMI };
  440. int i;
  441. /*
  442. * local APIC has default address
  443. */
  444. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  445. /*
  446. * 2 CPUs, numbered 0 & 1.
  447. */
  448. processor.mpc_type = MP_PROCESSOR;
  449. /* Either an integrated APIC or a discrete 82489DX. */
  450. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  451. processor.mpc_cpuflag = CPU_ENABLED;
  452. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  453. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  454. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  455. processor.mpc_reserved[0] = 0;
  456. processor.mpc_reserved[1] = 0;
  457. for (i = 0; i < 2; i++) {
  458. processor.mpc_apicid = i;
  459. MP_processor_info(&processor);
  460. }
  461. bus.mpc_type = MP_BUS;
  462. bus.mpc_busid = 0;
  463. switch (mpc_default_type) {
  464. default:
  465. printk(KERN_ERR "???\nUnknown standard configuration %d\n",
  466. mpc_default_type);
  467. /* fall through */
  468. case 1:
  469. case 5:
  470. memcpy(bus.mpc_bustype, "ISA ", 6);
  471. break;
  472. case 2:
  473. case 6:
  474. case 3:
  475. memcpy(bus.mpc_bustype, "EISA ", 6);
  476. break;
  477. case 4:
  478. case 7:
  479. memcpy(bus.mpc_bustype, "MCA ", 6);
  480. }
  481. MP_bus_info(&bus);
  482. if (mpc_default_type > 4) {
  483. bus.mpc_busid = 1;
  484. memcpy(bus.mpc_bustype, "PCI ", 6);
  485. MP_bus_info(&bus);
  486. }
  487. #ifdef CONFIG_X86_IO_APIC
  488. ioapic.mpc_type = MP_IOAPIC;
  489. ioapic.mpc_apicid = 2;
  490. ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  491. ioapic.mpc_flags = MPC_APIC_USABLE;
  492. ioapic.mpc_apicaddr = 0xFEC00000;
  493. MP_ioapic_info(&ioapic);
  494. /*
  495. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  496. */
  497. construct_default_ioirq_mptable(mpc_default_type);
  498. #endif
  499. lintsrc.mpc_type = MP_LINTSRC;
  500. lintsrc.mpc_irqflag = 0; /* conforming */
  501. lintsrc.mpc_srcbusid = 0;
  502. lintsrc.mpc_srcbusirq = 0;
  503. lintsrc.mpc_destapic = MP_APIC_ALL;
  504. for (i = 0; i < 2; i++) {
  505. lintsrc.mpc_irqtype = linttypes[i];
  506. lintsrc.mpc_destapiclint = i;
  507. MP_lintsrc_info(&lintsrc);
  508. }
  509. }
  510. static struct intel_mp_floating *mpf_found;
  511. /*
  512. * Scan the memory blocks for an SMP configuration block.
  513. */
  514. static void __init __get_smp_config(unsigned early)
  515. {
  516. struct intel_mp_floating *mpf = mpf_found;
  517. if (acpi_lapic && early)
  518. return;
  519. /*
  520. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  521. * processors, where MPS only supports physical.
  522. */
  523. if (acpi_lapic && acpi_ioapic) {
  524. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
  525. "information\n");
  526. return;
  527. } else if (acpi_lapic)
  528. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  529. "configuration information\n");
  530. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  531. mpf->mpf_specification);
  532. #ifdef CONFIG_X86_32
  533. if (mpf->mpf_feature2 & (1 << 7)) {
  534. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  535. pic_mode = 1;
  536. } else {
  537. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  538. pic_mode = 0;
  539. }
  540. #endif
  541. /*
  542. * Now see if we need to read further.
  543. */
  544. if (mpf->mpf_feature1 != 0) {
  545. if (early) {
  546. /*
  547. * local APIC has default address
  548. */
  549. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  550. return;
  551. }
  552. printk(KERN_INFO "Default MP configuration #%d\n",
  553. mpf->mpf_feature1);
  554. construct_default_ISA_mptable(mpf->mpf_feature1);
  555. } else if (mpf->mpf_physptr) {
  556. /*
  557. * Read the physical hardware table. Anything here will
  558. * override the defaults.
  559. */
  560. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
  561. smp_found_config = 0;
  562. printk(KERN_ERR
  563. "BIOS bug, MP table errors detected!...\n");
  564. printk(KERN_ERR "... disabling SMP support. "
  565. "(tell your hw vendor)\n");
  566. return;
  567. }
  568. if (early)
  569. return;
  570. #ifdef CONFIG_X86_IO_APIC
  571. /*
  572. * If there are no explicit MP IRQ entries, then we are
  573. * broken. We set up most of the low 16 IO-APIC pins to
  574. * ISA defaults and hope it will work.
  575. */
  576. if (!mp_irq_entries) {
  577. struct mpc_config_bus bus;
  578. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  579. "using default mptable. "
  580. "(tell your hw vendor)\n");
  581. bus.mpc_type = MP_BUS;
  582. bus.mpc_busid = 0;
  583. memcpy(bus.mpc_bustype, "ISA ", 6);
  584. MP_bus_info(&bus);
  585. construct_default_ioirq_mptable(0);
  586. }
  587. #endif
  588. } else
  589. BUG();
  590. if (!early)
  591. printk(KERN_INFO "Processors: %d\n", num_processors);
  592. /*
  593. * Only use the first configuration found.
  594. */
  595. }
  596. void __init early_get_smp_config(void)
  597. {
  598. __get_smp_config(1);
  599. }
  600. void __init get_smp_config(void)
  601. {
  602. __get_smp_config(0);
  603. }
  604. static int __init smp_scan_config(unsigned long base, unsigned long length,
  605. unsigned reserve)
  606. {
  607. extern void __bad_mpf_size(void);
  608. unsigned int *bp = phys_to_virt(base);
  609. struct intel_mp_floating *mpf;
  610. Dprintk("Scan SMP from %p for %ld bytes.\n", bp, length);
  611. if (sizeof(*mpf) != 16)
  612. __bad_mpf_size();
  613. while (length > 0) {
  614. mpf = (struct intel_mp_floating *)bp;
  615. if ((*bp == SMP_MAGIC_IDENT) &&
  616. (mpf->mpf_length == 1) &&
  617. !mpf_checksum((unsigned char *)bp, 16) &&
  618. ((mpf->mpf_specification == 1)
  619. || (mpf->mpf_specification == 4))) {
  620. smp_found_config = 1;
  621. mpf_found = mpf;
  622. #ifdef CONFIG_X86_32
  623. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  624. mpf, virt_to_phys(mpf));
  625. reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
  626. BOOTMEM_DEFAULT);
  627. if (mpf->mpf_physptr) {
  628. /*
  629. * We cannot access to MPC table to compute
  630. * table size yet, as only few megabytes from
  631. * the bottom is mapped now.
  632. * PC-9800's MPC table places on the very last
  633. * of physical memory; so that simply reserving
  634. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  635. * in reserve_bootmem.
  636. */
  637. unsigned long size = PAGE_SIZE;
  638. unsigned long end = max_low_pfn * PAGE_SIZE;
  639. if (mpf->mpf_physptr + size > end)
  640. size = end - mpf->mpf_physptr;
  641. reserve_bootmem(mpf->mpf_physptr, size,
  642. BOOTMEM_DEFAULT);
  643. }
  644. #else
  645. if (!reserve)
  646. return 1;
  647. reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
  648. if (mpf->mpf_physptr)
  649. reserve_bootmem_generic(mpf->mpf_physptr,
  650. PAGE_SIZE);
  651. #endif
  652. return 1;
  653. }
  654. bp += 4;
  655. length -= 16;
  656. }
  657. return 0;
  658. }
  659. static void __init __find_smp_config(unsigned reserve)
  660. {
  661. unsigned int address;
  662. /*
  663. * FIXME: Linux assumes you have 640K of base ram..
  664. * this continues the error...
  665. *
  666. * 1) Scan the bottom 1K for a signature
  667. * 2) Scan the top 1K of base RAM
  668. * 3) Scan the 64K of bios
  669. */
  670. if (smp_scan_config(0x0, 0x400, reserve) ||
  671. smp_scan_config(639 * 0x400, 0x400, reserve) ||
  672. smp_scan_config(0xF0000, 0x10000, reserve))
  673. return;
  674. /*
  675. * If it is an SMP machine we should know now, unless the
  676. * configuration is in an EISA/MCA bus machine with an
  677. * extended bios data area.
  678. *
  679. * there is a real-mode segmented pointer pointing to the
  680. * 4K EBDA area at 0x40E, calculate and scan it here.
  681. *
  682. * NOTE! There are Linux loaders that will corrupt the EBDA
  683. * area, and as such this kind of SMP config may be less
  684. * trustworthy, simply because the SMP table may have been
  685. * stomped on during early boot. These loaders are buggy and
  686. * should be fixed.
  687. *
  688. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  689. */
  690. address = get_bios_ebda();
  691. if (address)
  692. smp_scan_config(address, 0x400, reserve);
  693. }
  694. void __init early_find_smp_config(void)
  695. {
  696. __find_smp_config(0);
  697. }
  698. void __init find_smp_config(void)
  699. {
  700. __find_smp_config(1);
  701. }
  702. /* --------------------------------------------------------------------------
  703. ACPI-based MP Configuration
  704. -------------------------------------------------------------------------- */
  705. #ifdef CONFIG_ACPI
  706. #ifdef CONFIG_X86_IO_APIC
  707. #define MP_ISA_BUS 0
  708. #define MP_MAX_IOAPIC_PIN 127
  709. extern struct mp_ioapic_routing mp_ioapic_routing[MAX_IO_APICS];
  710. static int mp_find_ioapic(int gsi)
  711. {
  712. int i = 0;
  713. /* Find the IOAPIC that manages this GSI. */
  714. for (i = 0; i < nr_ioapics; i++) {
  715. if ((gsi >= mp_ioapic_routing[i].gsi_base)
  716. && (gsi <= mp_ioapic_routing[i].gsi_end))
  717. return i;
  718. }
  719. printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
  720. return -1;
  721. }
  722. static u8 uniq_ioapic_id(u8 id)
  723. {
  724. #ifdef CONFIG_X86_32
  725. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
  726. !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  727. return io_apic_get_unique_id(nr_ioapics, id);
  728. else
  729. return id;
  730. #else
  731. int i;
  732. DECLARE_BITMAP(used, 256);
  733. bitmap_zero(used, 256);
  734. for (i = 0; i < nr_ioapics; i++) {
  735. struct mpc_config_ioapic *ia = &mp_ioapics[i];
  736. __set_bit(ia->mpc_apicid, used);
  737. }
  738. if (!test_bit(id, used))
  739. return id;
  740. return find_first_zero_bit(used, 256);
  741. #endif
  742. }
  743. void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
  744. {
  745. int idx = 0;
  746. if (bad_ioapic(address))
  747. return;
  748. idx = nr_ioapics;
  749. mp_ioapics[idx].mpc_type = MP_IOAPIC;
  750. mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
  751. mp_ioapics[idx].mpc_apicaddr = address;
  752. set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
  753. mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
  754. #ifdef CONFIG_X86_32
  755. mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
  756. #else
  757. mp_ioapics[idx].mpc_apicver = 0;
  758. #endif
  759. /*
  760. * Build basic GSI lookup table to facilitate gsi->io_apic lookups
  761. * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
  762. */
  763. mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
  764. mp_ioapic_routing[idx].gsi_base = gsi_base;
  765. mp_ioapic_routing[idx].gsi_end = gsi_base +
  766. io_apic_get_redir_entries(idx);
  767. printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
  768. "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
  769. mp_ioapics[idx].mpc_apicver, mp_ioapics[idx].mpc_apicaddr,
  770. mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
  771. nr_ioapics++;
  772. }
  773. void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  774. {
  775. struct mpc_config_intsrc intsrc;
  776. int ioapic = -1;
  777. int pin = -1;
  778. /*
  779. * Convert 'gsi' to 'ioapic.pin'.
  780. */
  781. ioapic = mp_find_ioapic(gsi);
  782. if (ioapic < 0)
  783. return;
  784. pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  785. /*
  786. * TBD: This check is for faulty timer entries, where the override
  787. * erroneously sets the trigger to level, resulting in a HUGE
  788. * increase of timer interrupts!
  789. */
  790. if ((bus_irq == 0) && (trigger == 3))
  791. trigger = 1;
  792. intsrc.mpc_type = MP_INTSRC;
  793. intsrc.mpc_irqtype = mp_INT;
  794. intsrc.mpc_irqflag = (trigger << 2) | polarity;
  795. intsrc.mpc_srcbus = MP_ISA_BUS;
  796. intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
  797. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
  798. intsrc.mpc_dstirq = pin; /* INTIN# */
  799. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
  800. intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  801. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  802. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
  803. mp_irqs[mp_irq_entries] = intsrc;
  804. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  805. panic("Max # of irq sources exceeded!\n");
  806. }
  807. int es7000_plat;
  808. void __init mp_config_acpi_legacy_irqs(void)
  809. {
  810. struct mpc_config_intsrc intsrc;
  811. int i = 0;
  812. int ioapic = -1;
  813. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  814. /*
  815. * Fabricate the legacy ISA bus (bus #31).
  816. */
  817. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  818. #endif
  819. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  820. Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
  821. /*
  822. * Older generations of ES7000 have no legacy identity mappings
  823. */
  824. if (es7000_plat == 1)
  825. return;
  826. /*
  827. * Locate the IOAPIC that manages the ISA IRQs (0-15).
  828. */
  829. ioapic = mp_find_ioapic(0);
  830. if (ioapic < 0)
  831. return;
  832. intsrc.mpc_type = MP_INTSRC;
  833. intsrc.mpc_irqflag = 0; /* Conforming */
  834. intsrc.mpc_srcbus = MP_ISA_BUS;
  835. #ifdef CONFIG_X86_IO_APIC
  836. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
  837. #endif
  838. /*
  839. * Use the default configuration for the IRQs 0-15. Unless
  840. * overridden by (MADT) interrupt source override entries.
  841. */
  842. for (i = 0; i < 16; i++) {
  843. int idx;
  844. for (idx = 0; idx < mp_irq_entries; idx++) {
  845. struct mpc_config_intsrc *irq = mp_irqs + idx;
  846. /* Do we already have a mapping for this ISA IRQ? */
  847. if (irq->mpc_srcbus == MP_ISA_BUS
  848. && irq->mpc_srcbusirq == i)
  849. break;
  850. /* Do we already have a mapping for this IOAPIC pin */
  851. if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
  852. (irq->mpc_dstirq == i))
  853. break;
  854. }
  855. if (idx != mp_irq_entries) {
  856. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  857. continue; /* IRQ already used */
  858. }
  859. intsrc.mpc_irqtype = mp_INT;
  860. intsrc.mpc_srcbusirq = i; /* Identity mapped */
  861. intsrc.mpc_dstirq = i;
  862. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
  863. "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  864. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  865. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
  866. intsrc.mpc_dstirq);
  867. mp_irqs[mp_irq_entries] = intsrc;
  868. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  869. panic("Max # of irq sources exceeded!\n");
  870. }
  871. }
  872. int mp_register_gsi(u32 gsi, int triggering, int polarity)
  873. {
  874. int ioapic = -1;
  875. int ioapic_pin = 0;
  876. int idx, bit = 0;
  877. #ifdef CONFIG_X86_32
  878. #define MAX_GSI_NUM 4096
  879. #define IRQ_COMPRESSION_START 64
  880. static int pci_irq = IRQ_COMPRESSION_START;
  881. /*
  882. * Mapping between Global System Interrupts, which
  883. * represent all possible interrupts, and IRQs
  884. * assigned to actual devices.
  885. */
  886. static int gsi_to_irq[MAX_GSI_NUM];
  887. #else
  888. if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
  889. return gsi;
  890. #endif
  891. /* Don't set up the ACPI SCI because it's already set up */
  892. if (acpi_gbl_FADT.sci_interrupt == gsi)
  893. return gsi;
  894. ioapic = mp_find_ioapic(gsi);
  895. if (ioapic < 0) {
  896. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  897. return gsi;
  898. }
  899. ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  900. #ifdef CONFIG_X86_32
  901. if (ioapic_renumber_irq)
  902. gsi = ioapic_renumber_irq(ioapic, gsi);
  903. #endif
  904. /*
  905. * Avoid pin reprogramming. PRTs typically include entries
  906. * with redundant pin->gsi mappings (but unique PCI devices);
  907. * we only program the IOAPIC on the first.
  908. */
  909. bit = ioapic_pin % 32;
  910. idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
  911. if (idx > 3) {
  912. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  913. "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
  914. ioapic_pin);
  915. return gsi;
  916. }
  917. if ((1 << bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
  918. Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
  919. mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
  920. #ifdef CONFIG_X86_32
  921. return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
  922. #else
  923. return gsi;
  924. #endif
  925. }
  926. mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1 << bit);
  927. #ifdef CONFIG_X86_32
  928. /*
  929. * For GSI >= 64, use IRQ compression
  930. */
  931. if ((gsi >= IRQ_COMPRESSION_START)
  932. && (triggering == ACPI_LEVEL_SENSITIVE)) {
  933. /*
  934. * For PCI devices assign IRQs in order, avoiding gaps
  935. * due to unused I/O APIC pins.
  936. */
  937. int irq = gsi;
  938. if (gsi < MAX_GSI_NUM) {
  939. /*
  940. * Retain the VIA chipset work-around (gsi > 15), but
  941. * avoid a problem where the 8254 timer (IRQ0) is setup
  942. * via an override (so it's not on pin 0 of the ioapic),
  943. * and at the same time, the pin 0 interrupt is a PCI
  944. * type. The gsi > 15 test could cause these two pins
  945. * to be shared as IRQ0, and they are not shareable.
  946. * So test for this condition, and if necessary, avoid
  947. * the pin collision.
  948. */
  949. gsi = pci_irq++;
  950. /*
  951. * Don't assign IRQ used by ACPI SCI
  952. */
  953. if (gsi == acpi_gbl_FADT.sci_interrupt)
  954. gsi = pci_irq++;
  955. gsi_to_irq[irq] = gsi;
  956. } else {
  957. printk(KERN_ERR "GSI %u is too high\n", gsi);
  958. return gsi;
  959. }
  960. }
  961. #endif
  962. io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
  963. triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
  964. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  965. return gsi;
  966. }
  967. #endif /* CONFIG_X86_IO_APIC */
  968. #endif /* CONFIG_ACPI */