boot.c 40 KB

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