31static const char*
const s_tag =
"ra8_io_blockdev_cache";
58 for (uint32_t i = 0; i < st->
n_slots; ++i) {
93 for (uint32_t i = 0; i < st->
n_slots; ++i) {
137 (void)
memcpy(dst, &st->
data[(
size_t)hit * span], span);
149 (void)
memcpy(dst, &st->
data[(
size_t)v * span], span);
187 (void)
memcpy(&st->
data[(
size_t)idx * span], src, span);
226 for (uint32_t i = 0; i < count; ++i) {
266 for (uint32_t i = 0; i < count; ++i) {
304 const uint32_t end = lba + count;
305 for (uint32_t i = 0; i < st->
n_slots; ++i) {
421 state->
under = under;
423 state->
slots = slots;
454 for (uint32_t i = 0; i < n_slots; ++i) {
455 slots[i].
valid =
false;
485 uint32_t* out_misses)
488 if (out_hits !=
nullptr) {
489 *out_hits = state->
hits;
491 if (out_misses !=
nullptr) {
492 *out_misses = state->
misses;
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
ra8_io block-device fabric – one LBA vtable across every storage medium.
ra8_err_t ra8_io_blockdev_sync(const ra8_io_blockdev_t *bd)
Flush any backend write buffering to the medium.
ra8_err_t ra8_io_blockdev_read(const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count, uint8_t *buf)
Read count logical blocks starting at lba into buf.
struct ra8_io_blockdev_iface ra8_io_blockdev_iface_t
@ k_ra8_io_block_size_bytes
Bytes per logical block (the only size).
ra8_err_t ra8_io_blockdev_write(const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count, const uint8_t *buf)
Write count logical blocks from buf starting at lba.
ra8_err_t ra8_io_blockdev_get_caps(const ra8_io_blockdev_t *bd, ra8_io_blockdev_caps_t *out)
Report the bound backend's medium capabilities.
ra8_err_t ra8_io_blockdev_erase(const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count)
Erase count blocks starting at lba to the medium's erase value.
Backend implementation contract for the ra8_io block-device fabric.
static uint32_t internal_cache_find(const ra8_io_blockdev_cache_state_t *st, uint32_t lba)
Find the cache slot holding lba.
ra8_err_t ra8_io_blockdev_cache_init(ra8_io_blockdev_t *bd, ra8_io_blockdev_cache_state_t *state, const ra8_io_blockdev_t *under, uint8_t *data, ra8_io_blockdev_cache_slot_t *slots, uint32_t n_slots)
Bind a caching block device over an existing backend.
static uint32_t internal_cache_pick_victim(const ra8_io_blockdev_cache_state_t *st)
Pick a slot to (re)use: the first free slot, else least-recently-used.
static void internal_cache_reset_slots(ra8_io_blockdev_cache_slot_t *slots, uint32_t n_slots)
Reset a slot array to the empty (no sectors cached) state.
static ra8_err_t internal_cache_sync(void *ctx)
Cache vtable: flush the wrapped backend.
static ra8_err_t internal_cache_write_block(ra8_io_blockdev_cache_state_t *st, uint32_t lba, const uint8_t *src)
Write one block through to the backend and update the cache.
static ra8_err_t internal_cache_get_caps(const void *ctx, ra8_io_blockdev_caps_t *out)
Cache vtable: report the wrapped backend's capabilities.
static ra8_err_t internal_cache_erase(void *ctx, uint32_t lba, uint32_t count)
Cache vtable: erase through to the backend and drop stale slots.
static void internal_cache_state_init(ra8_io_blockdev_cache_state_t *state, const ra8_io_blockdev_t *under, uint8_t *data, ra8_io_blockdev_cache_slot_t *slots, uint32_t n_slots)
Populate the scalar fields of a fresh cache state.
ra8_err_t ra8_io_blockdev_cache_stats(const ra8_io_blockdev_cache_state_t *state, uint32_t *out_hits, uint32_t *out_misses)
Report the cache hit/miss counters.
static ra8_err_t internal_cache_read(void *ctx, uint32_t lba, uint32_t count, uint8_t *buf)
Cache vtable: read count blocks at lba into buf.
static ra8_err_t internal_cache_read_block(ra8_io_blockdev_cache_state_t *st, uint32_t lba, uint8_t *dst)
Read one block through the cache (hit) or fill it (miss).
static const ra8_io_blockdev_iface_t s_cache_iface
Caching block-device vtable.
static ra8_err_t internal_cache_write(void *ctx, uint32_t lba, uint32_t count, const uint8_t *buf)
Cache vtable: write count blocks from buf at lba.
ra8_io caching block device – an LRU sector cache over any backend.
Per-sector cache metadata (one caller-owned array entry per slot).
uint32_t lba
Cached logical block address (valid only if in use).
bool valid
true => this slot holds a cached sector.
uint32_t last_use
LRU stamp; larger == more recently used.
Caller-owned private state for a caching block device.
uint8_t * data
n_slots * 512 cache bytes.
uint32_t misses
Read cache misses so far.
const ra8_io_blockdev_t * under
Wrapped backend (private).
uint32_t clock
Monotonic LRU access counter.
uint32_t hits
Read cache hits so far.
uint32_t n_slots
Number of cached sectors.
ra8_io_blockdev_cache_slot_t * slots
n_slots metadata entries.
Static properties a backend reports about its medium.
Caller-allocated block-device handle binding a backend to its context.
const ra8_io_blockdev_iface_t * iface
Bound backend vtable (private).
void * ctx
Backend-private context (private).