mpparse.c 21 KB

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