2 * Copyright (c) 2010-2012 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 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #ifndef __ARCH_ARM_TABLE_WALKER_HH__
41 #define __ARCH_ARM_TABLE_WALKER_HH__
45 #include "arch/arm/miscregs.hh"
46 #include "arch/arm/tlb.hh"
47 #include "dev/io_device.hh"
48 #include "mem/mem_object.hh"
49 #include "mem/request.hh"
50 #include "params/ArmTableWalker.hh"
51 #include "sim/eventq.hh"
52 #include "sim/fault_fwd.hh"
60 class TableWalker : public MemObject
64 /** Type of page table entry ARM DDI 0406B: B3-8*/
72 /** The raw bits of the entry */
75 /** This entry has been modified (access flag set) and needs to be
76 * written back to memory */
79 EntryType type() const
81 return (EntryType)(data & 0x3);
84 /** Is the page a Supersection (16MB)?*/
85 bool supersection() const
87 return bits(data, 18);
90 /** Return the physcal address of the entry, bits in position*/
94 panic("Super sections not implemented\n");
95 return mbits(data, 31, 20);
97 /** Return the physcal address of the entry, bits in position*/
98 Addr paddr(Addr va) const
101 panic("Super sections not implemented\n");
102 return mbits(data, 31, 20) | mbits(va, 19, 0);
106 /** Return the physical frame, bits shifted right */
110 panic("Super sections not implemented\n");
111 return bits(data, 31, 20);
114 /** Is the translation global (no asid used)? */
117 return bits(data, 17);
120 /** Is the translation not allow execution? */
123 return bits(data, 4);
126 /** Three bit access protection flags */
129 return (bits(data, 15) << 2) | bits(data, 11, 10);
132 /** Domain Client/Manager: ARM DDI 0406B: B3-31 */
133 uint8_t domain() const
135 return bits(data, 8, 5);
138 /** Address of L2 descriptor if it exists */
141 return mbits(data, 31, 10);
144 /** Memory region attributes: ARM DDI 0406B: B3-32.
145 * These bits are largly ignored by M5 and only used to
146 * provide the illusion that the memory system cares about
147 * anything but cachable vs. uncachable.
149 uint8_t texcb() const
151 return bits(data, 2) | bits(data, 3) << 1 | bits(data, 14, 12) << 2;
154 /** If the section is shareable. See texcb() comment. */
155 bool shareable() const
157 return bits(data, 16);
160 /** Set access flag that this entry has been touched. Mark
161 * the entry as requiring a writeback, in the future.
169 /** This entry needs to be written back to memory */
176 /** Level 2 page table descriptor */
177 struct L2Descriptor {
179 /** The raw bits of the entry. */
182 /** This entry has been modified (access flag set) and needs to be
183 * written back to memory */
186 /** Is the entry invalid */
189 return bits(data, 1, 0) == 0;
192 /** What is the size of the mapping? */
195 return bits(data, 1) == 0;
198 /** Is execution allowed on this mapping? */
201 return large() ? bits(data, 15) : bits(data, 0);
204 /** Is the translation global (no asid used)? */
207 return !bits(data, 11);
210 /** Three bit access protection flags */
213 return bits(data, 5, 4) | (bits(data, 9) << 2);
216 /** Memory region attributes: ARM DDI 0406B: B3-32 */
217 uint8_t texcb() const
220 (bits(data, 2) | (bits(data, 3) << 1) | (bits(data, 14, 12) << 2)) :
221 (bits(data, 2) | (bits(data, 3) << 1) | (bits(data, 8, 6) << 2));
224 /** Return the physical frame, bits shifted right */
227 return large() ? bits(data, 31, 16) : bits(data, 31, 12);
230 /** Return complete physical address given a VA */
231 Addr paddr(Addr va) const
234 return mbits(data, 31, 16) | mbits(va, 15, 0);
236 return mbits(data, 31, 12) | mbits(va, 11, 0);
239 /** If the section is shareable. See texcb() comment. */
240 bool shareable() const
242 return bits(data, 10);
245 /** Set access flag that this entry has been touched. Mark
246 * the entry as requiring a writeback, in the future.
254 /** This entry needs to be written back to memory */
265 * A snooping DMA port that currently does nothing besides
266 * extending the DMA port to accept snoops without complaining.
268 class SnoopingDmaPort : public DmaPort
273 virtual void recvTimingSnoopReq(PacketPtr pkt)
276 virtual Tick recvAtomicSnoop(PacketPtr pkt)
279 virtual void recvFunctionalSnoop(PacketPtr pkt)
282 virtual bool isSnooping() const { return true; }
287 * A snooping DMA port merely calls the construtor of the DMA
290 SnoopingDmaPort(MemObject *dev, System *s, Tick min_backoff,
292 DmaPort(dev, s, min_backoff, max_backoff)
296 struct WalkerState //: public SimObject
298 /** Thread context that we're doing the walk for */
301 /** Request that is currently being serviced */
304 /** Context ID that we're servicing the request under */
307 /** Translation state for delayed requests */
308 TLB::Translation *transState;
310 /** The fault that we are going to return */
313 /** The virtual address that is being translated */
316 /** Cached copy of the sctlr as it existed when translation began */
319 /** Width of the base address held in TTRB0 */
322 /** If the access is a write */
325 /** If the access is a fetch (for execution, and no-exec) must be checked?*/
328 /** If the mode is timing or atomic */
331 /** If the atomic mode should be functional */
334 /** Save mode for use in delayed response */
340 /** Whether L1/L2 descriptor response is delayed in timing mode */
343 TableWalker *tableWalker;
345 void doL1Descriptor();
346 void doL2Descriptor();
348 std::string name() const {return tableWalker->name();}
352 /** Queue of requests that need processing first level translation */
353 std::list<WalkerState *> stateQueueL1;
355 /** Queue of requests that have passed first level translation and
356 * require an additional level. */
357 std::list<WalkerState *> stateQueueL2;
359 /** Queue of requests that have passed are waiting because the walker is
361 std::list<WalkerState *> pendingQueue;
364 /** Port to issue translation requests from */
365 SnoopingDmaPort port;
367 /** TLB that is initiating these table walks */
370 /** Cached copy of the sctlr as it existed when translation began */
373 WalkerState *currState;
375 /** If a timing translation is currently in progress */
378 /** Request id for requests generated by this walker */
382 typedef ArmTableWalkerParams Params;
383 TableWalker(const Params *p);
384 virtual ~TableWalker();
389 return dynamic_cast<const Params *>(_params);
392 virtual unsigned int drain(Event *de);
393 virtual void resume();
394 virtual MasterPort& getMasterPort(const std::string &if_name,
397 Fault walk(RequestPtr req, ThreadContext *tc, uint8_t cid, TLB::Mode mode,
398 TLB::Translation *_trans, bool timing, bool functional = false);
400 void setTlb(TLB *_tlb) { tlb = _tlb; }
401 void memAttrs(ThreadContext *tc, TlbEntry &te, SCTLR sctlr,
402 uint8_t texcb, bool s);
406 void doL1Descriptor();
407 void doL1DescriptorWrapper();
408 EventWrapper<TableWalker, &TableWalker::doL1DescriptorWrapper> doL1DescEvent;
410 void doL2Descriptor();
411 void doL2DescriptorWrapper();
412 EventWrapper<TableWalker, &TableWalker::doL2DescriptorWrapper> doL2DescEvent;
415 void processWalkWrapper();
416 EventWrapper<TableWalker, &TableWalker::processWalkWrapper> doProcessEvent;
418 void nextWalk(ThreadContext *tc);
422 } // namespace ArmISA
424 #endif //__ARCH_ARM_TABLE_WALKER_HH__