gem5 v25.0.0.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
51#include "params/ArmMMU.hh"
52
53namespace gem5
54{
55
56namespace ArmISA {
57
58class TableWalker;
59class TLB;
60struct TlbEntry;
61class TLBIOp;
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 tcr2 = rhs.tcr2;
150 pir = rhs.pir;
151 pire0 = rhs.pire0;
152 pie = rhs.pie;
153 asid = rhs.asid;
154 vmid = rhs.vmid;
155 prrr = rhs.prrr;
156 nmrr = rhs.nmrr;
157 hcr = rhs.hcr;
158 dacr = rhs.dacr;
161 stage2Req = rhs.stage2Req;
164
165 // When we copy we just flush the memoizer cache
166 computeAddrTop.flush();
167
168 return *this;
169 }
170
172
175 vmid_t getVMID(ThreadContext *tc) const;
176
178 bool isStage2 = false;
179 CPSR cpsr = 0;
180 bool aarch64 = false;
183 SCTLR sctlr = 0;
184 SCR scr = 0;
185 bool isPriv = false;
187 TTBCR ttbcr = 0;
188 TCR2 tcr2 = 0;
191 bool pie = false;
192 uint16_t asid = 0;
194 PRRR prrr = 0;
195 NMRR nmrr = 0;
196 HCR hcr = 0;
197 uint32_t dacr = 0;
198 bool miscRegValid = false;
200
201 // Indicates whether a stage 2 lookup is also required
202 bool stage2Req = false;
203
204 // Indicates whether a stage 2 lookup of the table descriptors is
205 // required. Certain address translation instructions will
206 // intercept the IPA but the table descriptors still need to be
207 // translated by the stage2.
208 bool stage2DescReq = false;
209
210 // Indicates whether all translation requests should
211 // be routed directly to the stage 2 TLB
212 bool directToStage2 = false;
213
214 Memoizer<int, ThreadContext*, bool,
216 };
217
218 MMU(const ArmMMUParams &p);
219
220 void init() override;
221
223
233
235 BaseMMU::Mode mode) override;
236
243
245 BaseMMU::Mode mode, ArmTranslationType tran_type, bool stage2);
246
247 Fault
249 ThreadContext *tc, Mode mode) override
250 {
251 return translateAtomic(req, tc, mode, NormalTran);
252 }
254 BaseMMU::Mode mode, ArmTranslationType tran_type, bool stage2);
256 ArmTranslationType tran_type);
257
258 void
260 Translation *translation, Mode mode) override
261 {
262 translateTiming(req, tc, translation, mode, NormalTran, false);
263 }
265 BaseMMU::Translation *translation, BaseMMU::Mode mode, bool stage2);
266 void translateTiming(
267 const RequestPtr &req, ThreadContext *tc,
268 Translation *translation, Mode mode,
269 ArmTranslationType tran_type, bool stage2);
270
272 ArmTranslationType tran_type, Addr vaddr, bool long_desc_format,
273 CachedState &state);
275 Translation *translation, bool &delay, bool timing, bool functional,
276 Addr vaddr, TranMethod tran_method,
277 CachedState &state);
278
280 Translation *translation, bool &delay,
281 bool timing, ArmTranslationType tran_type, bool functional,
282 CachedState &state);
284 Translation *translation, bool &delay, bool timing,
285 CachedState &state);
286
288
290 Translation *translation, Mode mode, ArmTranslationType tran_type,
291 bool call_from_s2);
293 Translation *translation, Mode mode, ArmTranslationType tran_type,
294 bool call_from_s2, CachedState &state);
296 const RequestPtr &req,
297 ThreadContext *tc, Mode mode) const override;
298
299 void drainResume() override;
300
301 void takeOverFrom(BaseMMU *old_mmu) override;
302
303 void invalidateMiscReg();
304
305 void flush(const TLBIOp &tlbi_op);
306 void flushStage1(const TLBIOp &tlbi_op);
307 void flushStage2(const TLBIOp &tlbi_op);
308 void iflush(const TLBIOp &tlbi_op);
309 void dflush(const TLBIOp &tlbi_op);
310
311 void flushAll() override;
312
313 uint64_t
314 getAttr() const
315 {
316 return _attr;
317 }
318
321 void
322 setAttr(uint64_t attr)
323 {
324 _attr = attr;
325 }
326
327 const ArmRelease* release() const { return _release; }
328
329 bool hasWalkCache() const { return _hasWalkCache; }
330
336 static ExceptionLevel tranTypeEL(CPSR cpsr, SCR scr, ArmTranslationType type);
337
338 static bool hasUnprivRegime(TranslationRegime regime);
339
340 public:
352 TlbEntry *lookup(Addr vpn, uint16_t asn, vmid_t vmid,
353 SecurityState ss, bool functional,
354 bool ignore_asn, TranslationRegime target_regime,
355 bool stage2, BaseMMU::Mode mode);
356
357 Fault getTE(TlbEntry **te, const RequestPtr &req,
359 Translation *translation, bool timing, bool functional,
360 SecurityState ss, PASpace ipaspace,
361 ArmTranslationType tran_type,
362 bool stage2);
363 Fault getTE(TlbEntry **te, const RequestPtr &req,
365 Translation *translation, bool timing, bool functional,
366 SecurityState ss, PASpace ipaspace,
367 ArmTranslationType tran_type,
368 CachedState &state);
369
370 Fault getResultTe(TlbEntry **te, const RequestPtr &req,
372 Translation *translation, bool timing,
373 bool functional, TlbEntry *mergeTe,
374 CachedState &state);
375
377 bool stage2);
379 CachedState &state);
381 ThreadContext *tc, bool stage2);
383 ThreadContext *tc, CachedState &state);
384
385 protected:
386 Addr purifyTaggedAddr(Addr vaddr_tainted, ThreadContext *tc,
388 TCR tcr, bool is_inst, CachedState& state);
389
391 TlbEntry *te, const RequestPtr &req, Mode mode,
392 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
393
394 std::tuple<bool, bool, bool> s1IndirectPermBits64(
395 TlbEntry *te, const RequestPtr &req, Mode mode,
396 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
397 std::tuple<bool, bool, bool> s1DirectPermBits64(
398 TlbEntry *te, const RequestPtr &req, Mode mode,
399 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
400
402 TlbEntry *te, const RequestPtr &req, Mode mode,
403 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
404
405 public: /* Testing */
407
409
411 DomainType domain, CachedState &state) const;
412
413 protected:
414 bool checkWalkCache() const;
415
416 bool isCompleteTranslation(TlbEntry *te) const;
417
419 ThreadContext *tc, ArmTranslationType tran_type,
420 bool stage2);
421
424 TlbEntry *te, CachedState &state) const;
425
426 protected:
428
429 public:
431
432 protected:
433 uint64_t _attr; // Memory attributes for last accessed TLB entry
434
435 // Cached copies of system-level properties
439
441
443
453
454};
455
456template<typename T>
457MMU *
459{
460 auto mmu = static_cast<MMU *>(tc->getMMUPtr());
461 assert(mmu);
462 return mmu;
463}
464
465} // namespace ArmISA
466} // namespace gem5
467
468#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:1089
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:732
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:322
void flushStage2(const TLBIOp &tlbi_op)
Definition mmu.cc:242
static bool hasUnprivRegime(TranslationRegime regime)
Definition mmu.cc:989
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:433
ContextID miscRegContext
Definition mmu.hh:427
Fault translateComplete(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode, ArmTranslationType tran_type, bool call_from_s2)
Definition mmu.cc:1310
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:1014
Fault testTranslation(const RequestPtr &req, Mode mode, DomainType domain, CachedState &state) const
Definition mmu.cc:1819
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:1380
bool isCompleteTranslation(TlbEntry *te) const
Definition mmu.cc:1783
void invalidateMiscReg()
Definition mmu.cc:208
bool haveLargeAsid64
Definition mmu.hh:437
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, Mode mode) const override
Definition mmu.cc:302
bool _hasWalkCache
Definition mmu.hh:442
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:959
Fault getResultTe(TlbEntry **te, const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool timing, bool functional, TlbEntry *mergeTe, CachedState &state)
Definition mmu.cc:1704
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:1581
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:873
uint8_t physAddrRange
Definition mmu.hh:438
ArmISA::TLB * getDTBPtr() const
Definition mmu.cc:138
bool checkWalkCache() const
Definition mmu.cc:112
TlbTestInterface * test
Definition mmu.hh:406
void flushAll() override
Definition mmu.cc:271
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Definition mmu.hh:259
enums::ArmLookupLevel LookupLevel
Definition mmu.hh:67
uint64_t getAttr() const
Definition mmu.hh:314
TLB * itbStage2
Definition mmu.hh:76
void setTestInterface(SimObject *ti)
Definition mmu.cc:1803
TableWalker * itbStage2Walker
Definition mmu.hh:81
Addr getValidAddr(Addr vaddr, ThreadContext *tc, Mode mode) override
Definition mmu.cc:377
AddrRange m5opRange
Definition mmu.hh:440
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:1613
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:1156
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:1623
TableWalker * itbWalker
Definition mmu.hh:79
const ArmRelease * _release
Definition mmu.hh:436
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:430
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
MMU(const ArmMMUParams &p)
Definition mmu.cc:60
TableWalker * getTableWalker(BaseMMU::Mode mode, bool stage2) const
Definition mmu.cc:166
void takeOverFrom(BaseMMU *old_mmu) override
Definition mmu.cc:1789
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:1001
CachedState s2State
Definition mmu.hh:430
void iflush(const TLBIOp &tlbi_op)
Definition mmu.cc:249
bool hasWalkCache() const
Definition mmu.hh:329
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition mmu.hh:248
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:327
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:458
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:181
SecurityState securityState
Definition mmu.hh:186
void updateMiscReg(ThreadContext *tc, ArmTranslationType tran_type)
Definition mmu.cc:1420
vmid_t getVMID(ThreadContext *tc) const
Returns the current VMID (information stored in the VTTBR_EL2 register)
Definition mmu.cc:1351
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:215
ArmTranslationType curTranType
Definition mmu.hh:199
TranslationRegime currRegime
Definition mmu.hh:182
Stats(statistics::Group *parent)
Definition mmu.cc:1830
statistics::Scalar permsFaults
Definition mmu.hh:451
statistics::Scalar alignFaults
Definition mmu.hh:448
statistics::Scalar prefetchFaults
Definition mmu.hh:449
statistics::Scalar domainFaults
Definition mmu.hh:450

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