mpparse_32.c 29 KB

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