diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2020-11-15 18:04:11 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2020-11-15 18:04:11 +0000 |
commit | d1e985206b7dcb2b0080173a5d3b59d4d0cc2cb9 (patch) | |
tree | 783c1e054576afb164b695432734aa05b3478499 /sys/dev/acpi | |
parent | 1eaa4b29ec29b98d22e171aa98c5b17b511e6dc0 (diff) |
Add acpige(4), a driver for ACPI generic event devices. This is a rather
simple device that simply reacts to interrupts by invoking _EVT with the
interrupt number. This is used on the HoneyComb LX2K to implement power
button handling.
ok kettenis@
Diffstat (limited to 'sys/dev/acpi')
-rw-r--r-- | sys/dev/acpi/acpige.c | 128 | ||||
-rw-r--r-- | sys/dev/acpi/files.acpi | 7 |
2 files changed, 134 insertions, 1 deletions
diff --git a/sys/dev/acpi/acpige.c b/sys/dev/acpi/acpige.c new file mode 100644 index 00000000000..1606f1db55c --- /dev/null +++ b/sys/dev/acpi/acpige.c @@ -0,0 +1,128 @@ +/* $OpenBSD: acpige.c,v 1.1 2020/11/15 18:04:10 patrick Exp $ */ +/* + * Copyright (c) 2020 Patrick Wildt <patrick@blueri.se> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/malloc.h> +#include <sys/systm.h> +#include <sys/tty.h> + +#include <dev/acpi/acpireg.h> +#include <dev/acpi/acpivar.h> +#include <dev/acpi/acpidev.h> +#include <dev/acpi/amltypes.h> +#include <dev/acpi/dsdt.h> + +struct acpige_softc; +struct acpige_irq { + struct acpige_softc *ai_sc; + void *ai_ih; + uint32_t ai_irq; +}; + +struct acpige_softc { + struct device sc_dev; + struct acpi_softc *sc_acpi; + struct aml_node *sc_devnode; + struct acpige_irq *sc_irq; +}; + +int acpige_match(struct device *, void *, void *); +void acpige_attach(struct device *, struct device *, void *); + +int acpige_intr(void *); +void acpige_event_task(void *, int); + +struct cfattach acpige_ca = { + sizeof(struct acpige_softc), acpige_match, acpige_attach +}; + +struct cfdriver acpige_cd = { + NULL, "acpige", DV_DULL +}; + +const char *acpige_hids[] = { + "ACPI0013", + NULL +}; + +int +acpige_match(struct device *parent, void *match, void *aux) +{ + struct acpi_attach_args *aaa = aux; + struct cfdata *cf = match; + + return acpi_matchhids(aaa, acpige_hids, cf->cf_driver->cd_name); +} + +void +acpige_attach(struct device *parent, struct device *self, void *aux) +{ + struct acpige_softc *sc = (struct acpige_softc *)self; + struct acpi_attach_args *aaa = aux; + struct acpige_irq *ai; + int i; + + sc->sc_acpi = (struct acpi_softc *)parent; + sc->sc_devnode = aaa->aaa_node; + + if (aaa->aaa_nirq < 1) { + printf(": no interrupt\n"); + return; + } + + sc->sc_irq = mallocarray(aaa->aaa_nirq, sizeof(struct acpige_irq), + M_DEVBUF, M_WAITOK); + + for (i = 0; i < aaa->aaa_nirq; i++) { + printf("%s %d", i ? "," : " irq", aaa->aaa_irq[i]); + ai = &sc->sc_irq[i]; + ai->ai_sc = sc; + ai->ai_irq = aaa->aaa_irq[i]; + ai->ai_ih = acpi_intr_establish(aaa->aaa_irq[i], + aaa->aaa_irq_flags[i], IPL_BIO, acpige_intr, ai, + sc->sc_dev.dv_xname); + if (ai->ai_ih == NULL) { + printf(": can't establish interrupt\n"); + return; + } + } + + printf("\n"); +} + +int +acpige_intr(void *arg) +{ + struct acpige_irq *ai = arg; + struct acpige_softc *sc = ai->ai_sc; + + acpi_addtask(sc->sc_acpi, acpige_event_task, sc, ai->ai_irq); + acpi_wakeup(sc->sc_acpi); + return 1; +} + +void +acpige_event_task(void *arg0, int irq) +{ + struct acpige_softc *sc = arg0; + struct aml_value cmd; + + memset(&cmd, 0, sizeof cmd); + cmd.v_integer = irq; + cmd.type = AML_OBJTYPE_INTEGER; + aml_evalname(sc->sc_acpi, sc->sc_devnode, "_EVT", 1, &cmd, NULL); +} diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi index 1d14299b54f..0e6e8f02992 100644 --- a/sys/dev/acpi/files.acpi +++ b/sys/dev/acpi/files.acpi @@ -1,4 +1,4 @@ -# $OpenBSD: files.acpi,v 1.59 2020/11/15 16:47:12 kettenis Exp $ +# $OpenBSD: files.acpi,v 1.60 2020/11/15 18:04:10 patrick Exp $ # # Config file and device description for machine-independent ACPI code. # Included by ports that need it. @@ -50,6 +50,11 @@ device acpiec attach acpiec at acpi file dev/acpi/acpiec.c acpiec +# Generic Event +device acpige +attach acpige at acpi +file dev/acpi/acpige.c acpige + # Thermal Zone device acpitz attach acpitz at acpi |