gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
tlb.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2013, 2016, 2019-2022, 2024-2025 Arm Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2001-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __ARCH_ARM_TLB_HH__
42#define __ARCH_ARM_TLB_HH__
43
44
45#include "arch/arm/faults.hh"
46#include "arch/arm/pagetable.hh"
47#include "arch/arm/utility.hh"
48#include "arch/generic/tlb.hh"
50#include "base/statistics.hh"
51#include "enums/TypeTLB.hh"
52#include "mem/request.hh"
53#include "sim/probe/pmu.hh"
54
55namespace gem5
56{
57
58struct ArmTLBParams;
59
60class ThreadContext;
61
62namespace ArmISA {
63
64class TableWalker;
65class TLB;
66class TLBIOp;
67
69{
70 public:
72 virtual ~TlbTestInterface() {}
73
82 virtual Fault translationCheck(const RequestPtr &req, bool is_priv,
84 DomainType domain) = 0;
85
97 virtual Fault walkCheck(const RequestPtr &walk_req,
98 Addr va, bool is_secure,
99 Addr is_priv, BaseMMU::Mode mode,
101 enums::ArmLookupLevel lookup_level) = 0;
102};
103
104class TLB : public BaseTLB
105{
106 protected:
107 class Table : public AssociativeCache<TlbEntry>
108 {
109 public:
112 TlbEntry* accessEntry(const KeyType &key) override;
113 TlbEntry* findEntry(const KeyType &key) const override;
114
124 void invalidatePrev(const TlbEntry *invalid=nullptr);
125
126 private:
128 mutable TlbEntry *prev = nullptr;
130
132 int size;
133
136
142 std::unordered_map<enums::ArmLookupLevel, bool> partialLevels;
143
148
150
176
180
181 int rangeMRU; //On lookup, only move entries ahead when outside rangeMRU
183
192 std::set<Addr> observedPageSizes;
193
194 public:
195 using Params = ArmTLBParams;
197 using LookupLevel = enums::ArmLookupLevel;
198
199 TLB(const Params &p);
200 TLB(const Params &p, int _size, TableWalker *_walker);
201
205 TlbEntry *lookup(Lookup lookup_data);
206
213 TlbEntry *multiLookup(const Lookup &lookup_data);
214
215 virtual ~TLB();
216
217 void takeOverFrom(BaseTLB *otlb) override;
218
219 void setTableWalker(TableWalker *table_walker);
220
222
223 int getsize() const { return size; }
224
225 bool walkCache() const { return _walkCache; }
226
227 void setVMID(vmid_t _vmid) { vmid = _vmid; }
228
230 void insert(const Lookup &lookup_data, TlbEntry &pte);
231
233 void multiInsert(const Lookup &lookup_data, TlbEntry &pte);
234
238 void flushAll() override;
239
240
243 void flush(const TLBIOp &tlbi_op);
244
245 void printTlb() const;
246
247 void demapPage(Addr vaddr, uint64_t asn) override
248 {
249 // needed for x86 only
250 panic("demapPage() is not implemented.\n");
251 }
252
253 Fault
255 BaseMMU::Mode mode) override
256 {
257 panic("unimplemented");
258 }
259
260 void
262 BaseMMU::Translation *translation,
263 BaseMMU::Mode mode) override
264 {
265 panic("unimplemented");
266 }
267
268 Fault
270 BaseMMU::Mode mode) const override
271 {
272 panic("unimplemented");
273 }
274
275 void regProbePoints() override;
276
287 Port *getTableWalkerPort() override;
288
289 // Caching misc register values here.
290 // Writing to misc registers needs to invalidate them.
291 // translateFunctional/translateSe/translateFs checks if they are
292 // invalid and call updateMiscReg if necessary.
293
294 private:
303 void _flushMva(Addr mva, uint64_t asn, bool secure_lookup,
304 bool ignore_asn, ExceptionLevel target_el,
305 bool in_host, TypeTLB entry_type);
306
313};
314
315} // namespace ArmISA
316} // namespace gem5
317
318#endif // __ARCH_ARM_TLB_HH__
TlbEntry * findEntry(const KeyType &key) const override
Definition tlb.cc:74
TlbEntry * accessEntry(const KeyType &key) override
Definition tlb.cc:62
TlbEntry * prev
Last matched entry.
Definition tlb.hh:128
void invalidatePrev(const TlbEntry *invalid=nullptr)
Invalidate the last matched entry The method has an optional param, which means: invalidate cached pr...
Definition tlb.cc:95
TableWalker * getTableWalker()
Definition tlb.hh:221
int size
TLB Size.
Definition tlb.hh:132
TLB(const Params &p, int _size, TableWalker *_walker)
TlbEntry::KeyType Lookup
Definition tlb.hh:196
void takeOverFrom(BaseTLB *otlb) override
Take over from an old tlb context.
Definition tlb.cc:330
bool walkCache() const
Definition tlb.hh:225
TableWalker * tableWalker
Definition tlb.hh:149
std::set< Addr > observedPageSizes
Set of observed page sizes in the TLB We update the set conservatively, therefore allowing false posi...
Definition tlb.hh:192
void setTableWalker(TableWalker *table_walker)
Definition tlb.cc:143
void setVMID(vmid_t _vmid)
Definition tlb.hh:227
TlbEntry * multiLookup(const Lookup &lookup_data)
Lookup an entry in the TLB and in the next levels by following the nextLevel pointer.
Definition tlb.cc:209
ArmTLBParams Params
Definition tlb.hh:195
void flush(const TLBIOp &tlbi_op)
Flush TLB entries.
Definition tlb.cc:309
int getsize() const
Definition tlb.hh:223
void regProbePoints() override
Register probe points for this object.
Definition tlb.cc:393
probing::PMUUPtr ppDataRefills
Definition tlb.hh:179
void printTlb() const
Definition tlb.cc:281
TLB(const Params &p)
Definition tlb.cc:101
virtual ~TLB()
Definition tlb.cc:138
Port * getTableWalkerPort() override
Get the table walker port.
Definition tlb.cc:403
bool _walkCache
True if the TLB caches partial translations.
Definition tlb.hh:147
void translateTiming(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode) override
Definition tlb.hh:261
gem5::ArmISA::TLB::Table table
std::unordered_map< enums::ArmLookupLevel, bool > partialLevels
Hash map containing one entry per lookup level The TLB is caching partial translations from the key l...
Definition tlb.hh:142
void _flushMva(Addr mva, uint64_t asn, bool secure_lookup, bool ignore_asn, ExceptionLevel target_el, bool in_host, TypeTLB entry_type)
Remove any entries that match both a va and asn.
probing::PMUUPtr ppInstRefills
PMU probe for TLB refills.
Definition tlb.hh:178
void insert(const Lookup &lookup_data, TlbEntry &pte)
Insert a PTE in the current TLB.
Definition tlb.cc:246
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) const override
Do post-translation physical address finalization.
Definition tlb.hh:269
vmid_t vmid
Definition tlb.hh:182
void checkPromotion(TlbEntry *entry, BaseMMU::Mode mode)
Check if the tlb entry passed as an argument needs to be "promoted" as a unified entry: this should h...
Definition tlb.cc:232
gem5::ArmISA::TLB::TlbStats stats
void demapPage(Addr vaddr, uint64_t asn) override
Definition tlb.hh:247
TlbEntry * lookup(Lookup lookup_data)
Lookup an entry in the TLB.
Definition tlb.cc:150
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) override
Definition tlb.hh:254
enums::ArmLookupLevel LookupLevel
Definition tlb.hh:197
bool isStage2
Indicates this TLB caches IPA->PA translations.
Definition tlb.hh:135
void flushAll() override
Reset the entire TLB.
Definition tlb.cc:291
void multiInsert(const Lookup &lookup_data, TlbEntry &pte)
Insert a PTE in the current TLB and in the higher levels.
Definition tlb.cc:267
virtual Fault translationCheck(const RequestPtr &req, bool is_priv, BaseMMU::Mode mode, DomainType domain)=0
Check if a TLB translation should be forced to fail.
virtual Fault walkCheck(const RequestPtr &walk_req, Addr va, bool is_secure, Addr is_priv, BaseMMU::Mode mode, DomainType domain, enums::ArmLookupLevel lookup_level)=0
Check if a page table walker access should be forced to fail.
BaseTLB(const BaseTLBParams &p)
Definition tlb.hh:61
Ports are used to interface objects to each other.
Definition port.hh:62
ThreadContext is the external interface to all thread state for anything outside of the CPU.
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Bitfield< 7, 4 > domain
uint16_t vmid_t
Definition types.hh:57
Bitfield< 8 > va
Bitfield< 0 > p
std::unique_ptr< PMU > PMUUPtr
Definition pmu.hh:60
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
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 writeAccesses
Definition tlb.hh:170
statistics::Formula hits
Definition tlb.hh:172
statistics::Scalar readHits
Definition tlb.hh:161
statistics::Scalar instHits
Definition tlb.hh:159
statistics::Scalar flushedEntries
Definition tlb.hh:167
statistics::Formula misses
Definition tlb.hh:173
statistics::Formula readAccesses
Definition tlb.hh:169
statistics::Formula accesses
Definition tlb.hh:174
statistics::Scalar inserts
Definition tlb.hh:165
statistics::Scalar flushTlb
Definition tlb.hh:166
TlbStats(TLB &parent)
Definition tlb.cc:334
statistics::Scalar readMisses
Definition tlb.hh:162
statistics::Scalar writeHits
Definition tlb.hh:163
statistics::Scalar writeMisses
Definition tlb.hh:164
statistics::Formula instAccesses
Definition tlb.hh:171
statistics::Scalar instMisses
Definition tlb.hh:160
statistics::Scalar partialHits
Definition tlb.hh:158
TLBTypes::KeyType KeyType
Definition pagetable.hh:238

Generated on Mon Oct 27 2025 04:12:58 for gem5 by doxygen 1.14.0