2 * acpi.c - Linux ACPI driver
4 * Copyright (C) 1999-2000 Andrew Henroid
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See http://www.geocities.com/SiliconValley/Hardware/3165/
23 * for the user-level ACPI stuff
26 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/08/31
27 * - check copy*user return
28 * - get rid of check_region
29 * - get rid of verify_area
30 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/09/28
31 * - do proper release on failure in acpi_claim_ioports and acpi_init
34 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/string.h>
38 #include <linux/miscdevice.h>
39 #include <linux/sched.h>
40 #include <linux/time.h>
41 #include <linux/wait.h>
42 #include <linux/spinlock.h>
43 #include <linux/ioport.h>
44 #include <linux/slab.h>
46 #include <linux/pci.h>
47 #include <asm/uaccess.h>
49 #include <linux/sysctl.h>
50 #include <linux/delay.h>
52 #include <linux/acpi.h>
55 * Yes, it's unfortunate that we are relying on get_cmos_time
56 * because it is slow (> 1 sec.) and i386 only. It might be better
57 * to use some of the code from drivers/char/rtc.c in the near future
59 extern unsigned long get_cmos_time(void);
61 static int acpi_do_ulong(ctl_table
*ctl
,
66 static int acpi_do_table(ctl_table
*ctl
,
71 static int acpi_do_event_reg(ctl_table
*ctl
,
76 static int acpi_do_event(ctl_table
*ctl
,
81 static int acpi_do_sleep(ctl_table
*ctl
,
86 static void acpi_release(unsigned long start
, unsigned long size
);
88 static struct ctl_table_header
*acpi_sysctl
= NULL
;
90 // current system sleep state (S0 - S4)
91 static acpi_sstate_t acpi_sleep_state
= ACPI_S0
;
93 static unsigned long acpi_sleep_start
= 0;
95 static spinlock_t acpi_event_lock
= SPIN_LOCK_UNLOCKED
;
96 static volatile u32 acpi_pm1_status
= 0;
97 static volatile u32 acpi_gpe_status
= 0;
98 static volatile u32 acpi_gpe_level
= 0;
99 static volatile acpi_sstate_t acpi_event_state
= ACPI_S0
;
100 static DECLARE_WAIT_QUEUE_HEAD(acpi_event_wait
);
102 /* Make it impossible to enter C2/C3 until after we've initialized */
103 static unsigned long acpi_enter_lvl2_lat
= ACPI_INFINITE_LAT
;
104 static unsigned long acpi_enter_lvl3_lat
= ACPI_INFINITE_LAT
;
105 static unsigned long acpi_p_lvl2_lat
= ACPI_INFINITE_LAT
;
106 static unsigned long acpi_p_lvl3_lat
= ACPI_INFINITE_LAT
;
109 struct Cx_stat_struct
{
116 static int acpi_do_stat(ctl_table
*ctl
,
124 struct Cx_stat_struct
*stat
= (struct Cx_stat_struct
*)ctl
->data
;
138 size
= sprintf(str
, "%9lu %9lu %9lu %9lu",
147 return copy_to_user(buffer
, str
, size
) ? -EFAULT
: 0;
150 static void cx_statistics(unsigned int x
, unsigned long time
)
152 struct Cx_stat_struct
*stat
= Cx_stat
+ (x
-1);
155 if (time
<= stat
->min
-1)
157 if (time
> stat
->max
)
159 stat
->avg
= time
+ (stat
->avg
>> 1);
162 static unsigned long acpi_p_blk
= 0;
164 static int acpi_p_lvl2_tested
= 0;
165 static int acpi_p_lvl3_tested
= 0;
169 ACPI_ENABLED
= 0x00000000, // use ACPI if present
170 ACPI_DISABLED
= 0x00000001, // never use ACPI
171 ACPI_TABLES_ONLY
= 0x00000002, // never use chipset-specific driver
172 ACPI_CHIPSET_ONLY
= 0x00000004, // always use chipset-specific driver
173 ACPI_IGNORE_ERRATA
= 0x00000008, // ignore any listed platform errata
174 ACPI_COPY_TABLES
= 0x00000010, // copy ACPI tables before use
175 ACPI_TRUST_TABLES
= 0x00000020, // use tables even after ioremap fails
176 ACPI_SCI_DISABLED
= 0x00000040, // never enable ACPI (info. only)
177 ACPI_C2_DISABLED
= 0x00000080, // never enter C2
178 ACPI_C3_DISABLED
= 0x00000100, // never enter C3
179 ACPI_S1_DISABLED
= 0x00000200, // never enter S1
180 ACPI_S5_DISABLED
= 0x00000400, // never enter S5
183 struct acpi_option_info
189 static struct acpi_option_info acpi_options
[] =
191 {"on", ACPI_ENABLED
},
192 {"off", ACPI_DISABLED
},
193 {"tables", ACPI_TABLES_ONLY
},
194 {"chipset", ACPI_CHIPSET_ONLY
},
195 {"no-errata", ACPI_IGNORE_ERRATA
},
196 {"copy-tables", ACPI_COPY_TABLES
},
197 {"trust-tables", ACPI_TRUST_TABLES
},
198 {"no-sci", ACPI_SCI_DISABLED
},
199 {"no-c2", ACPI_C2_DISABLED
},
200 {"no-c3", ACPI_C3_DISABLED
},
201 {"no-s1", ACPI_S1_DISABLED
},
202 {"no-s5", ACPI_S5_DISABLED
},
206 static unsigned long acpi_opts
= ACPI_ENABLED
;
208 struct acpi_errata_info
210 const char *signature
; // table signature (eg. "RSDT")
211 const char *oem
; // OEM name
212 const char *oem_table
; // OEM table identifier (optional)
213 u32 oem_rev
; // OEM table revision (optional)
214 unsigned long options
; // errata options
218 * We must identify systems that need ACPI_TRUST_TABLES solely from the
219 * RSDP ("RSD PTR "). All other options should be flagged from the
220 * RSDT ("RSDT") which can be better identified.
222 struct acpi_errata_info acpi_errata
[] =
224 {"RSD PTR ", "AMI ", NULL
, 0, ACPI_TRUST_TABLES
| ACPI_COPY_TABLES
},
228 // bits 8-15 are SLP_TYPa, bits 0-7 are SLP_TYPb
229 static unsigned long acpi_slp_typ
[] =
231 ACPI_SLP_TYP_DISABLED
, /* S0 */
232 ACPI_SLP_TYP_DISABLED
, /* S1 */
233 ACPI_SLP_TYP_DISABLED
, /* S2 */
234 ACPI_SLP_TYP_DISABLED
, /* S3 */
235 ACPI_SLP_TYP_DISABLED
, /* S4 */
236 ACPI_SLP_TYP_DISABLED
/* S5 */
239 struct acpi_table_info
241 u32 expected_signature
;
244 struct acpi_table
*table
;
249 static struct acpi_table_info acpi_facp
250 = {ACPI_FACP_SIG
, sizeof(struct acpi_facp
), NULL
, 0, 0};
251 static struct acpi_table_info acpi_dsdt
= {ACPI_DSDT_SIG
, 0, NULL
, 0, 0};
252 static struct acpi_table_info acpi_facs
253 = {ACPI_FACS_SIG
, sizeof(struct acpi_facs
), NULL
, 0, 0};
254 static rwlock_t acpi_do_table_lock
= RW_LOCK_UNLOCKED
;
256 static struct ctl_table acpi_table
[] =
258 {ACPI_FACP
, "facp", &acpi_facp
, 0, 0644, NULL
, &acpi_do_table
},
260 {ACPI_DSDT
, "dsdt", &acpi_dsdt
, 0, 0644, NULL
, &acpi_do_table
},
262 {ACPI_FACS
, "facs", &acpi_facs
, 0, 0644, NULL
, &acpi_do_table
},
264 {ACPI_PM1_ENABLE
, "pm1_enable",
266 0600, NULL
, &acpi_do_event_reg
},
268 {ACPI_GPE_ENABLE
, "gpe_enable",
270 0600, NULL
, &acpi_do_event_reg
},
272 {ACPI_GPE_LEVEL
, "gpe_level",
274 0600, NULL
, &acpi_do_event_reg
},
276 {ACPI_EVENT
, "event", NULL
, 0, 0400, NULL
, &acpi_do_event
},
278 {ACPI_P_BLK
, "p_blk",
279 &acpi_p_blk
, sizeof(acpi_p_blk
),
280 0600, NULL
, &acpi_do_ulong
},
282 {ACPI_P_LVL2_LAT
, "p_lvl2_lat",
283 &acpi_p_lvl2_lat
, sizeof(acpi_p_lvl2_lat
),
284 0644, NULL
, &acpi_do_ulong
},
286 {ACPI_P_LVL3_LAT
, "p_lvl3_lat",
287 &acpi_p_lvl3_lat
, sizeof(acpi_p_lvl3_lat
),
288 0644, NULL
, &acpi_do_ulong
},
290 {ACPI_ENTER_LVL2_LAT
, "enter_lvl2_lat",
291 &acpi_enter_lvl2_lat
, sizeof(acpi_enter_lvl2_lat
),
292 0644, NULL
, &acpi_do_ulong
},
294 {ACPI_ENTER_LVL3_LAT
, "enter_lvl3_lat",
295 &acpi_enter_lvl3_lat
, sizeof(acpi_enter_lvl3_lat
),
296 0644, NULL
, &acpi_do_ulong
},
298 {ACPI_C1_TIME
, "c1_time",
299 Cx_stat
+0, sizeof(struct Cx_stat_struct
),
300 0644, NULL
, &acpi_do_stat
},
302 {ACPI_C2_TIME
, "c2_time",
303 Cx_stat
+1, sizeof(struct Cx_stat_struct
),
304 0644, NULL
, &acpi_do_stat
},
306 {ACPI_C3_TIME
, "c3_time",
307 Cx_stat
+2, sizeof(struct Cx_stat_struct
),
308 0644, NULL
, &acpi_do_stat
},
310 {ACPI_S0_SLP_TYP
, "s0_slp_typ",
311 &acpi_slp_typ
[ACPI_S0
], sizeof(acpi_slp_typ
[ACPI_S0
]),
312 0600, NULL
, &acpi_do_ulong
},
314 {ACPI_S1_SLP_TYP
, "s1_slp_typ",
315 &acpi_slp_typ
[ACPI_S1
], sizeof(acpi_slp_typ
[ACPI_S1
]),
316 0600, NULL
, &acpi_do_ulong
},
318 {ACPI_S5_SLP_TYP
, "s5_slp_typ",
319 &acpi_slp_typ
[ACPI_S5
], sizeof(acpi_slp_typ
[ACPI_S5
]),
320 0600, NULL
, &acpi_do_ulong
},
322 {ACPI_SLEEP
, "sleep", NULL
, 0, 0600, NULL
, &acpi_do_sleep
},
327 static struct ctl_table acpi_dir_table
[] =
329 {CTL_ACPI
, "acpi", NULL
, 0, 0555, acpi_table
},
333 static u32
FASTCALL(acpi_read_pm1_control(struct acpi_facp
*));
334 static u32
FASTCALL(acpi_read_pm1_status(struct acpi_facp
*));
335 static u32
FASTCALL(acpi_read_pm1_enable(struct acpi_facp
*));
336 static u32
FASTCALL(acpi_read_gpe_status(struct acpi_facp
*));
337 static u32
FASTCALL(acpi_read_gpe_enable(struct acpi_facp
*));
339 static void FASTCALL(acpi_write_pm1_control(struct acpi_facp
*, u32
));
340 static void FASTCALL(acpi_write_pm1_status(struct acpi_facp
*, u32
));
341 static void FASTCALL(acpi_write_pm1_enable(struct acpi_facp
*, u32
));
342 static void FASTCALL(acpi_write_gpe_status(struct acpi_facp
*, u32
));
343 static void FASTCALL(acpi_write_gpe_enable(struct acpi_facp
*, u32
));
346 * Get the value of the PM1 control register (SCI_EN, ...)
348 static u32
acpi_read_pm1_control(struct acpi_facp
*facp
)
352 value
= inw(facp
->pm1a_cnt
);
354 value
|= inw(facp
->pm1b_cnt
);
359 * Set the value of the PM1 control register (BM_RLD, ...)
361 static void acpi_write_pm1_control(struct acpi_facp
*facp
, u32 value
)
364 outw(value
, facp
->pm1a_cnt
);
366 outw(value
, facp
->pm1b_cnt
);
370 * Get the value of the fixed event status register
372 static u32
acpi_read_pm1_status(struct acpi_facp
*facp
)
376 value
= inw(facp
->pm1a_evt
);
378 value
|= inw(facp
->pm1b_evt
);
383 * Set the value of the fixed event status register (clear events)
385 static void acpi_write_pm1_status(struct acpi_facp
*facp
, u32 value
)
388 outw(value
, facp
->pm1a_evt
);
390 outw(value
, facp
->pm1b_evt
);
394 * Get the value of the fixed event enable register
396 static u32
acpi_read_pm1_enable(struct acpi_facp
*facp
)
398 int offset
= facp
->pm1_evt_len
>> 1;
401 value
= inw(facp
->pm1a_evt
+ offset
);
403 value
|= inw(facp
->pm1b_evt
+ offset
);
408 * Set the value of the fixed event enable register (enable events)
410 static void acpi_write_pm1_enable(struct acpi_facp
*facp
, u32 value
)
412 int offset
= facp
->pm1_evt_len
>> 1;
414 outw(value
, facp
->pm1a_evt
+ offset
);
416 outw(value
, facp
->pm1b_evt
+ offset
);
420 * Get the value of the general-purpose event status register
422 static u32
acpi_read_gpe_status(struct acpi_facp
*facp
)
428 size
= facp
->gpe1_len
>> 1;
429 for (i
= size
- 1; i
>= 0; i
--)
430 value
= (value
<< 8) | inb(facp
->gpe1
+ i
);
433 size
= facp
->gpe0_len
>> 1;
434 for (i
= size
- 1; i
>= 0; i
--)
435 value
= (value
<< 8) | inb(facp
->gpe0
+ i
);
441 * Set the value of the general-purpose event status register (clear events)
443 static void acpi_write_gpe_status(struct acpi_facp
*facp
, u32 value
)
448 size
= facp
->gpe0_len
>> 1;
449 for (i
= 0; i
< size
; i
++) {
450 outb(value
& 0xff, facp
->gpe0
+ i
);
455 size
= facp
->gpe1_len
>> 1;
456 for (i
= 0; i
< size
; i
++) {
457 outb(value
& 0xff, facp
->gpe1
+ i
);
464 * Get the value of the general-purpose event enable register
466 static u32
acpi_read_gpe_enable(struct acpi_facp
*facp
)
471 offset
= facp
->gpe0_len
>> 1;
473 size
= facp
->gpe1_len
>> 1;
474 for (i
= size
- 1; i
>= 0; i
--) {
475 value
= (value
<< 8) | inb(facp
->gpe1
+ offset
+ i
);
479 size
= facp
->gpe0_len
>> 1;
480 for (i
= size
- 1; i
>= 0; i
--)
481 value
= (value
<< 8) | inb(facp
->gpe0
+ offset
+ i
);
487 * Set the value of the general-purpose event enable register (enable events)
489 static void acpi_write_gpe_enable(struct acpi_facp
*facp
, u32 value
)
493 offset
= facp
->gpe0_len
>> 1;
495 for (i
= 0; i
< offset
; i
++) {
496 outb(value
& 0xff, facp
->gpe0
+ offset
+ i
);
501 offset
= facp
->gpe1_len
>> 1;
502 for (i
= 0; i
< offset
; i
++) {
503 outb(value
& 0xff, facp
->gpe1
+ offset
+ i
);
510 * Map an ACPI table into virtual memory
512 static struct acpi_table
*__init
acpi_map_table(u32 addr
)
514 struct acpi_table
*table
= NULL
;
516 // map table header to determine size
517 table
= (struct acpi_table
*)
518 ioremap((unsigned long) addr
,
519 sizeof(struct acpi_table
));
521 unsigned long table_size
= table
->length
;
523 // remap entire table
524 table
= (struct acpi_table
*)
525 ioremap((unsigned long) addr
, table_size
);
528 if (!table
&& addr
< virt_to_phys(high_memory
)) {
529 /* sometimes we see ACPI tables in low memory
530 * and not reserved by the memory map (E820) code,
531 * who is at fault for this? BIOS?
534 "ACPI: unreserved table memory @ 0x%p!\n",
537 if (acpi_opts
& ACPI_TRUST_TABLES
) {
538 /* OK, trust that the table is there
539 * if it isn't you'll get an OOPS here
542 table
= (struct acpi_table
*)
544 sig
= table
->signature
;
552 * Unmap an ACPI table from virtual memory
554 static void acpi_unmap_table(struct acpi_table
*table
)
556 // iounmap ignores addresses within physical memory
562 * Initialize an ACPI table
564 static int acpi_init_table(struct acpi_table_info
*info
,
568 struct acpi_table
*table
= (struct acpi_table
*) data
;
574 if (!table
|| table
->signature
!= info
->expected_signature
)
577 if (mapped
&& (acpi_opts
& ACPI_COPY_TABLES
)) {
578 struct acpi_table
*copy
579 = kmalloc(table
->length
, GFP_KERNEL
);
582 memcpy(copy
, table
, table
->length
);
588 info
->size
= (size_t) table
->length
;
589 info
->mapped
= mapped
;
594 * Destroy an ACPI table
596 static void acpi_destroy_table(struct acpi_table_info
*info
)
600 acpi_unmap_table(info
->table
);
608 * Match ACPI table and set options based on platform errata, if any
610 static int __init
acpi_find_errata(struct acpi_table
*table
)
612 struct acpi_errata_info
*info
;
615 for (info
= acpi_errata
; info
->signature
&& info
->oem
; info
++) {
616 size
= strlen(info
->signature
);
617 if (memcmp(&table
->signature
, info
->signature
, size
))
619 if (strcmp(info
->signature
, "RSD PTR ")) {
620 // ordinary ACPI table
621 size
= strlen(info
->oem
);
622 if (memcmp(table
->oem
, info
->oem
, size
))
624 if (info
->oem_table
) {
625 size
= strlen(info
->oem_table
);
626 if (memcmp(table
->oem_table
,
631 if (info
->oem_rev
&& table
->oem_rev
!= info
->oem_rev
)
635 // special handling for RSDP
636 size
= strlen(info
->oem
);
637 if (memcmp(((struct acpi_rsdp
*) table
)->oem
,
644 "ACPI: found platform errata 0x%08lx\n",
646 acpi_opts
|= info
->options
;
653 * Locate and map ACPI tables
655 static int __init
acpi_find_tables(void)
657 struct acpi_rsdp
*rsdp
;
658 struct acpi_table
*rsdt
;
660 int rsdt_entry_count
;
663 // search BIOS memory for RSDP
664 for (i
= ACPI_BIOS_ROM_BASE
; i
< ACPI_BIOS_ROM_END
; i
+= 16) {
665 rsdp
= (struct acpi_rsdp
*) phys_to_virt(i
);
666 if (rsdp
->signature
[0] == ACPI_RSDP1_SIG
667 && rsdp
->signature
[1] == ACPI_RSDP2_SIG
) {
671 // strip trailing space and print OEM identifier
672 memcpy(oem
, rsdp
->oem
, 6);
675 j
> 0 && (oem
[j
] == '\0' || oem
[j
] == ' ');
679 printk(KERN_INFO
"ACPI: \"%s\" found at 0x%p\n",
685 if (i
>= ACPI_BIOS_ROM_END
)
688 // find any errata based on the RSDP
689 if (!acpi_find_errata((struct acpi_table
*) rsdp
)) {
690 if (acpi_opts
& ACPI_DISABLED
)
692 else if (acpi_opts
& ACPI_CHIPSET_ONLY
)
696 // fetch RSDT from RSDP
697 rsdt
= acpi_map_table(rsdp
->rsdt
);
699 printk(KERN_ERR
"ACPI: missing RSDT at 0x%p\n",
703 else if (rsdt
->signature
!= ACPI_RSDT_SIG
) {
704 printk(KERN_ERR
"ACPI: bad RSDT at 0x%p (%08x)\n",
705 (void*) rsdp
->rsdt
, (unsigned) rsdt
->signature
);
706 acpi_unmap_table(rsdt
);
710 // find any errata based on the RSDT
711 if (!acpi_find_errata(rsdt
)) {
712 if (acpi_opts
& ACPI_DISABLED
)
714 else if (acpi_opts
& ACPI_CHIPSET_ONLY
)
718 // search RSDT for FACP
719 acpi_facp
.table
= NULL
;
720 rsdt_entry
= (u32
*) (rsdt
+ 1);
721 rsdt_entry_count
= (int) ((rsdt
->length
- sizeof(*rsdt
)) >> 2);
722 while (rsdt_entry_count
) {
723 struct acpi_table
*dt
= acpi_map_table(*rsdt_entry
);
724 if (!acpi_init_table(&acpi_facp
, dt
, 1)) {
725 struct acpi_facp
*facp
726 = (struct acpi_facp
*) acpi_facp
.table
;
727 struct acpi_table
*facs
;
729 // map DSDT if it exists
730 if ((dt
= acpi_map_table(facp
->dsdt
))) {
731 if (acpi_init_table(&acpi_dsdt
, dt
, 1))
732 acpi_unmap_table(dt
);
736 * map FACS if it exists
738 if ((facs
= acpi_map_table(facp
->facs
))) {
739 if (acpi_init_table(&acpi_facs
,facs
,1))
740 acpi_unmap_table(facs
);
745 acpi_unmap_table(dt
);
752 acpi_unmap_table(rsdt
);
754 if (!acpi_facp
.table
) {
755 printk(KERN_ERR
"ACPI: missing FACP\n");
762 * Unmap or destroy ACPI tables
764 static void acpi_destroy_tables(void)
766 acpi_destroy_table(&acpi_facs
);
767 acpi_destroy_table(&acpi_dsdt
);
768 acpi_destroy_table(&acpi_facp
);
772 * Init PIIX4 device, create a fake FACP
774 static int __init
acpi_init_piix4(struct pci_dev
*dev
)
776 struct acpi_facp
*facp
;
781 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
782 if (!(cmd
& PCI_COMMAND_IO
))
785 pci_read_config_byte(dev
, ACPI_PIIX4_PMREGMISC
, &pmregmisc
);
786 if (!(pmregmisc
& ACPI_PIIX4_PMIOSE
))
789 base
= pci_resource_start (dev
, PCI_BRIDGE_RESOURCES
);
793 printk(KERN_INFO
"ACPI: found PIIX4 at 0x%04x\n", base
);
795 facp
= kmalloc(sizeof(struct acpi_facp
), GFP_KERNEL
);
799 memset(facp
, 0, sizeof(struct acpi_facp
));
800 facp
->hdr
.signature
= ACPI_FACP_SIG
;
801 facp
->hdr
.length
= sizeof(struct acpi_facp
);
802 facp
->int_model
= ACPI_PIIX4_INT_MODEL
;
803 facp
->sci_int
= ACPI_PIIX4_SCI_INT
;
804 facp
->smi_cmd
= ACPI_PIIX4_SMI_CMD
;
805 facp
->acpi_enable
= ACPI_PIIX4_ACPI_ENABLE
;
806 facp
->acpi_disable
= ACPI_PIIX4_ACPI_DISABLE
;
807 facp
->s4bios_req
= ACPI_PIIX4_S4BIOS_REQ
;
808 facp
->pm1a_evt
= base
+ ACPI_PIIX4_PM1_EVT
;
809 facp
->pm1a_cnt
= base
+ ACPI_PIIX4_PM1_CNT
;
810 facp
->pm2_cnt
= ACPI_PIIX4_PM2_CNT
;
811 facp
->pm_tmr
= base
+ ACPI_PIIX4_PM_TMR
;
812 facp
->gpe0
= base
+ ACPI_PIIX4_GPE0
;
813 facp
->pm1_evt_len
= ACPI_PIIX4_PM1_EVT_LEN
;
814 facp
->pm1_cnt_len
= ACPI_PIIX4_PM1_CNT_LEN
;
815 facp
->pm2_cnt_len
= ACPI_PIIX4_PM2_CNT_LEN
;
816 facp
->pm_tm_len
= ACPI_PIIX4_PM_TM_LEN
;
817 facp
->gpe0_len
= ACPI_PIIX4_GPE0_LEN
;
818 facp
->p_lvl2_lat
= (__u16
) ACPI_INFINITE_LAT
;
819 facp
->p_lvl3_lat
= (__u16
) ACPI_INFINITE_LAT
;
821 acpi_init_table(&acpi_facp
, facp
, 0);
822 acpi_init_table(&acpi_dsdt
, NULL
, 0);
824 acpi_p_blk
= base
+ ACPI_PIIX4_P_BLK
;
830 * Init VIA ACPI device and create a fake FACP
832 static int __init
acpi_init_via(struct pci_dev
*dev
)
834 struct acpi_facp
*facp
;
838 pci_read_config_byte(dev
, 0x41, &tmp
);
842 base
= pci_resource_start(dev
, PCI_BRIDGE_RESOURCES
);
844 base
= pci_resource_start(dev
, PCI_BASE_ADDRESS_4
);
849 pci_read_config_byte(dev
, 0x42, &irq
);
851 printk(KERN_INFO
"ACPI: found %s at 0x%04x\n", dev
->name
, base
);
853 facp
= kmalloc(sizeof(struct acpi_facp
), GFP_KERNEL
);
857 memset(facp
, 0, sizeof(struct acpi_facp
));
858 facp
->hdr
.signature
= ACPI_FACP_SIG
;
859 facp
->hdr
.length
= sizeof(struct acpi_facp
);
860 facp
->int_model
= ACPI_VIA_INT_MODEL
;
862 facp
->smi_cmd
= base
+ ACPI_VIA_SMI_CMD
;
863 facp
->acpi_enable
= ACPI_VIA_ACPI_ENABLE
;
864 facp
->acpi_disable
= ACPI_VIA_ACPI_DISABLE
;
865 facp
->pm1a_evt
= base
+ ACPI_VIA_PM1_EVT
;
866 facp
->pm1a_cnt
= base
+ ACPI_VIA_PM1_CNT
;
867 facp
->pm_tmr
= base
+ ACPI_VIA_PM_TMR
;
868 facp
->gpe0
= base
+ ACPI_VIA_GPE0
;
870 facp
->pm1_evt_len
= ACPI_VIA_PM1_EVT_LEN
;
871 facp
->pm1_cnt_len
= ACPI_VIA_PM1_CNT_LEN
;
872 facp
->pm_tm_len
= ACPI_VIA_PM_TM_LEN
;
873 facp
->gpe0_len
= ACPI_VIA_GPE0_LEN
;
874 facp
->p_lvl2_lat
= (__u16
) ACPI_INFINITE_LAT
;
875 facp
->p_lvl3_lat
= (__u16
) ACPI_INFINITE_LAT
;
877 facp
->duty_offset
= ACPI_VIA_DUTY_OFFSET
;
878 facp
->duty_width
= ACPI_VIA_DUTY_WIDTH
;
880 facp
->day_alarm
= ACPI_VIA_DAY_ALARM
;
881 facp
->mon_alarm
= ACPI_VIA_MON_ALARM
;
882 facp
->century
= ACPI_VIA_CENTURY
;
884 acpi_init_table(&acpi_facp
, facp
, 0);
885 acpi_init_table(&acpi_dsdt
, NULL
, 0);
887 acpi_p_blk
= base
+ ACPI_VIA_P_BLK
;
900 /* indexed by value of each enum in acpi_chip_t */
903 int (*chip_init
)(struct pci_dev
*dev
);
912 static struct pci_device_id acpi_pci_tbl
[] __initdata
=
914 {0x8086, 0x7113, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CH_INTEL_PIIX4
},
915 {0x1106, 0x3040, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CH_VIA_586
},
916 {0x1106, 0x3057, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CH_VIA_686A
},
917 {0,} /* terminate list */
920 static int __init
acpi_probe(struct pci_dev
*dev
,
921 const struct pci_device_id
*id
)
923 return acpi_chip_info
[id
->driver_data
].chip_init(dev
);
926 static struct pci_driver acpi_driver
=
929 id_table
: acpi_pci_tbl
,
932 static int pci_driver_registered
= 0;
935 * Locate a known ACPI chipset
937 static int __init
acpi_find_chipset(void)
939 if (pci_register_driver(&acpi_driver
) < 1)
942 pci_driver_registered
= 1;
948 * Handle an ACPI SCI (fixed or general purpose event)
950 static void acpi_irq(int irq
, void *dev_id
, struct pt_regs
*regs
)
952 struct acpi_facp
*facp
= (struct acpi_facp
*) acpi_facp
.table
;
953 u32 pm1_status
, gpe_status
, gpe_level
, gpe_edge
;
956 // detect and clear fixed events
957 pm1_status
= (acpi_read_pm1_status(facp
) & acpi_read_pm1_enable(facp
));
958 acpi_write_pm1_status(facp
, pm1_status
);
960 // detect and handle general-purpose events
961 gpe_status
= (acpi_read_gpe_status(facp
) & acpi_read_gpe_enable(facp
));
962 gpe_level
= gpe_status
& acpi_gpe_level
;
964 // disable level-triggered events (re-enabled after handling)
965 acpi_write_gpe_enable(facp
,
966 acpi_read_gpe_enable(facp
) & ~gpe_level
);
968 gpe_edge
= gpe_status
& ~gpe_level
;
970 // clear edge-triggered events
971 while (acpi_read_gpe_status(facp
) & gpe_edge
)
972 acpi_write_gpe_status(facp
, gpe_edge
);
975 // notify process waiting on /dev/acpi
976 spin_lock_irqsave(&acpi_event_lock
, flags
);
977 acpi_pm1_status
|= pm1_status
;
978 acpi_gpe_status
|= gpe_status
;
979 spin_unlock_irqrestore(&acpi_event_lock
, flags
);
980 acpi_event_state
= acpi_sleep_state
;
981 wake_up_interruptible(&acpi_event_wait
);
985 * Is SCI to be enabled?
988 acpi_sci_enabled(void)
990 return !(acpi_opts
& ACPI_SCI_DISABLED
);
994 * Is ACPI enabled or not?
996 static inline int acpi_is_enabled(struct acpi_facp
*facp
)
998 return ((acpi_read_pm1_control(facp
) & ACPI_SCI_EN
) ? 1:0);
1004 static int acpi_enable(struct acpi_facp
*facp
)
1006 if (facp
->smi_cmd
&& acpi_sci_enabled())
1007 outb(facp
->acpi_enable
, facp
->smi_cmd
);
1008 return (acpi_is_enabled(facp
) ? 0:-1);
1014 static int acpi_disable(struct acpi_facp
*facp
)
1016 if (facp
->smi_cmd
&& acpi_sci_enabled()) {
1017 // disable and clear any pending events
1018 acpi_write_gpe_enable(facp
, 0);
1019 while (acpi_read_gpe_status(facp
)) {
1020 acpi_write_gpe_status(facp
,
1021 acpi_read_gpe_status(facp
));
1023 acpi_write_pm1_enable(facp
, 0);
1024 acpi_write_pm1_status(facp
, acpi_read_pm1_status(facp
));
1026 /* writing acpi_disable to smi_cmd would be appropriate
1027 * here but this causes a nasty crash on many systems
1034 static inline int bm_activity(struct acpi_facp
*facp
)
1036 return acpi_read_pm1_status(facp
) & ACPI_BM
;
1039 static inline void clear_bm_activity(struct acpi_facp
*facp
)
1041 acpi_write_pm1_status(facp
, ACPI_BM
);
1044 static void sleep_on_busmaster(struct acpi_facp
*facp
)
1046 u32 pm1_cntr
= acpi_read_pm1_control(facp
);
1047 if (pm1_cntr
& ACPI_BM_RLD
) {
1048 pm1_cntr
&= ~ACPI_BM_RLD
;
1049 acpi_write_pm1_control(facp
, pm1_cntr
);
1053 static void wake_on_busmaster(struct acpi_facp
*facp
)
1055 u32 pm1_cntr
= acpi_read_pm1_control(facp
);
1056 if (!(pm1_cntr
& ACPI_BM_RLD
)) {
1057 pm1_cntr
|= ACPI_BM_RLD
;
1058 acpi_write_pm1_control(facp
, pm1_cntr
);
1060 clear_bm_activity(facp
);
1063 /* The ACPI timer is just the low 24 bits */
1064 #define TIME_BEGIN(tmr) inl(tmr)
1065 #define TIME_END(tmr, begin) ((inl(tmr) - (begin)) & 0x00ffffff)
1069 * Idle loop (uniprocessor only)
1071 static void acpi_idle(void)
1073 static int sleep_level
= 1;
1074 struct acpi_facp
*facp
= (struct acpi_facp
*) acpi_facp
.table
;
1076 if (!facp
|| !facp
->pm_tmr
|| !acpi_p_blk
)
1077 goto not_initialized
;
1080 * start from the previous sleep level..
1082 if (sleep_level
== 1)
1084 if (sleep_level
== 2)
1088 if (!acpi_p_lvl3_tested
) {
1089 printk(KERN_INFO
"ACPI C3 works\n");
1090 acpi_p_lvl3_tested
= 1;
1092 wake_on_busmaster(facp
);
1094 goto sleep3_with_arbiter
;
1098 unsigned int pm_tmr
= facp
->pm_tmr
;
1101 if (current
->need_resched
)
1103 if (bm_activity(facp
))
1106 time
= TIME_BEGIN(pm_tmr
);
1107 inb(acpi_p_blk
+ ACPI_P_LVL3
);
1108 inl(pm_tmr
); /* Dummy read, force synchronization with the PMU */
1109 time
= TIME_END(pm_tmr
, time
);
1112 cx_statistics(3, time
);
1113 if (time
< acpi_p_lvl3_lat
)
1117 sleep3_with_arbiter
:
1121 unsigned int pm2_cntr
= facp
->pm2_cnt
;
1122 unsigned int pm_tmr
= facp
->pm_tmr
;
1125 if (current
->need_resched
)
1127 if (bm_activity(facp
))
1130 time
= TIME_BEGIN(pm_tmr
);
1131 arbiter
= inb(pm2_cntr
) & ~ACPI_ARB_DIS
;
1132 outb(arbiter
| ACPI_ARB_DIS
, pm2_cntr
); /* Disable arbiter, park on CPU */
1133 inb(acpi_p_blk
+ ACPI_P_LVL3
);
1134 inl(pm_tmr
); /* Dummy read, force synchronization with the PMU */
1135 time
= TIME_END(pm_tmr
, time
);
1136 outb(arbiter
, pm2_cntr
); /* Enable arbiter again.. */
1139 cx_statistics(3, time
);
1140 if (time
< acpi_p_lvl3_lat
)
1146 if (!acpi_p_lvl2_tested
) {
1147 printk(KERN_INFO
"ACPI C2 works\n");
1148 acpi_p_lvl2_tested
= 1;
1150 wake_on_busmaster(facp
); /* Required to track BM activity.. */
1153 unsigned int pm_tmr
= facp
->pm_tmr
;
1156 if (current
->need_resched
)
1159 time
= TIME_BEGIN(pm_tmr
);
1160 inb(acpi_p_blk
+ ACPI_P_LVL2
);
1161 inl(pm_tmr
); /* Dummy read, force synchronization with the PMU */
1162 time
= TIME_END(pm_tmr
, time
);
1165 cx_statistics(2, time
);
1166 if (time
< acpi_p_lvl2_lat
)
1168 if (bm_activity(facp
)) {
1169 clear_bm_activity(facp
);
1172 if (time
> acpi_enter_lvl3_lat
)
1178 sleep_on_busmaster(facp
);
1181 unsigned int pm_tmr
= facp
->pm_tmr
;
1184 if (current
->need_resched
)
1186 time
= TIME_BEGIN(pm_tmr
);
1187 __asm__
__volatile__("sti ; hlt": : :"memory");
1188 time
= TIME_END(pm_tmr
, time
);
1189 cx_statistics(1, time
);
1190 if (time
> acpi_enter_lvl2_lat
)
1197 if (current
->need_resched
)
1199 __asm__
__volatile__("sti ; hlt": : :"memory");
1207 * Put all devices into specified D-state
1209 static int acpi_enter_dx(acpi_dstate_t state
)
1213 if (state
== ACPI_D0
)
1214 status
= pm_send_all(PM_RESUME
, (void*) state
);
1216 status
= pm_send_all(PM_SUSPEND
, (void*) state
);
1222 * Update system time from real-time clock
1224 static void acpi_update_clock(void)
1226 if (acpi_sleep_start
) {
1227 unsigned long delta
;
1230 delta
= get_cmos_time() - acpi_sleep_start
;
1231 do_gettimeofday(&tv
);
1233 do_settimeofday(&tv
);
1235 acpi_sleep_start
= 0;
1240 * Enter system sleep state
1242 static int acpi_enter_sx(acpi_sstate_t state
)
1244 unsigned long slp_typ
;
1245 u16 typa
, typb
, value
;
1246 struct acpi_facp
*facp
;
1248 slp_typ
= acpi_slp_typ
[(int) state
];
1249 if (slp_typ
== ACPI_SLP_TYP_DISABLED
)
1252 // bits 8-15 are SLP_TYPa, bits 0-7 are SLP_TYPb
1253 typa
= (slp_typ
>> 8) & 0xff;
1254 typb
= slp_typ
& 0xff;
1256 typa
= ((typa
<< ACPI_SLP_TYP_SHIFT
) & ACPI_SLP_TYP_MASK
);
1257 typb
= ((typb
<< ACPI_SLP_TYP_SHIFT
) & ACPI_SLP_TYP_MASK
);
1259 acpi_sleep_start
= get_cmos_time();
1260 acpi_enter_dx(ACPI_D3
);
1261 // disable interrupts globally while suspended
1263 acpi_sleep_state
= state
;
1265 facp
= (struct acpi_facp
*) acpi_facp
.table
;
1267 // clear wake status
1268 acpi_write_pm1_status(facp
, ACPI_WAK
);
1270 // set SLP_TYPa/b and SLP_EN
1271 if (facp
->pm1a_cnt
) {
1272 value
= inw(facp
->pm1a_cnt
) & ~ACPI_SLP_TYP_MASK
;
1273 outw(value
| typa
| ACPI_SLP_EN
, facp
->pm1a_cnt
);
1275 if (facp
->pm1b_cnt
) {
1276 value
= inw(facp
->pm1b_cnt
) & ~ACPI_SLP_TYP_MASK
;
1277 outw(value
| typb
| ACPI_SLP_EN
, facp
->pm1b_cnt
);
1280 // wait until S1 is entered
1281 while (!(acpi_read_pm1_status(facp
) & ACPI_WAK
)) ;
1282 // finished sleeping, update system time
1283 acpi_update_clock();
1284 acpi_enter_dx(ACPI_D0
);
1285 // reenable interrupts globally after resume
1287 acpi_sleep_state
= ACPI_S0
;
1293 * Enter soft-off (S5)
1295 static void acpi_power_off(void)
1297 acpi_enter_sx(ACPI_S5
);
1301 * Claim I/O port if available
1303 static int acpi_claim(unsigned long start
, unsigned long size
)
1306 if (!request_region(start
, size
, "acpi"))
1312 * Claim ACPI I/O ports
1314 static int acpi_claim_ioports(struct acpi_facp
*facp
)
1316 // we don't get a guarantee of contiguity for any of the ACPI registers
1317 if (acpi_claim(facp
->pm1a_evt
, facp
->pm1_evt_len
))
1319 if (acpi_claim(facp
->pm1b_evt
, facp
->pm1_evt_len
))
1320 goto release_pm1a_evt
;
1321 if (acpi_claim(facp
->pm1a_cnt
, facp
->pm1_cnt_len
))
1322 goto release_pm1b_evt
;
1323 if (acpi_claim(facp
->pm1b_cnt
, facp
->pm1_cnt_len
))
1324 goto release_pm1a_cnt
;
1325 if (acpi_claim(facp
->pm_tmr
, facp
->pm_tm_len
))
1326 goto release_pm1b_cnt
;
1327 if (acpi_claim(facp
->gpe0
, facp
->gpe0_len
))
1328 goto release_pm_tmr
;
1329 if (acpi_claim(facp
->gpe1
, facp
->gpe1_len
))
1332 release_gpe0
: acpi_release(facp
->gpe0
, facp
->gpe0_len
);
1333 release_pm_tmr
: acpi_release(facp
->pm_tmr
, facp
->pm_tm_len
);
1334 release_pm1b_cnt
: acpi_release(facp
->pm1b_cnt
, facp
->pm1_cnt_len
);
1335 release_pm1a_cnt
: acpi_release(facp
->pm1a_cnt
, facp
->pm1_cnt_len
);
1336 release_pm1b_evt
: acpi_release(facp
->pm1b_evt
, facp
->pm1_evt_len
);
1337 release_pm1a_evt
: acpi_release(facp
->pm1a_evt
, facp
->pm1_evt_len
);
1338 return_ebusy
: return -EBUSY
;
1342 * Release I/O port if claimed
1344 static void acpi_release(unsigned long start
, unsigned long size
)
1347 release_region(start
, size
);
1351 * Free ACPI I/O ports
1353 static int acpi_release_ioports(struct acpi_facp
*facp
)
1355 // we don't get a guarantee of contiguity for any of the ACPI registers
1356 acpi_release(facp
->gpe1
, facp
->gpe1_len
);
1357 acpi_release(facp
->gpe0
, facp
->gpe0_len
);
1358 acpi_release(facp
->pm_tmr
, facp
->pm_tm_len
);
1359 acpi_release(facp
->pm1b_cnt
, facp
->pm1_cnt_len
);
1360 acpi_release(facp
->pm1a_cnt
, facp
->pm1_cnt_len
);
1361 acpi_release(facp
->pm1b_evt
, facp
->pm1_evt_len
);
1362 acpi_release(facp
->pm1a_evt
, facp
->pm1_evt_len
);
1367 * Determine if modification of value is permitted
1370 acpi_verify_mod(int ctl_name
)
1373 case ACPI_PM1_ENABLE
:
1374 case ACPI_GPE_ENABLE
:
1375 case ACPI_GPE_LEVEL
:
1376 if (!acpi_sci_enabled())
1379 case ACPI_P_LVL2_LAT
:
1380 case ACPI_ENTER_LVL2_LAT
:
1381 if (acpi_opts
& ACPI_C2_DISABLED
)
1384 case ACPI_P_LVL3_LAT
:
1385 case ACPI_ENTER_LVL3_LAT
:
1386 if (acpi_opts
& ACPI_C3_DISABLED
)
1389 case ACPI_S1_SLP_TYP
:
1391 if (acpi_opts
& ACPI_S1_DISABLED
)
1394 case ACPI_S5_SLP_TYP
:
1395 if (acpi_opts
& ACPI_S5_DISABLED
)
1403 * Examine/modify value
1405 static int acpi_do_ulong(ctl_table
*ctl
,
1411 char str
[2 * sizeof(unsigned long) + 4], *strend
;
1421 val
= *(unsigned long*) ctl
->data
;
1422 size
= sprintf(str
, "0x%08lx\n", val
);
1424 if (copy_to_user(buffer
, str
, size
))
1432 if (acpi_verify_mod(ctl
->ctl_name
))
1435 size
= sizeof(str
) - 1;
1438 if (copy_from_user(str
, buffer
, size
))
1441 val
= simple_strtoul(str
, &strend
, 0);
1444 *(unsigned long*) ctl
->data
= val
;
1447 file
->f_pos
+= *len
;
1452 * Determine if user buffer contains a valid table
1454 static int acpi_verify_table(void *buffer
,
1456 struct acpi_table_info
*info
)
1458 struct acpi_table hdr
;
1461 if (size
< sizeof(struct acpi_table
))
1464 if (copy_from_user(&hdr
, buffer
, sizeof(hdr
)))
1467 table_size
= (size_t) hdr
.length
;
1468 if (hdr
.signature
!= info
->expected_signature
1469 || table_size
< size
1470 || (info
->expected_size
1471 && table_size
!= info
->expected_size
))
1478 * Examine/replace an ACPI table
1480 static int acpi_do_table(ctl_table
*ctl
,
1486 struct acpi_table_info
*info
= (struct acpi_table_info
*) ctl
->data
;
1498 read_lock(&acpi_do_table_lock
);
1499 if (info
->table
&& file
->f_pos
< info
->size
) {
1500 data
= (u8
*) info
->table
+ file
->f_pos
;
1501 size
= info
->size
- file
->f_pos
;
1504 if (copy_to_user(buffer
, data
, size
))
1507 read_unlock(&acpi_do_table_lock
);
1509 else if (file
->f_pos
) {
1510 // table body replacement
1511 write_lock(&acpi_do_table_lock
);
1512 if (info
->table
&& file
->f_pos
< info
->size
) {
1513 data
= (u8
*) info
->table
+ file
->f_pos
;
1514 size
= info
->size
- file
->f_pos
;
1517 if (copy_from_user(data
, buffer
, size
))
1520 write_unlock(&acpi_do_table_lock
);
1523 // table header/body replacement
1524 struct acpi_table hdr
;
1527 // make sure we are being given a valid table
1528 error
= acpi_verify_table(buffer
, *len
, info
);
1531 if (copy_from_user(&hdr
, buffer
, sizeof(hdr
)))
1533 table_size
= (size_t) hdr
.length
;
1535 write_lock(&acpi_do_table_lock
);
1537 data
= (u8
*) info
->table
;
1540 if (!data
|| info
->mapped
|| table_size
!= info
->size
) {
1541 // allocate a (different sized) table
1542 data
= kmalloc(table_size
, GFP_KERNEL
);
1544 memset(data
, 0, table_size
);
1545 memcpy(data
, &hdr
, sizeof(hdr
));
1546 acpi_destroy_table(info
);
1547 acpi_init_table(info
, data
, 0);
1553 if (copy_from_user(data
, buffer
, size
)) {
1554 acpi_destroy_table(info
);
1558 write_unlock(&acpi_do_table_lock
);
1565 file
->f_pos
+= size
;
1570 * Examine/modify event register
1572 static int acpi_do_event_reg(ctl_table
*ctl
,
1578 struct acpi_facp
*facp
= (struct acpi_facp
*) acpi_facp
.table
;
1579 char str
[2 * sizeof(u32
) + 4], *strend
;
1590 switch (ctl
->ctl_name
) {
1591 case ACPI_PM1_ENABLE
:
1592 val
= acpi_read_pm1_enable(facp
);
1594 case ACPI_GPE_ENABLE
:
1595 val
= acpi_read_gpe_enable(facp
);
1597 case ACPI_GPE_LEVEL
:
1598 val
= acpi_gpe_level
;
1602 size
= sprintf(str
, "0x%08x\n", val
);
1604 if (copy_to_user(buffer
, str
, size
))
1613 if (acpi_verify_mod(ctl
->ctl_name
))
1617 size
= sizeof(str
) - 1;
1620 if (copy_from_user(str
, buffer
, size
))
1623 val
= (u32
) simple_strtoul(str
, &strend
, 0);
1627 // store value in register
1628 switch (ctl
->ctl_name
) {
1629 case ACPI_PM1_ENABLE
:
1630 // clear previously disabled events
1631 enabling
= (val
& ~acpi_read_pm1_enable(facp
));
1632 acpi_write_pm1_status(facp
, enabling
);
1635 // enable ACPI unless it is already
1636 if (!acpi_is_enabled(facp
))
1639 else if (!acpi_read_gpe_enable(facp
)) {
1640 // disable ACPI unless it is already
1641 if (acpi_is_enabled(facp
))
1645 acpi_write_pm1_enable(facp
, val
);
1647 case ACPI_GPE_ENABLE
:
1648 // clear previously disabled events
1650 & ~acpi_read_gpe_enable(facp
));
1651 while (acpi_read_gpe_status(facp
) & enabling
)
1652 acpi_write_gpe_status(facp
, enabling
);
1655 // enable ACPI unless it is already
1656 if (!acpi_is_enabled(facp
))
1659 else if (!acpi_read_pm1_enable(facp
)) {
1660 // disable ACPI unless it is already
1661 if (acpi_is_enabled(facp
))
1665 acpi_write_gpe_enable(facp
, val
);
1667 case ACPI_GPE_LEVEL
:
1668 acpi_gpe_level
= val
;
1673 file
->f_pos
+= *len
;
1678 * Wait for next event
1680 static int acpi_do_event(ctl_table
*ctl
,
1686 u32 pm1_status
= 0, gpe_status
= 0;
1687 acpi_sstate_t event_state
= 0;
1693 if (*len
< sizeof(str
)) {
1699 unsigned long flags
;
1701 // we need an atomic exchange here
1702 spin_lock_irqsave(&acpi_event_lock
, flags
);
1703 pm1_status
= acpi_pm1_status
;
1704 acpi_pm1_status
= 0;
1705 gpe_status
= acpi_gpe_status
;
1706 acpi_gpe_status
= 0;
1707 spin_unlock_irqrestore(&acpi_event_lock
, flags
);
1708 event_state
= acpi_event_state
;
1710 if (pm1_status
|| gpe_status
)
1713 // wait for an event to arrive
1714 interruptible_sleep_on(&acpi_event_wait
);
1715 if (signal_pending(current
))
1716 return -ERESTARTSYS
;
1719 size
= sprintf(str
, "0x%08x 0x%08x 0x%01x\n",
1723 if (copy_to_user(buffer
, str
, size
))
1726 file
->f_pos
+= size
;
1732 * Enter system sleep state
1734 static int acpi_do_sleep(ctl_table
*ctl
,
1748 if (acpi_verify_mod(ctl
->ctl_name
) || acpi_enter_sx(ACPI_S1
))
1751 file
->f_pos
+= *len
;
1756 * Parse command line options
1758 static int __init
acpi_setup(char *str
)
1760 while (str
&& *str
) {
1761 struct acpi_option_info
*opt
= acpi_options
;
1763 if (!strncmp(str
, opt
->name
, strlen(opt
->name
))) {
1764 acpi_opts
|= opt
->value
;
1769 str
= strpbrk(str
, ",");
1771 str
+= strspn(str
, ",");
1775 printk(KERN_INFO
"ACPI: options 0x%08lx\n", acpi_opts
);
1781 * kernel/module command line interfaces are both "acpi=OPTION,OPTION,..."
1783 __setup("acpi=", acpi_setup
);
1785 static char * __initdata acpi
= NULL
;
1787 MODULE_DESCRIPTION("ACPI driver");
1788 MODULE_PARM(acpi
, "s");
1789 MODULE_PARM_DESC(acpi
, "ACPI driver command line");
1792 * Initialize and enable ACPI
1794 int __init
acpi_init(void)
1796 struct acpi_facp
*facp
= NULL
;
1801 if (acpi_opts
& ACPI_DISABLED
) {
1804 else if (acpi_opts
& ACPI_TABLES_ONLY
) {
1805 if (acpi_find_tables())
1808 else if (acpi_opts
& ACPI_CHIPSET_ONLY
) {
1809 if (acpi_find_chipset())
1813 switch (acpi_find_tables()) {
1815 // found valid ACPI tables
1818 // found no ACPI tables, try chipset-specific
1819 if (acpi_find_chipset())
1823 // found broken ACPI tables
1828 facp
= (struct acpi_facp
*) acpi_facp
.table
;
1830 if (PM_IS_ACTIVE()) {
1831 printk(KERN_NOTICE
"acpi: APM is already active.\n");
1837 * Internally we always keep latencies in timer
1838 * ticks, which is simpler and more consistent (what is
1839 * an uS to us?). Besides, that gives people more
1840 * control in the /proc interfaces.
1842 if (facp
->p_lvl2_lat
1843 && facp
->p_lvl2_lat
<= ACPI_MAX_P_LVL2_LAT
1844 && !acpi_verify_mod(ACPI_P_LVL2_LAT
)) {
1845 acpi_p_lvl2_lat
= ACPI_uS_TO_TMR_TICKS(facp
->p_lvl2_lat
);
1846 acpi_enter_lvl2_lat
= ACPI_uS_TO_TMR_TICKS(ACPI_TMR_HZ
/ 1000);
1848 if (facp
->p_lvl3_lat
1849 && facp
->p_lvl3_lat
<= ACPI_MAX_P_LVL3_LAT
1850 && !acpi_verify_mod(ACPI_P_LVL3_LAT
)) {
1851 acpi_p_lvl3_lat
= ACPI_uS_TO_TMR_TICKS(facp
->p_lvl3_lat
);
1853 = ACPI_uS_TO_TMR_TICKS(facp
->p_lvl3_lat
* 5);
1856 if (acpi_claim_ioports(facp
)) {
1857 printk(KERN_ERR
"ACPI: I/O port allocation failed\n");
1862 && acpi_sci_enabled()
1863 && request_irq(facp
->sci_int
,
1865 SA_INTERRUPT
| SA_SHIRQ
,
1868 printk(KERN_ERR
"ACPI: SCI (IRQ%d) allocation failed\n",
1870 goto cleanup_ioports
;
1873 #ifndef CONFIG_ACPI_S1_SLEEP
1874 acpi_opts
|= ACPI_S1_DISABLED
;
1877 acpi_sysctl
= register_sysctl_table(acpi_dir_table
, 1);
1881 pm_power_off
= acpi_power_off
;
1884 * Set up the ACPI idle function. Note that we can't really
1885 * do this with multiple CPU's, we'd need a per-CPU ACPI
1889 if (smp_num_cpus
> 1)
1894 pm_idle
= acpi_idle
;
1898 free_irq(facp
->sci_int
, &acpi_facp
);
1900 acpi_release_ioports(facp
);
1902 if (pci_driver_registered
)
1903 pci_unregister_driver(&acpi_driver
);
1904 acpi_destroy_tables();
1910 * Disable and deinitialize ACPI
1912 void __exit
acpi_exit(void)
1914 struct acpi_facp
*facp
= (struct acpi_facp
*) acpi_facp
.table
;
1917 pm_power_off
= NULL
;
1919 unregister_sysctl_table(acpi_sysctl
);
1921 acpi_release_ioports(facp
);
1923 if (facp
->sci_int
&& acpi_sci_enabled())
1924 free_irq(facp
->sci_int
, &acpi_facp
);
1926 acpi_destroy_tables();
1928 if (pci_driver_registered
)
1929 pci_unregister_driver(&acpi_driver
);
1934 module_init(acpi_init
);
1935 module_exit(acpi_exit
);