boot.c 41 KB

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