From 3d5e79a44455cfff4315175701b0f1686e407fa1 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Thu, 2 Feb 2017 18:19:30 +0100 Subject: [PATCH 1/9] memory: Provide memory_region_init_rom() RH-Author: Laurent Vivier Message-id: <20170202181932.551-2-lvivier@redhat.com> Patchwork-id: 73518 O-Subject: [RHEV-7.3.z qemu-kvm-rhev PATCH 1/3] memory: Provide memory_region_init_rom() Bugzilla: 1420456 RH-Acked-by: David Gibson RH-Acked-by: Michael S. Tsirkin RH-Acked-by: Thomas Huth From: Peter Maydell Provide a new helper function memory_region_init_rom() for memory regions which are read-only (and unlike those created by memory_region_init_rom_device() don't have special behaviour for writes). This has the same behaviour as calling memory_region_init_ram() and then memory_region_set_readonly() (which is what we do today in boards with pure ROMs) but is a more easily discoverable API for the purpose. Signed-off-by: Peter Maydell Message-id: 1467122287-24974-2-git-send-email-peter.maydell@linaro.org (cherry picked from commit a1777f7f6462c66e1ee6e98f0d5c431bfe988aa5) Signed-off-by: Laurent Vivier BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1404673 Signed-off-by: Miroslav Rezanina --- docs/memory.txt | 9 +++++++-- include/exec/memory.h | 19 +++++++++++++++++++ memory.c | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/docs/memory.txt b/docs/memory.txt index 431d9ca..811b1bd 100644 --- a/docs/memory.txt +++ b/docs/memory.txt @@ -41,8 +41,13 @@ MemoryRegion): MemoryRegionOps structure describing the callbacks. - ROM: a ROM memory region works like RAM for reads (directly accessing - a region of host memory), but like MMIO for writes (invoking a callback). - You initialize these with memory_region_init_rom_device(). + a region of host memory), and forbids writes. You initialize these with + memory_region_init_rom(). + +- ROM device: a ROM device memory region works like RAM for reads + (directly accessing a region of host memory), but like MMIO for + writes (invoking a callback). You initialize these with + memory_region_init_rom_device(). - IOMMU region: an IOMMU region translates addresses of accesses made to it and forwards them to some other target memory region. As the name suggests, diff --git a/include/exec/memory.h b/include/exec/memory.h index 8f13f4d..42455fc 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -444,6 +444,25 @@ void memory_region_init_alias(MemoryRegion *mr, uint64_t size); /** + * memory_region_init_rom: Initialize a ROM memory region. + * + * This has the same effect as calling memory_region_init_ram() + * and then marking the resulting region read-only with + * memory_region_set_readonly(). + * + * @mr: the #MemoryRegion to be initialized. + * @owner: the object that tracks the region's reference count + * @name: the name of the region. + * @size: size of the region. + * @errp: pointer to Error*, to store an error if it happens. + */ +void memory_region_init_rom(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + Error **errp); + +/** * memory_region_init_rom_device: Initialize a ROM memory region. Writes are * handled via callbacks. * diff --git a/memory.c b/memory.c index 8f273a1..3b603e2 100644 --- a/memory.c +++ b/memory.c @@ -1387,6 +1387,21 @@ void memory_region_init_alias(MemoryRegion *mr, mr->alias_offset = offset; } +void memory_region_init_rom(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + Error **errp) +{ + memory_region_init(mr, owner, name, size); + mr->ram = true; + mr->readonly = true; + mr->terminates = true; + mr->destructor = memory_region_destructor_ram; + mr->ram_block = qemu_ram_alloc(size, mr, errp); + mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; +} + void memory_region_init_rom_device(MemoryRegion *mr, Object *owner, const MemoryRegionOps *ops, -- 1.8.3.1