mpparse.c 21 KB

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