mpparse_32.c 30 KB

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