boot.c 39 KB

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