data-driven device registers
v7 cover data-driven device registers
This patch series is based on Peter C's original register API. His original cover letter is below.
Future work: Allow support for memory attributes.
V7:
- Rebase
- Fixup the DecCFG model
- Fixes and corrections to the register API model and functions
V6:
- Small changes to the API based on Alex's comments
- Remove 'register: Add support for decoding information' patch
- Move prefix and debug into the RegisterInfoArray as it is the same for every register.
V5:
- Only create a single memory region instead of a memory region for each register
- General tidyups based on Alex's comments
V4:
- Rebase and fix build issue
- Simplify the register write logic
- Other small fixes suggested by Alex Bennee
V3:
- Small changes reported by Fred
V2:
- Rebase
- Fix up IOU SLCR connections
- Add the memory_region_add_subregion_no_print() function and use it for the registers
Changes since RFC:
- Connect the ZynqMP IOU SLCR device
- Rebase
Original cover letter From Peter:
Hi All. This is a new scheme I've come up with handling device registers in a data driven way. My motivation for this is to factor out a lot of the access checking that seems to be replicated in every device. See P1 commit message for further discussion.
P1 is the main patch, adds the register definition functionality P2-3,6 add helpers that glue the register API to the Memory API P4 Defines a set of macros that minimise register and field definitions P5 is QOMfication
P7 is a trivial
P10-13 Work up to GPIO support
P8,9,14 add new devices (the Xilinx Zynq devcfg & ZynqMP SLCR) that use this
scheme.
P15: Connect the ZynqMP SLCR device
This Zynq devcfg device was particularly finnicky with per-bit restrictions. I'm also looking for a higher-than-usual modelling fidelity
on the register space, with semantics defined for random reserved bits in-between otherwise consistent fields.
Here's an example of the qemu_log output for the devcfg device. This is produced by now generic sharable code:
/machine/unattached/device[44]:Addr 0x000008:CFG: write of value 00000508 /machine/unattached/device[44]:Addr 0x000080:MCTRL: write of value 00800010 /machine/unattached/device[44]:Addr 0x000010:INT_MASK: write of value ffffffff /machine/unattached/device[44]:Addr 00000000:CTRL: write of value 0c00607f
And an example of a rogue guest banging on a bad bit:
/machine/unattached/device[44]:Addr 0x000014:STATUS bits 0x000001 may not be \
written to 1
A future feature I am interested in is implementing TCG optimisation of side-effectless registers. The register API allows clear definition of what registers have txn side effects and which ones don't. You could even go a step further and translate such side-effectless accesses based on the data pointer for the register.
Alistair Francis (6):
bitops: Add MAKE_64BIT_MASK macro
register: Add Register API
register: Add Memory API glue
dma: Add Xilinx Zynq devcfg device model
register: Add GPIO API
xlnx-zynqmp: Connect the ZynqMP IOU SLCR
Peter Crosthwaite (6):
register: Define REG and FIELD macros
register: QOMify
register: Add block initialise helper
xilinx_zynq: Connect devcfg to the Zynq machine model
irq: Add opaque setter routine
misc: Introduce ZynqMP IOU SLCR
default-configs/arm-softmmu.mak | 1 + hw/arm/xilinx_zynq.c | 6 + hw/arm/xlnx-zynqmp.c | 14 ++ hw/core/Makefile.objs | 1 + hw/core/irq.c | 5 + hw/core/register.c | 370 ++++++++++++++++++++++++++++++ hw/dma/Makefile.objs | 1 + hw/dma/xlnx-zynq-devcfg.c | 401 +++++++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/xlnx-zynqmp-iou-slcr.c | 122 ++++++++++ include/hw/arm/xlnx-zynqmp.h | 2 + include/hw/dma/xlnx-zynq-devcfg.h | 62 +++++ include/hw/irq.h | 2 + include/hw/misc/xlnx-zynqmp-iou-slcr.h | 47 ++++ include/hw/register.h | 263 +++++++++++++++++++++ include/qemu/bitops.h | 3 + 16 files changed, 1301 insertions(+) create mode 100644 hw/core/register.c create mode 100644 hw/dma/xlnx-zynq-devcfg.c create mode 100644 hw/misc/xlnx-zynqmp-iou-slcr.c create mode 100644 include/hw/dma/xlnx-zynq-devcfg.h create mode 100644 include/hw/misc/xlnx-zynqmp-iou-slcr.h create mode 100644 include/hw/register.h
Signature · 1 line
2.7.4
PATCH v7 3/12 register: Add Memory API glue
Add memory io handlers that glue the register API to the memory API. Just translation functions at this stage. Although it does allow for devices to be created without all-in-one mmio r/w handlers.
This patch also adds the RegisterInfoArray struct, which allows all of the individual RegisterInfo structs to be grouped into a single memory region.
---
V7:
- Remove endianess handling
- Remove assert() and log missing registers
V6:
- Add the memory region later
V5:
- Convert to using only one memory region
hw/core/register.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+)
hw/core/register.c +58 -0
@@ -154,3 +154,61 @@ void register_reset(RegisterInfo *reg)register_write_val (reg, reg->access->reset); } + +void register_write_memory (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +RegisterInfoArray *reg_array = opaque; +RegisterInfo *reg =NULL ; +uint64_t we = ~0 ; +int i; + +for (i =0 ; i < reg_array->num_elements; i++) { +if (reg_array->r[i]->access->addr == addr) { + reg = reg_array->r[i]; +break ; + } + } + +if (!reg) { +qemu_log_mask (LOG_UNIMP ,"Write to unimplemented register at " \ +"address: %#" PRIx64"\n" , addr); +return ; + } + +/* Generate appropriate write enable mask */ +if (reg->data_size < size) { + we =MAKE_64BIT_MASK (0 , reg->data_size *8 ); + }else if (reg->data_size >= size) { + we =MAKE_64BIT_MASK (0 , size *8 ); + } + +register_write (reg, value, we, reg_array->prefix, + reg_array->debug); +} + +uint64_t register_read_memory (void *opaque,hwaddr addr, +unsigned size) +{ +RegisterInfoArray *reg_array = opaque; +RegisterInfo *reg =NULL ; +uint64_t read_val; +int i; + +for (i =0 ; i < reg_array->num_elements; i++) { +if (reg_array->r[i]->access->addr == addr) { + reg = reg_array->r[i]; +break ; + } + } + +if (!reg) { +qemu_log_mask (LOG_UNIMP ,"Read to unimplemented register at " \ +"address: %#" PRIx64"\n" , addr); +return 0 ; + } + + read_val =register_read (reg, reg_array->prefix, reg_array->debug); + +return extract64 (read_val,0 , size *8 ); +}
include/hw/register.h +43 -0
65 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v7 1/12 bitops: Add MAKE_64BIT_MASK macro
In reply to Alistair FrancisAdd a macro that creates a 64bit value which has length number of ones shifted across by the value of shift.
---
V7:
- Fixup commit typo
- Use the method from deposit64()
V5:
- Re-write to a 64-bit mask instead of ONES()
- Re-order this patch in the series
include/qemu/bitops.h | 3 +++ 1 file changed, 3 insertions(+)
include/qemu/bitops.h +3 -0
@@ -24,6 +24,9 @@#define BIT_WORD (nr) ((nr) / BITS_PER_LONG)#define BITS_TO_LONGS (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) +#define MAKE_64BIT_MASK (shift, length) \ + (((~0ULL) >> (64 - (length))) << (shift)) +/** * set_bit - Set a bit in memory * @nr: the bit to set
Signature · 1 line
2.7.4
PATCH v7 4/12 register: Define REG and FIELD macros
In reply to Alistair FrancisFrom: Peter Crosthwaite <[email protected]>
Define some macros that can be used for defining registers and fields.
The REG32 macro will define A_FOO, for the byte address of a register as well as R_FOO for the uint32_t[] register number (A_FOO / 4).
The FIELD macro will define FOO_BAR_MASK, FOO_BAR_SHIFT and FOO_BAR_LENGTH constants for field BAR in register FOO.
Finally, there are some shorthand helpers for extracting/depositing fields from registers based on these naming schemes.
Usage can greatly reduce the verbosity of device code.
The deposit and extract macros (eg FIELD_EX32, FIELD_DP32 etc.) can be used to generate extract and deposits without any repetition of the name stems.
[ EI Changes:
* Add Deposit macros
]
---
E.g. Currently you have to define something like:
\#define R_FOOREG (0x84/4)
\#define R_FOOREG_BARFIELD_SHIFT 10
\#define R_FOOREG_BARFIELD_LENGTH 5
uint32_t foobar_val = extract32(s->regs[R_FOOREG],
R_FOOREG_BARFIELD_SHIFT,
R_FOOREG_BARFIELD_LENGTH);Which has:
2 macro definitions per field
3 register names ("FOOREG") per extract
2 field names ("BARFIELD") per extract
With these macros this becomes:
REG32(FOOREG, 0x84)FIELD(FOOREG, BARFIELD, 10, 5)
uint32_t foobar_val = ARRAY_FIELD_EX32(s->regs, FOOREG, BARFIELD)
Which has:
1 macro definition per field
1 register name per extract
1 field name per extract
If you are not using arrays for the register data you can just use the non-array "FIELD_" variants and still save 2 name stems:
uint32_t foobar_val = FIELD_EX32(s->fooreg, FOOREG, BARFIELD)
Deposit is similar for depositing values. Deposit has compile-time overflow checking for literals.
For example:
REG32(XYZ1, 0x84)FIELD(XYZ1, TRC, 0, 4)
/* Correctly set XYZ1.TRC = 5. */ARRAY_FIELD_DP32(s->regs, XYZ1, TRC, 5);
/* Incorrectly set XYZ1.TRC = 16. */ARRAY_FIELD_DP32(s->regs, XYZ1, TRC, 16);
The latter assignment results in:
warning: large integer implicitly truncated to unsigned type [-Woverflow]
include/hw/register.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
include/hw/register.h +43 -0
@@ -150,4 +150,47 @@ void register_write_memory(void *opaque, hwaddr addr, uint64_t value,uint64_t register_read_memory (void *opaque,hwaddr addr,unsigned size); +/* Define constants for a 32 bit register */ + +/* This macro will define A_FOO, for the byte address of a register +* as well as R_FOO for the uint32_t[] register number (A_FOO / 4). +*/ +#define REG32 (reg, addr) \ + enum { A_ ## reg = (addr) }; \ + enum { R_ ## reg = (addr) / 4 }; + +/* Define SHIFT, LEGTH and MASK constants for a field within a register */ + +/* This macro will define FOO_BAR_MASK, FOO_BAR_SHIFT and FOO_BAR_LENGTH +* constants for field BAR in register FOO. +*/ +#define FIELD (reg, field, shift, length) \ + enum { R_ ## reg ## _ ## field ## _SHIFT = (shift)}; \ + enum { R_ ## reg ## _ ## field ## _LENGTH = (length)}; \ + enum { R_ ## reg ## _ ## field ## _MASK = \ + MAKE_64BIT_MASK(shift, length); + +/* Extract a field from a register */ +#define FIELD_EX32 (storage, reg, field) \ + extract32((storage), R_ ## reg ## _ ## field ## _SHIFT, \ + R_ ## reg ## _ ## field ## _LENGTH) + +/* Extract a field from an array of registers */ +#define ARRAY_FIELD_EX32 (regs, reg, field) \ + FIELD_EX32((regs)[R_ ## reg], reg, field) + +/* Deposit a register field. */ +#define FIELD_DP32 (storage, reg, field, val) ({ \ + struct { \ + unsigned int v:R_ ## reg ## _ ## field ## _LENGTH; \ + } v = { .v = val }; \ + uint32_t d; \ + d = deposit32((storage), R_ ## reg ## _ ## field ## _SHIFT, \ + R_ ## reg ## _ ## field ## _LENGTH, v.v); \ + d; }) + +/* Deposit a field to array of registers. */ +#define ARRAY_FIELD_DP32 (regs, reg, field, val) \ + (regs)[R_ ## reg] = FIELD_DP32((regs)[R_ ## reg], reg, field, val); +#endif
Signature · 1 line
2.7.4
PATCH v7 5/12 register: QOMify
In reply to Alistair FrancisFrom: Peter Crosthwaite <[email protected]>
QOMify registers as a child of TYPE_DEVICE. This allows registers to define GPIOs.
Define an init helper that will do QOM initialisation.
---
V7:
- Remove uneeded struct
- Fixup documentation
V5:
- Convert to using only one memory region
hw/core/register.c | 23 +++++++++++++++++++++++ include/hw/register.h | 16 ++++++++++++++++ 2 files changed, 39 insertions(+)
hw/core/register.c +23 -0
@@ -155,6 +155,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) {
@@ -212,3 +223,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)
include/hw/register.h +16 -0
@@ -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 strucutre.
@@ -130,6 +137,15 @@ uint64_t register_read(RegisterInfo *reg, const char* prefix, bool debug);void register_reset (RegisterInfo *reg);/** +* Initialize a register. This will also setup any GPIO links which are used +* to connect register updates in one device to other devices. Generally this +* is useful for interrupt propagation. +* @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
Signature · 1 line
2.7.4
PATCH v7 6/12 register: Add block initialise helper
In reply to Alistair FrancisFrom: Peter Crosthwaite <[email protected]>
Add a helper that will scan a static RegisterAccessInfo Array and populate a container MemoryRegion with registers as defined.
---
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(+)
hw/core/register.c +36 -0
@@ -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 ,
include/hw/register.h +24 -0
@@ -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
Signature · 1 line
2.7.4
PATCH v7 2/12 register: Add Register API
In reply to Alistair FrancisThis API provides some encapsulation of registers and factors out some common functionality to common code. Bits of device state (usually MMIO registers) often have all sorts of access restrictions and semantics associated with them. This API allows you to define what those restrictions are on a bit-by-bit basis.
Helper functions are then used to access the register which observe the semantics defined by the RegisterAccessInfo struct.
Some features:
Bits can be marked as read_only (ro field)
Bits can be marked as write-1-clear (w1c field)
Bits can be marked as reserved (rsvd field)
Reset values can be defined (reset)
Bits can be marked clear on read (cor)
Pre and post action callbacks can be added to read and write ops Verbose debugging info can be enabled/disabled
Useful for defining device register spaces in a data driven way. Cuts down on a lot of the verbosity and repetition in the switch-case blocks in the standard foo_mmio_read/write functions.
Also useful for automated generation of device models from hardware design sources.
---
V5:
- Convert to using only one memory region
V4:
- Rebase
- Remove the guest error masking
- Simplify the unimplemented masking
- Use the reserved value in the write calculations
- Remove read_lite and write_lite
- General fixes to asserts and log printing
V3:
- Address some comments from Fred
hw/core/Makefile.objs | 1 + hw/core/register.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 110 +++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 hw/core/register.c create mode 100644 include/hw/register.h
hw/core/Makefile.objs +1 -0
@@ -15,4 +15,5 @@ common-obj-$(CONFIG_SOFTMMU) += machine.o common-obj-$(CONFIG_SOFTMMU) += null-machine.o common-obj-$(CONFIG_SOFTMMU) += loader.o common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o +common-obj-$(CONFIG_SOFTMMU) += register.o common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o
hw/core/register.c new file +156 -0
156 lines not on this page · raw message
include/hw/register.h new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v7 7/12 dma: Add Xilinx Zynq devcfg device model
In reply to Alistair FrancisAdd a minimal model for the devcfg device which is part of Zynq. This model supports DMA capabilities and interrupt generation.
---
V7:
- Corrections to the internal device
V5:
- Corrections to the device model logic
default-configs/arm-softmmu.mak | 1 + hw/dma/Makefile.objs | 1 + hw/dma/xlnx-zynq-devcfg.c | 401 ++++++++++++++++++++++++++++++++++++++ include/hw/dma/xlnx-zynq-devcfg.h | 62 ++++++ include/hw/register.h | 2 +- 5 files changed, 466 insertions(+), 1 deletion(-) create mode 100644 hw/dma/xlnx-zynq-devcfg.c create mode 100644 include/hw/dma/xlnx-zynq-devcfg.h
default-configs/arm-softmmu.mak +1 -0
@@ -66,6 +66,7 @@ CONFIG_PXA2XX=y CONFIG_BITBANG_I2C=y CONFIG_FRAMEBUFFER=y CONFIG_XILINX_SPIPS=y +CONFIG_ZYNQ_DEVCFG=y CONFIG_ARM11SCU=y CONFIG_A9SCU=y
hw/dma/Makefile.objs +1 -0
@@ -5,6 +5,7 @@ common-obj-$(CONFIG_PL330) += pl330.o common-obj-$(CONFIG_I82374) += i82374.o common-obj-$(CONFIG_I8257) += i8257.o common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o +common-obj-$(CONFIG_ZYNQ_DEVCFG) += xlnx-zynq-devcfg.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_dma.o common-obj-$(CONFIG_STP2000) += sparc32_dma.o common-obj-$(CONFIG_SUN4M) += sun4m_iommu.o
hw/dma/xlnx-zynq-devcfg.c new file +401 -0
401 lines not on this page · raw message
include/hw/dma/xlnx-zynq-devcfg.h new file +62 -0
62 lines not on this page · raw message
include/hw/register.h +1 -1
@@ -208,7 +208,7 @@ MemoryRegion *register_init_block32(DeviceState *owner, enum { R_ ## reg ## _ ## field ## _SHIFT = (shift)}; \ enum { R_ ## reg ## _ ## field ## _LENGTH = (length)}; \ enum { R_ ## reg ## _ ## field ## _MASK = \ - MAKE_64BIT_MASK(shift, length); + MAKE_64BIT_MASK(shift, length)};/* Extract a field from a register */ #define FIELD_EX32 (storage, reg, field) \
Signature · 1 line
2.7.4
PATCH v7 8/12 xilinx_zynq: Connect devcfg to the Zynq machine model
In reply to Alistair FrancisFrom: Peter Crosthwaite <[email protected]>
---
V7:
- Remove unused property add
V4:
- Small corrections to the device model logic
hw/arm/xilinx_zynq.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/arm/xilinx_zynq.c +6 -0
@@ -294,6 +294,12 @@ static void zynq_init(MachineState *machine)sysbus_connect_irq (busdev, n +1 , pic[dma_irqs[n] -IRQ_OFFSET ]); } + dev =qdev_create (NULL ,"xlnx.ps7-dev-cfg" ); +qdev_init_nofail (dev); + busdev =SYS_BUS_DEVICE (dev); +sysbus_connect_irq (busdev,0 , pic[40 -IRQ_OFFSET ]); +sysbus_mmio_map (busdev,0 ,0xF8007000 ); + zynq_binfo.ram_size = ram_size; zynq_binfo.kernel_filename = kernel_filename; zynq_binfo.kernel_cmdline = kernel_cmdline;
Signature · 1 line
2.7.4
PATCH v7 9/12 irq: Add opaque setter routine
In reply to Alistair FrancisFrom: Peter Crosthwaite <[email protected]>
Add a routine to set or override the opaque data of an IRQ.
Qdev currently always initialises IRQ opaque as the device itself. This allows you to override to a custom opaque in the case where there is extra or different data needed.
---
hw/core/irq.c | 5 +++++ include/hw/irq.h | 2 ++ 2 files changed, 7 insertions(+)
hw/core/irq.c +5 -0
@@ -77,6 +77,11 @@ qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n)return irq; } +void qemu_irq_set_opaque (qemu_irq irq,void *opaque) +{ + irq->opaque = opaque; +} +void qemu_free_irqs (qemu_irq *s,int n) {int i;
include/hw/irq.h +2 -0
@@ -44,6 +44,8 @@ qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n);qemu_irq *qemu_extend_irqs (qemu_irq *old,int n_old,qemu_irq_handler handler,void *opaque,int n); +void qemu_irq_set_opaque (qemu_irq irq,void *opaque); +void qemu_free_irqs (qemu_irq *s,int n);void qemu_free_irq (qemu_irq irq);
Signature · 1 line
2.7.4
PATCH v7 10/12 register: Add GPIO API
In reply to Alistair FrancisAdd GPIO functionality to the register API. This allows association and automatic connection of GPIOs to bits in registers. GPIO inputs will attach to handlers that automatically set read-only bits in registers. GPIO outputs will be updated to reflect their field value when their respective registers are written (or reset). Supports active low GPIOs.
This is particularly effective for implementing system level controllers, where heterogenous collections of control signals are placed is a SoC specific peripheral then propagated all over the system.
[ EI Changes:
* register: Add a polarity field to GPIO connections Makes it possible to directly connect active low signals to generic interrupt pins.
]
---
V6:
- Don't use qdev_pass_all_gpios() as it doesn't seem to work
V5
- Remove RegisterAccessError struct
hw/core/register.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 27 ++++++++++++++ 2 files changed, 124 insertions(+)
hw/core/register.c +97 -0
@@ -108,6 +108,7 @@ void register_write(RegisterInfo *reg, uint64_t val, uint64_t we, }register_write_val (reg, new_val); +register_refresh_gpios (reg, old_val, debug);if (ac->post_write) { ac->post_write (reg, new_val);
@@ -147,23 +148,119 @@ uint64_t register_read(RegisterInfo *reg, const char* prefix, bool debug)void register_reset (RegisterInfo *reg) {g_assert (reg); +uint64_t old_val;if (!reg->data || !reg->access) {return ; } + old_val =register_read_val (reg); +register_write_val (reg, reg->access->reset); +register_refresh_gpios (reg, old_val, false); +} + +void register_refresh_gpios (RegisterInfo *reg,uint64_t old_value,bool debug) +{ +const RegisterAccessInfo *ac; +const RegisterGPIOMapping *gpio; + + ac = reg->access; +for (gpio = ac->gpios; gpio && gpio->name; gpio++) { +int i; + +if (gpio->input) { +continue ; + } + +for (i =0 ; i < gpio->num; ++i) { +uint64_t gpio_value, gpio_value_old; + +qemu_irq gpo =qdev_get_gpio_out_connector (DEVICE (reg), + gpio->name, i); + gpio_value_old =extract64 (old_value, + gpio->bit_pos + i * gpio->width, + gpio->width) ^ gpio->polarity; + gpio_value =extract64 (register_read_val (reg), + gpio->bit_pos + i * gpio->width, + gpio->width) ^ gpio->polarity; +if (!(gpio_value_old ^ gpio_value)) { +continue ; + } +if (debug && gpo) { +qemu_log ("refreshing gpio out %s to %" PRIx64"\n" , + gpio->name, gpio_value); + } +qemu_set_irq (gpo, gpio_value); + } + } +} + +typedef struct DeviceNamedGPIOHandlerOpaque { +DeviceState *dev; +const char *name; +}DeviceNamedGPIOHandlerOpaque ; + +static void register_gpio_handler (void *opaque,int n,int level) +{ +DeviceNamedGPIOHandlerOpaque *gho = opaque; +RegisterInfo *reg =REGISTER (gho->dev); + +const RegisterAccessInfo *ac; +const RegisterGPIOMapping *gpio; + + ac = reg->access; +for (gpio = ac->gpios; gpio && gpio->name; gpio++) { +if (gpio->input && !strcmp (gho->name, gpio->name)) { +register_write_val (reg,deposit64 (register_read_val (reg), + gpio->bit_pos + n * gpio->width, + gpio->width, + level ^ gpio->polarity)); +return ; + } + } + +abort (); }void register_init (RegisterInfo *reg) {assert (reg); +const RegisterAccessInfo *ac; +const RegisterGPIOMapping *gpio;if (!reg->data || !reg->access) {return ; }object_initialize ((void *)reg,sizeof (*reg),TYPE_REGISTER ); + + ac = reg->access; +for (gpio = ac->gpios; gpio && gpio->name; gpio++) { +if (!gpio->num) { + ((RegisterGPIOMapping *)gpio)->num =1 ; + } +if (!gpio->width) { + ((RegisterGPIOMapping *)gpio)->width =1 ; + } +if (gpio->input) { +DeviceNamedGPIOHandlerOpaque gho = { + .name = gpio->name, + .dev =DEVICE (reg), + }; +qemu_irq irq; + +qdev_init_gpio_in_named (DEVICE (reg), register_gpio_handler, + gpio->name, gpio->num); + irq =qdev_get_gpio_in_named (DEVICE (reg), gpio->name, gpio->num); +qemu_irq_set_opaque (irq,g_memdup (&gho,sizeof (gho))); + }else { +qemu_irq *gpos =g_new0 (qemu_irq, gpio->num); + +qdev_init_gpio_out_named (DEVICE (reg), gpos, gpio->name, gpio->num); +qdev_pass_gpios (DEVICE (reg), reg->opaque, gpio->name); + } + } } void register_write_memory(void *opaque, hwaddr addr,
include/hw/register.h +27 -0
@@ -13,11 +13,24 @@#include "hw/qdev-core.h" #include "exec/memory.h" +#include "hw/irq.h" typedef struct RegisterInfo RegisterInfo ;typedef struct RegisterAccessInfo RegisterAccessInfo ;typedef struct RegisterInfoArray RegisterInfoArray ; +#define REG_GPIO_POL_HIGH 0 +#define REG_GPIO_POL_LOW 1 + +typedef struct RegisterGPIOMapping { +const char *name; +uint8_t bit_pos; +bool input; +bool polarity; +uint8_t num; +uint8_t width; +}RegisterGPIOMapping ; +/** * Access description for a register that is part of guest accessible device * state.
@@ -55,6 +68,8 @@ struct RegisterAccessInfo {uint64_t (*post_read)(RegisterInfo *reg,uint64_t val);hwaddr addr; + +const RegisterGPIOMapping *gpios; };/**
@@ -148,6 +163,18 @@ void register_reset(RegisterInfo *reg);void register_init (RegisterInfo *reg);/** +* Refresh GPIO outputs based on diff between old value register current value. +* GPIOs are refreshed for fields where the old value differs to the current +* value. +* +* @reg: Register to refresh GPIO outs +* @old_value: previous value of register +* @debug: Should the read operation debug information be printed? +*/ + +void register_refresh_gpios (RegisterInfo *reg,uint64_t old_value,bool debug); + +/** * Memory API MMIO write handler that will write to a Register API register. * @opaque: RegisterInfo to write to * @addr: Address to write
Signature · 1 line
2.7.4
PATCH v7 11/12 misc: Introduce ZynqMP IOU SLCR
In reply to Alistair FrancisFrom: Peter Crosthwaite <[email protected]>
IOU = I/O Unit
SLCR = System Level Control Registers
This IP is a misc collections of control registers that switch various properties of system IPs. Currently the only thing implemented is the SD_SLOTTYPE control (implemented as a GPIO output).
---
hw/misc/Makefile.objs | 1 + hw/misc/xlnx-zynqmp-iou-slcr.c | 122 +++++++++++++++++++++++++++++++++ include/hw/misc/xlnx-zynqmp-iou-slcr.h | 47 +++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 hw/misc/xlnx-zynqmp-iou-slcr.c create mode 100644 include/hw/misc/xlnx-zynqmp-iou-slcr.h
hw/misc/Makefile.objs +1 -0
@@ -43,6 +43,7 @@ obj-$(CONFIG_RASPI) += bcm2835_property.o obj-$(CONFIG_SLAVIO) += slavio_misc.o obj-$(CONFIG_ZYNQ) += zynq_slcr.o obj-$(CONFIG_ZYNQ) += zynq-xadc.o +obj-$(CONFIG_ZYNQ) += xlnx-zynqmp-iou-slcr.o obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o obj-$(CONFIG_MIPS_CPS) += mips_cpc.o
hw/misc/xlnx-zynqmp-iou-slcr.c new file +122 -0
122 lines not on this page · raw message
include/hw/misc/xlnx-zynqmp-iou-slcr.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v7 01/12] bitops: Add MAKE_64BIT_MASK macro
In reply to Alistair FrancisQuoted 5 lines · Alistair Francis
Add a macro that creates a 64bit value which has length number of ones shifted across by the value of shift.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Alex Bennée <[email protected]>
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 03/12] register: Add Memory API glue
In reply to Alistair FrancisQuoted 28 lines · Alistair Francis
Add memory io handlers that glue the register API to the memory API. Just translation functions at this stage. Although it does allow for devices to be created without all-in-one mmio r/w handlers.
This patch also adds the RegisterInfoArray struct, which allows all of the individual RegisterInfo structs to be grouped into a single memory region.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Alistair Francis <[email protected]>---
V7:
- Remove endianess handling
- Removeassert()and log missing registers
V6:
- Add the memory region later
V5:
- Convert to using only one memory regionhw/core/register.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+)hw/core/register.c +0
-0
hw/core/register.c void register_reset(RegisterInfo *reg) · line 163
Quoted 10 lines
hw/core/register.c +7
-0@@ -154,3 +154,61 @@ void register_reset(RegisterInfo *reg)register_write_val (reg, reg->access->reset); } + +void register_write_memory (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +RegisterInfoArray *reg_array = opaque; +RegisterInfo *reg =NULL ; +uint64_t we = ~0 ;
Really ~0 and not ~0ULL ? In any case this shouldn't need initializing as we will always set it later.
hw/core/register.c void register_reset(RegisterInfo *reg) · line 175
Quoted 12 lines
hw/core/register.c +12
-0+int i; + +for (i =0 ; i < reg_array->num_elements; i++) { +if (reg_array->r[i]->access->addr == addr) { + reg = reg_array->r[i]; +break ; + } + } + +if (!reg) { +qemu_log_mask (LOG_UNIMP ,"Write to unimplemented register at " \ +"address: %#" PRIx64"\n" , addr);
Shouldn't this be a LOG_GUEST_ERROR ?
hw/core/register.c void register_reset(RegisterInfo *reg) · line 182
Quoted 7 lines
hw/core/register.c +7
-0+return ; + } + +/* Generate appropriate write enable mask */ +if (reg->data_size < size) { + we =MAKE_64BIT_MASK (0 , reg->data_size *8 ); + }else if (reg->data_size >= size) {
Why not just "else {" ?
Quoted 19 lines
hw/core/register.c +19
-0+ we =MAKE_64BIT_MASK (0 , size *8 ); + } + +register_write (reg, value, we, reg_array->prefix, + reg_array->debug); +} + +uint64_t register_read_memory (void *opaque,hwaddr addr, +unsigned size) +{ +RegisterInfoArray *reg_array = opaque; +RegisterInfo *reg =NULL ; +uint64_t read_val; +int i; + +for (i =0 ; i < reg_array->num_elements; i++) { +if (reg_array->r[i]->access->addr == addr) { + reg = reg_array->r[i]; +break ;
hw/core/register.c void register_reset(RegisterInfo *reg) · line 211
Quoted 10 lines
hw/core/register.c +10
-0+ } + } + +if (!reg) { +qemu_log_mask (LOG_UNIMP ,"Read to unimplemented register at " \ +"address: %#" PRIx64"\n" , addr); +return 0 ; + } + + read_val =register_read (reg, reg_array->prefix, reg_array->debug);
This will silently affect bits of the register outside the specified size with clear-on-read or other "reads have side effects" behaviour, which isn't consistent with how we handle writes.
Quoted 3 lines
/**
+ * This structure is used to group all of the individual registers which are
+ * modeled using the RegisterInfo strucutre.
"structure"
Quoted 7 lines
+ *
+ * @r is an aray containing of all the relevent RegisterInfo structures.
+ *
+ * @num_elements is the number of elements in the array r
+ *
+ * @mem: optional Memory region for the register
+ */
hw/core/register.c
Quoted 9 lines
hw/core/register.c +9
-0+ +struct RegisterInfoArray { +int num_elements; +RegisterInfo **r; + +bool debug; +const char *prefix; +}; +
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 04/12] register: Define REG and FIELD macros
In reply to Alistair FrancisQuoted 36 lines · Alistair Francis
From: Peter Crosthwaite <[email protected]>
Define some macros that can be used for defining registers and fields.
The REG32 macro will define
A_FOO, for the byte address of a register as well asR_FOOfor the uint32_t[] register number (A_FOO/ 4).The FIELD macro will define
FOO_BAR_MASK,FOO_BAR_SHIFTandFOO_BAR_LENGTHconstants for field BAR in register FOO.Finally, there are some shorthand helpers for extracting/depositing fields from registers based on these naming schemes.
Usage can greatly reduce the verbosity of device code.
The deposit and extract macros (eg
FIELD_EX32,FIELD_DP32etc.) can be used to generate extract and deposits without any repetition of the name stems.Signed-off-by Peter Crosthwaite <[email protected]>[ EI Changes:
* Add Deposit macros
]Signed-off-by Edgar E. Iglesias <[email protected]>Signed-off-by Alistair Francis <[email protected]>---
include/hw/register.h +1
-0@@ -150,4 +150,47 @@ void register_write_memory(void *opaque, hwaddr addr, uint64_t value,uint64_t register_read_memory (void *opaque,hwaddr addr,unsigned size); +/* Define constants for a 32 bit register */
include/hw/register.h void register_write_memory(void *opaque, hwaddr addr, uint64_t value, · line 163
Quoted 10 lines
include/hw/register.h +10
-0+ +/* This macro will define A_FOO, for the byte address of a register +* as well as R_FOO for the uint32_t[] register number (A_FOO / 4). +*/ +#define REG32 (reg, addr) \ + enum { A_ ## reg = (addr) }; \ + enum { R_ ## reg = (addr) / 4 }; + +/* Define SHIFT, LEGTH and MASK constants for a field within a register */ +
"LENGTH".
include/hw/register.h void register_write_memory(void *opaque, hwaddr addr, uint64_t value, · line 190
Quoted 9 lines
include/hw/register.h +9
-0+/* Deposit a register field. */ +#define FIELD_DP32 (storage, reg, field, val) ({ \ + struct { \ + unsigned int v:R_ ## reg ## _ ## field ## _LENGTH; \ + } v = { .v = val }; \ + uint32_t d; \ + d = deposit32((storage), R_ ## reg ## _ ## field ## _SHIFT, \ + R_ ## reg ## _ ## field ## _LENGTH, v.v); \ + d; })
If you insist on different semantics to deposit32() (which I still think is a bad idea), can we at least have a comment noting the difference?
(Do you get a warning for putting a signed negative value into a field?)
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 05/12] register: QOMify
In reply to Alistair FrancisQuoted 92 lines · Alistair Francis
From: Peter Crosthwaite <[email protected]>
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 <[email protected]>Signed-off-by Alistair Francis <[email protected]>Reviewed-by KONRAD Frederic <[email protected]>---
V7:
- Remove uneeded struct
- Fixup documentation
V5:
- Convert to using only one memory regionhw/core/register.c | 23 +++++++++++++++++++++++ include/hw/register.h | 16 ++++++++++++++++ 2 files changed, 39 insertions(+)hw/core/register.c +23
-0@@ -155,6 +155,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) {@@ -212,3 +223,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)include/hw/register.h +7
-0@@ -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 strucutre.
include/hw/register.h uint64_t register_read(RegisterInfo *reg, const char* prefix, bool debug); · line 144
Quoted 8 lines
include/hw/register.h +5
-0@@ -130,6 +137,15 @@ uint64_t register_read(RegisterInfo *reg, const char* prefix, bool debug);void register_reset (RegisterInfo *reg);/** +* Initialize a register. This will also setup any GPIO links which are used +* to connect register updates in one device to other devices. Generally this +* is useful for interrupt propagation. +* @reg: Register to initialize +*/
Leave the remark about GPIOs to the patch that adds GPIO support.
Otherwise
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 06/12] register: Add block initialise helper
In reply to Alistair FrancisQuoted 32 lines · Alistair Francis
From: Peter Crosthwaite <[email protected]>
Add a helper that will scan a static RegisterAccessInfo Array and populate a container MemoryRegion with registers as defined.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Alistair Francis <[email protected]>---
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:
- Usememory_region_add_subregion_no_print()hw/core/register.c | 36 ++++++++++++++++++++++++++++++++++++ include/hw/register.h | 24 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+)hw/core/register.c +0
-0@@ -224,6 +224,42 @@ uint64_t register_read_memory(void *opaque, hwaddr addr,return extract64 (read_val,0 , size *8 );
hw/core/register.c uint64_t register_read_memory(void *opaque, hwaddr addr, · line 234
Quoted 10 lines
hw/core/register.c +8
-0} +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));
Prefer g_new0(RegisterInfoArray, 1)
hw/core/register.c uint64_t register_read_memory(void *opaque, hwaddr addr, · line 237
Quoted 3 lines
hw/core/register.c +3
-0+int i; + + r_array->r =g_malloc_n (num,sizeof (RegisterInfo *));
Prefer g_new0(RegisterInfo *, num)
Quoted 13 lines
hw/core/register.c +13
-0+ 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,
hw/core/register.c uint64_t register_read_memory(void *opaque, hwaddr addr, · line 260
Quoted 10 lines
hw/core/register.c +10
-0+ }; +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;
This API doesn't seem to have any provision for being able to free the RegisterInfoArray later ? (Consider hotpluggable devices which need to be able to free everything on hot-unplug.)
Quoted 23 lines
hw/core/register.c +1
-0+static const TypeInfo register_info = { .name =TYPE_REGISTER , .parent =TYPE_DEVICE ,include/hw/register.h +4
-0@@ -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
include/hw/register.h void register_write_memory(void *opaque, hwaddr addr, uint64_t value, · line 182
Quoted 10 lines
include/hw/register.h +10
-0+* 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
It's not clear to me which of these are input arguments to the function, and which are things that the function initializes (I think 'ri' is purely output?)
include/hw/register.h void register_write_memory(void *opaque, hwaddr addr, uint64_t value, · line 183
Quoted 1 line
include/hw/register.h +1
-0+* returns: A pointer to an initalised memory region that the caller should
"initialized"
Quoted 13 lines
include/hw/register.h +9
-1+* 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 --
Quoted 1 line
2.7.4
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 07/12] dma: Add Xilinx Zynq devcfg device model
In reply to Alistair Francishw/dma/xlnx-zynq-devcfg.c line 177
Quoted 13 lines · Alistair Francis
Add a minimal model for the devcfg device which is part of Zynq. This model supports DMA capabilities and interrupt generation.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Alistair Francis <[email protected]>hw/dma/xlnx-zynq-devcfg.c new file +7
-0+if (!dmah->src_len && !dmah->dest_len) { +DB_PRINT ("dma operation finished\n" ); + s->regs[R_INT_STS ] |=R_INT_STS_DMA_DONE_MASK | +R_INT_STS_DMA_P_DONE_MASK ; + s->dma_cmd_fifo_num--; +memmove (s->dma_cmd_fifo, &s->dma_cmd_fifo[1 ], +sizeof (s->dma_cmd_fifo));
This looks like an off-by-one error in the size argument.
Quoted 5 lines
hw/dma/xlnx-zynq-devcfg.c new file +4
-0+ } +xlnx_zynq_devcfg_update_ixr (s); + }while (s->dma_cmd_fifo_num); +}
hw/dma/xlnx-zynq-devcfg.c line 225
Quoted 10 lines
hw/dma/xlnx-zynq-devcfg.c new file +10
-0+static void r_unlock_post_write (RegisterInfo *reg,uint64_t val) +{ +XlnxZynqDevcfg *s =XLNX_ZYNQ_DEVCFG (reg->opaque); +const char *device_prefix =object_get_typename (OBJECT (s)); + +if (val ==R_UNLOCK_MAGIC ) { +DB_PRINT ("successful unlock\n" ); +/* BootROM will have already done the actual unlock so no need to do +* anything in successful subsequent unlock +*/
I don't understand this comment. Shouldn't we be marking the memory region as enabled here, to handle the case of "guest locks the device via a bad-unlock-attempt; guest unlocks via a good unlock attempt" ? What the guest bootrom does or doesn't do isn't usually relevant to the device implementation.
Quoted 13 lines
hw/dma/xlnx-zynq-devcfg.c new file +12
-0+ }else {/* bad unlock attempt */ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed unlock\n" , device_prefix); + s->regs[R_CTRL ] &= ~R_CTRL_PCAP_PR_MASK ; + s->regs[R_CTRL ] &= ~R_CTRL_PCFG_AES_EN_MASK ; +/* core becomes inaccessible */ +memory_region_set_enabled (&s->iomem, false); + } +} + +static const RegisterAccessInfo xlnx_zynq_devcfg_regs_info[] = { + { .name ="CTRL" , .addr =A_CTRL , + .reset =R_CTRL_PCAP_PR_MASK |R_CTRL_PCAP_MODE_MASK |0x3 <<13 ,
hw/dma/xlnx-zynq-devcfg.c line 271
Quoted 10 lines
hw/dma/xlnx-zynq-devcfg.c new file +10
-0+ .rsvd = 0x1 << 28 | 0x3ff << 13 | 0x3 << 13, + .pre_write = r_ctrl_pre_write, + .post_write = r_ctrl_post_write, + }, + { .name = "LOCK", .addr = A_LOCK, + .rsvd = MAKE_64BIT_MASK(5, 64 - 5), + .pre_write = r_lock_pre_write, + }, + { .name = "CFG", .addr = A_CFG, + .reset = 1 << R_CFG_RFIFO_TH_SHIFT | 1 << R_CFG_WFIFO_TH_SHIFT | 0x8,
I was expecting this to use the R_CFG_RESET value defined earlier (or alternatively don't bother defining a #define for it...)
hw/dma/xlnx-zynq-devcfg.c line 345
Quoted 5 lines
hw/dma/xlnx-zynq-devcfg.c new file +5
-0+static const VMStateDescription vmstate_xlnx_zynq_devcfg = { + .name ="xlnx_zynq_devcfg" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 ,
You don't need an _old field.
Quoted 17 lines
hw/dma/xlnx-zynq-devcfg.c new file +10
-0+ .fields = (VMStateField[]) { +VMSTATE_STRUCT_ARRAY (dma_cmd_fifo, XlnxZynqDevcfg, +XLNX_ZYNQ_DEVCFG_DMA_CMD_FIFO_LEN ,0 , + vmstate_xlnx_zynq_devcfg_dma_cmd, + XlnxZynqDevcfgDMACmd), +VMSTATE_UINT8 (dma_cmd_fifo_num, XlnxZynqDevcfg), +VMSTATE_UINT32_ARRAY (regs, XlnxZynqDevcfg,XLNX_ZYNQ_DEVCFG_R_MAX ), +VMSTATE_END_OF_LIST () + } +};include/hw/register.h +0
-0
include/hw/register.h MemoryRegion *register_init_block32(DeviceState *owner, · line 214
Quoted 8 lines
include/hw/register.h +1
-1@@ -208,7 +208,7 @@ MemoryRegion *register_init_block32(DeviceState *owner, enum { R_ ## reg ## _ ## field ## _SHIFT = (shift)}; \ enum { R_ ## reg ## _ ## field ## _LENGTH = (length)}; \ enum { R_ ## reg ## _ ## field ## _MASK = \ - MAKE_64BIT_MASK(shift, length); + MAKE_64BIT_MASK(shift, length)};/* Extract a field from a register */ #define FIELD_EX32 (storage, reg, field) \
Should this hunk be in some earlier patch ?
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 08/12] xilinx_zynq: Connect devcfg to the Zynq machine model
In reply to Alistair FrancisQuoted 31 lines · Alistair Francis
From: Peter Crosthwaite <[email protected]>
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Alistair Francis <[email protected]>---
V7:
- Remove unused property add
V4:
- Small corrections to the device model logichw/arm/xilinx_zynq.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/arm/xilinx_zynq.c +6
-1@@ -294,6 +294,12 @@ static void zynq_init(MachineState *machine)sysbus_connect_irq (busdev, n +1 , pic[dma_irqs[n] -IRQ_OFFSET ]); } + dev =qdev_create (NULL ,"xlnx.ps7-dev-cfg" ); +qdev_init_nofail (dev); + busdev =SYS_BUS_DEVICE (dev); +sysbus_connect_irq (busdev,0 , pic[40 -IRQ_OFFSET ]); +sysbus_mmio_map (busdev,0 ,0xF8007000 ); + zynq_binfo.ram_size = ram_size; zynq_binfo.kernel_filename = kernel_filename; zynq_binfo.kernel_cmdline = kernel_cmdline; --
Quoted 1 line
2.7.4
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 10/12] register: Add GPIO API
In reply to Alistair FrancisQuoted 11 lines · Alistair Francis
Add GPIO functionality to the register API. This allows association and automatic connection of GPIOs to bits in registers. GPIO inputs will attach to handlers that automatically set read-only bits in registers. GPIO outputs will be updated to reflect their field value when their respective registers are written (or reset). Supports active low GPIOs.
This is particularly effective for implementing system level controllers, where heterogenous collections of control signals are placed is a SoC specific peripheral then propagated all over the system.
I still don't think this is a good idea. GPIOs are device-level, not register-level. Most devices don't really have very many GPIOs. It should be easy to wire up "change GPIO state based on new register value" from a register post-write hook. This API can't handle the absolute most common case, which is "GPIO state is based on a bit being set in (raw-state-register AND mask-register)."
Basically I don't think GPIOs belong in this API, and I don't think there's a good case that adding them makes a significant class of devices much easier to write.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 03/12] register: Add Memory API glue
In reply to Peter MaydellQuoted 103 lines · Peter Maydell
Quoted 28 lines · Alistair Francis
Add memory io handlers that glue the register API to the memory API. Just translation functions at this stage. Although it does allow for devices to be created without all-in-one mmio r/w handlers.
This patch also adds the RegisterInfoArray struct, which allows all of the individual RegisterInfo structs to be grouped into a single memory region.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Alistair Francis <[email protected]>---
V7:
- Remove endianess handling
- Removeassert()and log missing registers
V6:
- Add the memory region later
V5:
- Convert to using only one memory regionhw/core/register.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+)hw/core/register.c +0
-0hw/core/register.c void register_reset(RegisterInfo *reg) · line 163
Quoted 10 lines
hw/core/register.c +7
-0@@ -154,3 +154,61 @@ void register_reset(RegisterInfo *reg)register_write_val (reg, reg->access->reset); } + +void register_write_memory (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +RegisterInfoArray *reg_array = opaque; +RegisterInfo *reg =NULL ; +uint64_t we = ~0 ;Really ~0 and not ~0ULL ? In any case this shouldn't need initializing as we will always set it later.
hw/core/register.c void register_reset(RegisterInfo *reg) · line 175
Quoted 12 lines
hw/core/register.c +12
-0+int i; + +for (i =0 ; i < reg_array->num_elements; i++) { +if (reg_array->r[i]->access->addr == addr) { + reg = reg_array->r[i]; +break ; + } + } + +if (!reg) { +qemu_log_mask (LOG_UNIMP ,"Write to unimplemented register at " \ +"address: %#" PRIx64"\n" , addr);Shouldn't this be a
LOG_GUEST_ERROR?hw/core/register.c void register_reset(RegisterInfo *reg) · line 182
Quoted 7 lines
hw/core/register.c +7
-0+return ; + } + +/* Generate appropriate write enable mask */ +if (reg->data_size < size) { + we =MAKE_64BIT_MASK (0 , reg->data_size *8 ); + }else if (reg->data_size >= size) {Why not just "else {" ?
Quoted 19 lines
hw/core/register.c +19
-0+ we =MAKE_64BIT_MASK (0 , size *8 ); + } + +register_write (reg, value, we, reg_array->prefix, + reg_array->debug); +} + +uint64_t register_read_memory (void *opaque,hwaddr addr, +unsigned size) +{ +RegisterInfoArray *reg_array = opaque; +RegisterInfo *reg =NULL ; +uint64_t read_val; +int i; + +for (i =0 ; i < reg_array->num_elements; i++) { +if (reg_array->r[i]->access->addr == addr) { + reg = reg_array->r[i]; +break ;hw/core/register.c void register_reset(RegisterInfo *reg) · line 211
Quoted 10 lines
hw/core/register.c +10
-0+ } + } + +if (!reg) { +qemu_log_mask (LOG_UNIMP ,"Read to unimplemented register at " \ +"address: %#" PRIx64"\n" , addr); +return 0 ; + } + + read_val =register_read (reg, reg_array->prefix, reg_array->debug);This will silently affect bits of the register outside the specified size with clear-on-read or other "reads have side effects" behaviour, which isn't consistent with how we handle writes.
Quoted 5 lines
Quoted 3 lines
/**
+ * This structure is used to group all of the individual registers which are
+ * modeled using the RegisterInfo strucutre."structure"
Fixed all.
Thanks,
Alistair
Quoted 21 lines
Quoted 8 lines
+ *
+ * @r is an aray containing of all the relevent RegisterInfo structures.
+ *
+ * @num_elements is the number of elements in the array r
+ *
+ * @mem: optional Memory region for the register
+ */hw/core/register.c
Quoted 9 lines
hw/core/register.c +9
-0+ +struct RegisterInfoArray { +int num_elements; +RegisterInfo **r; + +bool debug; +const char *prefix; +}; +thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 06/12] register: Add block initialise helper
In reply to Peter MaydellQuoted 46 lines · Peter Maydell
Quoted 32 lines · Alistair Francis
From: Peter Crosthwaite <[email protected]>
Add a helper that will scan a static RegisterAccessInfo Array and populate a container MemoryRegion with registers as defined.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Alistair Francis <[email protected]>---
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:
- Usememory_region_add_subregion_no_print()hw/core/register.c | 36 ++++++++++++++++++++++++++++++++++++ include/hw/register.h | 24 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+)hw/core/register.c +0
-0@@ -224,6 +224,42 @@ uint64_t register_read_memory(void *opaque, hwaddr addr,return extract64 (read_val,0 , size *8 );hw/core/register.c uint64_t register_read_memory(void *opaque, hwaddr addr, · line 234
Quoted 10 lines
hw/core/register.c +8
-0} +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));Prefer
g_new0(RegisterInfoArray, 1)
Quoted 5 lines
hw/core/register.c uint64_t register_read_memory(void *opaque, hwaddr addr, · line 237
Quoted 3 lines
hw/core/register.c +3
-0+int i; + + r_array->r =g_malloc_n (num,sizeof (RegisterInfo *));Prefer
g_new0(RegisterInfo *, num)
Ok, I have fixed these.
Quoted 20 lines
Quoted 20 lines
hw/core/register.c +19
-0+ 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; + } +
Quoted 8 lines
hw/core/register.c uint64_t register_read_memory(void *opaque, hwaddr addr, · line 260
Quoted 4 lines
hw/core/register.c +4
-0+memory_region_init_io (&r_array->mem,OBJECT (owner), ops, r_array, + device_prefix, memory_size); + +return &r_array->mem;This API doesn't seem to have any provision for being able to free the RegisterInfoArray later ? (Consider hotpluggable devices which need to be able to free everything on hot-unplug.)
I have added a finalise function which can be used to free the register array.
This meant I had to change register_init_block32() to return RegisterInfoArray instead of a MemoryRegion.
Quoted 21 lines
Quoted 21 lines
hw/core/register.c +1
-0+static const TypeInfo register_info = { .name =TYPE_REGISTER , .parent =TYPE_DEVICE ,include/hw/register.h +2
-0@@ -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);
Quoted 16 lines
include/hw/register.h void register_write_memory(void *opaque, hwaddr addr, uint64_t value, · line 182
Quoted 12 lines
include/hw/register.h +12
-0+/** +* 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 It's not clear to me which of these are input arguments to the function, and which are things that the function initializes (I think 'ri' is purely output?)
The function expects everything to already be initialised, it just wires them up.
ri should already be allocated, this function just sets up some pointers to it.
I added a comment in the description saying that ri and data must already be allocated. Is that enough?
Quoted 4 lines
include/hw/register.h void register_write_memory(void *opaque, hwaddr addr, uint64_t value, · line 183
Quoted 2 lines
include/hw/register.h +1
-0+* returns: A pointer to an initalised memory region that the caller should "initialized"
Fixed.
Thanks,
Alistair
Quoted 19 lines
Quoted 14 lines
include/hw/register.h +9
-1+* 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 -- Quoted 1 line
2.7.4
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 04/12] register: Define REG and FIELD macros
In reply to Peter MaydellQuoted 36 lines · Peter Maydell
Quoted 35 lines · Alistair Francis
From: Peter Crosthwaite <[email protected]>
Define some macros that can be used for defining registers and fields.
The REG32 macro will define
A_FOO, for the byte address of a register as well asR_FOOfor the uint32_t[] register number (A_FOO/ 4).The FIELD macro will define
FOO_BAR_MASK,FOO_BAR_SHIFTandFOO_BAR_LENGTHconstants for field BAR in register FOO.Finally, there are some shorthand helpers for extracting/depositing fields from registers based on these naming schemes.
Usage can greatly reduce the verbosity of device code.
The deposit and extract macros (eg
FIELD_EX32,FIELD_DP32etc.) can be used to generate extract and deposits without any repetition of the name stems.Signed-off-by Peter Crosthwaite <[email protected]>[ EI Changes:
* Add Deposit macros
]Signed-off-by Edgar E. Iglesias <[email protected]>Signed-off-by Alistair Francis <[email protected]>---
include/hw/register.h +0
-0@@ -150,4 +150,47 @@ void register_write_memory(void *opaque, hwaddr addr, uint64_t value,uint64_t register_read_memory (void *opaque,hwaddr addr,unsigned size);
Quoted 13 lines
include/hw/register.h void register_write_memory(void *opaque, hwaddr addr, uint64_t value, · line 163
Quoted 11 lines
include/hw/register.h +11
-0+/* Define constants for a 32 bit register */ + +/* This macro will define A_FOO, for the byte address of a register +* as well as R_FOO for the uint32_t[] register number (A_FOO / 4). +*/ +#define REG32 (reg, addr) \ + enum { A_ ## reg = (addr) }; \ + enum { R_ ## reg = (addr) / 4 }; + +/* Define SHIFT, LEGTH and MASK constants for a field within a register */ +"LENGTH".
Fixed
Quoted 14 lines
include/hw/register.h void register_write_memory(void *opaque, hwaddr addr, uint64_t value, · line 190
Quoted 10 lines
include/hw/register.h +9
-0+/* Deposit a register field. */ +#define FIELD_DP32 (storage, reg, field, val) ({ \ + struct { \ + unsigned int v:R_ ## reg ## _ ## field ## _LENGTH; \ + } v = { .v = val }; \ + uint32_t d; \ + d = deposit32((storage), R_ ## reg ## _ ## field ## _SHIFT, \ + R_ ## reg ## _ ## field ## _LENGTH, v.v); \ + d; })If you insist on different semantics to
deposit32()(which I still think is a bad idea), can we at least have a comment noting the difference?
I have added a comment.
Quoted 3 lines
(Do you get a warning for putting a signed negative value into a field?)
No, I don't see any warnings for forcing negative values in.
Thanks,
Alistair
Quoted 7 lines
Otherwise
Reviewed-by Peter Maydell <[email protected]>thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 06/12] register: Add block initialise helper
In reply to Alistair FrancisQuoted 5 lines · Alistair Francis
Quoted 3 lines · Peter Maydell
It's not clear to me which of these are input arguments to the function, and which are things that the function initializes (I think 'ri' is purely output?)
Quoted 7 lines
The function expects everything to already be initialised, it just wires them up.
ri should already be allocated, this function just sets up some pointers to it.
I added a comment in the description saying that ri and data must already be allocated. Is that enough?
Does the caller have to initialize the array that ri points to before it calls this?
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 07/12] dma: Add Xilinx Zynq devcfg device model
In reply to Peter MaydellQuoted 15 lines · Peter Maydell
hw/dma/xlnx-zynq-devcfg.c line 177
Quoted 13 lines · Alistair Francis
Add a minimal model for the devcfg device which is part of Zynq. This model supports DMA capabilities and interrupt generation.
Signed-off-by Peter Crosthwaite <[email protected]>Signed-off-by Alistair Francis <[email protected]>hw/dma/xlnx-zynq-devcfg.c new file +7
-0+if (!dmah->src_len && !dmah->dest_len) { +DB_PRINT ("dma operation finished\n" ); + s->regs[R_INT_STS ] |=R_INT_STS_DMA_DONE_MASK | +R_INT_STS_DMA_P_DONE_MASK ; + s->dma_cmd_fifo_num--; +memmove (s->dma_cmd_fifo, &s->dma_cmd_fifo[1 ], +sizeof (s->dma_cmd_fifo));
Quoted 1 line
This looks like an off-by-one error in the size argument.
Fixed.
Quoted 15 lines
Quoted 15 lines
hw/dma/xlnx-zynq-devcfg.c new file +13
-0+ } +xlnx_zynq_devcfg_update_ixr (s); + }while (s->dma_cmd_fifo_num); +} +static void r_unlock_post_write (RegisterInfo *reg,uint64_t val) +{ +XlnxZynqDevcfg *s =XLNX_ZYNQ_DEVCFG (reg->opaque); +const char *device_prefix =object_get_typename (OBJECT (s)); + +if (val ==R_UNLOCK_MAGIC ) { +DB_PRINT ("successful unlock\n" ); +/* BootROM will have already done the actual unlock so no need to do +* anything in successful subsequent unlock
Quoted 8 lines
Quoted 1 line
+ */
I don't understand this comment. Shouldn't we be marking the memory region as enabled here, to handle the case of "guest locks the device via a bad-unlock-attempt; guest unlocks via a good unlock attempt" ? What the guest bootrom does or doesn't do isn't usually relevant to the device implementation.
Agreed. I have added the ability to unlock.
Quoted 19 lines
Quoted 19 lines
hw/dma/xlnx-zynq-devcfg.c new file +17
-0+ }else {/* bad unlock attempt */ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed unlock\n" , device_prefix); + s->regs[R_CTRL ] &= ~R_CTRL_PCAP_PR_MASK ; + s->regs[R_CTRL ] &= ~R_CTRL_PCFG_AES_EN_MASK ; +/* core becomes inaccessible */ +memory_region_set_enabled (&s->iomem, false); + } +} + +static const RegisterAccessInfo xlnx_zynq_devcfg_regs_info[] = { + { .name ="CTRL" , .addr =A_CTRL , + .reset =R_CTRL_PCAP_PR_MASK |R_CTRL_PCAP_MODE_MASK |0x3 <<13 , + .rsvd =0x1 <<28 |0x3ff <<13 |0x3 <<13 , + .pre_write = r_ctrl_pre_write, + .post_write = r_ctrl_post_write, + }, + { .name ="LOCK" , .addr =A_LOCK ,
Quoted 8 lines
hw/dma/xlnx-zynq-devcfg.c line 271
Quoted 5 lines
hw/dma/xlnx-zynq-devcfg.c new file +5
-0+ .rsvd = MAKE_64BIT_MASK(5, 64 - 5), + .pre_write = r_lock_pre_write, + }, + { .name = "CFG", .addr = A_CFG, + .reset = 1 << R_CFG_RFIFO_TH_SHIFT | 1 << R_CFG_WFIFO_TH_SHIFT | 0x8,I was expecting this to use the
R_CFG_RESETvalue defined earlier (or alternatively don't bother defining a #define for it...)
Fixed, it's now using the macro.
Quoted 9 lines
hw/dma/xlnx-zynq-devcfg.c line 345
Quoted 7 lines
hw/dma/xlnx-zynq-devcfg.c new file +5
-0+static const VMStateDescription vmstate_xlnx_zynq_devcfg = { + .name ="xlnx_zynq_devcfg" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 ,You don't need an
_oldfield.
Removed.
Quoted 24 lines
Quoted 24 lines
hw/dma/xlnx-zynq-devcfg.c new file +10
-0+ .fields = (VMStateField[]) { +VMSTATE_STRUCT_ARRAY (dma_cmd_fifo, XlnxZynqDevcfg, +XLNX_ZYNQ_DEVCFG_DMA_CMD_FIFO_LEN ,0 , + vmstate_xlnx_zynq_devcfg_dma_cmd, + XlnxZynqDevcfgDMACmd), +VMSTATE_UINT8 (dma_cmd_fifo_num, XlnxZynqDevcfg), +VMSTATE_UINT32_ARRAY (regs, XlnxZynqDevcfg,XLNX_ZYNQ_DEVCFG_R_MAX ), +VMSTATE_END_OF_LIST () + } +};include/hw/register.h +1
-1@@ -208,7 +208,7 @@ MemoryRegion *register_init_block32(DeviceState *owner, enum { R_ ## reg ## _ ## field ## _SHIFT = (shift)}; \ enum { R_ ## reg ## _ ## field ## _LENGTH = (length)}; \ enum { R_ ## reg ## _ ## field ## _MASK = \ - MAKE_64BIT_MASK(shift, length); + MAKE_64BIT_MASK(shift, length)};
Quoted 4 lines
include/hw/register.h MemoryRegion *register_init_block32(DeviceState *owner, · line 214
Quoted 2 lines
include/hw/register.h +0
-0/* Extract a field from a register */ #define FIELD_EX32 (storage, reg, field) \Should this hunk be in some earlier patch ?
Yes it should, I have fixed this as well.
Thanks,
Alistair
Quoted 4 lines
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 06/12] register: Add block initialise helper
In reply to Peter MaydellQuoted 9 lines · Peter Maydell
Quoted 8 lines · Alistair Francis
Quoted 3 lines · Peter Maydell
It's not clear to me which of these are input arguments to the function, and which are things that the function initializes (I think 'ri' is purely output?)
The function expects everything to already be initialised, it just wires them up.
Quoted 7 lines
Quoted 4 lines
ri should already be allocated, this function just sets up some pointers to it.
I added a comment in the description saying that ri and data must already be allocated. Is that enough?
Does the caller have to initialize the array that ri points to before it calls this?
All the caller has to do is ensure that the array exists and is large enough for the number of registers.
Thanks,
Alistair
Quoted 4 lines
thanks
-- PMM
Re: [Qemu-devel] [PATCH v7 10/12] register: Add GPIO API
In reply to Peter MaydellQuoted 20 lines · Peter Maydell
Quoted 11 lines · Alistair Francis
Add GPIO functionality to the register API. This allows association and automatic connection of GPIOs to bits in registers. GPIO inputs will attach to handlers that automatically set read-only bits in registers. GPIO outputs will be updated to reflect their field value when their respective registers are written (or reset). Supports active low GPIOs.
This is particularly effective for implementing system level controllers, where heterogenous collections of control signals are placed is a SoC specific peripheral then propagated all over the system.
I still don't think this is a good idea. GPIOs are device-level, not register-level. Most devices don't really have very many GPIOs. It should be easy to wire up "change GPIO state based on new register value" from a register post-write hook. This API can't handle the absolute most common case, which is "GPIO state is based on a bit being set in (raw-state-register AND mask-register)."
Quoted 3 lines
Basically I don't think GPIOs belong in this API, and I don't think there's a good case that adding them makes a significant class of devices much easier to write.
Ok, I'm going to remove the GPIO part from this patch set (the last few patches).
Once this patchset is accepted I'll spin up a new series with the GPIOs and some better/more complex devices and we can go from there.
Thanks,
Alistair
Quoted 4 lines
thanks
-- PMM