boot.c 41 KB

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