From 334e951ec1bc648c721500ebe7692ae99b2f4114 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Sun, 25 Feb 2018 00:26:03 -0500 Subject: [PATCH] memory: Provide memory_region_init_rom() 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. Backports commit a1777f7f6462c66e1ee6e98f0d5c431bfe988aa5 from qemu --- qemu/aarch64.h | 1 + qemu/aarch64eb.h | 1 + qemu/arm.h | 1 + qemu/armeb.h | 1 + qemu/header_gen.py | 1 + qemu/include/exec/memory.h | 35 ++++++++++++++++++++++++++++++----- qemu/m68k.h | 1 + qemu/memory.c | 16 ++++++++++++++++ qemu/mips.h | 1 + qemu/mips64.h | 1 + qemu/mips64el.h | 1 + qemu/mipsel.h | 1 + qemu/powerpc.h | 1 + qemu/sparc.h | 1 + qemu/sparc64.h | 1 + qemu/x86_64.h | 1 + 16 files changed, 60 insertions(+), 5 deletions(-) diff --git a/qemu/aarch64.h b/qemu/aarch64.h index ebca033a..7443f9e3 100644 --- a/qemu/aarch64.h +++ b/qemu/aarch64.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_aarch64 #define memory_region_init_reservation memory_region_init_reservation_aarch64 #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_aarch64 +#define memory_region_init_rom memory_region_init_rom_aarch64 #define memory_region_is_logging memory_region_is_logging_aarch64 #define memory_region_is_mapped memory_region_is_mapped_aarch64 #define memory_region_is_skip_dump memory_region_is_skip_dump_aarch64 diff --git a/qemu/aarch64eb.h b/qemu/aarch64eb.h index 8ab939e1..97c911c1 100644 --- a/qemu/aarch64eb.h +++ b/qemu/aarch64eb.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_aarch64eb #define memory_region_init_reservation memory_region_init_reservation_aarch64eb #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_aarch64eb +#define memory_region_init_rom memory_region_init_rom_aarch64eb #define memory_region_is_logging memory_region_is_logging_aarch64eb #define memory_region_is_mapped memory_region_is_mapped_aarch64eb #define memory_region_is_skip_dump memory_region_is_skip_dump_aarch64eb diff --git a/qemu/arm.h b/qemu/arm.h index 996bb22d..0b0c2e40 100644 --- a/qemu/arm.h +++ b/qemu/arm.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_arm #define memory_region_init_reservation memory_region_init_reservation_arm #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_arm +#define memory_region_init_rom memory_region_init_rom_arm #define memory_region_is_logging memory_region_is_logging_arm #define memory_region_is_mapped memory_region_is_mapped_arm #define memory_region_is_skip_dump memory_region_is_skip_dump_arm diff --git a/qemu/armeb.h b/qemu/armeb.h index 5cc14f73..91280fe2 100644 --- a/qemu/armeb.h +++ b/qemu/armeb.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_armeb #define memory_region_init_reservation memory_region_init_reservation_armeb #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_armeb +#define memory_region_init_rom memory_region_init_rom_armeb #define memory_region_is_logging memory_region_is_logging_armeb #define memory_region_is_mapped memory_region_is_mapped_armeb #define memory_region_is_skip_dump memory_region_is_skip_dump_armeb diff --git a/qemu/header_gen.py b/qemu/header_gen.py index 0301bcf7..6b87d547 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -2105,6 +2105,7 @@ symbols = ( 'memory_region_init_ram_ptr', 'memory_region_init_reservation', 'memory_region_init_resizeable_ram', + 'memory_region_init_rom', 'memory_region_is_logging', 'memory_region_is_mapped', 'memory_region_is_skip_dump', diff --git a/qemu/include/exec/memory.h b/qemu/include/exec/memory.h index ebbca270..d9cdd06f 100644 --- a/qemu/include/exec/memory.h +++ b/qemu/include/exec/memory.h @@ -327,7 +327,8 @@ void memory_region_unref(MemoryRegion *mr); * @name: used for debugging; not visible to the user or ABI * @size: size of the region. */ -void memory_region_init_io(struct uc_struct *uc, MemoryRegion *mr, +void memory_region_init_io(struct uc_struct *uc, + MemoryRegion *mr, struct Object *owner, const MemoryRegionOps *ops, void *opaque, @@ -345,7 +346,8 @@ void memory_region_init_io(struct uc_struct *uc, MemoryRegion *mr, * @perms: permissions on the region (UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC). * @errp: pointer to Error*, to store an error if it happens. */ -void memory_region_init_ram(struct uc_struct *uc, MemoryRegion *mr, +void memory_region_init_ram(struct uc_struct *uc, + MemoryRegion *mr, struct Object *owner, const char *name, uint64_t size, @@ -363,7 +365,8 @@ void memory_region_init_ram(struct uc_struct *uc, MemoryRegion *mr, * @size: size of the region. * @ptr: memory to be mapped; must contain at least @size bytes. */ -void memory_region_init_ram_ptr(struct uc_struct *uc, MemoryRegion *mr, +void memory_region_init_ram_ptr(struct uc_struct *uc, + MemoryRegion *mr, struct Object *owner, const char *name, uint64_t size, @@ -381,13 +384,34 @@ void memory_region_init_ram_ptr(struct uc_struct *uc, MemoryRegion *mr, * @offset: start of the section in @orig to be referenced. * @size: size of the region. */ -void memory_region_init_alias(struct uc_struct *uc, MemoryRegion *mr, +void memory_region_init_alias(struct uc_struct *uc, + MemoryRegion *mr, struct Object *owner, const char *name, MemoryRegion *orig, hwaddr offset, 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(struct uc_struct *uc, + 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. @@ -402,7 +426,8 @@ void memory_region_init_alias(struct uc_struct *uc, MemoryRegion *mr, * @size: size of the region. * @errp: pointer to Error*, to store an error if it happens. */ -void memory_region_init_rom_device(MemoryRegion *mr, +void memory_region_init_rom_device(struct uc_struct *uc, + MemoryRegion *mr, struct Object *owner, const MemoryRegionOps *ops, void *opaque, diff --git a/qemu/m68k.h b/qemu/m68k.h index 14f78499..7bbedcf9 100644 --- a/qemu/m68k.h +++ b/qemu/m68k.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_m68k #define memory_region_init_reservation memory_region_init_reservation_m68k #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_m68k +#define memory_region_init_rom memory_region_init_rom_m68k #define memory_region_is_logging memory_region_is_logging_m68k #define memory_region_is_mapped memory_region_is_mapped_m68k #define memory_region_is_skip_dump memory_region_is_skip_dump_m68k diff --git a/qemu/memory.c b/qemu/memory.c index bc6950f0..88a8b84b 100644 --- a/qemu/memory.c +++ b/qemu/memory.c @@ -1196,6 +1196,22 @@ void memory_region_init_resizeable_ram(struct uc_struct *uc, mr->dirty_log_mask = tcg_enabled(uc) ? (1 << DIRTY_MEMORY_CODE) : 0; } +void memory_region_init_rom(struct uc_struct *uc, + MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + Error **errp) +{ + memory_region_init(uc, 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(uc) ? (1 << DIRTY_MEMORY_CODE) : 0; +} + void memory_region_set_skip_dump(MemoryRegion *mr) { mr->skip_dump = true; diff --git a/qemu/mips.h b/qemu/mips.h index 74705330..21dd1d64 100644 --- a/qemu/mips.h +++ b/qemu/mips.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_mips #define memory_region_init_reservation memory_region_init_reservation_mips #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_mips +#define memory_region_init_rom memory_region_init_rom_mips #define memory_region_is_logging memory_region_is_logging_mips #define memory_region_is_mapped memory_region_is_mapped_mips #define memory_region_is_skip_dump memory_region_is_skip_dump_mips diff --git a/qemu/mips64.h b/qemu/mips64.h index a8eff13a..aac5c011 100644 --- a/qemu/mips64.h +++ b/qemu/mips64.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_mips64 #define memory_region_init_reservation memory_region_init_reservation_mips64 #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_mips64 +#define memory_region_init_rom memory_region_init_rom_mips64 #define memory_region_is_logging memory_region_is_logging_mips64 #define memory_region_is_mapped memory_region_is_mapped_mips64 #define memory_region_is_skip_dump memory_region_is_skip_dump_mips64 diff --git a/qemu/mips64el.h b/qemu/mips64el.h index f08b3ee6..1b39f27c 100644 --- a/qemu/mips64el.h +++ b/qemu/mips64el.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_mips64el #define memory_region_init_reservation memory_region_init_reservation_mips64el #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_mips64el +#define memory_region_init_rom memory_region_init_rom_mips64el #define memory_region_is_logging memory_region_is_logging_mips64el #define memory_region_is_mapped memory_region_is_mapped_mips64el #define memory_region_is_skip_dump memory_region_is_skip_dump_mips64el diff --git a/qemu/mipsel.h b/qemu/mipsel.h index d03f081c..af732edb 100644 --- a/qemu/mipsel.h +++ b/qemu/mipsel.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_mipsel #define memory_region_init_reservation memory_region_init_reservation_mipsel #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_mipsel +#define memory_region_init_rom memory_region_init_rom_mipsel #define memory_region_is_logging memory_region_is_logging_mipsel #define memory_region_is_mapped memory_region_is_mapped_mipsel #define memory_region_is_skip_dump memory_region_is_skip_dump_mipsel diff --git a/qemu/powerpc.h b/qemu/powerpc.h index 7b12987f..61ae0093 100644 --- a/qemu/powerpc.h +++ b/qemu/powerpc.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_powerpc #define memory_region_init_reservation memory_region_init_reservation_powerpc #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_powerpc +#define memory_region_init_rom memory_region_init_rom_powerpc #define memory_region_is_logging memory_region_is_logging_powerpc #define memory_region_is_mapped memory_region_is_mapped_powerpc #define memory_region_is_skip_dump memory_region_is_skip_dump_powerpc diff --git a/qemu/sparc.h b/qemu/sparc.h index 0a9f4551..5bebe92c 100644 --- a/qemu/sparc.h +++ b/qemu/sparc.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_sparc #define memory_region_init_reservation memory_region_init_reservation_sparc #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_sparc +#define memory_region_init_rom memory_region_init_rom_sparc #define memory_region_is_logging memory_region_is_logging_sparc #define memory_region_is_mapped memory_region_is_mapped_sparc #define memory_region_is_skip_dump memory_region_is_skip_dump_sparc diff --git a/qemu/sparc64.h b/qemu/sparc64.h index df2136e2..4f4facf2 100644 --- a/qemu/sparc64.h +++ b/qemu/sparc64.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_sparc64 #define memory_region_init_reservation memory_region_init_reservation_sparc64 #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_sparc64 +#define memory_region_init_rom memory_region_init_rom_sparc64 #define memory_region_is_logging memory_region_is_logging_sparc64 #define memory_region_is_mapped memory_region_is_mapped_sparc64 #define memory_region_is_skip_dump memory_region_is_skip_dump_sparc64 diff --git a/qemu/x86_64.h b/qemu/x86_64.h index d8e61057..6af1d2da 100644 --- a/qemu/x86_64.h +++ b/qemu/x86_64.h @@ -2099,6 +2099,7 @@ #define memory_region_init_ram_ptr memory_region_init_ram_ptr_x86_64 #define memory_region_init_reservation memory_region_init_reservation_x86_64 #define memory_region_init_resizeable_ram memory_region_init_resizeable_ram_x86_64 +#define memory_region_init_rom memory_region_init_rom_x86_64 #define memory_region_is_logging memory_region_is_logging_x86_64 #define memory_region_is_mapped memory_region_is_mapped_x86_64 #define memory_region_is_skip_dump memory_region_is_skip_dump_x86_64