pmp.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2023 Bennet Blischke <bennet.blischke@haw-hamburg.de>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
21 #include <assert.h>
22 #include <stdint.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
32 #define PMP_NONE 0x00
33 #define PMP_R 0x01
34 #define PMP_W 0x02
35 #define PMP_X 0x04
37 #define PMP_A 0x18
38 #define PMP_OFF 0x00
39 #define PMP_TOR 0x08
40 #define PMP_NA4 0x10
41 #define PMP_NAPOT 0x18
43 #define PMP_L 0x80
52 static inline uint32_t make_napot(uint32_t addr, uint32_t size)
53 {
54  assert(addr % size == 0);
55  return addr | ((size - 1) >> 1);
56 }
57 
64 void write_pmpcfg(uint8_t reg_num, uint32_t value);
65 
73 uint32_t read_pmpcfg(uint8_t reg_num);
74 
81 void write_pmpaddr(uint8_t reg_num, uint32_t value);
82 
90 uint32_t read_pmpaddr(uint8_t reg_num);
91 
99 uint8_t get_pmpcfg(uint8_t entry);
100 
107 void set_pmpcfg(uint8_t entry, uint8_t value);
108 
114 void print_pmpcfg(uint8_t entry);
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:146
uint32_t read_pmpaddr(uint8_t reg_num)
Read a complete pmpaddr register.
void set_pmpcfg(uint8_t entry, uint8_t value)
Set's a single pmpcfg sub-register.
void print_pmpcfg(uint8_t entry)
Prints a single pmpcfg sub-register human readable.
uint8_t get_pmpcfg(uint8_t entry)
Read a single pmpcfg sub-register.
void write_pmpcfg(uint8_t reg_num, uint32_t value)
Writes a complete pmpcfg register.
void write_pmpaddr(uint8_t reg_num, uint32_t value)
Writes a complete pmpaddr register.
uint32_t read_pmpcfg(uint8_t reg_num)
Read a complete pmpcfg register.
static uint32_t make_napot(uint32_t addr, uint32_t size)
Create a NAPOT formatted address.
Definition: pmp.h:52