0.3.1
Cache

Data Structures

struct  cpu_cache_data_line
 Cache data line representing the data read from the cache. More...
 
struct  cpu_cache_data_way
 Cache data way. More...
 

Macros

#define CPU_CACHE   0x00000000UL
 Partition designated for using the cache.
 
#define CPU_CACHE_THROUGH   0x20000000UL
 Partition designated for bypassing the cache.
 
#define CPU_CACHE_PURGE   0x40000000UL
 Partition designated for purging a specific line.
 
#define CPU_CACHE_ADDRESS_RW   0x60000000UL
 Partition designated for accessing the address cache array directly.
 
#define CPU_CACHE_DATA_RW   0xC0000000UL
 Partition designated for accessing the cache data directly.
 
#define CPU_CACHE_IO   0xF0000000UL
 Partition designated for bypassing the cache (I/O area).
 
#define CPU_ADDRESS_PARTITION_MASK   0xF0000000UL
 Partition address mask.
 
#define CPU_CACHE_WAY_0_ADDR   0xC0000000UL
 Address for when accessing cache data directly.
 
#define CPU_CACHE_WAY_1_ADDR   0xC0000400UL
 Address for when accessing cache data directly.
 
#define CPU_CACHE_WAY_2_ADDR   0xC0000800UL
 Address for when accessing cache data directly.
 
#define CPU_CACHE_WAY_3_ADDR   0xC0000C00UL
 Address for when accessing cache data directly.
 
#define CPU_CACHE_WAY_SIZE   (CPU_CACHE_WAY_1_ADDR - CPU_CACHE_WAY_0_ADDR)
 The size in bytes of a cache way.
 
#define CPU_CACHE_2_WAY_SIZE   (CPU_CACHE_WAY_2_ADDR - CPU_CACHE_WAY_0_ADDR)
 The size in bytes of the 2KiB RAM.
 
#define CPU_CACHE_LINE_SIZE   16UL
 The size of a cache line in bytes.
 
#define CPU_CACHE_TAG_ADDRESS(x)   ((uint32_t)(x) >> 10)
 Given the tag bits from cpu_cache_data_line, convert to a physical address.
 
#define __uncached   __section(".uncached")
 Specify variable to be uncached.
 
#define __uncached_function   __section(".uncached.function")
 Specify function to be uncached.
 

Typedefs

typedef enum cpu_cache_mode cpu_cache_mode_t
 Cache mode.
 
typedef enum cpu_cache_type cpu_cache_type_t
 Cache type.
 
typedef struct cpu_cache_data_line cpu_cache_data_line_t
 Cache data line representing the data read from the cache.
 
typedef struct cpu_cache_data_way cpu_cache_data_way_t
 Cache data way.
 

Enumerations

enum  cpu_cache_mode
 Cache mode. More...
 
enum  cpu_cache_type
 Cache type. More...
 

Functions

static void cpu_cache_enable (void)
 Enable cache.
 
static void cpu_cache_disable (void)
 Disable cache.
 
static void cpu_cache_repl_enable (cpu_cache_type_t type)
 Enable type replacement.
 
static void cpu_cache_repl_disable (cpu_cache_type_t type)
 Disable type replacement in the cache.
 
static void cpu_cache_way_mode_set (cpu_cache_mode_t mode)
 Change the mode the cache operates.
 
void cpu_cache_line_purge (void *address) __uncached_function
 Cache line of the specified address is purged.
 
void cpu_cache_area_purge (void *address, uint32_t len) __uncached_function
 Cache lines of the specified address are purged.
 
void cpu_cache_purge (void) __no_reorder __uncached_function
 Purge the entire cache.
 
void cpu_cache_data_way_read (uint8_t way, cpu_cache_data_way_t *data_way) __uncached_function
 Walk one of the 4 ways the CPU cache and dump cache state bits.
 

Detailed Description

Description goes here.


Data Structure Documentation

◆ cpu_cache_data_line

struct cpu_cache_data_line

Cache data line representing the data read from the cache.

See also
cpu_cache_data_way_t
cpu_cache_data_way_read
Data Fields
unsigned int tag:19 Tag bits.
unsigned int lru:6 LRU bits.
unsigned int valid:1 Validity bit.

◆ cpu_cache_data_way

struct cpu_cache_data_way

Macro Definition Documentation

◆ CPU_CACHE_2_WAY_SIZE

#define CPU_CACHE_2_WAY_SIZE   (CPU_CACHE_WAY_2_ADDR - CPU_CACHE_WAY_0_ADDR)

The size in bytes of the 2KiB RAM.

See also
cpu_cache_way_mode_set

◆ CPU_CACHE_TAG_ADDRESS

#define CPU_CACHE_TAG_ADDRESS (   x)    ((uint32_t)(x) >> 10)

Given the tag bits from cpu_cache_data_line, convert to a physical address.

Parameters
xThe 32-bit address value.
See also
cpu_cache_data_line_t

Enumeration Type Documentation

◆ cpu_cache_mode

Cache mode.

Enumerator
CPU_CACHE_MODE_4_WAY 

Four-way set associative.

CPU_CACHE_MODE_2_WAY 

Two-way set associate and 2KiB RAM.

◆ cpu_cache_type

Cache type.

Enumerator
CPU_CACHE_TYPE_I 

Instruction cache type.

CPU_CACHE_TYPE_D 

Data cache type.

Function Documentation

◆ cpu_cache_repl_enable()

static void cpu_cache_repl_enable ( cpu_cache_type_t  type)
inlinestatic

Enable type replacement.

When either instruction and/or data is fetched from memory, the cache data is written.

Parameters
typeThe cache type(s) to enable.

◆ cpu_cache_repl_disable()

static void cpu_cache_repl_disable ( cpu_cache_type_t  type)
inlinestatic

Disable type replacement in the cache.

When either an instruction or data is fetched from memory, cache data is not written to the cache even if there is a cache miss.

Parameters
typeThe cache type(s) to disable.

◆ cpu_cache_way_mode_set()

static void cpu_cache_way_mode_set ( cpu_cache_mode_t  mode)
inlinestatic

Change the mode the cache operates.

The cache can be set to operate as a four-way set associative cache, or as a two-way associative cache and 2KiB RAM.

In the two-way mode, ways 0 and 1 are RAM.

Parameters
modeMode.

◆ cpu_cache_line_purge()

void cpu_cache_line_purge ( void *  address)

Cache line of the specified address is purged.

The starting address to purge does not to be cache-line aligned. Calling this function will not pollute the cache.

Parameters
addressThe address associated with cache line.

◆ cpu_cache_area_purge()

void cpu_cache_area_purge ( void *  address,
uint32_t  len 
)

Cache lines of the specified address are purged.

The starting address to purge does not to be cache-line aligned. The area to cache purge does not have to be in multiples of the cache line size. Calling this function will not pollute the cache.

Parameters
addressThe starting address.
lenThe area in bytes.

◆ cpu_cache_purge()

void cpu_cache_purge ( void  )

Purge the entire cache.

All cache entries and all valid bits and LRU bits of all ways are initialized to 0. Calling this function will not pollute the cache.

◆ cpu_cache_data_way_read()

void cpu_cache_data_way_read ( uint8_t  way,
cpu_cache_data_way_t data_way 
)

Walk one of the 4 ways the CPU cache and dump cache state bits.

It's imperative that the function that calls cpu_cache_data_way_read must be uncached so that it doesn't taint the cache itself.

Parameters
wayThe cache way to read from.
[in]data_wayThe cache way buffer to write to.