|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Virtual-memory object sources – the page-cache storage seam (Layer 1, #147). More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_vsource_obj_t |
| One registered object's backing (paged or XIP). More... | |
| struct | ra8_vsource_t |
| Object-source registry (caller-owned; treat as private). More... | |
Typedefs | |
| typedef ra8_err_t(* | ra8_vsource_read_fn) (void *ctx, uint64_t offset, uint8_t *buf, uint32_t len) |
| Read len bytes at offset from a paged object's backing. | |
Functions | |
| ra8_err_t | ra8_vsource_init (ra8_vsource_t *vs, ra8_vsource_obj_t *objs, uint32_t cap) |
| Initialise an empty source registry over a caller-owned object array. | |
| ra8_err_t | ra8_vsource_add_paged (ra8_vsource_t *vs, ra8_vsource_read_fn read, void *ctx, uint64_t base, uint64_t size, uint32_t *out_id) |
| Register a storage-paged object; returns its object_id. | |
| ra8_err_t | ra8_vsource_add_xip (ra8_vsource_t *vs, const uint8_t *xip_base, uint64_t size, uint32_t *out_id) |
| Register an execute-in-place (memory-mapped) object; returns its id. | |
| ra8_err_t | ra8_vsource_loader (void *ctx, uint32_t object_id, uint64_t offset, uint8_t *frame, uint32_t frame_bytes) |
| Fill a page frame from an object – the ra8_vmem_loader_fn adapter. | |
| ra8_err_t | ra8_vsource_xip_ptr (const ra8_vsource_t *vs, uint32_t object_id, uint64_t offset, uint32_t len, const uint8_t **out_ptr) |
| Get a direct pointer into an XIP object (no copy, no cache). | |
Virtual-memory object sources – the page-cache storage seam (Layer 1, #147).
Layer 1 of the #147 memory hierarchy. ::ra8_vmem (Layer 2) pages objects in through a single loader callback keyed by an object_id; a source registry maps each object_id to its backing so one cache can serve many objects of two kinds:
ra8_vsource_loader is the ra8_vmem_loader_fn the cache calls on a miss: it looks up the object, bounds-checks the request, and fills the frame from the object's backing (read callback, or memcpy for an XIP object), zero-padding any tail beyond the object's end.
This source is read-only and byte-addressed, and lives at [Ring 2 / Core]. The ra8_io block-device fabric (ra8_io_blockdev.h, [Ring 4 / PAL]) is a separate storage seam: read/write/erase over 512-byte LBAs. The two are kept distinct on purpose – a read-only byte view for the page cache versus a read/write block fabric for filesystems – and the split is intentional, not drift. ::ra8_vsource must never depend on ra8_io_blockdev: that would make Ring 2 depend on Ring 4 and invert ring ordering (see docs/RING_AND_WORLD.md). The sanctioned bridge runs the other (allowed) way: the Ring-4 adapter ra8_io_blockdev_vsource.h exposes a block device as a ra8_vsource_read_fn, doing the LBA<->byte translation so apps can wire a block device straight into ra8_vsource_add_paged.
Zero allocation (NASA P10 Rule 3): the caller supplies the object array.
Definition in file ra8_vsource.h.
| typedef ra8_err_t(* ra8_vsource_read_fn) (void *ctx, uint64_t offset, uint8_t *buf, uint32_t len) |
Read len bytes at offset from a paged object's backing.
The storage seam: the app binds this to an ra8_io block device or an ra8_fs file so ::ra8_vsource stays storage-agnostic.
| [in] | ctx | Opaque backing context registered with the object. |
| [in] | offset | Absolute byte offset within the backing. |
| [out] | buf | Destination buffer (len writable bytes). |
| [in] | len | Number of bytes to read. |
Definition at line 79 of file ra8_vsource.h.
|
nodiscard |
Register a storage-paged object; returns its object_id.
| [in] | vs | Initialised registry. |
| [in] | read | Backing read callback. |
| [in] | ctx | Context for read. |
| [in] | base | Absolute base offset of the object within the backing. |
| [in] | size | Object length in bytes (> 0). |
| [out] | out_id | Receives the assigned object_id. |
| k_ra8_ok | Registered; *out_id set. |
| k_ra8_err_null_ptr | vs, read, or out_id was NULL. |
| k_ra8_err_invalid_size | size was zero. |
| k_ra8_err_no_mem | The registry is full. |
Definition at line 42 of file ra8_vsource.c.
References ra8_vsource_t::cap, ra8_vsource_t::count, k_ra8_err_invalid_size, k_ra8_err_no_mem, k_ra8_ok, ra8_vsource_t::objs, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by internal_cache_bind(), internal_cache_open(), internal_prepare(), mem_run_vmem(), and sh_paged_bind().
|
nodiscard |
Register an execute-in-place (memory-mapped) object; returns its id.
| [in] | vs | Initialised registry. |
| [in] | xip_base | Base pointer of the memory-mapped object. |
| [in] | size | Object length in bytes (> 0). |
| [out] | out_id | Receives the assigned object_id. |
| k_ra8_ok | Registered; *out_id set. |
| k_ra8_err_null_ptr | vs, xip_base, or out_id was NULL. |
| k_ra8_err_invalid_size | size was zero. |
| k_ra8_err_no_mem | The registry is full. |
Definition at line 66 of file ra8_vsource.c.
References ra8_vsource_t::cap, ra8_vsource_t::count, k_ra8_err_invalid_size, k_ra8_err_no_mem, k_ra8_ok, ra8_vsource_t::objs, RA8_CHECK_NULL_PTR, and s_tag.
|
nodiscard |
Initialise an empty source registry over a caller-owned object array.
| [out] | vs | Registry to populate (zero-initialised by the caller). |
| [in] | objs | Object slot array (out-lives the registry). |
| [in] | cap | Number of slots in objs (>= 1). |
| k_ra8_ok | Registry ready (empty). |
| k_ra8_err_null_ptr | vs or objs was NULL. |
| k_ra8_err_invalid_size | cap was zero. |
Definition at line 29 of file ra8_vsource.c.
References ra8_vsource_t::cap, ra8_vsource_t::count, k_ra8_err_invalid_size, k_ra8_ok, ra8_vsource_t::objs, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by internal_cache_bind(), internal_cache_open(), internal_prepare(), mem_run_vmem(), and sh_paged_bind().
|
nodiscard |
Fill a page frame from an object – the ra8_vmem_loader_fn adapter.
Looks up object_id, bounds-checks against the object size, and fills frame from the object's backing (paged read callback, or memcpy for an XIP object). Any tail beyond the object end is zeroed. The signature matches ra8_vmem_loader_fn, so pass vs as the cache's loader_ctx and this function as its loader.
| [in] | ctx | The ra8_vsource_t registry (as a void cookie). |
| [in] | object_id | Object to page in. |
| [in] | offset | Frame-aligned byte offset within the object. |
| [out] | frame | Destination frame (frame_bytes writable). |
| [in] | frame_bytes | Frame size in bytes. |
| k_ra8_ok | Frame filled (zero-padded past the object end). |
| k_ra8_err_null_ptr | ctx or frame was NULL. |
| k_ra8_err_out_of_range | object_id is not registered, or offset is at or beyond the object size. |
| k_ra8_err_* | The read callback's error (paged objects). |
Definition at line 84 of file ra8_vsource.c.
References ra8_vsource_obj_t::base, ra8_vsource_t::count, ra8_vsource_obj_t::ctx, k_ra8_err_out_of_range, k_ra8_ok, memcpy(), memset(), ra8_vsource_t::objs, RA8_CHECK_NULL_PTR, ra8_vsource_obj_t::read, s_tag, ra8_vsource_obj_t::size, and ra8_vsource_obj_t::xip.
Referenced by internal_cache_bind(), internal_cache_open(), internal_vmem_setup(), mem_run_vmem(), and sh_paged_bind().
|
nodiscard |
Get a direct pointer into an XIP object (no copy, no cache).
| [in] | vs | Initialised registry. |
| [in] | object_id | An XIP object id. |
| [in] | offset | Byte offset within the object. |
| [in] | len | Number of bytes the caller will read. |
| [out] | out_ptr | Receives the pointer to object[offset]. |
| k_ra8_ok | Pointer returned. |
| k_ra8_err_null_ptr | vs or out_ptr was NULL. |
| k_ra8_err_out_of_range | Unknown id, or offset + len exceeds the size. |
| k_ra8_err_not_supported | The object is paged, not XIP. |
Definition at line 110 of file ra8_vsource.c.
References ra8_vsource_t::count, k_ra8_err_not_supported, k_ra8_err_out_of_range, k_ra8_ok, ra8_vsource_t::objs, RA8_CHECK_NULL_PTR, s_tag, ra8_vsource_obj_t::size, and ra8_vsource_obj_t::xip.