mpparse.c 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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@lxorguk.ukuu.org.uk>
  6. * (c) 1998, 1999, 2000, 2009 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/memblock.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/mc146818rtc.h>
  16. #include <linux/bitops.h>
  17. #include <linux/acpi.h>
  18. #include <linux/module.h>
  19. #include <linux/smp.h>
  20. #include <linux/pci.h>
  21. #include <asm/mtrr.h>
  22. #include <asm/mpspec.h>
  23. #include <asm/pgalloc.h>
  24. #include <asm/io_apic.h>
  25. #include <asm/proto.h>
  26. #include <asm/bios_ebda.h>
  27. #include <asm/e820.h>
  28. #include <asm/trampoline.h>
  29. #include <asm/setup.h>
  30. #include <asm/smp.h>
  31. #include <asm/apic.h>
  32. /*
  33. * Checksum an MP configuration block.
  34. */
  35. static int __init mpf_checksum(unsigned char *mp, int len)
  36. {
  37. int sum = 0;
  38. while (len--)
  39. sum += *mp++;
  40. return sum & 0xFF;
  41. }
  42. int __init default_mpc_apic_id(struct mpc_cpu *m)
  43. {
  44. return m->apicid;
  45. }
  46. static void __init MP_processor_info(struct mpc_cpu *m)
  47. {
  48. int apicid;
  49. char *bootup_cpu = "";
  50. if (!(m->cpuflag & CPU_ENABLED)) {
  51. disabled_cpus++;
  52. return;
  53. }
  54. apicid = x86_init.mpparse.mpc_apic_id(m);
  55. if (m->cpuflag & CPU_BOOTPROCESSOR) {
  56. bootup_cpu = " (Bootup-CPU)";
  57. boot_cpu_physical_apicid = m->apicid;
  58. }
  59. printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
  60. generic_processor_info(apicid, m->apicver);
  61. }
  62. #ifdef CONFIG_X86_IO_APIC
  63. void __init default_mpc_oem_bus_info(struct mpc_bus *m, char *str)
  64. {
  65. memcpy(str, m->bustype, 6);
  66. str[6] = 0;
  67. apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
  68. }
  69. static void __init MP_bus_info(struct mpc_bus *m)
  70. {
  71. char str[7];
  72. x86_init.mpparse.mpc_oem_bus_info(m, str);
  73. #if MAX_MP_BUSSES < 256
  74. if (m->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->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->busid, mp_bus_not_pci);
  83. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  84. mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
  85. #endif
  86. } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
  87. if (x86_init.mpparse.mpc_oem_pci_bus)
  88. x86_init.mpparse.mpc_oem_pci_bus(m);
  89. clear_bit(m->busid, mp_bus_not_pci);
  90. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  91. mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
  92. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
  93. mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
  94. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
  95. mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
  96. #endif
  97. } else
  98. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  99. }
  100. static void __init MP_ioapic_info(struct mpc_ioapic *m)
  101. {
  102. if (!(m->flags & MPC_APIC_USABLE))
  103. return;
  104. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  105. m->apicid, m->apicver, m->apicaddr);
  106. mp_register_ioapic(m->apicid, m->apicaddr, gsi_top);
  107. }
  108. static void print_MP_intsrc_info(struct mpc_intsrc *m)
  109. {
  110. apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
  111. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  112. m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
  113. m->srcbusirq, m->dstapic, m->dstirq);
  114. }
  115. static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
  116. {
  117. apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
  118. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  119. mp_irq->irqtype, mp_irq->irqflag & 3,
  120. (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
  121. mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
  122. }
  123. static void __init assign_to_mp_irq(struct mpc_intsrc *m,
  124. struct mpc_intsrc *mp_irq)
  125. {
  126. mp_irq->dstapic = m->dstapic;
  127. mp_irq->type = m->type;
  128. mp_irq->irqtype = m->irqtype;
  129. mp_irq->irqflag = m->irqflag;
  130. mp_irq->srcbus = m->srcbus;
  131. mp_irq->srcbusirq = m->srcbusirq;
  132. mp_irq->dstirq = m->dstirq;
  133. }
  134. static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
  135. struct mpc_intsrc *m)
  136. {
  137. m->dstapic = mp_irq->dstapic;
  138. m->type = mp_irq->type;
  139. m->irqtype = mp_irq->irqtype;
  140. m->irqflag = mp_irq->irqflag;
  141. m->srcbus = mp_irq->srcbus;
  142. m->srcbusirq = mp_irq->srcbusirq;
  143. m->dstirq = mp_irq->dstirq;
  144. }
  145. static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
  146. struct mpc_intsrc *m)
  147. {
  148. if (mp_irq->dstapic != m->dstapic)
  149. return 1;
  150. if (mp_irq->type != m->type)
  151. return 2;
  152. if (mp_irq->irqtype != m->irqtype)
  153. return 3;
  154. if (mp_irq->irqflag != m->irqflag)
  155. return 4;
  156. if (mp_irq->srcbus != m->srcbus)
  157. return 5;
  158. if (mp_irq->srcbusirq != m->srcbusirq)
  159. return 6;
  160. if (mp_irq->dstirq != m->dstirq)
  161. return 7;
  162. return 0;
  163. }
  164. static void __init MP_intsrc_info(struct mpc_intsrc *m)
  165. {
  166. int i;
  167. print_MP_intsrc_info(m);
  168. for (i = 0; i < mp_irq_entries; i++) {
  169. if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
  170. return;
  171. }
  172. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  173. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  174. panic("Max # of irq sources exceeded!!\n");
  175. }
  176. #else /* CONFIG_X86_IO_APIC */
  177. static inline void __init MP_bus_info(struct mpc_bus *m) {}
  178. static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
  179. static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
  180. #endif /* CONFIG_X86_IO_APIC */
  181. static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
  182. {
  183. apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
  184. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  185. m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
  186. m->srcbusirq, m->destapic, m->destapiclint);
  187. }
  188. /*
  189. * Read/parse the MPC
  190. */
  191. static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
  192. {
  193. if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
  194. printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
  195. mpc->signature[0], mpc->signature[1],
  196. mpc->signature[2], mpc->signature[3]);
  197. return 0;
  198. }
  199. if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
  200. printk(KERN_ERR "MPTABLE: checksum error!\n");
  201. return 0;
  202. }
  203. if (mpc->spec != 0x01 && mpc->spec != 0x04) {
  204. printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
  205. mpc->spec);
  206. return 0;
  207. }
  208. if (!mpc->lapic) {
  209. printk(KERN_ERR "MPTABLE: null local APIC address!\n");
  210. return 0;
  211. }
  212. memcpy(oem, mpc->oem, 8);
  213. oem[8] = 0;
  214. printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
  215. memcpy(str, mpc->productid, 12);
  216. str[12] = 0;
  217. printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
  218. printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
  219. return 1;
  220. }
  221. static void skip_entry(unsigned char **ptr, int *count, int size)
  222. {
  223. *ptr += size;
  224. *count += size;
  225. }
  226. static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
  227. {
  228. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
  229. "type %x\n", *mpt);
  230. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  231. 1, mpc, mpc->length, 1);
  232. }
  233. void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { }
  234. static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
  235. {
  236. char str[16];
  237. char oem[10];
  238. int count = sizeof(*mpc);
  239. unsigned char *mpt = ((unsigned char *)mpc) + count;
  240. if (!smp_check_mpc(mpc, oem, str))
  241. return 0;
  242. #ifdef CONFIG_X86_32
  243. generic_mps_oem_check(mpc, oem, str);
  244. #endif
  245. /* Initialize the lapic mapping */
  246. if (!acpi_lapic)
  247. register_lapic_address(mpc->lapic);
  248. if (early)
  249. return 1;
  250. if (mpc->oemptr)
  251. x86_init.mpparse.smp_read_mpc_oem(mpc);
  252. /*
  253. * Now process the configuration blocks.
  254. */
  255. x86_init.mpparse.mpc_record(0);
  256. while (count < mpc->length) {
  257. switch (*mpt) {
  258. case MP_PROCESSOR:
  259. /* ACPI may have already provided this data */
  260. if (!acpi_lapic)
  261. MP_processor_info((struct mpc_cpu *)mpt);
  262. skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
  263. break;
  264. case MP_BUS:
  265. MP_bus_info((struct mpc_bus *)mpt);
  266. skip_entry(&mpt, &count, sizeof(struct mpc_bus));
  267. break;
  268. case MP_IOAPIC:
  269. MP_ioapic_info((struct mpc_ioapic *)mpt);
  270. skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
  271. break;
  272. case MP_INTSRC:
  273. MP_intsrc_info((struct mpc_intsrc *)mpt);
  274. skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
  275. break;
  276. case MP_LINTSRC:
  277. MP_lintsrc_info((struct mpc_lintsrc *)mpt);
  278. skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
  279. break;
  280. default:
  281. /* wrong mptable */
  282. smp_dump_mptable(mpc, mpt);
  283. count = mpc->length;
  284. break;
  285. }
  286. x86_init.mpparse.mpc_record(1);
  287. }
  288. if (!num_processors)
  289. printk(KERN_ERR "MPTABLE: no processors registered!\n");
  290. return num_processors;
  291. }
  292. #ifdef CONFIG_X86_IO_APIC
  293. static int __init ELCR_trigger(unsigned int irq)
  294. {
  295. unsigned int port;
  296. port = 0x4d0 + (irq >> 3);
  297. return (inb(port) >> (irq & 7)) & 1;
  298. }
  299. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  300. {
  301. struct mpc_intsrc intsrc;
  302. int i;
  303. int ELCR_fallback = 0;
  304. intsrc.type = MP_INTSRC;
  305. intsrc.irqflag = 0; /* conforming */
  306. intsrc.srcbus = 0;
  307. intsrc.dstapic = mp_ioapics[0].apicid;
  308. intsrc.irqtype = mp_INT;
  309. /*
  310. * If true, we have an ISA/PCI system with no IRQ entries
  311. * in the MP table. To prevent the PCI interrupts from being set up
  312. * incorrectly, we try to use the ELCR. The sanity check to see if
  313. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  314. * never be level sensitive, so we simply see if the ELCR agrees.
  315. * If it does, we assume it's valid.
  316. */
  317. if (mpc_default_type == 5) {
  318. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
  319. "falling back to ELCR\n");
  320. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
  321. ELCR_trigger(13))
  322. printk(KERN_ERR "ELCR contains invalid data... "
  323. "not using ELCR\n");
  324. else {
  325. printk(KERN_INFO
  326. "Using ELCR to identify PCI interrupts\n");
  327. ELCR_fallback = 1;
  328. }
  329. }
  330. for (i = 0; i < 16; i++) {
  331. switch (mpc_default_type) {
  332. case 2:
  333. if (i == 0 || i == 13)
  334. continue; /* IRQ0 & IRQ13 not connected */
  335. /* fall through */
  336. default:
  337. if (i == 2)
  338. continue; /* IRQ2 is never connected */
  339. }
  340. if (ELCR_fallback) {
  341. /*
  342. * If the ELCR indicates a level-sensitive interrupt, we
  343. * copy that information over to the MP table in the
  344. * irqflag field (level sensitive, active high polarity).
  345. */
  346. if (ELCR_trigger(i))
  347. intsrc.irqflag = 13;
  348. else
  349. intsrc.irqflag = 0;
  350. }
  351. intsrc.srcbusirq = i;
  352. intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  353. MP_intsrc_info(&intsrc);
  354. }
  355. intsrc.irqtype = mp_ExtINT;
  356. intsrc.srcbusirq = 0;
  357. intsrc.dstirq = 0; /* 8259A to INTIN0 */
  358. MP_intsrc_info(&intsrc);
  359. }
  360. static void __init construct_ioapic_table(int mpc_default_type)
  361. {
  362. struct mpc_ioapic ioapic;
  363. struct mpc_bus bus;
  364. bus.type = MP_BUS;
  365. bus.busid = 0;
  366. switch (mpc_default_type) {
  367. default:
  368. printk(KERN_ERR "???\nUnknown standard configuration %d\n",
  369. mpc_default_type);
  370. /* fall through */
  371. case 1:
  372. case 5:
  373. memcpy(bus.bustype, "ISA ", 6);
  374. break;
  375. case 2:
  376. case 6:
  377. case 3:
  378. memcpy(bus.bustype, "EISA ", 6);
  379. break;
  380. case 4:
  381. case 7:
  382. memcpy(bus.bustype, "MCA ", 6);
  383. }
  384. MP_bus_info(&bus);
  385. if (mpc_default_type > 4) {
  386. bus.busid = 1;
  387. memcpy(bus.bustype, "PCI ", 6);
  388. MP_bus_info(&bus);
  389. }
  390. ioapic.type = MP_IOAPIC;
  391. ioapic.apicid = 2;
  392. ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  393. ioapic.flags = MPC_APIC_USABLE;
  394. ioapic.apicaddr = IO_APIC_DEFAULT_PHYS_BASE;
  395. MP_ioapic_info(&ioapic);
  396. /*
  397. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  398. */
  399. construct_default_ioirq_mptable(mpc_default_type);
  400. }
  401. #else
  402. static inline void __init construct_ioapic_table(int mpc_default_type) { }
  403. #endif
  404. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  405. {
  406. struct mpc_cpu processor;
  407. struct mpc_lintsrc lintsrc;
  408. int linttypes[2] = { mp_ExtINT, mp_NMI };
  409. int i;
  410. /*
  411. * local APIC has default address
  412. */
  413. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  414. /*
  415. * 2 CPUs, numbered 0 & 1.
  416. */
  417. processor.type = MP_PROCESSOR;
  418. /* Either an integrated APIC or a discrete 82489DX. */
  419. processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  420. processor.cpuflag = CPU_ENABLED;
  421. processor.cpufeature = (boot_cpu_data.x86 << 8) |
  422. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  423. processor.featureflag = boot_cpu_data.x86_capability[0];
  424. processor.reserved[0] = 0;
  425. processor.reserved[1] = 0;
  426. for (i = 0; i < 2; i++) {
  427. processor.apicid = i;
  428. MP_processor_info(&processor);
  429. }
  430. construct_ioapic_table(mpc_default_type);
  431. lintsrc.type = MP_LINTSRC;
  432. lintsrc.irqflag = 0; /* conforming */
  433. lintsrc.srcbusid = 0;
  434. lintsrc.srcbusirq = 0;
  435. lintsrc.destapic = MP_APIC_ALL;
  436. for (i = 0; i < 2; i++) {
  437. lintsrc.irqtype = linttypes[i];
  438. lintsrc.destapiclint = i;
  439. MP_lintsrc_info(&lintsrc);
  440. }
  441. }
  442. static struct mpf_intel *mpf_found;
  443. static unsigned long __init get_mpc_size(unsigned long physptr)
  444. {
  445. struct mpc_table *mpc;
  446. unsigned long size;
  447. mpc = early_ioremap(physptr, PAGE_SIZE);
  448. size = mpc->length;
  449. early_iounmap(mpc, PAGE_SIZE);
  450. apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
  451. return size;
  452. }
  453. static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
  454. {
  455. struct mpc_table *mpc;
  456. unsigned long size;
  457. size = get_mpc_size(mpf->physptr);
  458. mpc = early_ioremap(mpf->physptr, size);
  459. /*
  460. * Read the physical hardware table. Anything here will
  461. * override the defaults.
  462. */
  463. if (!smp_read_mpc(mpc, early)) {
  464. #ifdef CONFIG_X86_LOCAL_APIC
  465. smp_found_config = 0;
  466. #endif
  467. printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
  468. "... disabling SMP support. (tell your hw vendor)\n");
  469. early_iounmap(mpc, size);
  470. return -1;
  471. }
  472. early_iounmap(mpc, size);
  473. if (early)
  474. return -1;
  475. #ifdef CONFIG_X86_IO_APIC
  476. /*
  477. * If there are no explicit MP IRQ entries, then we are
  478. * broken. We set up most of the low 16 IO-APIC pins to
  479. * ISA defaults and hope it will work.
  480. */
  481. if (!mp_irq_entries) {
  482. struct mpc_bus bus;
  483. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  484. "using default mptable. (tell your hw vendor)\n");
  485. bus.type = MP_BUS;
  486. bus.busid = 0;
  487. memcpy(bus.bustype, "ISA ", 6);
  488. MP_bus_info(&bus);
  489. construct_default_ioirq_mptable(0);
  490. }
  491. #endif
  492. return 0;
  493. }
  494. /*
  495. * Scan the memory blocks for an SMP configuration block.
  496. */
  497. void __init default_get_smp_config(unsigned int early)
  498. {
  499. struct mpf_intel *mpf = mpf_found;
  500. if (!mpf)
  501. return;
  502. if (acpi_lapic && early)
  503. return;
  504. /*
  505. * MPS doesn't support hyperthreading, aka only have
  506. * thread 0 apic id in MPS table
  507. */
  508. if (acpi_lapic && acpi_ioapic)
  509. return;
  510. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  511. mpf->specification);
  512. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
  513. if (mpf->feature2 & (1 << 7)) {
  514. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  515. pic_mode = 1;
  516. } else {
  517. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  518. pic_mode = 0;
  519. }
  520. #endif
  521. /*
  522. * Now see if we need to read further.
  523. */
  524. if (mpf->feature1 != 0) {
  525. if (early) {
  526. /*
  527. * local APIC has default address
  528. */
  529. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  530. return;
  531. }
  532. printk(KERN_INFO "Default MP configuration #%d\n",
  533. mpf->feature1);
  534. construct_default_ISA_mptable(mpf->feature1);
  535. } else if (mpf->physptr) {
  536. if (check_physptr(mpf, early))
  537. return;
  538. } else
  539. BUG();
  540. if (!early)
  541. printk(KERN_INFO "Processors: %d\n", num_processors);
  542. /*
  543. * Only use the first configuration found.
  544. */
  545. }
  546. static void __init smp_reserve_memory(struct mpf_intel *mpf)
  547. {
  548. unsigned long size = get_mpc_size(mpf->physptr);
  549. memblock_x86_reserve_range(mpf->physptr, mpf->physptr+size, "* MP-table mpc");
  550. }
  551. static int __init smp_scan_config(unsigned long base, unsigned long length)
  552. {
  553. unsigned int *bp = phys_to_virt(base);
  554. struct mpf_intel *mpf;
  555. unsigned long mem;
  556. apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
  557. bp, length);
  558. BUILD_BUG_ON(sizeof(*mpf) != 16);
  559. while (length > 0) {
  560. mpf = (struct mpf_intel *)bp;
  561. if ((*bp == SMP_MAGIC_IDENT) &&
  562. (mpf->length == 1) &&
  563. !mpf_checksum((unsigned char *)bp, 16) &&
  564. ((mpf->specification == 1)
  565. || (mpf->specification == 4))) {
  566. #ifdef CONFIG_X86_LOCAL_APIC
  567. smp_found_config = 1;
  568. #endif
  569. mpf_found = mpf;
  570. printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
  571. mpf, (u64)virt_to_phys(mpf));
  572. mem = virt_to_phys(mpf);
  573. memblock_x86_reserve_range(mem, mem + sizeof(*mpf), "* MP-table mpf");
  574. if (mpf->physptr)
  575. smp_reserve_memory(mpf);
  576. return 1;
  577. }
  578. bp += 4;
  579. length -= 16;
  580. }
  581. return 0;
  582. }
  583. void __init default_find_smp_config(void)
  584. {
  585. unsigned int address;
  586. /*
  587. * FIXME: Linux assumes you have 640K of base ram..
  588. * this continues the error...
  589. *
  590. * 1) Scan the bottom 1K for a signature
  591. * 2) Scan the top 1K of base RAM
  592. * 3) Scan the 64K of bios
  593. */
  594. if (smp_scan_config(0x0, 0x400) ||
  595. smp_scan_config(639 * 0x400, 0x400) ||
  596. smp_scan_config(0xF0000, 0x10000))
  597. return;
  598. /*
  599. * If it is an SMP machine we should know now, unless the
  600. * configuration is in an EISA/MCA bus machine with an
  601. * extended bios data area.
  602. *
  603. * there is a real-mode segmented pointer pointing to the
  604. * 4K EBDA area at 0x40E, calculate and scan it here.
  605. *
  606. * NOTE! There are Linux loaders that will corrupt the EBDA
  607. * area, and as such this kind of SMP config may be less
  608. * trustworthy, simply because the SMP table may have been
  609. * stomped on during early boot. These loaders are buggy and
  610. * should be fixed.
  611. *
  612. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  613. */
  614. address = get_bios_ebda();
  615. if (address)
  616. smp_scan_config(address, 0x400);
  617. }
  618. #ifdef CONFIG_X86_IO_APIC
  619. static u8 __initdata irq_used[MAX_IRQ_SOURCES];
  620. static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
  621. {
  622. int i;
  623. if (m->irqtype != mp_INT)
  624. return 0;
  625. if (m->irqflag != 0x0f)
  626. return 0;
  627. /* not legacy */
  628. for (i = 0; i < mp_irq_entries; i++) {
  629. if (mp_irqs[i].irqtype != mp_INT)
  630. continue;
  631. if (mp_irqs[i].irqflag != 0x0f)
  632. continue;
  633. if (mp_irqs[i].srcbus != m->srcbus)
  634. continue;
  635. if (mp_irqs[i].srcbusirq != m->srcbusirq)
  636. continue;
  637. if (irq_used[i]) {
  638. /* already claimed */
  639. return -2;
  640. }
  641. irq_used[i] = 1;
  642. return i;
  643. }
  644. /* not found */
  645. return -1;
  646. }
  647. #define SPARE_SLOT_NUM 20
  648. static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
  649. static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
  650. {
  651. int i;
  652. apic_printk(APIC_VERBOSE, "OLD ");
  653. print_MP_intsrc_info(m);
  654. i = get_MP_intsrc_index(m);
  655. if (i > 0) {
  656. assign_to_mpc_intsrc(&mp_irqs[i], m);
  657. apic_printk(APIC_VERBOSE, "NEW ");
  658. print_mp_irq_info(&mp_irqs[i]);
  659. return;
  660. }
  661. if (!i) {
  662. /* legacy, do nothing */
  663. return;
  664. }
  665. if (*nr_m_spare < SPARE_SLOT_NUM) {
  666. /*
  667. * not found (-1), or duplicated (-2) are invalid entries,
  668. * we need to use the slot later
  669. */
  670. m_spare[*nr_m_spare] = m;
  671. *nr_m_spare += 1;
  672. }
  673. }
  674. #else /* CONFIG_X86_IO_APIC */
  675. static
  676. inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
  677. #endif /* CONFIG_X86_IO_APIC */
  678. static int
  679. check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
  680. {
  681. int ret = 0;
  682. if (!mpc_new_phys || count <= mpc_new_length) {
  683. WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
  684. return -1;
  685. }
  686. return ret;
  687. }
  688. static int __init replace_intsrc_all(struct mpc_table *mpc,
  689. unsigned long mpc_new_phys,
  690. unsigned long mpc_new_length)
  691. {
  692. #ifdef CONFIG_X86_IO_APIC
  693. int i;
  694. #endif
  695. int count = sizeof(*mpc);
  696. int nr_m_spare = 0;
  697. unsigned char *mpt = ((unsigned char *)mpc) + count;
  698. printk(KERN_INFO "mpc_length %x\n", mpc->length);
  699. while (count < mpc->length) {
  700. switch (*mpt) {
  701. case MP_PROCESSOR:
  702. skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
  703. break;
  704. case MP_BUS:
  705. skip_entry(&mpt, &count, sizeof(struct mpc_bus));
  706. break;
  707. case MP_IOAPIC:
  708. skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
  709. break;
  710. case MP_INTSRC:
  711. check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
  712. skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
  713. break;
  714. case MP_LINTSRC:
  715. skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
  716. break;
  717. default:
  718. /* wrong mptable */
  719. smp_dump_mptable(mpc, mpt);
  720. goto out;
  721. }
  722. }
  723. #ifdef CONFIG_X86_IO_APIC
  724. for (i = 0; i < mp_irq_entries; i++) {
  725. if (irq_used[i])
  726. continue;
  727. if (mp_irqs[i].irqtype != mp_INT)
  728. continue;
  729. if (mp_irqs[i].irqflag != 0x0f)
  730. continue;
  731. if (nr_m_spare > 0) {
  732. apic_printk(APIC_VERBOSE, "*NEW* found\n");
  733. nr_m_spare--;
  734. assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
  735. m_spare[nr_m_spare] = NULL;
  736. } else {
  737. struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
  738. count += sizeof(struct mpc_intsrc);
  739. if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
  740. goto out;
  741. assign_to_mpc_intsrc(&mp_irqs[i], m);
  742. mpc->length = count;
  743. mpt += sizeof(struct mpc_intsrc);
  744. }
  745. print_mp_irq_info(&mp_irqs[i]);
  746. }
  747. #endif
  748. out:
  749. /* update checksum */
  750. mpc->checksum = 0;
  751. mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
  752. return 0;
  753. }
  754. int enable_update_mptable;
  755. static int __init update_mptable_setup(char *str)
  756. {
  757. enable_update_mptable = 1;
  758. #ifdef CONFIG_PCI
  759. pci_routeirq = 1;
  760. #endif
  761. return 0;
  762. }
  763. early_param("update_mptable", update_mptable_setup);
  764. static unsigned long __initdata mpc_new_phys;
  765. static unsigned long mpc_new_length __initdata = 4096;
  766. /* alloc_mptable or alloc_mptable=4k */
  767. static int __initdata alloc_mptable;
  768. static int __init parse_alloc_mptable_opt(char *p)
  769. {
  770. enable_update_mptable = 1;
  771. #ifdef CONFIG_PCI
  772. pci_routeirq = 1;
  773. #endif
  774. alloc_mptable = 1;
  775. if (!p)
  776. return 0;
  777. mpc_new_length = memparse(p, &p);
  778. return 0;
  779. }
  780. early_param("alloc_mptable", parse_alloc_mptable_opt);
  781. void __init early_reserve_e820_mpc_new(void)
  782. {
  783. if (enable_update_mptable && alloc_mptable) {
  784. u64 startt = 0;
  785. mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
  786. }
  787. }
  788. static int __init update_mp_table(void)
  789. {
  790. char str[16];
  791. char oem[10];
  792. struct mpf_intel *mpf;
  793. struct mpc_table *mpc, *mpc_new;
  794. if (!enable_update_mptable)
  795. return 0;
  796. mpf = mpf_found;
  797. if (!mpf)
  798. return 0;
  799. /*
  800. * Now see if we need to go further.
  801. */
  802. if (mpf->feature1 != 0)
  803. return 0;
  804. if (!mpf->physptr)
  805. return 0;
  806. mpc = phys_to_virt(mpf->physptr);
  807. if (!smp_check_mpc(mpc, oem, str))
  808. return 0;
  809. printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
  810. printk(KERN_INFO "physptr: %x\n", mpf->physptr);
  811. if (mpc_new_phys && mpc->length > mpc_new_length) {
  812. mpc_new_phys = 0;
  813. printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
  814. mpc_new_length);
  815. }
  816. if (!mpc_new_phys) {
  817. unsigned char old, new;
  818. /* check if we can change the postion */
  819. mpc->checksum = 0;
  820. old = mpf_checksum((unsigned char *)mpc, mpc->length);
  821. mpc->checksum = 0xff;
  822. new = mpf_checksum((unsigned char *)mpc, mpc->length);
  823. if (old == new) {
  824. printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
  825. return 0;
  826. }
  827. printk(KERN_INFO "use in-positon replacing\n");
  828. } else {
  829. mpf->physptr = mpc_new_phys;
  830. mpc_new = phys_to_virt(mpc_new_phys);
  831. memcpy(mpc_new, mpc, mpc->length);
  832. mpc = mpc_new;
  833. /* check if we can modify that */
  834. if (mpc_new_phys - mpf->physptr) {
  835. struct mpf_intel *mpf_new;
  836. /* steal 16 bytes from [0, 1k) */
  837. printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
  838. mpf_new = phys_to_virt(0x400 - 16);
  839. memcpy(mpf_new, mpf, 16);
  840. mpf = mpf_new;
  841. mpf->physptr = mpc_new_phys;
  842. }
  843. mpf->checksum = 0;
  844. mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
  845. printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
  846. }
  847. /*
  848. * only replace the one with mp_INT and
  849. * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
  850. * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
  851. * may need pci=routeirq for all coverage
  852. */
  853. replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
  854. return 0;
  855. }
  856. late_initcall(update_mp_table);