Add these 2 wrappers to allow bindgen to generate the bindings based on MemoryRegionSection: * section_rust_write_continue_step() * section_rust_read_continue_step()
Then Rust side could be able to re-build a full write/read processes as address_space_write()/address_space_read_full() did. Signed-off-by: Zhao Liu <zhao1....@intel.com> --- include/system/memory.h | 51 +++++++++++++++++++++++++++++++++++++++++ system/physmem.c | 16 +++++++++++++ 2 files changed, 67 insertions(+) diff --git a/include/system/memory.h b/include/system/memory.h index 110ad0a3b590..a75c8c348f58 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -3413,6 +3413,57 @@ uint8_t *section_get_host_addr(const MemoryRegionSection *section, void section_fuzz_dma_read(MemoryRegionSection *section, hwaddr addr, hwaddr len); +/** + * section_rust_write_continue_step: write to #MemoryRegionSection. + * + * Not: This function should only used by Rust side, and user shouldn't + * call it directly! + * + * This function provides a wrapper of flatview_write_continue_step(), + * and allows Rust side to re-build a full write process as + * address_space_write() did. + * + * Should be called from an RCU critical section. + * + * @section: #MemoryRegionSection to be accessed. + * @attrs: memory transaction attributes. + * @buf: buffer with the data to be written. + * @len: the number of bytes to write. + * @mr_addr: address within that memory region. + * @l: the actual length of the data is written after function returns. + * + * Return a MemTxResult indicating whether the operation succeeded + * or failed (eg unassigned memory, device rejected the transaction, + * IOMMU fault). + */ +MemTxResult section_rust_write_continue_step(MemoryRegionSection *section, + MemTxAttrs attrs, const uint8_t *buf, hwaddr len, hwaddr mr_addr, hwaddr *l); + +/** + * section_read_continue_step: read from #MemoryRegionSection. + * + * Not: This function should only used by Rust side, and user shouldn't + * call it directly! + * + * This function provides a wrapper of flatview_read_continue_step(), + * and allows Rust side to re-build a full write process as + * address_space_read_full() did. + * + * Should be called from an RCU critical section. + * + * @section: #MemoryRegionSection to be accessed. + * @attrs: memory transaction attributes. + * @buf: buffer to be written. + * @len: the number of bytes is expected to read. + * @mr_addr: address within that memory region. + * @l: the actual length of the data is read after function returns. + * + * Return a MemTxResult indicating whether the operation succeeded + * or failed. + */ +MemTxResult section_read_continue_step(MemoryRegionSection *section, + MemTxAttrs attrs, uint8_t *buf, hwaddr len, hwaddr mr_addr, hwaddr *l); + /* * Inhibit technologies that require discarding of pages in RAM blocks, e.g., * to manage the actual amount of memory consumed by the VM (then, the memory diff --git a/system/physmem.c b/system/physmem.c index e06633f4d8a2..0c30dea775ca 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3119,6 +3119,14 @@ static MemTxResult flatview_read_continue_step(MemTxAttrs attrs, uint8_t *buf, } } +MemTxResult +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, @@ -3707,6 +3715,14 @@ static MemTxResult address_space_write_continue_cached(MemTxAttrs attrs, return result; } +MemTxResult +section_rust_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