boot.c 40 KB

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