gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  : MemObject(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 
57 AddrMapper::getMasterPort(const std::string& if_name, PortID idx)
58 {
59  if (if_name == "master") {
60  return masterPort;
61  } else {
62  return MemObject::getMasterPort(if_name, idx);
63  }
64 }
65 
67 AddrMapper::getSlavePort(const std::string& if_name, PortID idx)
68 {
69  if (if_name == "slave") {
70  return slavePort;
71  } else {
72  return MemObject::getSlavePort(if_name, idx);
73  }
74 }
75 
76 void
78 {
79  Addr orig_addr = pkt->getAddr();
80  pkt->setAddr(remapAddr(orig_addr));
82  pkt->setAddr(orig_addr);
83 }
84 
85 void
87 {
88  Addr orig_addr = pkt->getAddr();
89  pkt->setAddr(remapAddr(orig_addr));
91  pkt->setAddr(orig_addr);
92 }
93 
94 Tick
96 {
97  Addr orig_addr = pkt->getAddr();
98  pkt->setAddr(remapAddr(orig_addr));
99  Tick ret_tick = masterPort.sendAtomic(pkt);
100  pkt->setAddr(orig_addr);
101  return ret_tick;
102 }
103 
104 Tick
106 {
107  Addr orig_addr = pkt->getAddr();
108  pkt->setAddr(remapAddr(orig_addr));
109  Tick ret_tick = slavePort.sendAtomicSnoop(pkt);
110  pkt->setAddr(orig_addr);
111  return ret_tick;
112 }
113 
114 bool
116 {
117  Addr orig_addr = pkt->getAddr();
118  bool needsResponse = pkt->needsResponse();
119  bool cacheResponding = pkt->cacheResponding();
120 
121  if (needsResponse && !cacheResponding) {
122  pkt->pushSenderState(new AddrMapperSenderState(orig_addr));
123  }
124 
125  pkt->setAddr(remapAddr(orig_addr));
126 
127  // Attempt to send the packet
128  bool successful = masterPort.sendTimingReq(pkt);
129 
130  // If not successful, restore the address and sender state
131  if (!successful) {
132  pkt->setAddr(orig_addr);
133 
134  if (needsResponse) {
135  delete pkt->popSenderState();
136  }
137  }
138 
139  return successful;
140 }
141 
142 bool
144 {
145  AddrMapperSenderState* receivedState =
146  dynamic_cast<AddrMapperSenderState*>(pkt->senderState);
147 
148  // Restore initial sender state
149  if (receivedState == NULL)
150  panic("AddrMapper %s got a response without sender state\n",
151  name());
152 
153  Addr remapped_addr = pkt->getAddr();
154 
155  // Restore the state and address
156  pkt->senderState = receivedState->predecessor;
157  pkt->setAddr(receivedState->origAddr);
158 
159  // Attempt to send the packet
160  bool successful = slavePort.sendTimingResp(pkt);
161 
162  // If packet successfully sent, delete the sender state, otherwise
163  // restore state
164  if (successful) {
165  delete receivedState;
166  } else {
167  // Don't delete anything and let the packet look like we did
168  // not touch it
169  pkt->senderState = receivedState;
170  pkt->setAddr(remapped_addr);
171  }
172  return successful;
173 }
174 
175 void
177 {
179 }
180 
181 bool
183 {
184  return masterPort.sendTimingSnoopResp(pkt);
185 }
186 
187 bool
189 {
190  if (slavePort.isSnooping())
191  fatal("AddrMapper doesn't support remapping of snooping requests\n");
192  return false;
193 }
194 
195 void
197 {
199 }
200 
201 void
203 {
205 }
206 
207 void
209 {
211 }
212 
213 RangeAddrMapper::RangeAddrMapper(const RangeAddrMapperParams* p) :
214  AddrMapper(p),
215  originalRanges(p->original_ranges),
216  remappedRanges(p->remapped_ranges)
217 {
218  if (originalRanges.size() != remappedRanges.size())
219  fatal("AddrMapper: original and shadowed range list must "
220  "be same size\n");
221 
222  for (size_t x = 0; x < originalRanges.size(); x++) {
223  if (originalRanges[x].size() != remappedRanges[x].size())
224  fatal("AddrMapper: original and shadowed range list elements"
225  " aren't all of the same size\n");
226  }
227 }
228 
230 RangeAddrMapperParams::create()
231 {
232  return new RangeAddrMapper(this);
233 }
234 
235 Addr
237 {
238  for (int i = 0; i < originalRanges.size(); ++i) {
239  if (originalRanges[i].contains(addr)) {
240  Addr offset = addr - originalRanges[i].start();
241  return offset + remappedRanges[i].start();
242  }
243  }
244 
245  return addr;
246 }
247 
250 {
251  // Simply return the original ranges as given by the parameters
252  AddrRangeList ranges(originalRanges.begin(), originalRanges.end());
253  return ranges;
254 }
255 
256 
MapperMasterPort masterPort
Instance of master port, facing the memory side.
Definition: addr_mapper.hh:158
AddrMapper(const AddrMapperParams *params)
Definition: addr_mapper.cc:42
void recvRespRetry()
Definition: addr_mapper.cc:202
Addr origAddr
The original address the packet was destined for.
Definition: addr_mapper.hh:101
Tick recvAtomicSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:105
void recvReqRetry()
Definition: addr_mapper.cc:196
void recvTimingSnoopReq(PacketPtr pkt)
Definition: addr_mapper.cc:176
const std::string & name()
Definition: trace.cc:49
MapperSlavePort slavePort
Instance of slave port, i.e.
Definition: addr_mapper.hh:208
Bitfield< 7 > i
Definition: miscregs.hh:1378
#define panic(...)
Definition: misc.hh:153
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the slave port by calling its corresponding receive...
Definition: port.cc:187
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.cc:237
ip6_addr_t addr
Definition: inet.hh:335
void sendFunctionalSnoop(PacketPtr pkt)
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition: port.cc:244
Bitfield< 23, 0 > offset
Definition: types.hh:149
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the slave port by calling its corresponding receive function...
Definition: port.cc:180
void recvRangeChange()
Definition: addr_mapper.cc:208
virtual BaseSlavePort & getSlavePort(const std::string &if_name, PortID idx=InvalidPortID)
Get a slave port with a given name and index.
Definition: mem_object.cc:58
virtual void sendRetryResp()
Send a retry to the slave port that previously attempted a sendTimingResp to this master port and fai...
Definition: port.cc:194
AddrRangeList getAddrRanges() const
Definition: addr_mapper.cc:249
A BaseSlavePort is a protocol-agnostic slave port, responsible only for the structural connection to ...
Definition: port.hh:139
std::vector< AddrRange > originalRanges
This contains a list of ranges the should be remapped.
Definition: addr_mapper.hh:261
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: addr_mapper.cc:50
RangeAddrMapper(const RangeAddrMapperParams *p)
Definition: addr_mapper.cc:213
bool isSnooping() const
Find out if the peer master port is snooping or not.
Definition: port.hh:405
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the master port by calling its corresponding receive function...
Definition: port.cc:251
SenderState * predecessor
Definition: packet.hh:379
uint64_t Tick
Tick count type.
Definition: types.hh:63
void recvFunctional(PacketPtr pkt)
Definition: addr_mapper.cc:77
bool recvTimingReq(PacketPtr pkt)
Definition: addr_mapper.cc:115
#define fatal(...)
Definition: misc.hh:163
virtual Addr remapAddr(Addr addr) const =0
This function does the actual remapping of one address to another.
bool needsResponse() const
Definition: packet.hh:516
bool isSnooping() const
Definition: addr_mapper.cc:188
bool recvTimingResp(PacketPtr pkt)
Definition: addr_mapper.cc:143
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
bool cacheResponding() const
Definition: packet.hh:558
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
bool recvTimingSnoopResp(PacketPtr pkt)
Definition: addr_mapper.cc:182
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:410
bool isConnected() const
Definition: port.cc:84
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
Definition: packet.hh:647
Addr remapAddr(Addr addr) const
This function does the actual remapping of one address to another.
Definition: addr_mapper.cc:236
int size()
Definition: pagetable.hh:146
virtual const std::string name() const
Definition: sim_object.hh:117
An address mapper changes the packet addresses in going from the slave port side of the mapper to the...
Definition: addr_mapper.hh:56
void sendRetryReq()
Send a retry to the master port that previously attempted a sendTimingReq to this slave port and fail...
Definition: port.cc:265
SenderState * senderState
This packet's sender state.
Definition: packet.hh:454
Tick recvAtomic(PacketPtr pkt)
Definition: addr_mapper.cc:95
The MemObject class extends the ClockedObject with accessor functions to get its master and slave por...
Definition: mem_object.hh:60
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
Definition: port.hh:115
bool isConnected() const
Definition: port.cc:110
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:243
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the master port by calling its corresponding receive...
Definition: port.cc:258
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:329
virtual BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a master port with a given name and index.
Definition: addr_mapper.cc:57
void recvFunctionalSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:86
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:337
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
virtual BaseSlavePort & getSlavePort(const std::string &if_name, PortID idx=InvalidPortID)
Get a slave port with a given name and index.
Definition: addr_mapper.cc:67
Tick sendAtomic(PacketPtr pkt)
Send an atomic request packet, where the data is moved and the state is updated in zero time...
Definition: port.cc:166
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:267
virtual BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a master port with a given name and index.
Definition: mem_object.cc:52
void sendFunctional(PacketPtr pkt)
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.cc:173
Addr getAddr() const
Definition: packet.hh:639

Generated on Fri Jun 9 2017 13:03:48 for gem5 by doxygen 1.8.6