16c525ee4SJohn Baldwin /*-
26c525ee4SJohn Baldwin * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
36c525ee4SJohn Baldwin *
46c525ee4SJohn Baldwin * Redistribution and use in source and binary forms, with or without
56c525ee4SJohn Baldwin * modification, are permitted provided that the following conditions
66c525ee4SJohn Baldwin * are met:
76c525ee4SJohn Baldwin * 1. Redistributions of source code must retain the above copyright
86c525ee4SJohn Baldwin * notice, this list of conditions and the following disclaimer.
96c525ee4SJohn Baldwin * 2. Redistributions in binary form must reproduce the above copyright
106c525ee4SJohn Baldwin * notice, this list of conditions and the following disclaimer in the
116c525ee4SJohn Baldwin * documentation and/or other materials provided with the distribution.
126c525ee4SJohn Baldwin *
136c525ee4SJohn Baldwin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
146c525ee4SJohn Baldwin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
156c525ee4SJohn Baldwin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
166c525ee4SJohn Baldwin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
176c525ee4SJohn Baldwin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
186c525ee4SJohn Baldwin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
196c525ee4SJohn Baldwin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
206c525ee4SJohn Baldwin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
216c525ee4SJohn Baldwin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
226c525ee4SJohn Baldwin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
236c525ee4SJohn Baldwin * SUCH DAMAGE.
246c525ee4SJohn Baldwin */
256c525ee4SJohn Baldwin
26aad970f1SDavid E. O'Brien #include <sys/cdefs.h>
276c525ee4SJohn Baldwin /*
286c525ee4SJohn Baldwin * ISA Bridge driver for Generic ISA Bus Devices. See section 10.7 of the
296c525ee4SJohn Baldwin * ACPI 2.0a specification for details on this device.
306c525ee4SJohn Baldwin */
316c525ee4SJohn Baldwin
326c525ee4SJohn Baldwin #include "opt_acpi.h"
336c525ee4SJohn Baldwin #include <sys/param.h>
346c525ee4SJohn Baldwin #include <sys/bus.h>
356c525ee4SJohn Baldwin #include <sys/kernel.h>
365acd0218SNate Lawson #include <sys/malloc.h>
37fe12f24bSPoul-Henning Kamp #include <sys/module.h>
386c525ee4SJohn Baldwin
39129d3046SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
40129d3046SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
41129d3046SJung-uk Kim
426c525ee4SJohn Baldwin #include <dev/acpica/acpivar.h>
436c525ee4SJohn Baldwin #include <isa/isavar.h>
446c525ee4SJohn Baldwin
455acd0218SNate Lawson /* Hooks for the ACPI CA debugging infrastructure. */
466c525ee4SJohn Baldwin #define _COMPONENT ACPI_BUS
476c525ee4SJohn Baldwin ACPI_MODULE_NAME("ISA_ACPI")
486c525ee4SJohn Baldwin
496c525ee4SJohn Baldwin struct acpi_isab_softc {
506c525ee4SJohn Baldwin device_t ap_dev;
516c525ee4SJohn Baldwin ACPI_HANDLE ap_handle;
526c525ee4SJohn Baldwin };
536c525ee4SJohn Baldwin
546c525ee4SJohn Baldwin static int acpi_isab_probe(device_t bus);
556c525ee4SJohn Baldwin static int acpi_isab_attach(device_t bus);
566c525ee4SJohn Baldwin static int acpi_isab_read_ivar(device_t dev, device_t child, int which,
576c525ee4SJohn Baldwin uintptr_t *result);
586c525ee4SJohn Baldwin
596c525ee4SJohn Baldwin static device_method_t acpi_isab_methods[] = {
606c525ee4SJohn Baldwin /* Device interface */
616c525ee4SJohn Baldwin DEVMETHOD(device_probe, acpi_isab_probe),
626c525ee4SJohn Baldwin DEVMETHOD(device_attach, acpi_isab_attach),
636c525ee4SJohn Baldwin DEVMETHOD(device_shutdown, bus_generic_shutdown),
646c525ee4SJohn Baldwin DEVMETHOD(device_suspend, bus_generic_suspend),
656c525ee4SJohn Baldwin DEVMETHOD(device_resume, bus_generic_resume),
666c525ee4SJohn Baldwin
676c525ee4SJohn Baldwin /* Bus interface */
686c525ee4SJohn Baldwin DEVMETHOD(bus_read_ivar, acpi_isab_read_ivar),
696c525ee4SJohn Baldwin DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
706c525ee4SJohn Baldwin DEVMETHOD(bus_release_resource, bus_generic_release_resource),
716c525ee4SJohn Baldwin DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
726c525ee4SJohn Baldwin DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
736c525ee4SJohn Baldwin DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
746c525ee4SJohn Baldwin DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
756c525ee4SJohn Baldwin
764b7ec270SMarius Strobl DEVMETHOD_END
776c525ee4SJohn Baldwin };
786c525ee4SJohn Baldwin
796c525ee4SJohn Baldwin static driver_t acpi_isab_driver = {
806c525ee4SJohn Baldwin "isab",
816c525ee4SJohn Baldwin acpi_isab_methods,
826c525ee4SJohn Baldwin sizeof(struct acpi_isab_softc),
836c525ee4SJohn Baldwin };
846c525ee4SJohn Baldwin
85*43ac2b6dSJohn Baldwin DRIVER_MODULE(acpi_isab, acpi, acpi_isab_driver, 0, 0);
8664278df5SNate Lawson MODULE_DEPEND(acpi_isab, acpi, 1, 1, 1);
876c525ee4SJohn Baldwin
886c525ee4SJohn Baldwin static int
acpi_isab_probe(device_t dev)896c525ee4SJohn Baldwin acpi_isab_probe(device_t dev)
906c525ee4SJohn Baldwin {
915fcc8a58SNate Lawson static char *isa_ids[] = { "PNP0A05", "PNP0A06", NULL };
925efca36fSTakanori Watanabe int rv;
936c525ee4SJohn Baldwin
9490664711SJohn Baldwin if (acpi_disabled("isab") || device_get_unit(dev) != 0)
955fcc8a58SNate Lawson return (ENXIO);
965efca36fSTakanori Watanabe rv = ACPI_ID_PROBE(device_get_parent(dev), dev, isa_ids, NULL);
975efca36fSTakanori Watanabe if (rv <= 0)
986c525ee4SJohn Baldwin device_set_desc(dev, "ACPI Generic ISA bridge");
995efca36fSTakanori Watanabe return (rv);
1006c525ee4SJohn Baldwin }
1016c525ee4SJohn Baldwin
1026c525ee4SJohn Baldwin static int
acpi_isab_attach(device_t dev)1036c525ee4SJohn Baldwin acpi_isab_attach(device_t dev)
1046c525ee4SJohn Baldwin {
1056c525ee4SJohn Baldwin struct acpi_isab_softc *sc;
1066c525ee4SJohn Baldwin
1076c525ee4SJohn Baldwin ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
1086c525ee4SJohn Baldwin
1096c525ee4SJohn Baldwin sc = device_get_softc(dev);
1106c525ee4SJohn Baldwin sc->ap_dev = dev;
1116c525ee4SJohn Baldwin sc->ap_handle = acpi_get_handle(dev);
1126c525ee4SJohn Baldwin
1136c525ee4SJohn Baldwin return (isab_attach(dev));
1146c525ee4SJohn Baldwin }
1156c525ee4SJohn Baldwin
1166c525ee4SJohn Baldwin static int
acpi_isab_read_ivar(device_t dev,device_t child,int which,uintptr_t * result)1176c525ee4SJohn Baldwin acpi_isab_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
1186c525ee4SJohn Baldwin {
1196c525ee4SJohn Baldwin struct acpi_isab_softc *sc = device_get_softc(dev);
1206c525ee4SJohn Baldwin
1216c525ee4SJohn Baldwin switch (which) {
1226c525ee4SJohn Baldwin case ACPI_IVAR_HANDLE:
1236c525ee4SJohn Baldwin *result = (uintptr_t)sc->ap_handle;
1246c525ee4SJohn Baldwin return (0);
1256c525ee4SJohn Baldwin }
1266c525ee4SJohn Baldwin return (ENOENT);
1276c525ee4SJohn Baldwin }
128