boot.c 41 KB

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