hw/misc: Add support for interleaved memory accesses
cover hw/misc: Add support for interleaved memory accesses
This is a follow up on last year patch from Stephen Checkoway:
"block/pflash_cfi02: Implement intereleaved flash devices"
https://www.mail-archive.com/[email protected]/msg613077.html
Instead of making the PFLASH device more complex, I went implementing a generic interleaver device (that can be re-used for other MMIO devices, probably pointless, still useful for simple testing).
The series is available on [1] and is organized as:
1/ Fix a pair of issues in memory.c as we are not exercing much the memory_region_[read/write]_with_attrs_accessor functions (see also [2]).
2/ Allow to use qtest helpers with the 'none' machine (without any CPU).
3/ Add the interleaver device
4/ Add a device to test the interleaver device (later I'll expand it to other MMIO accesses, such access_with_adjusted_size, endianess and unaligned accesses). Let the 'none' machine create this device from command line.
5/ Add qtests using 4/ to test 3/.
6/ Add a way to display the interleaved memory (sub)regions in the HMP 'info mtree' command.
Based-on: <[email protected]>
[1] https://gitlab.com/philmd/qemu/-/tree/interleaved_device-v1
[2] https://www.mail-archive.com/[email protected]/msg730279.html
Philippe Mathieu-Daudé (9):
memory: Initialize MemoryRegionOps for RAM memory regions
qtest: Add local qtest_mem_as() getter
qtest: Directly use global address_space_memory when no CPU available hw/misc: Add interleaver device to make interleaved memory accesses hw/misc: Add MMIO test device
hw/core/null-machine: Allow to use the MMIO 'test' device tests/qtest: Add generic MMIO tests
memory: Allow memory region to display its subregions own descriptions hw/misc/interleaver: Display subregions in 'info mtree'
include/exec/memory.h | 6 + include/hw/misc/interleaver.h | 40 +++++ include/hw/misc/testdev.h | 15 ++ hw/core/null-machine.c | 2 + hw/misc/interleaver.c | 283 ++++++++++++++++++++++++++++++++++ hw/misc/mmio-testdev.c | 150 ++++++++++++++++++ softmmu/memory.c | 32 ++++ softmmu/qtest.c | 40 +++-- tests/qtest/mmio-test.c | 146 ++++++++++++++++++ MAINTAINERS | 9 ++ hw/misc/Kconfig | 9 ++ hw/misc/Makefile.objs | 2 + hw/misc/trace-events | 6 + tests/qtest/Makefile.include | 1 + 14 files changed, 728 insertions(+), 13 deletions(-) create mode 100644 include/hw/misc/interleaver.h create mode 100644 include/hw/misc/testdev.h create mode 100644 hw/misc/interleaver.c create mode 100644 hw/misc/mmio-testdev.c create mode 100644 tests/qtest/mmio-test.c
Signature · 1 line
2.26.2
RFC PATCH 1/9 memory: Initialize MemoryRegionOps for RAM memory regions
There is an issue when using memory_region_dispatch_read() or memory_region_dispatch_write() on RAM memory regions.
RAM memory regions are initialized as:
memory_region_init_ram()
-> memory_region_init_ram_nomigrate()
-> memory_region_init_ram_shared_nomigrate()
-> memory_region_init()
-> object_initialize(TYPE_MEMORY_REGION)
-> memory_region_initfn()
-> mr->ops = &unassigned_mem_ops;Later when accessing the alias, the memory_region_dispatch_read() flow is:
memory_region_dispatch_read()
-> memory_region_dispatch_read1()
-> if (mr->ops->read) { /* not taken */ } else ...
-> access_with_adjusted_size
-> memory_region_read_with_attrs_accessor
-> memory_region_dispatch_read
-> unassigned_mem_read
<- MEMTX_DECODE_ERRORThe caller gets a MEMTX_DECODE_ERROR while the access is OK. (Similar flow with memory_region_dispatch_write).
Fix by initializing the MemoryRegionOps to ram_device_mem_ops, this way the memory accesses are properly dispatched using memory_region_ram_device_read() / memory_region_ram_device_write().
---
Since v1: Corrected description (PJP)
Cc: P J P <[email protected]>
--- softmmu/memory.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
softmmu/memory.c +10 -0
@@ -1517,6 +1517,8 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr,Error *err =NULL ;memory_region_init (mr, owner, name, size); mr->ram = true; + mr->ops = &ram_device_mem_ops; + mr->opaque = mr; mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc (size, share, mr, &err);
@@ -1541,6 +1543,8 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,Error *err =NULL ;memory_region_init (mr, owner, name, size); mr->ram = true; + mr->ops = &ram_device_mem_ops; + mr->opaque = mr; mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_resizeable(size, max_size, resized,
@@ -1566,6 +1570,8 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,Error *err =NULL ;memory_region_init (mr, owner, name, size); mr->ram = true; + mr->ops = &ram_device_mem_ops; + mr->opaque = mr; mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->align = align;
@@ -1589,6 +1595,8 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,Error *err =NULL ;memory_region_init (mr, owner, name, size); mr->ram = true; + mr->ops = &ram_device_mem_ops; + mr->opaque = mr; mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
@@ -1611,6 +1619,8 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, {memory_region_init (mr, owner, name, size); mr->ram = true; + mr->ops = &ram_device_mem_ops; + mr->opaque = mr; mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;
Signature · 1 line
2.26.2
Re: [RFC PATCH 1/9] memory: Initialize MemoryRegionOps for RAM memory regions
+-- On Mon, 17 Aug 2020, Philippe Mathieu-Daudé wrote --+
| Fix by initializing the MemoryRegionOps to ram_device_mem_ops, this way the
| memory accesses are properly dispatched using
| memory_region_ram_device_read() / memory_region_ram_device_write().
|
| Fixes: 4a2e242bbb ("memory: Don't use memcpy for ram_device regions")
| Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
| ---
| Since v1: Corrected description (PJP)
| Cc: P J P <[email protected]>
| ---
| softmmu/memory.c | 10 ++++++++++
| 1 file changed, 10 insertions(+)
|
| diff --git a/softmmu/memory.c b/softmmu/memory.c
| index 651705b7d1..8139da1a58 100644
| --- a/softmmu/memory.c
| +++ b/softmmu/memory.c
| @@ -1517,6 +1517,8 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr,
| Error *err = NULL;
| memory_region_init(mr, owner, name, size);
| mr->ram = true;
| + mr->ops = &ram_device_mem_ops;
| + mr->opaque = mr;
| mr->terminates = true;I wonder if 'mr->ops = &ram_device_mem_ops' could be done in memory_region_init() instead?
Otherwise looks okay.
Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D
Re: [RFC PATCH 1/9] memory: Initialize MemoryRegionOps for RAM memory regions
Quoted 27 lines · P J P
+-- On Mon, 17 Aug 2020, Philippe Mathieu-Daudé wrote --+
| Fix by initializing the MemoryRegionOps to ram_device_mem_ops, this way the
| memory accesses are properly dispatched using
| memory_region_ram_device_read() / memory_region_ram_device_write().
|
| Fixes: 4a2e242bbb ("memory: Don't use memcpy for ram_device regions")
| Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
| ---
| Since v1: Corrected description (PJP)
| Cc: P J P <[email protected]>
| ---
| softmmu/memory.c | 10 ++++++++++
| 1 file changed, 10 insertions(+)
|
| diff --git a/softmmu/memory.c b/softmmu/memory.c
| index 651705b7d1..8139da1a58 100644
| --- a/softmmu/memory.c
| +++ b/softmmu/memory.c
| @@ -1517,6 +1517,8 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr,
| Error *err = NULL;
| memory_region_init(mr, owner, name, size);
| mr->ram = true;
| + mr->ops = &ram_device_mem_ops;
| + mr->opaque = mr;
| mr->terminates = true;Quoted 2 lines
I wonder if '
mr->ops=&ram_device_mem_ops' could be done inmemory_region_init()instead?
I don't think so, because to use &ram_device_mem_ops handlers use mr->opaque and mr->ram_block, so alias/io/iommu/rom types would directly crash accessing these NULL fields.
Quoted 2 lines
Otherwise looks okay.
Thanks!
Quoted 6 lines
Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D
RFC PATCH 2/9 qtest: Add local qtest_mem_as() getter
In reply to Philippe Mathieu-DaudéRefactor the access to the default address space introducing the qtest_mem_as() getter. This will help us to use another address space in the next commit.
--- softmmu/qtest.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
softmmu/qtest.c +19 -13
@@ -273,6 +273,12 @@ static void qtest_irq_handler(void *opaque, int n, int level) } } +/* Default address space for MMIO accesses */ +static AddressSpace *qtest_mem_as (void ) +{ +return first_cpu->as; +} +static void qtest_process_command (CharBackend *chr,gchar **words) {const gchar *command;
@@ -434,22 +440,22 @@ static void qtest_process_command(CharBackend *chr, gchar **words)if (words[0 ][5 ] =='b' ) {uint8_t data = value; -address_space_write (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_write (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , &data,1 ); }else if (words[0 ][5 ] =='w' ) {uint16_t data = value;tswap16s (&data); -address_space_write (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_write (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , &data,2 ); }else if (words[0 ][5 ] =='l' ) {uint32_t data = value;tswap32s (&data); -address_space_write (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_write (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , &data,4 ); }else if (words[0 ][5 ] =='q' ) {uint64_t data = value;tswap64s (&data); -address_space_write (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_write (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , &data,8 ); }qtest_send_prefix (chr);
@@ -468,21 +474,21 @@ static void qtest_process_command(CharBackend *chr, gchar **words)if (words[0 ][4 ] =='b' ) {uint8_t data; -address_space_read (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_read (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , &data,1 ); value = data; }else if (words[0 ][4 ] =='w' ) {uint16_t data; -address_space_read (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_read (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , &data,2 ); value =tswap16 (data); }else if (words[0 ][4 ] =='l' ) {uint32_t data; -address_space_read (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_read (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , &data,4 ); value =tswap32 (data); }else if (words[0 ][4 ] =='q' ) { -address_space_read (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_read (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , &value,8 );tswap64s (&value); }
@@ -503,7 +509,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)g_assert (len); data =g_malloc (len); -address_space_read (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , data, +address_space_read (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , data, len); enc =g_malloc (2 * len +1 );
@@ -529,7 +535,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)g_assert (ret ==0 ); data =g_malloc (len); -address_space_read (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , data, +address_space_read (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , data, len); b64_data =g_base64_encode (data, len);qtest_send_prefix (chr);
@@ -564,7 +570,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words) data[i] =0 ; } } -address_space_write (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , data, +address_space_write (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , data, len);g_free (data);
@@ -587,7 +593,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)if (len) { data =g_malloc (len);memset (data, pattern, len); -address_space_write (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , +address_space_write (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , data, len);g_free (data); }
@@ -621,7 +627,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words) out_len =MIN (out_len, len); } -address_space_write (first_cpu->as, addr,MEMTXATTRS_UNSPECIFIED , data, +address_space_write (qtest_mem_as (), addr,MEMTXATTRS_UNSPECIFIED , data, len);qtest_send_prefix (chr);
Signature · 1 line
2.26.2
RFC PATCH 3/9 qtest: Directly use global address_space_memory when no CPU available
In reply to Philippe Mathieu-DaudéCurrently all qtest MMIO access are dispatched via the first CPU available. This limitation doesn't allow use to use the 'none' machine to run tests. Unleash this limitation by selecting the global address_space_memory when no CPU is available.
--- softmmu/qtest.c | 8 ++++++++ 1 file changed, 8 insertions(+)
softmmu/qtest.c +8 -0
@@ -19,6 +19,7 @@#include "chardev/char-fe.h" #include "exec/ioport.h" #include "exec/memory.h" +#include "exec/address-spaces.h" #include "hw/irq.h" #include "sysemu/accel.h" #include "sysemu/cpus.h"
@@ -276,6 +277,13 @@ static void qtest_irq_handler(void *opaque, int n, int level)/* Default address space for MMIO accesses */ static AddressSpace *qtest_mem_as (void ) { +if (!first_cpu) { +/* +* The 'none' machine doesn't have any CPU, +* directly access the main address space. +*/ +return &address_space_memory; + }return first_cpu->as; }
Signature · 1 line
2.26.2
RFC PATCH 4/9 hw/misc: Add interleaver device to make interleaved memory accesses
In reply to Philippe Mathieu-DaudéSome slow devices might be arranged in an interleaved setup to reduce waiting for memory banks and improve memory throughput. Classical examples are NOR flashes.
Add an 'interleaver' device to allow making such interleaved memory accesses. This device support using the 16x8, 32x8, 32x16, 64x8, 64x16 and 64x32 configurations.
Example of 32x16 interleaver accesses (32-bit bus, 2x 16-bit banks):
Each interleaved 32-bit access on the bus results in contiguous 16-bit access on each banked device:
____________________________________________________
Bus accesses | 1st 32-bit | 2nd 32-bit |
-----------------------------------------------------
| | | |
v | v |
______________ | ______________ |
1st bank accesses | 1st 16-bit | | | 2nd 16-bit | |
-------------- | -------------- |
v v
______________ ______________
2nd bank accesses | 1st 16-bit | | 2nd 16-bit |
-------------- -----------------
How to simplify idx/addr initialization in the read/write handlers?
--- include/hw/misc/interleaver.h | 40 ++++++ hw/misc/interleaver.c | 254 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 6 + hw/misc/Kconfig | 4 + hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 6 + 6 files changed, 311 insertions(+) create mode 100644 include/hw/misc/interleaver.h create mode 100644 hw/misc/interleaver.c
include/hw/misc/interleaver.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* QEMU Interleaver device +* +* Copyright (C) 2020 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_MISC_INTERLEAVER_H +#define HW_MISC_INTERLEAVER_H + +/* +* Example of 32x16 interleaver accesses (32-bit bus, 2x 16-bit banks): +* +* Each interleaved 32-bit access on the bus results in contiguous 16-bit +* access on each banked device: +* +* ____________________________________________________ +* Bus accesses | 1st 32-bit | 2nd 32-bit | +* ----------------------------------------------------- +* | | | | +* v | v | +* ______________ | ______________ | +* 1st bank accesses | 1st 16-bit | | | 2nd 16-bit | | +* -------------- | -------------- | +* v v +* ______________ ______________ +* 2nd bank accesses | 1st 16-bit | | 2nd 16-bit | +* -------------- -------------- +*/ + +#define TYPE_INTERLEAVER_16X8_DEVICE "interleaver-16x8-device" +#define TYPE_INTERLEAVER_32X8_DEVICE "interleaver-32x8-device" +#define TYPE_INTERLEAVER_32X16_DEVICE "interleaver-32x16-device" +#define TYPE_INTERLEAVER_64X8_DEVICE "interleaver-64x8-device" +#define TYPE_INTERLEAVER_64X16_DEVICE "interleaver-64x16-device" +#define TYPE_INTERLEAVER_64X32_DEVICE "interleaver-64x32-device" + +#endif +
hw/misc/interleaver.c new file +254 -0
254 lines not on this page · raw message
MAINTAINERS +6 -0
@@ -1961,6 +1961,12 @@ S: Maintained F: include/hw/misc/empty_slot.h F: hw/misc/empty_slot.c +Interleaver device +M: Philippe Mathieu-Daudé <[email protected]> +S: Maintained +F: include/hw/misc/interleaver.h +F: hw/misc/interleaver.c + Standard VGA M: Gerd Hoffmann <[email protected]> S: Maintained
hw/misc/Kconfig +4 -0
@@ -21,6 +21,10 @@ config SGA bool depends on ISA_BUS +config INTERLEAVER + bool + default y + config ISA_TESTDEV bool default y if TEST_DEVICES
hw/misc/Makefile.objs +1 -0
@@ -12,6 +12,7 @@ common-obj-$(CONFIG_PCA9552) += pca9552.o common-obj-$(CONFIG_UNIMP) += unimp.o common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o common-obj-$(CONFIG_FW_CFG_DMA) += vmcoreinfo.o +common-obj-$(CONFIG_INTERLEAVER) += interleaver.o # ARM devices common-obj-$(CONFIG_PL310) += arm_l2x0.o
hw/misc/trace-events +6 -0
@@ -217,3 +217,9 @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6 # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u" + +# interleaver.c +interleaver_read_enter(unsigned input_access_size, unsigned output_access_size, unsigned size, unsigned mr_count, unsigned index, const char *mr_name, uint64_t in_addr, uint64_t out_addr) "rd ixs:%u oxs:%u sz:%u mr_cnt:%u mr_idx:%u mr_name:'%s' iadr:0x%"PRIx64" oadr:0x%"PRIx64 +interleaver_read_exit(unsigned size, uint64_t value, const char *result) "rd size:%u value:0x%08"PRIx64" result: %s" +interleaver_write_enter(unsigned input_access_size, unsigned output_access_size, unsigned size, unsigned mr_count, unsigned index, const char *mr_name, uint64_t in_addr, uint64_t out_addr) "wr ixs:%u oxs:%u sz:%u mr_cnt:%u mr_idx:%u mr_name:'%s' iadr:0x%"PRIx64" oadr:0x%"PRIx64 +interleaver_write_exit(unsigned size, uint64_t value, const char *result) "wr size:%u value:0x%08"PRIx64" result: %s"
Signature · 1 line
2.26.2
RFC PATCH 5/9 hw/misc: Add MMIO test device
In reply to Philippe Mathieu-DaudéAdd a MMIO test device handy to test QEMU internal devices via MMIO accesses.
This device is meant to be run by the 'none' machine, thus no CPU is required.
So far it is only useful to test the interleaver device. A SRAM region is split into 256B subregions, and these subregions are mapped at different addresses in an interleaved setup. All the following (INPUT x OUTPUT) configurations can be tested:
16x8, 32x8, 32x16, 64x8, 64x16 and 64x32.
--- include/hw/misc/testdev.h | 15 ++++ hw/misc/mmio-testdev.c | 146 ++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/misc/Kconfig | 5 ++ hw/misc/Makefile.objs | 1 + 5 files changed, 169 insertions(+) create mode 100644 include/hw/misc/testdev.h create mode 100644 hw/misc/mmio-testdev.c
include/hw/misc/testdev.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* QEMU MMIO test device +* +* Copyright (C) 2020 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_MISC_TESTDEV_H +#define HW_MISC_TESTDEV_H + +#define TYPE_MMIO_TESTDEV "mmio-testdev" + +#endif +
hw/misc/mmio-testdev.c new file +146 -0
146 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -1966,6 +1966,8 @@ M: Philippe Mathieu-Daudé <[email protected]> S: Maintained F: include/hw/misc/interleaver.h F: hw/misc/interleaver.c +F: hw/misc/mmio-testdev.c +F: include/hw/misc/testdev.h Standard VGA M: Gerd Hoffmann <[email protected]>
hw/misc/Kconfig +5 -0
@@ -30,6 +30,11 @@ config ISA_TESTDEV default y if TEST_DEVICES depends on ISA_BUS +config MMIO_TESTDEV + bool + default y if TEST_DEVICES + depends on INTERLEAVER + config PCI_TESTDEV bool default y if TEST_DEVICES
hw/misc/Makefile.objs +1 -0
@@ -5,6 +5,7 @@ common-obj-$(CONFIG_TMP421) += tmp421.o common-obj-$(CONFIG_ISA_DEBUG) += debugexit.o common-obj-$(CONFIG_SGA) += sga.o common-obj-$(CONFIG_ISA_TESTDEV) += pc-testdev.o +common-obj-$(CONFIG_MMIO_TESTDEV) += mmio-testdev.o common-obj-$(CONFIG_PCI_TESTDEV) += pci-testdev.o common-obj-$(CONFIG_EDU) += edu.o common-obj-$(CONFIG_PCA9552) += pca9552.o
Signature · 1 line
2.26.2
RFC PATCH 6/9 hw/core/null-machine: Allow to use the MMIO 'test' device
In reply to Philippe Mathieu-DaudéThe MMIO 'test' device (TYPE_MMIO_TESTDEV) can be mapped almost anywhere on the sysbus memory. Allow the 'none' machine to instantiate it from the command line, such:
$ qemu-system-sh4 -M none -monitor stdio \
-device mmio-testdev,address=0x00000000 -monitor stdio
(qemu) info mtree
address-space: memory
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-000000001fffffff (prio 0, i/o): testdev
0000000000000000-00000000000007ff (prio 0, ram): testdev-sram
0000000010000000-0000000017ffffff (prio 0, i/o): interleaver-container
0000000011608000-00000000116081ff (prio 0, i/o): interleaver-16x8
0000000013208000-00000000132083ff (prio 0, i/o): interleaver-32x8
0000000013216000-00000000132161ff (prio 0, i/o): interleaver-32x16
0000000016408000-00000000164087ff (prio 0, i/o): interleaver-64x8
0000000016416000-00000000164163ff (prio 0, i/o): interleaver-64x16
0000000016432000-00000000164321ff (prio 0, i/o): interleaver-64x32--- hw/core/null-machine.c | 2 ++ hw/misc/mmio-testdev.c | 4 ++++ 2 files changed, 6 insertions(+)
hw/core/null-machine.c +2 -0
@@ -17,6 +17,7 @@#include "sysemu/sysemu.h" #include "exec/address-spaces.h" #include "hw/core/cpu.h" +#include "hw/misc/testdev.h" static void machine_none_init (MachineState *mch) {
@@ -55,6 +56,7 @@ static void machine_none_machine_init(MachineClass *mc) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->no_sdcard =1 ; +machine_class_allow_dynamic_sysbus_dev (mc,TYPE_MMIO_TESTDEV ); }DEFINE_MACHINE ("none" , machine_none_machine_init)
hw/misc/mmio-testdev.c +4 -0
@@ -9,6 +9,10 @@/* * This device is mostly used to test QEMU internal MMIO devices. * Accesses using CPU core are not allowed. +* +* This device is meant to be used for testing, like: +* +* qemu-system-sh4 -M none -device mmio-testdev,address=0x10000000 */ #include "qemu/osdep.h"
Signature · 1 line
2.26.2
RFC PATCH 7/9 tests/qtest: Add generic MMIO tests
In reply to Philippe Mathieu-DaudéAdd generic MMIO tests (which don't need any particular knowledge about the architecture) and can be run without any CPU (using the 'none' machine).
Start testing the interleaved memory accesses.
Cross-endianess is not tested (host and target must have the same endianess).
--- tests/qtest/mmio-test.c | 146 +++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/Makefile.include | 1 + 3 files changed, 148 insertions(+) create mode 100644 tests/qtest/mmio-test.c
tests/qtest/mmio-test.c new file +146 -0
@@ -0,0 +1,146 @@ +/* +* QTest testcases for generic MMIO accesses +* +* Copyright (C) 2020 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" + +#include "libqtest.h" +#include "qemu/bswap.h" + +/* Must fit in arch address space */ +static const uint64_t base =0x20000000ul ; + +static bool is_cross_endian (QTestState *qts) +{ +bool te =qtest_big_endian (qts); +#ifdef HOST_WORDS_BIGENDIAN + te = !te; +#endif +return te; +} + +static QTestState *create_interleaver_qtest (void ) +{ +QTestState *qts; + + qts =qtest_initf ("-M none -device mmio-testdev,address=0x%" PRIx64, base); +if (is_cross_endian (qts)) { +g_test_skip ("Skipping on cross-endian targets" ); +qtest_quit (qts); +return NULL ; + } +return qts; +} + +static void test_interleaver_rd32x8a (void ) +{ +QTestState *qts =create_interleaver_qtest (); + +if (!qts) { +return ; + } + +/* write sram directly */ +qtest_writeb (qts, base +0x000 ,0x10 ); +qtest_writeb (qts, base +0x100 ,0x32 ); +qtest_writeb (qts, base +0x200 ,0x54 ); +qtest_writeb (qts, base +0x300 ,0x76 ); +/* read via interleaver */ + g_assert_cmphex(qtest_readl(qts, base + 0x13208000 + 0x00), ==, 0x76543210); +qtest_quit (qts); +} + +static void test_interleaver_rd32x8b (void ) +{ +QTestState *qts =create_interleaver_qtest (); + +if (!qts) { +return ; + } + +/* write sram directly */ +qtest_writeb (qts, base +0x003 ,0x10 ); +qtest_writeb (qts, base +0x103 ,0x32 ); +qtest_writeb (qts, base +0x203 ,0x54 ); +qtest_writeb (qts, base +0x303 ,0x76 ); +/* read via interleaver */ + g_assert_cmphex(qtest_readl(qts, base + 0x13208000 + 0x0c), ==, 0x76543210); +qtest_quit (qts); +} + +static void test_interleaver_rd32x16 (void ) +{ +QTestState *qts =create_interleaver_qtest (); + +if (!qts) { +return ; + } + +/* write sram directly */ +qtest_writew (qts, base +0x002 ,0x3210 ); +qtest_writew (qts, base +0x102 ,0x7654 ); +/* read via interleaver */ + g_assert_cmphex(qtest_readl(qts, base + 0x13216000 + 0x04), ==, 0x76543210); +qtest_quit (qts); +} + +static void test_interleaver_wr32x16 (void ) +{ +QTestState *qts =create_interleaver_qtest (); + +if (!qts) { +return ; + } + +/* write via interleaver */ +qtest_writel (qts, base +0x13216000 +0x04 ,0x76543210 ); +/* read sram directly */ + g_assert_cmphex(qtest_readw(qts, base + 0x002), ==, 0x3210); + g_assert_cmphex(qtest_readw(qts, base + 0x102), ==, 0x7654); +qtest_quit (qts); +} + +static void test_interleaver_wr64x8 (void ) +{ +QTestState *qts =create_interleaver_qtest (); + +if (!qts) { +return ; + } + +/* write via interleaver */ +qtest_writeq (qts, base +0x16408000 +0x08 ,0x9876543210 ); +/* read sram directly */ + g_assert_cmphex(qtest_readb(qts, base + 0x001), ==, 0x10); + g_assert_cmphex(qtest_readb(qts, base + 0x101), ==, 0x32); + g_assert_cmphex(qtest_readb(qts, base + 0x401), ==, 0x98); +qtest_quit (qts); +} + +static struct { +const char *name; +void (*test)(void ); +} tests[] = { + {"interleaver/rd32x8a" , test_interleaver_rd32x8a}, + {"interleaver/rd32x8b" , test_interleaver_rd32x8b}, + {"interleaver/rd32x16" , test_interleaver_rd32x16}, + {"interleaver/wr32x16" , test_interleaver_wr32x16}, + {"interleaver/wr64x8" , test_interleaver_wr64x8}, +}; + +int main (int argc,char **argv) +{ +g_test_init (&argc, &argv,NULL ); + +for (size_t i =0 ; i <ARRAY_SIZE (tests); i++) { + g_autofree gchar *path = g_strdup_printf("mmio/%s", + tests[i].name); +qtest_add_func (path, tests[i].test); + } + +return g_test_run (); +}
MAINTAINERS +1 -0
@@ -1968,6 +1968,7 @@ F: include/hw/misc/interleaver.h F: hw/misc/interleaver.c F: hw/misc/mmio-testdev.c F: include/hw/misc/testdev.h +F: tests/qtest/mmio-test.c Standard VGA M: Gerd Hoffmann <[email protected]>
tests/qtest/Makefile.include +1 -0
@@ -9,6 +9,7 @@ check-qtest-generic-y += qmp-cmd-test check-qtest-generic-y += qom-test check-qtest-generic-$(CONFIG_MODULES) += modules-test check-qtest-generic-y += test-hmp +check-qtest-generic-$(CONFIG_MMIO_TESTDEV) += mmio-test check-qtest-pci-$(CONFIG_RTL8139_PCI) += rtl8139-test check-qtest-pci-$(CONFIG_VGA) += display-vga-test
Signature · 1 line
2.26.2
RFC PATCH 8/9 memory: Allow memory region to display its subregions own descriptions
In reply to Philippe Mathieu-DaudéIf a MemoryRegion has subregion linked (but NOT mapped), these subregions won't be displayed in the 'info mtree' HMP command.
Add the possibility to display such subregion descriptions. It will result useful for the Interleaver memory device.
---
Any clever idea?
--- include/exec/memory.h | 6 ++++++ softmmu/memory.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+)
include/exec/memory.h +6 -0
@@ -404,6 +404,12 @@ struct MemoryRegion {const char *name;unsigned ioeventfd_nb;MemoryRegionIoeventfd *ioeventfds; +/* +* If a memory region has subregions linked, it can use this +* handler to return an array of string, each string holding +* the subregion description. +*/ +GStrv (*subregions_description)(const MemoryRegion *mr); };struct IOMMUMemoryRegion {
softmmu/memory.c +22 -0
@@ -2967,6 +2967,28 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level,mtree_print_mr_owner (mr); }qemu_printf ("\n" ); + +if (mr->subregions_description) { +GStrv s = mr->subregions_description (mr); +for (int j =0 ; s[j]; j++) { +for (i =0 ; i < level; i++) { +qemu_printf (MTREE_INDENT ); + } +qemu_printf (TARGET_FMT_plx"-" TARGET_FMT_plx +" (prio %d, %s%s): %s%s" , + cur_start, cur_end, + mr->priority, + mr->nonvolatile ?"nv-" :"" , +memory_region_type ((MemoryRegion *)mr), + s[j], + mr->enabled ?"" :" [disabled]" ); +if (owner) { +mtree_print_mr_owner (mr); + } +qemu_printf ("\n" ); + } +g_strfreev (s); + } } }
Signature · 1 line
2.26.2
RFC PATCH 9/9 hw/misc/interleaver: Display subregions in 'info mtree'
In reply to Philippe Mathieu-DaudéImplement the MemoryRegion::subregions_description() handler to be able to display the inverleaved memory regions:
$ qemu-system-sh4 -M none -monitor stdio \
-device mmio-testdev,address=0x00000000 -monitor stdio
address-space: memory
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-000000001fffffff (prio 0, i/o): testdev
0000000000000000-00000000000007ff (prio 0, ram): testdev-sram
0000000010000000-0000000017ffffff (prio 0, i/o): interleaver-container
0000000011608000-00000000116081ff (prio 0, i/o): interleaver-16x8
0000000011608000-00000000116081ff (prio 0, i/o): 8-bit access on 'sram-p0'
0000000011608000-00000000116081ff (prio 0, i/o): 8-bit access on 'sram-p1' (8-bit shifted)
0000000013208000-00000000132083ff (prio 0, i/o): interleaver-32x8
0000000013208000-00000000132083ff (prio 0, i/o): 8-bit access on 'sram-p0'
0000000013208000-00000000132083ff (prio 0, i/o): 8-bit access on 'sram-p1' (8-bit shifted)
0000000013208000-00000000132083ff (prio 0, i/o): 8-bit access on 'sram-p2' (16-bit shifted)
0000000013208000-00000000132083ff (prio 0, i/o): 8-bit access on 'sram-p3' (24-bit shifted)
0000000013216000-00000000132161ff (prio 0, i/o): interleaver-32x16
0000000013216000-00000000132161ff (prio 0, i/o): 16-bit access on 'sram-p0'
0000000013216000-00000000132161ff (prio 0, i/o): 16-bit access on 'sram-p1' (16-bit shifted)
0000000016408000-00000000164087ff (prio 0, i/o): interleaver-64x8
0000000016408000-00000000164087ff (prio 0, i/o): 8-bit access on 'sram-p0'
0000000016408000-00000000164087ff (prio 0, i/o): 8-bit access on 'sram-p1' (8-bit shifted)
0000000016408000-00000000164087ff (prio 0, i/o): 8-bit access on 'sram-p2' (16-bit shifted)
0000000016408000-00000000164087ff (prio 0, i/o): 8-bit access on 'sram-p3' (24-bit shifted)
0000000016408000-00000000164087ff (prio 0, i/o): 8-bit access on 'sram-p4' (32-bit shifted)
0000000016408000-00000000164087ff (prio 0, i/o): 8-bit access on 'sram-p5' (40-bit shifted)
0000000016408000-00000000164087ff (prio 0, i/o): 8-bit access on 'sram-p6' (48-bit shifted)
0000000016408000-00000000164087ff (prio 0, i/o): 8-bit access on 'sram-p7' (56-bit shifted)
0000000016416000-00000000164163ff (prio 0, i/o): interleaver-64x16
0000000016416000-00000000164163ff (prio 0, i/o): 16-bit access on 'sram-p0'
0000000016416000-00000000164163ff (prio 0, i/o): 16-bit access on 'sram-p1' (16-bit shifted)
0000000016416000-00000000164163ff (prio 0, i/o): 16-bit access on 'sram-p2' (32-bit shifted)
0000000016416000-00000000164163ff (prio 0, i/o): 16-bit access on 'sram-p3' (48-bit shifted)
0000000016432000-00000000164321ff (prio 0, i/o): interleaver-64x32
0000000016432000-00000000164321ff (prio 0, i/o): 32-bit access on 'sram-p0'
0000000016432000-00000000164321ff (prio 0, i/o): 32-bit access on 'sram-p1' (32-bit shifted)--- hw/misc/interleaver.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
hw/misc/interleaver.c +29 -0
@@ -112,6 +112,34 @@ static MemTxResult interleaver_write(void *opaque,return r; } +static GStrv interleaver_subregions_description (const MemoryRegion *mr) +{ +InterleaverDeviceState *s =container_of (mr, InterleaverDeviceState, iomem); +InterleaverDeviceClass *idc =INTERLEAVER_DEVICE_GET_CLASS (s); + gchar **descs = g_new(gchar *, idc->mr_count + 1); +unsigned output_access_bits = idc->output_access_size <<3 ; +size_t i; + +for (i =0 ; i < idc->mr_count; i++) { +if (i) { + descs[i] =g_strdup_printf (" %u-bit access on '%s'" +" (%zu-bit shifted)" , + output_access_bits, + s->mr[i] ?memory_region_name (s->mr[i]) + : emtpy_mr_name, + i * output_access_bits); + }else { + descs[i] =g_strdup_printf (" %u-bit access on '%s'" , + output_access_bits, + s->mr[i] ?memory_region_name (s->mr[i]) + : emtpy_mr_name); + } + } + descs[i] =NULL ; + +return descs; +} +static void interleaver_realize (DeviceState *dev,Error **errp) {InterleaverDeviceState *s =INTERLEAVER_DEVICE (dev);
@@ -139,6 +167,7 @@ static void interleaver_realize(DeviceState *dev, Error **errp) }memory_region_init_io (&s->iomem,OBJECT (s), &idc->ops, s, idc->name, s->size); + s->iomem.subregions_description = interleaver_subregions_description;sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->iomem); }
Signature · 1 line
2.26.2
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===
CC tests/qtest/e1000-test.o
CC tests/qtest/e1000e-test.o
CC tests/qtest/eepro100-test.o
/tmp/qemu-test/src/tests/qtest/mmio-test.c:9:24: fatal error: qemu/osdep.h: No such file or directory
#include "qemu/osdep.h"
^
compilation terminated.
CC tests/qtest/es1370-test.o
CC tests/qtest/ipoctal232-test.o
CC tests/qtest/megasas-test.omake: *** [tests/qtest/mmio-test] Error 1
make: *** Waiting for unfinished jobs....
CC test_abcz_f32.o
CC test_ab_f32_z_bool.o
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=84ffc0d808a34b62824e6e470c7b703a', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-4imsyimq/src/docker-src.2020-08-17-16.08.23.7359:/var/tmp/qemu:z,ro', 'qemu/centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=84ffc0d808a34b62824e6e470c7b703a
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-4imsyimq/src'
make: *** [docker-run-test-quick@centos7] Error 2
real 5m5.999s
user 0m6.598s
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 25 lines · Philippe Mathieu-Daudé
This is a follow up on last year patch from Stephen Checkoway:
"block/pflash_cfi02: Implement intereleaved flash devices"
https://www.mail-archive.com/[email protected]/msg613077.htmlInstead of making the PFLASH device more complex, I went implementing a generic interleaver device (that can be re-used for other MMIO devices, probably pointless, still useful for simple testing).
The series is available on [1] and is organized as:
1/ Fix a pair of issues in
memory.cas we are not exercing much the memory_region_[read/write]_with_attrs_accessor functions (see also [2]).2/ Allow to use qtest helpers with the 'none' machine (without any CPU).
3/ Add the interleaver device
4/ Add a device to test the interleaver device (later I'll expand it to other MMIO accesses, such
access_with_adjusted_size, endianess and unaligned accesses). Let the 'none' machine create this device from command line.
Quoted 8 lines
5/ Add qtests using 4/ to test 3/.
6/ Add a way to display the interleaved memory (sub)regions in the HMP 'info mtree' command.
Based-on: <[email protected]>
[1] https://gitlab.com/philmd/qemu/-/tree/interleaved_device-v1
[2] https://www.mail-archive.com/[email protected]/msg730279.html
I followed Paolo's suggestion to use qtest_memread/qtest_memwrite to avoid endianess swapping, and now cross-endianess works :)
Review still welcome, but I'll respin in September.
Regards,
Phil.
Quoted 25 lines · Philippe Mathieu-Daudé
This is a follow up on last year patch from Stephen Checkoway:
"block/pflash_cfi02: Implement intereleaved flash devices"
https://www.mail-archive.com/[email protected]/msg613077.htmlInstead of making the PFLASH device more complex, I went implementing a generic interleaver device (that can be re-used for other MMIO devices, probably pointless, still useful for simple testing).
The series is available on [1] and is organized as:
1/ Fix a pair of issues in
memory.cas we are not exercing much the memory_region_[read/write]_with_attrs_accessor functions (see also [2]).2/ Allow to use qtest helpers with the 'none' machine (without any CPU).
3/ Add the interleaver device
4/ Add a device to test the interleaver device (later I'll expand it to other MMIO accesses, such
access_with_adjusted_size, endianess and unaligned accesses). Let the 'none' machine create this device from command line.
Quoted 8 lines
5/ Add qtests using 4/ to test 3/.
6/ Add a way to display the interleaved memory (sub)regions in the HMP 'info mtree' command.
Based-on: <[email protected]>
[1] https://gitlab.com/philmd/qemu/-/tree/interleaved_device-v1
[2] https://www.mail-archive.com/[email protected]/msg730279.html
I followed Paolo's suggestion to use qtest_memread/qtest_memwrite to avoid endianess swapping, and now cross-endianess works :)
Review still welcome, but I'll respin in September.
Regards,
Phil.