mpparse.c 27 KB

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