mpparse.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. /*
  2. * Intel Multiprocessor Specification 1.1 and 1.4
  3. * compliant MP-table parsing routines.
  4. *
  5. * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
  6. * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
  7. *
  8. * Fixes
  9. * Erich Boleyn : MP v1.4 and additional changes.
  10. * Alan Cox : Added EBDA scanning
  11. * Ingo Molnar : various cleanups and rewrites
  12. * Maciej W. Rozycki: Bits for default MP configurations
  13. * Paul Diefenbaugh: Added full ACPI support
  14. */
  15. #include <linux/mm.h>
  16. #include <linux/init.h>
  17. #include <linux/acpi.h>
  18. #include <linux/delay.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/kernel_stat.h>
  22. #include <linux/mc146818rtc.h>
  23. #include <linux/bitops.h>
  24. #include <asm/smp.h>
  25. #include <asm/acpi.h>
  26. #include <asm/mtrr.h>
  27. #include <asm/mpspec.h>
  28. #include <asm/io_apic.h>
  29. #include <mach_apic.h>
  30. #include <mach_mpparse.h>
  31. #include <bios_ebda.h>
  32. /* Have we found an MP table */
  33. int smp_found_config;
  34. unsigned int __initdata maxcpus = NR_CPUS;
  35. /*
  36. * Various Linux-internal data structures created from the
  37. * MP-table.
  38. */
  39. int apic_version [MAX_APICS];
  40. int mp_bus_id_to_type [MAX_MP_BUSSES];
  41. int mp_bus_id_to_node [MAX_MP_BUSSES];
  42. int mp_bus_id_to_local [MAX_MP_BUSSES];
  43. int quad_local_to_mp_bus_id [NR_CPUS/4][4];
  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. static unsigned int __devinitdata num_processors;
  60. /* Bitmask of physically existing CPUs */
  61. physid_mask_t phys_cpu_present_map;
  62. u8 bios_cpu_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
  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] __initdata;
  83. static void __devinit 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. return;
  89. apicid = mpc_apic_id(m, translation_table[mpc_record]);
  90. if (m->mpc_featureflag&(1<<0))
  91. Dprintk(" Floating point unit present.\n");
  92. if (m->mpc_featureflag&(1<<7))
  93. Dprintk(" Machine Exception supported.\n");
  94. if (m->mpc_featureflag&(1<<8))
  95. Dprintk(" 64 bit compare & exchange supported.\n");
  96. if (m->mpc_featureflag&(1<<9))
  97. Dprintk(" Internal APIC present.\n");
  98. if (m->mpc_featureflag&(1<<11))
  99. Dprintk(" SEP present.\n");
  100. if (m->mpc_featureflag&(1<<12))
  101. Dprintk(" MTRR present.\n");
  102. if (m->mpc_featureflag&(1<<13))
  103. Dprintk(" PGE present.\n");
  104. if (m->mpc_featureflag&(1<<14))
  105. Dprintk(" MCA present.\n");
  106. if (m->mpc_featureflag&(1<<15))
  107. Dprintk(" CMOV present.\n");
  108. if (m->mpc_featureflag&(1<<16))
  109. Dprintk(" PAT present.\n");
  110. if (m->mpc_featureflag&(1<<17))
  111. Dprintk(" PSE present.\n");
  112. if (m->mpc_featureflag&(1<<18))
  113. Dprintk(" PSN present.\n");
  114. if (m->mpc_featureflag&(1<<19))
  115. Dprintk(" Cache Line Flush Instruction present.\n");
  116. /* 20 Reserved */
  117. if (m->mpc_featureflag&(1<<21))
  118. Dprintk(" Debug Trace and EMON Store present.\n");
  119. if (m->mpc_featureflag&(1<<22))
  120. Dprintk(" ACPI Thermal Throttle Registers present.\n");
  121. if (m->mpc_featureflag&(1<<23))
  122. Dprintk(" MMX present.\n");
  123. if (m->mpc_featureflag&(1<<24))
  124. Dprintk(" FXSR present.\n");
  125. if (m->mpc_featureflag&(1<<25))
  126. Dprintk(" XMM present.\n");
  127. if (m->mpc_featureflag&(1<<26))
  128. Dprintk(" Willamette New Instructions present.\n");
  129. if (m->mpc_featureflag&(1<<27))
  130. Dprintk(" Self Snoop present.\n");
  131. if (m->mpc_featureflag&(1<<28))
  132. Dprintk(" HT present.\n");
  133. if (m->mpc_featureflag&(1<<29))
  134. Dprintk(" Thermal Monitor present.\n");
  135. /* 30, 31 Reserved */
  136. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
  137. Dprintk(" Bootup CPU\n");
  138. boot_cpu_physical_apicid = m->mpc_apicid;
  139. }
  140. ver = m->mpc_apicver;
  141. /*
  142. * Validate version
  143. */
  144. if (ver == 0x0) {
  145. printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! "
  146. "fixing up to 0x10. (tell your hw vendor)\n",
  147. m->mpc_apicid);
  148. ver = 0x10;
  149. }
  150. apic_version[m->mpc_apicid] = ver;
  151. phys_cpu = apicid_to_cpu_present(apicid);
  152. physids_or(phys_cpu_present_map, phys_cpu_present_map, phys_cpu);
  153. if (num_processors >= NR_CPUS) {
  154. printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
  155. " Processor ignored.\n", NR_CPUS);
  156. return;
  157. }
  158. if (num_processors >= maxcpus) {
  159. printk(KERN_WARNING "WARNING: maxcpus limit of %i reached."
  160. " Processor ignored.\n", maxcpus);
  161. return;
  162. }
  163. cpu_set(num_processors, cpu_possible_map);
  164. num_processors++;
  165. /*
  166. * Would be preferable to switch to bigsmp when CONFIG_HOTPLUG_CPU=y
  167. * but we need to work other dependencies like SMP_SUSPEND etc
  168. * before this can be done without some confusion.
  169. * if (CPU_HOTPLUG_ENABLED || num_processors > 8)
  170. * - Ashok Raj <ashok.raj@intel.com>
  171. */
  172. if (num_processors > 8) {
  173. switch (boot_cpu_data.x86_vendor) {
  174. case X86_VENDOR_INTEL:
  175. if (!APIC_XAPIC(ver)) {
  176. def_to_bigsmp = 0;
  177. break;
  178. }
  179. /* If P4 and above fall through */
  180. case X86_VENDOR_AMD:
  181. def_to_bigsmp = 1;
  182. }
  183. }
  184. bios_cpu_apicid[num_processors - 1] = m->mpc_apicid;
  185. }
  186. static void __init MP_bus_info (struct mpc_config_bus *m)
  187. {
  188. char str[7];
  189. memcpy(str, m->mpc_bustype, 6);
  190. str[6] = 0;
  191. mpc_oem_bus_info(m, str, translation_table[mpc_record]);
  192. if (m->mpc_busid >= MAX_MP_BUSSES) {
  193. printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
  194. " is too large, max. supported is %d\n",
  195. m->mpc_busid, str, MAX_MP_BUSSES - 1);
  196. return;
  197. }
  198. if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA)-1) == 0) {
  199. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
  200. } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA)-1) == 0) {
  201. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
  202. } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI)-1) == 0) {
  203. mpc_oem_pci_bus(m, translation_table[mpc_record]);
  204. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
  205. mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
  206. mp_current_pci_id++;
  207. } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA)-1) == 0) {
  208. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
  209. } else if (strncmp(str, BUSTYPE_NEC98, sizeof(BUSTYPE_NEC98)-1) == 0) {
  210. mp_bus_id_to_type[m->mpc_busid] = MP_BUS_NEC98;
  211. } else {
  212. printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
  213. }
  214. }
  215. static void __init MP_ioapic_info (struct mpc_config_ioapic *m)
  216. {
  217. if (!(m->mpc_flags & MPC_APIC_USABLE))
  218. return;
  219. printk(KERN_INFO "I/O APIC #%d Version %d at 0x%lX.\n",
  220. m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
  221. if (nr_ioapics >= MAX_IO_APICS) {
  222. printk(KERN_CRIT "Max # of I/O APICs (%d) exceeded (found %d).\n",
  223. MAX_IO_APICS, nr_ioapics);
  224. panic("Recompile kernel with bigger MAX_IO_APICS!.\n");
  225. }
  226. if (!m->mpc_apicaddr) {
  227. printk(KERN_ERR "WARNING: bogus zero I/O APIC address"
  228. " found in MP table, skipping!\n");
  229. return;
  230. }
  231. mp_ioapics[nr_ioapics] = *m;
  232. nr_ioapics++;
  233. }
  234. static void __init MP_intsrc_info (struct mpc_config_intsrc *m)
  235. {
  236. mp_irqs [mp_irq_entries] = *m;
  237. Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
  238. " IRQ %02x, APIC ID %x, APIC INT %02x\n",
  239. m->mpc_irqtype, m->mpc_irqflag & 3,
  240. (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
  241. m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
  242. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  243. panic("Max # of irq sources exceeded!!\n");
  244. }
  245. static void __init MP_lintsrc_info (struct mpc_config_lintsrc *m)
  246. {
  247. Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
  248. " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
  249. m->mpc_irqtype, m->mpc_irqflag & 3,
  250. (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid,
  251. m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
  252. /*
  253. * Well it seems all SMP boards in existence
  254. * use ExtINT/LVT1 == LINT0 and
  255. * NMI/LVT2 == LINT1 - the following check
  256. * will show us if this assumptions is false.
  257. * Until then we do not have to add baggage.
  258. */
  259. if ((m->mpc_irqtype == mp_ExtINT) &&
  260. (m->mpc_destapiclint != 0))
  261. BUG();
  262. if ((m->mpc_irqtype == mp_NMI) &&
  263. (m->mpc_destapiclint != 1))
  264. BUG();
  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%lX\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. clustered_apic_check();
  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. Dprintk("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 %08lx\n",
  657. virt_to_phys(mpf));
  658. reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE);
  659. if (mpf->mpf_physptr) {
  660. /*
  661. * We cannot access to MPC table to compute
  662. * table size yet, as only few megabytes from
  663. * the bottom is mapped now.
  664. * PC-9800's MPC table places on the very last
  665. * of physical memory; so that simply reserving
  666. * PAGE_SIZE from mpg->mpf_physptr yields BUG()
  667. * in reserve_bootmem.
  668. */
  669. unsigned long size = PAGE_SIZE;
  670. unsigned long end = max_low_pfn * PAGE_SIZE;
  671. if (mpf->mpf_physptr + size > end)
  672. size = end - mpf->mpf_physptr;
  673. reserve_bootmem(mpf->mpf_physptr, size);
  674. }
  675. mpf_found = mpf;
  676. return 1;
  677. }
  678. bp += 4;
  679. length -= 16;
  680. }
  681. return 0;
  682. }
  683. void __init find_smp_config (void)
  684. {
  685. unsigned int address;
  686. /*
  687. * FIXME: Linux assumes you have 640K of base ram..
  688. * this continues the error...
  689. *
  690. * 1) Scan the bottom 1K for a signature
  691. * 2) Scan the top 1K of base RAM
  692. * 3) Scan the 64K of bios
  693. */
  694. if (smp_scan_config(0x0,0x400) ||
  695. smp_scan_config(639*0x400,0x400) ||
  696. smp_scan_config(0xF0000,0x10000))
  697. return;
  698. /*
  699. * If it is an SMP machine we should know now, unless the
  700. * configuration is in an EISA/MCA bus machine with an
  701. * extended bios data area.
  702. *
  703. * there is a real-mode segmented pointer pointing to the
  704. * 4K EBDA area at 0x40E, calculate and scan it here.
  705. *
  706. * NOTE! There are Linux loaders that will corrupt the EBDA
  707. * area, and as such this kind of SMP config may be less
  708. * trustworthy, simply because the SMP table may have been
  709. * stomped on during early boot. These loaders are buggy and
  710. * should be fixed.
  711. *
  712. * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
  713. */
  714. address = get_bios_ebda();
  715. if (address)
  716. smp_scan_config(address, 0x400);
  717. }
  718. int es7000_plat;
  719. /* --------------------------------------------------------------------------
  720. ACPI-based MP Configuration
  721. -------------------------------------------------------------------------- */
  722. #ifdef CONFIG_ACPI
  723. void __init mp_register_lapic_address (
  724. u64 address)
  725. {
  726. mp_lapic_addr = (unsigned long) address;
  727. set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
  728. if (boot_cpu_physical_apicid == -1U)
  729. boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  730. Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid);
  731. }
  732. void __devinit mp_register_lapic (
  733. u8 id,
  734. u8 enabled)
  735. {
  736. struct mpc_config_processor processor;
  737. int boot_cpu = 0;
  738. if (MAX_APICS - id <= 0) {
  739. printk(KERN_WARNING "Processor #%d invalid (max %d)\n",
  740. id, MAX_APICS);
  741. return;
  742. }
  743. if (id == boot_cpu_physical_apicid)
  744. boot_cpu = 1;
  745. processor.mpc_type = MP_PROCESSOR;
  746. processor.mpc_apicid = id;
  747. processor.mpc_apicver = GET_APIC_VERSION(apic_read(APIC_LVR));
  748. processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
  749. processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
  750. processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
  751. (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
  752. processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
  753. processor.mpc_reserved[0] = 0;
  754. processor.mpc_reserved[1] = 0;
  755. MP_processor_info(&processor);
  756. }
  757. #ifdef CONFIG_X86_IO_APIC
  758. #define MP_ISA_BUS 0
  759. #define MP_MAX_IOAPIC_PIN 127
  760. static struct mp_ioapic_routing {
  761. int apic_id;
  762. int gsi_base;
  763. int gsi_end;
  764. u32 pin_programmed[4];
  765. } mp_ioapic_routing[MAX_IO_APICS];
  766. static int mp_find_ioapic (
  767. int gsi)
  768. {
  769. int i = 0;
  770. /* Find the IOAPIC that manages this GSI. */
  771. for (i = 0; i < nr_ioapics; i++) {
  772. if ((gsi >= mp_ioapic_routing[i].gsi_base)
  773. && (gsi <= mp_ioapic_routing[i].gsi_end))
  774. return i;
  775. }
  776. printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
  777. return -1;
  778. }
  779. void __init mp_register_ioapic (
  780. u8 id,
  781. u32 address,
  782. u32 gsi_base)
  783. {
  784. int idx = 0;
  785. int tmpid;
  786. if (nr_ioapics >= MAX_IO_APICS) {
  787. printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
  788. "(found %d)\n", MAX_IO_APICS, nr_ioapics);
  789. panic("Recompile kernel with bigger MAX_IO_APICS!\n");
  790. }
  791. if (!address) {
  792. printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
  793. " found in MADT table, skipping!\n");
  794. return;
  795. }
  796. idx = nr_ioapics++;
  797. mp_ioapics[idx].mpc_type = MP_IOAPIC;
  798. mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
  799. mp_ioapics[idx].mpc_apicaddr = address;
  800. set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
  801. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
  802. && !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  803. tmpid = io_apic_get_unique_id(idx, id);
  804. else
  805. tmpid = id;
  806. if (tmpid == -1) {
  807. nr_ioapics--;
  808. return;
  809. }
  810. mp_ioapics[idx].mpc_apicid = tmpid;
  811. mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
  812. /*
  813. * Build basic GSI lookup table to facilitate gsi->io_apic lookups
  814. * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
  815. */
  816. mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
  817. mp_ioapic_routing[idx].gsi_base = gsi_base;
  818. mp_ioapic_routing[idx].gsi_end = gsi_base +
  819. io_apic_get_redir_entries(idx);
  820. printk("IOAPIC[%d]: apic_id %d, version %d, address 0x%lx, "
  821. "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
  822. mp_ioapics[idx].mpc_apicver, mp_ioapics[idx].mpc_apicaddr,
  823. mp_ioapic_routing[idx].gsi_base,
  824. mp_ioapic_routing[idx].gsi_end);
  825. return;
  826. }
  827. void __init mp_override_legacy_irq (
  828. u8 bus_irq,
  829. u8 polarity,
  830. u8 trigger,
  831. u32 gsi)
  832. {
  833. struct mpc_config_intsrc intsrc;
  834. int ioapic = -1;
  835. int pin = -1;
  836. /*
  837. * Convert 'gsi' to 'ioapic.pin'.
  838. */
  839. ioapic = mp_find_ioapic(gsi);
  840. if (ioapic < 0)
  841. return;
  842. pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  843. /*
  844. * TBD: This check is for faulty timer entries, where the override
  845. * erroneously sets the trigger to level, resulting in a HUGE
  846. * increase of timer interrupts!
  847. */
  848. if ((bus_irq == 0) && (trigger == 3))
  849. trigger = 1;
  850. intsrc.mpc_type = MP_INTSRC;
  851. intsrc.mpc_irqtype = mp_INT;
  852. intsrc.mpc_irqflag = (trigger << 2) | polarity;
  853. intsrc.mpc_srcbus = MP_ISA_BUS;
  854. intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
  855. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
  856. intsrc.mpc_dstirq = pin; /* INTIN# */
  857. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
  858. intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  859. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  860. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
  861. mp_irqs[mp_irq_entries] = intsrc;
  862. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  863. panic("Max # of irq sources exceeded!\n");
  864. return;
  865. }
  866. void __init mp_config_acpi_legacy_irqs (void)
  867. {
  868. struct mpc_config_intsrc intsrc;
  869. int i = 0;
  870. int ioapic = -1;
  871. /*
  872. * Fabricate the legacy ISA bus (bus #31).
  873. */
  874. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  875. Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
  876. /*
  877. * Older generations of ES7000 have no legacy identity mappings
  878. */
  879. if (es7000_plat == 1)
  880. return;
  881. /*
  882. * Locate the IOAPIC that manages the ISA IRQs (0-15).
  883. */
  884. ioapic = mp_find_ioapic(0);
  885. if (ioapic < 0)
  886. return;
  887. intsrc.mpc_type = MP_INTSRC;
  888. intsrc.mpc_irqflag = 0; /* Conforming */
  889. intsrc.mpc_srcbus = MP_ISA_BUS;
  890. intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
  891. /*
  892. * Use the default configuration for the IRQs 0-15. Unless
  893. * overriden by (MADT) interrupt source override entries.
  894. */
  895. for (i = 0; i < 16; i++) {
  896. int idx;
  897. for (idx = 0; idx < mp_irq_entries; idx++) {
  898. struct mpc_config_intsrc *irq = mp_irqs + idx;
  899. /* Do we already have a mapping for this ISA IRQ? */
  900. if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i)
  901. break;
  902. /* Do we already have a mapping for this IOAPIC pin */
  903. if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
  904. (irq->mpc_dstirq == i))
  905. break;
  906. }
  907. if (idx != mp_irq_entries) {
  908. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  909. continue; /* IRQ already used */
  910. }
  911. intsrc.mpc_irqtype = mp_INT;
  912. intsrc.mpc_srcbusirq = i; /* Identity mapped */
  913. intsrc.mpc_dstirq = i;
  914. Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
  915. "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
  916. (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
  917. intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
  918. intsrc.mpc_dstirq);
  919. mp_irqs[mp_irq_entries] = intsrc;
  920. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  921. panic("Max # of irq sources exceeded!\n");
  922. }
  923. }
  924. #define MAX_GSI_NUM 4096
  925. int mp_register_gsi (u32 gsi, int triggering, int polarity)
  926. {
  927. int ioapic = -1;
  928. int ioapic_pin = 0;
  929. int idx, bit = 0;
  930. static int pci_irq = 16;
  931. /*
  932. * Mapping between Global System Interrups, which
  933. * represent all possible interrupts, and IRQs
  934. * assigned to actual devices.
  935. */
  936. static int gsi_to_irq[MAX_GSI_NUM];
  937. /* Don't set up the ACPI SCI because it's already set up */
  938. if (acpi_fadt.sci_int == gsi)
  939. return gsi;
  940. ioapic = mp_find_ioapic(gsi);
  941. if (ioapic < 0) {
  942. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  943. return gsi;
  944. }
  945. ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
  946. if (ioapic_renumber_irq)
  947. gsi = ioapic_renumber_irq(ioapic, gsi);
  948. /*
  949. * Avoid pin reprogramming. PRTs typically include entries
  950. * with redundant pin->gsi mappings (but unique PCI devices);
  951. * we only program the IOAPIC on the first.
  952. */
  953. bit = ioapic_pin % 32;
  954. idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
  955. if (idx > 3) {
  956. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  957. "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
  958. ioapic_pin);
  959. return gsi;
  960. }
  961. if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
  962. Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
  963. mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
  964. return gsi_to_irq[gsi];
  965. }
  966. mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
  967. if (triggering == ACPI_LEVEL_SENSITIVE) {
  968. /*
  969. * For PCI devices assign IRQs in order, avoiding gaps
  970. * due to unused I/O APIC pins.
  971. */
  972. int irq = gsi;
  973. if (gsi < MAX_GSI_NUM) {
  974. /*
  975. * Retain the VIA chipset work-around (gsi > 15), but
  976. * avoid a problem where the 8254 timer (IRQ0) is setup
  977. * via an override (so it's not on pin 0 of the ioapic),
  978. * and at the same time, the pin 0 interrupt is a PCI
  979. * type. The gsi > 15 test could cause these two pins
  980. * to be shared as IRQ0, and they are not shareable.
  981. * So test for this condition, and if necessary, avoid
  982. * the pin collision.
  983. */
  984. if (gsi > 15 || (gsi == 0 && !timer_uses_ioapic_pin_0))
  985. gsi = pci_irq++;
  986. /*
  987. * Don't assign IRQ used by ACPI SCI
  988. */
  989. if (gsi == acpi_fadt.sci_int)
  990. gsi = pci_irq++;
  991. gsi_to_irq[irq] = gsi;
  992. } else {
  993. printk(KERN_ERR "GSI %u is too high\n", gsi);
  994. return gsi;
  995. }
  996. }
  997. io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
  998. triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
  999. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  1000. return gsi;
  1001. }
  1002. #endif /* CONFIG_X86_IO_APIC */
  1003. #endif /* CONFIG_ACPI */