From owner-freebsd-arch@FreeBSD.ORG Fri Sep 23 20:33:49 2005 Return-Path: X-Original-To: freebsd-arch@freebsd.org Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CF71216A41F for ; Fri, 23 Sep 2005 20:33:49 +0000 (GMT) (envelope-from phk@critter.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B57543D49 for ; Fri, 23 Sep 2005 20:33:48 +0000 (GMT) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (unknown [192.168.48.2]) by phk.freebsd.dk (Postfix) with ESMTP id 08568BC66 for ; Fri, 23 Sep 2005 20:33:46 +0000 (UTC) To: freebsd-arch@freebsd.org From: "Poul-Henning Kamp" In-Reply-To: Your message of "Tue, 20 Sep 2005 16:08:35 EDT." <200509201608.36461.jhb@FreeBSD.org> Date: Fri, 23 Sep 2005 22:33:46 +0200 Message-ID: <59445.1127507626@critter.freebsd.dk> Sender: phk@critter.freebsd.dk Subject: Re: Improving bus/resource API (take 2) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Sep 2005 20:33:49 -0000 OK, take two, changes from last: * naming changes adopted. * wrapper macros moved to sys/bus.h, and geneated with a script. The script is not run at compile time, and will go in src/tools/bus_macro.sh, but it is not included in this patch. * device_t typedef in sys/types.h instead of sys/param.h * lost flags in two drivers restored. I do wonder if these flags should not have sensible defaults (RF_ACTIVE for IO/MEM, RF_ACTIVE|RF_SHAREABLE for IRQ ?) * Add comment about why changing struct resource is bad. I would personally still prefer to do a s/bus_read/bus_rd/ s/bus_write/bus_wr/ to slim down the names further, but I can live with this patch. Index: dev/ieee488/tnt4882.c =================================================================== RCS file: /home/ncvs/src/sys/dev/ieee488/tnt4882.c,v retrieving revision 1.1 diff -u -r1.1 tnt4882.c --- dev/ieee488/tnt4882.c 15 Sep 2005 13:27:16 -0000 1.1 +++ dev/ieee488/tnt4882.c 23 Sep 2005 19:35:33 -0000 @@ -51,12 +51,17 @@ 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 @@ 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 @@ } 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 @@ 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,11 @@ 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_tag[i] = rman_get_bustag(sc->res[1]); + sc->upd7210.reg_handle[i] = rman_get_bushandle(sc->res[1]); sc->upd7210.reg_offset[i] = i * 2; } @@ -372,12 +321,10 @@ 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); } Index: kern/subr_rman.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_rman.c,v retrieving revision 1.43 diff -u -r1.43 subr_rman.c --- kern/subr_rman.c 6 May 2005 02:48:20 -0000 1.43 +++ kern/subr_rman.c 23 Sep 2005 19:46:43 -0000 @@ -81,10 +81,22 @@ struct rman_head rman_head; static struct mtx rman_mtx; /* mutex to protect rman_head */ -static int int_rman_activate_resource(struct rman *rm, struct resource *r, - struct resource **whohas); -static int int_rman_deactivate_resource(struct resource *r); -static int int_rman_release_resource(struct rman *rm, struct resource *r); +static int int_rman_activate_resource(struct rman *rm, struct resource_i *r, + struct resource_i **whohas); +static int int_rman_deactivate_resource(struct resource_i *r); +static int int_rman_release_resource(struct rman *rm, struct resource_i *r); + +static __inline struct resource_i * +int_alloc_resource(int malloc_flag) +{ + struct resource_i *r; + + r = malloc(sizeof *r, M_RMAN, malloc_flag | M_ZERO); + if (r != NULL) { + r->r_r.__r_i = r; + } + return (r); +} int rman_init(struct rman *rm) @@ -121,11 +133,11 @@ int rman_manage_region(struct rman *rm, u_long start, u_long end) { - struct resource *r, *s; + struct resource_i *r, *s; DPRINTF(("rman_manage_region: <%s> request: start %#lx, end %#lx\n", rm->rm_descr, start, end)); - r = malloc(sizeof *r, M_RMAN, M_NOWAIT | M_ZERO); + r = int_alloc_resource(M_NOWAIT); if (r == 0) return ENOMEM; r->r_start = start; @@ -151,7 +163,7 @@ int rman_fini(struct rman *rm) { - struct resource *r; + struct resource_i *r; mtx_lock(rm->rm_mtx); TAILQ_FOREACH(r, &rm->rm_list, r_link) { @@ -186,7 +198,7 @@ struct device *dev) { u_int want_activate; - struct resource *r, *s, *rv; + struct resource_i *r, *s, *rv; u_long rstart, rend, amask, bmask; rv = 0; @@ -267,7 +279,7 @@ * split it in two. The first case requires * two new allocations; the second requires but one. */ - rv = malloc(sizeof *rv, M_RMAN, M_NOWAIT | M_ZERO); + rv = int_alloc_resource(M_NOWAIT); if (rv == 0) goto out; rv->r_start = rstart; @@ -285,7 +297,7 @@ /* * We are allocating in the middle. */ - r = malloc(sizeof *r, M_RMAN, M_NOWAIT|M_ZERO); + r = int_alloc_resource(M_NOWAIT); if (r == 0) { free(rv, M_RMAN); rv = 0; @@ -343,7 +355,7 @@ && (s->r_end - s->r_start + 1) == count && (s->r_start & amask) == 0 && ((s->r_start ^ s->r_end) & bmask) == 0) { - rv = malloc(sizeof *rv, M_RMAN, M_NOWAIT | M_ZERO); + rv = int_alloc_resource(M_NOWAIT); if (rv == 0) goto out; rv->r_start = s->r_start; @@ -383,7 +395,7 @@ * make sense for RF_TIMESHARE-type resources.) */ if (rv && want_activate) { - struct resource *whohas; + struct resource_i *whohas; if (int_rman_activate_resource(rm, rv, &whohas)) { int_rman_release_resource(rm, rv); rv = 0; @@ -391,7 +403,7 @@ } mtx_unlock(rm->rm_mtx); - return (rv); + return (&rv->r_r); } struct resource * @@ -404,10 +416,10 @@ } static int -int_rman_activate_resource(struct rman *rm, struct resource *r, - struct resource **whohas) +int_rman_activate_resource(struct rman *rm, struct resource_i *r, + struct resource_i **whohas) { - struct resource *s; + struct resource_i *s; int ok; /* @@ -439,12 +451,13 @@ } int -rman_activate_resource(struct resource *r) +rman_activate_resource(struct resource *re) { int rv; - struct resource *whohas; + struct resource_i *r, *whohas; struct rman *rm; + r = re->__r_i; rm = r->r_rm; mtx_lock(rm->rm_mtx); rv = int_rman_activate_resource(rm, r, &whohas); @@ -453,12 +466,13 @@ } int -rman_await_resource(struct resource *r, int pri, int timo) +rman_await_resource(struct resource *re, int pri, int timo) { int rv; - struct resource *whohas; + struct resource_i *r, *whohas; struct rman *rm; + r = re->__r_i; rm = r->r_rm; mtx_lock(rm->rm_mtx); for (;;) { @@ -478,7 +492,7 @@ } static int -int_rman_deactivate_resource(struct resource *r) +int_rman_deactivate_resource(struct resource_i *r) { r->r_flags &= ~RF_ACTIVE; @@ -494,17 +508,17 @@ { struct rman *rm; - rm = r->r_rm; + rm = r->__r_i->r_rm; mtx_lock(rm->rm_mtx); - int_rman_deactivate_resource(r); + int_rman_deactivate_resource(r->__r_i); mtx_unlock(rm->rm_mtx); return 0; } static int -int_rman_release_resource(struct rman *rm, struct resource *r) +int_rman_release_resource(struct rman *rm, struct resource_i *r) { - struct resource *s, *t; + struct resource_i *s, *t; if (r->r_flags & RF_ACTIVE) int_rman_deactivate_resource(r); @@ -595,11 +609,14 @@ } int -rman_release_resource(struct resource *r) +rman_release_resource(struct resource *re) { int rv; - struct rman *rm = r->r_rm; + struct resource_i *r; + struct rman *rm; + r = re->__r_i; + rm = r->r_rm; mtx_lock(rm->rm_mtx); rv = int_rman_release_resource(rm, r); mtx_unlock(rm->rm_mtx); @@ -627,37 +644,37 @@ u_long rman_get_start(struct resource *r) { - return (r->r_start); + return (r->__r_i->r_start); } u_long rman_get_end(struct resource *r) { - return (r->r_end); + return (r->__r_i->r_end); } u_long rman_get_size(struct resource *r) { - return (r->r_end - r->r_start + 1); + return (r->__r_i->r_end - r->__r_i->r_start + 1); } u_int rman_get_flags(struct resource *r) { - return (r->r_flags); + return (r->__r_i->r_flags); } void rman_set_virtual(struct resource *r, void *v) { - r->r_virtual = v; + r->__r_i->r_virtual = v; } void * rman_get_virtual(struct resource *r) { - return (r->r_virtual); + return (r->__r_i->r_virtual); } void @@ -687,37 +704,69 @@ void rman_set_rid(struct resource *r, int rid) { - r->r_rid = rid; + r->__r_i->r_rid = rid; } void rman_set_start(struct resource *r, u_long start) { - r->r_start = start; + r->__r_i->r_start = start; } void rman_set_end(struct resource *r, u_long end) { - r->r_end = end; + r->__r_i->r_end = end; } int rman_get_rid(struct resource *r) { - return (r->r_rid); + return (r->__r_i->r_rid); } struct device * rman_get_device(struct resource *r) { - return (r->r_dev); + return (r->__r_i->r_dev); } void rman_set_device(struct resource *r, struct device *dev) { - r->r_dev = dev; + r->__r_i->r_dev = dev; +} + +/* + * Device driver convenience functions + */ + +int +bus_alloc_resources(device_t dev, struct resource_spec *rs, struct resource **res) +{ + int i; + + for (i = 0; rs[i].type != -1; i++) + res[i] = NULL; + for (i = 0; rs[i].type != -1; i++) { + res[i] = bus_alloc_resource_any(dev, + rs[i].type, &rs[i].rid, rs[i].flags); + if (res[i] == NULL) { + bus_release_resources(dev, rs, res); + return (ENXIO); + } + } + return (0); +} + +void +bus_release_resources(device_t dev, struct resource_spec *rs, struct resource **res) +{ + int i; + + for (i = 0; rs[i].type != -1; i++) + if (res[i] != NULL) + bus_release_resource(dev, rs[i].type, rs[i].rid, res[i]); } /* @@ -733,7 +782,7 @@ u_int namelen = arg2; int rman_idx, res_idx; struct rman *rm; - struct resource *res; + struct resource_i *res; struct u_rman urm; struct u_resource ures; int error; Index: pci/if_sis.c =================================================================== RCS file: /home/ncvs/src/sys/pci/if_sis.c,v retrieving revision 1.137 diff -u -r1.137 if_sis.c --- pci/if_sis.c 20 Sep 2005 09:52:53 -0000 1.137 +++ pci/if_sis.c 23 Sep 2005 19:28:49 -0000 @@ -107,14 +107,11 @@ /* * register space access macros */ -#define CSR_WRITE_4(sc, reg, val) \ - bus_space_write_4(sc->sis_btag, sc->sis_bhandle, reg, val) +#define CSR_WRITE_4(sc, reg, val) bus_write_4(sc->sis_res[0], reg, val) -#define CSR_READ_4(sc, reg) \ - bus_space_read_4(sc->sis_btag, sc->sis_bhandle, reg) +#define CSR_READ_4(sc, reg) bus_read_4(sc->sis_res[0], reg) -#define CSR_READ_2(sc, reg) \ - bus_space_read_2(sc->sis_btag, sc->sis_bhandle, reg) +#define CSR_READ_2(sc, reg) bus_read_2(sc->sis_res[0], reg) /* * Various supported device vendors/types and their names. @@ -147,6 +144,12 @@ #define SIS_RID SIS_PCI_LOMEM #endif +static struct resource_spec sis_res_spec[] = { + { SIS_RES, SIS_RID, RF_ACTIVE}, + { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE}, + { -1, 0 } +}; + #define SIS_SETBIT(sc, reg, x) \ CSR_WRITE_4(sc, reg, \ CSR_READ_4(sc, reg) | (x)) @@ -919,7 +922,7 @@ u_char eaddr[ETHER_ADDR_LEN]; struct sis_softc *sc; struct ifnet *ifp; - int unit, error = 0, rid, waittime = 0; + int unit, error = 0, waittime = 0; waittime = 0; sc = device_get_softc(dev); @@ -943,28 +946,9 @@ */ pci_enable_busmaster(dev); - rid = SIS_RID; - sc->sis_res = bus_alloc_resource_any(dev, SIS_RES, &rid, RF_ACTIVE); - - if (sc->sis_res == NULL) { - printf("sis%d: couldn't map ports/memory\n", unit); - error = ENXIO; - goto fail; - } - - sc->sis_btag = rman_get_bustag(sc->sis_res); - sc->sis_bhandle = rman_get_bushandle(sc->sis_res); - - /* Allocate interrupt */ - rid = 0; - sc->sis_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, - RF_SHAREABLE | RF_ACTIVE); - - if (sc->sis_irq == NULL) { - printf("sis%d: couldn't map interrupt\n", unit); - error = ENXIO; - goto fail; - } + error = bus_alloc_resources(dev, sis_res_spec, sc->sis_res); + if (error) + return (error); /* Reset the adapter. */ sis_reset(sc); @@ -1257,7 +1241,7 @@ ifp->if_capenable = ifp->if_capabilities; /* Hook interrupt last to avoid having to lock softc */ - error = bus_setup_intr(dev, sc->sis_irq, INTR_TYPE_NET | INTR_MPSAFE, + error = bus_setup_intr(dev, sc->sis_res[1], INTR_TYPE_NET | INTR_MPSAFE, sis_intr, sc, &sc->sis_intrhand); if (error) { @@ -1304,11 +1288,9 @@ bus_generic_detach(dev); if (sc->sis_intrhand) - bus_teardown_intr(dev, sc->sis_irq, sc->sis_intrhand); - if (sc->sis_irq) - bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sis_irq); - if (sc->sis_res) - bus_release_resource(dev, SIS_RES, SIS_RID, sc->sis_res); + bus_teardown_intr(dev, sc->sis_res[1], sc->sis_intrhand); + + bus_release_resources(dev, sis_res_spec, sc->sis_res); if (sc->sis_rx_tag) { bus_dmamap_unload(sc->sis_rx_tag, Index: pci/if_sisreg.h =================================================================== RCS file: /home/ncvs/src/sys/pci/if_sisreg.h,v retrieving revision 1.34 diff -u -r1.34 if_sisreg.h --- pci/if_sisreg.h 20 Sep 2005 09:52:53 -0000 1.34 +++ pci/if_sisreg.h 20 Sep 2005 11:00:52 -0000 @@ -431,10 +431,7 @@ struct sis_softc { struct ifnet *sis_ifp; /* interface info */ - bus_space_handle_t sis_bhandle; - bus_space_tag_t sis_btag; - struct resource *sis_res; - struct resource *sis_irq; + struct resource *sis_res[2]; void *sis_intrhand; device_t sis_self; device_t sis_miibus; Index: sys/bus.h =================================================================== RCS file: /home/ncvs/src/sys/sys/bus.h,v retrieving revision 1.71 diff -u -r1.71 bus.h --- sys/bus.h 18 Sep 2005 01:32:09 -0000 1.71 +++ sys/bus.h 23 Sep 2005 19:56:19 -0000 @@ -85,11 +85,6 @@ const char *__type, const char *__data); void devctl_queue_data(char *__data); -/* - * Forward declarations - */ -typedef struct device *device_t; - /** * @brief A device driver (included mainly for compatibility with * FreeBSD 4.x). @@ -294,6 +289,16 @@ * Wrapper functions for the BUS_*_RESOURCE methods to make client code * a little simpler. */ + +struct resource_spec { + int type; + int rid; + int flags; +}; + +int bus_alloc_resources(device_t dev, struct resource_spec *rs, struct resource **res); +void bus_release_resources(device_t dev, struct resource_spec *rs, struct resource **res); + struct resource *bus_alloc_resource(device_t dev, int type, int *rid, u_long start, u_long end, u_long count, u_int flags); @@ -514,6 +519,141 @@ ivarp ## _IVAR_ ## ivar, v); \ } +/** + * Shorthand macros, taking resource argument + * Generated with sys/tools/bus_macro.sh + */ + +#define bus_barrier(r, o, l, f) \ + bus_space_barrier((r)->r_bustag, (r)->r_bushandle, (o), (l), (f)) +#define bus_read_1(r, o) \ + bus_space_read_1((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_1(r, o, d, c) \ + bus_space_read_multi_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_1(r, o, d, c) \ + bus_space_read_region_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_1(r, o, v, c) \ + bus_space_set_multi_1((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_1(r, o, v, c) \ + bus_space_set_region_1((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_1(r, o, v) \ + bus_space_write_1((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_1(r, o, d, c) \ + bus_space_write_multi_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_1(r, o, d, c) \ + bus_space_write_region_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_stream_1(r, o) \ + bus_space_read_stream_1((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_stream_1(r, o, d, c) \ + bus_space_read_multi_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_stream_1(r, o, d, c) \ + bus_space_read_region_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_stream_1(r, o, v, c) \ + bus_space_set_multi_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_stream_1(r, o, v, c) \ + bus_space_set_region_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_stream_1(r, o, v) \ + bus_space_write_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_stream_1(r, o, d, c) \ + bus_space_write_multi_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_stream_1(r, o, d, c) \ + bus_space_write_region_stream_1((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_2(r, o) \ + bus_space_read_2((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_2(r, o, d, c) \ + bus_space_read_multi_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_2(r, o, d, c) \ + bus_space_read_region_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_2(r, o, v, c) \ + bus_space_set_multi_2((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_2(r, o, v, c) \ + bus_space_set_region_2((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_2(r, o, v) \ + bus_space_write_2((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_2(r, o, d, c) \ + bus_space_write_multi_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_2(r, o, d, c) \ + bus_space_write_region_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_stream_2(r, o) \ + bus_space_read_stream_2((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_stream_2(r, o, d, c) \ + bus_space_read_multi_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_stream_2(r, o, d, c) \ + bus_space_read_region_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_stream_2(r, o, v, c) \ + bus_space_set_multi_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_stream_2(r, o, v, c) \ + bus_space_set_region_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_stream_2(r, o, v) \ + bus_space_write_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_stream_2(r, o, d, c) \ + bus_space_write_multi_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_stream_2(r, o, d, c) \ + bus_space_write_region_stream_2((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_4(r, o) \ + bus_space_read_4((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_4(r, o, d, c) \ + bus_space_read_multi_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_4(r, o, d, c) \ + bus_space_read_region_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_4(r, o, v, c) \ + bus_space_set_multi_4((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_4(r, o, v, c) \ + bus_space_set_region_4((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_4(r, o, v) \ + bus_space_write_4((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_4(r, o, d, c) \ + bus_space_write_multi_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_4(r, o, d, c) \ + bus_space_write_region_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_stream_4(r, o) \ + bus_space_read_stream_4((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_stream_4(r, o, d, c) \ + bus_space_read_multi_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_stream_4(r, o, d, c) \ + bus_space_read_region_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_stream_4(r, o, v, c) \ + bus_space_set_multi_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_stream_4(r, o, v, c) \ + bus_space_set_region_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_stream_4(r, o, v) \ + bus_space_write_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_stream_4(r, o, d, c) \ + bus_space_write_multi_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_stream_4(r, o, d, c) \ + bus_space_write_region_stream_4((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_8(r, o) \ + bus_space_read_8((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_8(r, o, d, c) \ + bus_space_read_multi_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_8(r, o, d, c) \ + bus_space_read_region_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_8(r, o, v, c) \ + bus_space_set_multi_8((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_8(r, o, v, c) \ + bus_space_set_region_8((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_8(r, o, v) \ + bus_space_write_8((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_8(r, o, d, c) \ + bus_space_write_multi_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_8(r, o, d, c) \ + bus_space_write_region_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_stream_8(r, o) \ + bus_space_read_stream_8((r)->r_bustag, (r)->r_bushandle, (o)) +#define bus_read_multi_stream_8(r, o, d, c) \ + bus_space_read_multi_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_read_region_stream_8(r, o, d, c) \ + bus_space_read_region_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_set_multi_stream_8(r, o, v, c) \ + bus_space_set_multi_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_set_region_stream_8(r, o, v, c) \ + bus_space_set_region_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (v), (c)) +#define bus_write_stream_8(r, o, v) \ + bus_space_write_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (v)) +#define bus_write_multi_stream_8(r, o, d, c) \ + bus_space_write_multi_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) +#define bus_write_region_stream_8(r, o, d, c) \ + bus_space_write_region_stream_8((r)->r_bustag, (r)->r_bushandle, (o), (d), (c)) #endif /* _KERNEL */ #endif /* !_SYS_BUS_H_ */ Index: sys/rman.h =================================================================== RCS file: /home/ncvs/src/sys/sys/rman.h,v retrieving revision 1.27 diff -u -r1.27 rman.h --- sys/rman.h 12 Apr 2005 06:21:58 -0000 1.27 +++ sys/rman.h 23 Sep 2005 19:43:22 -0000 @@ -84,6 +84,21 @@ }; #ifdef _KERNEL + +/* + * The public (kernel) view of struct resource + * + * NB: Changing the offset/size/type of existing fields in struct resource + * NB: breaks the device driver ABI and is strongly FORBIDDEN. + * NB: Appending new fields is probably just misguided. + */ + +struct resource { + struct resource_i *__r_i; + bus_space_tag_t r_bustag; /* bus_space tag */ + bus_space_handle_t r_bushandle; /* bus_space handle */ +}; + /* * We use a linked list rather than a bitmap because we need to be able to * represent potentially huge objects (like all of a processor's physical @@ -93,18 +108,17 @@ * at some point in the future, particularly if we want to support 36-bit * addresses on IA32 hardware. */ -TAILQ_HEAD(resource_head, resource); +TAILQ_HEAD(resource_head, resource_i); #ifdef __RMAN_RESOURCE_VISIBLE -struct resource { - TAILQ_ENTRY(resource) r_link; - LIST_ENTRY(resource) r_sharelink; - LIST_HEAD(, resource) *r_sharehead; +struct resource_i { + struct resource r_r; + TAILQ_ENTRY(resource_i) r_link; + LIST_ENTRY(resource_i) r_sharelink; + LIST_HEAD(, resource_i) *r_sharehead; u_long r_start; /* index of the first entry in this resource */ u_long r_end; /* index of the last entry (inclusive) */ u_int r_flags; void *r_virtual; /* virtual address of this resource */ - bus_space_tag_t r_bustag; /* bus_space tag */ - bus_space_handle_t r_bushandle; /* bus_space handle */ struct device *r_dev; /* device which has allocated this resource */ struct rman *r_rm; /* resource manager from whence this came */ void *r_spare1; /* Spare pointer 1 */ @@ -112,7 +126,6 @@ int r_rid; /* optional rid for this resource. */ }; #else -struct resource; struct device; #endif Index: sys/types.h =================================================================== RCS file: /home/ncvs/src/sys/sys/types.h,v retrieving revision 1.92 diff -u -r1.92 types.h --- sys/types.h 31 May 2005 15:18:17 -0000 1.92 +++ sys/types.h 23 Sep 2005 18:43:39 -0000 @@ -285,6 +285,8 @@ typedef __uintfptr_t uintfptr_t; typedef __uint64_t uoff_t; typedef struct vm_page *vm_page_t; +typedef struct device *device_t; + #define offsetof(type, field) __offsetof(type, field) -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.