From: Jan Kiszka <jan.kiszka@xxxxxxxxxxx> Introduce a memory region type that can reserve I/O space. Such regions are useful for modeling I/O that is only handled outside of QEMU, i.e. in the context of an accelerator like KVM. Any access to such a region from QEMU is a bug and will be reported as such. Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx> --- memory.c | 35 +++++++++++++++++++++++++++++++++++ memory.h | 15 +++++++++++++++ 2 files changed, 50 insertions(+), 0 deletions(-) diff --git a/memory.c b/memory.c index dc5e35d..a40990c 100644 --- a/memory.c +++ b/memory.c @@ -1003,6 +1003,41 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->backend_registered = true; } +static uint64_t invalid_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + MemoryRegion *mr = opaque; + + fprintf(stderr, "Invalid read from memory region %s\n", mr->name); + abort(); +} + +static void invalid_write(void *opaque, target_phys_addr_t addr, uint64_t data, + unsigned size) +{ + MemoryRegion *mr = opaque; + + fprintf(stderr, "Invalid write to memory region %s\n", mr->name); + abort(); +} + +static const MemoryRegionOps reservation_ops = { + .read = invalid_read, + .write = invalid_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +void memory_region_init_reservation(MemoryRegion *mr, + const char *name, + uint64_t size) +{ + memory_region_init(mr, name, size); + mr->ops = &reservation_ops; + mr->opaque = mr; + mr->terminates = true; + mr->backend_registered = false; +} + void memory_region_destroy(MemoryRegion *mr) { assert(QTAILQ_EMPTY(&mr->subregions)); diff --git a/memory.h b/memory.h index d5b47da..4ff441f 100644 --- a/memory.h +++ b/memory.h @@ -242,6 +242,21 @@ void memory_region_init_rom_device(MemoryRegion *mr, uint64_t size); /** + * memory_region_init_reservation: Initialize a memory region that reserves + * I/O space. + * + * A reservation region primariy serves debugging purposes. It claims I/O + * space that is not supposed to be handled by QEMU itself. Any access via + * the memory API will cause an abort(). + * + * @mr: the #MemoryRegion to be initialized + * @name: used for debugging; not visible to the user or ABI + * @size: size of the region. + */ +void memory_region_init_reservation(MemoryRegion *mr, + const char *name, + uint64_t size); +/** * memory_region_destroy: Destroy a memory region and relaim all resources. * * @mr: the region to be destroyed. May not currently be a subregion -- 1.7.3.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html