mpparse.c 30 KB

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