mpparse.c 30 KB

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