PERFORCE change 171815 for review
Rafal Jaworowski
raj at FreeBSD.org
Tue Dec 15 14:15:23 PST 2009
http://p4web.freebsd.org/chv.cgi?CH=171815
Change 171815 by raj at raj_fdt on 2009/12/15 22:15:21
Provide missing resources management methods for fdtbus driver.
Affected files ...
.. //depot/projects/fdt/sys/powerpc/mpc85xx/fdtbus.c#2 edit
Differences ...
==== //depot/projects/fdt/sys/powerpc/mpc85xx/fdtbus.c#2 (text+ko) ====
@@ -57,6 +57,8 @@
static MALLOC_DEFINE(M_FDTBUS, "fdtbus", "FDTbus devices information");
+extern struct bus_space bs_be_tag;
+
struct fdtbus_devinfo {
phandle_t di_node;
const char *di_name;
@@ -75,6 +77,19 @@
static int fdtbus_probe(device_t);
static int fdtbus_attach(device_t);
+static struct resource *fdtbus_alloc_resource(device_t, device_t, int,
+ int *, u_long, u_long, u_long, u_int);
+static int fdtbus_release_resource(device_t, device_t, int, int,
+ struct resource *);
+static int fdtbus_activate_resource(device_t, device_t, int, int,
+ struct resource *);
+static int fdtbus_deactivate_resource(device_t, device_t, int, int,
+ struct resource *);
+static int fdtbus_setup_intr(device_t, device_t, struct resource *, int,
+ driver_filter_t *, driver_intr_t *, void *, void **);
+static int fdtbus_teardown_intr(device_t, device_t, struct resource *,
+ void *);
+
static const char *fdtbus_ofw_get_name(device_t, device_t);
static phandle_t fdtbus_ofw_get_node(device_t, device_t);
static const char *fdtbus_ofw_get_type(device_t, device_t);
@@ -97,6 +112,14 @@
DEVMETHOD(device_suspend, bus_generic_suspend),
DEVMETHOD(device_resume, bus_generic_resume),
+ /* Bus interface */
+ DEVMETHOD(bus_alloc_resource, fdtbus_alloc_resource),
+ DEVMETHOD(bus_release_resource, fdtbus_release_resource),
+ DEVMETHOD(bus_activate_resource, fdtbus_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, fdtbus_deactivate_resource),
+ DEVMETHOD(bus_setup_intr, fdtbus_setup_intr),
+ DEVMETHOD(bus_teardown_intr, fdtbus_teardown_intr),
+
/* OFW bus interface */
DEVMETHOD(ofw_bus_get_node, fdtbus_ofw_get_node),
DEVMETHOD(ofw_bus_get_name, fdtbus_ofw_get_name),
@@ -235,6 +258,120 @@
return (child);
}
+static struct resource *
+fdtbus_alloc_resource(device_t bus, device_t child, int type, int *rid,
+ u_long start, u_long end, u_long count, u_int flags)
+{
+ struct fdtbus_softc *sc;
+ struct resource *res;
+ struct rman *rm;
+ int needactivate;
+
+ sc = device_get_softc(bus);
+
+ needactivate = flags & RF_ACTIVE;
+ flags &= ~RF_ACTIVE;
+
+ switch (type) {
+ case SYS_RES_IRQ:
+ rm = &sc->sc_irq;
+ break;
+
+ case SYS_RES_IOPORT:
+ case SYS_RES_MEMORY:
+ rm = &sc->sc_mem;
+ break;
+
+ default:
+ return (NULL);
+ }
+
+ res = rman_reserve_resource(rm, start, end, count, flags, child);
+ if (res == NULL) {
+ device_printf(bus, "failed to reserve resource %#lx - %#lx "
+ "(%#lx)\n", start, end, count);
+ return (NULL);
+ }
+
+ rman_set_rid(res, *rid);
+
+ if (type == SYS_RES_IOPORT || type == SYS_RES_MEMORY) {
+ /* XXX endianess should be set based on SOC node */
+ rman_set_bustag(res, &bs_be_tag);
+ rman_set_bushandle(res, rman_get_start(res));
+ }
+
+ if (needactivate)
+ if (bus_activate_resource(child, type, *rid, res)) {
+ device_printf(child, "resource activation failed\n");
+ rman_release_resource(res);
+ return (NULL);
+ }
+
+ return (res);
+}
+
+static int
+fdtbus_release_resource(device_t bus, device_t child, int type, int rid,
+ struct resource *res)
+{
+ int err;
+
+ if (rman_get_flags(res) & RF_ACTIVE) {
+ err = bus_deactivate_resource(child, type, rid, res);
+ if (err)
+ return (err);
+ }
+
+ return (rman_release_resource(res));
+}
+
+static int
+fdtbus_setup_intr(device_t bus, device_t child, struct resource *res,
+ int flags, driver_filter_t *filter, driver_intr_t *ihand, void *arg,
+ void **cookiep)
+{
+ int err;
+
+ *cookiep = 0;
+ if ((rman_get_flags(res) & RF_SHAREABLE) == 0)
+ flags |= INTR_EXCL;
+
+ err = rman_activate_resource(res);
+ if (err)
+ return (err);
+
+ err = powerpc_setup_intr(device_get_nameunit(child),
+ rman_get_start(res), filter, ihand, arg, flags, cookiep);
+
+ return (err);
+}
+
+static int
+fdtbus_activate_resource(device_t bus, device_t child, int type, int rid,
+ struct resource *res)
+{
+
+ return (rman_activate_resource(res));
+}
+
+static int
+fdtbus_deactivate_resource(device_t bus, device_t child, int type, int rid,
+ struct resource *res)
+{
+
+ return (rman_deactivate_resource(res));
+}
+
+
+static int
+fdtbus_teardown_intr(device_t bus, device_t child, struct resource *res,
+ void *cookie)
+{
+
+ return (powerpc_teardown_intr(cookie));
+}
+
static const char *
fdtbus_ofw_get_name(device_t bus, device_t dev)
{
More information about the p4-projects
mailing list