gem5 v23.0.0.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
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
87Tick
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
97Tick
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
107bool
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
135bool
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
168void
170{
172}
173
174bool
176{
178}
179
180bool
182{
184 fatal("AddrMapper doesn't support remapping of snooping requests\n");
185 return false;
186}
187
188void
190{
192}
193
194void
196{
198}
199
200void
202{
204}
205
206RangeAddrMapper::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
222Addr
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.
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 void recvRangeChange()
MapperResponsePort cpuSidePort
Instance of response port, i.e.
Tick recvAtomicSnoop(PacketPtr pkt)
bool recvTimingResp(PacketPtr pkt)
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)
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
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
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
virtual void sendRetryResp()
Send a retry to the response port that previously attempted a sendTimingResp to this request port and...
Definition port.hh:560
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:487
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition port.hh:530
bool sendTimingSnoopResp(PacketPtr pkt)
Attempt to send a timing snoop response packet to the response port by calling its corresponding rece...
Definition port.hh:550
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition port.hh:508
bool sendTimingResp(PacketPtr pkt)
Attempt to send a timing response to the request port by calling its corresponding receive function.
Definition port.hh:393
void sendFunctionalSnoop(PacketPtr pkt) const
Send a functional snoop request packet, where the data is instantly updated everywhere in the memory ...
Definition port.hh:369
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:349
void sendTimingSnoopReq(PacketPtr pkt)
Attempt to send a timing snoop request packet to the request port by calling its corresponding receiv...
Definition port.hh:410
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition port.hh:314
void sendRangeChange() const
Called by the owner to send a range change.
Definition port.hh:319
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition port.hh:424
Abstract superclass for simulation objects.
#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
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:470
const std::string & name()
Definition trace.cc:48

Generated on Mon Jul 10 2023 14:24:32 for gem5 by doxygen 1.9.7