2 * Copyright (c) 2010, 2012-2013 ARM Limited
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.
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
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.
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.
43 #ifndef __ARCH_ARM_PAGETABLE_H__
44 #define __ARCH_ARM_PAGETABLE_H__
48 #include "arch/arm/isa_traits.hh"
49 #include "arch/arm/utility.hh"
50 #include "arch/arm/vtophys.hh"
51 #include "sim/serialize.hh"
57 VAddr(Addr a) { panic("not implemented yet."); }
61 // ITB/DTB page table entry
64 void serialize(CheckpointOut &cp) const
66 panic("Need to implement PTE serialization\n");
69 void unserialize(CheckpointIn &cp)
71 panic("Need to implement PTE serialization\n");
78 L0 = 0, // AArch64 only
85 // ITB/DTB table entry
86 struct TlbEntry : public Serializable
89 enum class MemoryType : std::uint8_t {
95 enum class DomainType : std::uint8_t {
102 // Matching variables
104 Addr size; // Size of this entry, == Type of TLB Rec
105 Addr vpn; // Virtual Page Number
106 uint64_t attributes; // Memory attributes formatted for PAR
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)
113 uint16_t asid; // Address Space Identifier
114 uint8_t vmid; // Virtual machine Identifier
115 uint8_t N; // Number of bits in pagesize
118 uint8_t ap; // Access permissions bits
119 uint8_t hap; // Hyp access permissions bits
120 DomainType domain; // Access Domain
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
131 // True if the entry targets the non-secure physical address space
133 // True if the entry was brought in from a non-secure page table
135 // Exception level on insert, AARCH64 EL0&1, AARCH32 -> el=1
139 bool nonCacheable; // Can we wrap this in mtype?
145 // Access permissions
146 bool xn; // Execute Never
147 bool pxn; // Privileged Execute Never (LPAE only)
149 //Construct an entry that maps to physical address addr for SE mode
150 TlbEntry(Addr _asn, Addr _vaddr, Addr _paddr,
151 bool uncacheable, bool read_only) :
152 pfn(_paddr >> PageShift), size(PageBytes - 1), vpn(_vaddr >> PageShift),
153 attributes(0), lookupLevel(L1), asid(_asn), vmid(0), N(0),
154 innerAttrs(0), outerAttrs(0), ap(read_only ? 0x3 : 0), hap(0x3),
155 domain(DomainType::Client), mtype(MemoryType::StronglyOrdered),
156 longDescFormat(false), isHyp(false), global(false), valid(true),
157 ns(true), nstid(true), el(EL0), nonCacheable(uncacheable),
158 shareable(false), outerShareable(false), xn(0), pxn(0)
160 // no restrictions by default, hap = 0x3
162 // @todo Check the memory type
164 warn("ARM TlbEntry does not support read-only mappings\n");
168 pfn(0), size(0), vpn(0), attributes(0), lookupLevel(L1), asid(0),
169 vmid(0), N(0), innerAttrs(0), outerAttrs(0), ap(0), hap(0x3),
170 domain(DomainType::Client), mtype(MemoryType::StronglyOrdered),
171 longDescFormat(false), isHyp(false), global(false), valid(false),
172 ns(true), nstid(true), el(EL0), nonCacheable(false),
173 shareable(false), outerShareable(false), xn(0), pxn(0)
175 // no restrictions by default, hap = 0x3
177 // @todo Check the memory type
181 updateVaddr(Addr new_vaddr)
183 vpn = new_vaddr >> PageShift;
189 return pfn << PageShift;
193 match(Addr va, uint8_t _vmid, bool hypLookUp, bool secure_lookup,
194 ExceptionLevel target_el) const
196 return match(va, 0, _vmid, hypLookUp, secure_lookup, true, target_el);
200 match(Addr va, uint16_t asn, uint8_t _vmid, bool hypLookUp,
201 bool secure_lookup, bool ignore_asn, ExceptionLevel target_el) const
206 if (valid && va >= v && va <= v + size && (secure_lookup == !nstid) &&
207 (hypLookUp == isHyp))
209 match = checkELMatch(target_el);
211 if (match && !ignore_asn) {
212 match = global || (asn == asid);
214 if (match && nstid) {
215 match = isHyp || (_vmid == vmid);
222 checkELMatch(ExceptionLevel target_el) const
224 if (target_el == EL2 || target_el == EL3) {
225 return (el == target_el);
227 return (el == EL0) || (el == EL1);
234 return (pfn << N) | (va & size);
243 // chec bit 11 to determine if its currently LPAE or VMSA format.
244 if ( attributes & (1 << 11) ) {
245 newBits = ((outerShareable ? 0x2 :
246 shareable ? 0x3 : 0) << 7);
249 /** Formatting for Physical Address Register (PAR)
250 * Only including lower bits (TLB info here)
251 * PAR (32-bit format):
253 * LPAE [11] (Large Physical Address Extension)
255 * NOS [10] (Not Outer Sharable)
256 * NS [9] (Non-Secure)
257 * -- [8] (Implementation Defined)
259 * Inner[6:4](Inner memory attributes)
260 * Outer[3:2](Outer memory attributes)
261 * SS [1] (SuperSection)
262 * F [0] (Fault, Fault Status in [6:1] if faulted)
264 newBits = ((outerShareable ? 0:1) << 10) |
265 ((shareable ? 1:0) << 7) |
268 // TODO: Supersection bit
272 newBits |= ns << 9; // NS bit
274 // add in the new bits
276 attributes |= newBits;
280 setAttributes(bool lpae)
282 attributes = lpae ? (1 << 11) : 0;
289 return csprintf("%#x, asn %d vmn %d hyp %d ppn %#x size: %#x ap:%d "
290 "ns:%d nstid:%d g:%d el:%d", vpn << N, asid, vmid,
291 isHyp, pfn << N, size, ap, ns, nstid, global, el);
295 serialize(CheckpointOut &cp) const override
297 SERIALIZE_SCALAR(longDescFormat);
298 SERIALIZE_SCALAR(pfn);
299 SERIALIZE_SCALAR(size);
300 SERIALIZE_SCALAR(vpn);
301 SERIALIZE_SCALAR(asid);
302 SERIALIZE_SCALAR(vmid);
303 SERIALIZE_SCALAR(isHyp);
305 SERIALIZE_SCALAR(global);
306 SERIALIZE_SCALAR(valid);
307 SERIALIZE_SCALAR(ns);
308 SERIALIZE_SCALAR(nstid);
309 SERIALIZE_SCALAR(nonCacheable);
310 SERIALIZE_ENUM(lookupLevel);
311 SERIALIZE_ENUM(mtype);
312 SERIALIZE_SCALAR(innerAttrs);
313 SERIALIZE_SCALAR(outerAttrs);
314 SERIALIZE_SCALAR(shareable);
315 SERIALIZE_SCALAR(outerShareable);
316 SERIALIZE_SCALAR(attributes);
317 SERIALIZE_SCALAR(xn);
318 SERIALIZE_SCALAR(pxn);
319 SERIALIZE_SCALAR(ap);
320 SERIALIZE_SCALAR(hap);
321 uint8_t domain_ = static_cast<uint8_t>(domain);
322 paramOut(cp, "domain", domain_);
325 unserialize(CheckpointIn &cp) override
327 UNSERIALIZE_SCALAR(longDescFormat);
328 UNSERIALIZE_SCALAR(pfn);
329 UNSERIALIZE_SCALAR(size);
330 UNSERIALIZE_SCALAR(vpn);
331 UNSERIALIZE_SCALAR(asid);
332 UNSERIALIZE_SCALAR(vmid);
333 UNSERIALIZE_SCALAR(isHyp);
334 UNSERIALIZE_SCALAR(N);
335 UNSERIALIZE_SCALAR(global);
336 UNSERIALIZE_SCALAR(valid);
337 UNSERIALIZE_SCALAR(ns);
338 UNSERIALIZE_SCALAR(nstid);
339 UNSERIALIZE_SCALAR(nonCacheable);
340 UNSERIALIZE_ENUM(lookupLevel);
341 UNSERIALIZE_ENUM(mtype);
342 UNSERIALIZE_SCALAR(innerAttrs);
343 UNSERIALIZE_SCALAR(outerAttrs);
344 UNSERIALIZE_SCALAR(shareable);
345 UNSERIALIZE_SCALAR(outerShareable);
346 UNSERIALIZE_SCALAR(attributes);
347 UNSERIALIZE_SCALAR(xn);
348 UNSERIALIZE_SCALAR(pxn);
349 UNSERIALIZE_SCALAR(ap);
350 UNSERIALIZE_SCALAR(hap);
352 paramIn(cp, "domain", domain_);
353 domain = static_cast<DomainType>(domain_);
361 #endif // __ARCH_ARM_PAGETABLE_H__