mpparse.c 23 KB

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