mpparse.c 30 KB

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