Skip to content

Commit 7fd970a

Browse files
davidhildenbrandxzpeter
authored andcommitted
physmem: factor out direct access check into memory_region_supports_direct_access()
Let's factor the complete "directly accessible" check independent of the "write" condition out so we can reuse it next. We can now split up the checks RAM and ROMD check, so we really only check for RAM DEVICE in case of RAM -- ROM DEVICE is neither RAM not RAM DEVICE. Reviewed-by: Peter Xu <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Peter Xu <[email protected]>
1 parent e76d7b6 commit 7fd970a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

include/exec/memory.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,18 +2995,26 @@ MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache,
29952995
int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr);
29962996
bool prepare_mmio_access(MemoryRegion *mr);
29972997

2998-
static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
2998+
static inline bool memory_region_supports_direct_access(MemoryRegion *mr)
29992999
{
30003000
/* ROM DEVICE regions only allow direct access if in ROMD mode. */
3001-
if (!memory_region_is_ram(mr) && !memory_region_is_romd(mr)) {
3001+
if (memory_region_is_romd(mr)) {
3002+
return true;
3003+
}
3004+
if (!memory_region_is_ram(mr)) {
30023005
return false;
30033006
}
30043007
/*
30053008
* RAM DEVICE regions can be accessed directly using memcpy, but it might
30063009
* be MMIO and access using mempy can be wrong (e.g., using instructions not
30073010
* intended for MMIO access). So we treat this as IO.
30083011
*/
3009-
if (memory_region_is_ram_device(mr)) {
3012+
return !memory_region_is_ram_device(mr);
3013+
}
3014+
3015+
static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
3016+
{
3017+
if (!memory_region_supports_direct_access(mr)) {
30103018
return false;
30113019
}
30123020
if (is_write) {

0 commit comments

Comments
 (0)