PERFORCE change 64481 for review
Marcel Moolenaar
marcel at FreeBSD.org
Sat Nov 6 21:50:10 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=64481
Change 64481 by marcel at marcel_nfs on 2004/11/07 05:49:23
Add resource allocation and release related code. With this,
uart(4) probes as a child of scc(4). Next, IRQ handling so
that we can do something other than wait for the interrupt
storm to pass over...
Affected files ...
.. //depot/projects/uart/dev/scc/scc_core.c#4 edit
Differences ...
==== //depot/projects/uart/dev/scc/scc_core.c#4 (text+ko) ====
@@ -27,6 +27,8 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#define __RMAN_RESOURCE_VISIBLE /* XXX shouldn't be needed. */
+
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
@@ -55,10 +57,12 @@
int
scc_bfe_attach(device_t dev)
{
+ struct resource_list_entry *rle;
struct scc_chan *ch;
struct scc_class *cl;
struct scc_mode *m;
struct scc_softc *sc;
+ bus_space_handle_t bh;
u_long size, start;
int c, error, i, mode;
@@ -102,14 +106,29 @@
for (c = 1; c <= cl->cl_channels; c++) {
ch = malloc(sizeof(struct scc_chan), M_SCC, M_WAITOK | M_ZERO);
STAILQ_INSERT_TAIL(&sc->sc_chan, ch, ch_link);
+ resource_list_init(&ch->ch_rlist);
ch->ch_nr = c;
- resource_list_init(&ch->ch_rlist);
resource_list_add(&ch->ch_rlist, sc->sc_rtype, sc->sc_rrid,
start, start + size - 1, size);
+ rle = resource_list_find(&ch->ch_rlist, sc->sc_rtype,
+ sc->sc_rrid);
+ rle->res = malloc(sizeof(struct resource), M_SCC,
+ M_WAITOK | M_ZERO);
+ rman_set_start(rle->res, rle->start);
+ rman_set_end(rle->res, rle->end);
+ bus_space_subregion(rman_get_bustag(sc->sc_rres),
+ rman_get_bushandle(sc->sc_rres),
+ start - rman_get_start(sc->sc_rres), size, &bh);
+ rman_set_bushandle(rle->res, bh);
+ rman_set_bustag(rle->res, rman_get_bustag(sc->sc_rres));
+
resource_list_add(&ch->ch_rlist, SYS_RES_IRQ, sc->sc_irid,
rman_get_start(sc->sc_ires), rman_get_end(sc->sc_ires), 1);
-
+ rle = resource_list_find(&ch->ch_rlist, SYS_RES_IRQ,
+ sc->sc_irid);
+ rle->res = sc->sc_ires;
+
STAILQ_INIT(&ch->ch_mode);
mode = cl->cl_modes;
while (mode != 0) {
@@ -184,16 +203,49 @@
scc_bus_alloc_resource(device_t dev, device_t child, int type, int *rid,
u_long start, u_long end, u_long count, u_int flags)
{
- device_printf(dev, "%s\n", __func__);
- return (NULL);
+ struct resource_list_entry *rle;
+ struct scc_chan *ch;
+ struct scc_mode *m;
+
+ /* We only support default allocations. */
+ if (start != 0UL || end != ~0UL)
+ return (NULL);
+
+ /* We don't support any grandchildren or children thereof. */
+ if (device_get_parent(child) != dev)
+ return (NULL);
+
+ m = device_get_ivars(child);
+ ch = m->m_chan;
+ rle = resource_list_find(&ch->ch_rlist, type, *rid);
+ if (rle == NULL)
+ return (NULL);
+ return (rle->res);
}
int
scc_bus_get_resource(device_t dev, device_t child, int type, int rid,
u_long *startp, u_long *countp)
{
+ struct resource_list_entry *rle;
+ struct scc_chan *ch;
+ struct scc_mode *m;
+
+ /* We don't support any grandchildren or children thereof. */
+ if (device_get_parent(child) != dev)
+ return (EINVAL);
+
+ m = device_get_ivars(child);
+ ch = m->m_chan;
+ rle = resource_list_find(&ch->ch_rlist, type, rid);
+ if (rle == NULL)
+ return (EINVAL);
- return (ENXIO);
+ if (startp != NULL)
+ *startp = rle->start;
+ if (countp != NULL)
+ *countp = rle->count;
+ return (0);
}
int
@@ -235,8 +287,18 @@
scc_bus_release_resource(device_t dev, device_t child, int type, int rid,
struct resource *res)
{
+ struct resource_list_entry *rle;
+ struct scc_chan *ch;
+ struct scc_mode *m;
- return (ENXIO);
+ /* We don't support any grandchildren or children thereof. */
+ if (device_get_parent(child) != dev)
+ return (EINVAL);
+
+ m = device_get_ivars(child);
+ ch = m->m_chan;
+ rle = resource_list_find(&ch->ch_rlist, type, rid);
+ return ((rle == NULL) ? EINVAL : 0);
}
int
More information about the p4-projects
mailing list