gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
51#include "params/ArmMMU.hh"
52
53namespace gem5
54{
55
56namespace ArmISA {
57
58class TableWalker;
59class TLB;
60struct TlbEntry;
61class TLBIOp;
62class TlbTestInterface;
63
64class MMU : public BaseMMU
65{
66 protected:
67 using LookupLevel = enums::ArmLookupLevel;
68
69 ArmISA::TLB * getDTBPtr() const;
70 ArmISA::TLB * getITBPtr() const;
71
72 TLB * getTlb(BaseMMU::Mode mode, bool stage2) const;
73 TableWalker * getTableWalker(BaseMMU::Mode mode, bool stage2) const;
74
75 protected:
78
83
84 public:
87 Mode mode, Request::Flags flags) override
88 {
90 PageBytes, start, size, tc, this, mode, flags));
91 }
92
94 {
96
97 AlignByte = 0x0,
99 AlignWord = 0x2,
103
105 // Priv code operating as if it wasn't
106 UserMode = 0x10
107 };
108
110 {
112 S1CTran = 0x1,
113 HypMode = 0x2,
114 // Secure code operating as if it wasn't (required by some Address
115 // Translate operations)
117 // Address translation instructions (eg AT S1E0R_Xt) need to be handled
118 // in special ways during translation because they could need to act
119 // like a different EL than the current EL. The following flags are
120 // for these instructions
121 S1E0Tran = 0x8,
122 S1E1Tran = 0x10,
123 S1E2Tran = 0x20,
124 S1E3Tran = 0x40,
125 S12E0Tran = 0x80,
126 S12E1Tran = 0x100
127 };
128
130 {
131 CachedState(MMU *_mmu, bool stage2)
132 : mmu(_mmu), isStage2(stage2),
134 {}
135
138 {
139 isStage2 = rhs.isStage2;
140 cpsr = rhs.cpsr;
141 aarch64 = rhs.aarch64;
144 sctlr = rhs.sctlr;
145 scr = rhs.scr;
146 isPriv = rhs.isPriv;
148 ttbcr = rhs.ttbcr;
149 asid = rhs.asid;
150 vmid = rhs.vmid;
151 prrr = rhs.prrr;
152 nmrr = rhs.nmrr;
153 hcr = rhs.hcr;
154 dacr = rhs.dacr;
157 stage2Req = rhs.stage2Req;
160
161 // When we copy we just flush the memoizer cache
162 computeAddrTop.flush();
163
164 return *this;
165 }
166
168
171 vmid_t getVMID(ThreadContext *tc) const;
172
174 bool isStage2 = false;
175 CPSR cpsr = 0;
176 bool aarch64 = false;
179 SCTLR sctlr = 0;
180 SCR scr = 0;
181 bool isPriv = false;
183 TTBCR ttbcr = 0;
184 uint16_t asid = 0;
186 PRRR prrr = 0;
187 NMRR nmrr = 0;
188 HCR hcr = 0;
189 uint32_t dacr = 0;
190 bool miscRegValid = false;
192
193 // Indicates whether a stage 2 lookup is also required
194 bool stage2Req = false;
195
196 // Indicates whether a stage 2 lookup of the table descriptors is
197 // required. Certain address translation instructions will
198 // intercept the IPA but the table descriptors still need to be
199 // translated by the stage2.
200 bool stage2DescReq = false;
201
202 // Indicates whether all translation requests should
203 // be routed directly to the stage 2 TLB
204 bool directToStage2 = false;
205
206 Memoizer<int, ThreadContext*, bool,
208 };
209
210 MMU(const ArmMMUParams &p);
211
212 void init() override;
213
215
225
227 BaseMMU::Mode mode) override;
228
235
237 BaseMMU::Mode mode, ArmTranslationType tran_type, bool stage2);
238
239 Fault
241 ThreadContext *tc, Mode mode) override
242 {
243 return translateAtomic(req, tc, mode, NormalTran);
244 }
246 BaseMMU::Mode mode, ArmTranslationType tran_type, bool stage2);
248 ArmTranslationType tran_type);
249
250 void
252 Translation *translation, Mode mode) override
253 {
254 translateTiming(req, tc, translation, mode, NormalTran, false);
255 }
257 BaseMMU::Translation *translation, BaseMMU::Mode mode, bool stage2);
258 void translateTiming(
259 const RequestPtr &req, ThreadContext *tc,
260 Translation *translation, Mode mode,
261 ArmTranslationType tran_type, bool stage2);
262
264 ArmTranslationType tran_type, Addr vaddr, bool long_desc_format,
267 Translation *translation, bool &delay, bool timing, bool functional,
268 Addr vaddr, TranMethod tran_method,
270
272 Translation *translation, bool &delay,
273 bool timing, ArmTranslationType tran_type, bool functional,
276 Translation *translation, bool &delay, bool timing,
278
280
282 Translation *translation, Mode mode, ArmTranslationType tran_type,
283 bool call_from_s2);
285 Translation *translation, Mode mode, ArmTranslationType tran_type,
286 bool call_from_s2, CachedState &state);
288 const RequestPtr &req,
289 ThreadContext *tc, Mode mode) const override;
290
291 void drainResume() override;
292
293 void takeOverFrom(BaseMMU *old_mmu) override;
294
295 void invalidateMiscReg();
296
297 void flush(const TLBIOp &tlbi_op);
298 void flushStage1(const TLBIOp &tlbi_op);
299 void flushStage2(const TLBIOp &tlbi_op);
300 void iflush(const TLBIOp &tlbi_op);
301 void dflush(const TLBIOp &tlbi_op);
302
303 void flushAll() override;
304
305 uint64_t
306 getAttr() const
307 {
308 return _attr;
309 }
310
313 void
314 setAttr(uint64_t attr)
315 {
316 _attr = attr;
317 }
318
319 const ArmRelease* release() const { return _release; }
320
321 bool hasWalkCache() const { return _hasWalkCache; }
322
328 static ExceptionLevel tranTypeEL(CPSR cpsr, SCR scr, ArmTranslationType type);
329
330 static bool hasUnprivRegime(TranslationRegime regime);
331
332 public:
344 TlbEntry *lookup(Addr vpn, uint16_t asn, vmid_t vmid,
345 SecurityState ss, bool functional,
346 bool ignore_asn, TranslationRegime target_regime,
347 bool stage2, BaseMMU::Mode mode);
348
349 Fault getTE(TlbEntry **te, const RequestPtr &req,
351 Translation *translation, bool timing, bool functional,
352 SecurityState ss, PASpace ipaspace,
353 ArmTranslationType tran_type,
354 bool stage2);
355 Fault getTE(TlbEntry **te, const RequestPtr &req,
357 Translation *translation, bool timing, bool functional,
358 SecurityState ss, PASpace ipaspace,
359 ArmTranslationType tran_type,
360 CachedState &state);
361
362 Fault getResultTe(TlbEntry **te, const RequestPtr &req,
364 Translation *translation, bool timing,
365 bool functional, TlbEntry *mergeTe,
366 CachedState &state);
367
369 bool stage2);
371 CachedState &state);
373 ThreadContext *tc, bool stage2);
375 ThreadContext *tc, CachedState &state);
376
377 protected:
378 Addr purifyTaggedAddr(Addr vaddr_tainted, ThreadContext *tc,
380 TCR tcr, bool is_inst, CachedState& state);
381
382 bool checkPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req,
383 Mode mode, const bool is_priv, CachedState &state);
384
385 bool faultPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req,
386 Mode mode, const bool is_priv, CachedState &state);
387
389 TlbEntry *te, const RequestPtr &req, Mode mode,
390 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
391
393 TlbEntry *te, const RequestPtr &req, Mode mode,
394 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
395
396 public: /* Testing */
398
400
403
404 protected:
405 bool checkWalkCache() const;
406
407 bool isCompleteTranslation(TlbEntry *te) const;
408
410 ThreadContext *tc, ArmTranslationType tran_type,
411 bool stage2);
412
415 TlbEntry *te, CachedState &state) const;
416
417 protected:
419
420 public:
422
423 protected:
424 uint64_t _attr; // Memory attributes for last accessed TLB entry
425
426 // Cached copies of system-level properties
430
432
434
444
445};
446
447template<typename T>
448MMU *
450{
451 auto mmu = static_cast<MMU *>(tc->getMMUPtr());
452 assert(mmu);
453 return mmu;
454}
455
456} // namespace ArmISA
457} // namespace gem5
458
459#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:970
ArmISA::TLB * getITBPtr() const
Definition mmu.cc:144
void setAttr(uint64_t attr)
Accessor functions for memory attributes for last accessed TLB entry.
Definition mmu.hh:314
bool checkPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req, Mode mode, const bool is_priv, CachedState &state)
Definition mmu.cc:853
void flushStage2(const TLBIOp &tlbi_op)
Definition mmu.cc:242
static bool hasUnprivRegime(TranslationRegime regime)
Definition mmu.cc:816
Fault translateSe(const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool &delay, bool timing, CachedState &state)
Definition mmu.cc:332
void drainResume() override
Resume execution after a successful drain.
Definition mmu.cc:131
uint64_t _attr
Definition mmu.hh:424
ContextID miscRegContext
Definition mmu.hh:418
Fault translateComplete(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode, ArmTranslationType tran_type, bool call_from_s2)
Definition mmu.cc:1191
TLB * getTlb(BaseMMU::Mode mode, bool stage2) const
Definition mmu.cc:150
Fault translateMmuOff(ThreadContext *tc, const RequestPtr &req, Mode mode, ArmTranslationType tran_type, Addr vaddr, bool long_desc_format, CachedState &state)
Definition mmu.cc:895
Fault testTranslation(const RequestPtr &req, Mode mode, DomainType domain, CachedState &state) const
Definition mmu.cc:1679
TLB * dtbStage2
Definition mmu.hh:77
void init() override
Called at init time, this method is traversing the TLB hierarchy and pupulating the instruction/data/...
Definition mmu.cc:93
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:1261
bool isCompleteTranslation(TlbEntry *te) const
Definition mmu.cc:1643
void invalidateMiscReg()
Definition mmu.cc:208
bool haveLargeAsid64
Definition mmu.hh:428
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, Mode mode) const override
Definition mmu.cc:302
bool _hasWalkCache
Definition mmu.hh:433
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:732
Fault getResultTe(TlbEntry **te, const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool timing, bool functional, TlbEntry *mergeTe, CachedState &state)
Definition mmu.cc:1564
void flushStage1(const TLBIOp &tlbi_op)
Definition mmu.cc:228
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:1441
uint8_t physAddrRange
Definition mmu.hh:429
ArmISA::TLB * getDTBPtr() const
Definition mmu.cc:138
bool checkWalkCache() const
Definition mmu.cc:112
TlbTestInterface * test
Definition mmu.hh:397
void flushAll() override
Definition mmu.cc:271
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Definition mmu.hh:251
enums::ArmLookupLevel LookupLevel
Definition mmu.hh:67
uint64_t getAttr() const
Definition mmu.hh:306
TLB * itbStage2
Definition mmu.hh:76
void setTestInterface(SimObject *ti)
Definition mmu.cc:1663
TableWalker * itbStage2Walker
Definition mmu.hh:81
Addr getValidAddr(Addr vaddr, ThreadContext *tc, Mode mode) override
Definition mmu.cc:377
AddrRange m5opRange
Definition mmu.hh:431
TableWalker * dtbStage2Walker
Definition mmu.hh:82
TableWalker * dtbWalker
Definition mmu.hh:80
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:1473
void dflush(const TLBIOp &tlbi_op)
Definition mmu.cc:260
Fault checkPermissions64(TlbEntry *te, const RequestPtr &req, Mode mode, ThreadContext *tc, bool stage2)
Definition mmu.cc:578
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:1037
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:1483
TableWalker * itbWalker
Definition mmu.hh:79
const ArmRelease * _release
Definition mmu.hh:427
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:691
CachedState s1State
Definition mmu.hh:421
void flush(const TLBIOp &tlbi_op)
Definition mmu.cc:216
Fault checkPermissions(TlbEntry *te, const RequestPtr &req, Mode mode, bool stage2)
Definition mmu.cc:391
bool faultPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req, Mode mode, const bool is_priv, CachedState &state)
Definition mmu.cc:828
TableWalker * getTableWalker(BaseMMU::Mode mode, bool stage2) const
Definition mmu.cc:166
void takeOverFrom(BaseMMU *old_mmu) override
Definition mmu.cc:1649
Fault testAndFinalize(const RequestPtr &req, ThreadContext *tc, Mode mode, TlbEntry *te, CachedState &state) const
Definition mmu.cc:280
Addr purifyTaggedAddr(Addr vaddr_tainted, ThreadContext *tc, ExceptionLevel el, TCR tcr, bool is_inst, CachedState &state)
Definition mmu.cc:882
CachedState s2State
Definition mmu.hh:421
void iflush(const TLBIOp &tlbi_op)
Definition mmu.cc:249
bool hasWalkCache() const
Definition mmu.hh:321
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition mmu.hh:240
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:86
const ArmRelease * release() const
Definition mmu.hh:319
virtual Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, Mode mode)
Definition mmu.cc:125
This class takes a function as a constructor argument and memoizes it: every time the function gets i...
Definition memoizer.hh:83
Abstract superclass for simulation objects.
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
atomic_var_t state
Definition helpers.cc:211
uint8_t flags
Definition helpers.cc:87
Bitfield< 30 > te
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Bitfield< 7, 4 > domain
MMU * getMMUPtr(T *tc)
Definition mmu.hh:449
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:74
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
int ContextID
Globally unique thread context ID.
Definition types.hh:239
std::unique_ptr< TranslationGen > TranslationGenPtr
Declaration of Statistics objects.
ExceptionLevel exceptionLevel
Definition mmu.hh:177
SecurityState securityState
Definition mmu.hh:182
void updateMiscReg(ThreadContext *tc, ArmTranslationType tran_type)
Definition mmu.cc:1301
vmid_t getVMID(ThreadContext *tc) const
Returns the current VMID (information stored in the VTTBR_EL2 register)
Definition mmu.cc:1232
CachedState & operator=(const CachedState &rhs)
Definition mmu.hh:137
CachedState(MMU *_mmu, bool stage2)
Definition mmu.hh:131
Memoizer< int, ThreadContext *, bool, bool, TCR, ExceptionLevel > computeAddrTop
Definition mmu.hh:207
ArmTranslationType curTranType
Definition mmu.hh:191
TranslationRegime currRegime
Definition mmu.hh:178
statistics::Scalar permsFaults
Definition mmu.hh:442
statistics::Scalar alignFaults
Definition mmu.hh:439
statistics::Scalar prefetchFaults
Definition mmu.hh:440
statistics::Scalar domainFaults
Definition mmu.hh:441

Generated on Mon Jan 13 2025 04:28:22 for gem5 by doxygen 1.9.8