boot.c 39 KB

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