boot.c 43 KB

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