Skip to content

Commit

Permalink
memory: Provide memory_region_init_rom()
Browse files Browse the repository at this point in the history
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 <peter.maydell@linaro.org>
Message-id: 1467122287-24974-2-git-send-email-peter.maydell@linaro.org
  • Loading branch information
pm215 committed Jul 4, 2016
1 parent f566641 commit a1777f7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docs/memory.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions include/exec/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,25 @@ void memory_region_init_alias(MemoryRegion *mr,
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(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.
Expand Down
15 changes: 15 additions & 0 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,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,
Expand Down

0 comments on commit a1777f7

Please sign in to comment.