gem5 v24.0.0.0
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/tlb.hh"
46#include "arch/arm/utility.hh"
47#include "arch/generic/mmu.hh"
48#include "base/memoizer.hh"
49#include "enums/ArmLookupLevel.hh"
50
51#include "params/ArmMMU.hh"
52
53namespace gem5
54{
55
56namespace ArmISA {
57
58class TableWalker;
59
60class MMU : public BaseMMU
61{
62 protected:
63 using LookupLevel = enums::ArmLookupLevel;
64
66 getDTBPtr() const
67 {
68 return static_cast<ArmISA::TLB *>(dtb);
69 }
70
72 getITBPtr() const
73 {
74 return static_cast<ArmISA::TLB *>(itb);
75 }
76
77 TLB * getTlb(BaseMMU::Mode mode, bool stage2) const;
78 TableWalker * getTableWalker(BaseMMU::Mode mode, bool stage2) const;
79
80 protected:
83
88
89 public:
92 Mode mode, Request::Flags flags) override
93 {
95 PageBytes, start, size, tc, this, mode, flags));
96 }
97
99 {
101
108
110 // Priv code operating as if it wasn't
111 UserMode = 0x10
112 };
113
115 {
117 S1CTran = 0x1,
118 HypMode = 0x2,
119 // Secure code operating as if it wasn't (required by some Address
120 // Translate operations)
122 // Address translation instructions (eg AT S1E0R_Xt) need to be handled
123 // in special ways during translation because they could need to act
124 // like a different EL than the current EL. The following flags are
125 // for these instructions
126 S1E0Tran = 0x8,
127 S1E1Tran = 0x10,
128 S1E2Tran = 0x20,
129 S1E3Tran = 0x40,
130 S12E0Tran = 0x80,
131 S12E1Tran = 0x100
132 };
133
135 {
136 CachedState(MMU *_mmu, bool stage2)
137 : mmu(_mmu), isStage2(stage2),
139 {}
140
143 {
144 isStage2 = rhs.isStage2;
145 cpsr = rhs.cpsr;
146 aarch64 = rhs.aarch64;
149 sctlr = rhs.sctlr;
150 scr = rhs.scr;
151 isPriv = rhs.isPriv;
152 isSecure = rhs.isSecure;
153 ttbcr = rhs.ttbcr;
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;
187 bool isSecure = false;
188 TTBCR ttbcr = 0;
189 uint16_t asid = 0;
191 PRRR prrr = 0;
192 NMRR nmrr = 0;
193 HCR hcr = 0;
194 uint32_t dacr = 0;
195 bool miscRegValid = false;
197
198 // Indicates whether a stage 2 lookup is also required
199 bool stage2Req = false;
200
201 // Indicates whether a stage 2 lookup of the table descriptors is
202 // required. Certain address translation instructions will
203 // intercept the IPA but the table descriptors still need to be
204 // translated by the stage2.
205 bool stage2DescReq = false;
206
207 // Indicates whether all translation requests should
208 // be routed directly to the stage 2 TLB
209 bool directToStage2 = false;
210
211 Memoizer<int, ThreadContext*, bool,
213 };
214
215 MMU(const ArmMMUParams &p);
216
217 void init() override;
218
220
230
232 BaseMMU::Mode mode) override;
233
240
242 BaseMMU::Mode mode, ArmTranslationType tran_type, bool stage2);
243
244 Fault
246 ThreadContext *tc, Mode mode) override
247 {
248 return translateAtomic(req, tc, mode, NormalTran);
249 }
251 BaseMMU::Mode mode, ArmTranslationType tran_type, bool stage2);
253 ArmTranslationType tran_type);
254
255 void
257 Translation *translation, Mode mode) override
258 {
259 translateTiming(req, tc, translation, mode, NormalTran, false);
260 }
262 BaseMMU::Translation *translation, BaseMMU::Mode mode, bool stage2);
263 void translateTiming(
264 const RequestPtr &req, ThreadContext *tc,
265 Translation *translation, Mode mode,
266 ArmTranslationType tran_type, bool stage2);
267
269 ArmTranslationType tran_type, Addr vaddr, bool long_desc_format,
272 Translation *translation, bool &delay, bool timing, bool functional,
273 Addr vaddr, ArmFault::TranMethod tranMethod,
275
277 Translation *translation, bool &delay,
278 bool timing, ArmTranslationType tran_type, bool functional,
281 Translation *translation, bool &delay, bool timing,
283
285 Translation *translation, Mode mode, ArmTranslationType tran_type,
286 bool call_from_s2);
288 Translation *translation, Mode mode, ArmTranslationType tran_type,
289 bool call_from_s2, CachedState &state);
291 const RequestPtr &req,
292 ThreadContext *tc, Mode mode) const override;
293
294 void drainResume() override;
295
296 void takeOverFrom(BaseMMU *old_mmu) override;
297
298 void invalidateMiscReg();
299
300 template <typename OP>
301 void
302 flush(const OP &tlbi_op)
303 {
304 if (tlbi_op.stage1Flush()) {
305 flushStage1(tlbi_op);
306 }
307
308 if (tlbi_op.stage2Flush()) {
309 flushStage2(tlbi_op.makeStage2());
310 }
311 }
312
313 template <typename OP>
314 void
315 flushStage1(const OP &tlbi_op)
316 {
317 for (auto tlb : instruction) {
318 static_cast<TLB*>(tlb)->flush(tlbi_op);
319 }
320 for (auto tlb : data) {
321 static_cast<TLB*>(tlb)->flush(tlbi_op);
322 }
323 for (auto tlb : unified) {
324 static_cast<TLB*>(tlb)->flush(tlbi_op);
325 }
326 }
327
328 template <typename OP>
329 void
330 flushStage2(const OP &tlbi_op)
331 {
332 itbStage2->flush(tlbi_op);
333 dtbStage2->flush(tlbi_op);
334 }
335
336 template <typename OP>
337 void
338 iflush(const OP &tlbi_op)
339 {
340 for (auto tlb : instruction) {
341 static_cast<TLB*>(tlb)->flush(tlbi_op);
342 }
343 for (auto tlb : unified) {
344 static_cast<TLB*>(tlb)->flush(tlbi_op);
345 }
346 }
347
348 template <typename OP>
349 void
350 dflush(const OP &tlbi_op)
351 {
352 for (auto tlb : data) {
353 static_cast<TLB*>(tlb)->flush(tlbi_op);
354 }
355 for (auto tlb : unified) {
356 static_cast<TLB*>(tlb)->flush(tlbi_op);
357 }
358 }
359
360 void
361 flushAll() override
362 {
366 }
367
368 uint64_t
369 getAttr() const
370 {
371 return _attr;
372 }
373
376 void
377 setAttr(uint64_t attr)
378 {
379 _attr = attr;
380 }
381
382 const ArmRelease* release() const { return _release; }
383
384 bool hasWalkCache() const { return _hasWalkCache; }
385
391 static ExceptionLevel tranTypeEL(CPSR cpsr, SCR scr, ArmTranslationType type);
392
393 static bool hasUnprivRegime(TranslationRegime regime);
394
395 public:
407 TlbEntry *lookup(Addr vpn, uint16_t asn, vmid_t vmid,
408 bool secure, bool functional,
409 bool ignore_asn, TranslationRegime target_regime,
410 bool stage2, BaseMMU::Mode mode);
411
412 Fault getTE(TlbEntry **te, const RequestPtr &req,
414 Translation *translation, bool timing, bool functional,
415 bool is_secure, ArmTranslationType tran_type,
416 bool stage2);
417 Fault getTE(TlbEntry **te, const RequestPtr &req,
419 Translation *translation, bool timing, bool functional,
420 bool is_secure, ArmTranslationType tran_type,
421 CachedState &state);
422
423 Fault getResultTe(TlbEntry **te, const RequestPtr &req,
425 Translation *translation, bool timing,
426 bool functional, TlbEntry *mergeTe,
427 CachedState &state);
428
430 bool stage2);
432 CachedState &state);
434 ThreadContext *tc, bool stage2);
436 ThreadContext *tc, CachedState &state);
437
438 protected:
439 Addr purifyTaggedAddr(Addr vaddr_tainted, ThreadContext *tc,
441 TCR tcr, bool is_inst, CachedState& state);
442
443 bool checkPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req,
444 Mode mode, const bool is_priv, CachedState &state);
445
446 bool faultPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req,
447 Mode mode, const bool is_priv, CachedState &state);
448
450 TlbEntry *te, const RequestPtr &req, Mode mode,
451 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
452
454 TlbEntry *te, const RequestPtr &req, Mode mode,
455 ThreadContext *tc, CachedState &state, bool r, bool w, bool x);
456
457 public: /* Testing */
459
461
464
465 protected:
466 bool checkWalkCache() const;
467
468 bool isCompleteTranslation(TlbEntry *te) const;
469
471 ThreadContext *tc, ArmTranslationType tran_type,
472 bool stage2);
473
476 TlbEntry *te, CachedState &state) const;
477
478 protected:
480
481 public:
483
484 protected:
485 uint64_t _attr; // Memory attributes for last accessed TLB entry
486
487 // Cached copies of system-level properties
491
493
495
505
506};
507
508template<typename T>
509MMU *
511{
512 auto mmu = static_cast<MMU *>(tc->getMMUPtr());
513 assert(mmu);
514 return mmu;
515}
516
517} // namespace ArmISA
518} // namespace gem5
519
520#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
void setAttr(uint64_t attr)
Accessor functions for memory attributes for last accessed TLB entry.
Definition mmu.hh:377
bool checkPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req, Mode mode, const bool is_priv, CachedState &state)
Definition mmu.cc:763
static bool hasUnprivRegime(TranslationRegime regime)
Definition mmu.cc:726
Fault translateSe(const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool &delay, bool timing, CachedState &state)
Definition mmu.cc:256
void drainResume() override
Resume execution after a successful drain.
Definition mmu.cc:131
uint64_t _attr
Definition mmu.hh:485
ContextID miscRegContext
Definition mmu.hh:479
Fault translateComplete(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode, ArmTranslationType tran_type, bool call_from_s2)
Definition mmu.cc:1099
TLB * getTlb(BaseMMU::Mode mode, bool stage2) const
Definition mmu.cc:138
Fault translateMmuOff(ThreadContext *tc, const RequestPtr &req, Mode mode, ArmTranslationType tran_type, Addr vaddr, bool long_desc_format, CachedState &state)
Definition mmu.cc:805
TLB * dtbStage2
Definition mmu.hh:82
void init() override
Called at init time, this method is traversing the TLB hierarchy and pupulating the instruction/data/...
Definition mmu.cc:93
Fault getTE(TlbEntry **te, const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool timing, bool functional, bool is_secure, ArmTranslationType tran_type, bool stage2)
Definition mmu.cc:1380
void flushStage2(const OP &tlbi_op)
Definition mmu.hh:330
void translateTiming(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode, bool stage2)
void iflush(const OP &tlbi_op)
Definition mmu.hh:338
CachedState & updateMiscReg(ThreadContext *tc, ArmTranslationType tran_type, bool stage2)
Definition mmu.cc:1169
bool isCompleteTranslation(TlbEntry *te) const
Definition mmu.cc:1545
void invalidateMiscReg()
Definition mmu.cc:196
bool haveLargeAsid64
Definition mmu.hh:489
Fault finalizePhysical(const RequestPtr &req, ThreadContext *tc, Mode mode) const override
Definition mmu.cc:226
bool _hasWalkCache
Definition mmu.hh:494
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:643
Fault getResultTe(TlbEntry **te, const RequestPtr &req, ThreadContext *tc, Mode mode, Translation *translation, bool timing, bool functional, TlbEntry *mergeTe, CachedState &state)
Definition mmu.cc:1471
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:1348
uint8_t physAddrRange
Definition mmu.hh:490
bool checkWalkCache() const
Definition mmu.cc:112
TlbTestInterface * test
Definition mmu.hh:458
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Definition mmu.hh:256
enums::ArmLookupLevel LookupLevel
Definition mmu.hh:63
uint64_t getAttr() const
Definition mmu.hh:369
TLB * itbStage2
Definition mmu.hh:81
void setTestInterface(SimObject *ti)
Definition mmu.cc:1565
TlbEntry * lookup(Addr vpn, uint16_t asn, vmid_t vmid, bool secure, bool functional, bool ignore_asn, TranslationRegime target_regime, bool stage2, BaseMMU::Mode mode)
Lookup an entry in the TLB.
Definition mmu.cc:1390
TableWalker * itbStage2Walker
Definition mmu.hh:86
AddrRange m5opRange
Definition mmu.hh:492
void flushStage1(const OP &tlbi_op)
Definition mmu.hh:315
TableWalker * dtbStage2Walker
Definition mmu.hh:87
void flush(const OP &tlbi_op)
Definition mmu.hh:302
TableWalker * dtbWalker
Definition mmu.hh:85
Fault checkPermissions64(TlbEntry *te, const RequestPtr &req, Mode mode, ThreadContext *tc, bool stage2)
Definition mmu.cc:487
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:946
ArmISA::TLB * getITBPtr() const
Definition mmu.hh:72
void flushAll() override
Definition mmu.hh:361
TableWalker * itbWalker
Definition mmu.hh:84
const ArmRelease * _release
Definition mmu.hh:488
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:603
CachedState s1State
Definition mmu.hh:482
Fault checkPermissions(TlbEntry *te, const RequestPtr &req, Mode mode, bool stage2)
Definition mmu.cc:301
bool faultPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req, Mode mode, const bool is_priv, CachedState &state)
Definition mmu.cc:738
MMU(const ArmMMUParams &p)
Definition mmu.cc:60
TableWalker * getTableWalker(BaseMMU::Mode mode, bool stage2) const
Definition mmu.cc:154
void takeOverFrom(BaseMMU *old_mmu) override
Definition mmu.cc:1551
void dflush(const OP &tlbi_op)
Definition mmu.hh:350
Fault translateMmuOn(ThreadContext *tc, const RequestPtr &req, Mode mode, Translation *translation, bool &delay, bool timing, bool functional, Addr vaddr, ArmFault::TranMethod tranMethod, CachedState &state)
Definition mmu.cc:879
Fault testAndFinalize(const RequestPtr &req, ThreadContext *tc, Mode mode, TlbEntry *te, CachedState &state) const
Definition mmu.cc:204
Addr purifyTaggedAddr(Addr vaddr_tainted, ThreadContext *tc, ExceptionLevel el, TCR tcr, bool is_inst, CachedState &state)
Definition mmu.cc:792
CachedState s2State
Definition mmu.hh:482
ArmISA::TLB * getDTBPtr() const
Definition mmu.hh:66
Fault testTranslation(const RequestPtr &req, Mode mode, TlbEntry::DomainType domain, CachedState &state) const
Definition mmu.cc:1581
bool hasWalkCache() const
Definition mmu.hh:384
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition mmu.hh:245
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:91
const ArmRelease * release() const
Definition mmu.hh:382
void flush(const TLBIOp &tlbi_op)
Flush TLB entries.
Definition tlb.cc:318
void flushAll() override
Reset the entire TLB.
Definition tlb.cc:298
std::set< BaseTLB * > instruction
It is possible from the MMU to traverse the entire hierarchy of TLBs, starting from the DTB and ITB (...
Definition mmu.hh:181
virtual void flushAll()
Definition mmu.cc:81
virtual Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, Mode mode)
Definition mmu.cc:118
BaseTLB * itb
Definition mmu.hh:159
std::set< BaseTLB * > data
Definition mmu.hh:182
std::set< BaseTLB * > unified
Definition mmu.hh:183
BaseTLB * dtb
Definition mmu.hh:158
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:510
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
Bitfield< 59, 56 > tlb
Bitfield< 0 > p
Bitfield< 30 > ti
Bitfield< 0 > w
Bitfield< 3 > x
Definition pagetable.hh:73
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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
std::unique_ptr< TranslationGen > TranslationGenPtr
int ContextID
Globally unique thread context ID.
Definition types.hh:239
ExceptionLevel exceptionLevel
Definition mmu.hh:182
void updateMiscReg(ThreadContext *tc, ArmTranslationType tran_type)
Definition mmu.cc:1209
vmid_t getVMID(ThreadContext *tc) const
Returns the current VMID (information stored in the VTTBR_EL2 register)
Definition mmu.cc:1140
CachedState & operator=(const CachedState &rhs)
Definition mmu.hh:142
CachedState(MMU *_mmu, bool stage2)
Definition mmu.hh:136
Memoizer< int, ThreadContext *, bool, bool, TCR, ExceptionLevel > computeAddrTop
Definition mmu.hh:212
ArmTranslationType curTranType
Definition mmu.hh:196
TranslationRegime currRegime
Definition mmu.hh:183
Stats(statistics::Group *parent)
Definition mmu.cc:1592
statistics::Scalar permsFaults
Definition mmu.hh:503
statistics::Scalar alignFaults
Definition mmu.hh:500
statistics::Scalar prefetchFaults
Definition mmu.hh:501
statistics::Scalar domainFaults
Definition mmu.hh:502

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0