]> Git Repo - qemu.git/blame - target/riscv/pmp.h
target/riscv: cpu: Add a config option for native debug
[qemu.git] / target / riscv / pmp.h
CommitLineData
65c5b75c
MC
1/*
2 * QEMU RISC-V PMP (Physical Memory Protection)
3 *
4 * Author: Daire McNamara, [email protected]
5 * Ivan Griffin, [email protected]
6 *
7 * This provides a RISC-V Physical Memory Protection interface
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2 or later, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
a8b991b5
MA
22#ifndef RISCV_PMP_H
23#define RISCV_PMP_H
65c5b75c 24
3cb1a410
PMD
25#include "cpu.h"
26
65c5b75c
MC
27typedef enum {
28 PMP_READ = 1 << 0,
29 PMP_WRITE = 1 << 1,
30 PMP_EXEC = 1 << 2,
31 PMP_LOCK = 1 << 7
32} pmp_priv_t;
33
34typedef enum {
35 PMP_AMATCH_OFF, /* Null (off) */
36 PMP_AMATCH_TOR, /* Top of Range */
37 PMP_AMATCH_NA4, /* Naturally aligned four-byte region */
38 PMP_AMATCH_NAPOT /* Naturally aligned power-of-two region */
39} pmp_am_t;
40
2582a95c
HW
41typedef enum {
42 MSECCFG_MML = 1 << 0,
43 MSECCFG_MMWP = 1 << 1,
44 MSECCFG_RLB = 1 << 2
45} mseccfg_field_t;
46
65c5b75c
MC
47typedef struct {
48 target_ulong addr_reg;
49 uint8_t cfg_reg;
50} pmp_entry_t;
51
52typedef struct {
53 target_ulong sa;
54 target_ulong ea;
55} pmp_addr_t;
56
57typedef struct {
58 pmp_entry_t pmp[MAX_RISCV_PMPS];
59 pmp_addr_t addr[MAX_RISCV_PMPS];
60 uint32_t num_rules;
61} pmp_table_t;
62
63void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index,
64 target_ulong val);
65target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index);
2582a95c
HW
66
67void mseccfg_csr_write(CPURISCVState *env, target_ulong val);
68target_ulong mseccfg_csr_read(CPURISCVState *env);
69
65c5b75c
MC
70void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
71 target_ulong val);
72target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index);
73bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
b297129a
JS
74 target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs,
75 target_ulong mode);
af3fc195
ZL
76bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
77 target_ulong *tlb_size);
24beb03e
YJ
78void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index);
79void pmp_update_rule_nums(CPURISCVState *env);
d102f19a 80uint32_t pmp_get_num_rules(CPURISCVState *env);
b297129a 81int pmp_priv_to_page_prot(pmp_priv_t pmp_priv);
65c5b75c 82
2582a95c
HW
83#define MSECCFG_MML_ISSET(env) get_field(env->mseccfg, MSECCFG_MML)
84#define MSECCFG_MMWP_ISSET(env) get_field(env->mseccfg, MSECCFG_MMWP)
85#define MSECCFG_RLB_ISSET(env) get_field(env->mseccfg, MSECCFG_RLB)
86
65c5b75c 87#endif
This page took 0.212802 seconds and 4 git commands to generate.