mpparse_32.c 29 KB

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