diff options
author | phk <phk@FreeBSD.org> | 2005-09-24 20:44:55 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2005-09-24 20:44:55 +0000 |
commit | 07f333af67ae3cf647bbe97f96f84334451e8f84 (patch) | |
tree | a321af6a46da42fda290c8a8ad90fcea1f5b19e9 /sys/dev/ieee488 | |
parent | 81a425948bada5590b8d692f6a60a131b7bd7f72 (diff) | |
download | FreeBSD-src-07f333af67ae3cf647bbe97f96f84334451e8f84.zip FreeBSD-src-07f333af67ae3cf647bbe97f96f84334451e8f84.tar.gz |
Use new bus_space/resource convenience functions.
Pretend the 10-bit I/O ISA addressing is not our problem.
Diffstat (limited to 'sys/dev/ieee488')
-rw-r--r-- | sys/dev/ieee488/pcii.c | 117 | ||||
-rw-r--r-- | sys/dev/ieee488/tnt4882.c | 88 | ||||
-rw-r--r-- | sys/dev/ieee488/upd7210.c | 11 | ||||
-rw-r--r-- | sys/dev/ieee488/upd7210.h | 3 |
4 files changed, 71 insertions, 148 deletions
diff --git a/sys/dev/ieee488/pcii.c b/sys/dev/ieee488/pcii.c index d575f69..6130b9c 100644 --- a/sys/dev/ieee488/pcii.c +++ b/sys/dev/ieee488/pcii.c @@ -56,8 +56,7 @@ __FBSDID("$FreeBSD$"); struct pcii_softc { int foo; - struct resource *port[8]; - struct resource *irq; + struct resource *res[2]; struct resource *dma; void *intr_handler; struct upd7210 upd7210; @@ -77,6 +76,13 @@ static device_method_t pcii_methods[] = { { 0, 0 } }; +static struct resource_spec pcii_res_spec[] = { + { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE}, + { SYS_RES_DRQ, 0, RF_ACTIVE | RF_SHAREABLE | RF_OPTIONAL}, + { SYS_RES_IOPORT, 0, RF_ACTIVE}, + { -1, 0, 0 } +}; + static driver_t pcii_driver = { "pcii", pcii_methods, @@ -86,12 +92,13 @@ static driver_t pcii_driver = { static int pcii_probe(device_t dev) { - struct resource *port; - int rid; + int rid, i, j; u_long start, count; - int i, j, error = 0; + int error = 0; + struct pcii_softc *sc; device_set_desc(dev, "PCII IEEE-4888 controller"); + sc = device_get_softc(dev); rid = 0; if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0) @@ -101,29 +108,26 @@ pcii_probe(device_t dev) count = 1; if (bus_set_resource(dev, SYS_RES_IOPORT, rid, start, count) != 0) return ENXIO; + error = bus_alloc_resources(dev, pcii_res_spec, sc->res); + if (error) + return (error); + error = ENXIO; for (i = 0; i < 8; i++) { - j = bus_set_resource(dev, SYS_RES_IOPORT, i, - start + 0x400 * i, 1); - if (j) { + j = bus_read_1(sc->res[2], i * 0x400); + if (j != 0x00 && j != 0xff) + error = 0; + } + if (!error) { + bus_write_1(sc->res[2], 3 * 0x400, 0x55); + if (bus_read_1(sc->res[2], 3 * 0x400) != 0x55) error = ENXIO; - break; - } - rid = i; - port = bus_alloc_resource_any(dev, SYS_RES_IOPORT, - &rid, RF_ACTIVE); - if (port == NULL) - return (ENXIO); - else - bus_release_resource(dev, SYS_RES_IOPORT, i, port); } - - rid = 0; - port = bus_alloc_resource_any(dev, - SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); - if (port == NULL) - return (ENXIO); - bus_release_resource(dev, SYS_RES_IRQ, rid, port); - + if (!error) { + bus_write_1(sc->res[2], 3 * 0x400, 0xaa); + if (bus_read_1(sc->res[2], 3 * 0x400) != 0xaa) + error = ENXIO; + } + bus_release_resources(dev, pcii_res_spec, sc->res); return (error); } @@ -133,7 +137,7 @@ pcii_attach(device_t dev) struct pcii_softc *sc; int unit; int rid; - int i, error = 0; + int error = 0; unit = device_get_unit(dev); sc = device_get_softc(dev); @@ -141,49 +145,28 @@ pcii_attach(device_t dev) device_set_desc(dev, "PCII IEEE-4888 controller"); - for (rid = 0; rid < 8; rid++) { - sc->port[rid] = bus_alloc_resource_any(dev, - SYS_RES_IOPORT, &rid, RF_ACTIVE); - if (sc->port[rid] == NULL) { - error = ENXIO; - break; - } - sc->upd7210.reg_tag[rid] = rman_get_bustag(sc->port[rid]); - sc->upd7210.reg_handle[rid] = rman_get_bushandle(sc->port[rid]); - } - if (!error) { - rid = 0; - sc->irq = bus_alloc_resource_any(dev, - SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); - if (sc->irq == NULL) { - error = ENXIO; - } else { - error = bus_setup_intr(dev, sc->irq, - INTR_TYPE_MISC | INTR_MPSAFE, - upd7210intr, &sc->upd7210, &sc->intr_handler); - } - } - if (!error) { - rid = 0; - sc->dma = bus_alloc_resource_any(dev, - SYS_RES_DRQ, &rid, RF_ACTIVE | RF_SHAREABLE); - if (sc->dma == NULL) - sc->upd7210.dmachan = -1; - else - sc->upd7210.dmachan = rman_get_start(sc->dma); - } + error = bus_alloc_resources(dev, pcii_res_spec, sc->res); + if (error) + return (error); + + error = bus_setup_intr(dev, sc->res[0], + INTR_TYPE_MISC | INTR_MPSAFE, + upd7210intr, &sc->upd7210, &sc->intr_handler); if (error) { - for (i = 0; i < 8; i++) { - if (sc->port[i] == NULL) - break; - bus_release_resource(dev, SYS_RES_IOPORT, - 0, sc->port[i]); - } - if (sc->intr_handler != NULL) - bus_teardown_intr(dev, sc->irq, sc->intr_handler); - if (sc->irq != NULL) - bus_release_resource(dev, SYS_RES_IRQ, i, sc->irq); + bus_release_resources(dev, pcii_res_spec, sc->res); + return (error); + } + + for (rid = 0; rid < 8; rid++) { + sc->upd7210.reg_res[rid] = sc->res[2]; + sc->upd7210.reg_offset[rid] = 0x400 * rid; } + + if (sc->res[1] == NULL) + sc->upd7210.dmachan = -1; + else + sc->upd7210.dmachan = rman_get_start(sc->res[1]); + upd7210attach(&sc->upd7210); return (error); } diff --git a/sys/dev/ieee488/tnt4882.c b/sys/dev/ieee488/tnt4882.c index 4910f62..4209bb3 100644 --- a/sys/dev/ieee488/tnt4882.c +++ b/sys/dev/ieee488/tnt4882.c @@ -51,12 +51,17 @@ struct tnt_softc { int foo; struct upd7210 upd7210; - struct resource *res0, *res1, *res2; - bus_space_tag_t bt0, bt1; - bus_space_handle_t bh0, bh1; + struct resource *res[3]; void *intr_handler; }; +static struct resource_spec tnt_res_spec[] = { + { SYS_RES_MEMORY, PCIR_BAR(0), RF_ACTIVE}, + { SYS_RES_MEMORY, PCIR_BAR(1), RF_ACTIVE}, + { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE}, + { -1, 0 } +}; + enum tnt4882reg { dir = 0x00, cdor = 0x00, @@ -229,10 +234,10 @@ tst_exec(struct tnt_softc *sc, struct tst *tp, const char *name) for (step = 0; tp->action != END; tp++, step++) { switch (tp->action) { case WT: - bus_space_write_1(sc->bt1, sc->bh1, tp->reg, tp->val); + bus_write_1(sc->res[1], tp->reg, tp->val); break; case RD: - u = bus_space_read_1(sc->bt1, sc->bh1, tp->reg); + u = bus_read_1(sc->res[1], tp->reg); if (u != tp->val) { printf( "Test %s, step %d: reg(%02x) = %02x", @@ -256,56 +261,6 @@ tst_exec(struct tnt_softc *sc, struct tst *tp, const char *name) } static int -bus_dwiw(device_t dev, ...) -{ - va_list ap, ap2; - int rid; - int type; - int flags; - struct resource **rp; - bus_space_tag_t *bt; - bus_space_handle_t *bh; - - va_start(ap, dev); - va_copy(ap2, ap); - while (1) { - type = va_arg(ap, int); - if (type == -1) { - va_end(ap); - return (0); - } - rid = va_arg(ap, int); - flags = va_arg(ap, int); - rp = va_arg(ap, struct resource **); - *rp = bus_alloc_resource_any(dev, type, &rid, flags); - if (*rp == NULL) - break; - if (type == SYS_RES_IOPORT || type == SYS_RES_MEMORY) { - bt = va_arg(ap, bus_space_tag_t *); - *bt = rman_get_bustag(*rp); - bh = va_arg(ap, bus_space_handle_t *); - *bh = rman_get_bushandle(*rp); - } - } - while (1) { - type = va_arg(ap2, int); - KASSERT(type != -1, ("bus_dwiw() internal mess")); - rid = va_arg(ap2, int); - flags = va_arg(ap2, int); - rp = va_arg(ap2, struct resource **); - if (*rp != NULL) - bus_release_resource(dev, type, rid, *rp); - else { - va_end(ap2); - return (ENXIO); - } - if (type == SYS_RES_IOPORT || type == SYS_RES_MEMORY) { - bt = va_arg(ap2, bus_space_tag_t *); - bh = va_arg(ap2, bus_space_handle_t *); - } - } -} -static int tnt_probe(device_t dev) { @@ -324,21 +279,15 @@ tnt_attach(device_t dev) sc = device_get_softc(dev); - error = bus_dwiw(dev, - SYS_RES_MEMORY, PCIR_BAR(0), RF_ACTIVE, - &sc->res0, &sc->bt0, &sc->bh0, - SYS_RES_MEMORY, PCIR_BAR(1), RF_ACTIVE, - &sc->res1, &sc->bt1, &sc->bh1, - SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE, &sc->res2, - -1); + error = bus_alloc_resources(dev, tnt_res_spec, sc->res); if (error) return (error); - error = bus_setup_intr(dev, sc->res2, INTR_TYPE_MISC | INTR_MPSAFE, + error = bus_setup_intr(dev, sc->res[2], INTR_TYPE_MISC | INTR_MPSAFE, upd7210intr, &sc->upd7210, &sc->intr_handler); /* Necessary magic for MITE */ - bus_space_write_4(sc->bt0, sc->bh0, 0xc0, vtophys(sc->bh1) | 0x80); + bus_write_4(sc->res[0], 0xc0, rman_get_start(sc->res[1]) | 0x80); tst_exec(sc, tst_reset, "Reset"); tst_exec(sc, tst_read_reg, "Read registers"); @@ -350,11 +299,10 @@ tnt_attach(device_t dev) tst_exec(sc, tst_reset, "Reset"); /* pass 7210 interrupts through */ - bus_space_write_1(sc->bt1, sc->bh1, imr3, 0x02); + bus_write_1(sc->res[1], imr3, 0x02); for (i = 0; i < 8; i++) { - sc->upd7210.reg_tag[i] = sc->bt1; - sc->upd7210.reg_handle[i] = sc->bh1; + sc->upd7210.reg_res[i] = sc->res[1]; sc->upd7210.reg_offset[i] = i * 2; } @@ -372,12 +320,10 @@ tnt_detach(device_t dev) struct tnt_softc *sc; sc = device_get_softc(dev); - bus_teardown_intr(dev, sc->res2, sc->intr_handler); + bus_teardown_intr(dev, sc->res[2], sc->intr_handler); upd7210detach(&sc->upd7210); - bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0), sc->res0); - bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(1), sc->res1); - bus_release_resource(dev, SYS_RES_IRQ, 0, sc->res2); + bus_release_resources(dev, tnt_res_spec, sc->res); return (0); } diff --git a/sys/dev/ieee488/upd7210.c b/sys/dev/ieee488/upd7210.c index 69b8c0b..30f9762 100644 --- a/sys/dev/ieee488/upd7210.c +++ b/sys/dev/ieee488/upd7210.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include <sys/kernel.h> #include <sys/limits.h> #include <sys/module.h> +#include <sys/rman.h> #include <sys/bus.h> #include <sys/lock.h> #include <sys/mutex.h> @@ -70,10 +71,7 @@ upd7210_rd(struct upd7210 *u, enum upd7210_rreg reg) { u_int r; - r = bus_space_read_1( - u->reg_tag[reg], - u->reg_handle[reg], - u->reg_offset[reg]); + r = bus_read_1(u->reg_res[reg], u->reg_offset[reg]); u->rreg[reg] = r; return (r); } @@ -82,10 +80,7 @@ void upd7210_wr(struct upd7210 *u, enum upd7210_wreg reg, u_int val) { - bus_space_write_1( - u->reg_tag[reg], - u->reg_handle[reg], - u->reg_offset[reg], val); + bus_write_1(u->reg_res[reg], u->reg_offset[reg], val); u->wreg[reg] = val; if (reg == AUXMR) u->wreg[8 + (val >> 5)] = val & 0x1f; diff --git a/sys/dev/ieee488/upd7210.h b/sys/dev/ieee488/upd7210.h index 7c18b7e..da1032c 100644 --- a/sys/dev/ieee488/upd7210.h +++ b/sys/dev/ieee488/upd7210.h @@ -47,8 +47,7 @@ struct ibfoo; typedef int upd7210_irq_t(struct upd7210 *, int); struct upd7210 { - bus_space_handle_t reg_handle[8]; - bus_space_tag_t reg_tag[8]; + struct resource *reg_res[8]; u_int reg_offset[8]; int dmachan; int unit; |