gem5  v22.1.0.0
tlb.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2005 The Regents of The University of Michigan
3  * Copyright (c) 2007 MIPS Technologies, Inc.
4  * Copyright (c) 2020 Barkhausen Institut
5  * Copyright (c) 2021 Huawei International
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met: redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer;
12  * redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution;
15  * neither the name of the copyright holders nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef __ARCH_RISCV_TLB_HH__
33 #define __ARCH_RISCV_TLB_HH__
34 
35 #include <list>
36 
37 #include "arch/generic/tlb.hh"
38 #include "arch/riscv/isa.hh"
39 #include "arch/riscv/pagetable.hh"
41 #include "arch/riscv/regs/misc.hh"
42 #include "arch/riscv/utility.hh"
43 #include "base/statistics.hh"
44 #include "mem/request.hh"
45 #include "params/RiscvTLB.hh"
46 #include "sim/sim_object.hh"
47 
48 namespace gem5
49 {
50 
51 class ThreadContext;
52 
53 /* To maintain compatibility with other architectures, we'll
54  simply create an ITLB and DTLB that will point to the real TLB */
55 namespace RiscvISA {
56 
57 class Walker;
58 
59 class TLB : public BaseTLB
60 {
62 
63  protected:
64  size_t size;
66  TlbEntryTrie trie; // for quick access
67  EntryList freeList; // free entries
68  uint64_t lruSeq;
69 
71 
72  struct TlbStats : public statistics::Group
73  {
75 
82 
86  } stats;
87 
88  public:
90  PMP *pmp;
91 
92  public:
93  typedef RiscvTLBParams Params;
94  TLB(const Params &p);
95 
97 
98  void takeOverFrom(BaseTLB *old) override {}
99 
100  TlbEntry *insert(Addr vpn, const TlbEntry &entry);
101  void flushAll() override;
102  void demapPage(Addr vaddr, uint64_t asn) override;
103 
105  BaseMMU::Mode mode, PTESv39 pte);
107 
109 
110  // Checkpointing
111  void serialize(CheckpointOut &cp) const override;
112  void unserialize(CheckpointIn &cp) override;
113 
125 
127 
129  ThreadContext *tc, BaseMMU::Mode mode) override;
131  BaseMMU::Translation *translation,
132  BaseMMU::Mode mode) override;
134  BaseMMU::Mode mode) override;
136  BaseMMU::Mode mode) const override;
137 
138  private:
139  uint64_t nextSeq() { return ++lruSeq; }
140 
141  TlbEntry *lookup(Addr vpn, uint16_t asid, BaseMMU::Mode mode, bool hidden);
142 
143  void evictLRU();
144  void remove(size_t idx);
145 
146  Fault translate(const RequestPtr &req, ThreadContext *tc,
148  bool &delayed);
149  Fault doTranslate(const RequestPtr &req, ThreadContext *tc,
151  bool &delayed);
152 };
153 
154 } // namespace RiscvISA
155 } // namespace gem5
156 
157 #endif // __RISCV_MEMORY_HH__
Based on the RISC-V ISA privileged specifications V1.11, there is no implementation guidelines on the...
Definition: pma_checker.hh:61
This class helps to implement RISCV's physical memory protection (pmp) primitive.
Definition: pmp.hh:54
Ports are used to interface objects to each other.
Definition: port.hh:62
void remove(size_t idx)
Definition: tlb.cc:210
void translateTiming(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode) override
RiscvTLBParams Params
Definition: tlb.hh:93
void unserialize(CheckpointIn &cp) override
Unserialize an object.
TLB(const Params &p)
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) const override
Do post-translation physical address finalization.
Walker * walker
Definition: tlb.hh:70
size_t size
Definition: tlb.hh:64
Fault createPagefault(Addr vaddr, BaseMMU::Mode mode)
Definition: tlb.cc:257
PMAChecker * pma
Definition: tlb.hh:89
Port * getTableWalkerPort() override
Get the table walker port.
gem5::RiscvISA::TLB::TlbStats stats
TlbEntry * insert(Addr vpn, const TlbEntry &entry)
Definition: tlb.cc:143
Walker * getWalker()
uint64_t lruSeq
Definition: tlb.hh:68
EntryList freeList
Definition: tlb.hh:67
Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) override
std::list< TlbEntry * > EntryList
Definition: tlb.hh:61
uint64_t nextSeq()
Definition: tlb.hh:139
std::vector< TlbEntry > tlb
Definition: tlb.hh:65
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) override
TlbEntryTrie trie
Definition: tlb.hh:66
PrivilegeMode getMemPriv(ThreadContext *tc, BaseMMU::Mode mode)
Definition: tlb.cc:326
void flushAll() override
Remove all entries from the TLB.
TlbEntry * lookup(Addr vpn, uint16_t asid, BaseMMU::Mode mode, bool hidden)
Definition: tlb.cc:109
Fault doTranslate(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode, bool &delayed)
Definition: tlb.cc:278
Fault translate(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode, bool &delayed)
Definition: tlb.cc:336
void serialize(CheckpointOut &cp) const override
Serialize an object.
Fault checkPermissions(STATUS status, PrivilegeMode pmode, Addr vaddr, BaseMMU::Mode mode, PTESv39 pte)
Definition: tlb.cc:223
void demapPage(Addr vaddr, uint64_t asn) override
Addr translateWithTLB(Addr vaddr, uint16_t asid, BaseMMU::Mode mode)
Definition: tlb.cc:270
void takeOverFrom(BaseTLB *old) override
Take over from an old tlb context.
Definition: tlb.hh:98
ThreadContext is the external interface to all thread state for anything outside of the CPU.
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
Statistics container.
Definition: group.hh:94
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
STL vector class.
Definition: stl.hh:37
Bitfield< 5, 0 > status
Definition: misc_types.hh:429
Bitfield< 0 > p
Bitfield< 59, 44 > asid
Definition: pagetable.hh:47
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
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Declaration of Statistics objects.
statistics::Formula accesses
Definition: tlb.hh:85
statistics::Scalar readHits
Definition: tlb.hh:76
statistics::Formula misses
Definition: tlb.hh:84
statistics::Formula hits
Definition: tlb.hh:83
statistics::Scalar writeAccesses
Definition: tlb.hh:81
TlbStats(statistics::Group *parent)
statistics::Scalar writeMisses
Definition: tlb.hh:80
statistics::Scalar writeHits
Definition: tlb.hh:79
statistics::Scalar readMisses
Definition: tlb.hh:77
statistics::Scalar readAccesses
Definition: tlb.hh:78

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