gem5 v24.0.0.0
Loading...
Searching...
No Matches
pagetable.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, 2012-2013, 2021, 2023 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) 2002-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_PAGETABLE_H__
42#define __ARCH_ARM_PAGETABLE_H__
43
44#include <cstdint>
45
46#include "arch/arm/page_size.hh"
47#include "arch/arm/types.hh"
48#include "arch/arm/utility.hh"
49#include "arch/generic/mmu.hh"
50#include "enums/TypeTLB.hh"
51#include "enums/ArmLookupLevel.hh"
52#include "sim/serialize.hh"
53
54namespace gem5
55{
56
57namespace ArmISA
58{
59
60// Granule sizes
68
69extern const GrainSize GrainMap_tg0[];
70extern const GrainSize GrainMap_tg1[];
71
72// Max. physical address range in bits supported by the architecture
73const unsigned MaxPhysAddrRange = 52;
74
75// ITB/DTB page table entry
76struct PTE
77{
78 void serialize(CheckpointOut &cp) const
79 {
80 panic("Need to implement PTE serialization\n");
81 }
82
84 {
85 panic("Need to implement PTE serialization\n");
86 }
87
88};
89
91{
92 typedef enums::ArmLookupLevel LookupLevel;
93 typedef int64_t pte_t;
94
95 virtual bool isValid(pte_t pte, unsigned level) const = 0;
96 virtual bool isLeaf(pte_t pte, unsigned level) const = 0;
97 virtual bool isWritable(pte_t pte, unsigned level, bool stage2) const = 0;
98 virtual Addr nextLevelPointer(pte_t pte, unsigned level) const = 0;
99 virtual Addr index(Addr va, unsigned level, int tsz) const = 0;
100 virtual Addr pageMask(pte_t pte, unsigned level) const = 0;
101 virtual unsigned walkBits(unsigned level) const = 0;
102 virtual LookupLevel firstLevel(uint8_t tsz) const = 0;
103 virtual LookupLevel firstS2Level(uint8_t sl0) const = 0;
104 virtual LookupLevel lastLevel() const = 0;
105
106 Addr walkMask(unsigned level) const;
107};
108
110{
111 bool isValid(pte_t pte, unsigned level) const override;
112 bool isLeaf(pte_t pte, unsigned level) const override;
113 bool isWritable(pte_t pte, unsigned level, bool stage2) const override;
114 Addr nextLevelPointer(pte_t pte, unsigned level) const override;
115 Addr index(Addr va, unsigned level, int tsz) const override;
116 Addr pageMask(pte_t pte, unsigned level) const override;
117 unsigned walkBits(unsigned level) const override;
118 LookupLevel firstLevel(uint8_t tsz) const override;
119 LookupLevel lastLevel() const override;
120};
121
123{
124 bool isValid(pte_t pte, unsigned level) const override;
125 bool isLeaf(pte_t pte, unsigned level) const override;
126 bool isWritable(pte_t pte, unsigned level, bool stage2) const override;
127 Addr nextLevelPointer(pte_t pte, unsigned level) const override;
128 Addr index(Addr va, unsigned level, int tsz) const override;
129 Addr pageMask(pte_t pte, unsigned level) const override;
130 unsigned walkBits(unsigned level) const override;
131 LookupLevel firstLevel(uint8_t tsz) const override;
132 LookupLevel firstS2Level(uint8_t sl0) const override;
133 LookupLevel lastLevel() const override;
134};
135
137{
138 bool isValid(pte_t pte, unsigned level) const override;
139 bool isLeaf(pte_t pte, unsigned level) const override;
140 bool isWritable(pte_t pte, unsigned level, bool stage2) const override;
141 Addr nextLevelPointer(pte_t pte, unsigned level) const override;
142 Addr index(Addr va, unsigned level, int tsz) const override;
143 Addr pageMask(pte_t pte, unsigned level) const override;
144 unsigned walkBits(unsigned level) const override;
145 LookupLevel firstLevel(uint8_t tsz) const override;
146 LookupLevel firstS2Level(uint8_t sl0) const override;
147 LookupLevel lastLevel() const override;
148};
149
151{
152 bool isValid(pte_t pte, unsigned level) const override;
153 bool isLeaf(pte_t pte, unsigned level) const override;
154 bool isWritable(pte_t pte, unsigned level, bool stage2) const override;
155 Addr nextLevelPointer(pte_t pte, unsigned level) const override;
156 Addr index(Addr va, unsigned level, int tsz) const override;
157 Addr pageMask(pte_t pte, unsigned level) const override;
158 unsigned walkBits(unsigned level) const override;
159 LookupLevel firstLevel(uint8_t tsz) const override;
160 LookupLevel firstS2Level(uint8_t sl0) const override;
161 LookupLevel lastLevel() const override;
162};
163
164// ITB/DTB table entry
165struct TlbEntry : public Serializable
166{
167 public:
168 typedef enums::ArmLookupLevel LookupLevel;
169
170 enum class MemoryType : std::uint8_t
171 {
173 Device,
174 Normal
175 };
176
177 enum class DomainType : std::uint8_t
178 {
179 NoAccess = 0,
180 Client,
181 Reserved,
182 Manager
183 };
184
185 struct Lookup
186 {
187 // virtual address
188 Addr va = 0;
189 // lookup size:
190 // * != 0 -> this is a range based lookup.
191 // end_address = va + size
192 // * == 0 -> This is a normal lookup. size should
193 // be ignored
195 // context id/address space id to use
196 uint16_t asn = 0;
197 // if on lookup asn should be ignored
198 bool ignoreAsn = false;
199 // The virtual machine ID used for stage 2 translation
201 // if the lookup is secure
202 bool secure = false;
203 // if the lookup should modify state
204 bool functional = false;
205 // selecting the translation regime
207 // mode to differentiate between read/writes/fetches.
209 };
210
211 // Matching variables
213 Addr size; // Size of this entry, == Type of TLB Rec
214 Addr vpn; // Virtual Page Number
215 uint64_t attributes; // Memory attributes formatted for PAR
216
217 LookupLevel lookupLevel; // Lookup level where the descriptor was fetched
218 // from. Used to set the FSR for faults
219 // occurring while the long desc. format is in
220 // use (AArch32 w/ LPAE and AArch64)
221
222 uint16_t asid; // Address Space Identifier
223 vmid_t vmid; // Virtual machine Identifier
224 GrainSize tg; // Translation Granule Size
225 uint8_t N; // Number of bits in pagesize
226 uint8_t innerAttrs;
227 uint8_t outerAttrs;
228 uint8_t ap; // Access permissions bits
229 uint8_t hap; // Hyp access permissions bits
230 DomainType domain; // Access Domain
231
233
234 // True if the long descriptor format is used for this entry (LPAE only)
235 bool longDescFormat; // @todo use this in the update attribute bethod
236
237 bool global;
238 bool valid;
239
240 // True if the entry targets the non-secure physical address space
241 bool ns;
242 // True if the entry was brought in from a non-secure page table
243 bool nstid;
244 // Translation regime on insert, AARCH64 EL0&1, AARCH32 -> el=1
246 // This is used to distinguish between instruction and data entries
247 // in unified TLBs
248 TypeTLB type;
249 // True if the entry is caching a partial translation (a table walk)
251
252 // Type of memory
253 bool nonCacheable; // Can we wrap this in mtype?
254
255 // Memory Attributes
258
259 // Access permissions
260 bool xn; // Execute Never
261 bool pxn; // Privileged Execute Never (LPAE only)
262
263 //Construct an entry that maps to physical address addr for SE mode
264 TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr,
265 bool uncacheable, bool read_only) :
266 pfn(_paddr >> PageShift), size(PageBytes - 1), vpn(_vaddr >> PageShift),
268 asid(_asn), vmid(0), tg(Grain4KB), N(0),
269 innerAttrs(0), outerAttrs(0), ap(read_only ? 0x3 : 0), hap(0x3),
271 longDescFormat(false), global(false), valid(true),
272 ns(true), nstid(true), regime(TranslationRegime::EL10),
273 type(TypeTLB::unified), partial(false),
274 nonCacheable(uncacheable),
275 shareable(false), outerShareable(false), xn(0), pxn(0)
276 {
277 // no restrictions by default, hap = 0x3
278
279 // @todo Check the memory type
280 if (read_only)
281 warn("ARM TlbEntry does not support read-only mappings\n");
282 }
283
285 pfn(0), size(0), vpn(0), attributes(0), lookupLevel(LookupLevel::L1),
286 asid(0), vmid(0), tg(ReservedGrain), N(0),
287 innerAttrs(0), outerAttrs(0), ap(0), hap(0x3),
289 longDescFormat(false), global(false), valid(false),
290 ns(true), nstid(true), regime(TranslationRegime::EL10),
291 type(TypeTLB::unified), partial(false), nonCacheable(false),
292 shareable(false), outerShareable(false), xn(0), pxn(0)
293 {
294 // no restrictions by default, hap = 0x3
295
296 // @todo Check the memory type
297 }
298
299 void
300 updateVaddr(Addr new_vaddr)
301 {
302 vpn = new_vaddr >> PageShift;
303 }
304
305 Addr
306 pageStart() const
307 {
308 return pfn << PageShift;
309 }
310
311 bool
312 matchAddress(const Lookup &lookup) const
313 {
314 Addr page_addr = vpn << N;
315 if (lookup.size) {
316 // This is a range based loookup
317 return lookup.va <= page_addr + size &&
318 lookup.va + lookup.size > page_addr;
319 } else {
320 // This is a normal lookup
321 return lookup.va >= page_addr && lookup.va <= page_addr + size;
322 }
323 }
324
325 bool
326 match(const Lookup &lookup) const
327 {
328 bool match = false;
329 if (valid && matchAddress(lookup) &&
330 (lookup.secure == !nstid))
331 {
333
334 if (match && !lookup.ignoreAsn) {
335 match = global || (lookup.asn == asid);
336 }
337 if (match && useVMID(lookup.targetRegime)) {
338 match = lookup.vmid == vmid;
339 }
340 }
341 return match;
342 }
343
344 bool
345 checkRegime(TranslationRegime target_regime) const
346 {
347 return regime == target_regime;
348 }
349
350 Addr
351 pAddr(Addr va) const
352 {
353 return (pfn << N) | (va & size);
354 }
355
356 void
358 {
359 uint64_t mask;
360 uint64_t newBits;
361
362 // chec bit 11 to determine if its currently LPAE or VMSA format.
363 if ( attributes & (1 << 11) ) {
364 newBits = ((outerShareable ? 0x2 :
365 shareable ? 0x3 : 0) << 7);
366 mask = 0x180;
367 } else {
383 newBits = ((outerShareable ? 0:1) << 10) |
384 ((shareable ? 1:0) << 7) |
385 (innerAttrs << 4) |
386 (outerAttrs << 2);
387 // TODO: Supersection bit
388 mask = 0x4FC;
389 }
390 // common bits
391 newBits |= ns << 9; // NS bit
392 mask |= 1 << 9;
393 // add in the new bits
394 attributes &= ~mask;
395 attributes |= newBits;
396 }
397
398 void
400 {
401 attributes = lpae ? (1 << 11) : 0;
403 }
404
405 std::string
406 print() const
407 {
408 return csprintf("%#x, asn %d vmn %d ppn %#x size: %#x ap:%d "
409 "ns:%d nstid:%d g:%d regime:%s", vpn << N, asid, vmid,
410 pfn << N, size, ap, ns, nstid, global,
412 }
413
414 void
444 void
475
476};
477
478const PageTableOps *getPageTableOps(GrainSize trans_granule);
479
480} // namespace ArmISA
481} // namespace gem5
482
483#endif // __ARCH_ARM_PAGETABLE_H__
Basic support for object serialization.
Definition serialize.hh:170
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define SERIALIZE_ENUM(scalar)
Definition serialize.hh:591
#define UNSERIALIZE_ENUM(scalar)
Definition serialize.hh:598
#define warn(...)
Definition logging.hh:256
static bool useVMID(TranslationRegime regime)
Definition utility.hh:376
const PageTableOps * getPageTableOps(GrainSize trans_granule)
Definition pagetable.cc:476
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 9 > lpae
static const char * regimeToStr(TranslationRegime regime)
Definition types.hh:474
const GrainSize GrainMap_tg1[]
Definition pagetable.cc:51
const unsigned MaxPhysAddrRange
Definition pagetable.hh:73
const Addr PageShift
Definition page_size.hh:52
uint16_t vmid_t
Definition types.hh:57
const Addr PageBytes
Definition page_size.hh:53
const GrainSize GrainMap_tg0[]
Definition pagetable.cc:49
Bitfield< 8 > va
Bitfield< 7, 6 > sl0
Bitfield< 30, 0 > index
Bitfield< 20 > level
Definition intmessage.hh:51
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition types.cc:40
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition types.cc:72
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568
void serialize(CheckpointOut &cp) const
Definition pagetable.hh:78
void unserialize(CheckpointIn &cp)
Definition pagetable.hh:83
virtual bool isWritable(pte_t pte, unsigned level, bool stage2) const =0
enums::ArmLookupLevel LookupLevel
Definition pagetable.hh:92
Addr walkMask(unsigned level) const
Definition pagetable.cc:55
virtual LookupLevel firstS2Level(uint8_t sl0) const =0
virtual LookupLevel lastLevel() const =0
virtual Addr nextLevelPointer(pte_t pte, unsigned level) const =0
virtual unsigned walkBits(unsigned level) const =0
virtual bool isValid(pte_t pte, unsigned level) const =0
virtual LookupLevel firstLevel(uint8_t tsz) const =0
virtual Addr pageMask(pte_t pte, unsigned level) const =0
virtual Addr index(Addr va, unsigned level, int tsz) const =0
virtual bool isLeaf(pte_t pte, unsigned level) const =0
TranslationRegime targetRegime
Definition pagetable.hh:206
TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr, bool uncacheable, bool read_only)
Definition pagetable.hh:264
void updateVaddr(Addr new_vaddr)
Definition pagetable.hh:300
TranslationRegime regime
Definition pagetable.hh:245
LookupLevel lookupLevel
Definition pagetable.hh:217
bool checkRegime(TranslationRegime target_regime) const
Definition pagetable.hh:345
void setAttributes(bool lpae)
Definition pagetable.hh:399
bool match(const Lookup &lookup) const
Definition pagetable.hh:326
std::string print() const
Definition pagetable.hh:406
enums::ArmLookupLevel LookupLevel
Definition pagetable.hh:168
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition pagetable.hh:445
Addr pAddr(Addr va) const
Definition pagetable.hh:351
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition pagetable.hh:415
bool matchAddress(const Lookup &lookup) const
Definition pagetable.hh:312
Addr pageStart() const
Definition pagetable.hh:306
Addr pageMask(pte_t pte, unsigned level) const override
Definition pagetable.cc:118
bool isValid(pte_t pte, unsigned level) const override
Definition pagetable.cc:61
bool isLeaf(pte_t pte, unsigned level) const override
Definition pagetable.cc:72
bool isWritable(pte_t pte, unsigned level, bool stage2) const override
Definition pagetable.cc:83
Addr nextLevelPointer(pte_t pte, unsigned level) const override
Definition pagetable.cc:89
unsigned walkBits(unsigned level) const override
Definition pagetable.cc:129
LookupLevel firstLevel(uint8_t tsz) const override
Definition pagetable.cc:140
LookupLevel lastLevel() const override
Definition pagetable.cc:146
LookupLevel firstS2Level(uint8_t sl0) const override
Definition pagetable.cc:356
unsigned walkBits(unsigned level) const override
Definition pagetable.cc:333
Addr pageMask(pte_t pte, unsigned level) const override
Definition pagetable.cc:319
bool isLeaf(pte_t pte, unsigned level) const override
Definition pagetable.cc:273
LookupLevel firstLevel(uint8_t tsz) const override
Definition pagetable.cc:345
bool isValid(pte_t pte, unsigned level) const override
Definition pagetable.cc:261
LookupLevel lastLevel() const override
Definition pagetable.cc:367
Addr nextLevelPointer(pte_t pte, unsigned level) const override
Definition pagetable.cc:291
bool isWritable(pte_t pte, unsigned level, bool stage2) const override
Definition pagetable.cc:285
unsigned walkBits(unsigned level) const override
Definition pagetable.cc:222
Addr pageMask(pte_t pte, unsigned level) const override
Definition pagetable.cc:210
LookupLevel firstS2Level(uint8_t sl0) const override
Definition pagetable.cc:244
bool isWritable(pte_t pte, unsigned level, bool stage2) const override
Definition pagetable.cc:176
Addr nextLevelPointer(pte_t pte, unsigned level) const override
Definition pagetable.cc:182
LookupLevel lastLevel() const override
Definition pagetable.cc:255
bool isValid(pte_t pte, unsigned level) const override
Definition pagetable.cc:152
bool isLeaf(pte_t pte, unsigned level) const override
Definition pagetable.cc:164
LookupLevel firstLevel(uint8_t tsz) const override
Definition pagetable.cc:234
Addr nextLevelPointer(pte_t pte, unsigned level) const override
Definition pagetable.cc:401
LookupLevel lastLevel() const override
Definition pagetable.cc:470
bool isValid(pte_t pte, unsigned level) const override
Definition pagetable.cc:373
unsigned walkBits(unsigned level) const override
Definition pagetable.cc:438
LookupLevel firstLevel(uint8_t tsz) const override
Definition pagetable.cc:449
Addr pageMask(pte_t pte, unsigned level) const override
Definition pagetable.cc:427
bool isWritable(pte_t pte, unsigned level, bool stage2) const override
Definition pagetable.cc:395
LookupLevel firstS2Level(uint8_t sl0) const override
Definition pagetable.cc:459
bool isLeaf(pte_t pte, unsigned level) const override
Definition pagetable.cc:384

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