boot.c 40 KB

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