mpparse.c 21 KB

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