mpparse_32.c 27 KB

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