gem5  v20.1.0.0
addr_mapper.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 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
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
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.
24  *
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.
36  */
37 
38 #include "mem/addr_mapper.hh"
39 
40 AddrMapper::AddrMapper(const AddrMapperParams* p)
41  : SimObject(p),
42  memSidePort(name() + "-mem_side_port", *this),
43  cpuSidePort(name() + "-cpu_side_port", *this)
44 {
45 }
46 
47 void
49 {
51  fatal("Address mapper is not connected on both sides.\n");
52 }
53 
54 Port &
55 AddrMapper::getPort(const std::string &if_name, PortID idx)
56 {
57  if (if_name == "mem_side_port") {
58  return memSidePort;
59  } else if (if_name == "cpu_side_port") {
60  return cpuSidePort;
61  } else {
62  return SimObject::getPort(if_name, idx);
63  }
64 }
65 
66 void
68 {
69  Addr orig_addr = pkt->getAddr();
70  pkt->setAddr(remapAddr(orig_addr));
72  pkt->setAddr(orig_addr);
73 }
74 
75 void
77 {
78  Addr orig_addr = pkt->getAddr();
79  pkt->setAddr(remapAddr(orig_addr));
81  pkt->setAddr(orig_addr);
82 }
83 
84 Tick
86 {
87  Addr orig_addr = pkt->getAddr();
88  pkt->setAddr(remapAddr(orig_addr));
89  Tick ret_tick = memSidePort.sendAtomic(pkt);
90  pkt->setAddr(orig_addr);
91  return ret_tick;
92 }
93 
94 Tick
96 {
97  Addr orig_addr = pkt->getAddr();
98  pkt->setAddr(remapAddr(orig_addr));
99  Tick ret_tick = cpuSidePort.sendAtomicSnoop(pkt);
100  pkt->setAddr(orig_addr);
101  return ret_tick;
102 }
103 
104 bool
106 {
107  Addr orig_addr = pkt->getAddr();
108  bool needsResponse = pkt->needsResponse();
109  bool cacheResponding = pkt->cacheResponding();
110 
111  if (needsResponse && !cacheResponding) {
112  pkt->pushSenderState(new AddrMapperSenderState(orig_addr));
113  }
114 
115  pkt->setAddr(remapAddr(orig_addr));
116 
117  // Attempt to send the packet
118  bool successful = memSidePort.sendTimingReq(pkt);
119 
120  // If not successful, restore the address and sender state
121  if (!successful) {
122  pkt->setAddr(orig_addr);
123 
124  if (needsResponse) {
125  delete pkt->popSenderState();
126  }
127  }
128 
129  return successful;
130 }
131 
132 bool
134 {
135  AddrMapperSenderState* receivedState =
136  dynamic_cast<AddrMapperSenderState*>(pkt->senderState);
137 
138  // Restore initial sender state
139  if (receivedState == NULL)
140  panic("AddrMapper %s got a response without sender state\n",
141  name());
142 
143  Addr remapped_addr = pkt->getAddr();
144 
145  // Restore the state and address
146  pkt->senderState = receivedState->predecessor;
147  pkt->setAddr(receivedState->origAddr);
148 
149  // Attempt to send the packet
150  bool successful = cpuSidePort.sendTimingResp(pkt);
151 
152  // If packet successfully sent, delete the sender state, otherwise
153  // restore state
154  if (successful) {
155  delete receivedState;
156  } else {
157  // Don't delete anything and let the packet look like we did
158  // not touch it
159  pkt->senderState = receivedState;
160  pkt->setAddr(remapped_addr);
161  }
162  return successful;
163 }
164 
165 void
167 {
169 }
170 
171 bool
173 {
174  return memSidePort.sendTimingSnoopResp(pkt);
175 }
176 
177 bool
179 {
180  if (cpuSidePort.isSnooping())
181  fatal("AddrMapper doesn't support remapping of snooping requests\n");
182  return false;
183 }
184 
185 void
187 {
189 }
190 
191 void
193 {
195 }
196 
197 void
199 {
201 }
202 
203 RangeAddrMapper::RangeAddrMapper(const RangeAddrMapperParams* p) :
204  AddrMapper(p),
205  originalRanges(p->original_ranges),
206  remappedRanges(p->remapped_ranges)
207 {
208  if (originalRanges.size() != remappedRanges.size())
209  fatal("AddrMapper: original and shadowed range list must "
210  "be same size\n");
211 
212  for (size_t x = 0; x < originalRanges.size(); x++) {
213  if (originalRanges[x].size() != remappedRanges[x].size())
214  fatal("AddrMapper: original and shadowed range list elements"
215  " aren't all of the same size\n");
216  }
217 }
218 
220 RangeAddrMapperParams::create()
221 {
222  return new RangeAddrMapper(this);
223 }
224 
225 Addr
227 {
228  for (int i = 0; i < originalRanges.size(); ++i) {
229  if (originalRanges[i].contains(addr)) {
230  Addr offset = addr - originalRanges[i].start();
231  return offset + remappedRanges[i].start();
232  }
233  }
234 
235  return addr;
236 }
237 
240 {
241  // Simply return the original ranges as given by the parameters
242  AddrRangeList ranges(originalRanges.begin(), originalRanges.end());
243  return ranges;
244 }
245 
246 
AddrMapper::recvTimingSnoopResp
bool recvTimingSnoopResp(PacketPtr pkt)
Definition: addr_mapper.cc:172
RangeAddrMapper::remappedRanges
std::vector< AddrRange > remappedRanges
This contains a list of ranges that addresses should be remapped to.
Definition: addr_mapper.hh:263
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
RangeAddrMapper::remapAddr
Addr remapAddr(Addr addr) const
This function does the actual remapping of one address to another.
Definition: addr_mapper.cc:226
AddrMapper::recvTimingReq
bool recvTimingReq(PacketPtr pkt)
Definition: addr_mapper.cc:105
Packet::cacheResponding
bool cacheResponding() const
Definition: packet.hh:619
AddrMapper::remapAddr
virtual Addr remapAddr(Addr addr) const =0
This function does the actual remapping of one address to another.
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
ResponsePort::sendTimingResp
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
Definition: port.hh:367
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
AddrMapper::recvTimingResp
bool recvTimingResp(PacketPtr pkt)
Definition: addr_mapper.cc:133
addr_mapper.hh
AddrMapper::recvFunctionalSnoop
void recvFunctionalSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:76
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
AddrMapper
An address mapper changes the packet addresses in going from the response port side of the mapper to ...
Definition: addr_mapper.hh:55
AddrMapper::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: addr_mapper.cc:48
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
ResponsePort::sendAtomicSnoop
Tick sendAtomicSnoop(PacketPtr pkt)
Send an atomic snoop request packet, where the data is moved and the state is updated in zero time,...
Definition: port.hh:323
RangeAddrMapper::originalRanges
std::vector< AddrRange > originalRanges
This contains a list of ranges the should be remapped.
Definition: addr_mapper.hh:257
RequestPort::sendFunctional
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:482
AddrMapper::recvAtomic
Tick recvAtomic(PacketPtr pkt)
Definition: addr_mapper.cc:85
RequestPort::sendTimingSnoopResp
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the response port by calling its corresponding rece...
Definition: port.hh:512
ResponsePort::sendTimingSnoopReq
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the request port by calling its corresponding receiv...
Definition: port.hh:384
AddrMapper::recvReqRetry
void recvReqRetry()
Definition: addr_mapper.cc:186
AddrMapper::recvAtomicSnoop
Tick recvAtomicSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:95
RequestPort::sendTimingReq
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition: port.hh:492
AddrMapper::isSnooping
bool isSnooping() const
Definition: addr_mapper.cc:178
AddrMapper::recvTimingSnoopReq
void recvTimingSnoopReq(PacketPtr pkt)
Definition: addr_mapper.cc:166
SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:123
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
Packet::needsResponse
bool needsResponse() const
Definition: packet.hh:570
RequestPort::sendRetryResp
virtual void sendRetryResp()
Send a retry to the response port that previously attempted a sendTimingResp to this request port and...
Definition: port.hh:522
ResponsePort::isSnooping
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition: port.hh:288
RangeAddrMapper::getAddrRanges
AddrRangeList getAddrRanges() const
Definition: addr_mapper.cc:239
RiscvISA::x
Bitfield< 3 > x
Definition: pagetable.hh:69
AddrMapper::recvRespRetry
void recvRespRetry()
Definition: addr_mapper.cc:192
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
AddrMapper::recvRangeChange
void recvRangeChange()
Definition: addr_mapper.cc:198
name
const std::string & name()
Definition: trace.cc:50
Packet::setAddr
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
Definition: packet.hh:762
AddrMapper::AddrMapper
AddrMapper(const AddrMapperParams *params)
Definition: addr_mapper.cc:40
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
Packet::pushSenderState
void pushSenderState(SenderState *sender_state)
Push a new sender state to the packet and make the current sender state the predecessor of the new on...
Definition: packet.cc:332
AddrMapper::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: addr_mapper.cc:55
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
AddrMapper::cpuSidePort
MapperResponsePort cpuSidePort
Instance of response port, i.e.
Definition: addr_mapper.hh:204
Packet::popSenderState
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:340
addr
ip6_addr_t addr
Definition: inet.hh:423
ResponsePort::sendFunctionalSnoop
void sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition: port.hh:343
Port::isConnected
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:128
AddrMapper::memSidePort
MapperRequestPort memSidePort
Instance of request port, facing the memory side.
Definition: addr_mapper.hh:154
RangeAddrMapper
Range address mapper that maps a set of original ranges to a set of remapped ranges,...
Definition: addr_mapper.hh:239
ResponsePort::sendRetryReq
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition: port.hh:398
Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:508
RangeAddrMapper::RangeAddrMapper
RangeAddrMapper(const RangeAddrMapperParams *p)
Definition: addr_mapper.cc:203
RequestPort::sendAtomic
Tick sendAtomic(PacketPtr pkt)
Send an atomic request packet, where the data is moved and the state is updated in zero time,...
Definition: port.hh:461
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
std::list< AddrRange >
Packet::SenderState::predecessor
SenderState * predecessor
Definition: packet.hh:433
ResponsePort::sendRangeChange
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:293
AddrMapper::recvFunctional
void recvFunctional(PacketPtr pkt)
Definition: addr_mapper.cc:67
AddrMapper::AddrMapperSenderState::origAddr
Addr origAddr
The original address the packet was destined for.
Definition: addr_mapper.hh:97
AddrMapper::AddrMapperSenderState
Definition: addr_mapper.hh:80
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

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