KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Cache

Driver and API for managing the SH4's cache. More...

Files

file  cache.h
 Cache management functionality.
 

Macros

#define CPU_CACHE_BLOCK_SIZE   32
 SH4 cache block size.
 
#define dcache_wback_sq(ptr)   dcache_pref_block(ptr)
 Write-back Store Queue buffer to external memory.
 

Functions

void icache_flush_range (uintptr_t start, size_t count)
 Flush the instruction cache.
 
void dcache_inval_range (uintptr_t start, size_t count)
 Invalidate the data/operand cache.
 
void dcache_flush_range (uintptr_t start, size_t count)
 Flush the data/operand cache.
 
void dcache_flush_all (void)
 Flush all the data/operand cache.
 
void dcache_purge_range (uintptr_t start, size_t count)
 Purge the data/operand cache.
 
void dcache_purge_all (void)
 Purge all the data/operand cache.
 
void dcache_purge_all_with_buffer (uintptr_t start, size_t count)
 Purge all the data/operand cache with buffer.
 
static __always_inline void dcache_pref_block (const void *src)
 Prefetch one block to the data/operand cache.
 
static __always_inline void dcache_alloc_block (const void *src, uint32_t value)
 Allocate one block of the data/operand cache.
 

Detailed Description

Driver and API for managing the SH4's cache.

Macro Definition Documentation

◆ CPU_CACHE_BLOCK_SIZE

#define CPU_CACHE_BLOCK_SIZE   32

SH4 cache block size.

The size of a cache block.

◆ dcache_wback_sq

#define dcache_wback_sq (   ptr)    dcache_pref_block(ptr)

Write-back Store Queue buffer to external memory.

This function initiates write-back for one Store Queue.

Parameters
ptrThe SQ mapped address to write-back.

Function Documentation

◆ dcache_alloc_block()

static __always_inline void dcache_alloc_block ( const void *  src,
uint32_t  value 
)
static

Allocate one block of the data/operand cache.

This function allocate a block of the data/operand cache.

Parameters
srcThe physical address to allocate.
valueThe value written to first 4-byte.

◆ dcache_flush_all()

void dcache_flush_all ( void  )

Flush all the data/operand cache.

This function flushes all the data/operand cache, forcing a write- back on all of the cache blocks that are marked as dirty.

Note
dcache_flush_range() is faster than dcache_flush_all() if the count param is 66560 or less.

◆ dcache_flush_range()

void dcache_flush_range ( uintptr_t  start,
size_t  count 
)

Flush the data/operand cache.

This function flushes a range of the data/operand cache, forcing a write- back on all of the data in the specified range. This does not invalidate the cache in the process (meaning the blocks will still be in the cache, just not marked as dirty after this has completed). If you wish to invalidate the cache as well, call dcache_inval_range() after calling this function or use dcache_purge_range() instead of dcache_flush_range().

Parameters
startThe physical address to begin flushing at.
countThe number of bytes to flush.

◆ dcache_inval_range()

void dcache_inval_range ( uintptr_t  start,
size_t  count 
)

Invalidate the data/operand cache.

This function invalidates a range of the data/operand cache. If you care about the contents of the cache that have not been written back yet, use dcache_flush_range() before using this function.

Parameters
startThe physical address to begin invalidating at.
countThe number of bytes to invalidate.

◆ dcache_pref_block()

static __always_inline void dcache_pref_block ( const void *  src)
static

Prefetch one block to the data/operand cache.

This function prefetch a block of the data/operand cache.

Parameters
srcThe physical address to prefetch.

◆ dcache_purge_all()

void dcache_purge_all ( void  )

Purge all the data/operand cache.

This function flushes the entire data/operand cache, ensuring that all cache blocks marked as dirty are written back to memory and all cache entries are invalidated. It does not require an additional buffer and is preferred when memory resources are constrained.

Note
dcache_purge_range() is faster than dcache_purge_all() if the count param is 39936 or less.

◆ dcache_purge_all_with_buffer()

void dcache_purge_all_with_buffer ( uintptr_t  start,
size_t  count 
)

Purge all the data/operand cache with buffer.

This function performs a purge of all data/operand cache blocks by utilizing an external buffer to speed up the write-back and invalidation process. It is always faster than dcache_purge_all() and is recommended where maximum speed is required.

Note
While this function offers a superior purge rate, it does require the use of a temporary buffer. So use this function if you have an extra 8/16 kb of memory laying around that you can utilize for no other purpose than for this function.
Parameters
startThe physical address for temporary buffer (32-byte aligned)
countThe size of the temporary buffer, which can be either 8 KB or 16 KB, depending on cache configuration - 8 KB buffer with OCRAM enabled, otherwise 16 KB.

◆ dcache_purge_range()

void dcache_purge_range ( uintptr_t  start,
size_t  count 
)

Purge the data/operand cache.

This function flushes a range of the data/operand cache, forcing a write- back and then invalidates all of the data in the specified range.

Parameters
startThe physical address to begin purging at.
countThe number of bytes to purge.

◆ icache_flush_range()

void icache_flush_range ( uintptr_t  start,
size_t  count 
)

Flush the instruction cache.

This function flushes a range of the instruction cache.

Parameters
startThe physical address to begin flushing at.
countThe number of bytes to flush.