gem5  v22.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 namespace gem5
41 {
42 
43 AddrMapper::AddrMapper(const AddrMapperParams &p)
44  : SimObject(p),
45  memSidePort(name() + "-mem_side_port", *this),
46  cpuSidePort(name() + "-cpu_side_port", *this)
47 {
48 }
49 
50 void
52 {
54  fatal("Address mapper is not connected on both sides.\n");
55 }
56 
57 Port &
58 AddrMapper::getPort(const std::string &if_name, PortID idx)
59 {
60  if (if_name == "mem_side_port") {
61  return memSidePort;
62  } else if (if_name == "cpu_side_port") {
63  return cpuSidePort;
64  } else {
65  return SimObject::getPort(if_name, idx);
66  }
67 }
68 
69 void
71 {
72  Addr orig_addr = pkt->getAddr();
73  pkt->setAddr(remapAddr(orig_addr));
75  pkt->setAddr(orig_addr);
76 }
77 
78 void
80 {
81  Addr orig_addr = pkt->getAddr();
82  pkt->setAddr(remapAddr(orig_addr));
84  pkt->setAddr(orig_addr);
85 }
86 
87 Tick
89 {
90  Addr orig_addr = pkt->getAddr();
91  pkt->setAddr(remapAddr(orig_addr));
92  Tick ret_tick = memSidePort.sendAtomic(pkt);
93  pkt->setAddr(orig_addr);
94  return ret_tick;
95 }
96 
97 Tick
99 {
100  Addr orig_addr = pkt->getAddr();
101  pkt->setAddr(remapAddr(orig_addr));
102  Tick ret_tick = cpuSidePort.sendAtomicSnoop(pkt);
103  pkt->setAddr(orig_addr);
104  return ret_tick;
105 }
106 
107 bool
109 {
110  Addr orig_addr = pkt->getAddr();
111  bool needsResponse = pkt->needsResponse();
112  bool cacheResponding = pkt->cacheResponding();
113 
114  if (needsResponse && !cacheResponding) {
115  pkt->pushSenderState(new AddrMapperSenderState(orig_addr));
116  }
117 
118  pkt->setAddr(remapAddr(orig_addr));
119 
120  // Attempt to send the packet
121  bool successful = memSidePort.sendTimingReq(pkt);
122 
123  // If not successful, restore the address and sender state
124  if (!successful) {
125  pkt->setAddr(orig_addr);
126 
127  if (needsResponse) {
128  delete pkt->popSenderState();
129  }
130  }
131 
132  return successful;
133 }
134 
135 bool
137 {
138  AddrMapperSenderState* receivedState =
139  dynamic_cast<AddrMapperSenderState*>(pkt->senderState);
140 
141  // Restore initial sender state
142  if (receivedState == NULL)
143  panic("AddrMapper %s got a response without sender state\n",
144  name());
145 
146  Addr remapped_addr = pkt->getAddr();
147 
148  // Restore the state and address
149  pkt->senderState = receivedState->predecessor;
150  pkt->setAddr(receivedState->origAddr);
151 
152  // Attempt to send the packet
153  bool successful = cpuSidePort.sendTimingResp(pkt);
154 
155  // If packet successfully sent, delete the sender state, otherwise
156  // restore state
157  if (successful) {
158  delete receivedState;
159  } else {
160  // Don't delete anything and let the packet look like we did
161  // not touch it
162  pkt->senderState = receivedState;
163  pkt->setAddr(remapped_addr);
164  }
165  return successful;
166 }
167 
168 void
170 {
172 }
173 
174 bool
176 {
177  return memSidePort.sendTimingSnoopResp(pkt);
178 }
179 
180 bool
182 {
183  if (cpuSidePort.isSnooping())
184  fatal("AddrMapper doesn't support remapping of snooping requests\n");
185  return false;
186 }
187 
188 void
190 {
192 }
193 
194 void
196 {
198 }
199 
200 void
202 {
204 }
205 
206 RangeAddrMapper::RangeAddrMapper(const RangeAddrMapperParams &p) :
207  AddrMapper(p),
208  originalRanges(p.original_ranges),
209  remappedRanges(p.remapped_ranges)
210 {
211  if (originalRanges.size() != remappedRanges.size())
212  fatal("AddrMapper: original and shadowed range list must "
213  "be same size\n");
214 
215  for (size_t x = 0; x < originalRanges.size(); x++) {
216  if (originalRanges[x].size() != remappedRanges[x].size())
217  fatal("AddrMapper: original and shadowed range list elements"
218  " aren't all of the same size\n");
219  }
220 }
221 
222 Addr
224 {
225  for (int i = 0; i < originalRanges.size(); ++i) {
226  if (originalRanges[i].contains(addr)) {
227  Addr offset = addr - originalRanges[i].start();
228  return offset + remappedRanges[i].start();
229  }
230  }
231 
232  return addr;
233 }
234 
237 {
238  // Simply return the original ranges as given by the parameters
239  AddrRangeList ranges(originalRanges.begin(), originalRanges.end());
240  return ranges;
241 }
242 
243 } // namespace gem5
Addr origAddr
The original address the packet was destined for.
Definition: addr_mapper.hh:97
An address mapper changes the packet addresses in going from the response port side of the mapper to ...
Definition: addr_mapper.hh:59
MapperRequestPort memSidePort
Instance of request port, facing the memory side.
Definition: addr_mapper.hh:155
virtual void recvRangeChange()
Definition: addr_mapper.cc:201
MapperResponsePort cpuSidePort
Instance of response port, i.e.
Definition: addr_mapper.hh:206
Tick recvAtomicSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:98
bool recvTimingResp(PacketPtr pkt)
Definition: addr_mapper.cc:136
void recvFunctionalSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:79
bool recvTimingReq(PacketPtr pkt)
Definition: addr_mapper.cc:108
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: addr_mapper.cc:51
void recvTimingSnoopReq(PacketPtr pkt)
Definition: addr_mapper.cc:169
bool isSnooping() const
Definition: addr_mapper.cc:181
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: addr_mapper.cc:58
void recvFunctional(PacketPtr pkt)
Definition: addr_mapper.cc:70
bool recvTimingSnoopResp(PacketPtr pkt)
Definition: addr_mapper.cc:175
Tick recvAtomic(PacketPtr pkt)
Definition: addr_mapper.cc:88
virtual Addr remapAddr(Addr addr) const =0
This function does the actual remapping of one address to another.
AddrMapper(const AddrMapperParams &params)
Definition: addr_mapper.cc:43
virtual std::string name() const
Definition: named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Addr getAddr() const
Definition: packet.hh:805
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
Definition: packet.hh:813
bool needsResponse() const
Definition: packet.hh:607
SenderState * senderState
This packet's sender state.
Definition: packet.hh:544
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:334
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:342
bool cacheResponding() const
Definition: packet.hh:657
Ports are used to interface objects to each other.
Definition: port.hh:62
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:133
std::vector< AddrRange > originalRanges
This contains a list of ranges the should be remapped.
Definition: addr_mapper.hh:263
std::vector< AddrRange > remappedRanges
This contains a list of ranges that addresses should be remapped to.
Definition: addr_mapper.hh:269
RangeAddrMapper(const RangeAddrMapperParams &p)
Definition: addr_mapper.cc:206
Addr remapAddr(Addr addr) const override
This function does the actual remapping of one address to another.
Definition: addr_mapper.cc:223
AddrRangeList getAddrRanges() const override
Definition: addr_mapper.cc:236
virtual void sendRetryResp()
Send a retry to the response port that previously attempted a sendTimingResp to this request port and...
Definition: port.hh:525
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:464
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition: port.hh:495
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the response port by calling its corresponding rece...
Definition: port.hh:515
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:485
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
Definition: port.hh:370
void sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition: port.hh:346
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:326
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the request port by calling its corresponding receiv...
Definition: port.hh:387
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition: port.hh:291
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:296
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition: port.hh:401
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
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
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 4 > x
Definition: pagetable.hh:61
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
uint64_t Tick
Tick count type.
Definition: types.hh:58
SenderState * predecessor
Definition: packet.hh:469
const std::string & name()
Definition: trace.cc:49

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