mpparse.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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 <mach_apic.h>
  27. #ifdef CONFIG_X86_32
  28. #include <mach_apicdef.h>
  29. #include <mach_mpparse.h>
  30. #endif
  31. /* Have we found an MP table */
  32. int smp_found_config;
  33. /*
  34. * Various Linux-internal data structures created from the
  35. * MP-table.
  36. */
  37. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  38. int mp_bus_id_to_type[MAX_MP_BUSSES];
  39. #endif
  40. DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
  41. int mp_bus_id_to_pci_bus[MAX_MP_BUSSES] = {[0 ... MAX_MP_BUSSES - 1] = -1 };
  42. static int mp_current_pci_id;
  43. int pic_mode;
  44. /*
  45. * Intel MP BIOS table parsing routines:
  46. */
  47. /*
  48. * Checksum an MP configuration block.
  49. */
  50. static int __init mpf_checksum(unsigned char *mp, int len)
  51. {
  52. int sum = 0;
  53. while (len--)
  54. sum += *mp++;
  55. return sum & 0xFF;
  56. }
  57. #ifdef CONFIG_X86_NUMAQ
  58. /*
  59. * Have to match translation table entries to main table entries by counter
  60. * hence the mpc_record variable .... can't see a less disgusting way of
  61. * doing this ....
  62. */
  63. static int mpc_record;
  64. static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
  65. __cpuinitdata;
  66. #endif
  67. static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
  68. {
  69. int apicid;
  70. char *bootup_cpu = "";
  71. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  72. disabled_cpus++;
  73. return;
  74. }
  75. #ifdef CONFIG_X86_NUMAQ
  76. apicid = mpc_apic_id(m, translation_table[mpc_record]);
  77. #else
  78. apicid = m->mpc_apicid;
  79. #endif
  80. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  81. bootup_cpu = " (Bootup-CPU)";
  82. boot_cpu_physical_apicid = m->mpc_apicid;
  83. }
  84. printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
  85. generic_processor_info(apicid, m->mpc_apicver);
  86. }
  87. static void __init MP_bus_info(struct mpc_config_bus *m)
  88. {
  89. char str[7];
  90. memcpy(str, m->mpc_bustype, 6);
  91. str[6] = 0;
  92. #ifdef CONFIG_X86_NUMAQ
  93. mpc_oem_bus_info(m, str, translation_table[mpc_record]);
  94. #else
  95. Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
  96. #endif
  97. #if MAX_MP_BUSSES < 256
  98. if (m->mpc_busid >= MAX_MP_BUSSES) {
  99. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  100. " is too large, max. supported is %d\n",
  101. m->mpc_busid, str, MAX_MP_BUSSES - 1);
  102. return;
  103. }
  104. #endif
  105. if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
  106. set_bit(m->mpc_busid, mp_bus_not_pci);
  107. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  108. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
  109. #endif
  110. } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
  111. #ifdef CONFIG_X86_NUMAQ
  112. mpc_oem_pci_bus(m, translation_table[mpc_record]);
  113. #endif
  114. clear_bit(m->mpc_busid, mp_bus_not_pci);
  115. mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
  116. mp_current_pci_id++;
  117. #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
  118. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
  119. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
  120. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
  121. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
  122. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
  123. #endif
  124. } else
  125. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  126. }
  127. #ifdef CONFIG_X86_IO_APIC
  128. static int bad_ioapic(unsigned long address)
  129. {
  130. if (nr_ioapics >= MAX_IO_APICS) {
  131. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  132. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  133. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  134. }
  135. if (!address) {
  136. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  137. " found in table, skipping!\n");
  138. return 1;
  139. }
  140. return 0;
  141. }
  142. static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
  143. {
  144. if (!(m->mpc_flags & MPC_APIC_USABLE))
  145. return;
  146. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
  147. m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
  148. if (bad_ioapic(m->mpc_apicaddr))
  149. return;
  150. mp_ioapics[nr_ioapics] = *m;
  151. nr_ioapics++;
  152. }
  153. static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
  154. {
  155. mp_irqs[mp_irq_entries] = *m;
  156. Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
  157. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  158. m->mpc_irqtype, m->mpc_irqflag & 3,
  159. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  160. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  161. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  162. panic("Max # of irq sources exceeded!!\n");
  163. }
  164. #endif
  165. static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
  166. {
  167. Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
  168. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  169. m->mpc_irqtype, m->mpc_irqflag & 3,
  170. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
  171. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  172. }
  173. #ifdef CONFIG_X86_NUMAQ
  174. static void __init MP_translation_info(struct mpc_config_translation *m)
  175. {
  176. printk(KERN_INFO
  177. "Translation: record %d, type %d, quad %d, global %d, local %d\n",
  178. mpc_record, m->trans_type, m->trans_quad, m->trans_global,
  179. m->trans_local);
  180. if (mpc_record >= MAX_MPC_ENTRY)
  181. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  182. else
  183. translation_table[mpc_record] = m; /* stash this for later */
  184. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  185. node_set_online(m->trans_quad);
  186. }
  187. /*
  188. * Read/parse the MPC oem tables
  189. */
  190. static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
  191. unsigned short oemsize)
  192. {
  193. int count = sizeof(*oemtable); /* the header size */
  194. unsigned char *oemptr = ((unsigned char *)oemtable) + count;
  195. mpc_record = 0;
  196. printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
  197. oemtable);
  198. if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
  199. printk(KERN_WARNING
  200. "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  201. oemtable->oem_signature[0], oemtable->oem_signature[1],
  202. oemtable->oem_signature[2], oemtable->oem_signature[3]);
  203. return;
  204. }
  205. if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
  206. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  207. return;
  208. }
  209. while (count < oemtable->oem_length) {
  210. switch (*oemptr) {
  211. case MP_TRANSLATION:
  212. {
  213. struct mpc_config_translation *m =
  214. (struct mpc_config_translation *)oemptr;
  215. MP_translation_info(m);
  216. oemptr += sizeof(*m);
  217. count += sizeof(*m);
  218. ++mpc_record;
  219. break;
  220. }
  221. default:
  222. {
  223. printk(KERN_WARNING
  224. "Unrecognised OEM table entry type! - %d\n",
  225. (int)*oemptr);
  226. return;
  227. }
  228. }
  229. }
  230. }
  231. static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
  232. char *productid)
  233. {
  234. if (strncmp(oem, "IBM NUMA", 8))
  235. printk("Warning! May not be a NUMA-Q system!\n");
  236. if (mpc->mpc_oemptr)
  237. smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
  238. mpc->mpc_oemsize);
  239. }
  240. #endif /* CONFIG_X86_NUMAQ */
  241. /*
  242. * Read/parse the MPC
  243. */
  244. static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
  245. {
  246. char str[16];
  247. char oem[10];
  248. int count = sizeof(*mpc);
  249. unsigned char *mpt = ((unsigned char *)mpc) + count;
  250. if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
  251. printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
  252. mpc->mpc_signature[0], mpc->mpc_signature[1],
  253. mpc->mpc_signature[2], mpc->mpc_signature[3]);
  254. return 0;
  255. }
  256. if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
  257. printk(KERN_ERR "MPTABLE: checksum error!\n");
  258. return 0;
  259. }
  260. if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
  261. printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
  262. mpc->mpc_spec);
  263. return 0;
  264. }
  265. if (!mpc->mpc_lapic) {
  266. printk(KERN_ERR "MPTABLE: null local APIC address!\n");
  267. return 0;
  268. }
  269. memcpy(oem, mpc->mpc_oem, 8);
  270. oem[8] = 0;
  271. printk(KERN_INFO "MPTABLE: OEM ID: %s ", oem);
  272. memcpy(str, mpc->mpc_productid, 12);
  273. str[12] = 0;
  274. printk("Product ID: %s ", str);
  275. #ifdef CONFIG_X86_32
  276. mps_oem_check(mpc, oem, str);
  277. #endif
  278. printk(KERN_INFO "MPTABLE: Product ID: %s ", str);
  279. printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
  280. /* save the local APIC address, it might be non-default */
  281. if (!acpi_lapic)
  282. mp_lapic_addr = mpc->mpc_lapic;
  283. if (early)
  284. return 1;
  285. /*
  286. * Now process the configuration blocks.
  287. */
  288. #ifdef CONFIG_X86_NUMAQ
  289. mpc_record = 0;
  290. #endif
  291. while (count < mpc->mpc_length) {
  292. switch (*mpt) {
  293. case MP_PROCESSOR:
  294. {
  295. struct mpc_config_processor *m =
  296. (struct mpc_config_processor *)mpt;
  297. /* ACPI may have already provided this data */
  298. if (!acpi_lapic)
  299. MP_processor_info(m);
  300. mpt += sizeof(*m);
  301. count += sizeof(*m);
  302. break;
  303. }
  304. case MP_BUS:
  305. {
  306. struct mpc_config_bus *m =
  307. (struct mpc_config_bus *)mpt;
  308. MP_bus_info(m);
  309. mpt += sizeof(*m);
  310. count += sizeof(*m);
  311. break;
  312. }
  313. case MP_IOAPIC:
  314. {
  315. #ifdef CONFIG_X86_IO_APIC
  316. struct mpc_config_ioapic *m =
  317. (struct mpc_config_ioapic *)mpt;
  318. MP_ioapic_info(m);
  319. #endif
  320. mpt += sizeof(struct mpc_config_ioapic);
  321. count += sizeof(struct mpc_config_ioapic);
  322. break;
  323. }
  324. case MP_INTSRC:
  325. {
  326. #ifdef CONFIG_X86_IO_APIC
  327. struct mpc_config_intsrc *m =
  328. (struct mpc_config_intsrc *)mpt;
  329. MP_intsrc_info(m);
  330. #endif
  331. mpt += sizeof(struct mpc_config_intsrc);
  332. count += sizeof(struct mpc_config_intsrc);
  333. break;
  334. }
  335. case MP_LINTSRC:
  336. {
  337. struct mpc_config_lintsrc *m =
  338. (struct mpc_config_lintsrc *)mpt;
  339. MP_lintsrc_info(m);
  340. mpt += sizeof(*m);
  341. count += sizeof(*m);
  342. break;
  343. }
  344. default:
  345. /* wrong mptable */
  346. printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
  347. printk(KERN_ERR "type %x\n", *mpt);
  348. print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
  349. 1, mpc, mpc->mpc_length, 1);
  350. count = mpc->mpc_length;
  351. break;
  352. }
  353. #ifdef CONFIG_X86_NUMAQ
  354. ++mpc_record;
  355. #endif
  356. }
  357. setup_apic_routing();
  358. if (!num_processors)
  359. printk(KERN_ERR "MPTABLE: no processors registered!\n");
  360. return num_processors;
  361. }
  362. #ifdef CONFIG_X86_IO_APIC
  363. static int __init ELCR_trigger(unsigned int irq)
  364. {
  365. unsigned int port;
  366. port = 0x4d0 + (irq >> 3);
  367. return (inb(port) >> (irq & 7)) & 1;
  368. }
  369. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  370. {
  371. struct mpc_config_intsrc intsrc;
  372. int i;
  373. int ELCR_fallback = 0;
  374. intsrc.mpc_type = MP_INTSRC;
  375. intsrc.mpc_irqflag = 0; /* conforming */
  376. intsrc.mpc_srcbus = 0;
  377. intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
  378. intsrc.mpc_irqtype = mp_INT;
  379. /*
  380. * If true, we have an ISA/PCI system with no IRQ entries
  381. * in the MP table. To prevent the PCI interrupts from being set up
  382. * incorrectly, we try to use the ELCR. The sanity check to see if
  383. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  384. * never be level sensitive, so we simply see if the ELCR agrees.
  385. * If it does, we assume it's valid.
  386. */
  387. if (mpc_default_type == 5) {
  388. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
  389. "falling back to ELCR\n");
  390. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
  391. ELCR_trigger(13))
  392. printk(KERN_ERR "ELCR contains invalid data... "
  393. "not using ELCR\n");
  394. else {
  395. printk(KERN_INFO
  396. "Using ELCR to identify PCI interrupts\n");
  397. ELCR_fallback = 1;
  398. }
  399. }
  400. for (i = 0; i < 16; i++) {
  401. switch (mpc_default_type) {
  402. case 2:
  403. if (i == 0 || i == 13)
  404. continue; /* IRQ0 & IRQ13 not connected */
  405. /* fall through */
  406. default:
  407. if (i == 2)
  408. continue; /* IRQ2 is never connected */
  409. }
  410. if (ELCR_fallback) {
  411. /*
  412. * If the ELCR indicates a level-sensitive interrupt, we
  413. * copy that information over to the MP table in the
  414. * irqflag field (level sensitive, active high polarity).
  415. */
  416. if (ELCR_trigger(i))
  417. intsrc.mpc_irqflag = 13;
  418. else
  419. intsrc.mpc_irqflag = 0;
  420. }
  421. intsrc.mpc_srcbusirq = i;
  422. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  423. MP_intsrc_info(&intsrc);
  424. }
  425. intsrc.mpc_irqtype = mp_ExtINT;
  426. intsrc.mpc_srcbusirq = 0;
  427. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  428. MP_intsrc_info(&intsrc);
  429. }
  430. #endif
  431. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  432. {
  433. struct mpc_config_processor processor;
  434. struct mpc_config_bus bus;
  435. #ifdef CONFIG_X86_IO_APIC
  436. struct mpc_config_ioapic ioapic;
  437. #endif
  438. struct mpc_config_lintsrc lintsrc;
  439. int linttypes[2] = { mp_ExtINT, mp_NMI };
  440. int i;
  441. /*
  442. * local APIC has default address
  443. */
  444. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  445. /*
  446. * 2 CPUs, numbered 0 & 1.
  447. */
  448. processor.mpc_type = MP_PROCESSOR;
  449. /* Either an integrated APIC or a discrete 82489DX. */
  450. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  451. processor.mpc_cpuflag = CPU_ENABLED;
  452. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  453. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  454. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  455. processor.mpc_reserved[0] = 0;
  456. processor.mpc_reserved[1] = 0;
  457. for (i = 0; i < 2; i++) {
  458. processor.mpc_apicid = i;
  459. MP_processor_info(&processor);
  460. }
  461. bus.mpc_type = MP_BUS;
  462. bus.mpc_busid = 0;
  463. switch (mpc_default_type) {
  464. default:
  465. printk(KERN_ERR "???\nUnknown standard configuration %d\n",
  466. mpc_default_type);
  467. /* fall through */
  468. case 1:
  469. case 5:
  470. memcpy(bus.mpc_bustype, "ISA ", 6);
  471. break;
  472. case 2:
  473. case 6:
  474. case 3:
  475. memcpy(bus.mpc_bustype, "EISA ", 6);
  476. break;
  477. case 4:
  478. case 7:
  479. memcpy(bus.mpc_bustype, "MCA ", 6);
  480. }
  481. MP_bus_info(&bus);
  482. if (mpc_default_type > 4) {
  483. bus.mpc_busid = 1;
  484. memcpy(bus.mpc_bustype, "PCI ", 6);
  485. MP_bus_info(&bus);
  486. }
  487. #ifdef CONFIG_X86_IO_APIC
  488. ioapic.mpc_type = MP_IOAPIC;
  489. ioapic.mpc_apicid = 2;
  490. ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  491. ioapic.mpc_flags = MPC_APIC_USABLE;
  492. ioapic.mpc_apicaddr = 0xFEC00000;
  493. MP_ioapic_info(&ioapic);
  494. /*
  495. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  496. */
  497. construct_default_ioirq_mptable(mpc_default_type);
  498. #endif
  499. lintsrc.mpc_type = MP_LINTSRC;
  500. lintsrc.mpc_irqflag = 0; /* conforming */
  501. lintsrc.mpc_srcbusid = 0;
  502. lintsrc.mpc_srcbusirq = 0;
  503. lintsrc.mpc_destapic = MP_APIC_ALL;
  504. for (i = 0; i < 2; i++) {
  505. lintsrc.mpc_irqtype = linttypes[i];
  506. lintsrc.mpc_destapiclint = i;
  507. MP_lintsrc_info(&lintsrc);
  508. }
  509. }
  510. static struct intel_mp_floating *mpf_found;
  511. /*
  512. * Scan the memory blocks for an SMP configuration block.
  513. */
  514. static void __init __get_smp_config(unsigned early)
  515. {
  516. struct intel_mp_floating *mpf = mpf_found;
  517. if (acpi_lapic && early)
  518. return;
  519. /*
  520. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  521. * processors, where MPS only supports physical.
  522. */
  523. if (acpi_lapic && acpi_ioapic) {
  524. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
  525. "information\n");
  526. return;
  527. } else if (acpi_lapic)
  528. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  529. "configuration information\n");
  530. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
  531. mpf->mpf_specification);
  532. #ifdef CONFIG_X86_32
  533. if (mpf->mpf_feature2 & (1 << 7)) {
  534. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  535. pic_mode = 1;
  536. } else {
  537. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  538. pic_mode = 0;
  539. }
  540. #endif
  541. /*
  542. * Now see if we need to read further.
  543. */
  544. if (mpf->mpf_feature1 != 0) {
  545. if (early) {
  546. /*
  547. * local APIC has default address
  548. */
  549. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  550. return;
  551. }
  552. printk(KERN_INFO "Default MP configuration #%d\n",
  553. mpf->mpf_feature1);
  554. construct_default_ISA_mptable(mpf->mpf_feature1);
  555. } else if (mpf->mpf_physptr) {
  556. /*
  557. * Read the physical hardware table. Anything here will
  558. * override the defaults.
  559. */
  560. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
  561. smp_found_config = 0;
  562. printk(KERN_ERR
  563. "BIOS bug, MP table errors detected!...\n");
  564. printk(KERN_ERR "... disabling SMP support. "
  565. "(tell your hw vendor)\n");
  566. return;
  567. }
  568. if (early)
  569. return;
  570. #ifdef CONFIG_X86_IO_APIC
  571. /*
  572. * If there are no explicit MP IRQ entries, then we are
  573. * broken. We set up most of the low 16 IO-APIC pins to
  574. * ISA defaults and hope it will work.
  575. */
  576. if (!mp_irq_entries) {
  577. struct mpc_config_bus bus;
  578. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
  579. "using default mptable. "
  580. "(tell your hw vendor)\n");
  581. bus.mpc_type = MP_BUS;
  582. bus.mpc_busid = 0;
  583. memcpy(bus.mpc_bustype, "ISA ", 6);
  584. MP_bus_info(&bus);
  585. construct_default_ioirq_mptable(0);
  586. }
  587. #endif
  588. } else
  589. BUG();
  590. if (!early)
  591. printk(KERN_INFO "Processors: %d\n", num_processors);
  592. /*
  593. * Only use the first configuration found.
  594. */
  595. }
  596. void __init early_get_smp_config(void)
  597. {
  598. __get_smp_config(1);
  599. }
  600. void __init get_smp_config(void)
  601. {
  602. __get_smp_config(0);
  603. }
  604. static int __init smp_scan_config(unsigned long base, unsigned long length,
  605. unsigned reserve)
  606. {
  607. unsigned int *bp = phys_to_virt(base);
  608. struct intel_mp_floating *mpf;
  609. Dprintk("Scan SMP from %p for %ld bytes.\n", bp, length);
  610. BUILD_BUG_ON(sizeof(*mpf) != 16);
  611. while (length > 0) {
  612. mpf = (struct intel_mp_floating *)bp;
  613. if ((*bp == SMP_MAGIC_IDENT) &&
  614. (mpf->mpf_length == 1) &&
  615. !mpf_checksum((unsigned char *)bp, 16) &&
  616. ((mpf->mpf_specification == 1)
  617. || (mpf->mpf_specification == 4))) {
  618. smp_found_config = 1;
  619. mpf_found = mpf;
  620. #ifdef CONFIG_X86_32
  621. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  622. mpf, virt_to_phys(mpf));
  623. reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
  624. BOOTMEM_DEFAULT);
  625. if (mpf->mpf_physptr) {
  626. /*
  627. * We cannot access to MPC table to compute
  628. * table size yet, as only few megabytes from
  629. * the bottom is mapped now.
  630. * PC-9800's MPC table places on the very last
  631. * of physical memory; so that simply reserving
  632. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  633. * in reserve_bootmem.
  634. */
  635. unsigned long size = PAGE_SIZE;
  636. unsigned long end = max_low_pfn * PAGE_SIZE;
  637. if (mpf->mpf_physptr + size > end)
  638. size = end - mpf->mpf_physptr;
  639. reserve_bootmem(mpf->mpf_physptr, size,
  640. BOOTMEM_DEFAULT);
  641. }
  642. #else
  643. if (!reserve)
  644. return 1;
  645. reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
  646. if (mpf->mpf_physptr)
  647. reserve_bootmem_generic(mpf->mpf_physptr,
  648. PAGE_SIZE);
  649. #endif
  650. return 1;
  651. }
  652. bp += 4;
  653. length -= 16;
  654. }
  655. return 0;
  656. }
  657. static void __init __find_smp_config(unsigned reserve)
  658. {
  659. unsigned int address;
  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. /* --------------------------------------------------------------------------
  701. ACPI-based MP Configuration
  702. -------------------------------------------------------------------------- */
  703. #ifdef CONFIG_ACPI
  704. #ifdef CONFIG_X86_IO_APIC
  705. #define MP_ISA_BUS 0
  706. #define MP_MAX_IOAPIC_PIN 127
  707. extern struct mp_ioapic_routing mp_ioapic_routing[MAX_IO_APICS];
  708. static int mp_find_ioapic(int gsi)
  709. {
  710. int i = 0;
  711. /* Find the IOAPIC that manages this GSI. */
  712. for (i = 0; i < nr_ioapics; i++) {
  713. if ((gsi >= mp_ioapic_routing[i].gsi_base)
  714. && (gsi <= mp_ioapic_routing[i].gsi_end))
  715. return i;
  716. }
  717. printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
  718. return -1;
  719. }
  720. static u8 uniq_ioapic_id(u8 id)
  721. {
  722. #ifdef CONFIG_X86_32
  723. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
  724. !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  725. return io_apic_get_unique_id(nr_ioapics, id);
  726. else
  727. return id;
  728. #else
  729. int i;
  730. DECLARE_BITMAP(used, 256);
  731. bitmap_zero(used, 256);
  732. for (i = 0; i < nr_ioapics; i++) {
  733. struct mpc_config_ioapic *ia = &mp_ioapics[i];
  734. __set_bit(ia->mpc_apicid, used);
  735. }
  736. if (!test_bit(id, used))
  737. return id;
  738. return find_first_zero_bit(used, 256);
  739. #endif
  740. }
  741. void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
  742. {
  743. int idx = 0;
  744. if (bad_ioapic(address))
  745. return;
  746. idx = nr_ioapics;
  747. mp_ioapics[idx].mpc_type = MP_IOAPIC;
  748. mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
  749. mp_ioapics[idx].mpc_apicaddr = address;
  750. set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
  751. mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
  752. #ifdef CONFIG_X86_32
  753. mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
  754. #else
  755. mp_ioapics[idx].mpc_apicver = 0;
  756. #endif
  757. /*
  758. * Build basic GSI lookup table to facilitate gsi->io_apic lookups
  759. * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
  760. */
  761. mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
  762. mp_ioapic_routing[idx].gsi_base = gsi_base;
  763. mp_ioapic_routing[idx].gsi_end = gsi_base +
  764. io_apic_get_redir_entries(idx);
  765. printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
  766. "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
  767. mp_ioapics[idx].mpc_apicver, mp_ioapics[idx].mpc_apicaddr,
  768. mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
  769. nr_ioapics++;
  770. }
  771. void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  772. {
  773. struct mpc_config_intsrc intsrc;
  774. int ioapic = -1;
  775. int pin = -1;
  776. /*
  777. * Convert 'gsi' to 'ioapic.pin'.
  778. */
  779. ioapic = mp_find_ioapic(gsi);
  780. if (ioapic < 0)
  781. return;
  782. pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  783. /*
  784. * TBD: This check is for faulty timer entries, where the override
  785. * erroneously sets the trigger to level, resulting in a HUGE
  786. * increase of timer interrupts!
  787. */
  788. if ((bus_irq == 0) && (trigger == 3))
  789. trigger = 1;
  790. intsrc.mpc_type = MP_INTSRC;
  791. intsrc.mpc_irqtype = mp_INT;
  792. intsrc.mpc_irqflag = (trigger << 2) | polarity;
  793. intsrc.mpc_srcbus = MP_ISA_BUS;
  794. intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
  795. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
  796. intsrc.mpc_dstirq = pin; /* INTIN# */
  797. MP_intsrc_info(&intsrc);
  798. }
  799. int es7000_plat;
  800. void __init mp_config_acpi_legacy_irqs(void)
  801. {
  802. struct mpc_config_intsrc intsrc;
  803. int i = 0;
  804. int ioapic = -1;
  805. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  806. /*
  807. * Fabricate the legacy ISA bus (bus #31).
  808. */
  809. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  810. #endif
  811. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  812. Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
  813. /*
  814. * Older generations of ES7000 have no legacy identity mappings
  815. */
  816. if (es7000_plat == 1)
  817. return;
  818. /*
  819. * Locate the IOAPIC that manages the ISA IRQs (0-15).
  820. */
  821. ioapic = mp_find_ioapic(0);
  822. if (ioapic < 0)
  823. return;
  824. intsrc.mpc_type = MP_INTSRC;
  825. intsrc.mpc_irqflag = 0; /* Conforming */
  826. intsrc.mpc_srcbus = MP_ISA_BUS;
  827. #ifdef CONFIG_X86_IO_APIC
  828. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
  829. #endif
  830. /*
  831. * Use the default configuration for the IRQs 0-15. Unless
  832. * overridden by (MADT) interrupt source override entries.
  833. */
  834. for (i = 0; i < 16; i++) {
  835. int idx;
  836. for (idx = 0; idx < mp_irq_entries; idx++) {
  837. struct mpc_config_intsrc *irq = mp_irqs + idx;
  838. /* Do we already have a mapping for this ISA IRQ? */
  839. if (irq->mpc_srcbus == MP_ISA_BUS
  840. && irq->mpc_srcbusirq == i)
  841. break;
  842. /* Do we already have a mapping for this IOAPIC pin */
  843. if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
  844. (irq->mpc_dstirq == i))
  845. break;
  846. }
  847. if (idx != mp_irq_entries) {
  848. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  849. continue; /* IRQ already used */
  850. }
  851. intsrc.mpc_irqtype = mp_INT;
  852. intsrc.mpc_srcbusirq = i; /* Identity mapped */
  853. intsrc.mpc_dstirq = i;
  854. MP_intsrc_info(&intsrc);
  855. }
  856. }
  857. int mp_register_gsi(u32 gsi, int triggering, int polarity)
  858. {
  859. int ioapic = -1;
  860. int ioapic_pin = 0;
  861. int idx, bit = 0;
  862. #ifdef CONFIG_X86_32
  863. #define MAX_GSI_NUM 4096
  864. #define IRQ_COMPRESSION_START 64
  865. static int pci_irq = IRQ_COMPRESSION_START;
  866. /*
  867. * Mapping between Global System Interrupts, which
  868. * represent all possible interrupts, and IRQs
  869. * assigned to actual devices.
  870. */
  871. static int gsi_to_irq[MAX_GSI_NUM];
  872. #else
  873. if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
  874. return gsi;
  875. #endif
  876. /* Don't set up the ACPI SCI because it's already set up */
  877. if (acpi_gbl_FADT.sci_interrupt == gsi)
  878. return gsi;
  879. ioapic = mp_find_ioapic(gsi);
  880. if (ioapic < 0) {
  881. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  882. return gsi;
  883. }
  884. ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  885. #ifdef CONFIG_X86_32
  886. if (ioapic_renumber_irq)
  887. gsi = ioapic_renumber_irq(ioapic, gsi);
  888. #endif
  889. /*
  890. * Avoid pin reprogramming. PRTs typically include entries
  891. * with redundant pin->gsi mappings (but unique PCI devices);
  892. * we only program the IOAPIC on the first.
  893. */
  894. bit = ioapic_pin % 32;
  895. idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
  896. if (idx > 3) {
  897. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  898. "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
  899. ioapic_pin);
  900. return gsi;
  901. }
  902. if ((1 << bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
  903. Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
  904. mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
  905. #ifdef CONFIG_X86_32
  906. return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
  907. #else
  908. return gsi;
  909. #endif
  910. }
  911. mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1 << bit);
  912. #ifdef CONFIG_X86_32
  913. /*
  914. * For GSI >= 64, use IRQ compression
  915. */
  916. if ((gsi >= IRQ_COMPRESSION_START)
  917. && (triggering == ACPI_LEVEL_SENSITIVE)) {
  918. /*
  919. * For PCI devices assign IRQs in order, avoiding gaps
  920. * due to unused I/O APIC pins.
  921. */
  922. int irq = gsi;
  923. if (gsi < MAX_GSI_NUM) {
  924. /*
  925. * Retain the VIA chipset work-around (gsi > 15), but
  926. * avoid a problem where the 8254 timer (IRQ0) is setup
  927. * via an override (so it's not on pin 0 of the ioapic),
  928. * and at the same time, the pin 0 interrupt is a PCI
  929. * type. The gsi > 15 test could cause these two pins
  930. * to be shared as IRQ0, and they are not shareable.
  931. * So test for this condition, and if necessary, avoid
  932. * the pin collision.
  933. */
  934. gsi = pci_irq++;
  935. /*
  936. * Don't assign IRQ used by ACPI SCI
  937. */
  938. if (gsi == acpi_gbl_FADT.sci_interrupt)
  939. gsi = pci_irq++;
  940. gsi_to_irq[irq] = gsi;
  941. } else {
  942. printk(KERN_ERR "GSI %u is too high\n", gsi);
  943. return gsi;
  944. }
  945. }
  946. #endif
  947. io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
  948. triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
  949. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  950. return gsi;
  951. }
  952. #endif /* CONFIG_X86_IO_APIC */
  953. #endif /* CONFIG_ACPI */