mpparse_32.c 31 KB

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