summaryrefslogtreecommitdiffstats
path: root/sys/sparc64/ebus
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2004-08-12 17:41:33 +0000
committermarius <marius@FreeBSD.org>2004-08-12 17:41:33 +0000
commitf8c9f3a5e2940ba4fac814bea5bf4f4728dcd87b (patch)
treee750b2d26d6511903970a6a2a5d73da06845d58b /sys/sparc64/ebus
parent482740a238b6b7d0f1c649d1d3391e801547f668 (diff)
downloadFreeBSD-src-f8c9f3a5e2940ba4fac814bea5bf4f4728dcd87b.zip
FreeBSD-src-f8c9f3a5e2940ba4fac814bea5bf4f4728dcd87b.tar.gz
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard properties in drivers for devices on Open Firmware supported busses. The standard properties "reg", "interrupts" und "address" are not covered by this interface because they are only of interest in the respective bridge code. There's a remaining standard property "status" which is unclear how to support properly but which also isn't used in FreeBSD at present. This ofw_bus kobj-interface allows to replace the various (ebus_get_node(), ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type() vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one. This in turn allows to simplify and remove code-duplication in drivers for devices that can hang off of more than one OFW supported bus. - Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the drivers for their children to use the ofw_bus kobj-interface. The IVAR- interfaces of the Central, EBus and FHC are entirely replaced by this. The PCI bus driver used its own kobj-interface and now also uses the ofw_bus one. The IVARs special to the SBus, e.g. for retrieving the burst size, remain. Beware: this causes an ABI-breakage for modules of drivers which used the IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be recompiled. The style-inconsistencies introduced in some of the bus drivers will be fixed by tmm@ in a generic clean-up of the respective drivers later (he requested to add the changes in the "new" style). - Convert the powerpc MacIO bus driver and the drivers for its children to use the ofw_bus kobj-interface. This invloves removing the IVARs related to the "reg" property which were unused and a leftover from the NetBSD origini of the code. There's no ABI-breakage caused by this because none of these driver are currently built as modules. There are other powerpc bus drivers which can be converted to the ofw_bus kobj-interface, e.g. the PCI bus driver, which should be done together with converting powerpc to use the OFW PCI code from sparc64. - Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take advantage of the ofw_bus kobj-interface and simplify them a bit. Reviewed by: grehan, tmm Approved by: re (scottl) Discussed with: tmm Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
Diffstat (limited to 'sys/sparc64/ebus')
-rw-r--r--sys/sparc64/ebus/ebus.c120
-rw-r--r--sys/sparc64/ebus/ebusvar.h56
2 files changed, 71 insertions, 105 deletions
diff --git a/sys/sparc64/ebus/ebus.c b/sys/sparc64/ebus/ebus.c
index 10b98bc..bf12a26 100644
--- a/sys/sparc64/ebus/ebus.c
+++ b/sys/sparc64/ebus/ebus.c
@@ -57,6 +57,7 @@
#include <sys/rman.h>
+#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/openfirm.h>
#include <machine/ofw_bus.h>
@@ -72,11 +73,12 @@
* ones.
*/
#include <sparc64/isa/ofw_isa.h>
-#include <sparc64/ebus/ebusvar.h>
struct ebus_devinfo {
+ char *edi_compat; /* PROM compatible */
+ char *edi_model; /* PROM model */
char *edi_name; /* PROM name */
- char *edi_compat;
+ char *edi_type; /* PROM device_type */
phandle_t edi_node; /* PROM node */
struct resource_list edi_rl;
@@ -104,11 +106,14 @@ static device_probe_t ebus_probe;
static device_attach_t ebus_attach;
static bus_print_child_t ebus_print_child;
static bus_probe_nomatch_t ebus_probe_nomatch;
-static bus_read_ivar_t ebus_read_ivar;
-static bus_write_ivar_t ebus_write_ivar;
static bus_alloc_resource_t ebus_alloc_resource;
static bus_release_resource_t ebus_release_resource;
static bus_get_resource_list_t ebus_get_resource_list;
+static ofw_bus_get_compat_t ebus_get_compat;
+static ofw_bus_get_model_t ebus_get_model;
+static ofw_bus_get_name_t ebus_get_name;
+static ofw_bus_get_node_t ebus_get_node;
+static ofw_bus_get_type_t ebus_get_type;
static struct ebus_devinfo *ebus_setup_dinfo(device_t, struct ebus_softc *,
phandle_t, char *);
@@ -123,8 +128,6 @@ static device_method_t ebus_methods[] = {
/* Bus interface */
DEVMETHOD(bus_print_child, ebus_print_child),
DEVMETHOD(bus_probe_nomatch, ebus_probe_nomatch),
- DEVMETHOD(bus_read_ivar, ebus_read_ivar),
- DEVMETHOD(bus_write_ivar, ebus_write_ivar),
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
DEVMETHOD(bus_alloc_resource, ebus_alloc_resource),
@@ -134,6 +137,13 @@ static device_method_t ebus_methods[] = {
DEVMETHOD(bus_release_resource, ebus_release_resource),
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
+ /* ofw_bus interface */
+ DEVMETHOD(ofw_bus_get_compat, ebus_get_compat),
+ DEVMETHOD(ofw_bus_get_model, ebus_get_model),
+ DEVMETHOD(ofw_bus_get_name, ebus_get_name),
+ DEVMETHOD(ofw_bus_get_node, ebus_get_node),
+ DEVMETHOD(ofw_bus_get_type, ebus_get_type),
+
{ 0, 0 }
};
@@ -153,7 +163,7 @@ ebus_probe(device_t dev)
char name[10];
phandle_t node;
- if ((node = ofw_pci_get_node(dev)) == 0)
+ if ((node = ofw_bus_get_node(dev)) == 0)
return (ENXIO);
OF_getprop(node, "name", &name, sizeof(name));
@@ -184,7 +194,7 @@ ebus_attach(device_t dev)
int i, rnum, rid;
sc = device_get_softc(dev);
- sc->sc_node = node = ofw_pci_get_node(dev);
+ sc->sc_node = node = ofw_bus_get_node(dev);
sc->sc_nrange = OF_getprop_alloc(node, "ranges",
sizeof(*sc->sc_range), (void **)&sc->sc_range);
@@ -281,47 +291,6 @@ ebus_probe_nomatch(device_t dev, device_t child)
printf(" (no driver attached)\n");
}
-static int
-ebus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
-{
- struct ebus_devinfo *dinfo;
-
- if ((dinfo = device_get_ivars(child)) == NULL)
- return (ENOENT);
- switch (which) {
- case EBUS_IVAR_COMPAT:
- *result = (uintptr_t)dinfo->edi_compat;
- break;
- case EBUS_IVAR_NAME:
- *result = (uintptr_t)dinfo->edi_name;
- break;
- case EBUS_IVAR_NODE:
- *result = dinfo->edi_node;
- break;
- default:
- return (ENOENT);
- }
- return 0;
-}
-
-static int
-ebus_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
-{
- struct ebus_devinfo *dinfo;
-
- if ((dinfo = device_get_ivars(child)) == NULL)
- return (ENOENT);
- switch (which) {
- case EBUS_IVAR_COMPAT:
- case EBUS_IVAR_NAME:
- case EBUS_IVAR_NODE:
- return (EINVAL);
- default:
- return (ENOENT);
- }
- return 0;
-}
-
static struct resource *
ebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
u_long start, u_long end, u_long count, u_int flags)
@@ -452,6 +421,8 @@ ebus_setup_dinfo(device_t dev, struct ebus_softc *sc, phandle_t node,
edi->edi_node = node;
OF_getprop_alloc(node, "compatible", 1, (void **)&edi->edi_compat);
+ OF_getprop_alloc(node, "device_type", 1, (void **)&edi->edi_type);
+ OF_getprop_alloc(node, "model", 1, (void **)&edi->edi_model);
nreg = OF_getprop_alloc(node, "reg", sizeof(*reg), (void **)&reg);
if (nreg == -1) {
ebus_destroy_dinfo(edi);
@@ -492,6 +463,12 @@ static void
ebus_destroy_dinfo(struct ebus_devinfo *edi)
{
+ if (edi->edi_compat != NULL)
+ free(edi->edi_compat, M_OFWPROP);
+ if (edi->edi_type != NULL)
+ free(edi->edi_type, M_OFWPROP);
+ if (edi->edi_model != NULL)
+ free(edi->edi_model, M_OFWPROP);
resource_list_free(&edi->edi_rl);
free(edi, M_DEVBUF);
}
@@ -508,3 +485,48 @@ ebus_print_res(struct ebus_devinfo *edi)
"%ld");
return (retval);
}
+
+static const char *
+ebus_get_compat(device_t bus, device_t dev)
+{
+ struct ebus_devinfo *dinfo;
+
+ dinfo = device_get_ivars(dev);
+ return (dinfo->edi_compat);
+}
+
+static const char *
+ebus_get_model(device_t bus, device_t dev)
+{
+ struct ebus_devinfo *dinfo;
+
+ dinfo = device_get_ivars(dev);
+ return (dinfo->edi_model);
+}
+
+static const char *
+ebus_get_name(device_t bus, device_t dev)
+{
+ struct ebus_devinfo *dinfo;
+
+ dinfo = device_get_ivars(dev);
+ return (dinfo->edi_name);
+}
+
+static phandle_t
+ebus_get_node(device_t bus, device_t dev)
+{
+ struct ebus_devinfo *dinfo;
+
+ dinfo = device_get_ivars(dev);
+ return (dinfo->edi_node);
+}
+
+static const char *
+ebus_get_type(device_t bus, device_t dev)
+{
+ struct ebus_devinfo *dinfo;
+
+ dinfo = device_get_ivars(dev);
+ return (dinfo->edi_type);
+}
diff --git a/sys/sparc64/ebus/ebusvar.h b/sys/sparc64/ebus/ebusvar.h
deleted file mode 100644
index c8fd7c6..0000000
--- a/sys/sparc64/ebus/ebusvar.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1999, 2000 Matthew R. Green
- * 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.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
- *
- * from: NetBSD: ebusvar.h,v 1.5 2001/07/20 00:07:13 eeh Exp
- * and
- * from: FreeBSD: src/sys/dev/pci/pcivar.h,v 1.51 2001/02/27
- *
- * $FreeBSD$
- */
-
-#ifndef _SPARC64_EBUS_EBUSVAR_H_
-#define _SPARC64_EBUS_EBUSVAR_H_
-
-enum ebus_device_ivars {
- EBUS_IVAR_COMPAT,
- EBUS_IVAR_NAME,
- EBUS_IVAR_NODE,
-};
-
-/*
- * Simplified accessors for ebus devices
- */
-#define EBUS_ACCESSOR(var, ivar, type) \
- __BUS_ACCESSOR(ebus, var, EBUS, ivar, type)
-
-EBUS_ACCESSOR(compat, COMPAT, char *)
-EBUS_ACCESSOR(name, NAME, char *)
-EBUS_ACCESSOR(node, NODE, phandle_t)
-
-#undef EBUS_ACCESSOR
-
-#endif /* !_SPARC64_EBUS_EBUSVAR_H_ */
OpenPOWER on IntegriCloud