gem5 v25.0.0.1
Loading...
Searching...
No Matches
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"
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
48namespace gem5
49{
50
51class 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 */
55namespace RiscvISA {
56
58{
59 public:
61 bool virt;
63 bool hlvx;
64 bool lr;
65
66 MemAccessInfo() = default;
70
71 bool
72 bypassTLB() const
73 {
74 return (force_virt || hlvx);
75 }
76};
77
83
84class Walker;
85
86class TLB : public BaseTLB
87{
89
90 protected:
91 size_t size;
93 TlbEntryTrie trie; // for quick access
94 EntryList freeList; // free entries
95 uint64_t lruSeq;
96
98
114
115 public:
118
119 public:
120 typedef RiscvTLBParams Params;
121 TLB(const Params &p);
122
124
125 void takeOverFrom(BaseTLB *old) override {}
126
135 TlbEntry *insert(Addr vpn, const TlbEntry &entry);
136 void flushAll() override;
137 void demapPage(Addr vaddr, uint64_t asn) override;
138
140 Addr vaddr, BaseMMU::Mode mode, PTESv39 pte,
141 Addr gvaddr = 0x0,
143
145 bool gpf = false, bool virt = false);
146
148 const Request::ArchFlagsType arch_flags);
149
150 // Checkpointing
151 void serialize(CheckpointOut &cp) const override;
152 void unserialize(CheckpointIn &cp) override;
153
165
168
170 ThreadContext *tc, BaseMMU::Mode mode) override;
172 BaseMMU::Translation *translation,
173 BaseMMU::Mode mode) override;
175 BaseMMU::Mode mode) override;
177 BaseMMU::Mode mode) const override;
178
179 Addr
181 {
188 ISA* isa = static_cast<ISA*>(tc->getIsaPtr());
189 if (isa->rvType() == RV32) {
190 return bits(vaddr, 31, 0);
191 }
192 return vaddr;
193 }
194
204 TlbEntry *lookup(Addr vpn, uint16_t asid, BaseMMU::Mode mode, bool hidden);
205
206 private:
207 uint64_t nextSeq() { return ++lruSeq; }
208
209 void evictLRU();
210 void remove(size_t idx);
211
212 Fault translate(const RequestPtr &req, ThreadContext *tc,
214 bool &delayed);
217 bool &delayed);
218};
219
220} // namespace RiscvISA
221} // namespace gem5
222
223#endif // __RISCV_MEMORY_HH__
BaseTLB(const BaseTLBParams &p)
Definition tlb.hh:61
Ports are used to interface objects to each other.
Definition port.hh:62
uint8_t ArchFlagsType
Definition request.hh:101
Based on the RISC-V ISA privileged specifications V1.11, there is no implementation guidelines on the...
RiscvType rvType() const
Definition isa.hh:185
MemAccessInfo(PrivilegeMode priv, bool virt, bool force_virt, bool hlvx, bool lr)
Definition tlb.hh:67
bool bypassTLB() const
Definition tlb.hh:72
This class helps to implement RISCV's physical memory protection (pmp) primitive.
Definition pmp.hh:58
void remove(size_t idx)
Definition tlb.cc:239
void translateTiming(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode) override
RiscvTLBParams Params
Definition tlb.hh:120
void unserialize(CheckpointIn &cp) override
Unserialize an object.
TLB(const Params &p)
Fault checkPermissions(ThreadContext *tc, MemAccessInfo mem_access, Addr vaddr, BaseMMU::Mode mode, PTESv39 pte, Addr gvaddr=0x0, XlateStage stage=XlateStage::FIRST_STAGE)
Definition tlb.cc:252
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) const override
Do post-translation physical address finalization.
Walker * walker
Definition tlb.hh:97
BasePMAChecker * pma
Definition tlb.hh:116
Addr hiddenTranslateWithTLB(Addr vaddr, uint16_t asid, Addr xmode, BaseMMU::Mode mode)
Definition tlb.cc:331
Port * getTableWalkerPort() override
Get the table walker port.
gem5::RiscvISA::TLB::TlbStats stats
TlbEntry * insert(Addr vpn, const TlbEntry &entry)
Insert an entry into the TLB.
Definition tlb.cc:153
Walker * getWalker()
uint64_t lruSeq
Definition tlb.hh:95
EntryList freeList
Definition tlb.hh:94
Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) override
std::list< TlbEntry * > EntryList
Definition tlb.hh:88
uint64_t nextSeq()
Definition tlb.hh:207
std::vector< TlbEntry > tlb
Definition tlb.hh:92
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) override
MemAccessInfo getMemAccessInfo(ThreadContext *tc, BaseMMU::Mode mode, const Request::ArchFlagsType arch_flags)
Definition tlb.cc:463
TlbEntryTrie trie
Definition tlb.hh:93
void flushAll() override
Remove all entries from the TLB.
TlbEntry * lookup(Addr vpn, uint16_t asid, BaseMMU::Mode mode, bool hidden)
Perform the tlb lookup.
Definition tlb.cc:116
Addr getValidAddr(Addr vaddr, ThreadContext *tc, BaseMMU::Mode mode)
Definition tlb.hh:180
Fault doTranslate(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode, bool &delayed)
Definition tlb.cc:340
Fault translate(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode, bool &delayed)
Definition tlb.cc:503
Fault createPagefault(Addr vaddr, BaseMMU::Mode mode, Addr gvaddr=0x0, bool gpf=false, bool virt=false)
Definition tlb.cc:309
void serialize(CheckpointOut &cp) const override
Serialize an object.
void demapPage(Addr vaddr, uint64_t asn) override
void takeOverFrom(BaseTLB *old) override
Take over from an old tlb context.
Definition tlb.hh:125
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual BaseISA * getIsaPtr() const =0
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition bitfield.hh:79
Bitfield< 0 > p
constexpr enums::RiscvType RV32
Definition pcstate.hh:56
Trie< Addr, TlbEntry > TlbEntryTrie
Definition pagetable.hh:92
Bitfield< 59, 44 > asid
Definition pagetable.hh:47
@ FIRST_STAGE
Definition tlb.hh:80
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
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:112
statistics::Scalar readHits
Definition tlb.hh:103
statistics::Formula misses
Definition tlb.hh:111
statistics::Formula hits
Definition tlb.hh:110
statistics::Scalar writeAccesses
Definition tlb.hh:108
TlbStats(statistics::Group *parent)
statistics::Scalar writeMisses
Definition tlb.hh:107
statistics::Scalar writeHits
Definition tlb.hh:106
statistics::Scalar readMisses
Definition tlb.hh:104
statistics::Scalar readAccesses
Definition tlb.hh:105

Generated on Sat Oct 18 2025 08:06:40 for gem5 by doxygen 1.14.0