Message ID | c79e28d0a2c9672629f9839a1377501770c59d9e.1453237258.git.alistair.francis@xilinx.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Le 19/01/2016 23:35, Alistair Francis a écrit : > From: Peter Crosthwaite <peter.crosthwaite@xilinx.com> > > Add a helper that will scan a static RegisterAccessInfo Array > and populate a container MemoryRegion with registers as defined. > > Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> > Signed-off-by: Alistair Francis <alistair.francis@xilinx.com> > --- > V2: > - Use memory_region_add_subregion_no_print() > > hw/core/register.c | 29 +++++++++++++++++++++++++++++ > include/hw/register.h | 21 +++++++++++++++++++++ > 2 files changed, 50 insertions(+) > > diff --git a/hw/core/register.c b/hw/core/register.c > index 000b87f..116fd0b 100644 > --- a/hw/core/register.c > +++ b/hw/core/register.c > @@ -255,6 +255,35 @@ uint64_t register_read_memory_le(void *opaque, hwaddr addr, unsigned size) > return register_read_memory(opaque, addr, size, false); > } > > +void register_init_block32(DeviceState *owner, const RegisterAccessInfo *rae, > + int num, RegisterInfo *ri, uint32_t *data, > + MemoryRegion *container, const MemoryRegionOps *ops, > + bool debug_enabled) > +{ > + const char *debug_prefix = object_get_typename(OBJECT(owner)); > + int i; > + > + for (i = 0; i < num; i++) { > + int index = rae[i].decode.addr / 4; > + RegisterInfo *r = &ri[index]; > + > + *r = (RegisterInfo) { > + .data = &data[index], > + .data_size = sizeof(uint32_t), > + .access = &rae[i], > + .debug = debug_enabled, > + .prefix = debug_prefix, > + .opaque = owner, > + }; > + register_init(r); > + > + memory_region_init_io(&r->mem, OBJECT(owner), ops, r, r->access->name, > + sizeof(uint32_t)); > + memory_region_add_subregion_no_print(container, > + r->access->decode.addr, &r->mem); > + } > +} > + > static const TypeInfo register_info = { > .name = TYPE_REGISTER, > .parent = TYPE_DEVICE, > diff --git a/include/hw/register.h b/include/hw/register.h > index 6677dee..f3e4c2c 100644 > --- a/include/hw/register.h > +++ b/include/hw/register.h > @@ -186,6 +186,27 @@ void register_write_memory_le(void *opaque, hwaddr addr, uint64_t value, > uint64_t register_read_memory_be(void *opaque, hwaddr addr, unsigned size); > uint64_t register_read_memory_le(void *opaque, hwaddr addr, unsigned size); > > +/** > + * Init a block of consecutive registers into a container MemoryRegion. A > + * number of constant register definitions are parsed to create a corresponding > + * array of RegisterInfo's. > + * > + * @owner: device owning the registers > + * @rae: Register definitions to init > + * @num: number of registers to init (length of @rae) > + * @ri: Register array to init > + * @data: Array to use for register data > + * @container: Memory region to contain new registers > + * @ops: Memory region ops to use to access registers. Opaque data of handler > + * with be a RegisterInfo * (from @ri) typo here Fred > + * @debug enabled: turn on/off verbose debug information > + */ > + > +void register_init_block32(DeviceState *owner, const RegisterAccessInfo *rae, > + int num, RegisterInfo *ri, uint32_t *data, > + MemoryRegion *container, const MemoryRegionOps *ops, > + bool debug_enabled); > + > /* Define constants for a 32 bit register */ > #define REG32(reg, addr) \ > enum { A_ ## reg = (addr) }; \
diff --git a/hw/core/register.c b/hw/core/register.c index 000b87f..116fd0b 100644 --- a/hw/core/register.c +++ b/hw/core/register.c @@ -255,6 +255,35 @@ uint64_t register_read_memory_le(void *opaque, hwaddr addr, unsigned size) return register_read_memory(opaque, addr, size, false); } +void register_init_block32(DeviceState *owner, const RegisterAccessInfo *rae, + int num, RegisterInfo *ri, uint32_t *data, + MemoryRegion *container, const MemoryRegionOps *ops, + bool debug_enabled) +{ + const char *debug_prefix = object_get_typename(OBJECT(owner)); + int i; + + for (i = 0; i < num; i++) { + int index = rae[i].decode.addr / 4; + RegisterInfo *r = &ri[index]; + + *r = (RegisterInfo) { + .data = &data[index], + .data_size = sizeof(uint32_t), + .access = &rae[i], + .debug = debug_enabled, + .prefix = debug_prefix, + .opaque = owner, + }; + register_init(r); + + memory_region_init_io(&r->mem, OBJECT(owner), ops, r, r->access->name, + sizeof(uint32_t)); + memory_region_add_subregion_no_print(container, + r->access->decode.addr, &r->mem); + } +} + static const TypeInfo register_info = { .name = TYPE_REGISTER, .parent = TYPE_DEVICE, diff --git a/include/hw/register.h b/include/hw/register.h index 6677dee..f3e4c2c 100644 --- a/include/hw/register.h +++ b/include/hw/register.h @@ -186,6 +186,27 @@ void register_write_memory_le(void *opaque, hwaddr addr, uint64_t value, uint64_t register_read_memory_be(void *opaque, hwaddr addr, unsigned size); uint64_t register_read_memory_le(void *opaque, hwaddr addr, unsigned size); +/** + * Init a block of consecutive registers into a container MemoryRegion. A + * number of constant register definitions are parsed to create a corresponding + * array of RegisterInfo's. + * + * @owner: device owning the registers + * @rae: Register definitions to init + * @num: number of registers to init (length of @rae) + * @ri: Register array to init + * @data: Array to use for register data + * @container: Memory region to contain new registers + * @ops: Memory region ops to use to access registers. Opaque data of handler + * with be a RegisterInfo * (from @ri) + * @debug enabled: turn on/off verbose debug information + */ + +void register_init_block32(DeviceState *owner, const RegisterAccessInfo *rae, + int num, RegisterInfo *ri, uint32_t *data, + MemoryRegion *container, const MemoryRegionOps *ops, + bool debug_enabled); + /* Define constants for a 32 bit register */ #define REG32(reg, addr) \ enum { A_ ## reg = (addr) }; \