gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
40namespace gem5
41{
42
43AddrMapper::AddrMapper(const AddrMapperParams &p)
44 : SimObject(p),
45 memSidePort(name() + "-mem_side_port", *this),
46 cpuSidePort(name() + "-cpu_side_port", *this)
47{
48}
49
50void
52{
54 fatal("Address mapper is not connected on both sides.\n");
55}
56
57Port &
58AddrMapper::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
69void
71{
72 Addr orig_addr = pkt->getAddr();
73 pkt->setAddr(remapAddr(orig_addr));
75 pkt->setAddr(orig_addr);
76}
77
78void
80{
81 Addr orig_addr = pkt->getAddr();
82 pkt->setAddr(remapAddr(orig_addr));
84 pkt->setAddr(orig_addr);
85}
86
87void
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
100Tick
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
110Tick
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
120Tick
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
133bool
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
161bool
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
194void
199
200bool
205
206bool
208{
210 fatal("AddrMapper doesn't support remapping of snooping requests\n");
211 return false;
212}
213
214void
219
220void
225
226void
231
232RangeAddrMapper::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
249Addr
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
Addr origAddr
The original address the packet was destined for.
An address mapper changes the packet addresses in going from the response port side of the mapper to ...
MapperRequestPort memSidePort
Instance of request port, facing the memory side.
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...
virtual void recvRangeChange()
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
MapperResponsePort cpuSidePort
Instance of response port, i.e.
Tick recvAtomicSnoop(PacketPtr pkt)
bool recvTimingResp(PacketPtr pkt)
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor)
void recvFunctionalSnoop(PacketPtr pkt)
bool recvTimingReq(PacketPtr pkt)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
void recvTimingSnoopReq(PacketPtr pkt)
bool isSnooping() const
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
void recvFunctional(PacketPtr pkt)
bool recvTimingSnoopResp(PacketPtr pkt)
Tick recvAtomic(PacketPtr pkt)
virtual Addr remapAddr(Addr addr) const =0
This function does the actual remapping of one address to another.
AddrMapper(const AddrMapperParams &params)
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition addr_range.hh:82
MemBackdoorPtr getRevertedBackdoor(MemBackdoorPtr backdoor, const AddrRange &pkt_range)
const AddrRange & range() const
Definition backdoor.hh:140
MemBackdoor::Flags flags() const
Definition backdoor.hh:145
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:295
Addr getAddr() const
Definition packet.hh:807
AddrRange getAddrRange() const
Get address range to which this packet belongs.
Definition packet.cc:243
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
Definition packet.hh:815
bool needsResponse() const
Definition packet.hh:608
SenderState * senderState
This packet's sender state.
Definition packet.hh:545
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:659
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
MemBackdoorPtr getRevertedBackdoor(MemBackdoorPtr &backdoor, const AddrRange &range) override
This function returns a backdoor that fulfills the initiator request, based on the target backdoor at...
std::vector< AddrRange > originalRanges
This contains a list of ranges the should be remapped.
std::vector< AddrRange > remappedRanges
This contains a list of ranges that addresses should be remapped to.
RangeAddrMapper(const RangeAddrMapperParams &p)
Addr remapAddr(Addr addr) const override
This function does the actual remapping of one address to another.
AddrRangeList getAddrRanges() const override
BackdoorManager backdoorManager
void sendMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &backdoor)
Send a request for a back door to a range of memory.
Definition port.hh:591
virtual void sendRetryResp()
Send a retry to the response port that previously attempted a sendTimingResp to this request port and...
Definition port.hh:637
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:552
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition port.hh:603
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the response port by calling its corresponding rece...
Definition port.hh:627
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition port.hh:579
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:565
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
Definition port.hh:454
void sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition port.hh:430
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:410
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the request port by calling its corresponding receiv...
Definition port.hh:475
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition port.hh:375
void sendRangeChange() const
Called by the owner to send a range change.
Definition port.hh:380
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition port.hh:489
Abstract superclass for simulation objects.
Addr end() const
Get the end address of the range.
Addr start() const
Get the start address of the range.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 0 > p
Bitfield< 3 > x
Definition pagetable.hh:73
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
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:470
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:04 for gem5 by doxygen 1.11.0