mpparse.c 25 KB

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