boot.c 43 KB

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