boot.c 39 KB

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