boot.c 40 KB

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