gem5  v20.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/riscv/pagetable.hh"
45 #include "arch/riscv/tlb.hh"
46 #include "base/types.hh"
47 #include "mem/packet.hh"
48 #include "params/RiscvPagetableWalker.hh"
49 #include "sim/clocked_object.hh"
50 #include "sim/faults.hh"
51 #include "sim/system.hh"
52 
53 class ThreadContext;
54 
55 namespace RiscvISA
56 {
57  class Walker : public ClockedObject
58  {
59  protected:
60  // Port for accessing memory
61  class WalkerPort : public RequestPort
62  {
63  public:
64  WalkerPort(const std::string &_name, Walker * _walker) :
65  RequestPort(_name, _walker), walker(_walker)
66  {}
67 
68  protected:
70 
71  bool recvTimingResp(PacketPtr pkt);
72  void recvReqRetry();
73  };
74 
75  friend class WalkerPort;
77 
78  // State to track each walk of the page table
80  {
81  friend class Walker;
82  private:
83  enum State {
87  };
88 
89  protected:
95  int level;
96  unsigned inflight;
103  SATP satp;
104  STATUS status;
107  bool timing;
108  bool retrying;
109  bool started;
110  bool squashed;
111  public:
112  WalkerState(Walker * _walker, BaseTLB::Translation *_translation,
113  const RequestPtr &_req, bool _isFunctional = false) :
114  walker(_walker), req(_req), state(Ready),
115  nextState(Ready), level(0), inflight(0),
116  translation(_translation),
117  functional(_isFunctional), timing(false),
118  retrying(false), started(false), squashed(false)
119  {
120  }
121  void initState(ThreadContext * _tc, BaseTLB::Mode _mode,
122  bool _isTiming = false);
123  Fault startWalk();
124  Fault startFunctional(Addr &addr, unsigned &logBytes);
125  bool recvPacket(PacketPtr pkt);
126  unsigned numInflight() const;
127  bool isRetrying();
128  bool wasStarted();
129  bool isTiming();
130  void retry();
131  void squash();
132  std::string name() const {return walker->name();}
133 
134  private:
135  void setupWalk(Addr vaddr);
136  Fault stepWalk(PacketPtr &write);
137  void sendPackets();
138  void endWalk();
139  Fault pageFault(bool present);
140  };
141 
142  friend class WalkerState;
143  // State for timing and atomic accesses (need multiple per walker in
144  // the case of multiple outstanding requests in timing mode)
146  // State for functional accesses (only need one of these per walker)
148 
150  {
153  senderWalk(_senderWalk) {}
154  };
155 
156  public:
157  // Kick off the state machine.
158  Fault start(ThreadContext * _tc, BaseTLB::Translation *translation,
159  const RequestPtr &req, BaseTLB::Mode mode);
161  unsigned &logBytes, BaseTLB::Mode mode);
162  Port &getPort(const std::string &if_name,
163  PortID idx=InvalidPortID) override;
164 
165  protected:
166  // The TLB we're supposed to load.
167  TLB * tlb;
170 
171  // The number of outstanding walks that can be squashed per cycle.
172  unsigned numSquashable;
173 
174  // Wrapper for checking for squashes before starting a translation.
175  void startWalkWrapper();
176 
181 
182  // Functions for dealing with packets.
183  bool recvTimingResp(PacketPtr pkt);
184  void recvReqRetry();
185  bool sendTiming(WalkerState * sendingState, PacketPtr pkt);
186 
187  public:
188 
189  void setTLB(TLB * _tlb)
190  {
191  tlb = _tlb;
192  }
193 
194  typedef RiscvPagetableWalkerParams Params;
195 
196  const Params *
197  params() const
198  {
199  return static_cast<const Params *>(_params);
200  }
201 
202  Walker(const Params *params) :
203  ClockedObject(params), port(name() + ".port", this),
204  funcState(this, NULL, NULL, true), tlb(NULL), sys(params->system),
205  requestorId(sys->getRequestorId(this)),
206  numSquashable(params->num_squash_per_cycle),
208  {
209  }
210  };
211 }
212 
213 #endif // __ARCH_RISCV_PAGE_TABLE_WALKER_HH__
RiscvISA::TlbEntry
Definition: pagetable.hh:78
RiscvISA::Walker::numSquashable
unsigned numSquashable
Definition: pagetable_walker.hh:172
RiscvISA::Walker::params
const Params * params() const
Definition: pagetable_walker.hh:197
RiscvISA::Walker::WalkerState::req
RequestPtr req
Definition: pagetable_walker.hh:92
RiscvISA::mode
mode
Definition: pagetable.hh:42
RiscvISA::Walker::funcState
WalkerState funcState
Definition: pagetable_walker.hh:147
system.hh
RiscvISA::Walker::WalkerState::setupWalk
void setupWalk(Addr vaddr)
Definition: pagetable_walker.cc:419
RiscvISA::Walker::WalkerState::timingFault
Fault timingFault
Definition: pagetable_walker.hh:100
RiscvISA::Walker::WalkerState::timing
bool timing
Definition: pagetable_walker.hh:107
InvalidPortID
const PortID InvalidPortID
Definition: types.hh:238
RiscvISA::Walker::WalkerState::sendPackets
void sendPackets()
Definition: pagetable_walker.cc:505
RiscvISA::Walker::WalkerState::status
STATUS status
Definition: pagetable_walker.hh:104
X86ISA::present
Bitfield< 7 > present
Definition: misc.hh:992
RiscvISA::Walker::sys
System * sys
Definition: pagetable_walker.hh:168
RiscvISA::Walker::WalkerPort::WalkerPort
WalkerPort(const std::string &_name, Walker *_walker)
Definition: pagetable_walker.hh:64
RiscvISA::Walker::WalkerPort::recvTimingResp
bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
Definition: pagetable_walker.cc:102
BaseTLB::Mode
Mode
Definition: tlb.hh:57
RiscvISA::Walker::WalkerState::read
PacketPtr read
Definition: pagetable_walker.hh:98
RiscvISA::Walker::WalkerState::isRetrying
bool isRetrying()
Definition: pagetable_walker.cc:544
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
RiscvISA::Walker::sendTiming
bool sendTiming(WalkerState *sendingState, PacketPtr pkt)
Definition: pagetable_walker.cc:153
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
RiscvISA::Walker::WalkerState::isTiming
bool isTiming()
Definition: pagetable_walker.cc:550
std::vector
STL vector class.
Definition: stl.hh:37
RiscvISA::Walker::WalkerState::endWalk
void endWalk()
Definition: pagetable_walker.cc:411
RiscvISA::Walker::recvTimingResp
bool recvTimingResp(PacketPtr pkt)
Definition: pagetable_walker.cc:108
RiscvISA::Walker::WalkerSenderState::senderWalk
WalkerState * senderWalk
Definition: pagetable_walker.hh:151
RiscvISA::Walker::requestorId
RequestorID requestorId
Definition: pagetable_walker.hh:169
RiscvISA::TLB
Definition: tlb.hh:54
faults.hh
RiscvISA::Walker::WalkerState::started
bool started
Definition: pagetable_walker.hh:109
RiscvISA
Definition: fs_workload.cc:36
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
packet.hh
EventFunctionWrapper
Definition: eventq.hh:1101
RiscvISA::Walker::WalkerPort::walker
Walker * walker
Definition: pagetable_walker.hh:69
RiscvISA::Walker::WalkerState::name
std::string name() const
Definition: pagetable_walker.hh:132
RiscvISA::Walker::start
Fault start(ThreadContext *_tc, BaseTLB::Translation *translation, const RequestPtr &req, BaseTLB::Mode mode)
Definition: pagetable_walker.cc:69
X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:997
RequestorID
uint16_t RequestorID
Definition: request.hh:85
RiscvISA::vaddr
vaddr
Definition: pra_constants.hh:275
RiscvISA::Walker::WalkerState::squashed
bool squashed
Definition: pagetable_walker.hh:110
RiscvISA::Walker::WalkerState::initState
void initState(ThreadContext *_tc, BaseTLB::Mode _mode, bool _isTiming=false)
Definition: pagetable_walker.cc:179
RiscvISA::Walker::WalkerState::level
int level
Definition: pagetable_walker.hh:95
RiscvISA::Walker::WalkerState::entry
TlbEntry entry
Definition: pagetable_walker.hh:97
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
RiscvISA::Walker::WalkerState::Waiting
@ Waiting
Definition: pagetable_walker.hh:85
Packet::SenderState
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition: packet.hh:431
tlb.hh
RiscvISA::Walker::WalkerState::WalkerState
WalkerState(Walker *_walker, BaseTLB::Translation *_translation, const RequestPtr &_req, bool _isFunctional=false)
Definition: pagetable_walker.hh:112
System
Definition: system.hh:73
RiscvISA::Walker::WalkerState
Definition: pagetable_walker.hh:79
RiscvISA::Walker::WalkerState::walker
Walker * walker
Definition: pagetable_walker.hh:90
Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
RiscvISA::Walker::setTLB
void setTLB(TLB *_tlb)
Definition: pagetable_walker.hh:189
RiscvISA::Walker::WalkerState::pmode
PrivilegeMode pmode
Definition: pagetable_walker.hh:105
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
RiscvISA::Walker::WalkerState::startWalk
Fault startWalk()
Definition: pagetable_walker.cc:232
RiscvISA::Walker
Definition: pagetable_walker.hh:57
RiscvISA::Walker::WalkerState::wasStarted
bool wasStarted()
Definition: pagetable_walker.cc:556
RiscvISA::PrivilegeMode
PrivilegeMode
Definition: isa.hh:56
BaseTLB::Translation
Definition: tlb.hh:59
RiscvISA::Walker::WalkerState::pageFault
Fault pageFault(bool present)
Definition: pagetable_walker.cc:575
RiscvISA::Walker::WalkerState::retry
void retry()
Definition: pagetable_walker.cc:568
RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:74
RiscvISA::Walker::tlb
TLB * tlb
Definition: pagetable_walker.hh:167
RiscvISA::Walker::Walker
Walker(const Params *params)
Definition: pagetable_walker.hh:202
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
RiscvISA::Walker::WalkerState::stepWalk
Fault stepWalk(PacketPtr &write)
Definition: pagetable_walker.cc:285
RiscvISA::Walker::WalkerState::mode
BaseTLB::Mode mode
Definition: pagetable_walker.hh:102
RiscvISA::Walker::WalkerState::recvPacket
bool recvPacket(PacketPtr pkt)
Definition: pagetable_walker.cc:445
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
RiscvISA::Walker::startWalkWrapper
void startWalkWrapper()
Definition: pagetable_walker.cc:195
RiscvISA::Walker::WalkerState::numInflight
unsigned numInflight() const
Definition: pagetable_walker.cc:538
RiscvISA::Walker::WalkerState::Ready
@ Ready
Definition: pagetable_walker.hh:84
RiscvISA::Walker::WalkerSenderState
Definition: pagetable_walker.hh:149
RiscvISA::Walker::WalkerState::translation
TLB::Translation * translation
Definition: pagetable_walker.hh:101
RiscvISA::Walker::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: pagetable_walker.cc:170
RiscvISA::Walker::recvReqRetry
void recvReqRetry()
Definition: pagetable_walker.cc:142
types.hh
SimObject::_params
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
RiscvISA::Walker::WalkerState::functional
bool functional
Definition: pagetable_walker.hh:106
clocked_object.hh
RiscvISA::Walker::port
WalkerPort port
Definition: pagetable_walker.hh:76
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
RiscvISA::Walker::WalkerState::retrying
bool retrying
Definition: pagetable_walker.hh:108
RiscvISA::Walker::WalkerState::satp
SATP satp
Definition: pagetable_walker.hh:103
addr
ip6_addr_t addr
Definition: inet.hh:423
RiscvISA::Walker::WalkerSenderState::WalkerSenderState
WalkerSenderState(WalkerState *_senderWalk)
Definition: pagetable_walker.hh:152
RiscvISA::Walker::WalkerState::squash
void squash()
Definition: pagetable_walker.cc:562
RiscvISA::Walker::WalkerState::State
State
Definition: pagetable_walker.hh:83
RiscvISA::Walker::Params
RiscvPagetableWalkerParams Params
Definition: pagetable_walker.hh:194
RiscvISA::Walker::WalkerPort
Definition: pagetable_walker.hh:61
RiscvISA::Walker::startWalkWrapperEvent
EventFunctionWrapper startWalkWrapperEvent
Event used to call startWalkWrapper.
Definition: pagetable_walker.hh:180
std::list
STL list class.
Definition: stl.hh:51
RiscvISA::Walker::WalkerPort::recvReqRetry
void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: pagetable_walker.cc:136
RiscvISA::Walker::WalkerState::state
State state
Definition: pagetable_walker.hh:93
RiscvISA::Walker::startFunctional
Fault startFunctional(ThreadContext *_tc, Addr &addr, unsigned &logBytes, BaseTLB::Mode mode)
Definition: pagetable_walker.cc:94
RiscvISA::Walker::WalkerState::tc
ThreadContext * tc
Definition: pagetable_walker.hh:91
RiscvISA::Walker::WalkerState::inflight
unsigned inflight
Definition: pagetable_walker.hh:96
RiscvISA::Walker::WalkerState::writes
std::vector< PacketPtr > writes
Definition: pagetable_walker.hh:99
RiscvISA::Walker::WalkerState::nextState
State nextState
Definition: pagetable_walker.hh:94
pagetable.hh
RiscvISA::Walker::WalkerState::Translate
@ Translate
Definition: pagetable_walker.hh:86
RiscvISA::Walker::currStates
std::list< WalkerState * > currStates
Definition: pagetable_walker.hh:145
RiscvISA::Walker::WalkerState::startFunctional
Fault startFunctional(Addr &addr, unsigned &logBytes)
Definition: pagetable_walker.cc:261

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17