memory: Introduce memory region fetch operation
RFC PATCH 1/1 memory: Introduce memory region fetch operation
Allow the memory region to have different behaviors for read and fetch operations.
For example RISCV IOPMP will raise interrupt when cpu try to fetch a non-excutable region.
If fetch operation of a memory region is not implemented, it still uses the read operation for fetch.
--- accel/tcg/cputlb.c | 9 +++- include/exec/memory.h | 30 ++++++++++++ system/memory.c | 104 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 2 deletions(-)
accel/tcg/cputlb.c +7 -2
@@ -1942,8 +1942,13 @@ static uint64_t int_ld_mmio_beN(CPUState *cpu, CPUTLBEntryFull *full, this_size =1 << this_mop; this_mop |=MO_BE ; - r =memory_region_dispatch_read (mr, mr_offset, &val, - this_mop, full->attrs); +if (type ==MMU_INST_FETCH ) { + r =memory_region_dispatch_fetch (mr, mr_offset, &val, + this_mop, full->attrs); + }else { + r =memory_region_dispatch_read (mr, mr_offset, &val, + this_mop, full->attrs); + }if (unlikely (r !=MEMTX_OK )) {io_failed (cpu, full, addr, this_size, type, mmu_idx, r, ra); }
include/exec/memory.h +30 -0
@@ -274,6 +274,13 @@ struct MemoryRegionOps {uint64_t data, unsigned size); +/* Fetch to the memory region. @addr is relative to @mr; @size is +* in bytes. */ +uint64_t (*fetch)(void *opaque, +hwaddr addr, +unsigned size); + + MemTxResult (*read_with_attrs)(void *opaque, hwaddr addr, uint64_t *data,
@@ -284,6 +291,12 @@ struct MemoryRegionOps {uint64_t data, unsigned size, MemTxAttrs attrs); +MemTxResult (*fetch_with_attrs)(void *opaque, +hwaddr addr, +uint64_t *data, +unsigned size, +MemTxAttrs attrs); +enum device_endian endianness;/* Guest-visible constraints: */
@@ -2672,6 +2685,23 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,MemOp op, MemTxAttrs attrs); + +/** +* memory_region_dispatch_fetch: perform a fetch directly to the specified +* MemoryRegion. +* +* @mr: #MemoryRegion to access +* @addr: address within that region +* @pval: pointer to uint64_t which the data is written to +* @op: size, sign, and endianness of the memory operation +* @attrs: memory transaction attributes to use for the access +*/ +MemTxResult memory_region_dispatch_fetch (MemoryRegion *mr, +hwaddr addr, +uint64_t *pval, +MemOp op, +MemTxAttrs attrs); +/** * address_space_init: initializes an address space *
system/memory.c +104 -0
116 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 6 lines · Ethan Chen via
Allow the memory region to have different behaviors for read and fetch operations.
For example RISCV IOPMP will raise interrupt when cpu try to fetch a non-excutable region.
It actually raises an interrupt rather than it being a permissions fault?
Quoted 2 lines
If fetch operation of a memory region is not implemented, it still uses the read operation for fetch.
This patch should probably be part of the series with the device that needs it.
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 6 lines · Ethan Chen via
Allow the memory region to have different behaviors for read and fetch operations.
For example RISCV IOPMP will raise interrupt when cpu try to fetch a non-excutable region.
It actually raises an interrupt rather than it being a permissions fault?
Device can return bus error, interrupt or success with fabricated data.
Quoted 6 lines
Quoted 3 lines
If fetch operation of a memory region is not implemented, it still uses the read operation for fetch.
This patch should probably be part of the series with the device that needs it.
I will add this patch to IOPMP patch series.
Thanks,
Ethan