mpparse_32.c 28 KB

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