mpparse.c 25 KB

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