mpparse.c 30 KB

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