mpparse_32.c 31 KB

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