gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Andreas Hansson
38  */
39 
40 #include "mem/addr_mapper.hh"
41 
42 AddrMapper::AddrMapper(const AddrMapperParams* p)
43  : SimObject(p),
44  masterPort(name() + "-master", *this),
45  slavePort(name() + "-slave", *this)
46 {
47 }
48 
49 void
51 {
53  fatal("Address mapper is not connected on both sides.\n");
54 }
55 
56 Port &
57 AddrMapper::getPort(const std::string &if_name, PortID idx)
58 {
59  if (if_name == "master") {
60  return masterPort;
61  } else if (if_name == "slave") {
62  return slavePort;
63  } else {
64  return SimObject::getPort(if_name, idx);
65  }
66 }
67 
68 void
70 {
71  Addr orig_addr = pkt->getAddr();
72  pkt->setAddr(remapAddr(orig_addr));
74  pkt->setAddr(orig_addr);
75 }
76 
77 void
79 {
80  Addr orig_addr = pkt->getAddr();
81  pkt->setAddr(remapAddr(orig_addr));
83  pkt->setAddr(orig_addr);
84 }
85 
86 Tick
88 {
89  Addr orig_addr = pkt->getAddr();
90  pkt->setAddr(remapAddr(orig_addr));
91  Tick ret_tick = masterPort.sendAtomic(pkt);
92  pkt->setAddr(orig_addr);
93  return ret_tick;
94 }
95 
96 Tick
98 {
99  Addr orig_addr = pkt->getAddr();
100  pkt->setAddr(remapAddr(orig_addr));
101  Tick ret_tick = slavePort.sendAtomicSnoop(pkt);
102  pkt->setAddr(orig_addr);
103  return ret_tick;
104 }
105 
106 bool
108 {
109  Addr orig_addr = pkt->getAddr();
110  bool needsResponse = pkt->needsResponse();
111  bool cacheResponding = pkt->cacheResponding();
112 
113  if (needsResponse && !cacheResponding) {
114  pkt->pushSenderState(new AddrMapperSenderState(orig_addr));
115  }
116 
117  pkt->setAddr(remapAddr(orig_addr));
118 
119  // Attempt to send the packet
120  bool successful = masterPort.sendTimingReq(pkt);
121 
122  // If not successful, restore the address and sender state
123  if (!successful) {
124  pkt->setAddr(orig_addr);
125 
126  if (needsResponse) {
127  delete pkt->popSenderState();
128  }
129  }
130 
131  return successful;
132 }
133 
134 bool
136 {
137  AddrMapperSenderState* receivedState =
138  dynamic_cast<AddrMapperSenderState*>(pkt->senderState);
139 
140  // Restore initial sender state
141  if (receivedState == NULL)
142  panic("AddrMapper %s got a response without sender state\n",
143  name());
144 
145  Addr remapped_addr = pkt->getAddr();
146 
147  // Restore the state and address
148  pkt->senderState = receivedState->predecessor;
149  pkt->setAddr(receivedState->origAddr);
150 
151  // Attempt to send the packet
152  bool successful = slavePort.sendTimingResp(pkt);
153 
154  // If packet successfully sent, delete the sender state, otherwise
155  // restore state
156  if (successful) {
157  delete receivedState;
158  } else {
159  // Don't delete anything and let the packet look like we did
160  // not touch it
161  pkt->senderState = receivedState;
162  pkt->setAddr(remapped_addr);
163  }
164  return successful;
165 }
166 
167 void
169 {
171 }
172 
173 bool
175 {
176  return masterPort.sendTimingSnoopResp(pkt);
177 }
178 
179 bool
181 {
182  if (slavePort.isSnooping())
183  fatal("AddrMapper doesn't support remapping of snooping requests\n");
184  return false;
185 }
186 
187 void
189 {
191 }
192 
193 void
195 {
197 }
198 
199 void
201 {
203 }
204 
205 RangeAddrMapper::RangeAddrMapper(const RangeAddrMapperParams* p) :
206  AddrMapper(p),
207  originalRanges(p->original_ranges),
208  remappedRanges(p->remapped_ranges)
209 {
210  if (originalRanges.size() != remappedRanges.size())
211  fatal("AddrMapper: original and shadowed range list must "
212  "be same size\n");
213 
214  for (size_t x = 0; x < originalRanges.size(); x++) {
215  if (originalRanges[x].size() != remappedRanges[x].size())
216  fatal("AddrMapper: original and shadowed range list elements"
217  " aren't all of the same size\n");
218  }
219 }
220 
222 RangeAddrMapperParams::create()
223 {
224  return new RangeAddrMapper(this);
225 }
226 
227 Addr
229 {
230  for (int i = 0; i < originalRanges.size(); ++i) {
231  if (originalRanges[i].contains(addr)) {
232  Addr offset = addr - originalRanges[i].start();
233  return offset + remappedRanges[i].start();
234  }
235  }
236 
237  return addr;
238 }
239 
242 {
243  // Simply return the original ranges as given by the parameters
244  AddrRangeList ranges(originalRanges.begin(), originalRanges.end());
245  return ranges;
246 }
247 
248 
bool isSnooping() const
Definition: addr_mapper.cc:180
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
MapperMasterPort masterPort
Instance of master port, facing the memory side.
Definition: addr_mapper.hh:156
AddrMapper(const AddrMapperParams *params)
Definition: addr_mapper.cc:42
Ports are used to interface objects to each other.
Definition: port.hh:60
void recvRespRetry()
Definition: addr_mapper.cc:194
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:126
Addr origAddr
The original address the packet was destined for.
Definition: addr_mapper.hh:99
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:286
Tick recvAtomicSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:97
void recvReqRetry()
Definition: addr_mapper.cc:188
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:175
void recvTimingSnoopReq(PacketPtr pkt)
Definition: addr_mapper.cc:168
const std::string & name()
Definition: trace.cc:54
MapperSlavePort slavePort
Instance of slave port, i.e.
Definition: addr_mapper.hh:206
Bitfield< 7 > i
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the slave port by calling its corresponding receive...
Definition: port.hh:457
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:321
ip6_addr_t addr
Definition: inet.hh:335
bool cacheResponding() const
Definition: packet.hh:591
Bitfield< 23, 0 > offset
Definition: types.hh:154
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the slave port by calling its corresponding receive function...
Definition: port.hh:445
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:128
void recvRangeChange()
Definition: addr_mapper.cc:200
virtual void sendRetryResp()
Send a retry to the slave port that previously attempted a sendTimingResp to this master port and fai...
Definition: port.hh:463
std::vector< AddrRange > originalRanges
This contains a list of ranges the should be remapped.
Definition: addr_mapper.hh:259
void sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition: port.hh:337
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: addr_mapper.cc:57
RangeAddrMapper(const RangeAddrMapperParams *p)
Definition: addr_mapper.cc:205
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the master port by calling its corresponding receive function...
Definition: port.hh:357
bool needsResponse() const
Definition: packet.hh:542
SenderState * predecessor
Definition: packet.hh:405
uint64_t Tick
Tick count type.
Definition: types.hh:63
void recvFunctional(PacketPtr pkt)
Definition: addr_mapper.cc:69
bool recvTimingReq(PacketPtr pkt)
Definition: addr_mapper.cc:107
Addr getAddr() const
Definition: packet.hh:726
virtual Addr remapAddr(Addr addr) const =0
This function does the actual remapping of one address to another.
bool recvTimingResp(PacketPtr pkt)
Definition: addr_mapper.cc:135
bool isSnooping() const
Find out if the peer master port is snooping or not.
Definition: port.hh:280
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
virtual const std::string name() const
Definition: sim_object.hh:120
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
AddrRangeList getAddrRanges() const
Definition: addr_mapper.cc:241
bool recvTimingSnoopResp(PacketPtr pkt)
Definition: addr_mapper.cc:174
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: addr_mapper.cc:50
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
Definition: packet.hh:734
An address mapper changes the packet addresses in going from the slave port side of the mapper to the...
Definition: addr_mapper.hh:57
void sendRetryReq()
Send a retry to the master port that previously attempted a sendTimingReq to this slave port and fail...
Definition: port.hh:380
SenderState * senderState
This packet&#39;s sender state.
Definition: packet.hh:480
Tick recvAtomic(PacketPtr pkt)
Definition: addr_mapper.cc:87
Range address mapper that maps a set of original ranges to a set of remapped ranges, where a specific range is of the same size (original and remapped), only with an offset.
Definition: addr_mapper.hh:241
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the master port by calling its corresponding receive...
Definition: port.hh:370
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:319
void recvFunctionalSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:78
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:327
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:439
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
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:427
Bitfield< 0 > p
Bitfield< 1 > x
Definition: types.hh:105
std::vector< AddrRange > remappedRanges
This contains a list of ranges that addresses should be remapped to.
Definition: addr_mapper.hh:265
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
Addr remapAddr(Addr addr) const
This function does the actual remapping of one address to another.
Definition: addr_mapper.cc:228

Generated on Fri Feb 28 2020 16:27:01 for gem5 by doxygen 1.8.13