2 * Copyright (c) 2012 ARM Limited
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.
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.
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.
37 * Authors: Andreas Hansson
40 #ifndef __MEM_ADDR_MAPPER_HH__
41 #define __MEM_ADDR_MAPPER_HH__
43 #include "mem/mem_object.hh"
44 #include "params/AddrMapper.hh"
45 #include "params/RangeAddrMapper.hh"
48 * An address mapper changes the packet addresses in going from the
49 * slave port side of the mapper to the master port side. When the
50 * slave port is queried for the address ranges, it also performs the
51 * necessary range updates. Note that snoop requests that travel from
52 * the master port (i.e. the memory side) to the slave port are
53 * currently not modified.
56 class AddrMapper : public MemObject
61 AddrMapper(const AddrMapperParams* params);
63 virtual ~AddrMapper() { }
65 virtual MasterPort& getMasterPort(const std::string& if_name,
68 virtual SlavePort& getSlavePort(const std::string& if_name,
76 * This function does the actual remapping of one address to another.
77 * It is pure virtual in this case to to allow any implementation
79 * @param addr the address to remap
80 * @return the new address (can be unchanged)
82 virtual Addr remapAddr(Addr addr) const = 0;
84 class AddrMapperSenderState : public Packet::SenderState
90 * Construct a new sender state and remember the original one
91 * so that we can implement a stack.
93 * @param _origSenderState Sender state to remember
94 * @param _origAddr Address before remapping
96 AddrMapperSenderState(SenderState* _origSenderState,
98 : origSenderState(_origSenderState), origAddr(_origAddr)
102 ~AddrMapperSenderState() { }
104 /** Pointer to old sender state of packet */
105 SenderState* origSenderState;
107 /** The original address the packet was destined for */
112 class MapperMasterPort : public MasterPort
117 MapperMasterPort(const std::string& _name, AddrMapper& _mapper)
118 : MasterPort(_name, &_mapper), mapper(_mapper)
123 void recvFunctionalSnoop(PacketPtr pkt)
125 mapper.recvFunctionalSnoop(pkt);
128 Tick recvAtomicSnoop(PacketPtr pkt)
130 return mapper.recvAtomicSnoop(pkt);
133 bool recvTimingResp(PacketPtr pkt)
135 return mapper.recvTimingResp(pkt);
138 void recvTimingSnoopReq(PacketPtr pkt)
140 mapper.recvTimingSnoopReq(pkt);
143 void recvRangeChange()
145 mapper.recvRangeChange();
148 bool isSnooping() const
150 return mapper.isSnooping();
153 unsigned deviceBlockSize() const
155 return mapper.deviceBlockSizeMaster();
160 mapper.recvRetryMaster();
169 /** Instance of master port, facing the memory side */
170 MapperMasterPort masterPort;
172 class MapperSlavePort : public SlavePort
177 MapperSlavePort(const std::string& _name, AddrMapper& _mapper)
178 : SlavePort(_name, &_mapper), mapper(_mapper)
183 void recvFunctional(PacketPtr pkt)
185 mapper.recvFunctional(pkt);
188 Tick recvAtomic(PacketPtr pkt)
190 return mapper.recvAtomic(pkt);
193 bool recvTimingReq(PacketPtr pkt)
195 return mapper.recvTimingReq(pkt);
198 bool recvTimingSnoopResp(PacketPtr pkt)
200 return mapper.recvTimingSnoopResp(pkt);
203 unsigned deviceBlockSize() const
205 return mapper.deviceBlockSizeSlave();
208 AddrRangeList getAddrRanges() const
210 return mapper.getAddrRanges();
215 mapper.recvRetrySlave();
224 /** Instance of slave port, i.e. on the CPU side */
225 MapperSlavePort slavePort;
227 void recvFunctional(PacketPtr pkt);
229 void recvFunctionalSnoop(PacketPtr pkt);
231 Tick recvAtomic(PacketPtr pkt);
233 Tick recvAtomicSnoop(PacketPtr pkt);
235 bool recvTimingReq(PacketPtr pkt);
237 bool recvTimingResp(PacketPtr pkt);
239 void recvTimingSnoopReq(PacketPtr pkt);
241 bool recvTimingSnoopResp(PacketPtr pkt);
243 unsigned deviceBlockSizeMaster();
245 unsigned deviceBlockSizeSlave();
247 virtual AddrRangeList getAddrRanges() const = 0;
249 bool isSnooping() const;
251 void recvRetryMaster();
253 void recvRetrySlave();
255 void recvRangeChange();
259 * Range address mapper that maps a set of original ranges to a set of
260 * remapped ranges, where a specific range is of the same size
261 * (original and remapped), only with an offset. It's useful for cases
262 * where memory is mapped to two different locations
264 class RangeAddrMapper : public AddrMapper
269 RangeAddrMapper(const RangeAddrMapperParams* p);
271 ~RangeAddrMapper() { }
273 AddrRangeList getAddrRanges() const;
278 * This contains a list of ranges the should be remapped. It must
279 * be the exact same length as remappedRanges which describes what
280 * manipulation should be done to each range.
282 std::vector<AddrRange> originalRanges;
285 * This contains a list of ranges that addresses should be
286 * remapped to. See the description for originalRanges above
288 std::vector<AddrRange> remappedRanges;
290 Addr remapAddr(Addr addr) const;
294 #endif //__MEM_ADDR_MAPPER_HH__