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