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