SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Macros | Enumerations | Functions | Variables
cache.c File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <types.h>
#include <barrier.h>
#include <mmu.h>
#include <timer.h>
#include <csr.h>
#include <common.h>
#include <log.h>
#include <e907/sysmap.h>
Include dependency graph for cache.c:

Macros

#define L1_CACHE_BYTES   (32)
 Size of L1 cache line in bytes.
 

Enumerations

enum  sysmap_ret_code {
  SYSMAP_RET_OK = 0 , SYSMAP_RET_INVALID_MEM_ADDR = -100 , SYSMAP_RET_INVALID_MEM_LEN , SYSMAP_RET_INVALID_MEM_ATTR ,
  SYSMAP_RET_REGION_IS_FULL , SYSMAP_RET_REGION_NOT_ENOUGH
}
 

Functions

static uint32_t sysmap_region_get_upper_limit (uint32_t region_index)
 
static uint32_t sysmap_region_get_mem_attr (uint32_t region_index)
 
static void sysmap_region_set_upper_limit (uint32_t region_index, uint32_t upper_limit_addr)
 
static void sysmap_region_set_mem_attr (uint32_t region_index, uint32_t mem_attr)
 
static uint32_t get_mem_region_upper_limit (uint32_t region_index)
 
static uint32_t get_mem_region_start_addr (uint32_t region_index)
 
static uint32_t get_mem_region_end_addr (uint32_t region_index)
 
static uint32_t get_mem_region_len (uint32_t region_index)
 
static uint32_t get_mem_region_attr (uint32_t region_index)
 
static void set_mem_region_upper_limit (uint32_t region_index, uint32_t upper_limit_addr)
 
static void set_mem_region_attr (uint32_t region_index, uint32_t mem_attr)
 
static void sysmap_setup_mem_region (uint32_t region_index, uint32_t upper_limit_addr, uint32_t mem_attr)
 
static void setup_mem_region (uint32_t region_index, uint32_t start_addr, uint32_t len, uint32_t mem_attr)
 
int sysmap_add_mem_region (uint32_t start_addr, uint32_t len, uint32_t mem_attr)
 Adds a memory region to the system memory map.
 
void sysmap_dump_region_info (void)
 
void data_sync_barrier (void)
 Insert a data synchronization barrier.
 
void cache_init (void)
 Initialize the cache configuration.
 
void dcache_enable (void)
 Enable the data cache.
 
void icache_enable (void)
 Enable the instruction cache.
 
void mmu_enable (void)
 Enable the SV39 MMU with cache initialization.
 
void flush_dcache_range (uint64_t start, uint64_t end)
 Flush a range of the data cache.
 
void invalidate_dcache_range (uint64_t start, uint64_t end)
 Invalidate a range of the data cache.
 
void flush_dcache_all ()
 Flushes the entire data cache.
 
void invalidate_dcache_all ()
 Invalidates the entire data cache.
 

Variables

static uint32_t region_index = 0
 

Macro Definition Documentation

◆ L1_CACHE_BYTES

#define L1_CACHE_BYTES   (32)

Size of L1 cache line in bytes.

Enumeration Type Documentation

◆ sysmap_ret_code

Enumerator
SYSMAP_RET_OK 
SYSMAP_RET_INVALID_MEM_ADDR 
SYSMAP_RET_INVALID_MEM_LEN 
SYSMAP_RET_INVALID_MEM_ATTR 
SYSMAP_RET_REGION_IS_FULL 
SYSMAP_RET_REGION_NOT_ENOUGH 

Function Documentation

◆ cache_init()

void cache_init ( void  )

Initialize the cache configuration.

This function configures the cache settings by writing specific values to the control and status registers.

◆ data_sync_barrier()

void data_sync_barrier ( void  )

Insert a data synchronization barrier.

This function ensures that all previous instructions are completed before any subsequent instructions are executed, particularly useful for ensuring memory consistency.

◆ dcache_enable()

void dcache_enable ( void  )

Enable the data cache.

This function enables the data cache by writing to the machine cache control register.

◆ flush_dcache_all()

void flush_dcache_all ( )

Flushes the entire data cache.

This function flushes all data cache lines, ensuring that any modified or "dirty" cache lines are written back to the main memory. It ensures that the data in the cache is coherent with the memory.

◆ flush_dcache_range()

