mpparse.c 29 KB

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