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
This commit is contained in:
Peter Maydell 2018-02-25 00:26:03 -05:00 committed by Lioncash
parent 7187d77cfa
commit 334e951ec1
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
16 changed files with 60 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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',

View file

@ -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,

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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