gem5  [DEVELOP-FOR-23.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 
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 void
89  MemBackdoorPtr &backdoor)
90 {
91  AddrRange remapped_req_range = AddrRange(remapAddr(req.range().start()),
92  remapAddr(req.range().end()));
93  MemBackdoorReq remapped_req(remapped_req_range, req.flags());
94  memSidePort.sendMemBackdoorReq(remapped_req, backdoor);
95  if (backdoor != nullptr) {
96  backdoor = getRevertedBackdoor(backdoor, req.range());
97  }
98 }
99 
100 Tick
102 {
103  Addr orig_addr = pkt->getAddr();
104  pkt->setAddr(remapAddr(orig_addr));
105  Tick ret_tick = memSidePort.sendAtomic(pkt);
106  pkt->setAddr(orig_addr);
107  return ret_tick;
108 }
109 
110 Tick
112 {
113  Addr orig_addr = pkt->getAddr();
114  pkt->setAddr(remapAddr(orig_addr));
115  Tick ret_tick = cpuSidePort.sendAtomicSnoop(pkt);
116  pkt->setAddr(orig_addr);
117  return ret_tick;
118 }
119 
120 Tick
122 {
123  Addr orig_addr = pkt->getAddr();
124  pkt->setAddr(remapAddr(orig_addr));
125  Tick ret_tick = memSidePort.sendAtomicBackdoor(pkt, backdoor);
126  pkt->setAddr(orig_addr);
127  if (backdoor != nullptr) {
128  backdoor = getRevertedBackdoor(backdoor, pkt->getAddrRange());
129  }
130  return ret_tick;
131 }
132 
133 bool
135 {
136  Addr orig_addr = pkt->getAddr();
137  bool needsResponse = pkt->needsResponse();
138  bool cacheResponding = pkt->cacheResponding();
139 
140  if (needsResponse && !cacheResponding) {
141  pkt->pushSenderState(new AddrMapperSenderState(orig_addr));
142  }
143 
144  pkt->setAddr(remapAddr(orig_addr));
145 
146  // Attempt to send the packet
147  bool successful = memSidePort.sendTimingReq(pkt);
148 
149  // If not successful, restore the address and sender state
150  if (!successful) {
151  pkt->setAddr(orig_addr);
152 
153  if (needsResponse) {
154  delete pkt->popSenderState();
155  }
156  }
157 
158  return successful;
159 }
160 
161 bool
163 {
164  AddrMapperSenderState* receivedState =
165  dynamic_cast<AddrMapperSenderState*>(pkt->senderState);
166 
167  // Restore initial sender state
168  if (receivedState == NULL)
169  panic("AddrMapper %s got a response without sender state\n",
170  name());
171 
172  Addr remapped_addr = pkt->getAddr();
173 
174  // Restore the state and address
175  pkt->senderState = receivedState->predecessor;
176  pkt->setAddr(receivedState->origAddr);
177 
178  // Attempt to send the packet
179  bool successful = cpuSidePort.sendTimingResp(pkt);
180 
181  // If packet successfully sent, delete the sender state, otherwise
182  // restore state
183  if (successful) {
184  delete receivedState;
185  } else {
186  // Don't delete anything and let the packet look like we did
187  // not touch it
188  pkt->senderState = receivedState;
189  pkt->setAddr(remapped_addr);
190  }
191  return successful;
192 }
193 
194 void
196 {
198 }
199 
200 bool
202 {
203  return memSidePort.sendTimingSnoopResp(pkt);
204 }
205 
206 bool
208 {
209  if (cpuSidePort.isSnooping())
210  fatal("AddrMapper doesn't support remapping of snooping requests\n");
211  return false;
212 }
213 
214 void
216 {
218 }
219 
220 void
222 {
224 }
225 
226 void
228 {
230 }
231 
232 RangeAddrMapper::RangeAddrMapper(const RangeAddrMapperParams &p) :
233  AddrMapper(p),
234  originalRanges(p.original_ranges),
235  remappedRanges(p.remapped_ranges),
236  backdoorManager(originalRanges, remappedRanges)
237 {
238  if (originalRanges.size() != remappedRanges.size())
239  fatal("AddrMapper: original and shadowed range list must "
240  "be same size\n");
241 
242  for (size_t x = 0; x < originalRanges.size(); x++) {
243  if (originalRanges[x].size() != remappedRanges[x].size())
244  fatal("AddrMapper: original and shadowed range list elements"
245  " aren't all of the same size\n");
246  }
247 }
248 
249 Addr
251 {
252  for (int i = 0; i < originalRanges.size(); ++i) {
253  if (originalRanges[i].contains(addr)) {
254  Addr offset = addr - originalRanges[i].start();
255  return offset + remappedRanges[i].start();
256  }
257  }
258 
259  return addr;
260 }
261 
264  const AddrRange &range)
265 {
266  return backdoorManager.getRevertedBackdoor(backdoor, range);
267 }
268 
271 {
272  // Simply return the original ranges as given by the parameters
273  AddrRangeList ranges(originalRanges.begin(), originalRanges.end());
274  return ranges;
275 }
276 
277 } // namespace gem5
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:200
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::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
gem5::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:587
gem5::AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:343
gem5::RangeAddrMapper::remapAddr
Addr remapAddr(Addr addr) const override
This function does the actual remapping of one address to another.
Definition: addr_mapper.cc:250
gem5::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:414
gem5::ResponsePort::sendRetryReq
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition: port.hh:473
gem5::AddrMapper::recvTimingReq
bool recvTimingReq(PacketPtr pkt)
Definition: addr_mapper.cc:134
gem5::AddrMapper::recvAtomicBackdoor
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
Definition: addr_mapper.cc:121
gem5::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:334
gem5::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:536
addr_mapper.hh
gem5::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:58
gem5::RangeAddrMapper::remappedRanges
std::vector< AddrRange > remappedRanges
This contains a list of ranges that addresses should be remapped to.
Definition: addr_mapper.hh:304
gem5::Packet::cacheResponding
bool cacheResponding() const
Definition: packet.hh:659
gem5::AddrMapper::recvTimingResp
bool recvTimingResp(PacketPtr pkt)
Definition: addr_mapper.cc:162
gem5::AddrMapper::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: addr_mapper.cc:51
gem5::AddrMapper::recvRespRetry
void recvRespRetry()
Definition: addr_mapper.cc:221
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::AddrMapper::memSidePort
MapperRequestPort memSidePort
Instance of request port, facing the memory side.
Definition: addr_mapper.hh:173
gem5::Packet::SenderState::predecessor
SenderState * predecessor
Definition: packet.hh:470
gem5::AddrMapper::getRevertedBackdoor
virtual MemBackdoorPtr getRevertedBackdoor(MemBackdoorPtr &backdoor, const AddrRange &range)=0
This function returns a backdoor that fulfills the initiator request, based on the target backdoor at...
gem5::RequestPort::sendAtomicBackdoor
Tick sendAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
Send an atomic request packet like above, but also request a backdoor to the data being accessed.
Definition: port.hh:549
gem5::AddrMapper::remapAddr
virtual Addr remapAddr(Addr addr) const =0
This function does the actual remapping of one address to another.
gem5::AddrMapper::recvAtomicSnoop
Tick recvAtomicSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:111
gem5::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:563
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::Packet::setAddr
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
Definition: packet.hh:815
gem5::RangeAddrMapper::getRevertedBackdoor
MemBackdoorPtr getRevertedBackdoor(MemBackdoorPtr &backdoor, const AddrRange &range) override
This function returns a backdoor that fulfills the initiator request, based on the target backdoor at...
Definition: addr_mapper.cc:263
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::VegaISA::x
Bitfield< 4 > x
Definition: pagetable.hh:61
gem5::ResponsePort::isSnooping
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition: port.hh:359
gem5::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:621
gem5::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:438
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::AddrRange::end
Addr end() const
Get the end address of the range.
Definition: addr_range.hh:350
gem5::RangeAddrMapper::getAddrRanges
AddrRangeList getAddrRanges() const override
Definition: addr_mapper.cc:270
gem5::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:459
gem5::Port::isConnected
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:133
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::RequestPort::sendMemBackdoorReq
void sendMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor)
Send a request for a back door to a range of memory.
Definition: port.hh:575
gem5::Packet::needsResponse
bool needsResponse() const
Definition: packet.hh:608
gem5::MemBackdoorReq::range
const AddrRange & range() const
Definition: backdoor.hh:140
gem5::RangeAddrMapper::backdoorManager
BackdoorManager backdoorManager
Definition: addr_mapper.hh:319
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:545
name
const std::string & name()
Definition: trace.cc:48
gem5::AddrMapper::recvTimingSnoopResp
bool recvTimingSnoopResp(PacketPtr pkt)
Definition: addr_mapper.cc:201
gem5::MemBackdoor
Definition: backdoor.hh:41
gem5::ResponsePort::sendRangeChange
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:364
gem5::Packet::popSenderState
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:342
gem5::AddrMapper::recvTimingSnoopReq
void recvTimingSnoopReq(PacketPtr pkt)
Definition: addr_mapper.cc:195
gem5::AddrMapper::recvFunctional
void recvFunctional(PacketPtr pkt)
Definition: addr_mapper.cc:70
gem5::AddrMapper::isSnooping
bool isSnooping() const
Definition: addr_mapper.cc:207
gem5::AddrMapper::AddrMapperSenderState
Definition: addr_mapper.hh:98
gem5::AddrMapper::recvRangeChange
virtual void recvRangeChange()
Definition: addr_mapper.cc:227
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::AddrMapper::cpuSidePort
MapperResponsePort cpuSidePort
Instance of response port, i.e.
Definition: addr_mapper.hh:236
gem5::AddrMapper
An address mapper changes the packet addresses in going from the response port side of the mapper to ...
Definition: addr_mapper.hh:62
gem5::AddrMapper::recvFunctionalSnoop
void recvFunctionalSnoop(PacketPtr pkt)
Definition: addr_mapper.cc:79
gem5::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:394
gem5::AddrMapper::recvReqRetry
void recvReqRetry()
Definition: addr_mapper.cc:215
gem5::AddrMapper::AddrMapperSenderState::origAddr
Addr origAddr
The original address the packet was destined for.
Definition: addr_mapper.hh:115
gem5::AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:81
std::list< AddrRange >
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:807
gem5::AddrMapper::recvMemBackdoorReq
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor)
Definition: addr_mapper.cc:88
gem5::AddrMapper::recvAtomic
Tick recvAtomic(PacketPtr pkt)
Definition: addr_mapper.cc:101
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::Packet::getAddrRange
AddrRange getAddrRange() const
Get address range to which this packet belongs.
Definition: packet.cc:243
gem5::MemBackdoorReq
Definition: backdoor.hh:129
gem5::MemBackdoorReq::flags
MemBackdoor::Flags flags() const
Definition: backdoor.hh:145
gem5::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:611
gem5::BackdoorManager::getRevertedBackdoor
MemBackdoorPtr getRevertedBackdoor(MemBackdoorPtr backdoor, const AddrRange &pkt_range)
Definition: backdoor_manager.cc:55
gem5::RangeAddrMapper::originalRanges
std::vector< AddrRange > originalRanges
This contains a list of ranges the should be remapped.
Definition: addr_mapper.hh:298
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::AddrMapper::AddrMapper
AddrMapper(const AddrMapperParams &params)
Definition: addr_mapper.cc:43
gem5::RangeAddrMapper::RangeAddrMapper
RangeAddrMapper(const RangeAddrMapperParams &p)
Definition: addr_mapper.cc:232
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Sun Jul 30 2023 01:56:57 for gem5 by doxygen 1.8.17