boot.c 42 KB

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