boot.c 40 KB

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