gem5  v22.1.0.0
pmp.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 The Regents of the University of California
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __ARCH_RISCV_PMP_HH__
30 #define __ARCH_RISCV_PMP_HH__
31 
32 #include "arch/generic/tlb.hh"
33 #include "arch/riscv/isa.hh"
34 #include "base/addr_range.hh"
35 #include "base/types.hh"
36 #include "mem/packet.hh"
37 #include "params/PMP.hh"
38 #include "sim/sim_object.hh"
39 
45 namespace gem5
46 {
47 
53 class PMP : public SimObject
54 {
55  public:
57  PMP(const Params &params);
58 
59  private:
62 
71  enum pmpAmatch
72  {
76  PMP_NAPOT
77  };
78 
80  const uint8_t PMP_READ = 1 << 0;
81 
83  const uint8_t PMP_WRITE = 1 << 1;
84 
86  const uint8_t PMP_EXEC = 1 << 2;
87 
89  const uint8_t PMP_LOCK = 1 << 7;
90 
92  int numRules;
93 
95  struct PmpEntry
96  {
102  uint8_t pmpCfg = 0;
103  };
104 
107 
108  public:
122  Addr vaddr = 0);
123 
131  void pmpUpdateCfg(uint32_t pmp_index, uint8_t this_cfg);
132 
140  void pmpUpdateAddr(uint32_t pmp_index, Addr this_addr);
141 
142  private:
154 
166 
173  void pmpUpdateRule(uint32_t pmp_index);
174 
181  inline uint8_t pmpGetAField(uint8_t cfg);
182 
191  inline AddrRange pmpDecodeNapot(Addr pmpaddr);
192 
193 };
194 
195 } // namespace gem5
196 
197 #endif // __ARCH_RISCV_PMP_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:82
This class helps to implement RISCV's physical memory protection (pmp) primitive.
Definition: pmp.hh:54
const uint8_t PMP_LOCK
pmpcfg address range locked mask
Definition: pmp.hh:89
const uint8_t PMP_WRITE
pmpcfg address range write permission mask
Definition: pmp.hh:83
int pmpEntries
maximum number of entries in the pmp table
Definition: pmp.hh:61
PMP(const Params &params)
Definition: pmp.cc:47
void pmpUpdateRule(uint32_t pmp_index)
pmpUpdateRule updates the pmp rule for a given pmp entry depending on the value of pmpaddr and pmpcfg...
Definition: pmp.cc:167
const uint8_t PMP_READ
pmpcfg address range read permission mask
Definition: pmp.hh:80
int numRules
variable to keep track of active number of rules any time
Definition: pmp.hh:92
AddrRange pmpDecodeNapot(Addr pmpaddr)
This function decodes a pmpaddr register value into an address range when A field of pmpcfg register ...
Definition: pmp.cc:254
pmpAmatch
This enum is used for encoding of address matching mode of pmp address register, which is present in ...
Definition: pmp.hh:72
@ PMP_TOR
Definition: pmp.hh:74
@ PMP_NA4
Definition: pmp.hh:75
@ PMP_OFF
Definition: pmp.hh:73
@ PMP_NAPOT
Definition: pmp.hh:76
std::vector< PmpEntry > pmpTable
a table of pmp entries
Definition: pmp.hh:106
void pmpUpdateAddr(uint32_t pmp_index, Addr this_addr)
pmpUpdateAddr updates the pmpaddr for a pmp entry and calls pmpUpdateRule to update the rule of corre...
Definition: pmp.cc:216
Fault createAddrfault(Addr vaddr, BaseMMU::Mode mode)
createAddrfault creates an address fault if the pmp checks fail to pass for a given access.
Definition: pmp.cc:130
void pmpUpdateCfg(uint32_t pmp_index, uint8_t this_cfg)
pmpUpdateCfg updates the pmpcfg for a pmp entry and calls pmpUpdateRule to update the rule of corresp...
Definition: pmp.cc:154
uint8_t pmpGetAField(uint8_t cfg)
pmpGetAField extracts the A field (address matching mode) from an input pmpcfg register
Definition: pmp.cc:145
const uint8_t PMP_EXEC
pmpcfg address range execute permission mask
Definition: pmp.hh:86
Fault pmpCheck(const RequestPtr &req, BaseMMU::Mode mode, RiscvISA::PrivilegeMode pmode, ThreadContext *tc, Addr vaddr=0)
pmpCheck checks if a particular memory access is allowed based on the pmp rules.
Definition: pmp.cc:56
bool shouldCheckPMP(RiscvISA::PrivilegeMode pmode, BaseMMU::Mode mode, ThreadContext *tc)
This function is called during a memory access to determine if the pmp table should be consulted for ...
Definition: pmp.cc:231
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
SimObjectParams Params
Definition: sim_object.hh:170
ThreadContext is the external interface to all thread state for anything outside of the CPU.
STL vector class.
Definition: stl.hh:37
const Params & params() const
Definition: sim_object.hh:176
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
Declaration of the Packet class.
single pmp entry struct
Definition: pmp.hh:96
Addr rawAddr
raw addr in pmpaddr register for a pmp entry
Definition: pmp.hh:100
AddrRange pmpAddr
addr range corresponding to a single pmp entry
Definition: pmp.hh:98
uint8_t pmpCfg
pmpcfg reg value for a pmp entry
Definition: pmp.hh:102

Generated on Wed Dec 21 2022 10:22:27 for gem5 by doxygen 1.9.1