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. 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. static void __init MP_bus_info(struct mpc_bus *m)
  63. {
  64. char str[7];
  65. memcpy(str, m->bustype, 6);
  66. str[6] = 0;
  67. if (x86_quirks->mpc_oem_bus_info)
  68. x86_quirks->mpc_oem_bus_info(m, str);
  69. else
  70. apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
  71. #if MAX_MP_BUSSES < 256
  72. if (m->busid >= MAX_MP_BUSSES) {
  73. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  74. " is too large, max. supported is %d\n",
  75. m->busid, str, MAX_MP_BUSSES - 1);
  76. return;
  77. }
  78. #endif
  79. if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
  80. set_bit(m->busid, mp_bus_not_pci);
  81. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  82. mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
  83. #endif
  84. } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
  85. if (x86_quirks->mpc_oem_pci_bus)
  86. x86_quirks->mpc_oem_pci_bus(m);
  87. clear_bit(m->busid, mp_bus_not_pci);
  88. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  89. mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
  90. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
  91. mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
  92. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
  93. mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
  94. #endif
  95. } else
  96. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  97. }
  98. static int bad_ioapic(unsigned long address)
  99. {
  100. if (nr_ioapics >= MAX_IO_APICS) {
  101. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  102. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  103. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  104. }
  105. if (!address) {
  106. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  107. " found in table, skipping!\n");
  108. return 1;
  109. }
  110. return 0;
  111. }
  112. static void __init MP_ioapic_info(struct mpc_ioapic *m)
  113. {
  114. if (!(m->flags & MPC_APIC_USABLE))
  115. return;
  116. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  117. m->apicid, m->apicver, m->apicaddr);
  118. if (bad_ioapic(m->apicaddr))
  119. return;
  120. mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
  121. mp_ioapics[nr_ioapics].apicid = m->apicid;
  122. mp_ioapics[nr_ioapics].type = m->type;
  123. mp_ioapics[nr_ioapics].apicver = m->apicver;
  124. mp_ioapics[nr_ioapics].flags = m->flags;
  125. nr_ioapics++;
  126. }
  127. static void print_MP_intsrc_info(struct mpc_intsrc *m)
  128. {
  129. apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
  130. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  131. m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
  132. m->srcbusirq, m->dstapic, m->dstirq);
  133. }
  134. static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
  135. {
  136. apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
  137. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  138. mp_irq->irqtype, mp_irq->irqflag & 3,
  139. (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
  140. mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
  141. }
  142. static void __init assign_to_mp_irq(struct mpc_intsrc *m,
  143. struct mpc_intsrc *mp_irq)
  144. {
  145. mp_irq->dstapic = m->dstapic;
  146. mp_irq->type = m->type;
  147. mp_irq->irqtype = m->irqtype;
  148. mp_irq->irqflag = m->irqflag;
  149. mp_irq->srcbus = m->srcbus;
  150. mp_irq->srcbusirq = m->srcbusirq;
  151. mp_irq->dstirq = m->dstirq;
  152. }
  153. static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
  154. struct mpc_intsrc *m)
  155. {
  156. m->dstapic = mp_irq->dstapic;
  157. m->type = mp_irq->type;
  158. m->irqtype = mp_irq->irqtype;
  159. m->irqflag = mp_irq->irqflag;
  160. m->srcbus = mp_irq->srcbus;
  161. m->srcbusirq = mp_irq->srcbusirq;
  162. m->dstirq = mp_irq->dstirq;
  163. }
  164. static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
  165. struct mpc_intsrc *m)
  166. {
  167. if (mp_irq->dstapic != m->dstapic)
  168. return 1;
  169. if (mp_irq->type != m->type)
  170. return 2;
  171. if (mp_irq->irqtype != m->irqtype)
  172. return 3;
  173. if (mp_irq->irqflag != m->irqflag)
  174. return 4;
  175. if (mp_irq->srcbus != m->srcbus)
  176. return 5;
  177. if (mp_irq->srcbusirq != m->srcbusirq)
  178. return 6;
  179. if (mp_irq->dstirq != m->dstirq)
  180. return 7;
  181. return 0;
  182. }
  183. static void __init MP_intsrc_info(struct mpc_intsrc *m)
  184. {
  185. int i;
  186. print_MP_intsrc_info(m);
  187. for (i = 0; i < mp_irq_entries; i++) {
  188. if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
  189. return;
  190. }
  191. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  192. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  193. panic("Max # of irq sources exceeded!!\n");
  194. }
  195. #else /* CONFIG_X86_IO_APIC */
  196. static inline void __init MP_bus_info(struct mpc_bus *m) {}
  197. static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
  198. static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
  199. #endif /* CONFIG_X86_IO_APIC */
  200. static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
  201. {
  202. apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
  203. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  204. m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
  205. m->srcbusirq, m->destapic, m->destapiclint);
  206. }
  207. /*
  208. * Read/parse the MPC
  209. */
  210. static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
  211. {
  212. if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
  213. printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
  214. mpc->signature[0], mpc->signature[1],
  215. mpc->signature[2], mpc->signature[3]);
  216. return 0;
  217. }
  218. if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
  219. printk(KERN_ERR "MPTABLE: checksum error!\n");
  220. return 0;
  221. }
  222. if (mpc->spec != 0x01 && mpc->spec != 0x04) {
  223. printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
  224. mpc->spec);
  225. return 0;
  226. }
  227. if (!mpc->lapic) {
  228. printk(KERN_ERR "MPTABLE: null local APIC address!\n");
  229. return 0;
  230. }
  231. memcpy(oem, mpc->oem, 8);
  232. oem[8] = 0;
  233. printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
  234. memcpy(str, mpc->productid, 12);
  235. str[12] = 0;
  236. printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
  237. printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
  238. return 1;
  239. }
  240. static void skip_entry(unsigned char **ptr, int *count, int size)
  241. {
  242. *ptr += size;
  243. *count += size;
  244. }
  245. static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
  246. {
  247. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
  248. "type %x\n", *mpt);
  249. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  250. 1, mpc, mpc->length, 1);
  251. }
  252. static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
  253. {
  254. char str[16];
  255. char oem[10];
  256. int count = sizeof(*mpc);
  257. unsigned char *mpt = ((unsigned char *)mpc) + count;
  258. if (!smp_check_mpc(mpc, oem, str))
  259. return 0;
  260. #ifdef CONFIG_X86_32
  261. generic_mps_oem_check(mpc, oem, str);
  262. #endif
  263. /* save the local APIC address, it might be non-default */
  264. if (!acpi_lapic)
  265. mp_lapic_addr = mpc->lapic;
  266. if (early)
  267. return 1;
  268. if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
  269. struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
  270. x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
  271. }
  272. /*
  273. * Now process the configuration blocks.
  274. */
  275. x86_init.mpparse.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. x86_init.mpparse.mpc_record(1);
  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
  748. check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
  749. {
  750. int ret = 0;
  751. if (!mpc_new_phys || count <= mpc_new_length) {
  752. WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
  753. return -1;
  754. }
  755. return ret;
  756. }
  757. static int __init replace_intsrc_all(struct mpc_table *mpc,
  758. unsigned long mpc_new_phys,
  759. unsigned long mpc_new_length)
  760. {
  761. #ifdef CONFIG_X86_IO_APIC
  762. int i;
  763. #endif
  764. int count = sizeof(*mpc);
  765. int nr_m_spare = 0;
  766. unsigned char *mpt = ((unsigned char *)mpc) + count;
  767. printk(KERN_INFO "mpc_length %x\n", mpc->length);
  768. while (count < mpc->length) {
  769. switch (*mpt) {
  770. case MP_PROCESSOR:
  771. skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
  772. break;
  773. case MP_BUS:
  774. skip_entry(&mpt, &count, sizeof(struct mpc_bus));
  775. break;
  776. case MP_IOAPIC:
  777. skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
  778. break;
  779. case MP_INTSRC:
  780. check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
  781. skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
  782. break;
  783. case MP_LINTSRC:
  784. skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
  785. break;
  786. default:
  787. /* wrong mptable */
  788. smp_dump_mptable(mpc, mpt);
  789. goto out;
  790. }
  791. }
  792. #ifdef CONFIG_X86_IO_APIC
  793. for (i = 0; i < mp_irq_entries; i++) {
  794. if (irq_used[i])
  795. continue;
  796. if (mp_irqs[i].irqtype != mp_INT)
  797. continue;
  798. if (mp_irqs[i].irqflag != 0x0f)
  799. continue;
  800. if (nr_m_spare > 0) {
  801. apic_printk(APIC_VERBOSE, "*NEW* found\n");
  802. nr_m_spare--;
  803. assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
  804. m_spare[nr_m_spare] = NULL;
  805. } else {
  806. struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
  807. count += sizeof(struct mpc_intsrc);
  808. if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
  809. goto out;
  810. assign_to_mpc_intsrc(&mp_irqs[i], m);
  811. mpc->length = count;
  812. mpt += sizeof(struct mpc_intsrc);
  813. }
  814. print_mp_irq_info(&mp_irqs[i]);
  815. }
  816. #endif
  817. out:
  818. /* update checksum */
  819. mpc->checksum = 0;
  820. mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
  821. return 0;
  822. }
  823. int enable_update_mptable;
  824. static int __init update_mptable_setup(char *str)
  825. {
  826. enable_update_mptable = 1;
  827. #ifdef CONFIG_PCI
  828. pci_routeirq = 1;
  829. #endif
  830. return 0;
  831. }
  832. early_param("update_mptable", update_mptable_setup);
  833. static unsigned long __initdata mpc_new_phys;
  834. static unsigned long mpc_new_length __initdata = 4096;
  835. /* alloc_mptable or alloc_mptable=4k */
  836. static int __initdata alloc_mptable;
  837. static int __init parse_alloc_mptable_opt(char *p)
  838. {
  839. enable_update_mptable = 1;
  840. #ifdef CONFIG_PCI
  841. pci_routeirq = 1;
  842. #endif
  843. alloc_mptable = 1;
  844. if (!p)
  845. return 0;
  846. mpc_new_length = memparse(p, &p);
  847. return 0;
  848. }
  849. early_param("alloc_mptable", parse_alloc_mptable_opt);
  850. void __init early_reserve_e820_mpc_new(void)
  851. {
  852. if (enable_update_mptable && alloc_mptable) {
  853. u64 startt = 0;
  854. #ifdef CONFIG_X86_TRAMPOLINE
  855. startt = TRAMPOLINE_BASE;
  856. #endif
  857. mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
  858. }
  859. }
  860. static int __init update_mp_table(void)
  861. {
  862. char str[16];
  863. char oem[10];
  864. struct mpf_intel *mpf;
  865. struct mpc_table *mpc, *mpc_new;
  866. if (!enable_update_mptable)
  867. return 0;
  868. mpf = mpf_found;
  869. if (!mpf)
  870. return 0;
  871. /*
  872. * Now see if we need to go further.
  873. */
  874. if (mpf->feature1 != 0)
  875. return 0;
  876. if (!mpf->physptr)
  877. return 0;
  878. mpc = phys_to_virt(mpf->physptr);
  879. if (!smp_check_mpc(mpc, oem, str))
  880. return 0;
  881. printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
  882. printk(KERN_INFO "physptr: %x\n", mpf->physptr);
  883. if (mpc_new_phys && mpc->length > mpc_new_length) {
  884. mpc_new_phys = 0;
  885. printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
  886. mpc_new_length);
  887. }
  888. if (!mpc_new_phys) {
  889. unsigned char old, new;
  890. /* check if we can change the postion */
  891. mpc->checksum = 0;
  892. old = mpf_checksum((unsigned char *)mpc, mpc->length);
  893. mpc->checksum = 0xff;
  894. new = mpf_checksum((unsigned char *)mpc, mpc->length);
  895. if (old == new) {
  896. printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
  897. return 0;
  898. }
  899. printk(KERN_INFO "use in-positon replacing\n");
  900. } else {
  901. mpf->physptr = mpc_new_phys;
  902. mpc_new = phys_to_virt(mpc_new_phys);
  903. memcpy(mpc_new, mpc, mpc->length);
  904. mpc = mpc_new;
  905. /* check if we can modify that */
  906. if (mpc_new_phys - mpf->physptr) {
  907. struct mpf_intel *mpf_new;
  908. /* steal 16 bytes from [0, 1k) */
  909. printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
  910. mpf_new = phys_to_virt(0x400 - 16);
  911. memcpy(mpf_new, mpf, 16);
  912. mpf = mpf_new;
  913. mpf->physptr = mpc_new_phys;
  914. }
  915. mpf->checksum = 0;
  916. mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
  917. printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
  918. }
  919. /*
  920. * only replace the one with mp_INT and
  921. * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
  922. * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
  923. * may need pci=routeirq for all coverage
  924. */
  925. replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
  926. return 0;
  927. }
  928. late_initcall(update_mp_table);