mpparse_32.c 30 KB

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