mpparse_32.c 28 KB

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