Index: sys/dev/bhnd/bcma/bcma.c =================================================================== --- sys/dev/bhnd/bcma/bcma.c +++ sys/dev/bhnd/bcma/bcma.c @@ -194,6 +194,14 @@ return (&dinfo->resources); } +static device_t +bcma_find_hostb_device(device_t dev) +{ + struct bcma_softc *sc = device_get_softc(dev); + + /* This is set (or not) by the concrete bcma driver subclass. */ + return (sc->hostb_dev); +} static int bcma_reset_core(device_t dev, device_t child, uint16_t flags) @@ -471,6 +479,7 @@ DEVMETHOD(bus_get_resource_list, bcma_get_resource_list), /* BHND interface */ + DEVMETHOD(bhnd_bus_find_hostb_device, bcma_find_hostb_device), DEVMETHOD(bhnd_bus_reset_core, bcma_reset_core), DEVMETHOD(bhnd_bus_suspend_core, bcma_suspend_core), DEVMETHOD(bhnd_bus_get_port_count, bcma_get_port_count), Index: sys/dev/bhnd/bcma/bcma_bhndb.c =================================================================== --- sys/dev/bhnd/bcma/bcma_bhndb.c +++ sys/dev/bhnd/bcma/bcma_bhndb.c @@ -65,14 +65,16 @@ static int bcma_bhndb_attach(device_t dev) { + struct bcma_softc *sc; const struct bhnd_chipid *cid; struct resource *erom_res; int error; int rid; - cid = BHNDB_GET_CHIPID(device_get_parent(dev), dev); + sc = device_get_softc(dev); /* Map the EROM resource and enumerate our children. */ + cid = BHNDB_GET_CHIPID(device_get_parent(dev), dev); rid = 0; erom_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, cid->enum_addr, cid->enum_addr + BCMA_EROM_TABLE_SIZE, BCMA_EROM_TABLE_SIZE, @@ -95,6 +97,9 @@ if (error) return (error); + /* Ask our parent bridge to find the corresponding bridge core */ + sc->hostb_dev = BHNDB_FIND_HOSTB_DEVICE(device_get_parent(dev), dev); + /* Call our superclass' implementation */ return (bcma_attach(dev)); } Index: sys/dev/bhnd/bcma/bcmavar.h =================================================================== --- sys/dev/bhnd/bcma/bcmavar.h +++ sys/dev/bhnd/bcma/bcmavar.h @@ -144,6 +144,7 @@ /** BMCA per-instance state */ struct bcma_softc { struct bhnd_softc bhnd_sc; /**< bhnd state */ + device_t hostb_dev; /**< host bridge core, or NULL */ }; #endif /* _BCMA_BCMAVAR_H_ */ \ No newline at end of file Index: sys/dev/bhnd/bhnd.h =================================================================== --- sys/dev/bhnd/bhnd.h +++ sys/dev/bhnd/bhnd.h @@ -335,8 +335,6 @@ void bhnd_set_default_core_desc(device_t dev); -bool bhnd_bus_generic_is_hostb_device(device_t dev, - device_t child); bool bhnd_bus_generic_is_hw_disabled(device_t dev, device_t child); bool bhnd_bus_generic_is_region_valid(device_t dev, @@ -364,14 +362,14 @@ /** - * Return true if @p dev is serving as a host bridge for its parent bhnd - * bus. + * Return the active host bridge core for the bhnd bus, if any, or NULL if + * not found. * - * @param dev A bhnd bus child device. + * @param dev A bhnd bus device. */ -static inline bool -bhnd_is_hostb_device(device_t dev) { - return (BHND_BUS_IS_HOSTB_DEVICE(device_get_parent(dev), dev)); +static inline device_t +bhnd_find_hostb_device(device_t dev) { + return (BHND_BUS_FIND_HOSTB_DEVICE(dev)); } /** @@ -610,37 +608,152 @@ #define bhnd_bus_barrier(r, o, l, f) \ ((r)->direct) ? \ bus_barrier((r)->res, (o), (l), (f)) : \ - BHND_BUS_BARRIER(device_get_parent(rman_get_device((r)->res)), \ + BHND_BUS_BARRIER( \ + device_get_parent(rman_get_device((r)->res)), \ rman_get_device((r)->res), (r), (o), (l), (f)) #define bhnd_bus_read_1(r, o) \ ((r)->direct) ? \ bus_read_1((r)->res, (o)) : \ - BHND_BUS_READ_1(device_get_parent(rman_get_device((r)->res)), \ + BHND_BUS_READ_1( \ + device_get_parent(rman_get_device((r)->res)), \ rman_get_device((r)->res), (r), (o)) +#define bhnd_bus_read_multi_1(r, o, d, c) \ + ((r)->direct) ? \ + bus_read_multi_1((r)->res, (o), (d), (c)) : \ + BHND_BUS_READ_MULTI_1( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) #define bhnd_bus_write_1(r, o, v) \ ((r)->direct) ? \ bus_write_1((r)->res, (o), (v)) : \ - BHND_BUS_WRITE_1(device_get_parent(rman_get_device((r)->res)), \ + BHND_BUS_WRITE_1( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (v)) +#define bhnd_bus_write_multi_1(r, o, d, c) \ + ((r)->direct) ? \ + bus_write_multi_1((r)->res, (o), (d), (c)) : \ + BHND_BUS_WRITE_MULTI_1( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) +#define bhnd_bus_read_stream_1(r, o) \ + ((r)->direct) ? \ + bus_read_stream_1((r)->res, (o)) : \ + BHND_BUS_READ_STREAM_1( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o)) +#define bhnd_bus_read_multi_stream_1(r, o, d, c) \ + ((r)->direct) ? \ + bus_read_multi_stream_1((r)->res, (o), (d), (c)) : \ + BHND_BUS_READ_MULTI_STREAM_1( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) +#define bhnd_bus_write_stream_1(r, o, v) \ + ((r)->direct) ? \ + bus_write_stream_1((r)->res, (o), (v)) : \ + BHND_BUS_WRITE_STREAM_1( \ + device_get_parent(rman_get_device((r)->res)), \ rman_get_device((r)->res), (r), (o), (v)) +#define bhnd_bus_write_multi_stream_1(r, o, d, c) \ + ((r)->direct) ? \ + bus_write_multi_stream_1((r)->res, (o), (d), (c)) : \ + BHND_BUS_WRITE_MULTI_STREAM_1( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) #define bhnd_bus_read_2(r, o) \ ((r)->direct) ? \ bus_read_2((r)->res, (o)) : \ - BHND_BUS_READ_2(device_get_parent(rman_get_device((r)->res)), \ + BHND_BUS_READ_2( \ + device_get_parent(rman_get_device((r)->res)), \ rman_get_device((r)->res), (r), (o)) +#define bhnd_bus_read_multi_2(r, o, d, c) \ + ((r)->direct) ? \ + bus_read_multi_2((r)->res, (o), (d), (c)) : \ + BHND_BUS_READ_MULTI_2( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) #define bhnd_bus_write_2(r, o, v) \ ((r)->direct) ? \ bus_write_2((r)->res, (o), (v)) : \ - BHND_BUS_WRITE_2(device_get_parent(rman_get_device((r)->res)), \ + BHND_BUS_WRITE_2( \ + device_get_parent(rman_get_device((r)->res)), \ rman_get_device((r)->res), (r), (o), (v)) +#define bhnd_bus_write_multi_2(r, o, d, c) \ + ((r)->direct) ? \ + bus_write_multi_2((r)->res, (o), (d), (c)) : \ + BHND_BUS_WRITE_MULTI_2( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) +#define bhnd_bus_read_stream_2(r, o) \ + ((r)->direct) ? \ + bus_read_stream_2((r)->res, (o)) : \ + BHND_BUS_READ_STREAM_2( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o)) +#define bhnd_bus_read_multi_stream_2(r, o, d, c) \ + ((r)->direct) ? \ + bus_read_multi_stream_2((r)->res, (o), (d), (c)) : \ + BHND_BUS_READ_MULTI_STREAM_2( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) +#define bhnd_bus_write_stream_2(r, o, v) \ + ((r)->direct) ? \ + bus_write_stream_2((r)->res, (o), (v)) : \ + BHND_BUS_WRITE_STREAM_2( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (v)) +#define bhnd_bus_write_multi_stream_2(r, o, d, c) \ + ((r)->direct) ? \ + bus_write_multi_stream_2((r)->res, (o), (d), (c)) : \ + BHND_BUS_WRITE_MULTI_STREAM_2( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) #define bhnd_bus_read_4(r, o) \ ((r)->direct) ? \ bus_read_4((r)->res, (o)) : \ - BHND_BUS_READ_4(device_get_parent(rman_get_device((r)->res)), \ + BHND_BUS_READ_4( \ + device_get_parent(rman_get_device((r)->res)), \ rman_get_device((r)->res), (r), (o)) +#define bhnd_bus_read_multi_4(r, o, d, c) \ + ((r)->direct) ? \ + bus_read_multi_4((r)->res, (o), (d), (c)) : \ + BHND_BUS_READ_MULTI_4( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) #define bhnd_bus_write_4(r, o, v) \ ((r)->direct) ? \ bus_write_4((r)->res, (o), (v)) : \ - BHND_BUS_WRITE_4(device_get_parent(rman_get_device((r)->res)), \ + BHND_BUS_WRITE_4( \ + device_get_parent(rman_get_device((r)->res)), \ rman_get_device((r)->res), (r), (o), (v)) +#define bhnd_bus_write_multi_4(r, o, d, c) \ + ((r)->direct) ? \ + bus_write_multi_4((r)->res, (o), (d), (c)) : \ + BHND_BUS_WRITE_MULTI_4( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) +#define bhnd_bus_read_stream_4(r, o) \ + ((r)->direct) ? \ + bus_read_stream_4((r)->res, (o)) : \ + BHND_BUS_READ_STREAM_4( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o)) +#define bhnd_bus_read_multi_stream_4(r, o, d, c) \ + ((r)->direct) ? \ + bus_read_multi_stream_4((r)->res, (o), (d), (c)) : \ + BHND_BUS_READ_MULTI_STREAM_4( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) +#define bhnd_bus_write_stream_4(r, o, v) \ + ((r)->direct) ? \ + bus_write_stream_4((r)->res, (o), (v)) : \ + BHND_BUS_WRITE_STREAM_4( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (v)) +#define bhnd_bus_write_multi_stream_4(r, o, d, c) \ + ((r)->direct) ? \ + bus_write_multi_stream_4((r)->res, (o), (d), (c)) : \ + BHND_BUS_WRITE_MULTI_STREAM_4( \ + device_get_parent(rman_get_device((r)->res)), \ + rman_get_device((r)->res), (r), (o), (d), (c)) #endif /* _BHND_BHND_H_ */ Index: sys/dev/bhnd/bhnd.c =================================================================== --- sys/dev/bhnd/bhnd.c +++ sys/dev/bhnd/bhnd.c @@ -347,7 +347,7 @@ case BHND_DEVCLASS_EROM: case BHND_DEVCLASS_OTHER: case BHND_DEVCLASS_INVALID: - if (bhnd_is_hostb_device(child)) + if (bhnd_find_hostb_device(dev) == child) return (BHND_PROBE_ROOT + BHND_PROBE_ORDER_EARLY); return (BHND_PROBE_DEFAULT); @@ -587,48 +587,53 @@ * non-bridged bus implementations, resources will never be marked as * indirect, and these methods should never be called. */ - -static uint8_t -bhnd_read_1(device_t dev, device_t child, struct bhnd_resource *r, - bus_size_t offset) -{ - return (BHND_BUS_READ_1(device_get_parent(dev), child, r, offset)); +#define BHND_IO_READ(_type, _name, _method) \ +static _type \ +bhnd_read_ ## _name (device_t dev, device_t child, \ + struct bhnd_resource *r, bus_size_t offset) \ +{ \ + return (BHND_BUS_READ_ ## _method( \ + device_get_parent(dev), child, r, offset)); \ } -static uint16_t -bhnd_read_2(device_t dev, device_t child, struct bhnd_resource *r, - bus_size_t offset) -{ - return (BHND_BUS_READ_2(device_get_parent(dev), child, r, offset)); +#define BHND_IO_WRITE(_type, _name, _method) \ +static void \ +bhnd_write_ ## _name (device_t dev, device_t child, \ + struct bhnd_resource *r, bus_size_t offset, _type value) \ +{ \ + return (BHND_BUS_WRITE_ ## _method( \ + device_get_parent(dev), child, r, offset, \ + value)); \ } -static uint32_t -bhnd_read_4(device_t dev, device_t child, struct bhnd_resource *r, - bus_size_t offset) -{ - return (BHND_BUS_READ_4(device_get_parent(dev), child, r, offset)); +#define BHND_IO_MULTI(_type, _rw, _name, _method) \ +static void \ +bhnd_ ## _rw ## _multi_ ## _name (device_t dev, device_t child, \ + struct bhnd_resource *r, bus_size_t offset, _type *datap, \ + bus_size_t count) \ +{ \ + BHND_BUS_ ## _method(device_get_parent(dev), child, r, \ + offset, datap, count); \ } -static void -bhnd_write_1(device_t dev, device_t child, struct bhnd_resource *r, - bus_size_t offset, uint8_t value) -{ - BHND_BUS_WRITE_1(device_get_parent(dev), child, r, offset, value); -} - -static void -bhnd_write_2(device_t dev, device_t child, struct bhnd_resource *r, - bus_size_t offset, uint16_t value) -{ - BHND_BUS_WRITE_2(device_get_parent(dev), child, r, offset, value); -} - -static void -bhnd_write_4(device_t dev, device_t child, struct bhnd_resource *r, - bus_size_t offset, uint32_t value) -{ - BHND_BUS_WRITE_4(device_get_parent(dev), child, r, offset, value); -} +#define BHND_IO_METHODS(_type, _size) \ + BHND_IO_READ(_type, _size, _size) \ + BHND_IO_WRITE(_type, _size, _size) \ + \ + BHND_IO_READ(_type, stream_ ## _size, STREAM_ ## _size) \ + BHND_IO_WRITE(_type, stream_ ## _size, STREAM_ ## _size) \ + \ + BHND_IO_MULTI(_type, read, _size, READ_MULTI_ ## _size) \ + BHND_IO_MULTI(_type, write, _size, WRITE_MULTI_ ## _size) \ + \ + BHND_IO_MULTI(_type, read, stream_ ## _size, \ + READ_MULTI_STREAM_ ## _size) \ + BHND_IO_MULTI(_type, write, stream_ ## _size, \ + WRITE_MULTI_STREAM_ ## _size) \ + +BHND_IO_METHODS(uint8_t, 1); +BHND_IO_METHODS(uint16_t, 2); +BHND_IO_METHODS(uint32_t, 4); static void bhnd_barrier(device_t dev, device_t child, struct bhnd_resource *r, @@ -676,7 +681,6 @@ DEVMETHOD(bhnd_bus_get_chipid, bhnd_bus_generic_get_chipid), DEVMETHOD(bhnd_bus_get_probe_order, bhnd_generic_get_probe_order), DEVMETHOD(bhnd_bus_is_region_valid, bhnd_generic_is_region_valid), - DEVMETHOD(bhnd_bus_is_hostb_device, bhnd_bus_generic_is_hostb_device), DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_bus_generic_is_hw_disabled), DEVMETHOD(bhnd_bus_read_nvram_var, bhnd_generic_read_nvram_var), DEVMETHOD(bhnd_bus_read_1, bhnd_read_1), @@ -685,6 +689,27 @@ DEVMETHOD(bhnd_bus_write_1, bhnd_write_1), DEVMETHOD(bhnd_bus_write_2, bhnd_write_2), DEVMETHOD(bhnd_bus_write_4, bhnd_write_4), + DEVMETHOD(bhnd_bus_read_stream_1, bhnd_read_stream_1), + DEVMETHOD(bhnd_bus_read_stream_2, bhnd_read_stream_2), + DEVMETHOD(bhnd_bus_read_stream_4, bhnd_read_stream_4), + DEVMETHOD(bhnd_bus_write_stream_1, bhnd_write_stream_1), + DEVMETHOD(bhnd_bus_write_stream_2, bhnd_write_stream_2), + DEVMETHOD(bhnd_bus_write_stream_4, bhnd_write_stream_4), + + DEVMETHOD(bhnd_bus_read_multi_1, bhnd_read_multi_1), + DEVMETHOD(bhnd_bus_read_multi_2, bhnd_read_multi_2), + DEVMETHOD(bhnd_bus_read_multi_4, bhnd_read_multi_4), + DEVMETHOD(bhnd_bus_write_multi_1, bhnd_write_multi_1), + DEVMETHOD(bhnd_bus_write_multi_2, bhnd_write_multi_2), + DEVMETHOD(bhnd_bus_write_multi_4, bhnd_write_multi_4), + + DEVMETHOD(bhnd_bus_read_multi_stream_1, bhnd_read_multi_stream_1), + DEVMETHOD(bhnd_bus_read_multi_stream_2, bhnd_read_multi_stream_2), + DEVMETHOD(bhnd_bus_read_multi_stream_4, bhnd_read_multi_stream_4), + DEVMETHOD(bhnd_bus_write_multi_stream_1,bhnd_write_multi_stream_1), + DEVMETHOD(bhnd_bus_write_multi_stream_2,bhnd_write_multi_stream_2), + DEVMETHOD(bhnd_bus_write_multi_stream_4,bhnd_write_multi_stream_4), + DEVMETHOD(bhnd_bus_barrier, bhnd_barrier), DEVMETHOD_END Index: sys/dev/bhnd/bhnd_bus_if.m =================================================================== --- sys/dev/bhnd/bhnd_bus_if.m +++ sys/dev/bhnd/bhnd_bus_if.m @@ -55,10 +55,10 @@ panic("bhnd_bus_get_chipid unimplemented"); } - static bool - bhnd_bus_null_is_hostb_device(device_t dev, device_t child) + static device_t + bhnd_bus_null_find_hostb_device(device_t dev) { - panic("bhnd_bus_is_hostb_device unimplemented"); + panic("bhnd_bus_find_hostb_device unimplemented"); } static bool @@ -105,19 +105,16 @@ } /** - * Returns true if @p child is serving as a host bridge for the bhnd - * bus. + * Return the active host bridge core for the bhnd bus, if any. * - * The default implementation will walk the parent device tree until - * the root node is hit, returning false. + * @param dev The bhnd bus device. * - * @param dev The device whose child is being examined. - * @param child The child device. + * @retval device_t if a hostb device exists + * @retval NULL if no hostb device is found. */ -METHOD bool is_hostb_device { +METHOD device_t find_hostb_device { device_t dev; - device_t child; -} DEFAULT bhnd_bus_null_is_hostb_device; +} DEFAULT bhnd_bus_null_find_hostb_device; /** * Return true if the hardware components required by @p child are unpopulated @@ -466,6 +463,183 @@ uint32_t value; } +/** An implementation of bus_read_stream_1() compatible with bhnd_resource */ +METHOD uint8_t read_stream_1 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; +} + +/** An implementation of bus_read_stream_2() compatible with bhnd_resource */ +METHOD uint16_t read_stream_2 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; +} + +/** An implementation of bus_read_stream_4() compatible with bhnd_resource */ +METHOD uint32_t read_stream_4 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; +} + +/** An implementation of bus_write_stream_1() compatible with bhnd_resource */ +METHOD void write_stream_1 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint8_t value; +} + +/** An implementation of bus_write_stream_2() compatible with bhnd_resource */ +METHOD void write_stream_2 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint16_t value; +} + +/** An implementation of bus_write_stream_4() compatible with bhnd_resource */ +METHOD void write_stream_4 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint32_t value; +} + +/** An implementation of bus_read_multi_1() compatible with bhnd_resource */ +METHOD void read_multi_1 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint8_t *datap; + bus_size_t count; +} + +/** An implementation of bus_read_multi_2() compatible with bhnd_resource */ +METHOD void read_multi_2 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint16_t *datap; + bus_size_t count; +} + +/** An implementation of bus_read_multi_4() compatible with bhnd_resource */ +METHOD void read_multi_4 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint32_t *datap; + bus_size_t count; +} + +/** An implementation of bus_write_multi_1() compatible with bhnd_resource */ +METHOD void write_multi_1 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint8_t *datap; + bus_size_t count; +} + +/** An implementation of bus_write_multi_2() compatible with bhnd_resource */ +METHOD void write_multi_2 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint16_t *datap; + bus_size_t count; +} + +/** An implementation of bus_write_multi_4() compatible with bhnd_resource */ +METHOD void write_multi_4 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint32_t *datap; + bus_size_t count; +} + +/** An implementation of bus_read_multi_stream_1() compatible + * bhnd_resource */ +METHOD void read_multi_stream_1 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint8_t *datap; + bus_size_t count; +} + +/** An implementation of bus_read_multi_stream_2() compatible + * bhnd_resource */ +METHOD void read_multi_stream_2 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint16_t *datap; + bus_size_t count; +} + +/** An implementation of bus_read_multi_stream_4() compatible + * bhnd_resource */ +METHOD void read_multi_stream_4 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint32_t *datap; + bus_size_t count; +} + +/** An implementation of bus_write_multi_stream_1() compatible + * bhnd_resource */ +METHOD void write_multi_stream_1 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint8_t *datap; + bus_size_t count; +} + +/** An implementation of bus_write_multi_stream_2() compatible with + * bhnd_resource */ +METHOD void write_multi_stream_2 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint16_t *datap; + bus_size_t count; +} + +/** An implementation of bus_write_multi_stream_4() compatible with + * bhnd_resource */ +METHOD void write_multi_stream_4 { + device_t dev; + device_t child; + struct bhnd_resource *r; + bus_size_t offset; + uint32_t *datap; + bus_size_t count; +} + /** An implementation of bus_barrier() compatible with bhnd_resource */ METHOD void barrier { device_t dev; Index: sys/dev/bhnd/bhnd_subr.c =================================================================== --- sys/dev/bhnd/bhnd_subr.c +++ sys/dev/bhnd/bhnd_subr.c @@ -486,7 +486,11 @@ bhnd_device_lookup(device_t dev, const struct bhnd_device *table, size_t entry_size) { - const struct bhnd_device *entry; + const struct bhnd_device *entry; + device_t hostb, parent; + + parent = device_get_parent(dev); + hostb = bhnd_find_hostb_device(parent); for (entry = table; entry->desc != NULL; entry = (const struct bhnd_device *) ((const char *) entry + entry_size)) @@ -496,8 +500,8 @@ continue; /* match device flags */ - if (entry->device_flags & BHND_DF_HOSTB) { - if (!bhnd_is_hostb_device(dev)) + if (entry->device_flags & BHND_DF_HOSTB) { + if (dev != hostb) continue; } @@ -738,24 +742,6 @@ } /** - * Helper function for implementing BHND_BUS_IS_HOSTB_DEVICE(). - * - * If a parent device is available, this implementation delegates the - * request to the BHND_BUS_IS_HOSTB_DEVICE() method on the parent of @p dev. - * - * If no parent device is available (i.e. on a the bus root), false - * is returned. - */ -bool -bhnd_bus_generic_is_hostb_device(device_t dev, device_t child) { - if (device_get_parent(dev) != NULL) - return (BHND_BUS_IS_HOSTB_DEVICE(device_get_parent(dev), - child)); - - return (false); -} - -/** * Helper function for implementing BHND_BUS_IS_HW_DISABLED(). * * If a parent device is available, this implementation delegates the Index: sys/dev/bhnd/bhndb/bhndb.c =================================================================== --- sys/dev/bhnd/bhndb/bhndb.c +++ sys/dev/bhnd/bhndb/bhndb.c @@ -589,18 +589,12 @@ sc = device_get_softc(dev); hostb = NULL; - /* Fetch the full set of attached devices */ + /* Fetch the full set of bhnd-attached cores */ if ((error = device_get_children(sc->bus_dev, &devs, &ndevs))) return (error); /* Find our host bridge device */ - for (int i = 0; i < ndevs; i++) { - if (bhnd_is_hostb_device(devs[i])) { - hostb = devs[i]; - break; - } - } - + hostb = BHNDB_FIND_HOSTB_DEVICE(dev, child); if (hostb == NULL) { device_printf(sc->dev, "no host bridge core found\n"); error = ENODEV; @@ -950,13 +944,13 @@ /* Otherwise, we treat bridge-capable cores as unpopulated if they're * not the configured host bridge */ if (BHND_DEVCLASS_SUPPORTS_HOSTB(bhnd_core_class(&core))) - return (!BHND_BUS_IS_HOSTB_DEVICE(dev, child)); + return (BHNDB_FIND_HOSTB_DEVICE(dev, sc->bus_dev) != child); /* Otherwise, assume the core is populated */ return (false); } -/* ascending core index comparison used by bhndb_is_hostb_device() */ +/* ascending core index comparison used by bhndb_find_hostb_device() */ static int compare_core_index(const void *lhs, const void *rhs) { @@ -972,7 +966,7 @@ } /** - * Default bhndb(4) implementation of BHND_BUS_IS_HOSTB_DEVICE(). + * Default bhndb(4) implementation of BHND_BUS_FIND_HOSTB_DEVICE(). * * This function uses a heuristic valid on all known PCI/PCIe/PCMCIA-bridged * bhnd(4) devices to determine the hostb core: @@ -982,27 +976,19 @@ * - The core must be the first device on the bus with the bridged device * class. * - * @param sc The bridge device state. - * @param cores The table of bridge-enumerated cores. - * @param num_cores The length of @p cores. - * @param core The core to check. + * @param dev The bhndb device + * @param child The requesting bhnd bus. */ -static bool -bhndb_is_hostb_device(device_t dev, device_t child) +static device_t +bhndb_find_hostb_device(device_t dev, device_t child) { struct bhndb_softc *sc; struct bhnd_core_match md; device_t hostb_dev, *devlist; int devcnt, error; - sc = device_get_softc(dev); - /* Requestor must be attached to the bhnd bus */ - if (device_get_parent(child) != sc->bus_dev) - return (BHND_BUS_IS_HOSTB_DEVICE(device_get_parent(dev), - child)); - /* Determine required device class and set up a match descriptor. */ md = (struct bhnd_core_match) { .vendor = BHND_MFGID_BCM, @@ -1011,19 +997,15 @@ .class = sc->bridge_class, .unit = 0 }; - - /* Pre-screen the device before searching over the full device list. */ - if (!bhnd_device_matches(child, &md)) - return (false); /* Must be the absolute first matching device on the bus. */ - if ((error = device_get_children(sc->bus_dev, &devlist, &devcnt))) + if ((error = device_get_children(child, &devlist, &devcnt))) return (false); /* Sort by core index value, ascending */ qsort(devlist, devcnt, sizeof(*devlist), compare_core_index); - /* Find the actual hostb device */ + /* Find the hostb device */ hostb_dev = NULL; for (int i = 0; i < devcnt; i++) { if (bhnd_device_matches(devlist[i], &md)) { @@ -1035,7 +1017,7 @@ /* Clean up */ free(devlist, M_TEMP); - return (child == hostb_dev); + return (hostb_dev); } /** @@ -1755,37 +1737,60 @@ BHNDB_UNLOCK(sc); /* Defines a bhndb_bus_read_* method implementation */ -#define BHNDB_IO_READ(_type, _size) \ +#define BHNDB_IO_READ(_type, _name) \ static _type \ -bhndb_bus_read_ ## _size (device_t dev, device_t child, \ +bhndb_bus_read_ ## _name (device_t dev, device_t child, \ struct bhnd_resource *r, bus_size_t offset) \ { \ _type v; \ BHNDB_IO_COMMON_SETUP(sizeof(_type)); \ - v = bus_read_ ## _size (io_res, io_offset); \ + v = bus_read_ ## _name (io_res, io_offset); \ BHNDB_IO_COMMON_TEARDOWN(); \ \ return (v); \ } /* Defines a bhndb_bus_write_* method implementation */ -#define BHNDB_IO_WRITE(_type, _size) \ +#define BHNDB_IO_WRITE(_type, _name) \ static void \ -bhndb_bus_write_ ## _size (device_t dev, device_t child, \ +bhndb_bus_write_ ## _name (device_t dev, device_t child, \ struct bhnd_resource *r, bus_size_t offset, _type value) \ { \ BHNDB_IO_COMMON_SETUP(sizeof(_type)); \ - bus_write_ ## _size (io_res, io_offset, value); \ + bus_write_ ## _name (io_res, io_offset, value); \ BHNDB_IO_COMMON_TEARDOWN(); \ } -BHNDB_IO_READ(uint8_t, 1); -BHNDB_IO_READ(uint16_t, 2); -BHNDB_IO_READ(uint32_t, 4); +/* Defines a bhndb_bus_(read|write)_multi_* method implementation */ +#define BHNDB_IO_MULTI(_type, _rw, _name) \ +static void \ +bhndb_bus_ ## _rw ## _multi_ ## _name (device_t dev, \ + device_t child, struct bhnd_resource *r, bus_size_t offset, \ + _type *datap, bus_size_t count) \ +{ \ + BHNDB_IO_COMMON_SETUP(sizeof(_type) * count); \ + bus_ ## _rw ## _multi_ ## _name (io_res, io_offset, \ + datap, count); \ + BHNDB_IO_COMMON_TEARDOWN(); \ +} -BHNDB_IO_WRITE(uint8_t, 1); -BHNDB_IO_WRITE(uint16_t, 2); -BHNDB_IO_WRITE(uint32_t, 4); +/* Defines a complete set of read/write methods */ +#define BHNDB_IO_METHODS(_type, _size) \ + BHNDB_IO_READ(_type, _size) \ + BHNDB_IO_WRITE(_type, _size) \ + \ + BHNDB_IO_READ(_type, stream_ ## _size) \ + BHNDB_IO_WRITE(_type, stream_ ## _size) \ + \ + BHNDB_IO_MULTI(_type, read, _size) \ + BHNDB_IO_MULTI(_type, write, _size) \ + \ + BHNDB_IO_MULTI(_type, read, stream_ ## _size) \ + BHNDB_IO_MULTI(_type, write, stream_ ## _size) + +BHNDB_IO_METHODS(uint8_t, 1); +BHNDB_IO_METHODS(uint16_t, 2); +BHNDB_IO_METHODS(uint32_t, 4); /** * Default bhndb(4) implementation of BHND_BUS_BARRIER(). @@ -1922,12 +1927,12 @@ /* BHNDB interface */ DEVMETHOD(bhndb_get_chipid, bhndb_get_chipid), DEVMETHOD(bhndb_init_full_config, bhndb_generic_init_full_config), + DEVMETHOD(bhndb_find_hostb_device, bhndb_find_hostb_device), DEVMETHOD(bhndb_suspend_resource, bhndb_suspend_resource), DEVMETHOD(bhndb_resume_resource, bhndb_resume_resource), /* BHND interface */ DEVMETHOD(bhnd_bus_is_hw_disabled, bhndb_is_hw_disabled), - DEVMETHOD(bhnd_bus_is_hostb_device, bhndb_is_hostb_device), DEVMETHOD(bhnd_bus_get_chipid, bhndb_get_chipid), DEVMETHOD(bhnd_bus_activate_resource, bhndb_activate_bhnd_resource), DEVMETHOD(bhnd_bus_deactivate_resource, bhndb_deactivate_bhnd_resource), @@ -1937,6 +1942,28 @@ DEVMETHOD(bhnd_bus_write_1, bhndb_bus_write_1), DEVMETHOD(bhnd_bus_write_2, bhndb_bus_write_2), DEVMETHOD(bhnd_bus_write_4, bhndb_bus_write_4), + + DEVMETHOD(bhnd_bus_read_stream_1, bhndb_bus_read_stream_1), + DEVMETHOD(bhnd_bus_read_stream_2, bhndb_bus_read_stream_2), + DEVMETHOD(bhnd_bus_read_stream_4, bhndb_bus_read_stream_4), + DEVMETHOD(bhnd_bus_write_stream_1, bhndb_bus_write_stream_1), + DEVMETHOD(bhnd_bus_write_stream_2, bhndb_bus_write_stream_2), + DEVMETHOD(bhnd_bus_write_stream_4, bhndb_bus_write_stream_4), + + DEVMETHOD(bhnd_bus_read_multi_1, bhndb_bus_read_multi_1), + DEVMETHOD(bhnd_bus_read_multi_2, bhndb_bus_read_multi_2), + DEVMETHOD(bhnd_bus_read_multi_4, bhndb_bus_read_multi_4), + DEVMETHOD(bhnd_bus_write_multi_1, bhndb_bus_write_multi_1), + DEVMETHOD(bhnd_bus_write_multi_2, bhndb_bus_write_multi_2), + DEVMETHOD(bhnd_bus_write_multi_4, bhndb_bus_write_multi_4), + + DEVMETHOD(bhnd_bus_read_multi_stream_1, bhndb_bus_read_multi_stream_1), + DEVMETHOD(bhnd_bus_read_multi_stream_2, bhndb_bus_read_multi_stream_2), + DEVMETHOD(bhnd_bus_read_multi_stream_4, bhndb_bus_read_multi_stream_4), + DEVMETHOD(bhnd_bus_write_multi_stream_1,bhndb_bus_write_multi_stream_1), + DEVMETHOD(bhnd_bus_write_multi_stream_2,bhndb_bus_write_multi_stream_2), + DEVMETHOD(bhnd_bus_write_multi_stream_4,bhndb_bus_write_multi_stream_4), + DEVMETHOD(bhnd_bus_barrier, bhndb_bus_barrier), DEVMETHOD_END Index: sys/dev/bhnd/bhndb/bhndb_if.m =================================================================== --- sys/dev/bhnd/bhndb/bhndb_if.m +++ sys/dev/bhnd/bhndb/bhndb_if.m @@ -62,6 +62,12 @@ panic("bhndb_init_full_config unimplemented"); } + static device_t + bhndb_null_find_hostb_device(device_t dev, device_t child) + { + panic("bhndb_find_hostb_device unimplemented"); + } + static void bhndb_null_suspend_resource(device_t dev, device_t child, int type, struct resource *r) @@ -120,6 +126,17 @@ } DEFAULT bhndb_null_init_full_config; /** + * Locate the active host bridge core for the attached bhnd bus. + * + * @param dev The bridge device. + * @param child The bhnd bus device attached to @p dev. + */ +METHOD device_t find_hostb_device { + device_t dev; + device_t child; +} DEFAULT bhndb_null_find_hostb_device; + +/** * Mark a resource as 'suspended', gauranteeing to the bridge that no * further use of the resource will be made until BHNDB_RESUME_RESOURCE() * is called. Index: sys/dev/bhnd/siba/siba.c =================================================================== --- sys/dev/bhnd/siba/siba.c +++ sys/dev/bhnd/siba/siba.c @@ -216,6 +216,15 @@ return (&dinfo->resources); } +static device_t +siba_find_hostb_device(device_t dev) +{ + struct siba_softc *sc = device_get_softc(dev); + + /* This is set (or not) by the concrete siba driver subclass. */ + return (sc->hostb_dev); +} + static int siba_reset_core(device_t dev, device_t child, uint16_t flags) { @@ -662,6 +671,7 @@ DEVMETHOD(bus_get_resource_list, siba_get_resource_list), /* BHND interface */ + DEVMETHOD(bhnd_bus_find_hostb_device, siba_find_hostb_device), DEVMETHOD(bhnd_bus_reset_core, siba_reset_core), DEVMETHOD(bhnd_bus_suspend_core, siba_suspend_core), DEVMETHOD(bhnd_bus_get_port_count, siba_get_port_count), Index: sys/dev/bhnd/siba/siba_bhndb.c =================================================================== --- sys/dev/bhnd/siba/siba_bhndb.c +++ sys/dev/bhnd/siba/siba_bhndb.c @@ -73,9 +73,12 @@ static int siba_bhndb_attach(device_t dev) { + struct siba_softc *sc; const struct bhnd_chipid *chipid; int error; + sc = device_get_softc(dev); + /* Enumerate our children. */ chipid = BHNDB_GET_CHIPID(device_get_parent(dev), dev); if ((error = siba_add_children(dev, chipid))) @@ -87,6 +90,9 @@ if (error) return (error); + /* Ask our parent bridge to find the corresponding bridge core */ + sc->hostb_dev = BHNDB_FIND_HOSTB_DEVICE(device_get_parent(dev), dev); + /* Call our superclass' implementation */ return (siba_attach(dev)); } Index: sys/dev/bhnd/siba/sibavar.h =================================================================== --- sys/dev/bhnd/siba/sibavar.h +++ sys/dev/bhnd/siba/sibavar.h @@ -145,6 +145,7 @@ /** siba(4) per-instance state */ struct siba_softc { struct bhnd_softc bhnd_sc; /**< bhnd state */ + device_t hostb_dev; /**< host bridge core, or NULL */ }; #endif /* _SIBA_SIBAVAR_H_ */ Index: sys/dev/bhnd/tools/bus_macro.sh =================================================================== --- sys/dev/bhnd/tools/bus_macro.sh +++ sys/dev/bhnd/tools/bus_macro.sh @@ -50,8 +50,8 @@ echo -n ", (${i})" done echo ") : \\" - echo -n " BHND_BUS_${bus_n}(" - echo "device_get_parent(rman_get_device((r)->res)), \\" + echo " BHND_BUS_${bus_n}( \\" + echo " device_get_parent(rman_get_device((r)->res)), \\" echo -n " rman_get_device((r)->res), (r)" for i do @@ -70,15 +70,15 @@ # macro copy_region_$w so dh do c # macro copy_region_stream_$w ? # macro peek_$w - for s in "" #stream_ + for s in "" stream_ do macro read_$s$w o -# macro read_multi_$s$w o d c + macro read_multi_$s$w o d c # macro read_region_$s$w o d c # macro set_multi_$s$w o v c # macro set_region_$s$w o v c macro write_$s$w o v -# macro write_multi_$s$w o d c + macro write_multi_$s$w o d c # macro write_region_$s$w o d c done done