提交 047be4ed 编写于 作者: S Stefan Hajnoczi 提交者: Peter Maydell

memory: add memory_region_flush_rom_device()

ROM devices go via MemoryRegionOps->write() callbacks for write
operations and do not dirty/invalidate that memory.  Device emulation
must be able to mark memory ranges that have been modified internally
(e.g. using memory_region_get_ram_ptr()).

Introduce the memory_region_flush_rom_device() API for this purpose.
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
Message-id: 20190123212234.32068-2-stefanha@redhat.com
Reviewed-by: NPeter Maydell <peter.maydell@linaro.org>
[PMM: fix block comment style]
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
上级 bf8d0969
...@@ -3162,6 +3162,19 @@ static void invalidate_and_set_dirty(MemoryRegion *mr, hwaddr addr, ...@@ -3162,6 +3162,19 @@ static void invalidate_and_set_dirty(MemoryRegion *mr, hwaddr addr,
cpu_physical_memory_set_dirty_range(addr, length, dirty_log_mask); cpu_physical_memory_set_dirty_range(addr, length, dirty_log_mask);
} }
void memory_region_flush_rom_device(MemoryRegion *mr, hwaddr addr, hwaddr size)
{
/*
* In principle this function would work on other memory region types too,
* but the ROM device use case is the only one where this operation is
* necessary. Other memory regions should use the
* address_space_read/write() APIs.
*/
assert(memory_region_is_romd(mr));
invalidate_and_set_dirty(mr, addr, size);
}
static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
{ {
unsigned access_size_max = mr->ops->valid.max_access_size; unsigned access_size_max = mr->ops->valid.max_access_size;
......
...@@ -1344,6 +1344,24 @@ bool memory_region_snapshot_get_dirty(MemoryRegion *mr, ...@@ -1344,6 +1344,24 @@ bool memory_region_snapshot_get_dirty(MemoryRegion *mr,
void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr, void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,
hwaddr size, unsigned client); hwaddr size, unsigned client);
/**
* memory_region_flush_rom_device: Mark a range of pages dirty and invalidate
* TBs (for self-modifying code).
*
* The MemoryRegionOps->write() callback of a ROM device must use this function
* to mark byte ranges that have been modified internally, such as by directly
* accessing the memory returned by memory_region_get_ram_ptr().
*
* This function marks the range dirty and invalidates TBs so that TCG can
* detect self-modifying code.
*
* @mr: the region being flushed.
* @addr: the start, relative to the start of the region, of the range being
* flushed.
* @size: the size, in bytes, of the range being flushed.
*/
void memory_region_flush_rom_device(MemoryRegion *mr, hwaddr addr, hwaddr size);
/** /**
* memory_region_set_readonly: Turn a memory region read-only (or read-write) * memory_region_set_readonly: Turn a memory region read-only (or read-write)
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册