mpparse_32.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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] __cpuinitdata;
  66. #endif
  67. static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
  68. {
  69. int apicid;
  70. if (!(m->mpc_cpuflag & CPU_ENABLED)) {
  71. disabled_cpus++;
  72. return;
  73. }
  74. #ifdef CONFIG_X86_NUMAQ
  75. apicid = mpc_apic_id(m, translation_table[mpc_record]);
  76. #else
  77. Dprintk("Processor #%d %u:%u APIC version %d\n",
  78. m->mpc_apicid,
  79. (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
  80. (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
  81. 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 "Translation: record %d, type %d, quad %d, global %d, local %d\n", mpc_record, m->trans_type, m->trans_quad, m->trans_global, m->trans_local);
  225. if (mpc_record >= MAX_MPC_ENTRY)
  226. printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
  227. else
  228. translation_table[mpc_record] = m; /* stash this for later */
  229. if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
  230. node_set_online(m->trans_quad);
  231. }
  232. /*
  233. * Read/parse the MPC oem tables
  234. */
  235. static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable, \
  236. unsigned short oemsize)
  237. {
  238. int count = sizeof (*oemtable); /* the header size */
  239. unsigned char *oemptr = ((unsigned char *)oemtable)+count;
  240. mpc_record = 0;
  241. printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n", oemtable);
  242. if (memcmp(oemtable->oem_signature,MPC_OEM_SIGNATURE,4))
  243. {
  244. printk(KERN_WARNING "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
  245. oemtable->oem_signature[0],
  246. oemtable->oem_signature[1],
  247. oemtable->oem_signature[2],
  248. oemtable->oem_signature[3]);
  249. return;
  250. }
  251. if (mpf_checksum((unsigned char *)oemtable,oemtable->oem_length))
  252. {
  253. printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
  254. return;
  255. }
  256. while (count < oemtable->oem_length) {
  257. switch (*oemptr) {
  258. case MP_TRANSLATION:
  259. {
  260. struct mpc_config_translation *m=
  261. (struct mpc_config_translation *)oemptr;
  262. MP_translation_info(m);
  263. oemptr += sizeof(*m);
  264. count += sizeof(*m);
  265. ++mpc_record;
  266. break;
  267. }
  268. default:
  269. {
  270. printk(KERN_WARNING "Unrecognised OEM table entry type! - %d\n", (int) *oemptr);
  271. return;
  272. }
  273. }
  274. }
  275. }
  276. static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
  277. char *productid)
  278. {
  279. if (strncmp(oem, "IBM NUMA", 8))
  280. printk("Warning! May not be a NUMA-Q system!\n");
  281. if (mpc->mpc_oemptr)
  282. smp_read_mpc_oem((struct mp_config_oemtable *) mpc->mpc_oemptr,
  283. mpc->mpc_oemsize);
  284. }
  285. #endif /* CONFIG_X86_NUMAQ */
  286. /*
  287. * Read/parse the MPC
  288. */
  289. static int __init smp_read_mpc(struct mp_config_table *mpc)
  290. {
  291. char str[16];
  292. char oem[10];
  293. int count=sizeof(*mpc);
  294. unsigned char *mpt=((unsigned char *)mpc)+count;
  295. if (memcmp(mpc->mpc_signature,MPC_SIGNATURE,4)) {
  296. printk(KERN_ERR "SMP mptable: bad signature [0x%x]!\n",
  297. *(u32 *)mpc->mpc_signature);
  298. return 0;
  299. }
  300. if (mpf_checksum((unsigned char *)mpc,mpc->mpc_length)) {
  301. printk(KERN_ERR "SMP mptable: checksum error!\n");
  302. return 0;
  303. }
  304. if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) {
  305. printk(KERN_ERR "SMP mptable: bad table version (%d)!!\n",
  306. mpc->mpc_spec);
  307. return 0;
  308. }
  309. if (!mpc->mpc_lapic) {
  310. printk(KERN_ERR "SMP mptable: null local APIC address!\n");
  311. return 0;
  312. }
  313. memcpy(oem,mpc->mpc_oem,8);
  314. oem[8]=0;
  315. printk(KERN_INFO "OEM ID: %s ",oem);
  316. memcpy(str,mpc->mpc_productid,12);
  317. str[12]=0;
  318. printk("Product ID: %s ",str);
  319. mps_oem_check(mpc, oem, str);
  320. printk("APIC at: 0x%X\n", mpc->mpc_lapic);
  321. /*
  322. * Save the local APIC address (it might be non-default) -- but only
  323. * if we're not using ACPI.
  324. */
  325. if (!acpi_lapic)
  326. mp_lapic_addr = mpc->mpc_lapic;
  327. /*
  328. * Now process the configuration blocks.
  329. */
  330. #ifdef CONFIG_X86_NUMAQ
  331. mpc_record = 0;
  332. #endif
  333. while (count < mpc->mpc_length) {
  334. switch(*mpt) {
  335. case MP_PROCESSOR:
  336. {
  337. struct mpc_config_processor *m=
  338. (struct mpc_config_processor *)mpt;
  339. /* ACPI may have already provided this data */
  340. if (!acpi_lapic)
  341. MP_processor_info(m);
  342. mpt += sizeof(*m);
  343. count += sizeof(*m);
  344. break;
  345. }
  346. case MP_BUS:
  347. {
  348. struct mpc_config_bus *m=
  349. (struct mpc_config_bus *)mpt;
  350. MP_bus_info(m);
  351. mpt += sizeof(*m);
  352. count += sizeof(*m);
  353. break;
  354. }
  355. case MP_IOAPIC:
  356. {
  357. #ifdef CONFIG_X86_IO_APIC
  358. struct mpc_config_ioapic *m=
  359. (struct mpc_config_ioapic *)mpt;
  360. MP_ioapic_info(m);
  361. #endif
  362. mpt+=sizeof(struct mpc_config_ioapic);
  363. count+=sizeof(struct mpc_config_ioapic);
  364. break;
  365. }
  366. case MP_INTSRC:
  367. {
  368. #ifdef CONFIG_X86_IO_APIC
  369. struct mpc_config_intsrc *m=
  370. (struct mpc_config_intsrc *)mpt;
  371. MP_intsrc_info(m);
  372. #endif
  373. mpt+=sizeof(struct mpc_config_intsrc);
  374. count+=sizeof(struct mpc_config_intsrc);
  375. break;
  376. }
  377. case MP_LINTSRC:
  378. {
  379. struct mpc_config_lintsrc *m=
  380. (struct mpc_config_lintsrc *)mpt;
  381. MP_lintsrc_info(m);
  382. mpt+=sizeof(*m);
  383. count+=sizeof(*m);
  384. break;
  385. }
  386. default:
  387. {
  388. count = mpc->mpc_length;
  389. break;
  390. }
  391. }
  392. #ifdef CONFIG_X86_NUMAQ
  393. ++mpc_record;
  394. #endif
  395. }
  396. setup_apic_routing();
  397. if (!num_processors)
  398. printk(KERN_ERR "SMP mptable: no processors registered!\n");
  399. return num_processors;
  400. }
  401. #ifdef CONFIG_X86_IO_APIC
  402. static int __init ELCR_trigger(unsigned int irq)
  403. {
  404. unsigned int port;
  405. port = 0x4d0 + (irq >> 3);
  406. return (inb(port) >> (irq & 7)) & 1;
  407. }
  408. static void __init construct_default_ioirq_mptable(int mpc_default_type)
  409. {
  410. struct mpc_config_intsrc intsrc;
  411. int i;
  412. int ELCR_fallback = 0;
  413. intsrc.mpc_type = MP_INTSRC;
  414. intsrc.mpc_irqflag = 0; /* conforming */
  415. intsrc.mpc_srcbus = 0;
  416. intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
  417. intsrc.mpc_irqtype = mp_INT;
  418. /*
  419. * If true, we have an ISA/PCI system with no IRQ entries
  420. * in the MP table. To prevent the PCI interrupts from being set up
  421. * incorrectly, we try to use the ELCR. The sanity check to see if
  422. * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
  423. * never be level sensitive, so we simply see if the ELCR agrees.
  424. * If it does, we assume it's valid.
  425. */
  426. if (mpc_default_type == 5) {
  427. printk(KERN_INFO "ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
  428. if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
  429. printk(KERN_WARNING "ELCR contains invalid data... not using ELCR\n");
  430. else {
  431. printk(KERN_INFO "Using ELCR to identify PCI interrupts\n");
  432. ELCR_fallback = 1;
  433. }
  434. }
  435. for (i = 0; i < 16; i++) {
  436. switch (mpc_default_type) {
  437. case 2:
  438. if (i == 0 || i == 13)
  439. continue; /* IRQ0 & IRQ13 not connected */
  440. /* fall through */
  441. default:
  442. if (i == 2)
  443. continue; /* IRQ2 is never connected */
  444. }
  445. if (ELCR_fallback) {
  446. /*
  447. * If the ELCR indicates a level-sensitive interrupt, we
  448. * copy that information over to the MP table in the
  449. * irqflag field (level sensitive, active high polarity).
  450. */
  451. if (ELCR_trigger(i))
  452. intsrc.mpc_irqflag = 13;
  453. else
  454. intsrc.mpc_irqflag = 0;
  455. }
  456. intsrc.mpc_srcbusirq = i;
  457. intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
  458. MP_intsrc_info(&intsrc);
  459. }
  460. intsrc.mpc_irqtype = mp_ExtINT;
  461. intsrc.mpc_srcbusirq = 0;
  462. intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
  463. MP_intsrc_info(&intsrc);
  464. }
  465. #endif
  466. static inline void __init construct_default_ISA_mptable(int mpc_default_type)
  467. {
  468. struct mpc_config_processor processor;
  469. struct mpc_config_bus bus;
  470. #ifdef CONFIG_X86_IO_APIC
  471. struct mpc_config_ioapic ioapic;
  472. #endif
  473. struct mpc_config_lintsrc lintsrc;
  474. int linttypes[2] = { mp_ExtINT, mp_NMI };
  475. int i;
  476. /*
  477. * local APIC has default address
  478. */
  479. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  480. /*
  481. * 2 CPUs, numbered 0 & 1.
  482. */
  483. processor.mpc_type = MP_PROCESSOR;
  484. /* Either an integrated APIC or a discrete 82489DX. */
  485. processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  486. processor.mpc_cpuflag = CPU_ENABLED;
  487. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  488. (boot_cpu_data.x86_model << 4) |
  489. boot_cpu_data.x86_mask;
  490. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  491. processor.mpc_reserved[0] = 0;
  492. processor.mpc_reserved[1] = 0;
  493. for (i = 0; i < 2; i++) {
  494. processor.mpc_apicid = i;
  495. MP_processor_info(&processor);
  496. }
  497. bus.mpc_type = MP_BUS;
  498. bus.mpc_busid = 0;
  499. switch (mpc_default_type) {
  500. default:
  501. printk("???\n");
  502. printk(KERN_ERR "Unknown standard configuration %d\n",
  503. mpc_default_type);
  504. /* fall through */
  505. case 1:
  506. case 5:
  507. memcpy(bus.mpc_bustype, "ISA ", 6);
  508. break;
  509. case 2:
  510. case 6:
  511. case 3:
  512. memcpy(bus.mpc_bustype, "EISA ", 6);
  513. break;
  514. case 4:
  515. case 7:
  516. memcpy(bus.mpc_bustype, "MCA ", 6);
  517. }
  518. MP_bus_info(&bus);
  519. if (mpc_default_type > 4) {
  520. bus.mpc_busid = 1;
  521. memcpy(bus.mpc_bustype, "PCI ", 6);
  522. MP_bus_info(&bus);
  523. }
  524. #ifdef CONFIG_X86_IO_APIC
  525. ioapic.mpc_type = MP_IOAPIC;
  526. ioapic.mpc_apicid = 2;
  527. ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
  528. ioapic.mpc_flags = MPC_APIC_USABLE;
  529. ioapic.mpc_apicaddr = 0xFEC00000;
  530. MP_ioapic_info(&ioapic);
  531. /*
  532. * We set up most of the low 16 IO-APIC pins according to MPS rules.
  533. */
  534. construct_default_ioirq_mptable(mpc_default_type);
  535. #endif
  536. lintsrc.mpc_type = MP_LINTSRC;
  537. lintsrc.mpc_irqflag = 0; /* conforming */
  538. lintsrc.mpc_srcbusid = 0;
  539. lintsrc.mpc_srcbusirq = 0;
  540. lintsrc.mpc_destapic = MP_APIC_ALL;
  541. for (i = 0; i < 2; i++) {
  542. lintsrc.mpc_irqtype = linttypes[i];
  543. lintsrc.mpc_destapiclint = i;
  544. MP_lintsrc_info(&lintsrc);
  545. }
  546. }
  547. static struct intel_mp_floating *mpf_found;
  548. /*
  549. * Scan the memory blocks for an SMP configuration block.
  550. */
  551. void __init get_smp_config (void)
  552. {
  553. struct intel_mp_floating *mpf = mpf_found;
  554. /*
  555. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  556. * processors, where MPS only supports physical.
  557. */
  558. if (acpi_lapic && acpi_ioapic) {
  559. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration information\n");
  560. return;
  561. }
  562. else if (acpi_lapic)
  563. printk(KERN_INFO "Using ACPI for processor (LAPIC) configuration information\n");
  564. printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", mpf->mpf_specification);
  565. if (mpf->mpf_feature2 & (1<<7)) {
  566. printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
  567. pic_mode = 1;
  568. } else {
  569. printk(KERN_INFO " Virtual Wire compatibility mode.\n");
  570. pic_mode = 0;
  571. }
  572. /*
  573. * Now see if we need to read further.
  574. */
  575. if (mpf->mpf_feature1 != 0) {
  576. printk(KERN_INFO "Default MP configuration #%d\n", mpf->mpf_feature1);
  577. construct_default_ISA_mptable(mpf->mpf_feature1);
  578. } else if (mpf->mpf_physptr) {
  579. /*
  580. * Read the physical hardware table. Anything here will
  581. * override the defaults.
  582. */
  583. if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr))) {
  584. smp_found_config = 0;
  585. printk(KERN_ERR "BIOS bug, MP table errors detected!...\n");
  586. printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n");
  587. return;
  588. }
  589. #ifdef CONFIG_X86_IO_APIC
  590. /*
  591. * If there are no explicit MP IRQ entries, then we are
  592. * broken. We set up most of the low 16 IO-APIC pins to
  593. * ISA defaults and hope it will work.
  594. */
  595. if (!mp_irq_entries) {
  596. struct mpc_config_bus bus;
  597. printk(KERN_ERR "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
  598. bus.mpc_type = MP_BUS;
  599. bus.mpc_busid = 0;
  600. memcpy(bus.mpc_bustype, "ISA ", 6);
  601. MP_bus_info(&bus);
  602. construct_default_ioirq_mptable(0);
  603. }
  604. #endif
  605. } else
  606. BUG();
  607. printk(KERN_INFO "Processors: %d\n", num_processors);
  608. /*
  609. * Only use the first configuration found.
  610. */
  611. }
  612. static int __init smp_scan_config (unsigned long base, unsigned long length)
  613. {
  614. unsigned long *bp = phys_to_virt(base);
  615. struct intel_mp_floating *mpf;
  616. printk(KERN_INFO "Scan SMP from %p for %ld bytes.\n", bp,length);
  617. if (sizeof(*mpf) != 16)
  618. printk("Error: MPF size\n");
  619. while (length > 0) {
  620. mpf = (struct intel_mp_floating *)bp;
  621. if ((*bp == SMP_MAGIC_IDENT) &&
  622. (mpf->mpf_length == 1) &&
  623. !mpf_checksum((unsigned char *)bp, 16) &&
  624. ((mpf->mpf_specification == 1)
  625. || (mpf->mpf_specification == 4)) ) {
  626. smp_found_config = 1;
  627. printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
  628. mpf, virt_to_phys(mpf));
  629. reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
  630. BOOTMEM_DEFAULT);
  631. if (mpf->mpf_physptr) {
  632. /*
  633. * We cannot access to MPC table to compute
  634. * table size yet, as only few megabytes from
  635. * the bottom is mapped now.
  636. * PC-9800's MPC table places on the very last
  637. * of physical memory; so that simply reserving
  638. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  639. * in reserve_bootmem.
  640. */
  641. unsigned long size = PAGE_SIZE;
  642. unsigned long end = max_low_pfn * PAGE_SIZE;
  643. if (mpf->mpf_physptr + size > end)
  644. size = end - mpf->mpf_physptr;
  645. reserve_bootmem(mpf->mpf_physptr, size,
  646. BOOTMEM_DEFAULT);
  647. }
  648. mpf_found = mpf;
  649. return 1;
  650. }
  651. bp += 4;
  652. length -= 16;
  653. }
  654. return 0;
  655. }
  656. void __init find_smp_config (void)
  657. {
  658. unsigned int address;
  659. /*
  660. * FIXME: Linux assumes you have 640K of base ram..
  661. * this continues the error...
  662. *
  663. * 1) Scan the bottom 1K for a signature
  664. * 2) Scan the top 1K of base RAM
  665. * 3) Scan the 64K of bios
  666. */
  667. if (smp_scan_config(0x0,0x400) ||
  668. smp_scan_config(639*0x400,0x400) ||
  669. smp_scan_config(0xF0000,0x10000))
  670. return;
  671. /*
  672. * If it is an SMP machine we should know now, unless the
  673. * configuration is in an EISA/MCA bus machine with an
  674. * extended bios data area.
  675. *
  676. * there is a real-mode segmented pointer pointing to the
  677. * 4K EBDA area at 0x40E, calculate and scan it here.
  678. *
  679. * NOTE! There are Linux loaders that will corrupt the EBDA
  680. * area, and as such this kind of SMP config may be less
  681. * trustworthy, simply because the SMP table may have been
  682. * stomped on during early boot. These loaders are buggy and
  683. * should be fixed.
  684. *
  685. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  686. */
  687. address = get_bios_ebda();
  688. if (address)
  689. smp_scan_config(address, 0x400);
  690. }
  691. /* --------------------------------------------------------------------------
  692. ACPI-based MP Configuration
  693. -------------------------------------------------------------------------- */
  694. #ifdef CONFIG_ACPI
  695. void __init mp_register_lapic_address(u64 address)
  696. {
  697. mp_lapic_addr = (unsigned long) address;
  698. set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
  699. if (boot_cpu_physical_apicid == -1U)
  700. boot_cpu_physical_apicid = GET_APIC_ID(read_apic_id());
  701. Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid);
  702. }
  703. #ifdef CONFIG_X86_IO_APIC
  704. #define MP_ISA_BUS 0
  705. #define MP_MAX_IOAPIC_PIN 127
  706. extern struct mp_ioapic_routing mp_ioapic_routing[MAX_IO_APICS];
  707. static int mp_find_ioapic (int gsi)
  708. {
  709. int i = 0;
  710. /* Find the IOAPIC that manages this GSI. */
  711. for (i = 0; i < nr_ioapics; i++) {
  712. if ((gsi >= mp_ioapic_routing[i].gsi_base)
  713. && (gsi <= mp_ioapic_routing[i].gsi_end))
  714. return i;
  715. }
  716. printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
  717. return -1;
  718. }
  719. static u8 uniq_ioapic_id(u8 id)
  720. {
  721. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
  722. !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  723. return io_apic_get_unique_id(nr_ioapics, id);
  724. else
  725. return id;
  726. }
  727. void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
  728. {
  729. int idx = 0;
  730. if (bad_ioapic(address))
  731. return;
  732. idx = nr_ioapics;
  733. mp_ioapics[idx].mpc_type = MP_IOAPIC;
  734. mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
  735. mp_ioapics[idx].mpc_apicaddr = address;
  736. set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
  737. mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
  738. mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
  739. /*
  740. * Build basic GSI lookup table to facilitate gsi->io_apic lookups
  741. * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
  742. */
  743. mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
  744. mp_ioapic_routing[idx].gsi_base = gsi_base;
  745. mp_ioapic_routing[idx].gsi_end = gsi_base +
  746. io_apic_get_redir_entries(idx);
  747. printk("IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
  748. "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
  749. mp_ioapics[idx].mpc_apicver,
  750. mp_ioapics[idx].mpc_apicaddr,
  751. mp_ioapic_routing[idx].gsi_base,
  752. mp_ioapic_routing[idx].gsi_end);
  753. nr_ioapics++;
  754. }
  755. void __init
  756. mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  757. {
  758. struct mpc_config_intsrc intsrc;
  759. int ioapic = -1;
  760. int pin = -1;
  761. /*
  762. * Convert 'gsi' to 'ioapic.pin'.
  763. */
  764. ioapic = mp_find_ioapic(gsi);
  765. if (ioapic < 0)
  766. return;
  767. pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  768. /*
  769. * TBD: This check is for faulty timer entries, where the override
  770. * erroneously sets the trigger to level, resulting in a HUGE
  771. * increase of timer interrupts!
  772. */
  773. if ((bus_irq == 0) && (trigger == 3))
  774. trigger = 1;
  775. intsrc.mpc_type = MP_INTSRC;
  776. intsrc.mpc_irqtype = mp_INT;
  777. intsrc.mpc_irqflag = (trigger << 2) | polarity;
  778. intsrc.mpc_srcbus = MP_ISA_BUS;
  779. intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
  780. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
  781. intsrc.mpc_dstirq = pin; /* INTIN# */
  782. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
  783. intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  784. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  785. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
  786. mp_irqs[mp_irq_entries] = intsrc;
  787. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  788. panic("Max # of irq sources exceeded!\n");
  789. }
  790. int es7000_plat;
  791. void __init mp_config_acpi_legacy_irqs (void)
  792. {
  793. struct mpc_config_intsrc intsrc;
  794. int i = 0;
  795. int ioapic = -1;
  796. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  797. /*
  798. * Fabricate the legacy ISA bus (bus #31).
  799. */
  800. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  801. #endif
  802. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  803. Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
  804. /*
  805. * Older generations of ES7000 have no legacy identity mappings
  806. */
  807. if (es7000_plat == 1)
  808. return;
  809. /*
  810. * Locate the IOAPIC that manages the ISA IRQs (0-15).
  811. */
  812. ioapic = mp_find_ioapic(0);
  813. if (ioapic < 0)
  814. return;
  815. intsrc.mpc_type = MP_INTSRC;
  816. intsrc.mpc_irqflag = 0; /* Conforming */
  817. intsrc.mpc_srcbus = MP_ISA_BUS;
  818. #ifdef CONFIG_X86_IO_APIC
  819. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
  820. #endif
  821. /*
  822. * Use the default configuration for the IRQs 0-15. Unless
  823. * overridden by (MADT) interrupt source override entries.
  824. */
  825. for (i = 0; i < 16; i++) {
  826. int idx;
  827. for (idx = 0; idx < mp_irq_entries; idx++) {
  828. struct mpc_config_intsrc *irq = mp_irqs + idx;
  829. /* Do we already have a mapping for this ISA IRQ? */
  830. if (irq->mpc_srcbus == MP_ISA_BUS && 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 */