boot.c 39 KB

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