mpparse_32.c 28 KB

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