1117339Sjhb/*-
2117339Sjhb * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
3117339Sjhb * All rights reserved.
4117339Sjhb *
5117339Sjhb * Redistribution and use in source and binary forms, with or without
6117339Sjhb * modification, are permitted provided that the following conditions
7117339Sjhb * are met:
8117339Sjhb * 1. Redistributions of source code must retain the above copyright
9117339Sjhb *    notice, this list of conditions and the following disclaimer.
10117339Sjhb * 2. Redistributions in binary form must reproduce the above copyright
11117339Sjhb *    notice, this list of conditions and the following disclaimer in the
12117339Sjhb *    documentation and/or other materials provided with the distribution.
13117339Sjhb *
14117339Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15117339Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16117339Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17117339Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18117339Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19117339Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20117339Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21117339Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22117339Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23117339Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24117339Sjhb * SUCH DAMAGE.
25117339Sjhb */
26117339Sjhb
27119418Sobrien#include <sys/cdefs.h>
28119418Sobrien__FBSDID("$FreeBSD$");
29119418Sobrien
30117339Sjhb/*
31117339Sjhb * ISA Bridge driver for Generic ISA Bus Devices.  See section 10.7 of the
32117339Sjhb * ACPI 2.0a specification for details on this device.
33117339Sjhb */
34117339Sjhb
35117339Sjhb#include "opt_acpi.h"
36117339Sjhb#include <sys/param.h>
37117339Sjhb#include <sys/bus.h>
38129829Snjl#include <sys/kernel.h>
39117339Sjhb#include <sys/malloc.h>
40129879Sphk#include <sys/module.h>
41117339Sjhb
42193530Sjkim#include <contrib/dev/acpica/include/acpi.h>
43193530Sjkim#include <contrib/dev/acpica/include/accommon.h>
44193530Sjkim
45117339Sjhb#include <dev/acpica/acpivar.h>
46117339Sjhb#include <isa/isavar.h>
47117339Sjhb
48129829Snjl/* Hooks for the ACPI CA debugging infrastructure. */
49117339Sjhb#define _COMPONENT	ACPI_BUS
50117339SjhbACPI_MODULE_NAME("ISA_ACPI")
51117339Sjhb
52117339Sjhbstruct acpi_isab_softc {
53117339Sjhb	device_t	ap_dev;
54117339Sjhb	ACPI_HANDLE	ap_handle;
55117339Sjhb};
56117339Sjhb
57117339Sjhbstatic int	acpi_isab_probe(device_t bus);
58117339Sjhbstatic int	acpi_isab_attach(device_t bus);
59117339Sjhbstatic int	acpi_isab_read_ivar(device_t dev, device_t child, int which,
60117339Sjhb		    uintptr_t *result);
61117339Sjhb
62117339Sjhbstatic device_method_t acpi_isab_methods[] = {
63117339Sjhb	/* Device interface */
64117339Sjhb	DEVMETHOD(device_probe,		acpi_isab_probe),
65117339Sjhb	DEVMETHOD(device_attach,	acpi_isab_attach),
66117339Sjhb	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
67117339Sjhb	DEVMETHOD(device_suspend,	bus_generic_suspend),
68117339Sjhb	DEVMETHOD(device_resume,	bus_generic_resume),
69117339Sjhb
70117339Sjhb	/* Bus interface */
71117339Sjhb	DEVMETHOD(bus_read_ivar,	acpi_isab_read_ivar),
72117339Sjhb	DEVMETHOD(bus_alloc_resource,	bus_generic_alloc_resource),
73117339Sjhb	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
74117339Sjhb	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
75117339Sjhb	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
76117339Sjhb	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
77117339Sjhb	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
78117339Sjhb
79227843Smarius	DEVMETHOD_END
80117339Sjhb};
81117339Sjhb
82117339Sjhbstatic driver_t acpi_isab_driver = {
83117339Sjhb	"isab",
84117339Sjhb	acpi_isab_methods,
85117339Sjhb	sizeof(struct acpi_isab_softc),
86117339Sjhb};
87117339Sjhb
88117339SjhbDRIVER_MODULE(acpi_isab, acpi, acpi_isab_driver, isab_devclass, 0, 0);
89128071SnjlMODULE_DEPEND(acpi_isab, acpi, 1, 1, 1);
90117339Sjhb
91117339Sjhbstatic int
92117339Sjhbacpi_isab_probe(device_t dev)
93117339Sjhb{
94131282Snjl	static char *isa_ids[] = { "PNP0A05", "PNP0A06", NULL };
95117339Sjhb
96131282Snjl	if (acpi_disabled("isab") ||
97131282Snjl	    ACPI_ID_PROBE(device_get_parent(dev), dev, isa_ids) == NULL ||
98131282Snjl	    devclass_get_device(isab_devclass, 0) != dev)
99131282Snjl		return (ENXIO);
100131282Snjl
101131282Snjl	device_set_desc(dev, "ACPI Generic ISA bridge");
102131282Snjl	return (0);
103117339Sjhb}
104117339Sjhb
105117339Sjhbstatic int
106117339Sjhbacpi_isab_attach(device_t dev)
107117339Sjhb{
108117339Sjhb	struct acpi_isab_softc *sc;
109117339Sjhb
110117339Sjhb	ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
111117339Sjhb
112117339Sjhb	sc = device_get_softc(dev);
113117339Sjhb	sc->ap_dev = dev;
114117339Sjhb	sc->ap_handle = acpi_get_handle(dev);
115117339Sjhb
116117339Sjhb	return (isab_attach(dev));
117117339Sjhb}
118117339Sjhb
119117339Sjhbstatic int
120117339Sjhbacpi_isab_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
121117339Sjhb{
122117339Sjhb	struct acpi_isab_softc *sc = device_get_softc(dev);
123117339Sjhb
124117339Sjhb	switch (which) {
125129829Snjl	case ACPI_IVAR_HANDLE:
126117339Sjhb		*result = (uintptr_t)sc->ap_handle;
127129829Snjl		return (0);
128117339Sjhb	}
129129829Snjl	return (ENOENT);
130117339Sjhb}
131