boot.c 41 KB

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