mpparse.c 24 KB

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