mpparse_32.c 27 KB

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