boot.c 40 KB

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