diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 7f23432a4ffd..7b76fd592902 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi.c,v 1.68 2005/02/27 00:26:58 perry Exp $ */ +/* $NetBSD: acpi.c,v 1.69 2005/05/02 14:53:59 kochi Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.68 2005/02/27 00:26:58 perry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.69 2005/05/02 14:53:59 kochi Exp $"); #include "opt_acpi.h" @@ -949,6 +949,36 @@ acpi_match_hid(ACPI_DEVICE_INFO *ad, const char * const *ids) return 0; } +/* + * acpi_set_wake_gpe + * + * Set GPE as both Runtime and Wake + */ +void +acpi_set_wake_gpe(ACPI_HANDLE handle) +{ + ACPI_BUFFER buf; + ACPI_STATUS rv; + ACPI_OBJECT *p, *elt; + + rv = acpi_eval_struct(handle, METHOD_NAME__PRW, &buf); + if (ACPI_FAILURE(rv)) + return; /* just ignore */ + + p = buf.Pointer; + if (p->Type != ACPI_TYPE_PACKAGE || p->Package.Count < 2) + goto out; /* just ignore */ + + elt = p->Package.Elements; + + /* TBD: package support */ + AcpiSetGpeType(NULL, elt[0].Integer.Value, ACPI_GPE_TYPE_WAKE_RUN); + AcpiEnableGpe(NULL, elt[0].Integer.Value, ACPI_NOT_ISR); + + out: + AcpiOsFree(buf.Pointer); +} + /***************************************************************************** * ACPI sleep support. diff --git a/sys/dev/acpi/acpi_button.c b/sys/dev/acpi/acpi_button.c index 8efa96350894..09c3d62f39dd 100644 --- a/sys/dev/acpi/acpi_button.c +++ b/sys/dev/acpi/acpi_button.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_button.c,v 1.16 2004/05/01 12:03:48 kochi Exp $ */ +/* $NetBSD: acpi_button.c,v 1.17 2005/05/02 14:54:00 kochi Exp $ */ /* * Copyright 2001, 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.16 2004/05/01 12:03:48 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.17 2005/05/02 14:54:00 kochi Exp $"); #include #include @@ -146,6 +146,8 @@ acpibut_attach(struct device *parent, struct device *self, void *aux) return; } + acpi_set_wake_gpe(sc->sc_node->ad_handle); + #ifdef ACPI_BUT_DEBUG /* Display the current state when it changes. */ sc->sc_flags = ACPIBUT_F_VERBOSE; diff --git a/sys/dev/acpi/acpi_ec.c b/sys/dev/acpi/acpi_ec.c index c01ac5d153c0..b35dc4f90698 100644 --- a/sys/dev/acpi/acpi_ec.c +++ b/sys/dev/acpi/acpi_ec.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_ec.c,v 1.32 2004/06/25 11:15:15 yamt Exp $ */ +/* $NetBSD: acpi_ec.c,v 1.33 2005/05/02 14:54:00 kochi Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -172,7 +172,7 @@ *****************************************************************************/ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.32 2004/06/25 11:15:15 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.33 2005/05/02 14:54:00 kochi Exp $"); #include #include @@ -246,7 +246,7 @@ typedef struct { UINT8 Data; } EC_REQUEST; -static void EcGpeHandler(void *Context); +static UINT32 EcGpeHandler(void *Context); static ACPI_STATUS EcSpaceSetup(ACPI_HANDLE Region, UINT32 Function, void *Context, void **return_Context); static ACPI_STATUS EcSpaceHandler(UINT32 Function, @@ -426,14 +426,27 @@ acpiec_early_attach(struct device *parent) ecdt_sc->sc_glk = 1; rv = AcpiInstallGpeHandler(NULL, ecdt_sc->sc_gpebit, - ACPI_EVENT_EDGE_TRIGGERED, EcGpeHandler, ecdt_sc); + ACPI_GPE_EDGE_TRIGGERED, EcGpeHandler, ecdt_sc); if (ACPI_FAILURE(rv)) { printf("%s: unable to install GPE handler: %s\n", - parent->dv_xname, - AcpiFormatException(rv)); + parent->dv_xname, AcpiFormatException(rv)); goto out3; } + rv = AcpiSetGpeType(NULL, ecdt_sc->sc_gpebit, ACPI_GPE_TYPE_RUNTIME); + if (ACPI_FAILURE(rv)) { + printf("%s: unable to set GPE type: %s\n", + parent->dv_xname, AcpiFormatException(rv)); + goto out4; + } + + rv = AcpiEnableGpe(NULL, ecdt_sc->sc_gpebit, ACPI_NOT_ISR); + if (ACPI_FAILURE(rv)) { + printf("%s: unable to enable GPE: %s\n", + parent->dv_xname, AcpiFormatException(rv)); + goto out4; + } + rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_EC, EcSpaceHandler, EcSpaceSetup, ecdt_sc); if (ACPI_FAILURE(rv)) { @@ -592,23 +605,40 @@ acpiec_attach(struct device *parent, struct device *self, void *aux) * cleared before re-enabling the GPE. */ rv = AcpiInstallGpeHandler(NULL, sc->sc_gpebit, - ACPI_EVENT_EDGE_TRIGGERED, EcGpeHandler, sc); + ACPI_GPE_EDGE_TRIGGERED, EcGpeHandler, sc); if (ACPI_FAILURE(rv)) { printf("%s: unable to install GPE handler: %s\n", sc->sc_dev.dv_xname, AcpiFormatException(rv)); goto out; } + rv = AcpiSetGpeType(NULL, sc->sc_gpebit, ACPI_GPE_TYPE_RUNTIME); + if (ACPI_FAILURE(rv)) { + printf("%s: unable to set GPE type: %s\n", + sc->sc_dev.dv_xname, AcpiFormatException(rv)); + goto out2; + } + + rv = AcpiEnableGpe(NULL, sc->sc_gpebit, ACPI_NOT_ISR); + if (ACPI_FAILURE(rv)) { + printf("%s: unable to enable GPE: %s\n", + sc->sc_dev.dv_xname, AcpiFormatException(rv)); + goto out2; + } + /* Install address space handler. */ rv = AcpiInstallAddressSpaceHandler(sc->sc_handle, ACPI_ADR_SPACE_EC, EcSpaceHandler, EcSpaceSetup, sc); if (ACPI_FAILURE(rv)) { printf("%s: unable to install address space handler: %s\n", sc->sc_dev.dv_xname, AcpiFormatException(rv)); - (void)AcpiRemoveGpeHandler(NULL, sc->sc_gpebit, - EcGpeHandler); + goto out2; } + return_VOID; + out2: + (void)AcpiRemoveGpeHandler(NULL, sc->sc_gpebit, EcGpeHandler); + out: acpi_resource_cleanup(&res); return_VOID; @@ -685,7 +715,7 @@ EcGpeQueryHandler(void *Context) return_VOID; } -static void +static UINT32 EcGpeHandler(void *Context) { struct acpi_ec_softc *sc = Context; @@ -716,6 +746,8 @@ EcGpeHandler(void *Context) printf("%s: failed to enqueue query handler: %s\n", sc->sc_dev.dv_xname, AcpiFormatException(rv)); } + + return 0; /* XXX not yet used in ACPI-CA */ } static ACPI_STATUS diff --git a/sys/dev/acpi/acpi_lid.c b/sys/dev/acpi/acpi_lid.c index 258830456a2a..1814ccca870f 100644 --- a/sys/dev/acpi/acpi_lid.c +++ b/sys/dev/acpi/acpi_lid.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_lid.c,v 1.15 2004/05/01 12:03:48 kochi Exp $ */ +/* $NetBSD: acpi_lid.c,v 1.16 2005/05/02 14:54:00 kochi Exp $ */ /* * Copyright 2001, 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_lid.c,v 1.15 2004/05/01 12:03:48 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_lid.c,v 1.16 2005/05/02 14:54:00 kochi Exp $"); #include #include @@ -119,6 +119,8 @@ acpilid_attach(struct device *parent, struct device *self, void *aux) sc->sc_dev.dv_xname, AcpiFormatException(rv)); return; } + + acpi_set_wake_gpe(sc->sc_node->ad_handle); } /* diff --git a/sys/dev/acpi/acpi_tz.c b/sys/dev/acpi/acpi_tz.c index 84bfe362c0ec..a60fb4862b9a 100644 --- a/sys/dev/acpi/acpi_tz.c +++ b/sys/dev/acpi/acpi_tz.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_tz.c,v 1.14 2004/06/06 17:27:05 martin Exp $ */ +/* $NetBSD: acpi_tz.c,v 1.15 2005/05/02 14:54:00 kochi Exp $ */ /* * Copyright (c) 2003 Jared D. McNeill @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.14 2004/06/06 17:27:05 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.15 2005/05/02 14:54:00 kochi Exp $"); #include #include @@ -508,7 +508,7 @@ static void acpitz_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque) { struct acpitz_softc *sc = opaque; - OSD_EXECUTION_CALLBACK func = NULL; + ACPI_OSD_EXEC_CALLBACK func = NULL; const char *name; int rv; diff --git a/sys/dev/acpi/acpica/Osd/OsdInterrupt.c b/sys/dev/acpi/acpica/Osd/OsdInterrupt.c index bae7468c7217..a2f3f1d602e1 100644 --- a/sys/dev/acpi/acpica/Osd/OsdInterrupt.c +++ b/sys/dev/acpi/acpica/Osd/OsdInterrupt.c @@ -1,4 +1,4 @@ -/* $NetBSD: OsdInterrupt.c,v 1.5 2004/05/01 12:03:27 kochi Exp $ */ +/* $NetBSD: OsdInterrupt.c,v 1.6 2005/05/02 14:53:04 kochi Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -42,7 +42,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: OsdInterrupt.c,v 1.5 2004/05/01 12:03:27 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: OsdInterrupt.c,v 1.6 2005/05/02 14:53:04 kochi Exp $"); #include #include @@ -68,7 +68,7 @@ MALLOC_DEFINE(M_ACPI, "acpi", "Advanced Configuration and Power Interface"); struct acpi_interrupt_handler { LIST_ENTRY(acpi_interrupt_handler) aih_list; UINT32 aih_intrnum; - OSD_HANDLER aih_func; + ACPI_OSD_HANDLER aih_func; void *aih_ih; }; @@ -95,7 +95,7 @@ do { \ */ ACPI_STATUS AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, - OSD_HANDLER ServiceRoutine, void *Context) + ACPI_OSD_HANDLER ServiceRoutine, void *Context) { struct acpi_interrupt_handler *aih; ACPI_STATUS rv; @@ -133,7 +133,8 @@ AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, * Remove an interrupt handler. */ ACPI_STATUS -AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, OSD_HANDLER ServiceRoutine) +AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, + ACPI_OSD_HANDLER ServiceRoutine) { struct acpi_interrupt_handler *aih; int s; diff --git a/sys/dev/acpi/acpica/Osd/OsdSchedule.c b/sys/dev/acpi/acpica/Osd/OsdSchedule.c index 557f9074e4e6..af730fdff7e2 100644 --- a/sys/dev/acpi/acpica/Osd/OsdSchedule.c +++ b/sys/dev/acpi/acpica/Osd/OsdSchedule.c @@ -1,4 +1,4 @@ -/* $NetBSD: OsdSchedule.c,v 1.10 2003/08/15 17:07:04 kochi Exp $ */ +/* $NetBSD: OsdSchedule.c,v 1.11 2005/05/02 14:53:04 kochi Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -42,7 +42,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: OsdSchedule.c,v 1.10 2003/08/15 17:07:04 kochi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: OsdSchedule.c,v 1.11 2005/05/02 14:53:04 kochi Exp $"); #include #include @@ -114,7 +114,7 @@ AcpiOsGetThreadId(void) * Schedule a procedure for deferred execution. */ ACPI_STATUS -AcpiOsQueueForExecution(UINT32 Priority, OSD_EXECUTION_CALLBACK Function, +AcpiOsQueueForExecution(UINT32 Priority, ACPI_OSD_EXEC_CALLBACK Function, void *Context) { int pri; @@ -160,13 +160,13 @@ AcpiOsQueueForExecution(UINT32 Priority, OSD_EXECUTION_CALLBACK Function, * Suspend the running task (coarse granularity). */ void -AcpiOsSleep(UINT32 Seconds, UINT32 Milliseconds) +AcpiOsSleep(ACPI_INTEGER Milliseconds) { int timo; ACPI_FUNCTION_TRACE(__FUNCTION__); - timo = Seconds * hz + Milliseconds * hz / 1000; + timo = Milliseconds * hz / 1000; if (timo == 0) timo = 1; @@ -200,4 +200,27 @@ AcpiOsStall(UINT32 Microseconds) delay(Microseconds); return_VOID; + +} + +/* + * AcpiOsStall: + * + * Get the current system time in 100 nanosecond units + */ +UINT64 +AcpiOsGetTimer(void) +{ + struct timeval tv; + UINT64 t; + + /* XXX During early boot there is no (decent) timer available yet. */ + if (cold) + panic("acpi: timer op not yet supported during boot"); + + microtime(&tv); + t = (UINT64)10 * tv.tv_usec; + t += (UINT64)10000000 * tv.tv_sec; + + return (t); } diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index be64b657b79b..1ff0d41c89d8 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: acpivar.h,v 1.20 2004/05/26 17:15:17 kochi Exp $ */ +/* $NetBSD: acpivar.h,v 1.21 2005/05/02 14:54:00 kochi Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -260,6 +260,7 @@ extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default; int acpi_probe(void); int acpi_match_hid(ACPI_DEVICE_INFO *, const char * const *); +void acpi_set_wake_gpe(ACPI_HANDLE); ACPI_STATUS acpi_eval_integer(ACPI_HANDLE, char *, ACPI_INTEGER *); ACPI_STATUS acpi_eval_string(ACPI_HANDLE, char *, char **);