mpparse.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  529. mpf->mpf_specification);
  530. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
  531. if (mpf->mpf_feature2 & (1 << 7)) {
  532. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  533. pic_mode = 1;
  534. } else {
  535. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  536. pic_mode = 0;
  537. }
  538. #endif
  539. /*
  540. * Now see if we need to read further.
  541. */
  542. if (mpf->mpf_feature1 != 0) {
  543. if (early) {
  544. /*
  545. * local APIC has default address
  546. */
  547. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  548. return;
  549. }
  550. printk(KERN_INFO "Default MP configuration #%d\n",
  551. mpf->mpf_feature1);
  552. construct_default_ISA_mptable(mpf->mpf_feature1);
  553. } else if (mpf->mpf_physptr) {
  554. /*
  555. * Read the physical hardware table. Anything here will
  556. * override the defaults.
  557. */
  558. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
  559. #ifdef CONFIG_X86_LOCAL_APIC
  560. smp_found_config = 0;
  561. #endif
  562. printk(KERN_ERR
  563. "BIOS bug, MP table errors detected!...\n");
  564. printk(KERN_ERR "... disabling SMP support. "
  565. "(tell your hw vendor)\n");
  566. return;
  567. }
  568. if (early)
  569. return;
  570. #ifdef CONFIG_X86_IO_APIC
  571. /*
  572. * If there are no explicit MP IRQ entries, then we are
  573. * broken. We set up most of the low 16 IO-APIC pins to
  574. * ISA defaults and hope it will work.
  575. */
  576. if (!mp_irq_entries) {
  577. struct mpc_config_bus bus;
  578. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  579. "using default mptable. "
  580. "(tell your hw vendor)\n");
  581. bus.mpc_type = MP_BUS;
  582. bus.mpc_busid = 0;
  583. memcpy(bus.mpc_bustype, "ISA ", 6);
  584. MP_bus_info(&bus);
  585. construct_default_ioirq_mptable(0);
  586. }
  587. #endif
  588. } else
  589. BUG();
  590. if (!early)
  591. printk(KERN_INFO "Processors: %d\n", num_processors);
  592. /*
  593. * Only use the first configuration found.
  594. */
  595. }
  596. void __init early_get_smp_config(void)
  597. {
  598. __get_smp_config(1);
  599. }
  600. void __init get_smp_config(void)
  601. {
  602. __get_smp_config(0);
  603. }
  604. static int __init smp_scan_config(unsigned long base, unsigned long length,
  605. unsigned reserve)
  606. {
  607. unsigned int *bp = phys_to_virt(base);
  608. struct intel_mp_floating *mpf;
  609. apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
  610. bp, length);
  611. BUILD_BUG_ON(sizeof(*mpf) != 16);
  612. while (length > 0) {
  613. mpf = (struct intel_mp_floating *)bp;
  614. if ((*bp == SMP_MAGIC_IDENT) &&
  615. (mpf->mpf_length == 1) &&
  616. !mpf_checksum((unsigned char *)bp, 16) &&
  617. ((mpf->mpf_specification == 1)
  618. || (mpf->mpf_specification == 4))) {
  619. #ifdef CONFIG_X86_LOCAL_APIC
  620. smp_found_config = 1;
  621. #endif
  622. mpf_found = mpf;
  623. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  624. mpf, virt_to_phys(mpf));
  625. if (!reserve)
  626. return 1;
  627. reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
  628. BOOTMEM_DEFAULT);
  629. if (mpf->mpf_physptr) {
  630. unsigned long size = PAGE_SIZE;
  631. #ifdef CONFIG_X86_32
  632. /*
  633. * We cannot access to MPC table to compute
  634. * table size yet, as only few megabytes from
  635. * the bottom is mapped now.
  636. * PC-9800's MPC table places on the very last
  637. * of physical memory; so that simply reserving
  638. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  639. * in reserve_bootmem.
  640. */
  641. unsigned long end = max_low_pfn * PAGE_SIZE;
  642. if (mpf->mpf_physptr + size > end)
  643. size = end - mpf->mpf_physptr;
  644. #endif
  645. reserve_bootmem_generic(mpf->mpf_physptr, size,
  646. BOOTMEM_DEFAULT);
  647. }
  648. return 1;
  649. }
  650. bp += 4;
  651. length -= 16;
  652. }
  653. return 0;
  654. }
  655. static void __init __find_smp_config(unsigned int reserve)
  656. {
  657. unsigned int address;
  658. if (x86_quirks->mach_find_smp_config) {
  659. if (x86_quirks->mach_find_smp_config(reserve))
  660. return;
  661. }
  662. /*
  663. * FIXME: Linux assumes you have 640K of base ram..
  664. * this continues the error...
  665. *
  666. * 1) Scan the bottom 1K for a signature
  667. * 2) Scan the top 1K of base RAM
  668. * 3) Scan the 64K of bios
  669. */
  670. if (smp_scan_config(0x0, 0x400, reserve) ||
  671. smp_scan_config(639 * 0x400, 0x400, reserve) ||
  672. smp_scan_config(0xF0000, 0x10000, reserve))
  673. return;
  674. /*
  675. * If it is an SMP machine we should know now, unless the
  676. * configuration is in an EISA/MCA bus machine with an
  677. * extended bios data area.
  678. *
  679. * there is a real-mode segmented pointer pointing to the
  680. * 4K EBDA area at 0x40E, calculate and scan it here.
  681. *
  682. * NOTE! There are Linux loaders that will corrupt the EBDA
  683. * area, and as such this kind of SMP config may be less
  684. * trustworthy, simply because the SMP table may have been
  685. * stomped on during early boot. These loaders are buggy and
  686. * should be fixed.
  687. *
  688. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  689. */
  690. address = get_bios_ebda();
  691. if (address)
  692. smp_scan_config(address, 0x400, reserve);
  693. }
  694. void __init early_find_smp_config(void)
  695. {
  696. __find_smp_config(0);
  697. }
  698. void __init find_smp_config(void)
  699. {
  700. __find_smp_config(1);
  701. }
  702. #ifdef CONFIG_X86_IO_APIC
  703. static u8 __initdata irq_used[MAX_IRQ_SOURCES];
  704. static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
  705. {
  706. int i;
  707. if (m->mpc_irqtype != mp_INT)
  708. return 0;
  709. if (m->mpc_irqflag != 0x0f)
  710. return 0;
  711. /* not legacy */
  712. for (i = 0; i < mp_irq_entries; i++) {
  713. if (mp_irqs[i].mp_irqtype != mp_INT)
  714. continue;
  715. if (mp_irqs[i].mp_irqflag != 0x0f)
  716. continue;
  717. if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
  718. continue;
  719. if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
  720. continue;
  721. if (irq_used[i]) {
  722. /* already claimed */
  723. return -2;
  724. }
  725. irq_used[i] = 1;
  726. return i;
  727. }
  728. /* not found */
  729. return -1;
  730. }
  731. #define SPARE_SLOT_NUM 20
  732. static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
  733. #endif
  734. static int __init replace_intsrc_all(struct mp_config_table *mpc,
  735. unsigned long mpc_new_phys,
  736. unsigned long mpc_new_length)
  737. {
  738. #ifdef CONFIG_X86_IO_APIC
  739. int i;
  740. int nr_m_spare = 0;
  741. #endif
  742. int count = sizeof(*mpc);
  743. unsigned char *mpt = ((unsigned char *)mpc) + count;
  744. printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
  745. while (count < mpc->mpc_length) {
  746. switch (*mpt) {
  747. case MP_PROCESSOR:
  748. {
  749. struct mpc_config_processor *m =
  750. (struct mpc_config_processor *)mpt;
  751. mpt += sizeof(*m);
  752. count += sizeof(*m);
  753. break;
  754. }
  755. case MP_BUS:
  756. {
  757. struct mpc_config_bus *m =
  758. (struct mpc_config_bus *)mpt;
  759. mpt += sizeof(*m);
  760. count += sizeof(*m);
  761. break;
  762. }
  763. case MP_IOAPIC:
  764. {
  765. mpt += sizeof(struct mpc_config_ioapic);
  766. count += sizeof(struct mpc_config_ioapic);
  767. break;
  768. }
  769. case MP_INTSRC:
  770. {
  771. #ifdef CONFIG_X86_IO_APIC
  772. struct mpc_config_intsrc *m =
  773. (struct mpc_config_intsrc *)mpt;
  774. printk(KERN_INFO "OLD ");
  775. print_MP_intsrc_info(m);
  776. i = get_MP_intsrc_index(m);
  777. if (i > 0) {
  778. assign_to_mpc_intsrc(&mp_irqs[i], m);
  779. printk(KERN_INFO "NEW ");
  780. print_mp_irq_info(&mp_irqs[i]);
  781. } else if (!i) {
  782. /* legacy, do nothing */
  783. } else if (nr_m_spare < SPARE_SLOT_NUM) {
  784. /*
  785. * not found (-1), or duplicated (-2)
  786. * are invalid entries,
  787. * we need to use the slot later
  788. */
  789. m_spare[nr_m_spare] = m;
  790. nr_m_spare++;
  791. }
  792. #endif
  793. mpt += sizeof(struct mpc_config_intsrc);
  794. count += sizeof(struct mpc_config_intsrc);
  795. break;
  796. }
  797. case MP_LINTSRC:
  798. {
  799. struct mpc_config_lintsrc *m =
  800. (struct mpc_config_lintsrc *)mpt;
  801. mpt += sizeof(*m);
  802. count += sizeof(*m);
  803. break;
  804. }
  805. default:
  806. /* wrong mptable */
  807. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  808. printk(KERN_ERR "type %x\n", *mpt);
  809. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  810. 1, mpc, mpc->mpc_length, 1);
  811. goto out;
  812. }
  813. }
  814. #ifdef CONFIG_X86_IO_APIC
  815. for (i = 0; i < mp_irq_entries; i++) {
  816. if (irq_used[i])
  817. continue;
  818. if (mp_irqs[i].mp_irqtype != mp_INT)
  819. continue;
  820. if (mp_irqs[i].mp_irqflag != 0x0f)
  821. continue;
  822. if (nr_m_spare > 0) {
  823. printk(KERN_INFO "*NEW* found ");
  824. nr_m_spare--;
  825. assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
  826. m_spare[nr_m_spare] = NULL;
  827. } else {
  828. struct mpc_config_intsrc *m =
  829. (struct mpc_config_intsrc *)mpt;
  830. count += sizeof(struct mpc_config_intsrc);
  831. if (!mpc_new_phys) {
  832. printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
  833. } else {
  834. if (count <= mpc_new_length)
  835. printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
  836. else {
  837. printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
  838. goto out;
  839. }
  840. }
  841. assign_to_mpc_intsrc(&mp_irqs[i], m);
  842. mpc->mpc_length = count;
  843. mpt += sizeof(struct mpc_config_intsrc);
  844. }
  845. print_mp_irq_info(&mp_irqs[i]);
  846. }
  847. #endif
  848. out:
  849. /* update checksum */
  850. mpc->mpc_checksum = 0;
  851. mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
  852. mpc->mpc_length);
  853. return 0;
  854. }
  855. static int __initdata enable_update_mptable;
  856. static int __init update_mptable_setup(char *str)
  857. {
  858. enable_update_mptable = 1;
  859. return 0;
  860. }
  861. early_param("update_mptable", update_mptable_setup);
  862. static unsigned long __initdata mpc_new_phys;
  863. static unsigned long mpc_new_length __initdata = 4096;
  864. /* alloc_mptable or alloc_mptable=4k */
  865. static int __initdata alloc_mptable;
  866. static int __init parse_alloc_mptable_opt(char *p)
  867. {
  868. enable_update_mptable = 1;
  869. alloc_mptable = 1;
  870. if (!p)
  871. return 0;
  872. mpc_new_length = memparse(p, &p);
  873. return 0;
  874. }
  875. early_param("alloc_mptable", parse_alloc_mptable_opt);
  876. void __init early_reserve_e820_mpc_new(void)
  877. {
  878. if (enable_update_mptable && alloc_mptable) {
  879. u64 startt = 0;
  880. #ifdef CONFIG_X86_TRAMPOLINE
  881. startt = TRAMPOLINE_BASE;
  882. #endif
  883. mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
  884. }
  885. }
  886. static int __init update_mp_table(void)
  887. {
  888. char str[16];
  889. char oem[10];
  890. struct intel_mp_floating *mpf;
  891. struct mp_config_table *mpc;
  892. struct mp_config_table *mpc_new;
  893. if (!enable_update_mptable)
  894. return 0;
  895. mpf = mpf_found;
  896. if (!mpf)
  897. return 0;
  898. /*
  899. * Now see if we need to go further.
  900. */
  901. if (mpf->mpf_feature1 != 0)
  902. return 0;
  903. if (!mpf->mpf_physptr)
  904. return 0;
  905. mpc = phys_to_virt(mpf->mpf_physptr);
  906. if (!smp_check_mpc(mpc, oem, str))
  907. return 0;
  908. printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
  909. printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
  910. if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
  911. mpc_new_phys = 0;
  912. printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
  913. mpc_new_length);
  914. }
  915. if (!mpc_new_phys) {
  916. unsigned char old, new;
  917. /* check if we can change the postion */
  918. mpc->mpc_checksum = 0;
  919. old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
  920. mpc->mpc_checksum = 0xff;
  921. new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
  922. if (old == new) {
  923. printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
  924. return 0;
  925. }
  926. printk(KERN_INFO "use in-positon replacing\n");
  927. } else {
  928. mpf->mpf_physptr = mpc_new_phys;
  929. mpc_new = phys_to_virt(mpc_new_phys);
  930. memcpy(mpc_new, mpc, mpc->mpc_length);
  931. mpc = mpc_new;
  932. /* check if we can modify that */
  933. if (mpc_new_phys - mpf->mpf_physptr) {
  934. struct intel_mp_floating *mpf_new;
  935. /* steal 16 bytes from [0, 1k) */
  936. printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
  937. mpf_new = phys_to_virt(0x400 - 16);
  938. memcpy(mpf_new, mpf, 16);
  939. mpf = mpf_new;
  940. mpf->mpf_physptr = mpc_new_phys;
  941. }
  942. mpf->mpf_checksum = 0;
  943. mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
  944. printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
  945. }
  946. /*
  947. * only replace the one with mp_INT and
  948. * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
  949. * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
  950. * may need pci=routeirq for all coverage
  951. */
  952. replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
  953. return 0;
  954. }
  955. late_initcall(update_mp_table);