From 676159d418a54d7ea0667940332a4bd6a06aa192 Mon Sep 17 00:00:00 2001 From: Hasso Tepper Date: Wed, 27 Aug 2008 16:35:19 +0000 Subject: [PATCH] Add some methods to ACPI to handle embedded controllers and device matching. Obtained-from: FreeBSD --- sys/conf/files | 3 +- sys/conf/kmod.mk | 4 +- sys/dev/acpica5/Makefile | 8 ++-- sys/dev/acpica5/acpi.c | 24 +++++++++- sys/dev/acpica5/acpi_ec.c | 39 ++++++++++++++++- sys/dev/acpica5/acpi_if.m | 92 +++++++++++++++++++++++++++++++++++++++ sys/dev/acpica5/acpivar.h | 3 +- 7 files changed, 163 insertions(+), 10 deletions(-) create mode 100644 sys/dev/acpica5/acpi_if.m diff --git a/sys/conf/files b/sys/conf/files index ec4a4e34a1..d5c4f3c6cb 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/files,v 1.340.2.137 2003/06/04 17:10:30 sam Exp $ -# $DragonFly: src/sys/conf/files,v 1.229 2008/07/28 15:07:28 sephe Exp $ +# $DragonFly: src/sys/conf/files,v 1.230 2008/08/27 16:35:19 hasso Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -1537,6 +1537,7 @@ ${OSACPI_MI_DIR}/acpi_button.c optional acpi ${OSACPI_MI_DIR}/acpi_cmbat.c optional acpi ${OSACPI_MI_DIR}/acpi_cpu.c optional acpi ${OSACPI_MI_DIR}/acpi_ec.c optional acpi +${OSACPI_MI_DIR}/acpi_if.m optional acpi ${OSACPI_MI_DIR}/acpi_isab.c optional acpi isa ${OSACPI_MI_DIR}/acpi_lid.c optional acpi ${OSACPI_MI_DIR}/acpi_package.c optional acpi diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk index 65d9c569b8..395597b5dd 100644 --- a/sys/conf/kmod.mk +++ b/sys/conf/kmod.mk @@ -1,6 +1,6 @@ # From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 # $FreeBSD: src/sys/conf/kmod.mk,v 1.82.2.15 2003/02/10 13:11:50 nyan Exp $ -# $DragonFly: src/sys/conf/kmod.mk,v 1.34 2008/07/23 16:39:31 dillon Exp $ +# $DragonFly: src/sys/conf/kmod.mk,v 1.35 2008/08/27 16:35:19 hasso Exp $ # # The include file handles installing Kernel Loadable Device # drivers (KLD's). @@ -281,7 +281,7 @@ MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \ bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \ bus/pci/pcib_if.m \ bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \ - dev/disk/nata/ata_if.m \ + dev/acpica5/acpi_if.m dev/disk/nata/ata_if.m \ dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \ libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m diff --git a/sys/dev/acpica5/Makefile b/sys/dev/acpica5/Makefile index 29bf7098d1..7e2e935de4 100644 --- a/sys/dev/acpica5/Makefile +++ b/sys/dev/acpica5/Makefile @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/modules/acpi/acpi/Makefile,v 1.3 2004/01/08 16:38:32 njl Exp $ -# $DragonFly: src/sys/dev/acpica5/Makefile,v 1.20 2007/03/26 02:34:39 y0netan1 Exp $ +# $DragonFly: src/sys/dev/acpica5/Makefile,v 1.21 2008/08/27 16:35:19 hasso Exp $ CONTRIBDIR= ${SYSDIR}/${ACPICA_DIR} # patches to fix problems in ACPI-CA code @@ -69,12 +69,14 @@ SRCS+= acpi_package.c # SRCS+= acpi_pci.c acpi_pcib.c acpi_pcib_acpi.c acpi_pcib_pci.c # SRCS+= acpi_pci_link.c SRCS+= acpi_powerres.c acpi_resource.c acpi_thermal.c -SRCS+= acpi_timer.c +SRCS+= acpi_timer.c acpi_if.c SRCS+= OsdDebug.c SRCS+= OsdHardware.c OsdInterface.c OsdInterrupt.c OsdMemory.c OsdSchedule.c SRCS+= OsdStream.c OsdSynch.c OsdTable.c OsdEnvironment.c SRCS+= opt_acpi.h opt_bus.h opt_ddb.h -SRCS+= device_if.h bus_if.h pci_if.h pcib_if.h isa_if.h +SRCS+= device_if.h bus_if.h pci_if.h pcib_if.h isa_if.h acpi_if.h +MFILES = kern/device_if.m kern/bus_if.m bus/pci/pci_if.m bus/pci/pcib_if.m +MFILES+= bus/isa/isa_if.m dev/acpica5/acpi_if.m # Debugging support DBSRC= dbcmds.c dbdisply.c dbexec.c dbfileio.c dbhistry.c diff --git a/sys/dev/acpica5/acpi.c b/sys/dev/acpica5/acpi.c index 2120119e0a..5bec581090 100644 --- a/sys/dev/acpica5/acpi.c +++ b/sys/dev/acpica5/acpi.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/acpi.c,v 1.160 2004/06/14 03:52:19 njl Exp $ - * $DragonFly: src/sys/dev/acpica5/acpi.c,v 1.34 2008/06/05 18:06:31 swildner Exp $ + * $DragonFly: src/sys/dev/acpica5/acpi.c,v 1.35 2008/08/27 16:35:19 hasso Exp $ */ #include "opt_acpi.h" @@ -135,6 +135,7 @@ static int acpi_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r); static uint32_t acpi_isa_get_logicalid(device_t dev); static int acpi_isa_get_compatid(device_t dev, uint32_t *cids, int count); +static char *acpi_device_id_probe(device_t bus, device_t dev, char **ids); static int acpi_isa_pnp_probe(device_t bus, device_t child, struct isa_pnp_id *ids); static void acpi_probe_children(device_t bus); @@ -190,6 +191,9 @@ static device_method_t acpi_methods[] = { DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), + /* ACPI bus */ + DEVMETHOD(acpi_id_probe, acpi_device_id_probe), + /* ISA emulation */ DEVMETHOD(isa_pnp_probe, acpi_isa_pnp_probe), @@ -1123,6 +1127,24 @@ out: return_VALUE (valid); } +static char * +acpi_device_id_probe(device_t bus, device_t dev, char **ids) +{ + ACPI_HANDLE h; + int i; + + h = acpi_get_handle(dev); + if (ids == NULL || h == NULL || acpi_get_type(dev) != ACPI_TYPE_DEVICE) + return (NULL); + + /* Try to match one of the array of IDs with a HID or CID. */ + for (i = 0; ids[i] != NULL; i++) { + if (acpi_MatchHid(h, ids[i])) + return (ids[i]); + } + return (NULL); +} + static int acpi_isa_pnp_probe(device_t bus, device_t child, struct isa_pnp_id *ids) { diff --git a/sys/dev/acpica5/acpi_ec.c b/sys/dev/acpica5/acpi_ec.c index 73019de478..c988506852 100644 --- a/sys/dev/acpica5/acpi_ec.c +++ b/sys/dev/acpica5/acpi_ec.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/acpi_ec.c,v 1.52 2004/06/13 22:52:30 njl Exp $ - * $DragonFly: src/sys/dev/acpica5/acpi_ec.c,v 1.13 2007/10/23 03:04:48 y0netan1 Exp $ + * $DragonFly: src/sys/dev/acpica5/acpi_ec.c,v 1.14 2008/08/27 16:35:19 hasso Exp $ */ /****************************************************************************** * @@ -138,7 +138,7 @@ *****************************************************************************/ /* * $FreeBSD: src/sys/dev/acpica/acpi_ec.c,v 1.52 2004/06/13 22:52:30 njl Exp $ - * $DragonFly: src/sys/dev/acpica5/acpi_ec.c,v 1.13 2007/10/23 03:04:48 y0netan1 Exp $ + * $DragonFly: src/sys/dev/acpica5/acpi_ec.c,v 1.14 2008/08/27 16:35:19 hasso Exp $ * */ @@ -327,12 +327,20 @@ static ACPI_STATUS EcWrite(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data); static int acpi_ec_probe(device_t dev); static int acpi_ec_attach(device_t dev); +static int acpi_ec_read_method(device_t dev, u_int addr, + ACPI_INTEGER *val, int width); +static int acpi_ec_write_method(device_t dev, u_int addr, + ACPI_INTEGER val, int width); static device_method_t acpi_ec_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_ec_probe), DEVMETHOD(device_attach, acpi_ec_attach), + /* Embedded controller interface */ + DEVMETHOD(acpi_ec_read, acpi_ec_read_method), + DEVMETHOD(acpi_ec_write, acpi_ec_write_method), + {0, 0} }; @@ -622,6 +630,33 @@ error: return (ENXIO); } +/* Methods to allow other devices (e.g., smbat) to read/write EC space. */ +static int +acpi_ec_read_method(device_t dev, u_int addr, ACPI_INTEGER *val, int width) +{ + struct acpi_ec_softc *sc; + ACPI_STATUS status; + + sc = device_get_softc(dev); + status = EcSpaceHandler(ACPI_READ, addr, width * 8, val, sc, NULL); + if (ACPI_FAILURE(status)) + return (ENXIO); + return (0); +} + +static int +acpi_ec_write_method(device_t dev, u_int addr, ACPI_INTEGER val, int width) +{ + struct acpi_ec_softc *sc; + ACPI_STATUS status; + + sc = device_get_softc(dev); + status = EcSpaceHandler(ACPI_WRITE, addr, width * 8, &val, sc, NULL); + if (ACPI_FAILURE(status)) + return (ENXIO); + return (0); +} + static void EcGpeQueryHandler(void *Context) { diff --git a/sys/dev/acpica5/acpi_if.m b/sys/dev/acpica5/acpi_if.m new file mode 100644 index 0000000000..9c46815240 --- /dev/null +++ b/sys/dev/acpica5/acpi_if.m @@ -0,0 +1,92 @@ +#- +# Copyright (c) 2004 Nate Lawson +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $DragonFly: src/sys/dev/acpica5/acpi_if.m,v 1.1 2008/08/27 16:35:19 hasso Exp $ +# + +#include +#include +#include "acpi.h" + +INTERFACE acpi; + +# +# Default implementation for acpi_id_probe(). +# +CODE { + static char * + acpi_generic_id_probe(device_t bus, device_t dev, char **ids) + { + return (NULL); + } +}; + +# +# Check a device for a match in a list of ID strings. The strings can be +# EISA PNP IDs or ACPI _HID/_CID values. +# +# device_t bus: parent bus for the device +# +# device_t dev: device being considered +# +# char **ids: array of ID strings to consider +# +# Returns: ID string matched or NULL if no match +# +METHOD char * id_probe { + device_t bus; + device_t dev; + char **ids; +} DEFAULT acpi_generic_id_probe; + +# +# Read embedded controller (EC) address space +# +# device_t dev: EC device +# u_int addr: Address to read from in EC space +# ACPI_INTEGER *val: Location to store read value +# int width: Size of area to read in bytes +# +METHOD int ec_read { + device_t dev; + u_int addr; + ACPI_INTEGER *val; + int width; +}; + +# +# Write embedded controller (EC) address space +# +# device_t dev: EC device +# u_int addr: Address to write to in EC space +# ACPI_INTEGER val: Value to write +# int width: Size of value to write in bytes +# +METHOD int ec_write { + device_t dev; + u_int addr; + ACPI_INTEGER val; + int width; +}; diff --git a/sys/dev/acpica5/acpivar.h b/sys/dev/acpica5/acpivar.h index ed824e4cf2..7ac09dd994 100644 --- a/sys/dev/acpica5/acpivar.h +++ b/sys/dev/acpica5/acpivar.h @@ -26,9 +26,10 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/acpivar.h,v 1.71 2004/06/13 22:52:30 njl Exp $ - * $DragonFly: src/sys/dev/acpica5/acpivar.h,v 1.12 2007/10/23 03:04:48 y0netan1 Exp $ + * $DragonFly: src/sys/dev/acpica5/acpivar.h,v 1.13 2008/08/27 16:35:19 hasso Exp $ */ +#include "acpi_if.h" #include "bus_if.h" #include #include -- 2.41.0