mpparse.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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 <asm/e820.h>
  27. #include <asm/trampoline.h>
  28. #include <asm/setup.h>
  29. #include <mach_apic.h>
  30. #ifdef CONFIG_X86_32
  31. #include <mach_apicdef.h>
  32. #include <mach_mpparse.h>
  33. #endif
  34. /*
  35. * Checksum an MP configuration block.
  36. */
  37. static int __init mpf_checksum(unsigned char *mp, int len)
  38. {
  39. int sum = 0;
  40. while (len--)
  41. sum += *mp++;
  42. return sum & 0xFF;
  43. }
  44. static void __init MP_processor_info(struct mpc_config_processor *m)
  45. {
  46. int apicid;
  47. char *bootup_cpu = "";
  48. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  49. disabled_cpus++;
  50. return;
  51. }
  52. if (x86_quirks->mpc_apic_id)
  53. apicid = x86_quirks->mpc_apic_id(m);
  54. else
  55. apicid = m->mpc_apicid;
  56. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  57. bootup_cpu = " (Bootup-CPU)";
  58. boot_cpu_physical_apicid = m->mpc_apicid;
  59. }
  60. printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
  61. generic_processor_info(apicid, m->mpc_apicver);
  62. }
  63. #ifdef CONFIG_X86_IO_APIC
  64. static void __init MP_bus_info(struct mpc_config_bus *m)
  65. {
  66. char str[7];
  67. memcpy(str, m->mpc_bustype, 6);
  68. str[6] = 0;
  69. if (x86_quirks->mpc_oem_bus_info)
  70. x86_quirks->mpc_oem_bus_info(m, str);
  71. else
  72. apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->mpc_busid, str);
  73. #if MAX_MP_BUSSES < 256
  74. if (m->mpc_busid >= MAX_MP_BUSSES) {
  75. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  76. " is too large, max. supported is %d\n",
  77. m->mpc_busid, str, MAX_MP_BUSSES - 1);
  78. return;
  79. }
  80. #endif
  81. if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
  82. set_bit(m->mpc_busid, mp_bus_not_pci);
  83. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  84. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
  85. #endif
  86. } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
  87. if (x86_quirks->mpc_oem_pci_bus)
  88. x86_quirks->mpc_oem_pci_bus(m);
  89. clear_bit(m->mpc_busid, mp_bus_not_pci);
  90. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  91. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
  92. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
  93. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
  94. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
  95. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
  96. #endif
  97. } else
  98. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  99. }
  100. #endif
  101. #ifdef CONFIG_X86_IO_APIC
  102. static int bad_ioapic(unsigned long address)
  103. {
  104. if (nr_ioapics >= MAX_IO_APICS) {
  105. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  106. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  107. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  108. }
  109. if (!address) {
  110. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  111. " found in table, skipping!\n");
  112. return 1;
  113. }
  114. return 0;
  115. }
  116. static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
  117. {
  118. if (!(m->mpc_flags & MPC_APIC_USABLE))
  119. return;
  120. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  121. m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
  122. if (bad_ioapic(m->mpc_apicaddr))
  123. return;
  124. mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
  125. mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
  126. mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
  127. mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
  128. mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
  129. nr_ioapics++;
  130. }
  131. static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
  132. {
  133. apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
  134. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  135. m->mpc_irqtype, m->mpc_irqflag & 3,
  136. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  137. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  138. }
  139. static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
  140. {
  141. apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
  142. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  143. mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
  144. (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
  145. mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
  146. }
  147. static void __init assign_to_mp_irq(struct mpc_config_intsrc *m,
  148. struct mp_config_intsrc *mp_irq)
  149. {
  150. mp_irq->mp_dstapic = m->mpc_dstapic;
  151. mp_irq->mp_type = m->mpc_type;
  152. mp_irq->mp_irqtype = m->mpc_irqtype;
  153. mp_irq->mp_irqflag = m->mpc_irqflag;
  154. mp_irq->mp_srcbus = m->mpc_srcbus;
  155. mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
  156. mp_irq->mp_dstirq = m->mpc_dstirq;
  157. }
  158. static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
  159. struct mpc_config_intsrc *m)
  160. {
  161. m->mpc_dstapic = mp_irq->mp_dstapic;
  162. m->mpc_type = mp_irq->mp_type;
  163. m->mpc_irqtype = mp_irq->mp_irqtype;
  164. m->mpc_irqflag = mp_irq->mp_irqflag;
  165. m->mpc_srcbus = mp_irq->mp_srcbus;
  166. m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
  167. m->mpc_dstirq = mp_irq->mp_dstirq;
  168. }
  169. static int __init mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
  170. struct mpc_config_intsrc *m)
  171. {
  172. if (mp_irq->mp_dstapic != m->mpc_dstapic)
  173. return 1;
  174. if (mp_irq->mp_type != m->mpc_type)
  175. return 2;
  176. if (mp_irq->mp_irqtype != m->mpc_irqtype)
  177. return 3;
  178. if (mp_irq->mp_irqflag != m->mpc_irqflag)
  179. return 4;
  180. if (mp_irq->mp_srcbus != m->mpc_srcbus)
  181. return 5;
  182. if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
  183. return 6;
  184. if (mp_irq->mp_dstirq != m->mpc_dstirq)
  185. return 7;
  186. return 0;
  187. }
  188. static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
  189. {
  190. int i;
  191. print_MP_intsrc_info(m);
  192. for (i = 0; i < mp_irq_entries; i++) {
  193. if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
  194. return;
  195. }
  196. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  197. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  198. panic("Max # of irq sources exceeded!!\n");
  199. }
  200. #endif
  201. static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
  202. {
  203. apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
  204. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  205. m->mpc_irqtype, m->mpc_irqflag & 3,
  206. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
  207. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  208. }
  209. /*
  210. * Read/parse the MPC
  211. */
  212. static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
  213. char *str)
  214. {
  215. if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
  216. printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
  217. mpc->mpc_signature[0], mpc->mpc_signature[1],
  218. mpc->mpc_signature[2], mpc->mpc_signature[3]);
  219. return 0;
  220. }
  221. if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
  222. printk(KERN_ERR "MPTABLE: checksum error!\n");
  223. return 0;
  224. }
  225. if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
  226. printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
  227. mpc->mpc_spec);
  228. return 0;
  229. }
  230. if (!mpc->mpc_lapic) {
  231. printk(KERN_ERR "MPTABLE: null local APIC address!\n");
  232. return 0;
  233. }
  234. memcpy(oem, mpc->mpc_oem, 8);
  235. oem[8] = 0;
  236. printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
  237. memcpy(str, mpc->mpc_productid, 12);
  238. str[12] = 0;
  239. printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
  240. printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
  241. return 1;
  242. }
  243. static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
  244. {
  245. char str[16];
  246. char oem[10];
  247. int count = sizeof(*mpc);
  248. unsigned char *mpt = ((unsigned char *)mpc) + count;
  249. if (!smp_check_mpc(mpc, oem, str))
  250. return 0;
  251. #ifdef CONFIG_X86_32
  252. /*
  253. * need to make sure summit and es7000's mps_oem_check is safe to be
  254. * called early via genericarch 's mps_oem_check
  255. */
  256. if (early) {
  257. #ifdef CONFIG_X86_NUMAQ
  258. numaq_mps_oem_check(mpc, oem, str);
  259. #endif
  260. } else
  261. mps_oem_check(mpc, oem, str);
  262. #endif
  263. /* save the local APIC address, it might be non-default */
  264. if (!acpi_lapic)
  265. mp_lapic_addr = mpc->mpc_lapic;
  266. if (early)
  267. return 1;
  268. if (mpc->mpc_oemptr && x86_quirks->smp_read_mpc_oem) {
  269. struct mp_config_oemtable *oem_table = (struct mp_config_oemtable *)(unsigned long)mpc->mpc_oemptr;
  270. x86_quirks->smp_read_mpc_oem(oem_table, mpc->mpc_oemsize);
  271. }
  272. /*
  273. * Now process the configuration blocks.
  274. */
  275. if (x86_quirks->mpc_record)
  276. *x86_quirks->mpc_record = 0;
  277. while (count < mpc->mpc_length) {
  278. switch (*mpt) {
  279. case MP_PROCESSOR:
  280. {
  281. struct mpc_config_processor *m =
  282. (struct mpc_config_processor *)mpt;
  283. /* ACPI may have already provided this data */
  284. if (!acpi_lapic)
  285. MP_processor_info(m);
  286. mpt += sizeof(*m);
  287. count += sizeof(*m);
  288. break;
  289. }
  290. case MP_BUS:
  291. {
  292. struct mpc_config_bus *m =
  293. (struct mpc_config_bus *)mpt;
  294. #ifdef CONFIG_X86_IO_APIC
  295. MP_bus_info(m);
  296. #endif
  297. mpt += sizeof(*m);
  298. count += sizeof(*m);
  299. break;
  300. }
  301. case MP_IOAPIC:
  302. {
  303. #ifdef CONFIG_X86_IO_APIC
  304. struct mpc_config_ioapic *m =
  305. (struct mpc_config_ioapic *)mpt;
  306. MP_ioapic_info(m);
  307. #endif
  308. mpt += sizeof(struct mpc_config_ioapic);
  309. count += sizeof(struct mpc_config_ioapic);
  310. break;
  311. }
  312. case MP_INTSRC:
  313. {
  314. #ifdef CONFIG_X86_IO_APIC
  315. struct mpc_config_intsrc *m =
  316. (struct mpc_config_intsrc *)mpt;
  317. MP_intsrc_info(m);
  318. #endif
  319. mpt += sizeof(struct mpc_config_intsrc);
  320. count += sizeof(struct mpc_config_intsrc);
  321. break;
  322. }
  323. case MP_LINTSRC:
  324. {
  325. struct mpc_config_lintsrc *m =
  326. (struct mpc_config_lintsrc *)mpt;
  327. MP_lintsrc_info(m);
  328. mpt += sizeof(*m);
  329. count += sizeof(*m);
  330. break;
  331. }
  332. default:
  333. /* wrong mptable */
  334. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  335. printk(KERN_ERR "type %x\n", *mpt);
  336. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  337. 1, mpc, mpc->mpc_length, 1);
  338. count = mpc->mpc_length;
  339. break;
  340. }
  341. if (x86_quirks->mpc_record)
  342. (*x86_quirks->mpc_record)++;
  343. }
  344. #ifdef CONFIG_X86_GENERICARCH
  345. generic_bigsmp_probe();
  346. #endif
  347. #ifdef CONFIG_X86_32
  348. setup_apic_routing();
  349. #endif
  350. if (!num_processors)
  351. printk(KERN_ERR "MPTABLE: no processors registered!\n");
  352. return num_processors;
  353. }
  354. #ifdef CONFIG_X86_IO_APIC
  355. static int __init ELCR_trigger(unsigned int irq)
  356. {
  357. unsigned int port;
  358. port = 0x4d0 + (irq >> 3);
  359. return (inb(port) >> (irq & 7)) & 1;
  360. }
  361. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  362. {
  363. struct mpc_config_intsrc intsrc;
  364. int i;
  365. int ELCR_fallback = 0;
  366. intsrc.mpc_type = MP_INTSRC;
  367. intsrc.mpc_irqflag = 0; /* conforming */
  368. intsrc.mpc_srcbus = 0;
  369. intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
  370. intsrc.mpc_irqtype = mp_INT;
  371. /*
  372. * If true, we have an ISA/PCI system with no IRQ entries
  373. * in the MP table. To prevent the PCI interrupts from being set up
  374. * incorrectly, we try to use the ELCR. The sanity check to see if
  375. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  376. * never be level sensitive, so we simply see if the ELCR agrees.
  377. * If it does, we assume it's valid.
  378. */
  379. if (mpc_default_type == 5) {
  380. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
  381. "falling back to ELCR\n");
  382. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
  383. ELCR_trigger(13))
  384. printk(KERN_ERR "ELCR contains invalid data... "
  385. "not using ELCR\n");
  386. else {
  387. printk(KERN_INFO
  388. "Using ELCR to identify PCI interrupts\n");
  389. ELCR_fallback = 1;
  390. }
  391. }
  392. for (i = 0; i < 16; i++) {
  393. switch (mpc_default_type) {
  394. case 2:
  395. if (i == 0 || i == 13)
  396. continue; /* IRQ0 & IRQ13 not connected */
  397. /* fall through */
  398. default:
  399. if (i == 2)
  400. continue; /* IRQ2 is never connected */
  401. }
  402. if (ELCR_fallback) {
  403. /*
  404. * If the ELCR indicates a level-sensitive interrupt, we
  405. * copy that information over to the MP table in the
  406. * irqflag field (level sensitive, active high polarity).
  407. */
  408. if (ELCR_trigger(i))
  409. intsrc.mpc_irqflag = 13;
  410. else
  411. intsrc.mpc_irqflag = 0;
  412. }
  413. intsrc.mpc_srcbusirq = i;
  414. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  415. MP_intsrc_info(&intsrc);
  416. }
  417. intsrc.mpc_irqtype = mp_ExtINT;
  418. intsrc.mpc_srcbusirq = 0;
  419. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  420. MP_intsrc_info(&intsrc);
  421. }
  422. static void __init construct_ioapic_table(int mpc_default_type)
  423. {
  424. struct mpc_config_ioapic ioapic;
  425. struct mpc_config_bus bus;
  426. bus.mpc_type = MP_BUS;
  427. bus.mpc_busid = 0;
  428. switch (mpc_default_type) {
  429. default:
  430. printk(KERN_ERR "???\nUnknown standard configuration %d\n",
  431. mpc_default_type);
  432. /* fall through */
  433. case 1:
  434. case 5:
  435. memcpy(bus.mpc_bustype, "ISA ", 6);
  436. break;
  437. case 2:
  438. case 6:
  439. case 3:
  440. memcpy(bus.mpc_bustype, "EISA ", 6);
  441. break;
  442. case 4:
  443. case 7:
  444. memcpy(bus.mpc_bustype, "MCA ", 6);
  445. }
  446. MP_bus_info(&bus);
  447. if (mpc_default_type > 4) {
  448. bus.mpc_busid = 1;
  449. memcpy(bus.mpc_bustype, "PCI ", 6);
  450. MP_bus_info(&bus);
  451. }
  452. ioapic.mpc_type = MP_IOAPIC;
  453. ioapic.mpc_apicid = 2;
  454. ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  455. ioapic.mpc_flags = MPC_APIC_USABLE;
  456. ioapic.mpc_apicaddr = 0xFEC00000;
  457. MP_ioapic_info(&ioapic);
  458. /*
  459. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  460. */
  461. construct_default_ioirq_mptable(mpc_default_type);
  462. }
  463. #else
  464. static inline void __init construct_ioapic_table(int mpc_default_type) { }
  465. #endif
  466. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  467. {
  468. struct mpc_config_processor processor;
  469. struct mpc_config_lintsrc lintsrc;
  470. int linttypes[2] = { mp_ExtINT, mp_NMI };
  471. int i;
  472. /*
  473. * local APIC has default address
  474. */
  475. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  476. /*
  477. * 2 CPUs, numbered 0 & 1.
  478. */
  479. processor.mpc_type = MP_PROCESSOR;
  480. /* Either an integrated APIC or a discrete 82489DX. */
  481. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  482. processor.mpc_cpuflag = CPU_ENABLED;
  483. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  484. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  485. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  486. processor.mpc_reserved[0] = 0;
  487. processor.mpc_reserved[1] = 0;
  488. for (i = 0; i < 2; i++) {
  489. processor.mpc_apicid = i;
  490. MP_processor_info(&processor);
  491. }
  492. construct_ioapic_table(mpc_default_type);
  493. lintsrc.mpc_type = MP_LINTSRC;
  494. lintsrc.mpc_irqflag = 0; /* conforming */
  495. lintsrc.mpc_srcbusid = 0;
  496. lintsrc.mpc_srcbusirq = 0;
  497. lintsrc.mpc_destapic = MP_APIC_ALL;
  498. for (i = 0; i < 2; i++) {
  499. lintsrc.mpc_irqtype = linttypes[i];
  500. lintsrc.mpc_destapiclint = i;
  501. MP_lintsrc_info(&lintsrc);
  502. }
  503. }
  504. static struct intel_mp_floating *mpf_found;
  505. /*
  506. * Scan the memory blocks for an SMP configuration block.
  507. */
  508. static void __init __get_smp_config(unsigned int early)
  509. {
  510. struct intel_mp_floating *mpf = mpf_found;
  511. if (x86_quirks->mach_get_smp_config) {
  512. if (x86_quirks->mach_get_smp_config(early))
  513. return;
  514. }
  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 "Using ACPI (MADT) for SMP configuration "
  523. "information\n");
  524. return;
  525. } else if (acpi_lapic)
  526. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  527. "configuration information\n");
  528. if (!mpf)
  529. return;
  530. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  531. mpf->mpf_specification);
  532. #if defined(CONFIG_X86_LOCAL_APIC) && defined(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. #ifdef CONFIG_X86_LOCAL_APIC
  562. smp_found_config = 0;
  563. #endif
  564. printk(KERN_ERR
  565. "BIOS bug, MP table errors detected!...\n");
  566. printk(KERN_ERR "... disabling SMP support. "
  567. "(tell your hw vendor)\n");
  568. return;
  569. }
  570. if (early)
  571. return;
  572. #ifdef CONFIG_X86_IO_APIC
  573. /*
  574. * If there are no explicit MP IRQ entries, then we are
  575. * broken. We set up most of the low 16 IO-APIC pins to
  576. * ISA defaults and hope it will work.
  577. */
  578. if (!mp_irq_entries) {
  579. struct mpc_config_bus bus;
  580. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  581. "using default mptable. "
  582. "(tell your hw vendor)\n");
  583. bus.mpc_type = MP_BUS;
  584. bus.mpc_busid = 0;
  585. memcpy(bus.mpc_bustype, "ISA ", 6);
  586. MP_bus_info(&bus);
  587. construct_default_ioirq_mptable(0);
  588. }
  589. #endif
  590. } else
  591. BUG();
  592. if (!early)
  593. printk(KERN_INFO "Processors: %d\n", num_processors);
  594. /*
  595. * Only use the first configuration found.
  596. */
  597. }
  598. void __init early_get_smp_config(void)
  599. {
  600. __get_smp_config(1);
  601. }
  602. void __init get_smp_config(void)
  603. {
  604. __get_smp_config(0);
  605. }
  606. static int __init smp_scan_config(unsigned long base, unsigned long length,
  607. unsigned reserve)
  608. {
  609. unsigned int *bp = phys_to_virt(base);
  610. struct intel_mp_floating *mpf;
  611. apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
  612. bp, length);
  613. BUILD_BUG_ON(sizeof(*mpf) != 16);
  614. while (length > 0) {
  615. mpf = (struct intel_mp_floating *)bp;
  616. if ((*bp == SMP_MAGIC_IDENT) &&
  617. (mpf->mpf_length == 1) &&
  618. !mpf_checksum((unsigned char *)bp, 16) &&
  619. ((mpf->mpf_specification == 1)
  620. || (mpf->mpf_specification == 4))) {
  621. #ifdef CONFIG_X86_LOCAL_APIC
  622. smp_found_config = 1;
  623. #endif
  624. mpf_found = mpf;
  625. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  626. mpf, virt_to_phys(mpf));
  627. if (!reserve)
  628. return 1;
  629. reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
  630. BOOTMEM_DEFAULT);
  631. if (mpf->mpf_physptr) {
  632. unsigned long size = PAGE_SIZE;
  633. #ifdef CONFIG_X86_32
  634. /*
  635. * We cannot access to MPC table to compute
  636. * table size yet, as only few megabytes from
  637. * the bottom is mapped now.
  638. * PC-9800's MPC table places on the very last
  639. * of physical memory; so that simply reserving
  640. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  641. * in reserve_bootmem.
  642. */
  643. unsigned long end = max_low_pfn * PAGE_SIZE;
  644. if (mpf->mpf_physptr + size > end)
  645. size = end - mpf->mpf_physptr;
  646. #endif
  647. reserve_bootmem_generic(mpf->mpf_physptr, size,
  648. BOOTMEM_DEFAULT);
  649. }
  650. return 1;
  651. }
  652. bp += 4;
  653. length -= 16;
  654. }
  655. return 0;
  656. }
  657. static void __init __find_smp_config(unsigned int reserve)
  658. {
  659. unsigned int address;
  660. if (x86_quirks->mach_find_smp_config) {
  661. if (x86_quirks->mach_find_smp_config(reserve))
  662. return;
  663. }
  664. /*
  665. * FIXME: Linux assumes you have 640K of base ram..
  666. * this continues the error...
  667. *
  668. * 1) Scan the bottom 1K for a signature
  669. * 2) Scan the top 1K of base RAM
  670. * 3) Scan the 64K of bios
  671. */
  672. if (smp_scan_config(0x0, 0x400, reserve) ||
  673. smp_scan_config(639 * 0x400, 0x400, reserve) ||
  674. smp_scan_config(0xF0000, 0x10000, reserve))
  675. return;
  676. /*
  677. * If it is an SMP machine we should know now, unless the
  678. * configuration is in an EISA/MCA bus machine with an
  679. * extended bios data area.
  680. *
  681. * there is a real-mode segmented pointer pointing to the
  682. * 4K EBDA area at 0x40E, calculate and scan it here.
  683. *
  684. * NOTE! There are Linux loaders that will corrupt the EBDA
  685. * area, and as such this kind of SMP config may be less
  686. * trustworthy, simply because the SMP table may have been
  687. * stomped on during early boot. These loaders are buggy and
  688. * should be fixed.
  689. *
  690. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  691. */
  692. address = get_bios_ebda();
  693. if (address)
  694. smp_scan_config(address, 0x400, reserve);
  695. }
  696. void __init early_find_smp_config(void)
  697. {
  698. __find_smp_config(0);
  699. }
  700. void __init find_smp_config(void)
  701. {
  702. __find_smp_config(1);
  703. }
  704. #ifdef CONFIG_X86_IO_APIC
  705. static u8 __initdata irq_used[MAX_IRQ_SOURCES];
  706. static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
  707. {
  708. int i;
  709. if (m->mpc_irqtype != mp_INT)
  710. return 0;
  711. if (m->mpc_irqflag != 0x0f)
  712. return 0;
  713. /* not legacy */
  714. for (i = 0; i < mp_irq_entries; i++) {
  715. if (mp_irqs[i].mp_irqtype != mp_INT)
  716. continue;
  717. if (mp_irqs[i].mp_irqflag != 0x0f)
  718. continue;
  719. if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
  720. continue;
  721. if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
  722. continue;
  723. if (irq_used[i]) {
  724. /* already claimed */
  725. return -2;
  726. }
  727. irq_used[i] = 1;
  728. return i;
  729. }
  730. /* not found */
  731. return -1;
  732. }
  733. #define SPARE_SLOT_NUM 20
  734. static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
  735. #endif
  736. static int __init replace_intsrc_all(struct mp_config_table *mpc,
  737. unsigned long mpc_new_phys,
  738. unsigned long mpc_new_length)
  739. {
  740. #ifdef CONFIG_X86_IO_APIC
  741. int i;
  742. int nr_m_spare = 0;
  743. #endif
  744. int count = sizeof(*mpc);
  745. unsigned char *mpt = ((unsigned char *)mpc) + count;
  746. printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
  747. while (count < mpc->mpc_length) {
  748. switch (*mpt) {
  749. case MP_PROCESSOR:
  750. {
  751. struct mpc_config_processor *m =
  752. (struct mpc_config_processor *)mpt;
  753. mpt += sizeof(*m);
  754. count += sizeof(*m);
  755. break;
  756. }
  757. case MP_BUS:
  758. {
  759. struct mpc_config_bus *m =
  760. (struct mpc_config_bus *)mpt;
  761. mpt += sizeof(*m);
  762. count += sizeof(*m);
  763. break;
  764. }
  765. case MP_IOAPIC:
  766. {
  767. mpt += sizeof(struct mpc_config_ioapic);
  768. count += sizeof(struct mpc_config_ioapic);
  769. break;
  770. }
  771. case MP_INTSRC:
  772. {
  773. #ifdef CONFIG_X86_IO_APIC
  774. struct mpc_config_intsrc *m =
  775. (struct mpc_config_intsrc *)mpt;
  776. printk(KERN_INFO "OLD ");
  777. print_MP_intsrc_info(m);
  778. i = get_MP_intsrc_index(m);
  779. if (i > 0) {
  780. assign_to_mpc_intsrc(&mp_irqs[i], m);
  781. printk(KERN_INFO "NEW ");
  782. print_mp_irq_info(&mp_irqs[i]);
  783. } else if (!i) {
  784. /* legacy, do nothing */
  785. } else if (nr_m_spare < SPARE_SLOT_NUM) {
  786. /*
  787. * not found (-1), or duplicated (-2)
  788. * are invalid entries,
  789. * we need to use the slot later
  790. */
  791. m_spare[nr_m_spare] = m;
  792. nr_m_spare++;
  793. }
  794. #endif
  795. mpt += sizeof(struct mpc_config_intsrc);
  796. count += sizeof(struct mpc_config_intsrc);
  797. break;
  798. }
  799. case MP_LINTSRC:
  800. {
  801. struct mpc_config_lintsrc *m =
  802. (struct mpc_config_lintsrc *)mpt;
  803. mpt += sizeof(*m);
  804. count += sizeof(*m);
  805. break;
  806. }
  807. default:
  808. /* wrong mptable */
  809. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  810. printk(KERN_ERR "type %x\n", *mpt);
  811. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  812. 1, mpc, mpc->mpc_length, 1);
  813. goto out;
  814. }
  815. }
  816. #ifdef CONFIG_X86_IO_APIC
  817. for (i = 0; i < mp_irq_entries; i++) {
  818. if (irq_used[i])
  819. continue;
  820. if (mp_irqs[i].mp_irqtype != mp_INT)
  821. continue;
  822. if (mp_irqs[i].mp_irqflag != 0x0f)
  823. continue;
  824. if (nr_m_spare > 0) {
  825. printk(KERN_INFO "*NEW* found ");
  826. nr_m_spare--;
  827. assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
  828. m_spare[nr_m_spare] = NULL;
  829. } else {
  830. struct mpc_config_intsrc *m =
  831. (struct mpc_config_intsrc *)mpt;
  832. count += sizeof(struct mpc_config_intsrc);
  833. if (!mpc_new_phys) {
  834. printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
  835. } else {
  836. if (count <= mpc_new_length)
  837. printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
  838. else {
  839. printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
  840. goto out;
  841. }
  842. }
  843. assign_to_mpc_intsrc(&mp_irqs[i], m);
  844. mpc->mpc_length = count;
  845. mpt += sizeof(struct mpc_config_intsrc);
  846. }
  847. print_mp_irq_info(&mp_irqs[i]);
  848. }
  849. #endif
  850. out:
  851. /* update checksum */
  852. mpc->mpc_checksum = 0;
  853. mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
  854. mpc->mpc_length);
  855. return 0;
  856. }
  857. static int __initdata enable_update_mptable;
  858. static int __init update_mptable_setup(char *str)
  859. {
  860. enable_update_mptable = 1;
  861. return 0;
  862. }
  863. early_param("update_mptable", update_mptable_setup);
  864. static unsigned long __initdata mpc_new_phys;
  865. static unsigned long mpc_new_length __initdata = 4096;
  866. /* alloc_mptable or alloc_mptable=4k */
  867. static int __initdata alloc_mptable;
  868. static int __init parse_alloc_mptable_opt(char *p)
  869. {
  870. enable_update_mptable = 1;
  871. alloc_mptable = 1;
  872. if (!p)
  873. return 0;
  874. mpc_new_length = memparse(p, &p);
  875. return 0;
  876. }
  877. early_param("alloc_mptable", parse_alloc_mptable_opt);
  878. void __init early_reserve_e820_mpc_new(void)
  879. {
  880. if (enable_update_mptable && alloc_mptable) {
  881. u64 startt = 0;
  882. #ifdef CONFIG_X86_TRAMPOLINE
  883. startt = TRAMPOLINE_BASE;
  884. #endif
  885. mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
  886. }
  887. }
  888. static int __init update_mp_table(void)
  889. {
  890. char str[16];
  891. char oem[10];
  892. struct intel_mp_floating *mpf;
  893. struct mp_config_table *mpc;
  894. struct mp_config_table *mpc_new;
  895. if (!enable_update_mptable)
  896. return 0;
  897. mpf = mpf_found;
  898. if (!mpf)
  899. return 0;
  900. /*
  901. * Now see if we need to go further.
  902. */
  903. if (mpf->mpf_feature1 != 0)
  904. return 0;
  905. if (!mpf->mpf_physptr)
  906. return 0;
  907. mpc = phys_to_virt(mpf->mpf_physptr);
  908. if (!smp_check_mpc(mpc, oem, str))
  909. return 0;
  910. printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
  911. printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
  912. if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
  913. mpc_new_phys = 0;
  914. printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
  915. mpc_new_length);
  916. }
  917. if (!mpc_new_phys) {
  918. unsigned char old, new;
  919. /* check if we can change the postion */
  920. mpc->mpc_checksum = 0;
  921. old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
  922. mpc->mpc_checksum = 0xff;
  923. new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
  924. if (old == new) {
  925. printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
  926. return 0;
  927. }
  928. printk(KERN_INFO "use in-positon replacing\n");
  929. } else {
  930. mpf->mpf_physptr = mpc_new_phys;
  931. mpc_new = phys_to_virt(mpc_new_phys);
  932. memcpy(mpc_new, mpc, mpc->mpc_length);
  933. mpc = mpc_new;
  934. /* check if we can modify that */
  935. if (mpc_new_phys - mpf->mpf_physptr) {
  936. struct intel_mp_floating *mpf_new;
  937. /* steal 16 bytes from [0, 1k) */
  938. printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
  939. mpf_new = phys_to_virt(0x400 - 16);
  940. memcpy(mpf_new, mpf, 16);
  941. mpf = mpf_new;
  942. mpf->mpf_physptr = mpc_new_phys;
  943. }
  944. mpf->mpf_checksum = 0;
  945. mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
  946. printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
  947. }
  948. /*
  949. * only replace the one with mp_INT and
  950. * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
  951. * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
  952. * may need pci=routeirq for all coverage
  953. */
  954. replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
  955. return 0;
  956. }
  957. late_initcall(update_mp_table);