gem5  v22.1.0.0
pagetable_walker.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 The Hewlett-Packard Development Company
3  * Copyright (c) 2020 Barkhausen Institut
4  * All rights reserved.
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met: redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer;
19  * redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution;
22  * neither the name of the copyright holders nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef __ARCH_RISCV_TABLE_WALKER_HH__
40 #define __ARCH_RISCV_TABLE_WALKER_HH__
41 
42 #include <vector>
43 
44 #include "arch/generic/mmu.hh"
45 #include "arch/riscv/pagetable.hh"
47 #include "arch/riscv/pmp.hh"
48 #include "arch/riscv/tlb.hh"
49 #include "base/types.hh"
50 #include "mem/packet.hh"
51 #include "params/RiscvPagetableWalker.hh"
52 #include "sim/clocked_object.hh"
53 #include "sim/faults.hh"
54 #include "sim/system.hh"
55 
56 namespace gem5
57 {
58 
59 class ThreadContext;
60 
61 namespace RiscvISA
62 {
63  class Walker : public ClockedObject
64  {
65  protected:
66  // Port for accessing memory
67  class WalkerPort : public RequestPort
68  {
69  public:
70  WalkerPort(const std::string &_name, Walker * _walker) :
71  RequestPort(_name, _walker), walker(_walker)
72  {}
73 
74  protected:
76 
77  bool recvTimingResp(PacketPtr pkt);
78  void recvReqRetry();
79  };
80 
81  friend class WalkerPort;
83 
84  // State to track each walk of the page table
86  {
87  friend class Walker;
88  private:
89  enum State
90  {
94  };
95 
96  protected:
102  int level;
103  unsigned inflight;
110  SATP satp;
111  STATUS status;
114  bool timing;
115  bool retrying;
116  bool started;
117  bool squashed;
118  public:
119  WalkerState(Walker * _walker, BaseMMU::Translation *_translation,
120  const RequestPtr &_req, bool _isFunctional = false) :
121  walker(_walker), req(_req), state(Ready),
122  nextState(Ready), level(0), inflight(0),
123  translation(_translation),
124  functional(_isFunctional), timing(false),
125  retrying(false), started(false), squashed(false)
126  {
127  }
128  void initState(ThreadContext * _tc, BaseMMU::Mode _mode,
129  bool _isTiming = false);
130  Fault startWalk();
131  Fault startFunctional(Addr &addr, unsigned &logBytes);
132  bool recvPacket(PacketPtr pkt);
133  unsigned numInflight() const;
134  bool isRetrying();
135  bool wasStarted();
136  bool isTiming();
137  void retry();
138  void squash();
139  std::string name() const {return walker->name();}
140 
141  private:
142  void setupWalk(Addr vaddr);
143  Fault stepWalk(PacketPtr &write);
144  void sendPackets();
145  void endWalk();
146  Fault pageFault(bool present);
147  };
148 
149  friend class WalkerState;
150  // State for timing and atomic accesses (need multiple per walker in
151  // the case of multiple outstanding requests in timing mode)
153  // State for functional accesses (only need one of these per walker)
155 
157  {
160  senderWalk(_senderWalk) {}
161  };
162 
163  public:
164  // Kick off the state machine.
165  Fault start(ThreadContext * _tc, BaseMMU::Translation *translation,
166  const RequestPtr &req, BaseMMU::Mode mode);
168  unsigned &logBytes, BaseMMU::Mode mode);
169  Port &getPort(const std::string &if_name,
170  PortID idx=InvalidPortID) override;
171 
172  protected:
173  // The TLB we're supposed to load.
174  TLB * tlb;
177  PMP * pmp;
179 
180  // The number of outstanding walks that can be squashed per cycle.
181  unsigned numSquashable;
182 
183  // Wrapper for checking for squashes before starting a translation.
184  void startWalkWrapper();
185 
190 
191  // Functions for dealing with packets.
192  bool recvTimingResp(PacketPtr pkt);
193  void recvReqRetry();
194  bool sendTiming(WalkerState * sendingState, PacketPtr pkt);
195 
196  public:
197 
198  void setTLB(TLB * _tlb)
199  {
200  tlb = _tlb;
201  }
202 
203  using Params = RiscvPagetableWalkerParams;
204 
205  Walker(const Params &params) :
206  ClockedObject(params), port(name() + ".port", this),
207  funcState(this, NULL, NULL, true), tlb(NULL), sys(params.system),
208  pma(params.pma_checker),
209  pmp(params.pmp),
210  requestorId(sys->getRequestorId(this)),
211  numSquashable(params.num_squash_per_cycle),
213  {
214  }
215  };
216 
217 } // namespace RiscvISA
218 } // namespace gem5
219 
220 #endif // __ARCH_RISCV_PAGE_TABLE_WALKER_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
const std::string _name
Definition: named.hh:41
virtual std::string name() const
Definition: named.hh:47
Based on the RISC-V ISA privileged specifications V1.11, there is no implementation guidelines on the...
Definition: pma_checker.hh:61
This class helps to implement RISCV's physical memory protection (pmp) primitive.
Definition: pmp.hh:54
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Ports are used to interface objects to each other.
Definition: port.hh:62
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:79
WalkerPort(const std::string &_name, Walker *_walker)
void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
Fault startFunctional(Addr &addr, unsigned &logBytes)
WalkerState(Walker *_walker, BaseMMU::Translation *_translation, const RequestPtr &_req, bool _isFunctional=false)
void initState(ThreadContext *_tc, BaseMMU::Mode _mode, bool _isTiming=false)
Fault startFunctional(ThreadContext *_tc, Addr &addr, unsigned &logBytes, BaseMMU::Mode mode)
EventFunctionWrapper startWalkWrapperEvent
Event used to call startWalkWrapper.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
bool sendTiming(WalkerState *sendingState, PacketPtr pkt)
bool recvTimingResp(PacketPtr pkt)
std::list< WalkerState * > currStates
Fault start(ThreadContext *_tc, BaseMMU::Translation *translation, const RequestPtr &req, BaseMMU::Mode mode)
RiscvPagetableWalkerParams Params
Walker(const Params &params)
ThreadContext is the external interface to all thread state for anything outside of the CPU.
STL list class.
Definition: stl.hh:51
STL vector class.
Definition: stl.hh:37
ClockedObject declaration and implementation.
const Params & params() const
Definition: sim_object.hh:176
Bitfield< 15 > system
Definition: misc.hh:1004
Bitfield< 7 > present
Definition: misc.hh:999
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
const PortID InvalidPortID
Definition: types.hh:246
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
uint16_t RequestorID
Definition: request.hh:95
Declaration of the Packet class.
PMP header file.
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition: packet.hh:468

Generated on Wed Dec 21 2022 10:22:24 for gem5 by doxygen 1.9.1