gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
mmu.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2013, 2016, 2019-2024 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_MMU_HH__
42#define __ARCH_ARM_MMU_HH__
43
44#include "arch/arm/page_size.hh"
45#include "arch/arm/utility.hh"
46#include "arch/generic/mmu.hh"
47#include "base/memoizer.hh"
48#include "base/statistics.hh"
49#include "enums/ArmLookupLevel.hh"
50
51namespace gem5
52{
53
54struct ArmMMUParams;
55class ArmRelease;
56
57namespace ArmISA {
58
59class TableWalker;
60class TLB;
61struct TlbEntry;
62class TLBIOp;
64
65class MMU : public BaseMMU
66{
67 protected:
68 using LookupLevel = enums::ArmLookupLevel;
69
70 ArmISA::TLB * getDTBPtr() const;
71 ArmISA::TLB * getITBPtr() const;
72
73 TLB * getTlb(BaseMMU::Mode mode, bool stage2) const;
74 TableWalker * getTableWalker(BaseMMU::Mode mode, bool stage2) const;
75
76 protected:
79
84
85 public:
88 Mode mode, Request::Flags flags) override
89 {
91 PageBytes, start, size, tc, this, mode, flags));
92 }
93
95 {
97
98 AlignByte = 0x0,
104
106 // Priv code operating as if it wasn't
107 UserMode = 0x10
108 };
109
111 {
113 S1CTran = 0x1,
114 HypMode = 0x2,
115 // Secure code operating as if it wasn't (required by some Address
116 // Translate operations)
118 // Address translation instructions (eg AT S1E0R_Xt) need to be handled
119 // in special ways during translation because they could need to act
120 // like a different EL than the current EL. The following flags are
121 // for these instructions
122 S1E0Tran = 0x8,
123 S1E1Tran = 0x10,
124 S1E2Tran = 0x20,
125 S1E3Tran = 0x40,
126 S12E0Tran = 0x80,
127 S12E1Tran = 0x100
128 };
129
131 {
132 CachedState(MMU *_mmu, bool stage2)
133 : mmu(_mmu), isStage2(stage2),
135 {}
136
139 {
140 isStage2 = rhs.isStage2;
141 cpsr = rhs.cpsr;
142 aarch64 = rhs.aarch64;
145 sctlr = rhs.sctlr;
146 scr = rhs.scr;
147 isPriv = rhs.isPriv;
149 ttbcr = rhs.ttbcr;
150 tcr2 = rhs.tcr2;
151 pir = rhs.pir;
152 pire0 = rhs.pire0;
153 pie = rhs.pie;
154 asid = rhs.asid;
155 vmid = rhs.vmid;
156 prrr = rhs.prrr;
157 nmrr = rhs.nmrr;
158 hcr = rhs.hcr;
159 dacr = rhs.dacr;
162 stage2Req = rhs.stage2Req;
165
166 // When we copy we just flush the memoizer cache
167 computeAddrTop.flush();
168
169 return *this;
170 }
171
173
176 vmid_t getVMID(ThreadContext *tc) const;
177
179 bool isStage2 = false;
180 CPSR cpsr = 0;
181 bool aarch64 = false;
184 SCTLR sctlr = 0;
185 SCR scr = 0;
186 bool isPriv = false;
188 TTBCR ttbcr = 0;
189 TCR2 tcr2 = 0;
192 bool pie = false;
193 uint16_t asid = 0;
195 PRRR prrr = 0;
196 NMRR nmrr = 0;
197 HCR hcr = 0;
198 uint32_t dacr = 0;
199 bool miscRegValid = false;
201
202 // Indicates whether a stage 2 lookup is also required
203 bool stage2Req = false;
204
205 // Indicates whether a stage 2 lookup of the table descriptors is
206 // required. Certain address translation instructions will
207 // intercept the IPA but the table descriptors still need to be
208 // translated by the stage2.
209 bool stage2DescReq = false;
210
211 // Indicates whether all translation requests should
212 // be routed directly to the stage 2 TLB
213 bool directToStage2 = false;
214
215 Memoizer<int, ThreadContext*, bool,
217 };
218
219 MMU(const ArmMMUParams &p);
220
221 void init() override;
222
224
234
236 BaseMMU::Mode mode) override;
237
244
246 BaseMMU::Mode mode, ArmTranslationType tran_type, bool stage2);
247
248 Fault
250 ThreadContext *tc, Mode mode) override
251 {
252 return translateAtomic(req, tc, mode, NormalTran);
253 }
255 BaseMMU::Mode mode, ArmTranslationType tran_type, bool stage2);
257 ArmTranslationType tran_type);
258
259 void
261 Translation *translation, Mode mode) override
262 {
263 translateTiming(req, tc, translation, mode, NormalTran, false);
264 }
266 BaseMMU::Translation *translation, BaseMMU::Mode mode, bool stage2);
267 void translateTiming(
268 const RequestPtr &req, ThreadContext *tc,
269 Translation *translation, Mode mode,
270 ArmTranslationType tran_type, bool stage2);
271
273 ArmTranslationType tran_type, Addr vaddr, bool long_desc_format,
274 CachedState &state);
276 Translation *translation, bool &delay, bool timing, bool functional,
277 Addr vaddr, TranMethod tran_method,
278 CachedState &state);
279
281 Translation *translation, bool &delay,
282 bool timing, ArmTranslationType tran_type, bool functional,
283 CachedState &state);
285 Translation *translation, bool &delay, bool timing,
286 CachedState &state);
287
289
291 Translation *translation, Mode mode, ArmTranslationType tran_type,
292 bool call_from_s2);
294 Translation *translation, Mode mode, ArmTranslationType tran_type,
295 bool call_from_s2, CachedState &state);
297 const RequestPtr &req,
298 ThreadContext *tc, Mode mode) const override;
299
300 void drainResume() override;
301
302 void takeOverFrom(BaseMMU *old_mmu) override;
303
304 void invalidateMiscReg();
305
306 void flush(const TLBIOp &tlbi_op);
307 void flushStage1(const TLBIOp &tlbi_op);
308 void flushStage2(const TLBIOp &tlbi_op);
309 void iflush(const TLBIOp &tlbi_op);
310 void dflush(const TLBIOp &tlbi_op);
311
312 void flushAll() override;
313
314 uint64_t
315 getAttr() const
316 {
317 return _attr;
318 }
319
322 void
323 setAttr(uint64_t attr)
324 {
325 _attr = attr;
326 }
327
328 const ArmRelease* release() const { return _release; }
329
330 bool hasWalkCache() const { return _hasWalkCache; }
331
337 static ExceptionLevel tranTypeEL(CPSR cpsr, SCR scr, ArmTranslationType type);
338
339 static bool hasUnprivRegime(TranslationRegime regime);
340
341 public:
353 TlbEntry *lookup(Addr vpn, uint16_t asn, vmid_t vmid,
354 SecurityState ss, bool functional,
355 bool ignore_asn, TranslationRegime target_regime,
356 bool stage2, BaseMMU::Mode mode);
357
358 Fault getTE(TlbEntry **te, const RequestPtr &req,
360 Translation *translation, bool timing, bool functional,
361 SecurityState ss, PASpace ipaspace,
362 ArmTranslationType tran_type,
363 bool stage2);
364 Fault getTE(TlbEntry **te, const RequestPtr &req,
366 Translation *translation, bool timing, bool functional,
367 SecurityState ss, PASpace ipaspace,
368 ArmTranslationType tran_type,
369 CachedState &state);
370
371 Fault getResultTe(TlbEntry **te, const RequestPtr &req,
373 Translation *translation, bool timing,
374 bool functional, TlbEntry *mergeTe,
375 CachedState &state);
376
378 bool stage2);
380 CachedState &state);
382 ThreadContext *tc, bool stage2);
384 ThreadContext *tc, CachedState &state);
385
386 protected:
387 Addr purifyTaggedAddr(Addr vaddr_tainted, ThreadContext *tc,
389 TCR tcr, bool is_inst, CachedState& state);
390
392 TlbEntry *te, const RequestPtr &req, Mode mode,
393 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
394
395 std::tuple<bool, bool, bool> s1IndirectPermBits64(
396 TlbEntry *te, const RequestPtr &req, Mode mode,
397 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
398 std::tuple<bool, bool, bool> s1DirectPermBits64(
399 TlbEntry *te, const RequestPtr &req, Mode mode,
400 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
401
403 TlbEntry *te, const RequestPtr &req, Mode mode,
404 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
405
406 public: /* Testing */
408
410
412 DomainType domain, CachedState &state) const;
413
414 protected:
415 bool checkWalkCache() const;
416
417 bool isCompleteTranslation(TlbEntry *te) const;
418
420 ThreadContext *tc, ArmTranslationType tran_type,
421 bool stage2);
422
425 TlbEntry *te, CachedState &state) const;
426
427 protected:
429
430 public:
432
433 protected:
434 uint64_t _attr; // Memory attributes for last accessed TLB entry
435
436 // Cached copies of system-level properties
440
442
444
454
455};
456
457template<typename T>
458MMU *
460{
461 auto mmu = static_cast<MMU *>(tc->getMMUPtr());
462 assert(mmu);
463 return mmu;
464}
465
466} // namespace ArmISA
467} // namespace gem5
468
469#endif // __ARCH_ARM_MMU_HH__
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition addr_range.hh:82
Fault translateMmuOn(ThreadContext *tc, const RequestPtr &req, Mode mode, Translation *translation, bool &delay, bool timing, bool functional, Addr vaddr, TranMethod tran_method, CachedState &state)
Definition mmu.cc:1090
std::tuple< bool, bool, bool > s1IndirectPermBits64(TlbEntry *te, const RequestPtr &req, Mode mode, ThreadContext *tc, CachedState &state, bool r, bool w, bool x)
Definition mmu.cc:733
ArmISA::TLB * getITBPtr() const
Definition mmu.cc:145
void setAttr(uint64_t attr)
Accessor functions for memory attributes for last accessed TLB entry.
Definition mmu.hh:323
void flushStage2(const TLBIOp &tlbi_op)
Definition mmu.cc:243
static bool hasUnprivRegime(TranslationRegime regime)
Definition mmu.cc:990
Fault translateSe(const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool &delay, bool timing, CachedState &state)
Definition mmu.cc:333
void drainResume() override
Resume execution after a successful drain.
Definition mmu.cc:132
uint64_t _attr
Definition mmu.hh:434
ContextID miscRegContext
Definition mmu.hh:428
Fault translateComplete(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode, ArmTranslationType tran_type, bool call_from_s2)
Definition mmu.cc:1311
TLB * getTlb(BaseMMU::Mode mode, bool stage2) const
Definition mmu.cc:151
Fault translateMmuOff(ThreadContext *tc, const RequestPtr &req, Mode mode, ArmTranslationType tran_type, Addr vaddr, bool long_desc_format, CachedState &state)
Definition mmu.cc:1015
Fault testTranslation(const RequestPtr &req, Mode mode, DomainType domain, CachedState &state) const
Definition mmu.cc:1820
TLB * dtbStage2
Definition mmu.hh:78
void init() override
Called at init time, this method is traversing the TLB hierarchy and pupulating the instruction/data/...
Definition mmu.cc:94
void translateTiming(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode, bool stage2)
CachedState & updateMiscReg(ThreadContext *tc, ArmTranslationType tran_type, bool stage2)
Definition mmu.cc:1381
bool isCompleteTranslation(TlbEntry *te) const
Definition mmu.cc:1784
void invalidateMiscReg()
Definition mmu.cc:209
bool haveLargeAsid64
Definition mmu.hh:438
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, Mode mode) const override
Definition mmu.cc:303
bool _hasWalkCache
Definition mmu.hh:443
std::pair< bool, bool > s1PermBits64(TlbEntry *te, const RequestPtr &req, Mode mode, ThreadContext *tc, CachedState &state, bool r, bool w, bool x)
Definition mmu.cc:960
Fault getResultTe(TlbEntry **te, const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool timing, bool functional, TlbEntry *mergeTe, CachedState &state)
Definition mmu.cc:1705
void flushStage1(const TLBIOp &tlbi_op)
Definition mmu.cc:229
static ExceptionLevel tranTypeEL(CPSR cpsr, SCR scr, ArmTranslationType type)
Determine the EL to use for the purpose of a translation given a specific translation type.
Definition mmu.cc:1582
std::tuple< bool, bool, bool > s1DirectPermBits64(TlbEntry *te, const RequestPtr &req, Mode mode, ThreadContext *tc, CachedState &state, bool r, bool w, bool x)
Definition mmu.cc:874
uint8_t physAddrRange
Definition mmu.hh:439
ArmISA::TLB * getDTBPtr() const
Definition mmu.cc:139
bool checkWalkCache() const
Definition mmu.cc:113
TlbTestInterface * test
Definition mmu.hh:407
void flushAll() override
Definition mmu.cc:272
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Definition mmu.hh:260
enums::ArmLookupLevel LookupLevel
Definition mmu.hh:68
uint64_t getAttr() const
Definition mmu.hh:315
TLB * itbStage2
Definition mmu.hh:77
void setTestInterface(SimObject *ti)
Definition mmu.cc:1804
TableWalker * itbStage2Walker
Definition mmu.hh:82
Addr getValidAddr(Addr vaddr, ThreadContext *tc, Mode mode) override
Definition mmu.cc:378
AddrRange m5opRange
Definition mmu.hh:441
TableWalker * dtbStage2Walker
Definition mmu.hh:83
TableWalker * dtbWalker
Definition mmu.hh:81
Fault getTE(TlbEntry **te, const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool timing, bool functional, SecurityState ss, PASpace ipaspace, ArmTranslationType tran_type, bool stage2)
Definition mmu.cc:1614
void dflush(const TLBIOp &tlbi_op)
Definition mmu.cc:261
Fault checkPermissions64(TlbEntry *te, const RequestPtr &req, Mode mode, ThreadContext *tc, bool stage2)
Definition mmu.cc:579
Fault translateFs(const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool &delay, bool timing, ArmTranslationType tran_type, bool functional, CachedState &state)
Definition mmu.cc:1157
TlbEntry * lookup(Addr vpn, uint16_t asn, vmid_t vmid, SecurityState ss, bool functional, bool ignore_asn, TranslationRegime target_regime, bool stage2, BaseMMU::Mode mode)
Lookup an entry in the TLB.
Definition mmu.cc:1624
TableWalker * itbWalker
Definition mmu.hh:80
const ArmRelease * _release
Definition mmu.hh:437
gem5::ArmISA::MMU::Stats stats
std::pair< bool, bool > s2PermBits64(TlbEntry *te, const RequestPtr &req, Mode mode, ThreadContext *tc, CachedState &state, bool r, bool w, bool x)
Definition mmu.cc:692
CachedState s1State
Definition mmu.hh:431
void flush(const TLBIOp &tlbi_op)
Definition mmu.cc:217
Fault checkPermissions(TlbEntry *te, const RequestPtr &req, Mode mode, bool stage2)
Definition mmu.cc:392
MMU(const ArmMMUParams &p)
Definition mmu.cc:61
TableWalker * getTableWalker(BaseMMU::Mode mode, bool stage2) const
Definition mmu.cc:167
void takeOverFrom(BaseMMU *old_mmu) override
Definition mmu.cc:1790
Fault testAndFinalize(const RequestPtr &req, ThreadContext *tc, Mode mode, TlbEntry *te, CachedState &state) const
Definition mmu.cc:281
Addr purifyTaggedAddr(Addr vaddr_tainted, ThreadContext *tc, ExceptionLevel el, TCR tcr, bool is_inst, CachedState &state)
Definition mmu.cc:1002
CachedState s2State
Definition mmu.hh:431
void iflush(const TLBIOp &tlbi_op)
Definition mmu.cc:250
bool hasWalkCache() const
Definition mmu.hh:330
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition mmu.hh:249
TranslationGenPtr translateFunctional(Addr start, Addr size, ThreadContext *tc, Mode mode, Request::Flags flags) override
Returns a translation generator for a region of virtual addresses, instead of directly translating a ...
Definition mmu.hh:87
const ArmRelease * release() const
Definition mmu.hh:328
virtual Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, Mode mode)
Definition mmu.cc:125
BaseMMU(const Params &p)
Definition mmu.hh:90
This class takes a function as a constructor argument and memoizes it: every time the function gets i...
Definition memoizer.hh:83
gem5::Flags< FlagsType > Flags
Definition request.hh:102
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
STL pair class.
Definition stl.hh:58
SimObject(const Params &p)
Definition sim_object.cc:58
Bitfield< 30 > te
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Bitfield< 7, 4 > domain
MMU * getMMUPtr(T *tc)
Definition mmu.hh:459
SecurityState
Security State.
Definition types.hh:273
Bitfield< 3, 2 > el
Definition misc_types.hh:73
uint16_t vmid_t
Definition types.hh:57
const Addr PageBytes
Definition page_size.hh:53
PASpace
Physical Address Space.
Definition types.hh:280
Bitfield< 21 > ss
Definition misc_types.hh:60
Bitfield< 0 > p
Bitfield< 30 > ti
Bitfield< 0 > w
Bitfield< 3 > x
Definition pagetable.hh:78
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 RegVal
Definition types.hh:173
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
std::unique_ptr< TranslationGen > TranslationGenPtr
int ContextID
Globally unique thread context ID.
Definition types.hh:239
Declaration of Statistics objects.
ExceptionLevel exceptionLevel
Definition mmu.hh:182
SecurityState securityState
Definition mmu.hh:187
void updateMiscReg(ThreadContext *tc, ArmTranslationType tran_type)
Definition mmu.cc:1421
vmid_t getVMID(ThreadContext *tc) const
Returns the current VMID (information stored in the VTTBR_EL2 register)
Definition mmu.cc:1352
CachedState & operator=(const CachedState &rhs)
Definition mmu.hh:138
CachedState(MMU *_mmu, bool stage2)
Definition mmu.hh:132
Memoizer< int, ThreadContext *, bool, bool, TCR, ExceptionLevel > computeAddrTop
Definition mmu.hh:216
ArmTranslationType curTranType
Definition mmu.hh:200
TranslationRegime currRegime
Definition mmu.hh:183
Stats(statistics::Group *parent)
Definition mmu.cc:1831
statistics::Scalar permsFaults
Definition mmu.hh:452
statistics::Scalar alignFaults
Definition mmu.hh:449
statistics::Scalar prefetchFaults
Definition mmu.hh:450
statistics::Scalar domainFaults
Definition mmu.hh:451

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