boot.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. /*
  2. * boot.c - Architecture-Specific Low-Level ACPI Boot Support
  3. *
  4. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  5. * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #include <linux/init.h>
  26. #include <linux/acpi.h>
  27. #include <linux/acpi_pmtmr.h>
  28. #include <linux/efi.h>
  29. #include <linux/cpumask.h>
  30. #include <linux/module.h>
  31. #include <linux/dmi.h>
  32. #include <linux/irq.h>
  33. #include <linux/slab.h>
  34. #include <linux/bootmem.h>
  35. #include <linux/ioport.h>
  36. #include <linux/pci.h>
  37. #include <asm/pci_x86.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/io_apic.h>
  40. #include <asm/apic.h>
  41. #include <asm/io.h>
  42. #include <asm/mpspec.h>
  43. #include <asm/smp.h>
  44. static int __initdata acpi_force = 0;
  45. u32 acpi_rsdt_forced;
  46. int acpi_disabled;
  47. EXPORT_SYMBOL(acpi_disabled);
  48. #ifdef CONFIG_X86_64
  49. # include <asm/proto.h>
  50. # include <asm/numa_64.h>
  51. #endif /* X86 */
  52. #define BAD_MADT_ENTRY(entry, end) ( \
  53. (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
  54. ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
  55. #define PREFIX "ACPI: "
  56. int acpi_noirq; /* skip ACPI IRQ initialization */
  57. int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
  58. EXPORT_SYMBOL(acpi_pci_disabled);
  59. int acpi_lapic;
  60. int acpi_ioapic;
  61. int acpi_strict;
  62. u8 acpi_sci_flags __initdata;
  63. int acpi_sci_override_gsi __initdata;
  64. int acpi_skip_timer_override __initdata;
  65. int acpi_use_timer_override __initdata;
  66. #ifdef CONFIG_X86_LOCAL_APIC
  67. static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
  68. #endif
  69. #ifndef __HAVE_ARCH_CMPXCHG
  70. #warning ACPI uses CMPXCHG, i486 and later hardware
  71. #endif
  72. /* --------------------------------------------------------------------------
  73. Boot-time Configuration
  74. -------------------------------------------------------------------------- */
  75. /*
  76. * The default interrupt routing model is PIC (8259). This gets
  77. * overridden if IOAPICs are enumerated (below).
  78. */
  79. enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
  80. /*
  81. * ISA irqs by default are the first 16 gsis but can be
  82. * any gsi as specified by an interrupt source override.
  83. */
  84. static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
  85. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  86. };
  87. static unsigned int gsi_to_irq(unsigned int gsi)
  88. {
  89. unsigned int irq = gsi + NR_IRQS_LEGACY;
  90. unsigned int i;
  91. for (i = 0; i < NR_IRQS_LEGACY; i++) {
  92. if (isa_irq_to_gsi[i] == gsi) {
  93. return i;
  94. }
  95. }
  96. /* Provide an identity mapping of gsi == irq
  97. * except on truly weird platforms that have
  98. * non isa irqs in the first 16 gsis.
  99. */
  100. if (gsi >= NR_IRQS_LEGACY)
  101. irq = gsi;
  102. else
  103. irq = gsi_top + gsi;
  104. return irq;
  105. }
  106. static u32 irq_to_gsi(int irq)
  107. {
  108. unsigned int gsi;
  109. if (irq < NR_IRQS_LEGACY)
  110. gsi = isa_irq_to_gsi[irq];
  111. else if (irq < gsi_top)
  112. gsi = irq;
  113. else if (irq < (gsi_top + NR_IRQS_LEGACY))
  114. gsi = irq - gsi_top;
  115. else
  116. gsi = 0xffffffff;
  117. return gsi;
  118. }
  119. /*
  120. * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
  121. * to map the target physical address. The problem is that set_fixmap()
  122. * provides a single page, and it is possible that the page is not
  123. * sufficient.
  124. * By using this area, we can map up to MAX_IO_APICS pages temporarily,
  125. * i.e. until the next __va_range() call.
  126. *
  127. * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
  128. * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
  129. * count idx down while incrementing the phys address.
  130. */
  131. char *__init __acpi_map_table(unsigned long phys, unsigned long size)
  132. {
  133. if (!phys || !size)
  134. return NULL;
  135. return early_ioremap(phys, size);
  136. }
  137. void __init __acpi_unmap_table(char *map, unsigned long size)
  138. {
  139. if (!map || !size)
  140. return;
  141. early_iounmap(map, size);
  142. }
  143. #ifdef CONFIG_X86_LOCAL_APIC
  144. static int __init acpi_parse_madt(struct acpi_table_header *table)
  145. {
  146. struct acpi_table_madt *madt = NULL;
  147. if (!cpu_has_apic)
  148. return -EINVAL;
  149. madt = (struct acpi_table_madt *)table;
  150. if (!madt) {
  151. printk(KERN_WARNING PREFIX "Unable to map MADT\n");
  152. return -ENODEV;
  153. }
  154. if (madt->address) {
  155. acpi_lapic_addr = (u64) madt->address;
  156. printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
  157. madt->address);
  158. }
  159. default_acpi_madt_oem_check(madt->header.oem_id,
  160. madt->header.oem_table_id);
  161. return 0;
  162. }
  163. static void __cpuinit acpi_register_lapic(int id, u8 enabled)
  164. {
  165. unsigned int ver = 0;
  166. if (id >= (MAX_LOCAL_APIC-1)) {
  167. printk(KERN_INFO PREFIX "skipped apicid that is too big\n");
  168. return;
  169. }
  170. if (!enabled) {
  171. ++disabled_cpus;
  172. return;
  173. }
  174. if (boot_cpu_physical_apicid != -1U)
  175. ver = apic_version[boot_cpu_physical_apicid];
  176. generic_processor_info(id, ver);
  177. }
  178. static int __init
  179. acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
  180. {
  181. struct acpi_madt_local_x2apic *processor = NULL;
  182. processor = (struct acpi_madt_local_x2apic *)header;
  183. if (BAD_MADT_ENTRY(processor, end))
  184. return -EINVAL;
  185. acpi_table_print_madt_entry(header);
  186. #ifdef CONFIG_X86_X2APIC
  187. /*
  188. * We need to register disabled CPU as well to permit
  189. * counting disabled CPUs. This allows us to size
  190. * cpus_possible_map more accurately, to permit
  191. * to not preallocating memory for all NR_CPUS
  192. * when we use CPU hotplug.
  193. */
  194. acpi_register_lapic(processor->local_apic_id, /* APIC ID */
  195. processor->lapic_flags & ACPI_MADT_ENABLED);
  196. #else
  197. printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
  198. #endif
  199. return 0;
  200. }
  201. static int __init
  202. acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
  203. {
  204. struct acpi_madt_local_apic *processor = NULL;
  205. processor = (struct acpi_madt_local_apic *)header;
  206. if (BAD_MADT_ENTRY(processor, end))
  207. return -EINVAL;
  208. acpi_table_print_madt_entry(header);
  209. /*
  210. * We need to register disabled CPU as well to permit
  211. * counting disabled CPUs. This allows us to size
  212. * cpus_possible_map more accurately, to permit
  213. * to not preallocating memory for all NR_CPUS
  214. * when we use CPU hotplug.
  215. */
  216. acpi_register_lapic(processor->id, /* APIC ID */
  217. processor->lapic_flags & ACPI_MADT_ENABLED);
  218. return 0;
  219. }
  220. static int __init
  221. acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
  222. {
  223. struct acpi_madt_local_sapic *processor = NULL;
  224. processor = (struct acpi_madt_local_sapic *)header;
  225. if (BAD_MADT_ENTRY(processor, end))
  226. return -EINVAL;
  227. acpi_table_print_madt_entry(header);
  228. acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
  229. processor->lapic_flags & ACPI_MADT_ENABLED);
  230. return 0;
  231. }
  232. static int __init
  233. acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
  234. const unsigned long end)
  235. {
  236. struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
  237. lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
  238. if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
  239. return -EINVAL;
  240. acpi_lapic_addr = lapic_addr_ovr->address;
  241. return 0;
  242. }
  243. static int __init
  244. acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
  245. const unsigned long end)
  246. {
  247. struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
  248. x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
  249. if (BAD_MADT_ENTRY(x2apic_nmi, end))
  250. return -EINVAL;
  251. acpi_table_print_madt_entry(header);
  252. if (x2apic_nmi->lint != 1)
  253. printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
  254. return 0;
  255. }
  256. static int __init
  257. acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
  258. {
  259. struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
  260. lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
  261. if (BAD_MADT_ENTRY(lapic_nmi, end))
  262. return -EINVAL;
  263. acpi_table_print_madt_entry(header);
  264. if (lapic_nmi->lint != 1)
  265. printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
  266. return 0;
  267. }
  268. #endif /*CONFIG_X86_LOCAL_APIC */
  269. #ifdef CONFIG_X86_IO_APIC
  270. static int __init
  271. acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
  272. {
  273. struct acpi_madt_io_apic *ioapic = NULL;
  274. ioapic = (struct acpi_madt_io_apic *)header;
  275. if (BAD_MADT_ENTRY(ioapic, end))
  276. return -EINVAL;
  277. acpi_table_print_madt_entry(header);
  278. mp_register_ioapic(ioapic->id,
  279. ioapic->address, ioapic->global_irq_base);
  280. return 0;
  281. }
  282. /*
  283. * Parse Interrupt Source Override for the ACPI SCI
  284. */
  285. static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
  286. {
  287. if (trigger == 0) /* compatible SCI trigger is level */
  288. trigger = 3;
  289. if (polarity == 0) /* compatible SCI polarity is low */
  290. polarity = 3;
  291. /* Command-line over-ride via acpi_sci= */
  292. if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
  293. trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
  294. if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
  295. polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
  296. /*
  297. * mp_config_acpi_legacy_irqs() already setup IRQs < 16
  298. * If GSI is < 16, this will update its flags,
  299. * else it will create a new mp_irqs[] entry.
  300. */
  301. mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
  302. /*
  303. * stash over-ride to indicate we've been here
  304. * and for later update of acpi_gbl_FADT
  305. */
  306. acpi_sci_override_gsi = gsi;
  307. return;
  308. }
  309. static int __init
  310. acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
  311. const unsigned long end)
  312. {
  313. struct acpi_madt_interrupt_override *intsrc = NULL;
  314. intsrc = (struct acpi_madt_interrupt_override *)header;
  315. if (BAD_MADT_ENTRY(intsrc, end))
  316. return -EINVAL;
  317. acpi_table_print_madt_entry(header);
  318. if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
  319. acpi_sci_ioapic_setup(intsrc->source_irq,
  320. intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
  321. (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
  322. intsrc->global_irq);
  323. return 0;
  324. }
  325. if (acpi_skip_timer_override &&
  326. intsrc->source_irq == 0 && intsrc->global_irq == 2) {
  327. printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
  328. return 0;
  329. }
  330. mp_override_legacy_irq(intsrc->source_irq,
  331. intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
  332. (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
  333. intsrc->global_irq);
  334. return 0;
  335. }
  336. static int __init
  337. acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
  338. {
  339. struct acpi_madt_nmi_source *nmi_src = NULL;
  340. nmi_src = (struct acpi_madt_nmi_source *)header;
  341. if (BAD_MADT_ENTRY(nmi_src, end))
  342. return -EINVAL;
  343. acpi_table_print_madt_entry(header);
  344. /* TBD: Support nimsrc entries? */
  345. return 0;
  346. }
  347. #endif /* CONFIG_X86_IO_APIC */
  348. /*
  349. * acpi_pic_sci_set_trigger()
  350. *
  351. * use ELCR to set PIC-mode trigger type for SCI
  352. *
  353. * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
  354. * it may require Edge Trigger -- use "acpi_sci=edge"
  355. *
  356. * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
  357. * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
  358. * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
  359. * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
  360. */
  361. void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
  362. {
  363. unsigned int mask = 1 << irq;
  364. unsigned int old, new;
  365. /* Real old ELCR mask */
  366. old = inb(0x4d0) | (inb(0x4d1) << 8);
  367. /*
  368. * If we use ACPI to set PCI IRQs, then we should clear ELCR
  369. * since we will set it correctly as we enable the PCI irq
  370. * routing.
  371. */
  372. new = acpi_noirq ? old : 0;
  373. /*
  374. * Update SCI information in the ELCR, it isn't in the PCI
  375. * routing tables..
  376. */
  377. switch (trigger) {
  378. case 1: /* Edge - clear */
  379. new &= ~mask;
  380. break;
  381. case 3: /* Level - set */
  382. new |= mask;
  383. break;
  384. }
  385. if (old == new)
  386. return;
  387. printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
  388. outb(new, 0x4d0);
  389. outb(new >> 8, 0x4d1);
  390. }
  391. int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
  392. {
  393. *irq = gsi_to_irq(gsi);
  394. #ifdef CONFIG_X86_IO_APIC
  395. if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
  396. setup_IO_APIC_irq_extra(gsi);
  397. #endif
  398. return 0;
  399. }
  400. EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
  401. int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
  402. {
  403. if (isa_irq >= 16)
  404. return -1;
  405. *gsi = irq_to_gsi(isa_irq);
  406. return 0;
  407. }
  408. static int acpi_register_gsi_pic(struct device *dev, u32 gsi,
  409. int trigger, int polarity)
  410. {
  411. #ifdef CONFIG_PCI
  412. /*
  413. * Make sure all (legacy) PCI IRQs are set as level-triggered.
  414. */
  415. if (trigger == ACPI_LEVEL_SENSITIVE)
  416. eisa_set_level_irq(gsi);
  417. #endif
  418. return gsi;
  419. }
  420. static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi,
  421. int trigger, int polarity)
  422. {
  423. #ifdef CONFIG_X86_IO_APIC
  424. gsi = mp_register_gsi(dev, gsi, trigger, polarity);
  425. #endif
  426. return gsi;
  427. }
  428. int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
  429. int trigger, int polarity) = acpi_register_gsi_pic;
  430. /*
  431. * success: return IRQ number (>=0)
  432. * failure: return < 0
  433. */
  434. int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
  435. {
  436. unsigned int irq;
  437. unsigned int plat_gsi = gsi;
  438. plat_gsi = (*__acpi_register_gsi)(dev, gsi, trigger, polarity);
  439. irq = gsi_to_irq(plat_gsi);
  440. return irq;
  441. }
  442. void __init acpi_set_irq_model_pic(void)
  443. {
  444. acpi_irq_model = ACPI_IRQ_MODEL_PIC;
  445. __acpi_register_gsi = acpi_register_gsi_pic;
  446. acpi_ioapic = 0;
  447. }
  448. void __init acpi_set_irq_model_ioapic(void)
  449. {
  450. acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
  451. __acpi_register_gsi = acpi_register_gsi_ioapic;
  452. acpi_ioapic = 1;
  453. }
  454. /*
  455. * ACPI based hotplug support for CPU
  456. */
  457. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  458. #include <acpi/processor.h>
  459. static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
  460. {
  461. #ifdef CONFIG_ACPI_NUMA
  462. int nid;
  463. nid = acpi_get_node(handle);
  464. if (nid == -1 || !node_online(nid))
  465. return;
  466. #ifdef CONFIG_X86_64
  467. apicid_to_node[physid] = nid;
  468. numa_set_node(cpu, nid);
  469. #else /* CONFIG_X86_32 */
  470. apicid_2_node[physid] = nid;
  471. cpu_to_node_map[cpu] = nid;
  472. #endif
  473. #endif
  474. }
  475. static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
  476. {
  477. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  478. union acpi_object *obj;
  479. struct acpi_madt_local_apic *lapic;
  480. cpumask_var_t tmp_map, new_map;
  481. u8 physid;
  482. int cpu;
  483. int retval = -ENOMEM;
  484. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  485. return -EINVAL;
  486. if (!buffer.length || !buffer.pointer)
  487. return -EINVAL;
  488. obj = buffer.pointer;
  489. if (obj->type != ACPI_TYPE_BUFFER ||
  490. obj->buffer.length < sizeof(*lapic)) {
  491. kfree(buffer.pointer);
  492. return -EINVAL;
  493. }
  494. lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
  495. if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
  496. !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
  497. kfree(buffer.pointer);
  498. return -EINVAL;
  499. }
  500. physid = lapic->id;
  501. kfree(buffer.pointer);
  502. buffer.length = ACPI_ALLOCATE_BUFFER;
  503. buffer.pointer = NULL;
  504. if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
  505. goto out;
  506. if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
  507. goto free_tmp_map;
  508. cpumask_copy(tmp_map, cpu_present_mask);
  509. acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
  510. /*
  511. * If mp_register_lapic successfully generates a new logical cpu
  512. * number, then the following will get us exactly what was mapped
  513. */
  514. cpumask_andnot(new_map, cpu_present_mask, tmp_map);
  515. if (cpumask_empty(new_map)) {
  516. printk ("Unable to map lapic to logical cpu number\n");
  517. retval = -EINVAL;
  518. goto free_new_map;
  519. }
  520. acpi_processor_set_pdc(handle);
  521. cpu = cpumask_first(new_map);
  522. acpi_map_cpu2node(handle, cpu, physid);
  523. *pcpu = cpu;
  524. retval = 0;
  525. free_new_map:
  526. free_cpumask_var(new_map);
  527. free_tmp_map:
  528. free_cpumask_var(tmp_map);
  529. out:
  530. return retval;
  531. }
  532. /* wrapper to silence section mismatch warning */
  533. int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
  534. {
  535. return _acpi_map_lsapic(handle, pcpu);
  536. }
  537. EXPORT_SYMBOL(acpi_map_lsapic);
  538. int acpi_unmap_lsapic(int cpu)
  539. {
  540. per_cpu(x86_cpu_to_apicid, cpu) = -1;
  541. set_cpu_present(cpu, false);
  542. num_processors--;
  543. return (0);
  544. }
  545. EXPORT_SYMBOL(acpi_unmap_lsapic);
  546. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  547. int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
  548. {
  549. /* TBD */
  550. return -EINVAL;
  551. }
  552. EXPORT_SYMBOL(acpi_register_ioapic);
  553. int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
  554. {
  555. /* TBD */
  556. return -EINVAL;
  557. }
  558. EXPORT_SYMBOL(acpi_unregister_ioapic);
  559. static int __init acpi_parse_sbf(struct acpi_table_header *table)
  560. {
  561. struct acpi_table_boot *sb;
  562. sb = (struct acpi_table_boot *)table;
  563. if (!sb) {
  564. printk(KERN_WARNING PREFIX "Unable to map SBF\n");
  565. return -ENODEV;
  566. }
  567. sbf_port = sb->cmos_index; /* Save CMOS port */
  568. return 0;
  569. }
  570. #ifdef CONFIG_HPET_TIMER
  571. #include <asm/hpet.h>
  572. static struct __initdata resource *hpet_res;
  573. static int __init acpi_parse_hpet(struct acpi_table_header *table)
  574. {
  575. struct acpi_table_hpet *hpet_tbl;
  576. hpet_tbl = (struct acpi_table_hpet *)table;
  577. if (!hpet_tbl) {
  578. printk(KERN_WARNING PREFIX "Unable to map HPET\n");
  579. return -ENODEV;
  580. }
  581. if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
  582. printk(KERN_WARNING PREFIX "HPET timers must be located in "
  583. "memory.\n");
  584. return -1;
  585. }
  586. hpet_address = hpet_tbl->address.address;
  587. hpet_blockid = hpet_tbl->sequence;
  588. /*
  589. * Some broken BIOSes advertise HPET at 0x0. We really do not
  590. * want to allocate a resource there.
  591. */
  592. if (!hpet_address) {
  593. printk(KERN_WARNING PREFIX
  594. "HPET id: %#x base: %#lx is invalid\n",
  595. hpet_tbl->id, hpet_address);
  596. return 0;
  597. }
  598. #ifdef CONFIG_X86_64
  599. /*
  600. * Some even more broken BIOSes advertise HPET at
  601. * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
  602. * some noise:
  603. */
  604. if (hpet_address == 0xfed0000000000000UL) {
  605. if (!hpet_force_user) {
  606. printk(KERN_WARNING PREFIX "HPET id: %#x "
  607. "base: 0xfed0000000000000 is bogus\n "
  608. "try hpet=force on the kernel command line to "
  609. "fix it up to 0xfed00000.\n", hpet_tbl->id);
  610. hpet_address = 0;
  611. return 0;
  612. }
  613. printk(KERN_WARNING PREFIX
  614. "HPET id: %#x base: 0xfed0000000000000 fixed up "
  615. "to 0xfed00000.\n", hpet_tbl->id);
  616. hpet_address >>= 32;
  617. }
  618. #endif
  619. printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
  620. hpet_tbl->id, hpet_address);
  621. /*
  622. * Allocate and initialize the HPET firmware resource for adding into
  623. * the resource tree during the lateinit timeframe.
  624. */
  625. #define HPET_RESOURCE_NAME_SIZE 9
  626. hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
  627. hpet_res->name = (void *)&hpet_res[1];
  628. hpet_res->flags = IORESOURCE_MEM;
  629. snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
  630. hpet_tbl->sequence);
  631. hpet_res->start = hpet_address;
  632. hpet_res->end = hpet_address + (1 * 1024) - 1;
  633. return 0;
  634. }
  635. /*
  636. * hpet_insert_resource inserts the HPET resources used into the resource
  637. * tree.
  638. */
  639. static __init int hpet_insert_resource(void)
  640. {
  641. if (!hpet_res)
  642. return 1;
  643. return insert_resource(&iomem_resource, hpet_res);
  644. }
  645. late_initcall(hpet_insert_resource);
  646. #else
  647. #define acpi_parse_hpet NULL
  648. #endif
  649. static int __init acpi_parse_fadt(struct acpi_table_header *table)
  650. {
  651. #ifdef CONFIG_X86_PM_TIMER
  652. /* detect the location of the ACPI PM Timer */
  653. if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
  654. /* FADT rev. 2 */
  655. if (acpi_gbl_FADT.xpm_timer_block.space_id !=
  656. ACPI_ADR_SPACE_SYSTEM_IO)
  657. return 0;
  658. pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
  659. /*
  660. * "X" fields are optional extensions to the original V1.0
  661. * fields, so we must selectively expand V1.0 fields if the
  662. * corresponding X field is zero.
  663. */
  664. if (!pmtmr_ioport)
  665. pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
  666. } else {
  667. /* FADT rev. 1 */
  668. pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
  669. }
  670. if (pmtmr_ioport)
  671. printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
  672. pmtmr_ioport);
  673. #endif
  674. return 0;
  675. }
  676. #ifdef CONFIG_X86_LOCAL_APIC
  677. /*
  678. * Parse LAPIC entries in MADT
  679. * returns 0 on success, < 0 on error
  680. */
  681. static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
  682. {
  683. int count;
  684. if (!cpu_has_apic)
  685. return -ENODEV;
  686. /*
  687. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  688. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  689. */
  690. count =
  691. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
  692. acpi_parse_lapic_addr_ovr, 0);
  693. if (count < 0) {
  694. printk(KERN_ERR PREFIX
  695. "Error parsing LAPIC address override entry\n");
  696. return count;
  697. }
  698. register_lapic_address(acpi_lapic_addr);
  699. return count;
  700. }
  701. static int __init acpi_parse_madt_lapic_entries(void)
  702. {
  703. int count;
  704. int x2count = 0;
  705. if (!cpu_has_apic)
  706. return -ENODEV;
  707. /*
  708. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  709. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  710. */
  711. count =
  712. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
  713. acpi_parse_lapic_addr_ovr, 0);
  714. if (count < 0) {
  715. printk(KERN_ERR PREFIX
  716. "Error parsing LAPIC address override entry\n");
  717. return count;
  718. }
  719. register_lapic_address(acpi_lapic_addr);
  720. count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
  721. acpi_parse_sapic, MAX_LOCAL_APIC);
  722. if (!count) {
  723. x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
  724. acpi_parse_x2apic, MAX_LOCAL_APIC);
  725. count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
  726. acpi_parse_lapic, MAX_LOCAL_APIC);
  727. }
  728. if (!count && !x2count) {
  729. printk(KERN_ERR PREFIX "No LAPIC entries present\n");
  730. /* TBD: Cleanup to allow fallback to MPS */
  731. return -ENODEV;
  732. } else if (count < 0 || x2count < 0) {
  733. printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
  734. /* TBD: Cleanup to allow fallback to MPS */
  735. return count;
  736. }
  737. x2count =
  738. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
  739. acpi_parse_x2apic_nmi, 0);
  740. count =
  741. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
  742. if (count < 0 || x2count < 0) {
  743. printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
  744. /* TBD: Cleanup to allow fallback to MPS */
  745. return count;
  746. }
  747. return 0;
  748. }
  749. #endif /* CONFIG_X86_LOCAL_APIC */
  750. #ifdef CONFIG_X86_IO_APIC
  751. #define MP_ISA_BUS 0
  752. #ifdef CONFIG_X86_ES7000
  753. extern int es7000_plat;
  754. #endif
  755. void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  756. {
  757. int ioapic;
  758. int pin;
  759. struct mpc_intsrc mp_irq;
  760. /*
  761. * Convert 'gsi' to 'ioapic.pin'.
  762. */
  763. ioapic = mp_find_ioapic(gsi);
  764. if (ioapic < 0)
  765. return;
  766. pin = mp_find_ioapic_pin(ioapic, gsi);
  767. /*
  768. * TBD: This check is for faulty timer entries, where the override
  769. * erroneously sets the trigger to level, resulting in a HUGE
  770. * increase of timer interrupts!
  771. */
  772. if ((bus_irq == 0) && (trigger == 3))
  773. trigger = 1;
  774. mp_irq.type = MP_INTSRC;
  775. mp_irq.irqtype = mp_INT;
  776. mp_irq.irqflag = (trigger << 2) | polarity;
  777. mp_irq.srcbus = MP_ISA_BUS;
  778. mp_irq.srcbusirq = bus_irq; /* IRQ */
  779. mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
  780. mp_irq.dstirq = pin; /* INTIN# */
  781. mp_save_irq(&mp_irq);
  782. isa_irq_to_gsi[bus_irq] = gsi;
  783. }
  784. void __init mp_config_acpi_legacy_irqs(void)
  785. {
  786. int i;
  787. struct mpc_intsrc mp_irq;
  788. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  789. /*
  790. * Fabricate the legacy ISA bus (bus #31).
  791. */
  792. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  793. #endif
  794. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  795. pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
  796. #ifdef CONFIG_X86_ES7000
  797. /*
  798. * Older generations of ES7000 have no legacy identity mappings
  799. */
  800. if (es7000_plat == 1)
  801. return;
  802. #endif
  803. /*
  804. * Use the default configuration for the IRQs 0-15. Unless
  805. * overridden by (MADT) interrupt source override entries.
  806. */
  807. for (i = 0; i < 16; i++) {
  808. int ioapic, pin;
  809. unsigned int dstapic;
  810. int idx;
  811. u32 gsi;
  812. /* Locate the gsi that irq i maps to. */
  813. if (acpi_isa_irq_to_gsi(i, &gsi))
  814. continue;
  815. /*
  816. * Locate the IOAPIC that manages the ISA IRQ.
  817. */
  818. ioapic = mp_find_ioapic(gsi);
  819. if (ioapic < 0)
  820. continue;
  821. pin = mp_find_ioapic_pin(ioapic, gsi);
  822. dstapic = mp_ioapics[ioapic].apicid;
  823. for (idx = 0; idx < mp_irq_entries; idx++) {
  824. struct mpc_intsrc *irq = mp_irqs + idx;
  825. /* Do we already have a mapping for this ISA IRQ? */
  826. if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
  827. break;
  828. /* Do we already have a mapping for this IOAPIC pin */
  829. if (irq->dstapic == dstapic && irq->dstirq == pin)
  830. break;
  831. }
  832. if (idx != mp_irq_entries) {
  833. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  834. continue; /* IRQ already used */
  835. }
  836. mp_irq.type = MP_INTSRC;
  837. mp_irq.irqflag = 0; /* Conforming */
  838. mp_irq.srcbus = MP_ISA_BUS;
  839. mp_irq.dstapic = dstapic;
  840. mp_irq.irqtype = mp_INT;
  841. mp_irq.srcbusirq = i; /* Identity mapped */
  842. mp_irq.dstirq = pin;
  843. mp_save_irq(&mp_irq);
  844. }
  845. }
  846. static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
  847. int polarity)
  848. {
  849. #ifdef CONFIG_X86_MPPARSE
  850. struct mpc_intsrc mp_irq;
  851. struct pci_dev *pdev;
  852. unsigned char number;
  853. unsigned int devfn;
  854. int ioapic;
  855. u8 pin;
  856. if (!acpi_ioapic)
  857. return 0;
  858. if (!dev)
  859. return 0;
  860. if (dev->bus != &pci_bus_type)
  861. return 0;
  862. pdev = to_pci_dev(dev);
  863. number = pdev->bus->number;
  864. devfn = pdev->devfn;
  865. pin = pdev->pin;
  866. /* print the entry should happen on mptable identically */
  867. mp_irq.type = MP_INTSRC;
  868. mp_irq.irqtype = mp_INT;
  869. mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
  870. (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
  871. mp_irq.srcbus = number;
  872. mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
  873. ioapic = mp_find_ioapic(gsi);
  874. mp_irq.dstapic = mp_ioapics[ioapic].apicid;
  875. mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
  876. mp_save_irq(&mp_irq);
  877. #endif
  878. return 0;
  879. }
  880. int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
  881. {
  882. int ioapic;
  883. int ioapic_pin;
  884. struct io_apic_irq_attr irq_attr;
  885. if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
  886. return gsi;
  887. /* Don't set up the ACPI SCI because it's already set up */
  888. if (acpi_gbl_FADT.sci_interrupt == gsi)
  889. return gsi;
  890. ioapic = mp_find_ioapic(gsi);
  891. if (ioapic < 0) {
  892. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  893. return gsi;
  894. }
  895. ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
  896. if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
  897. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  898. "%d-%d\n", mp_ioapics[ioapic].apicid,
  899. ioapic_pin);
  900. return gsi;
  901. }
  902. if (enable_update_mptable)
  903. mp_config_acpi_gsi(dev, gsi, trigger, polarity);
  904. set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
  905. trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
  906. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  907. io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
  908. return gsi;
  909. }
  910. /*
  911. * Parse IOAPIC related entries in MADT
  912. * returns 0 on success, < 0 on error
  913. */
  914. static int __init acpi_parse_madt_ioapic_entries(void)
  915. {
  916. int count;
  917. /*
  918. * ACPI interpreter is required to complete interrupt setup,
  919. * so if it is off, don't enumerate the io-apics with ACPI.
  920. * If MPS is present, it will handle them,
  921. * otherwise the system will stay in PIC mode
  922. */
  923. if (acpi_disabled || acpi_noirq)
  924. return -ENODEV;
  925. if (!cpu_has_apic)
  926. return -ENODEV;
  927. /*
  928. * if "noapic" boot option, don't look for IO-APICs
  929. */
  930. if (skip_ioapic_setup) {
  931. printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
  932. "due to 'noapic' option.\n");
  933. return -ENODEV;
  934. }
  935. count =
  936. acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
  937. MAX_IO_APICS);
  938. if (!count) {
  939. printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
  940. return -ENODEV;
  941. } else if (count < 0) {
  942. printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
  943. return count;
  944. }
  945. count =
  946. acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
  947. nr_irqs);
  948. if (count < 0) {
  949. printk(KERN_ERR PREFIX
  950. "Error parsing interrupt source overrides entry\n");
  951. /* TBD: Cleanup to allow fallback to MPS */
  952. return count;
  953. }
  954. /*
  955. * If BIOS did not supply an INT_SRC_OVR for the SCI
  956. * pretend we got one so we can set the SCI flags.
  957. */
  958. if (!acpi_sci_override_gsi)
  959. acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
  960. acpi_gbl_FADT.sci_interrupt);
  961. /* Fill in identity legacy mappings where no override */
  962. mp_config_acpi_legacy_irqs();
  963. count =
  964. acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
  965. nr_irqs);
  966. if (count < 0) {
  967. printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
  968. /* TBD: Cleanup to allow fallback to MPS */
  969. return count;
  970. }
  971. return 0;
  972. }
  973. #else
  974. static inline int acpi_parse_madt_ioapic_entries(void)
  975. {
  976. return -1;
  977. }
  978. #endif /* !CONFIG_X86_IO_APIC */
  979. static void __init early_acpi_process_madt(void)
  980. {
  981. #ifdef CONFIG_X86_LOCAL_APIC
  982. int error;
  983. if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  984. /*
  985. * Parse MADT LAPIC entries
  986. */
  987. error = early_acpi_parse_madt_lapic_addr_ovr();
  988. if (!error) {
  989. acpi_lapic = 1;
  990. smp_found_config = 1;
  991. }
  992. if (error == -EINVAL) {
  993. /*
  994. * Dell Precision Workstation 410, 610 come here.
  995. */
  996. printk(KERN_ERR PREFIX
  997. "Invalid BIOS MADT, disabling ACPI\n");
  998. disable_acpi();
  999. }
  1000. }
  1001. #endif
  1002. }
  1003. static void __init acpi_process_madt(void)
  1004. {
  1005. #ifdef CONFIG_X86_LOCAL_APIC
  1006. int error;
  1007. if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  1008. /*
  1009. * Parse MADT LAPIC entries
  1010. */
  1011. error = acpi_parse_madt_lapic_entries();
  1012. if (!error) {
  1013. acpi_lapic = 1;
  1014. /*
  1015. * Parse MADT IO-APIC entries
  1016. */
  1017. error = acpi_parse_madt_ioapic_entries();
  1018. if (!error) {
  1019. acpi_set_irq_model_ioapic();
  1020. smp_found_config = 1;
  1021. }
  1022. }
  1023. if (error == -EINVAL) {
  1024. /*
  1025. * Dell Precision Workstation 410, 610 come here.
  1026. */
  1027. printk(KERN_ERR PREFIX
  1028. "Invalid BIOS MADT, disabling ACPI\n");
  1029. disable_acpi();
  1030. }
  1031. } else {
  1032. /*
  1033. * ACPI found no MADT, and so ACPI wants UP PIC mode.
  1034. * In the event an MPS table was found, forget it.
  1035. * Boot with "acpi=off" to use MPS on such a system.
  1036. */
  1037. if (smp_found_config) {
  1038. printk(KERN_WARNING PREFIX
  1039. "No APIC-table, disabling MPS\n");
  1040. smp_found_config = 0;
  1041. }
  1042. }
  1043. /*
  1044. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  1045. * processors, where MPS only supports physical.
  1046. */
  1047. if (acpi_lapic && acpi_ioapic)
  1048. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
  1049. "information\n");
  1050. else if (acpi_lapic)
  1051. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  1052. "configuration information\n");
  1053. #endif
  1054. return;
  1055. }
  1056. static int __init disable_acpi_irq(const struct dmi_system_id *d)
  1057. {
  1058. if (!acpi_force) {
  1059. printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
  1060. d->ident);
  1061. acpi_noirq_set();
  1062. }
  1063. return 0;
  1064. }
  1065. static int __init disable_acpi_pci(const struct dmi_system_id *d)
  1066. {
  1067. if (!acpi_force) {
  1068. printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
  1069. d->ident);
  1070. acpi_disable_pci();
  1071. }
  1072. return 0;
  1073. }
  1074. static int __init dmi_disable_acpi(const struct dmi_system_id *d)
  1075. {
  1076. if (!acpi_force) {
  1077. printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
  1078. disable_acpi();
  1079. } else {
  1080. printk(KERN_NOTICE
  1081. "Warning: DMI blacklist says broken, but acpi forced\n");
  1082. }
  1083. return 0;
  1084. }
  1085. /*
  1086. * Force ignoring BIOS IRQ0 pin2 override
  1087. */
  1088. static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
  1089. {
  1090. /*
  1091. * The ati_ixp4x0_rev() early PCI quirk should have set
  1092. * the acpi_skip_timer_override flag already:
  1093. */
  1094. if (!acpi_skip_timer_override) {
  1095. WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
  1096. pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
  1097. d->ident);
  1098. acpi_skip_timer_override = 1;
  1099. }
  1100. return 0;
  1101. }
  1102. /*
  1103. * If your system is blacklisted here, but you find that acpi=force
  1104. * works for you, please contact linux-acpi@vger.kernel.org
  1105. */
  1106. static struct dmi_system_id __initdata acpi_dmi_table[] = {
  1107. /*
  1108. * Boxes that need ACPI disabled
  1109. */
  1110. {
  1111. .callback = dmi_disable_acpi,
  1112. .ident = "IBM Thinkpad",
  1113. .matches = {
  1114. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1115. DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
  1116. },
  1117. },
  1118. /*
  1119. * Boxes that need ACPI PCI IRQ routing disabled
  1120. */
  1121. {
  1122. .callback = disable_acpi_irq,
  1123. .ident = "ASUS A7V",
  1124. .matches = {
  1125. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
  1126. DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
  1127. /* newer BIOS, Revision 1011, does work */
  1128. DMI_MATCH(DMI_BIOS_VERSION,
  1129. "ASUS A7V ACPI BIOS Revision 1007"),
  1130. },
  1131. },
  1132. {
  1133. /*
  1134. * Latest BIOS for IBM 600E (1.16) has bad pcinum
  1135. * for LPC bridge, which is needed for the PCI
  1136. * interrupt links to work. DSDT fix is in bug 5966.
  1137. * 2645, 2646 model numbers are shared with 600/600E/600X
  1138. */
  1139. .callback = disable_acpi_irq,
  1140. .ident = "IBM Thinkpad 600 Series 2645",
  1141. .matches = {
  1142. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1143. DMI_MATCH(DMI_BOARD_NAME, "2645"),
  1144. },
  1145. },
  1146. {
  1147. .callback = disable_acpi_irq,
  1148. .ident = "IBM Thinkpad 600 Series 2646",
  1149. .matches = {
  1150. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1151. DMI_MATCH(DMI_BOARD_NAME, "2646"),
  1152. },
  1153. },
  1154. /*
  1155. * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
  1156. */
  1157. { /* _BBN 0 bug */
  1158. .callback = disable_acpi_pci,
  1159. .ident = "ASUS PR-DLS",
  1160. .matches = {
  1161. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  1162. DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
  1163. DMI_MATCH(DMI_BIOS_VERSION,
  1164. "ASUS PR-DLS ACPI BIOS Revision 1010"),
  1165. DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
  1166. },
  1167. },
  1168. {
  1169. .callback = disable_acpi_pci,
  1170. .ident = "Acer TravelMate 36x Laptop",
  1171. .matches = {
  1172. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1173. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  1174. },
  1175. },
  1176. {}
  1177. };
  1178. /* second table for DMI checks that should run after early-quirks */
  1179. static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
  1180. /*
  1181. * HP laptops which use a DSDT reporting as HP/SB400/10000,
  1182. * which includes some code which overrides all temperature
  1183. * trip points to 16C if the INTIN2 input of the I/O APIC
  1184. * is enabled. This input is incorrectly designated the
  1185. * ISA IRQ 0 via an interrupt source override even though
  1186. * it is wired to the output of the master 8259A and INTIN0
  1187. * is not connected at all. Force ignoring BIOS IRQ0 pin2
  1188. * override in that cases.
  1189. */
  1190. {
  1191. .callback = dmi_ignore_irq0_timer_override,
  1192. .ident = "HP nx6115 laptop",
  1193. .matches = {
  1194. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1195. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
  1196. },
  1197. },
  1198. {
  1199. .callback = dmi_ignore_irq0_timer_override,
  1200. .ident = "HP NX6125 laptop",
  1201. .matches = {
  1202. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1203. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
  1204. },
  1205. },
  1206. {
  1207. .callback = dmi_ignore_irq0_timer_override,
  1208. .ident = "HP NX6325 laptop",
  1209. .matches = {
  1210. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1211. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
  1212. },
  1213. },
  1214. {
  1215. .callback = dmi_ignore_irq0_timer_override,
  1216. .ident = "HP 6715b laptop",
  1217. .matches = {
  1218. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1219. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
  1220. },
  1221. },
  1222. {}
  1223. };
  1224. /*
  1225. * acpi_boot_table_init() and acpi_boot_init()
  1226. * called from setup_arch(), always.
  1227. * 1. checksums all tables
  1228. * 2. enumerates lapics
  1229. * 3. enumerates io-apics
  1230. *
  1231. * acpi_table_init() is separate to allow reading SRAT without
  1232. * other side effects.
  1233. *
  1234. * side effects of acpi_boot_init:
  1235. * acpi_lapic = 1 if LAPIC found
  1236. * acpi_ioapic = 1 if IOAPIC found
  1237. * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
  1238. * if acpi_blacklisted() acpi_disabled = 1;
  1239. * acpi_irq_model=...
  1240. * ...
  1241. */
  1242. void __init acpi_boot_table_init(void)
  1243. {
  1244. dmi_check_system(acpi_dmi_table);
  1245. /*
  1246. * If acpi_disabled, bail out
  1247. */
  1248. if (acpi_disabled)
  1249. return;
  1250. /*
  1251. * Initialize the ACPI boot-time table parser.
  1252. */
  1253. if (acpi_table_init()) {
  1254. disable_acpi();
  1255. return;
  1256. }
  1257. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1258. /*
  1259. * blacklist may disable ACPI entirely
  1260. */
  1261. if (acpi_blacklisted()) {
  1262. if (acpi_force) {
  1263. printk(KERN_WARNING PREFIX "acpi=force override\n");
  1264. } else {
  1265. printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
  1266. disable_acpi();
  1267. return;
  1268. }
  1269. }
  1270. }
  1271. int __init early_acpi_boot_init(void)
  1272. {
  1273. /*
  1274. * If acpi_disabled, bail out
  1275. */
  1276. if (acpi_disabled)
  1277. return 1;
  1278. /*
  1279. * Process the Multiple APIC Description Table (MADT), if present
  1280. */
  1281. early_acpi_process_madt();
  1282. return 0;
  1283. }
  1284. int __init acpi_boot_init(void)
  1285. {
  1286. /* those are executed after early-quirks are executed */
  1287. dmi_check_system(acpi_dmi_table_late);
  1288. /*
  1289. * If acpi_disabled, bail out
  1290. */
  1291. if (acpi_disabled)
  1292. return 1;
  1293. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1294. /*
  1295. * set sci_int and PM timer address
  1296. */
  1297. acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
  1298. /*
  1299. * Process the Multiple APIC Description Table (MADT), if present
  1300. */
  1301. acpi_process_madt();
  1302. acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
  1303. if (!acpi_noirq)
  1304. x86_init.pci.init = pci_acpi_init;
  1305. return 0;
  1306. }
  1307. static int __init parse_acpi(char *arg)
  1308. {
  1309. if (!arg)
  1310. return -EINVAL;
  1311. /* "acpi=off" disables both ACPI table parsing and interpreter */
  1312. if (strcmp(arg, "off") == 0) {
  1313. disable_acpi();
  1314. }
  1315. /* acpi=force to over-ride black-list */
  1316. else if (strcmp(arg, "force") == 0) {
  1317. acpi_force = 1;
  1318. acpi_disabled = 0;
  1319. }
  1320. /* acpi=strict disables out-of-spec workarounds */
  1321. else if (strcmp(arg, "strict") == 0) {
  1322. acpi_strict = 1;
  1323. }
  1324. /* acpi=rsdt use RSDT instead of XSDT */
  1325. else if (strcmp(arg, "rsdt") == 0) {
  1326. acpi_rsdt_forced = 1;
  1327. }
  1328. /* "acpi=noirq" disables ACPI interrupt routing */
  1329. else if (strcmp(arg, "noirq") == 0) {
  1330. acpi_noirq_set();
  1331. }
  1332. /* "acpi=copy_dsdt" copys DSDT */
  1333. else if (strcmp(arg, "copy_dsdt") == 0) {
  1334. acpi_gbl_copy_dsdt_locally = 1;
  1335. } else {
  1336. /* Core will printk when we return error. */
  1337. return -EINVAL;
  1338. }
  1339. return 0;
  1340. }
  1341. early_param("acpi", parse_acpi);
  1342. /* FIXME: Using pci= for an ACPI parameter is a travesty. */
  1343. static int __init parse_pci(char *arg)
  1344. {
  1345. if (arg && strcmp(arg, "noacpi") == 0)
  1346. acpi_disable_pci();
  1347. return 0;
  1348. }
  1349. early_param("pci", parse_pci);
  1350. int __init acpi_mps_check(void)
  1351. {
  1352. #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
  1353. /* mptable code is not built-in*/
  1354. if (acpi_disabled || acpi_noirq) {
  1355. printk(KERN_WARNING "MPS support code is not built-in.\n"
  1356. "Using acpi=off or acpi=noirq or pci=noacpi "
  1357. "may have problem\n");
  1358. return 1;
  1359. }
  1360. #endif
  1361. return 0;
  1362. }
  1363. #ifdef CONFIG_X86_IO_APIC
  1364. static int __init parse_acpi_skip_timer_override(char *arg)
  1365. {
  1366. acpi_skip_timer_override = 1;
  1367. return 0;
  1368. }
  1369. early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
  1370. static int __init parse_acpi_use_timer_override(char *arg)
  1371. {
  1372. acpi_use_timer_override = 1;
  1373. return 0;
  1374. }
  1375. early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
  1376. #endif /* CONFIG_X86_IO_APIC */
  1377. static int __init setup_acpi_sci(char *s)
  1378. {
  1379. if (!s)
  1380. return -EINVAL;
  1381. if (!strcmp(s, "edge"))
  1382. acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
  1383. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1384. else if (!strcmp(s, "level"))
  1385. acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
  1386. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1387. else if (!strcmp(s, "high"))
  1388. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
  1389. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1390. else if (!strcmp(s, "low"))
  1391. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
  1392. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1393. else
  1394. return -EINVAL;
  1395. return 0;
  1396. }
  1397. early_param("acpi_sci", setup_acpi_sci);
  1398. int __acpi_acquire_global_lock(unsigned int *lock)
  1399. {
  1400. unsigned int old, new, val;
  1401. do {
  1402. old = *lock;
  1403. new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
  1404. val = cmpxchg(lock, old, new);
  1405. } while (unlikely (val != old));
  1406. return (new < 3) ? -1 : 0;
  1407. }
  1408. int __acpi_release_global_lock(unsigned int *lock)
  1409. {
  1410. unsigned int old, new, val;
  1411. do {
  1412. old = *lock;
  1413. new = old & ~0x3;
  1414. val = cmpxchg(lock, old, new);
  1415. } while (unlikely (val != old));
  1416. return old & 0x1;
  1417. }