mpparse_32.c 30 KB

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