pagetable.hh (8902:75b524b64c28) pagetable.hh (10037:5cac77888310)
1/*
1/*
2 * Copyright (c) 2010 ARM Limited
2 * Copyright (c) 2010, 2012-2013 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

--- 27 unchanged lines hidden (view full) ---

38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ali Saidi
41 */
42
43#ifndef __ARCH_ARM_PAGETABLE_H__
44#define __ARCH_ARM_PAGETABLE_H__
45
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

--- 27 unchanged lines hidden (view full) ---

38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ali Saidi
41 */
42
43#ifndef __ARCH_ARM_PAGETABLE_H__
44#define __ARCH_ARM_PAGETABLE_H__
45
46#include <cstdint>
47
46#include "arch/arm/isa_traits.hh"
47#include "arch/arm/utility.hh"
48#include "arch/arm/vtophys.hh"
49#include "sim/serialize.hh"
50
51namespace ArmISA {
52
53struct VAddr

--- 12 unchanged lines hidden (view full) ---

66
67 void unserialize(Checkpoint *cp, const std::string &section)
68 {
69 panic("Need to implement PTE serialization\n");
70 }
71
72};
73
48#include "arch/arm/isa_traits.hh"
49#include "arch/arm/utility.hh"
50#include "arch/arm/vtophys.hh"
51#include "sim/serialize.hh"
52
53namespace ArmISA {
54
55struct VAddr

--- 12 unchanged lines hidden (view full) ---

68
69 void unserialize(Checkpoint *cp, const std::string &section)
70 {
71 panic("Need to implement PTE serialization\n");
72 }
73
74};
75
76// Lookup level
77enum LookupLevel {
78 L0 = 0, // AArch64 only
79 L1,
80 L2,
81 L3,
82 MAX_LOOKUP_LEVELS
83};
84
74// ITB/DTB table entry
75struct TlbEntry
76{
77 public:
85// ITB/DTB table entry
86struct TlbEntry
87{
88 public:
78 enum MemoryType {
89 enum class MemoryType : std::uint8_t {
79 StronglyOrdered,
80 Device,
81 Normal
82 };
90 StronglyOrdered,
91 Device,
92 Normal
93 };
83 enum DomainType {
84 DomainNoAccess = 0,
85 DomainClient,
86 DomainReserved,
87 DomainManager
94
95 enum class DomainType : std::uint8_t {
96 NoAccess = 0,
97 Client,
98 Reserved,
99 Manager
88 };
89
90 // Matching variables
91 Addr pfn;
92 Addr size; // Size of this entry, == Type of TLB Rec
93 Addr vpn; // Virtual Page Number
100 };
101
102 // Matching variables
103 Addr pfn;
104 Addr size; // Size of this entry, == Type of TLB Rec
105 Addr vpn; // Virtual Page Number
94 uint32_t asid; // Address Space Identifier
106 uint64_t attributes; // Memory attributes formatted for PAR
107
108 LookupLevel lookupLevel; // Lookup level where the descriptor was fetched
109 // from. Used to set the FSR for faults
110 // occurring while the long desc. format is in
111 // use (AArch32 w/ LPAE and AArch64)
112
113 uint16_t asid; // Address Space Identifier
114 uint8_t vmid; // Virtual machine Identifier
95 uint8_t N; // Number of bits in pagesize
115 uint8_t N; // Number of bits in pagesize
116 uint8_t innerAttrs;
117 uint8_t outerAttrs;
118 uint8_t ap; // Access permissions bits
119 uint8_t hap; // Hyp access permissions bits
120 DomainType domain; // Access Domain
121
122 MemoryType mtype;
123
124 // True if the long descriptor format is used for this entry (LPAE only)
125 bool longDescFormat; // @todo use this in the update attribute bethod
126
127 bool isHyp;
96 bool global;
97 bool valid;
98
128 bool global;
129 bool valid;
130
131 // True if the entry targets the non-secure physical address space
132 bool ns;
133 // True if the entry was brought in from a non-secure page table
134 bool nstid;
135 // Exception level on insert, AARCH64 EL0&1, AARCH32 -> el=1
136 uint8_t el;
137
99 // Type of memory
100 bool nonCacheable; // Can we wrap this in mtype?
138 // Type of memory
139 bool nonCacheable; // Can we wrap this in mtype?
101 bool sNp; // Section descriptor
102
103 // Memory Attributes
140
141 // Memory Attributes
104 MemoryType mtype;
105 uint8_t innerAttrs;
106 uint8_t outerAttrs;
107 bool shareable;
142 bool shareable;
108 uint32_t attributes; // Memory attributes formatted for PAR
143 bool outerShareable;
109
144
110
111 // Access permissions
112 bool xn; // Execute Never
145 // Access permissions
146 bool xn; // Execute Never
113 uint8_t ap; // Access permissions bits
114 uint8_t domain; // Access Domain
147 bool pxn; // Privileged Execute Never (LPAE only)
115
116 //Construct an entry that maps to physical address addr for SE mode
148
149 //Construct an entry that maps to physical address addr for SE mode
117 TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr)
150 TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr) :
151 pfn(_paddr >> PageShift), size(PageBytes - 1), vpn(_vaddr >> PageShift),
152 attributes(0), lookupLevel(L1), asid(_asn), vmid(0), N(0),
153 innerAttrs(0), outerAttrs(0), ap(0), hap(0x3),
154 domain(DomainType::Client), mtype(MemoryType::StronglyOrdered),
155 longDescFormat(false), isHyp(false), global(false), valid(true),
156 ns(true), nstid(true), el(0), nonCacheable(false), shareable(false),
157 outerShareable(false), xn(0), pxn(0)
118 {
158 {
119 pfn = _paddr >> PageShift;
120 size = PageBytes - 1;
121 asid = _asn;
122 global = false;
123 valid = true;
159 // no restrictions by default, hap = 0x3
124
160
125 vpn = _vaddr >> PageShift;
161 // @todo Check the memory type
162 }
126
163
127 nonCacheable = sNp = false;
164 TlbEntry() :
165 pfn(0), size(0), vpn(0), attributes(0), lookupLevel(L1), asid(0),
166 vmid(0), N(0), innerAttrs(0), outerAttrs(0), ap(0), hap(0x3),
167 domain(DomainType::Client), mtype(MemoryType::StronglyOrdered),
168 longDescFormat(false), isHyp(false), global(false), valid(true),
169 ns(true), nstid(true), el(0), nonCacheable(false),
170 shareable(false), outerShareable(false), xn(0), pxn(0)
171 {
172 // no restrictions by default, hap = 0x3
128
173
129 xn = 0;
130 ap = 0; // ???
131 domain = DomainClient; //???
174 // @todo Check the memory type
132 }
133
175 }
176
134 TlbEntry()
135 {}
136
137 void
138 updateVaddr(Addr new_vaddr)
139 {
140 vpn = new_vaddr >> PageShift;
141 }
142
143 Addr
177 void
178 updateVaddr(Addr new_vaddr)
179 {
180 vpn = new_vaddr >> PageShift;
181 }
182
183 Addr
144 pageStart()
184 pageStart() const
145 {
146 return pfn << PageShift;
147 }
148
149 bool
185 {
186 return pfn << PageShift;
187 }
188
189 bool
150 match(Addr va, uint8_t cid)
190 match(Addr va, uint8_t _vmid, bool hypLookUp, bool secure_lookup,
191 uint8_t target_el) const
151 {
192 {
193 return match(va, 0, _vmid, hypLookUp, secure_lookup, true, target_el);
194 }
195
196 bool
197 match(Addr va, uint16_t asn, uint8_t _vmid, bool hypLookUp,
198 bool secure_lookup, bool ignore_asn, uint8_t target_el) const
199 {
200 bool match = false;
152 Addr v = vpn << N;
201 Addr v = vpn << N;
153 if (valid && va >= v && va <= v + size && (global || cid == asid))
154 return true;
155 return false;
202
203 if (valid && va >= v && va <= v + size && (secure_lookup == !nstid) &&
204 (hypLookUp == isHyp))
205 {
206 if (target_el == 2 || target_el == 3)
207 match = (el == target_el);
208 else
209 match = (el == 0) || (el == 1);
210 if (match && !ignore_asn) {
211 match = global || (asn == asid);
212 }
213 if (match && nstid) {
214 match = isHyp || (_vmid == vmid);
215 }
216 }
217 return match;
156 }
157
158 Addr
218 }
219
220 Addr
159 pAddr(Addr va)
221 pAddr(Addr va) const
160 {
161 return (pfn << N) | (va & size);
162 }
163
164 void
222 {
223 return (pfn << N) | (va & size);
224 }
225
226 void
227 updateAttributes()
228 {
229 uint64_t mask;
230 uint64_t newBits;
231
232 // chec bit 11 to determine if its currently LPAE or VMSA format.
233 if ( attributes & (1 << 11) ) {
234 newBits = ((outerShareable ? 0x2 :
235 shareable ? 0x3 : 0) << 7);
236 mask = 0x180;
237 } else {
238 /** Formatting for Physical Address Register (PAR)
239 * Only including lower bits (TLB info here)
240 * PAR (32-bit format):
241 * PA [31:12]
242 * LPAE [11] (Large Physical Address Extension)
243 * TLB info [10:1]
244 * NOS [10] (Not Outer Sharable)
245 * NS [9] (Non-Secure)
246 * -- [8] (Implementation Defined)
247 * SH [7] (Sharable)
248 * Inner[6:4](Inner memory attributes)
249 * Outer[3:2](Outer memory attributes)
250 * SS [1] (SuperSection)
251 * F [0] (Fault, Fault Status in [6:1] if faulted)
252 */
253 newBits = ((outerShareable ? 0:1) << 10) |
254 ((shareable ? 1:0) << 7) |
255 (innerAttrs << 4) |
256 (outerAttrs << 2);
257 // TODO: Supersection bit
258 mask = 0x4FC;
259 }
260 // common bits
261 newBits |= ns << 9; // NS bit
262 mask |= 1 << 9;
263 // add in the new bits
264 attributes &= ~mask;
265 attributes |= newBits;
266 }
267
268 void
269 setAttributes(bool lpae)
270 {
271 attributes = lpae ? (1 << 11) : 0;
272 updateAttributes();
273 }
274
275 std::string
276 print() const
277 {
278 return csprintf("%#x, asn %d vmn %d hyp %d ppn %#x size: %#x ap:%d "
279 "ns:%d nstid:%d g:%d el:%d", vpn << N, asid, vmid,
280 isHyp, pfn << N, size, ap, ns, nstid, global, el);
281 }
282
283 void
165 serialize(std::ostream &os)
166 {
284 serialize(std::ostream &os)
285 {
286 SERIALIZE_SCALAR(longDescFormat);
167 SERIALIZE_SCALAR(pfn);
168 SERIALIZE_SCALAR(size);
169 SERIALIZE_SCALAR(vpn);
170 SERIALIZE_SCALAR(asid);
287 SERIALIZE_SCALAR(pfn);
288 SERIALIZE_SCALAR(size);
289 SERIALIZE_SCALAR(vpn);
290 SERIALIZE_SCALAR(asid);
291 SERIALIZE_SCALAR(vmid);
292 SERIALIZE_SCALAR(isHyp);
171 SERIALIZE_SCALAR(N);
172 SERIALIZE_SCALAR(global);
173 SERIALIZE_SCALAR(valid);
293 SERIALIZE_SCALAR(N);
294 SERIALIZE_SCALAR(global);
295 SERIALIZE_SCALAR(valid);
296 SERIALIZE_SCALAR(ns);
297 SERIALIZE_SCALAR(nstid);
174 SERIALIZE_SCALAR(nonCacheable);
298 SERIALIZE_SCALAR(nonCacheable);
175 SERIALIZE_SCALAR(sNp);
299 SERIALIZE_ENUM(lookupLevel);
176 SERIALIZE_ENUM(mtype);
177 SERIALIZE_SCALAR(innerAttrs);
178 SERIALIZE_SCALAR(outerAttrs);
179 SERIALIZE_SCALAR(shareable);
300 SERIALIZE_ENUM(mtype);
301 SERIALIZE_SCALAR(innerAttrs);
302 SERIALIZE_SCALAR(outerAttrs);
303 SERIALIZE_SCALAR(shareable);
304 SERIALIZE_SCALAR(outerShareable);
180 SERIALIZE_SCALAR(attributes);
181 SERIALIZE_SCALAR(xn);
305 SERIALIZE_SCALAR(attributes);
306 SERIALIZE_SCALAR(xn);
307 SERIALIZE_SCALAR(pxn);
182 SERIALIZE_SCALAR(ap);
308 SERIALIZE_SCALAR(ap);
183 SERIALIZE_SCALAR(domain);
309 SERIALIZE_SCALAR(hap);
310 uint8_t domain_ = static_cast<uint8_t>(domain);
311 paramOut(os, "domain", domain_);
184 }
185 void
186 unserialize(Checkpoint *cp, const std::string &section)
187 {
312 }
313 void
314 unserialize(Checkpoint *cp, const std::string &section)
315 {
316 UNSERIALIZE_SCALAR(longDescFormat);
188 UNSERIALIZE_SCALAR(pfn);
189 UNSERIALIZE_SCALAR(size);
190 UNSERIALIZE_SCALAR(vpn);
191 UNSERIALIZE_SCALAR(asid);
317 UNSERIALIZE_SCALAR(pfn);
318 UNSERIALIZE_SCALAR(size);
319 UNSERIALIZE_SCALAR(vpn);
320 UNSERIALIZE_SCALAR(asid);
321 UNSERIALIZE_SCALAR(vmid);
322 UNSERIALIZE_SCALAR(isHyp);
192 UNSERIALIZE_SCALAR(N);
193 UNSERIALIZE_SCALAR(global);
194 UNSERIALIZE_SCALAR(valid);
323 UNSERIALIZE_SCALAR(N);
324 UNSERIALIZE_SCALAR(global);
325 UNSERIALIZE_SCALAR(valid);
326 UNSERIALIZE_SCALAR(ns);
327 UNSERIALIZE_SCALAR(nstid);
195 UNSERIALIZE_SCALAR(nonCacheable);
328 UNSERIALIZE_SCALAR(nonCacheable);
196 UNSERIALIZE_SCALAR(sNp);
329 UNSERIALIZE_ENUM(lookupLevel);
197 UNSERIALIZE_ENUM(mtype);
198 UNSERIALIZE_SCALAR(innerAttrs);
199 UNSERIALIZE_SCALAR(outerAttrs);
200 UNSERIALIZE_SCALAR(shareable);
330 UNSERIALIZE_ENUM(mtype);
331 UNSERIALIZE_SCALAR(innerAttrs);
332 UNSERIALIZE_SCALAR(outerAttrs);
333 UNSERIALIZE_SCALAR(shareable);
334 UNSERIALIZE_SCALAR(outerShareable);
201 UNSERIALIZE_SCALAR(attributes);
202 UNSERIALIZE_SCALAR(xn);
335 UNSERIALIZE_SCALAR(attributes);
336 UNSERIALIZE_SCALAR(xn);
337 UNSERIALIZE_SCALAR(pxn);
203 UNSERIALIZE_SCALAR(ap);
338 UNSERIALIZE_SCALAR(ap);
204 UNSERIALIZE_SCALAR(domain);
339 UNSERIALIZE_SCALAR(hap);
340 uint8_t domain_;
341 paramIn(cp, section, "domain", domain_);
342 domain = static_cast<DomainType>(domain_);
205 }
206
207};
208
209
210
211}
212#endif // __ARCH_ARM_PAGETABLE_H__
213
343 }
344
345};
346
347
348
349}
350#endif // __ARCH_ARM_PAGETABLE_H__
351