From: Alistair Francis <alistair.francis@xilinx.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: alistair.francis@xilinx.com, crosthwaitepeter@gmail.com,
edgar.iglesias@xilinx.com, edgar.iglesias@gmail.com,
afaerber@suse.de, fred.konrad@greensocs.com,
alex.bennee@linaro.org
Subject: [Qemu-devel] [PATCH v7 06/12] register: Add block initialise helper
Date: Wed, 22 Jun 2016 13:23:59 -0700 [thread overview]
Message-ID: <6ae9a75f0189ac76f8fc0b74ec85eb45b443d9af.1466626975.git.alistair.francis@xilinx.com> (raw)
In-Reply-To: <cover.1466626975.git.alistair.francis@xilinx.com>
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>
---
The reason that I'm not using GArray is because the array needs to store
the memory region that covers all of the registers.
V7:
- Return the memory region instead of adding it as a subregion
V6:
- Fixup the loop logic
V5:
- Convert to only using one memory region
V3:
- Fix typo
V2:
- Use memory_region_add_subregion_no_print()
hw/core/register.c | 36 ++++++++++++++++++++++++++++++++++++
include/hw/register.h | 24 ++++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/hw/core/register.c b/hw/core/register.c
index 41c11c8..f32faac 100644
--- a/hw/core/register.c
+++ b/hw/core/register.c
@@ -224,6 +224,42 @@ uint64_t register_read_memory(void *opaque, hwaddr addr,
return extract64(read_val, 0, size * 8);
}
+MemoryRegion *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_malloc(sizeof(RegisterInfoArray));
+ int i;
+
+ r_array->r = g_malloc_n(num, sizeof(RegisterInfo *));
+ 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->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 18a63df..104d381 100644
--- a/include/hw/register.h
+++ b/include/hw/register.h
@@ -100,6 +100,8 @@ struct RegisterInfo {
*/
struct RegisterInfoArray {
+ MemoryRegion mem;
+
int num_elements;
RegisterInfo **r;
@@ -166,6 +168,28 @@ void register_write_memory(void *opaque, hwaddr addr, uint64_t value,
uint64_t register_read_memory(void *opaque, hwaddr addr, unsigned size);
+/**
+ * Init a block of 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
+ * @ops: Memory region ops to access registers.
+ * @debug enabled: turn on/off verbose debug information
+ * returns: A pointer to an initalised memory region that the caller should
+ * add to a container.
+ */
+
+MemoryRegion *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);
+
/* Define constants for a 32 bit register */
/* This macro will define A_FOO, for the byte address of a register
--
2.7.4
next prev parent reply other threads:[~2016-06-22 20:24 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-22 20:23 [Qemu-devel] [PATCH v7 00/12] data-driven device registers Alistair Francis
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 01/12] bitops: Add MAKE_64BIT_MASK macro Alistair Francis
2016-06-23 12:14 ` Peter Maydell
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 02/12] register: Add Register API Alistair Francis
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 03/12] register: Add Memory API glue Alistair Francis
2016-06-23 12:21 ` Peter Maydell
2016-06-23 16:30 ` Alistair Francis
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 04/12] register: Define REG and FIELD macros Alistair Francis
2016-06-23 12:39 ` Peter Maydell
2016-06-23 17:51 ` Alistair Francis
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 05/12] register: QOMify Alistair Francis
2016-06-23 12:40 ` Peter Maydell
2016-06-22 20:23 ` Alistair Francis [this message]
2016-06-23 12:55 ` [Qemu-devel] [PATCH v7 06/12] register: Add block initialise helper Peter Maydell
2016-06-23 17:29 ` Alistair Francis
2016-06-23 18:02 ` Peter Maydell
2016-06-23 18:10 ` Alistair Francis
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 07/12] dma: Add Xilinx Zynq devcfg device model Alistair Francis
2016-06-23 13:08 ` Peter Maydell
2016-06-23 18:08 ` Alistair Francis
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 08/12] xilinx_zynq: Connect devcfg to the Zynq machine model Alistair Francis
2016-06-23 13:09 ` Peter Maydell
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 09/12] irq: Add opaque setter routine Alistair Francis
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 10/12] register: Add GPIO API Alistair Francis
2016-06-23 13:19 ` Peter Maydell
2016-06-23 18:14 ` Alistair Francis
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 11/12] misc: Introduce ZynqMP IOU SLCR Alistair Francis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6ae9a75f0189ac76f8fc0b74ec85eb45b443d9af.1466626975.git.alistair.francis@xilinx.com \
--to=alistair.francis@xilinx.com \
--cc=afaerber@suse.de \
--cc=alex.bennee@linaro.org \
--cc=crosthwaitepeter@gmail.com \
--cc=edgar.iglesias@gmail.com \
--cc=edgar.iglesias@xilinx.com \
--cc=fred.konrad@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).