mpparse.c 22 KB

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