gem5 [DEVELOP-FOR-25.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{
53 if (!cpuSidePort.isConnected() || !memSidePort.isConnected())
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));
74 memSidePort.sendFunctional(pkt);
75 pkt->setAddr(orig_addr);
76}
77
78void
80{
81 Addr orig_addr = pkt->getAddr();
82 pkt->setAddr(remapAddr(orig_addr));
83 cpuSidePort.sendFunctionalSnoop(pkt);
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
196{
197 cpuSidePort.sendTimingSnoopReq(pkt);
198}
199
200bool
202{
203 return memSidePort.sendTimingSnoopResp(pkt);
204}
205
206bool
208{
209 if (cpuSidePort.isSnooping())
210 fatal("AddrMapper doesn't support remapping of snooping requests\n");
211 return false;
212}
213
214void
216{
217 cpuSidePort.sendRetryReq();
218}
219
220void
222{
223 memSidePort.sendRetryResp();
224}
225
226void
228{
229 cpuSidePort.sendRangeChange();
230}
231
232RangeAddrMapper::RangeAddrMapper(const RangeAddrMapperParams &p) :
233 AddrMapper(p),
234 originalRanges(p.original_ranges),
235 remappedRanges(p.remapped_ranges),
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.
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
const AddrRange & range() const
Definition backdoor.hh:140
MemBackdoor::Flags flags() const
Definition backdoor.hh:145
virtual std::string name() const
Definition named.hh:60
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
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
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition addr_range.hh:64
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:220
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:232
SimObject(const Params &p)
Definition sim_object.cc:58
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:76
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 Arm Limited 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
MemBackdoor * MemBackdoorPtr
Definition backdoor.hh:127
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
Packet * PacketPtr
SenderState * predecessor
Definition packet.hh:470

Generated on Mon May 26 2025 09:19:11 for gem5 by doxygen 1.13.2