gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tlb.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2013, 2016 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/isa_traits.hh"
48 #include "arch/arm/pagetable.hh"
49 #include "arch/arm/utility.hh"
50 #include "arch/arm/vtophys.hh"
51 #include "arch/generic/tlb.hh"
52 #include "base/statistics.hh"
53 #include "mem/request.hh"
54 #include "params/ArmTLB.hh"
55 #include "sim/probe/pmu.hh"
56 
57 class ThreadContext;
58 
59 namespace ArmISA {
60 
61 class TableWalker;
62 class Stage2LookUp;
63 class Stage2MMU;
64 class TLB;
65 
67 {
68  public:
70  virtual ~TlbTestInterface() {}
71 
80  virtual Fault translationCheck(RequestPtr req, bool is_priv,
83 
96  virtual Fault walkCheck(Addr pa, Addr size, Addr va, bool is_secure,
97  Addr is_priv, BaseTLB::Mode mode,
99  LookupLevel lookup_level) = 0;
100 };
101 
102 class TLB : public BaseTLB
103 {
104  public:
105  enum ArmFlags {
107 
108  AlignByte = 0x0,
110  AlignWord = 0x2,
114 
116  // Priv code operating as if it wasn't
117  UserMode = 0x10,
118  // Because zero otherwise looks like a valid setting and may be used
119  // accidentally, this bit must be non-zero to show it was used on
120  // purpose.
121  MustBeOne = 0x40
122  };
123 
126  S1CTran = 0x1,
127  HypMode = 0x2,
128  // Secure code operating as if it wasn't (required by some Address
129  // Translate operations)
130  S1S2NsTran = 0x4,
131  // Address translation instructions (eg AT S1E0R_Xt) need to be handled
132  // in special ways during translation because they could need to act
133  // like a different EL than the current EL. The following flags are
134  // for these instructions
135  S1E0Tran = 0x8,
136  S1E1Tran = 0x10,
137  S1E2Tran = 0x20,
138  S1E3Tran = 0x40,
139  S12E0Tran = 0x80,
140  S12E1Tran = 0x100
141  };
142  protected:
143  TlbEntry* table; // the Page Table
144  int size; // TLB Size
145  bool isStage2; // Indicates this TLB is part of the second stage MMU
146  bool stage2Req; // Indicates whether a stage 2 lookup is also required
147  uint64_t _attr; // Memory attributes for last accessed TLB entry
148  bool directToStage2; // Indicates whether all translation requests should
149  // be routed directly to the stage 2 TLB
150 
154 
156 
157  // Access Stats
174 
181 
184 
185  int rangeMRU; //On lookup, only move entries ahead when outside rangeMRU
186 
187  public:
188  TLB(const ArmTLBParams *p);
189  TLB(const Params *p, int _size, TableWalker *_walker);
190 
201  TlbEntry *lookup(Addr vpn, uint16_t asn, uint8_t vmid, bool hyp,
202  bool secure, bool functional,
203  bool ignore_asn, uint8_t target_el);
204 
205  virtual ~TLB();
206 
207  void takeOverFrom(BaseTLB *otlb) override;
208 
210  void init() override;
211 
213 
215 
216  void setMMU(Stage2MMU *m, MasterID master_id);
217 
218  int getsize() const { return size; }
219 
220  void insert(Addr vaddr, TlbEntry &pte);
221 
223  Translation *translation, bool timing, bool functional,
224  bool is_secure, ArmTranslationType tranType);
225 
227  Mode mode, Translation *translation, bool timing,
228  bool functional, TlbEntry *mergeTe);
229 
232  ThreadContext *tc);
233 
234 
238  void flushAllSecurity(bool secure_lookup, uint8_t target_el,
239  bool ignore_el = false);
240 
245  void flushAllNs(bool hyp, uint8_t target_el, bool ignore_el = false);
246 
247 
251  void flushAll() override
252  {
253  flushAllSecurity(false, 0, true);
254  flushAllSecurity(true, 0, true);
255  }
256 
262  void flushMvaAsid(Addr mva, uint64_t asn, bool secure_lookup,
263  uint8_t target_el);
264 
269  void flushAsid(uint64_t asn, bool secure_lookup, uint8_t target_el);
270 
276  void flushMva(Addr mva, bool secure_lookup, bool hyp, uint8_t target_el);
277 
285  void flushIpaVmid(Addr ipa, bool secure_lookup, bool hyp, uint8_t target_el);
286 
288  Fault walkTrickBoxCheck(Addr pa, bool is_secure, Addr va, Addr sz, bool is_exec,
289  bool is_write, TlbEntry::DomainType domain, LookupLevel lookup_level);
290 
291  void printTlb() const;
292 
293  void demapPage(Addr vaddr, uint64_t asn) override
294  {
295  // needed for x86 only
296  panic("demapPage() is not implemented.\n");
297  }
298 
307  bool translateFunctional(ThreadContext *tc, Addr vaddr, Addr &paddr);
308 
314  ArmTranslationType tranType = NormalTran);
315 
318  void
319  setAttr(uint64_t attr)
320  {
321  _attr = attr;
322  }
323 
324  uint64_t
325  getAttr() const
326  {
327  return _attr;
328  }
329 
331  Translation *translation, bool &delay,
332  bool timing, ArmTranslationType tranType, bool functional = false);
334  Translation *translation, bool &delay, bool timing);
336  ArmTranslationType tranType = NormalTran);
338  Translation *translation, Mode mode,
339  ArmTranslationType tranType = NormalTran);
341  Translation *translation, Mode mode, ArmTranslationType tranType,
342  bool callFromS2);
344 
345  void drainResume() override;
346 
347  // Checkpointing
348  void serialize(CheckpointOut &cp) const override;
349  void unserialize(CheckpointIn &cp) override;
350 
351  void regStats() override;
352 
353  void regProbePoints() override;
354 
365  BaseMasterPort* getMasterPort() override;
366 
367  // Caching misc register values here.
368  // Writing to misc registers needs to invalidate them.
369  // translateFunctional/translateSe/translateFs checks if they are
370  // invalid and call updateMiscReg if necessary.
371 protected:
372  CPSR cpsr;
373  bool aarch64;
375  SCTLR sctlr;
376  SCR scr;
377  bool isPriv;
378  bool isSecure;
379  bool isHyp;
380  TTBCR ttbcr;
381  uint16_t asid;
382  uint8_t vmid;
383  PRRR prrr;
384  NMRR nmrr;
385  HCR hcr;
386  uint32_t dacr;
390 
391  // Cached copies of system-level properties
392  bool haveLPAE;
395 
397 
398  void updateMiscReg(ThreadContext *tc,
399  ArmTranslationType tranType = NormalTran);
400 
401 public:
402  const Params *
403  params() const
404  {
405  return dynamic_cast<const Params *>(_params);
406  }
407  inline void invalidateMiscReg() { miscRegValid = false; }
408 
409 private:
417  void _flushMva(Addr mva, uint64_t asn, bool secure_lookup,
418  bool hyp, bool ignore_asn, uint8_t target_el);
419 
420  bool checkELMatch(uint8_t target_el, uint8_t tentry_el, bool ignore_el);
421 
422  public: /* Testing */
425  Fault testWalk(Addr pa, Addr size, Addr va, bool is_secure, Mode mode,
427  LookupLevel lookup_level);
428 };
429 
430 } // namespace ArmISA
431 
432 #endif // __ARCH_ARM_TLB_HH__
Stats::Formula hits
Definition: tlb.hh:178
int size
Definition: tlb.hh:144
ProbePoints::PMUUPtr ppRefills
PMU probe for TLB refills.
Definition: tlb.hh:183
ExceptionLevel aarch64EL
Definition: tlb.hh:374
bool aarch64
Definition: tlb.hh:373
const Params * params() const
Definition: tlb.hh:403
AddrRange m5opRange
Definition: tlb.hh:396
Bitfield< 15 > te
Definition: mt_constants.hh:62
void flushMvaAsid(Addr mva, uint64_t asn, bool secure_lookup, uint8_t target_el)
Remove any entries that match both a va and asn.
Definition: tlb.cc:294
Fault finalizePhysical(RequestPtr req, ThreadContext *tc, Mode mode) const
Definition: tlb.cc:136
bool checkELMatch(uint8_t target_el, uint8_t tentry_el, bool ignore_el)
Definition: tlb.cc:364
void flushAll() override
Reset the entire TLB.
Definition: tlb.hh:251
bool isHyp
Definition: tlb.hh:379
Fault translateFs(RequestPtr req, ThreadContext *tc, Mode mode, Translation *translation, bool &delay, bool timing, ArmTranslationType tranType, bool functional=false)
Definition: tlb.cc:976
virtual ~TLB()
Definition: tlb.cc:98
bool directToStage2
Definition: tlb.hh:148
TLB * stage2Tlb
Definition: tlb.hh:152
virtual Fault translationCheck(RequestPtr req, bool is_priv, BaseTLB::Mode mode, TlbEntry::DomainType domain)=0
Check if a TLB translation should be forced to fail.
Bitfield< 0 > m
Definition: miscregs.hh:1577
#define panic(...)
Definition: misc.hh:153
SimObjectParams Params
Definition: sim_object.hh:110
TTBCR ttbcr
Definition: tlb.hh:380
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
void flushAllSecurity(bool secure_lookup, uint8_t target_el, bool ignore_el=false)
Reset the entire TLB.
Definition: tlb.cc:238
uint64_t getAttr() const
Definition: tlb.hh:325
bool stage2Req
Definition: tlb.hh:146
bool isSecure
Definition: tlb.hh:378
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: tlb.cc:425
void regStats() override
Register statistics for this object.
Definition: tlb.cc:441
Bitfield< 30 > ti
Stats::Scalar prefetchFaults
Definition: tlb.hh:171
Bitfield< 4, 0 > mode
Definition: miscregs.hh:1385
void drainResume() override
Resume execution after a successful drain.
Definition: tlb.cc:378
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:2475
ExceptionLevel
Definition: types.hh:562
Fault testWalk(Addr pa, Addr size, Addr va, bool is_secure, Mode mode, TlbEntry::DomainType domain, LookupLevel lookup_level)
Definition: tlb.cc:1534
Stats::Formula writeAccesses
Definition: tlb.hh:176
bool isPriv
Definition: tlb.hh:377
TableWalker * tableWalker
Definition: tlb.hh:151
void _flushMva(Addr mva, uint64_t asn, bool secure_lookup, bool hyp, bool ignore_asn, uint8_t target_el)
Remove any entries that match both a va and asn.
Definition: tlb.cc:337
Stats::Scalar flushedEntries
Definition: tlb.hh:169
Stats::Scalar readMisses
Definition: tlb.hh:161
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:53
Stats::Formula misses
Definition: tlb.hh:179
bool miscRegValid
Definition: tlb.hh:387
Fault translateComplete(RequestPtr req, ThreadContext *tc, Translation *translation, Mode mode, ArmTranslationType tranType, bool callFromS2)
Definition: tlb.cc:1199
HCR hcr
Definition: tlb.hh:385
Stats::Scalar permsFaults
Definition: tlb.hh:173
virtual ~TlbTestInterface()
Definition: tlb.hh:70
int rangeMRU
Definition: tlb.hh:185
Stats::Scalar writeMisses
Definition: tlb.hh:163
void flushMva(Addr mva, bool secure_lookup, bool hyp, uint8_t target_el)
Remove all entries that match the va regardless of asn.
Definition: tlb.cc:328
bool haveVirtualization
Definition: tlb.hh:393
Stats::Scalar instMisses
Definition: tlb.hh:159
std::unique_ptr< PMU > PMUUPtr
Definition: pmu.hh:57
Fault trickBoxCheck(RequestPtr req, Mode mode, TlbEntry::DomainType domain)
Fault translateTiming(RequestPtr req, ThreadContext *tc, Translation *translation, Mode mode, ArmTranslationType tranType=NormalTran)
Definition: tlb.cc:1183
uint16_t asid
Definition: tlb.hh:381
void printTlb() const
Definition: tlb.cc:224
BaseMasterPort * getMasterPort() override
Get the table walker master port.
Definition: tlb.cc:1227
Fault getTE(TlbEntry **te, RequestPtr req, ThreadContext *tc, Mode mode, Translation *translation, bool timing, bool functional, bool is_secure, ArmTranslationType tranType)
Definition: tlb.cc:1379
PRRR prrr
Definition: tlb.hh:383
Stats::Scalar inserts
Definition: tlb.hh:164
TlbTestInterface * test
Definition: tlb.hh:155
Bitfield< 39, 12 > pa
Definition: miscregs.hh:1829
bool haveLargeAsid64
Definition: tlb.hh:394
Stats::Scalar domainFaults
Definition: tlb.hh:172
void updateMiscReg(ThreadContext *tc, ArmTranslationType tranType=NormalTran)
Definition: tlb.cc:1233
uint32_t dacr
Definition: tlb.hh:386
TlbEntry * lookup(Addr vpn, uint16_t asn, uint8_t vmid, bool hyp, bool secure, bool functional, bool ignore_asn, uint8_t target_el)
Lookup an entry in the TLB.
Definition: tlb.cc:151
Stage2MMU * stage2Mmu
Definition: tlb.hh:153
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.
Fault checkPermissions64(TlbEntry *te, RequestPtr req, Mode mode, ThreadContext *tc)
Definition: tlb.cc:776
bool translateFunctional(ThreadContext *tc, Addr vaddr, Addr &paddr)
Do a functional lookup on the TLB (for debugging) and don't modify any internal state.
Definition: tlb.cc:118
ArmTranslationType
Definition: tlb.hh:124
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
TLB(const ArmTLBParams *p)
Definition: tlb.cc:76
uint16_t MasterID
Definition: request.hh:85
bool haveLPAE
Definition: tlb.hh:392
void demapPage(Addr vaddr, uint64_t asn) override
Definition: tlb.hh:293
Stats::Scalar writeHits
Definition: tlb.hh:162
Bitfield< 8 > va
Definition: miscregs.hh:1473
Stats::Scalar flushTlbMva
Definition: tlb.hh:166
void init() override
setup all the back pointers
Definition: tlb.cc:104
Stats::Scalar instHits
Definition: tlb.hh:158
Stats::Formula accesses
Definition: tlb.hh:180
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2895
Mode
Definition: tlb.hh:61
Stats::Scalar flushTlbMvaAsid
Definition: tlb.hh:167
uint64_t _attr
Definition: tlb.hh:147
Stats::Formula readAccesses
Definition: tlb.hh:175
int size()
Definition: pagetable.hh:146
Stats::Scalar alignFaults
Definition: tlb.hh:170
void flushAsid(uint64_t asn, bool secure_lookup, uint8_t target_el)
Remove any entries that match the asn.
Definition: tlb.cc:304
Bitfield< 7, 4 > domain
Definition: miscregs.hh:1605
std::ostream CheckpointOut
Definition: serialize.hh:67
Stats::Scalar readHits
Definition: tlb.hh:160
void insert(Addr vaddr, TlbEntry &pte)
Definition: tlb.cc:194
void regProbePoints() override
Register probe points for this object.
Definition: tlb.cc:558
void setMMU(Stage2MMU *m, MasterID master_id)
Definition: tlb.cc:111
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
Definition: port.hh:115
NMRR nmrr
Definition: tlb.hh:384
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:107
Fault getResultTe(TlbEntry **te, RequestPtr req, ThreadContext *tc, Mode mode, Translation *translation, bool timing, bool functional, TlbEntry *mergeTe)
Definition: tlb.cc:1441
Stats::Formula instAccesses
Definition: tlb.hh:177
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: tlb.cc:409
Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode, ArmTranslationType tranType=NormalTran)
Definition: tlb.cc:1141
SCTLR sctlr
Definition: tlb.hh:375
Fault checkPermissions(TlbEntry *te, RequestPtr req, Mode mode)
Definition: tlb.cc:604
void flushIpaVmid(Addr ipa, bool secure_lookup, bool hyp, uint8_t target_el)
Invalidate all entries in the stage 2 TLB that match the given ipa and the current VMID...
Definition: tlb.cc:357
CPSR cpsr
Definition: tlb.hh:372
Stats::Scalar flushTlbAsid
Definition: tlb.hh:168
void invalidateMiscReg()
Definition: tlb.hh:407
Fault testTranslation(RequestPtr req, Mode mode, TlbEntry::DomainType domain)
Definition: tlb.cc:1524
TableWalker * getTableWalker()
Definition: tlb.hh:214
void takeOverFrom(BaseTLB *otlb) override
Take over from an old tlb context.
Definition: tlb.cc:386
void flushAllNs(bool hyp, uint8_t target_el, bool ignore_el=false)
Remove all entries in the non secure world, depending on whether they were allocated in hyp mode or n...
Definition: tlb.cc:267
Fault translateSe(RequestPtr req, ThreadContext *tc, Mode mode, Translation *translation, bool &delay, bool timing)
Definition: tlb.cc:564
ArmTranslationType curTranType
Definition: tlb.hh:389
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:319
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
TlbEntry * table
Definition: tlb.hh:143
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
int ContextID
Globally unique thread context ID.
Definition: types.hh:175
Fault walkTrickBoxCheck(Addr pa, bool is_secure, Addr va, Addr sz, bool is_exec, bool is_write, TlbEntry::DomainType domain, LookupLevel lookup_level)
Stats::Scalar flushTlb
Definition: tlb.hh:165
uint8_t vmid
Definition: tlb.hh:382
void setTestInterface(SimObject *ti)
Definition: tlb.cc:1512
bool isStage2
Definition: tlb.hh:145
ContextID miscRegContext
Definition: tlb.hh:388
SCR scr
Definition: tlb.hh:376
int getsize() const
Definition: tlb.hh:218

Generated on Fri Jun 9 2017 13:03:36 for gem5 by doxygen 1.8.6