[RFC v2 16/26] memory: Add wrappers for intermediate read/write steps
Zhao Liu <[email protected]> Wed, 8 Jul 2026 16:10:42 +0800
| Newsgroups | org.nongnu.qemu-rust,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
Add the following two wrappers to allow bindgen to generate bindings based on MemoryRegionSection: * rust_section_write_continue_step() * rust_section_read_continue_step() This allows the Rust side to reconstruct the full write/read process, similar to what address_space_write() and address_space_read_full() do. Signed-off-by: Zhao Liu <[email protected]> --- include/system/memory.h | 53 +++++++++++++++++++++++++++++++++++++++++ system/physmem.c | 16 +++++++++++++ 2 files changed, 69 insertions(+) diff --git a/include/system/memory.h b/include/system/memory.h index 18f269ac4dab..87006ce79d47 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -2917,6 +2917,59 @@ bool section_covers_region_addr(const MemoryRegionSection *section, void section_fuzz_dma_read(MemoryRegionSection *section, hwaddr addr, hwaddr len); +/** + * rust_section_write_continue_step: Write to a #MemoryRegionSection. + * + * Note: This function should only be used by the Rust side, and callers + * should not invoke it directly! + * + * This function provides a wrapper for flatview_write_continue_step(), + * and allows the Rust side to reconstruct the full write process, similar + * to what address_space_write() does. + * + * Must be called within an RCU critical section. + * + * @section: The #MemoryRegionSection to be accessed. + * @attrs: Memory transaction attributes. + * @buf: Buffer containing the data to be written. + * @len: The number of bytes to write. + * @mr_addr: The address within that memory region. + * @l: Pointer to the actual length. On return, this is updated to the + * number of bytes written. + * + * Returns: + * A MemTxResult indicating whether the operation succeeded or failed + * (e.g., unassigned memory, device rejected the transaction, IOMMU fault). + */ +MemTxResult rust_section_write_continue_step(MemoryRegionSection *section, + MemTxAttrs attrs, const uint8_t *buf, hwaddr len, hwaddr mr_addr, hwaddr *l); + +/** + * rust_section_read_continue_step: Read from a #MemoryRegionSection. + * + * Note: This function should only be used by the Rust side, and callers + * should not invoke it directly! + * + * This function provides a wrapper for flatview_read_continue_step(), + * and allows the Rust side to reconstruct the full read process, similar + * to what address_space_read_full() does. + * + * Must be called within an RCU critical section. + * + * @section: The #MemoryRegionSection to be accessed. + * @attrs: Memory transaction attributes. + * @buf: Buffer to store the read data. + * @len: The expected number of bytes to read. + * @mr_addr: The address within that memory region. + * @l: Pointer to the actual length. On return, this is updated to the + * number of bytes read. + * + * Returns: + * A MemTxResult indicating whether the operation succeeded or failed. + */ +MemTxResult rust_section_read_continue_step(MemoryRegionSection *section, + MemTxAttrs attrs, uint8_t *buf, hwaddr len, hwaddr mr_addr, hwaddr *l); + /* Coalesced MMIO regions are areas where write operations can be reordered. * This usually implies that write operations are side-effect free. This allows * batching which can make a major impact on performance when using diff --git a/system/physmem.c b/system/physmem.c index c227d4680e33..f19709be59e5 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3398,6 +3398,14 @@ static MemTxResult flatview_read_continue_step(MemTxAttrs attrs, uint8_t *buf, } } +MemTxResult +rust_section_read_continue_step(MemoryRegionSection *section, MemTxAttrs attrs, + uint8_t *buf, hwaddr len, hwaddr mr_addr, + hwaddr *l) +{ + return flatview_read_continue_step(attrs, buf, len, mr_addr, l, section->mr); +} + /* Called within RCU critical section. */ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, MemTxAttrs attrs, void *ptr, @@ -3987,6 +3995,14 @@ static MemTxResult address_space_write_continue_cached(MemTxAttrs attrs, return result; } +MemTxResult +rust_section_write_continue_step(MemoryRegionSection *section, MemTxAttrs attrs, + const uint8_t *buf, hwaddr len, hwaddr mr_addr, + hwaddr *l) +{ + return flatview_write_continue_step(attrs, buf, len, mr_addr, l, section->mr); +} + /* Called within RCU critical section. */ static MemTxResult address_space_read_continue_cached(MemTxAttrs attrs, void *ptr, hwaddr len, -- 2.34.1