void flush_dcache_range ( uint64_t  start,
uint64_t  end 
)

Flush a range of the data cache.

This function flushes the data cache for a specified range, ensuring that any dirty cache lines are written back to memory.

Parameters
startThe starting address of the range to flush.
endThe ending address of the range to flush.

◆ get_mem_region_attr()

static uint32_t get_mem_region_attr ( uint32_t  region_index)
inlinestatic

◆ get_mem_region_end_addr()

static uint32_t get_mem_region_end_addr ( uint32_t  region_index)
inlinestatic

◆ get_mem_region_len()

static uint32_t get_mem_region_len ( uint32_t  region_index)
inlinestatic

◆ get_mem_region_start_addr()

static uint32_t get_mem_region_start_addr ( uint32_t  region_index)
inlinestatic

◆ get_mem_region_upper_limit()

static uint32_t get_mem_region_upper_limit ( uint32_t  region_index)
inlinestatic

◆ icache_enable()

void icache_enable ( void  )

Enable the instruction cache.

This function enables the instruction cache by setting the appropriate control bits in the machine cache control register.

◆ invalidate_dcache_all()

void invalidate_dcache_all ( )

Invalidates the entire data cache.

This function invalidates all data cache lines, ensuring that no stale or outdated data remains in the cache. This operation discards the cache contents and ensures that the next access will fetch fresh data from memory.

◆ invalidate_dcache_range()

void invalidate_dcache_range ( uint64_t  start,
uint64_t  end 
)

Invalidate a range of the data cache.

This function invalidates the data cache for a specified range, ensuring that no stale data remains in the cache for the given addresses.

Parameters
startThe starting address of the range to invalidate.
endThe ending address of the range to invalidate.

◆ mmu_enable()

void mmu_enable ( void  )

Enable the SV39 MMU with cache initialization.

This function initializes the cache and enables both data and instruction caches for the SV39 memory management unit.

◆ set_mem_region_attr()

static void set_mem_region_attr ( uint32_t  region_index,
uint32_t  mem_attr 
)
inlinestatic

◆ set_mem_region_upper_limit()

static void set_mem_region_upper_limit ( uint32_t  region_index,
uint32_t  upper_limit_addr 
)
inlinestatic

◆ setup_mem_region()

static void setup_mem_region ( uint32_t  region_index,
uint32_t  start_addr,
uint32_t  len,
uint32_t  mem_attr 
)
inlinestatic

◆ sysmap_add_mem_region()

int sysmap_add_mem_region ( uint32_t  start_addr,
uint32_t  len,
uint32_t  mem_attr 
)

Adds a memory region to the system memory map.

This function registers a new memory region with the given starting address, length, and memory attributes to the system's memory map. The region can be used for various purposes, such as memory allocation or defining regions for specific hardware access.

Parameters
start_addrStarting address of the memory region. This address should be aligned to the appropriate boundary for the memory type.
lenLength of the memory region in bytes. The length should be a positive value and should not exceed the system's available memory range.
mem_attrMemory attributes for the region (e.g., read/write, cacheable, non-cacheable, etc.). The exact attributes depend on the platform and memory type.
Returns
0 if the memory region was successfully added. A non-zero value if the addition failed (e.g., invalid address or conflicting region).
Note
This function assumes that the provided address and length are valid. Any conflicts with existing memory regions will result in failure.

◆ sysmap_dump_region_info()

void sysmap_dump_region_info ( void  )

◆ sysmap_region_get_mem_attr()

static uint32_t sysmap_region_get_mem_attr ( uint32_t  region_index)
inlinestatic

◆ sysmap_region_get_upper_limit()

static uint32_t sysmap_region_get_upper_limit ( uint32_t  region_index)
inlinestatic

◆ sysmap_region_set_mem_attr()

static void sysmap_region_set_mem_attr ( uint32_t  region_index,
uint32_t  mem_attr 
)
static

◆ sysmap_region_set_upper_limit()

static void sysmap_region_set_upper_limit ( uint32_t  region_index,
uint32_t  upper_limit_addr 
)
static

◆ sysmap_setup_mem_region()

static void sysmap_setup_mem_region ( uint32_t  region_index,
uint32_t  upper_limit_addr,
uint32_t  mem_attr 
)
inlinestatic

Variable Documentation

◆ region_index

uint32_t region_index = 0
static