diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2018-06-25 22:33:25 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2018-06-25 22:33:25 +0000 |
commit | d4be10bb2300db550fd687cc4bbee19535681603 (patch) | |
tree | c7f9d515cb06587a2479f030ad1a2524bc3bbf68 /sys/dev/acpi | |
parent | ebc6c03003108f9b51191ef34c6b7f463eb9d06e (diff) |
Reorganize acpi(4) code a bit in preparation for upcoming arm64 support.
ok deraadt@
Diffstat (limited to 'sys/dev/acpi')
-rw-r--r-- | sys/dev/acpi/acpi.c | 90 | ||||
-rw-r--r-- | sys/dev/acpi/acpivar.h | 17 |
2 files changed, 60 insertions, 47 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 9536a7e6f23..4b60b233f27 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.344 2018/05/20 09:12:35 kettenis Exp $ */ +/* $OpenBSD: acpi.c,v 1.345 2018/06/25 22:33:24 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org> @@ -79,8 +79,6 @@ pcireg_t acpi_pci_min_powerstate(pci_chipset_tag_t, pcitag_t); void acpi_pci_set_powerstate(pci_chipset_tag_t, pcitag_t, int, int); int acpi_pci_notify(struct aml_node *, int, void *); -int acpi_match(struct device *, void *, void *); -void acpi_attach(struct device *, struct device *, void *); int acpi_submatch(struct device *, void *, void *); int acpi_print(void *, const char *); @@ -198,21 +196,55 @@ static const char *sbtn_pnp[] = { int mouse_has_softbtn; #endif /* SMALL_KERNEL */ +struct acpi_softc *acpi_softc; + /* XXX move this into dsdt softc at some point */ extern struct aml_node aml_root; +struct cfdriver acpi_cd = { + NULL, "acpi", DV_DULL +}; + +#if defined(__amd64__) || defined(__i386__) + +#include <machine/biosvar.h> + +int acpi_match(struct device *, void *, void *); +void acpi_attach(struct device *, struct device *, void *); + struct cfattach acpi_ca = { sizeof(struct acpi_softc), acpi_match, acpi_attach }; -struct cfdriver acpi_cd = { - NULL, "acpi", DV_DULL -}; +int +acpi_match(struct device *parent, void *match, void *aux) +{ + struct bios_attach_args *ba = aux; + struct cfdata *cf = match; -struct acpi_softc *acpi_softc; + /* sanity */ + if (strcmp(ba->ba_name, cf->cf_driver->cd_name)) + return (0); -#define acpi_bus_space_map _bus_space_map -#define acpi_bus_space_unmap _bus_space_unmap + if (!acpi_probe(parent, cf, ba)) + return (0); + + return (1); +} + +void +acpi_attach(struct device *parent, struct device *self, void *aux) +{ + struct acpi_softc *sc = (struct acpi_softc *)self; + struct bios_attach_args *ba = aux; + + sc->sc_iot = ba->ba_iot; + sc->sc_memt = ba->ba_memt; + + acpi_attach_common(sc, ba->ba_acpipbase); +} + +#endif uint8_t acpi_pci_conf_read_1(pci_chipset_tag_t pc, pcitag_t tag, int reg) @@ -336,7 +368,7 @@ acpi_gasio(struct acpi_softc *sc, int iodir, int iospace, uint64_t address, } } } - acpi_bus_space_unmap(iot, ioh, len, NULL); + acpi_bus_space_unmap(iot, ioh, len); break; case GAS_PCI_CFG_SPACE: @@ -492,22 +524,6 @@ acpi_foundprt(struct aml_node *node, void *arg) return 0; } -int -acpi_match(struct device *parent, void *match, void *aux) -{ - struct bios_attach_args *ba = aux; - struct cfdata *cf = match; - - /* sanity */ - if (strcmp(ba->ba_name, cf->cf_driver->cd_name)) - return (0); - - if (!acpi_probe(parent, cf, ba)) - return (0); - - return (1); -} - TAILQ_HEAD(, acpi_pci) acpi_pcidevs = TAILQ_HEAD_INITIALIZER(acpi_pcidevs); TAILQ_HEAD(, acpi_pci) acpi_pcirootdevs = @@ -942,10 +958,8 @@ acpi_register_gsb(struct acpi_softc *sc, struct aml_node *devnode) #endif void -acpi_attach(struct device *parent, struct device *self, void *aux) +acpi_attach_common(struct acpi_softc *sc, paddr_t base) { - struct bios_attach_args *ba = aux; - struct acpi_softc *sc = (struct acpi_softc *)self; struct acpi_mem_map handle; struct acpi_rsdp *rsdp; struct acpi_q *entry; @@ -959,14 +973,11 @@ acpi_attach(struct device *parent, struct device *self, void *aux) uint16_t pm1; int s; - sc->sc_iot = ba->ba_iot; - sc->sc_memt = ba->ba_memt; - rw_init(&sc->sc_lck, "acpilk"); acpi_softc = sc; - if (acpi_map(ba->ba_acpipbase, sizeof(struct acpi_rsdp), &handle)) { + if (acpi_map(base, sizeof(struct acpi_rsdp), &handle)) { printf(": can't map memory\n"); return; } @@ -1150,11 +1161,7 @@ acpi_attach(struct device *parent, struct device *self, void *aux) aaa.aaa_name = "acpitimer"; aaa.aaa_iot = sc->sc_iot; aaa.aaa_memt = sc->sc_memt; -#if 0 - aaa.aaa_pcit = sc->sc_pcit; - aaa.aaa_smbust = sc->sc_smbust; -#endif - config_found(self, &aaa, acpi_print); + config_found(&sc->sc_dev, &aaa, acpi_print); } #endif /* SMALL_KERNEL */ @@ -1167,12 +1174,8 @@ acpi_attach(struct device *parent, struct device *self, void *aux) memset(&aaa, 0, sizeof(aaa)); aaa.aaa_iot = sc->sc_iot; aaa.aaa_memt = sc->sc_memt; - #if 0 - aaa.aaa_pcit = sc->sc_pcit; - aaa.aaa_smbust = sc->sc_smbust; - #endif aaa.aaa_table = entry->q_table; - config_found_sm(self, &aaa, acpi_print, acpi_submatch); + config_found_sm(&sc->sc_dev, &aaa, acpi_print, acpi_submatch); } /* initialize runtime environment */ @@ -3402,4 +3405,5 @@ acpikqfilter(dev_t dev, struct knote *kn) { return (ENXIO); } + #endif /* SMALL_KERNEL */ diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index 82fc12ba740..451bb10c7f1 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpivar.h,v 1.90 2018/05/17 20:21:15 kettenis Exp $ */ +/* $OpenBSD: acpivar.h,v 1.91 2018/06/25 22:33:24 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> * @@ -25,7 +25,8 @@ #include <sys/timeout.h> #include <sys/rwlock.h> -#include <machine/biosvar.h> + +#include <machine/bus.h> #include "acpipwrres.h" @@ -296,14 +297,22 @@ struct acpi_dev_rank { #define ACPI_IOC_SETSLEEPSTATE _IOW('A', 2, int) #if defined(_KERNEL) + struct acpi_gas; -int acpi_map_address(struct acpi_softc *, struct acpi_gas *, bus_addr_t, bus_size_t, - bus_space_handle_t *, bus_space_tag_t *); +int acpi_map_address(struct acpi_softc *, struct acpi_gas *, bus_addr_t, + bus_size_t, bus_space_handle_t *, bus_space_tag_t *); int acpi_map(paddr_t, size_t, struct acpi_mem_map *); void acpi_unmap(struct acpi_mem_map *); + +int acpi_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void acpi_bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); + +struct bios_attach_args; int acpi_probe(struct device *, struct cfdata *, struct bios_attach_args *); u_int acpi_checksum(const void *, size_t); +void acpi_attach_common(struct acpi_softc *, paddr_t); void acpi_attach_machdep(struct acpi_softc *); int acpi_interrupt(void *); void acpi_powerdown(void); |