boot.c 39 KB

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