diff options
author | Peter Crosthwaite <peter.crosthwaite@xilinx.com> | 2016-07-04 13:06:36 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2016-07-04 13:15:22 +0100 |
commit | 49e14ddbcef3477c9c47900ef132a92d1ca4180c (patch) | |
tree | 80e23299c55e8c449fe63e68c3d1c7684afaa337 | |
parent | 684204593d9b81ba4cd4c441b5ee395a29cff606 (diff) |
register: QOMify
QOMify registers as a child of TYPE_DEVICE. This allows registers to
define GPIOs.
Define an init helper that will do QOM initialisation.
Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Reviewed-by: KONRAD Frederic <fred.konrad@greensocs.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 2545f71db26bf5586ca0c08a3e3cf1b217450552.1467053537.git.alistair.francis@xilinx.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r-- | hw/core/register.c | 23 | ||||
-rw-r--r-- | include/hw/register.h | 14 |
2 files changed, 37 insertions, 0 deletions
diff --git a/hw/core/register.c b/hw/core/register.c index f7f63389d2..c7d71037e3 100644 --- a/hw/core/register.c +++ b/hw/core/register.c @@ -159,6 +159,17 @@ void register_reset(RegisterInfo *reg) register_write_val(reg, reg->access->reset); } +void register_init(RegisterInfo *reg) +{ + assert(reg); + + if (!reg->data || !reg->access) { + return; + } + + object_initialize((void *)reg, sizeof(*reg), TYPE_REGISTER); +} + void register_write_memory(void *opaque, hwaddr addr, uint64_t value, unsigned size) { @@ -217,3 +228,15 @@ uint64_t register_read_memory(void *opaque, hwaddr addr, return extract64(read_val, 0, size * 8); } + +static const TypeInfo register_info = { + .name = TYPE_REGISTER, + .parent = TYPE_DEVICE, +}; + +static void register_register_types(void) +{ + type_register_static(®ister_info); +} + +type_init(register_register_types) diff --git a/include/hw/register.h b/include/hw/register.h index e8c58a1dbb..61c53fbf0a 100644 --- a/include/hw/register.h +++ b/include/hw/register.h @@ -11,6 +11,7 @@ #ifndef REGISTER_H #define REGISTER_H +#include "hw/qdev-core.h" #include "exec/memory.h" typedef struct RegisterInfo RegisterInfo; @@ -72,6 +73,9 @@ struct RegisterAccessInfo { */ struct RegisterInfo { + /* <private> */ + DeviceState parent_obj; + /* <public> */ void *data; int data_size; @@ -81,6 +85,9 @@ struct RegisterInfo { void *opaque; }; +#define TYPE_REGISTER "qemu,register" +#define REGISTER(obj) OBJECT_CHECK(RegisterInfo, (obj), TYPE_REGISTER) + /** * This structure is used to group all of the individual registers which are * modeled using the RegisterInfo structure. @@ -132,6 +139,13 @@ uint64_t register_read(RegisterInfo *reg, uint64_t re, const char* prefix, void register_reset(RegisterInfo *reg); /** + * Initialize a register. + * @reg: Register to initialize + */ + +void register_init(RegisterInfo *reg); + +/** * Memory API MMIO write handler that will write to a Register API register. * @opaque: RegisterInfo to write to * @addr: Address to write |