diff options
author | Peter Crosthwaite | 2016-07-04 14:06:36 +0200 |
---|---|---|
committer | Peter Maydell | 2016-07-04 14:15:22 +0200 |
commit | a74229597e2c226a1a1f46a8926a0d2ec9c7574e (patch) | |
tree | 5ff4a221d441cb22f5c2bd59c656dfe6687fd02b /hw | |
parent | register: QOMify (diff) | |
download | qemu-a74229597e2c226a1a1f46a8926a0d2ec9c7574e.tar.gz qemu-a74229597e2c226a1a1f46a8926a0d2ec9c7574e.tar.xz qemu-a74229597e2c226a1a1f46a8926a0d2ec9c7574e.zip |
register: Add block initialise helper
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>
Message-id: 347b810b2799e413c98d5bbeca97bcb1557946c3.1467053537.git.alistair.francis@xilinx.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/core/register.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/hw/core/register.c b/hw/core/register.c index c7d71037e3..4bfbc508de 100644 --- a/hw/core/register.c +++ b/hw/core/register.c @@ -229,6 +229,51 @@ uint64_t register_read_memory(void *opaque, hwaddr addr, return extract64(read_val, 0, size * 8); } +RegisterInfoArray *register_init_block32(DeviceState *owner, + const RegisterAccessInfo *rae, + int num, RegisterInfo *ri, + uint32_t *data, + const MemoryRegionOps *ops, + bool debug_enabled, + uint64_t memory_size) +{ + const char *device_prefix = object_get_typename(OBJECT(owner)); + RegisterInfoArray *r_array = g_new0(RegisterInfoArray, 1); + int i; + + r_array->r = g_new0(RegisterInfo *, num); + r_array->num_elements = num; + r_array->debug = debug_enabled; + r_array->prefix = device_prefix; + + for (i = 0; i < num; i++) { + int index = rae[i].addr / 4; + RegisterInfo *r = &ri[index]; + + *r = (RegisterInfo) { + .data = &data[index], + .data_size = sizeof(uint32_t), + .access = &rae[i], + .opaque = owner, + }; + register_init(r); + + r_array->r[i] = r; + } + + memory_region_init_io(&r_array->mem, OBJECT(owner), ops, r_array, + device_prefix, memory_size); + + return r_array; +} + +void register_finalize_block(RegisterInfoArray *r_array) +{ + object_unparent(OBJECT(&r_array->mem)); + g_free(r_array->r); + g_free(r_array); +} + static const TypeInfo register_info = { .name = TYPE_REGISTER, .parent = TYPE_DEVICE, |