mpparse.c 25 KB

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