gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tlb.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2013, 2016, 2019 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  * Authors: Ali Saidi
41  */
42 
43 #ifndef __ARCH_ARM_TLB_HH__
44 #define __ARCH_ARM_TLB_HH__
45 
46 
47 #include "arch/arm/faults.hh"
48 #include "arch/arm/isa_traits.hh"
49 #include "arch/arm/pagetable.hh"
50 #include "arch/arm/utility.hh"
51 #include "arch/arm/vtophys.hh"
52 #include "arch/generic/tlb.hh"
53 #include "base/statistics.hh"
54 #include "mem/request.hh"
55 #include "params/ArmTLB.hh"
56 #include "sim/probe/pmu.hh"
57 
58 class ThreadContext;
59 
60 namespace ArmISA {
61 
62 class TableWalker;
63 class Stage2LookUp;
64 class Stage2MMU;
65 class TLB;
66 
68 {
69  public:
71  virtual ~TlbTestInterface() {}
72 
81  virtual Fault translationCheck(const RequestPtr &req, bool is_priv,
84 
97  virtual Fault walkCheck(Addr pa, Addr size, Addr va, bool is_secure,
98  Addr is_priv, BaseTLB::Mode mode,
99  TlbEntry::DomainType domain,
100  LookupLevel lookup_level) = 0;
101 };
102 
103 class TLB : public BaseTLB
104 {
105  public:
106  enum ArmFlags {
107  AlignmentMask = 0x7,
108 
109  AlignByte = 0x0,
110  AlignHalfWord = 0x1,
111  AlignWord = 0x2,
112  AlignDoubleWord = 0x3,
113  AlignQuadWord = 0x4,
114  AlignOctWord = 0x5,
115 
116  AllowUnaligned = 0x8,
117  // Priv code operating as if it wasn't
118  UserMode = 0x10,
119  // Because zero otherwise looks like a valid setting and may be used
120  // accidentally, this bit must be non-zero to show it was used on
121  // purpose.
122  MustBeOne = 0x40
123  };
124 
126  NormalTran = 0,
127  S1CTran = 0x1,
128  HypMode = 0x2,
129  // Secure code operating as if it wasn't (required by some Address
130  // Translate operations)
131  S1S2NsTran = 0x4,
132  // Address translation instructions (eg AT S1E0R_Xt) need to be handled
133  // in special ways during translation because they could need to act
134  // like a different EL than the current EL. The following flags are
135  // for these instructions
136  S1E0Tran = 0x8,
137  S1E1Tran = 0x10,
138  S1E2Tran = 0x20,
139  S1E3Tran = 0x40,
140  S12E0Tran = 0x80,
141  S12E1Tran = 0x100
142  };
143 
149  static ExceptionLevel tranTypeEL(CPSR cpsr, ArmTranslationType type);
150 
151  protected:
152  TlbEntry* table; // the Page Table
153  int size; // TLB Size
154  bool isStage2; // Indicates this TLB is part of the second stage MMU
155  bool stage2Req; // Indicates whether a stage 2 lookup is also required
156  // Indicates whether a stage 2 lookup of the table descriptors is required.
157  // Certain address translation instructions will intercept the IPA but the
158  // table descriptors still need to be translated by the stage2.
160  uint64_t _attr; // Memory attributes for last accessed TLB entry
161  bool directToStage2; // Indicates whether all translation requests should
162  // be routed directly to the stage 2 TLB
163 
167 
169 
170  // Access Stats
187 
194 
197 
198  int rangeMRU; //On lookup, only move entries ahead when outside rangeMRU
199 
200  public:
201  TLB(const ArmTLBParams *p);
202  TLB(const Params *p, int _size, TableWalker *_walker);
203 
214  TlbEntry *lookup(Addr vpn, uint16_t asn, uint8_t vmid, bool hyp,
215  bool secure, bool functional,
216  bool ignore_asn, ExceptionLevel target_el);
217 
218  virtual ~TLB();
219 
220  void takeOverFrom(BaseTLB *otlb) override;
221 
223  void init() override;
224 
225  void setTestInterface(SimObject *ti);
226 
227  TableWalker *getTableWalker() { return tableWalker; }
228 
229  void setMMU(Stage2MMU *m, MasterID master_id);
230 
231  int getsize() const { return size; }
232 
233  void insert(Addr vaddr, TlbEntry &pte);
234 
235  Fault getTE(TlbEntry **te, const RequestPtr &req,
236  ThreadContext *tc, Mode mode,
237  Translation *translation, bool timing, bool functional,
238  bool is_secure, ArmTranslationType tranType);
239 
240  Fault getResultTe(TlbEntry **te, const RequestPtr &req,
241  ThreadContext *tc, Mode mode,
242  Translation *translation, bool timing,
243  bool functional, TlbEntry *mergeTe);
244 
245  Fault checkPermissions(TlbEntry *te, const RequestPtr &req, Mode mode);
246  Fault checkPermissions64(TlbEntry *te, const RequestPtr &req, Mode mode,
247  ThreadContext *tc);
248  bool checkPAN(ThreadContext *tc, uint8_t ap, const RequestPtr &req,
249  Mode mode);
250 
251 
255  void flushAllSecurity(bool secure_lookup, ExceptionLevel target_el,
256  bool ignore_el = false);
257 
261  void flushAllNs(ExceptionLevel target_el, bool ignore_el = false);
262 
263 
267  void flushAll() override
268  {
269  flushAllSecurity(false, EL0, true);
270  flushAllSecurity(true, EL0, true);
271  }
272 
278  void flushMvaAsid(Addr mva, uint64_t asn, bool secure_lookup,
279  ExceptionLevel target_el);
280 
285  void flushAsid(uint64_t asn, bool secure_lookup,
286  ExceptionLevel target_el);
287 
292  void flushMva(Addr mva, bool secure_lookup, ExceptionLevel target_el);
293 
300  void flushIpaVmid(Addr ipa, bool secure_lookup, ExceptionLevel target_el);
301 
302  Fault trickBoxCheck(const RequestPtr &req, Mode mode,
304 
305  Fault walkTrickBoxCheck(Addr pa, bool is_secure, Addr va, Addr sz,
306  bool is_exec, bool is_write,
307  TlbEntry::DomainType domain,
308  LookupLevel lookup_level);
309 
310  void printTlb() const;
311 
312  void demapPage(Addr vaddr, uint64_t asn) override
313  {
314  // needed for x86 only
315  panic("demapPage() is not implemented.\n");
316  }
317 
326  bool translateFunctional(ThreadContext *tc, Addr vaddr, Addr &paddr);
327 
332  Fault translateFunctional(const RequestPtr &req, ThreadContext *tc,
333  Mode mode, ArmTranslationType tranType);
334  Fault
336  ThreadContext *tc, Mode mode) override
337  {
338  return translateFunctional(req, tc, mode, NormalTran);
339  }
340 
343  void
344  setAttr(uint64_t attr)
345  {
346  _attr = attr;
347  }
348 
349  uint64_t
350  getAttr() const
351  {
352  return _attr;
353  }
354 
355  Fault translateMmuOff(ThreadContext *tc, const RequestPtr &req, Mode mode,
356  TLB::ArmTranslationType tranType, Addr vaddr, bool long_desc_format);
357  Fault translateMmuOn(ThreadContext *tc, const RequestPtr &req, Mode mode,
358  Translation *translation, bool &delay, bool timing, bool functional,
359  Addr vaddr, ArmFault::TranMethod tranMethod);
360 
361  Fault translateFs(const RequestPtr &req, ThreadContext *tc, Mode mode,
362  Translation *translation, bool &delay,
363  bool timing, ArmTranslationType tranType, bool functional = false);
364  Fault translateSe(const RequestPtr &req, ThreadContext *tc, Mode mode,
365  Translation *translation, bool &delay, bool timing);
366  Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode,
367  ArmTranslationType tranType);
368  Fault
370  ThreadContext *tc, Mode mode) override
371  {
372  return translateAtomic(req, tc, mode, NormalTran);
373  }
374  void translateTiming(
375  const RequestPtr &req, ThreadContext *tc,
376  Translation *translation, Mode mode,
377  ArmTranslationType tranType);
378  void
380  Translation *translation, Mode mode) override
381  {
382  translateTiming(req, tc, translation, mode, NormalTran);
383  }
384  Fault translateComplete(const RequestPtr &req, ThreadContext *tc,
385  Translation *translation, Mode mode, ArmTranslationType tranType,
386  bool callFromS2);
387  Fault finalizePhysical(
388  const RequestPtr &req,
389  ThreadContext *tc, Mode mode) const override;
390 
391  void drainResume() override;
392 
393  void regStats() override;
394 
395  void regProbePoints() override;
396 
407  Port *getTableWalkerPort() override;
408 
409  // Caching misc register values here.
410  // Writing to misc registers needs to invalidate them.
411  // translateFunctional/translateSe/translateFs checks if they are
412  // invalid and call updateMiscReg if necessary.
413 protected:
414  CPSR cpsr;
415  bool aarch64;
417  SCTLR sctlr;
418  SCR scr;
419  bool isPriv;
420  bool isSecure;
421  bool isHyp;
422  TTBCR ttbcr;
423  uint16_t asid;
424  uint8_t vmid;
425  PRRR prrr;
426  NMRR nmrr;
427  HCR hcr;
428  uint32_t dacr;
432 
433  // Cached copies of system-level properties
434  bool haveLPAE;
437 
439 
440  void updateMiscReg(ThreadContext *tc,
441  ArmTranslationType tranType = NormalTran);
442 
443 public:
444  const Params *
445  params() const
446  {
447  return dynamic_cast<const Params *>(_params);
448  }
449  inline void invalidateMiscReg() { miscRegValid = false; }
450 
451 private:
458  void _flushMva(Addr mva, uint64_t asn, bool secure_lookup,
459  bool ignore_asn, ExceptionLevel target_el);
460 
461  public: /* Testing */
462  Fault testTranslation(const RequestPtr &req, Mode mode,
463  TlbEntry::DomainType domain);
464  Fault testWalk(Addr pa, Addr size, Addr va, bool is_secure, Mode mode,
465  TlbEntry::DomainType domain,
466  LookupLevel lookup_level);
467 };
468 
469 template<typename T>
470 TLB *
471 getITBPtr(T *tc)
472 {
473  auto tlb = static_cast<TLB *>(tc->getITBPtr());
474  assert(tlb);
475  return tlb;
476 }
477 
478 template<typename T>
479 TLB *
480 getDTBPtr(T *tc)
481 {
482  auto tlb = static_cast<TLB *>(tc->getDTBPtr());
483  assert(tlb);
484  return tlb;
485 }
486 
487 } // namespace ArmISA
488 
489 #endif // __ARCH_ARM_TLB_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
Fault translateFunctional(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition: tlb.hh:335
Stats::Formula hits
Definition: tlb.hh:191
int size
Definition: tlb.hh:153
ProbePoints::PMUUPtr ppRefills
PMU probe for TLB refills.
Definition: tlb.hh:196
ExceptionLevel aarch64EL
Definition: tlb.hh:416
bool aarch64
Definition: tlb.hh:415
Ports are used to interface objects to each other.
Definition: port.hh:60
AddrRange m5opRange
Definition: tlb.hh:438
void flushAll() override
Reset the entire TLB.
Definition: tlb.hh:267
bool isHyp
Definition: tlb.hh:421
bool directToStage2
Definition: tlb.hh:161
TLB * stage2Tlb
Definition: tlb.hh:165
Bitfield< 0 > m
void translateTiming(const RequestPtr &req, ThreadContext *tc, Translation *translation, Mode mode) override
Definition: tlb.hh:379
SimObjectParams Params
Definition: sim_object.hh:113
TTBCR ttbcr
Definition: tlb.hh:422
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
void takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
Copy state between thread contexts in preparation for CPU handover.
TLB * getDTBPtr(T *tc)
Definition: tlb.hh:480
bool stage2Req
Definition: tlb.hh:155
bool isSecure
Definition: tlb.hh:420
Bitfield< 30 > te
uint64_t getAttr() const
Definition: tlb.hh:350
int getsize() const
Definition: tlb.hh:231
Definition: ccregs.hh:42
Bitfield< 30 > ti
Stats::Scalar prefetchFaults
Definition: tlb.hh:184
bool stage2DescReq
Definition: tlb.hh:159
Bitfield< 4, 0 > mode
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
ExceptionLevel
Definition: types.hh:585
Stats::Formula writeAccesses
Definition: tlb.hh:189
bool isPriv
Definition: tlb.hh:419
TableWalker * tableWalker
Definition: tlb.hh:164
Stats::Scalar flushedEntries
Definition: tlb.hh:182
Stats::Scalar readMisses
Definition: tlb.hh:174
const Params * params() const
Definition: tlb.hh:445
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:72
Definition: tlb.hh:52
Stats::Formula misses
Definition: tlb.hh:192
bool miscRegValid
Definition: tlb.hh:429
uint8_t type
Definition: inet.hh:333
HCR hcr
Definition: tlb.hh:427
Stats::Scalar permsFaults
Definition: tlb.hh:186
virtual ~TlbTestInterface()
Definition: tlb.hh:71
Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode) override
Definition: tlb.hh:369
int rangeMRU
Definition: tlb.hh:198
Stats::Scalar writeMisses
Definition: tlb.hh:176
bool haveVirtualization
Definition: tlb.hh:435
Stats::Scalar instMisses
Definition: tlb.hh:172
std::unique_ptr< PMU > PMUUPtr
Definition: pmu.hh:57
uint16_t asid
Definition: tlb.hh:423
PRRR prrr
Definition: tlb.hh:425
Stats::Scalar inserts
Definition: tlb.hh:177
TlbTestInterface * test
Definition: tlb.hh:168
Bitfield< 39, 12 > pa
bool haveLargeAsid64
Definition: tlb.hh:436
Stats::Scalar domainFaults
Definition: tlb.hh:185
uint32_t dacr
Definition: tlb.hh:428
Bitfield< 59, 56 > tlb
Stage2MMU * stage2Mmu
Definition: tlb.hh:166
virtual Fault walkCheck(Addr pa, Addr size, Addr va, bool is_secure, Addr is_priv, BaseTLB::Mode mode, TlbEntry::DomainType domain, LookupLevel lookup_level)=0
Check if a page table walker access should be forced to fail.
ArmTranslationType
Definition: tlb.hh:125
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint16_t MasterID
Definition: request.hh:86
bool haveLPAE
Definition: tlb.hh:434
void demapPage(Addr vaddr, uint64_t asn) override
Definition: tlb.hh:312
Stats::Scalar writeHits
Definition: tlb.hh:175
Bitfield< 8 > va
Stats::Scalar flushTlbMva
Definition: tlb.hh:179
Stats::Scalar instHits
Definition: tlb.hh:171
Stats::Formula accesses
Definition: tlb.hh:193
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3012
Mode
Definition: tlb.hh:59
Stats::Scalar flushTlbMvaAsid
Definition: tlb.hh:180
uint64_t _attr
Definition: tlb.hh:160
Stats::Formula readAccesses
Definition: tlb.hh:188
Stats::Scalar alignFaults
Definition: tlb.hh:183
Bitfield< 7, 4 > domain
virtual Fault translationCheck(const RequestPtr &req, bool is_priv, BaseTLB::Mode mode, TlbEntry::DomainType domain)=0
Check if a TLB translation should be forced to fail.
Stats::Scalar readHits
Definition: tlb.hh:173
NMRR nmrr
Definition: tlb.hh:426
Stats::Formula instAccesses
Definition: tlb.hh:190
SCTLR sctlr
Definition: tlb.hh:417
CPSR cpsr
Definition: tlb.hh:414
Stats::Scalar flushTlbAsid
Definition: tlb.hh:181
void invalidateMiscReg()
Definition: tlb.hh:449
TableWalker * getTableWalker()
Definition: tlb.hh:227
ArmTranslationType curTranType
Definition: tlb.hh:431
Bitfield< 0 > p
LookupLevel
Definition: pagetable.hh:77
void setAttr(uint64_t attr)
Accessor functions for memory attributes for last accessed TLB entry.
Definition: tlb.hh:344
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
TlbEntry * table
Definition: tlb.hh:152
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
const FlagsType init
This Stat is Initialized.
Definition: info.hh:47
Stats::Scalar flushTlb
Definition: tlb.hh:178
uint8_t vmid
Definition: tlb.hh:424
TLB * getITBPtr(T *tc)
Definition: tlb.hh:471
bool isStage2
Definition: tlb.hh:154
ContextID miscRegContext
Definition: tlb.hh:430
SCR scr
Definition: tlb.hh:418

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13