gem5  v21.1.0.2
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
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:189
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:252
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:126
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:495
gem5::RangeAddrMapper::remapAddr
Addr remapAddr(Addr addr) const override
This function does the actual remapping of one address to another.
Definition: addr_mapper.cc:223
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:346
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:401
gem5::AddrMapper::recvTimingReq
bool recvTimingReq(PacketPtr pkt)
Definition: addr_mapper.cc:108
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:316
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:464
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:269
gem5::Packet::cacheResponding
bool cacheResponding() const
Definition: packet.hh:646
gem5::AddrMapper::recvTimingResp
bool recvTimingResp(PacketPtr pkt)
Definition: addr_mapper.cc:136
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:195
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::AddrMapper::memSidePort
MapperRequestPort memSidePort
Instance of request port, facing the memory side.
Definition: addr_mapper.hh:155
gem5::Packet::SenderState::predecessor
SenderState * predecessor
Definition: packet.hh:459
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:98
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:485
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::Packet::setAddr
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
Definition: packet.hh:789
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::ResponsePort::isSnooping
bool isSnooping() const
Find out if the peer request port is snooping or not.
Definition: port.hh:291
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:525
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:370
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::RangeAddrMapper::getAddrRanges
AddrRangeList getAddrRanges() const override
Definition: addr_mapper.cc:236
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:387
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::Packet::needsResponse
bool needsResponse() const
Definition: packet.hh:597
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:534
name
const std::string & name()
Definition: trace.cc:49
gem5::AddrMapper::recvTimingSnoopResp
bool recvTimingSnoopResp(PacketPtr pkt)
Definition: addr_mapper.cc:175
gem5::ResponsePort::sendRangeChange
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:296
gem5::Packet::popSenderState
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:324
gem5::AddrMapper::recvTimingSnoopReq
void recvTimingSnoopReq(PacketPtr pkt)
Definition: addr_mapper.cc:169
gem5::AddrMapper::recvFunctional
void recvFunctional(PacketPtr pkt)
Definition: addr_mapper.cc:70
gem5::AddrMapper::isSnooping
bool isSnooping() const
Definition: addr_mapper.cc:181
gem5::AddrMapper::AddrMapperSenderState
Definition: addr_mapper.hh:80
gem5::RiscvISA::x
Bitfield< 3 > x
Definition: pagetable.hh:73
gem5::AddrMapper::recvRangeChange
virtual void recvRangeChange()
Definition: addr_mapper.cc:201
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:206
gem5::AddrMapper
An address mapper changes the packet addresses in going from the response port side of the mapper to ...
Definition: addr_mapper.hh:58
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:326
gem5::AddrMapper::recvReqRetry
void recvReqRetry()
Definition: addr_mapper.cc:189
gem5::AddrMapper::AddrMapperSenderState::origAddr
Addr origAddr
The original address the packet was destined for.
Definition: addr_mapper.hh:97
std::list< AddrRange >
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:781
gem5::AddrMapper::recvAtomic
Tick recvAtomic(PacketPtr pkt)
Definition: addr_mapper.cc:88
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
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:515
gem5::RangeAddrMapper::originalRanges
std::vector< AddrRange > originalRanges
This contains a list of ranges the should be remapped.
Definition: addr_mapper.hh:263
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::AddrMapper::AddrMapper
AddrMapper(const AddrMapperParams &params)
Definition: addr_mapper.cc:43
gem5::RangeAddrMapper::RangeAddrMapper
RangeAddrMapper(const RangeAddrMapperParams &p)
Definition: addr_mapper.cc:206
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:25:26 for gem5 by doxygen 1.8.17