addr_mapper.hh revision 13784
18441SN/A/* 28441SN/A * Copyright (c) 2012 ARM Limited 37893SN/A * All rights reserved 410798Ssteve.reinhardt@amd.com * 510798Ssteve.reinhardt@amd.com * The license below extends only to copyright in the software and shall 610242Ssteve.reinhardt@amd.com * not be construed as granting a license to any other intellectual 710242Ssteve.reinhardt@amd.com * property including but not limited to intellectual property relating 810798Ssteve.reinhardt@amd.com * to a hardware implementation of the functionality of the software 97893SN/A * licensed hereunder. You may use the software subject to the license 107893SN/A * terms below provided that you ensure that this notice is replicated 117893SN/A * unmodified and in its entirety in all distributions of the software, 1210798Ssteve.reinhardt@amd.com * modified or unmodified, in source code or in binary form. 1310798Ssteve.reinhardt@amd.com * 1410798Ssteve.reinhardt@amd.com * Redistribution and use in source and binary forms, with or without 1510242Ssteve.reinhardt@amd.com * modification, are permitted provided that the following conditions are 1610242Ssteve.reinhardt@amd.com * met: redistributions of source code must retain the above copyright 1710242Ssteve.reinhardt@amd.com * notice, this list of conditions and the following disclaimer; 1810242Ssteve.reinhardt@amd.com * redistributions in binary form must reproduce the above copyright 1910242Ssteve.reinhardt@amd.com * notice, this list of conditions and the following disclaimer in the 2010242Ssteve.reinhardt@amd.com * documentation and/or other materials provided with the distribution; 2110242Ssteve.reinhardt@amd.com * neither the name of the copyright holders nor the names of its 2210242Ssteve.reinhardt@amd.com * contributors may be used to endorse or promote products derived from 2310242Ssteve.reinhardt@amd.com * this software without specific prior written permission. 2410242Ssteve.reinhardt@amd.com * 2510242Ssteve.reinhardt@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610798Ssteve.reinhardt@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 277893SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 287893SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 297893SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 307893SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 317893SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 327893SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 337893SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 347893SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 357893SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 367893SN/A * 377893SN/A * Authors: Andreas Hansson 387893SN/A */ 397893SN/A 4010036SAli.Saidi@ARM.com#ifndef __MEM_ADDR_MAPPER_HH__ 4110036SAli.Saidi@ARM.com#define __MEM_ADDR_MAPPER_HH__ 4210036SAli.Saidi@ARM.com 4310036SAli.Saidi@ARM.com#include "mem/mem_object.hh" 4410036SAli.Saidi@ARM.com#include "params/AddrMapper.hh" 4510036SAli.Saidi@ARM.com#include "params/RangeAddrMapper.hh" 4610036SAli.Saidi@ARM.com 4710036SAli.Saidi@ARM.com/** 487893SN/A * An address mapper changes the packet addresses in going from the 497893SN/A * slave port side of the mapper to the master port side. When the 507893SN/A * slave port is queried for the address ranges, it also performs the 517893SN/A * necessary range updates. Note that snoop requests that travel from 527893SN/A * the master port (i.e. the memory side) to the slave port are 537893SN/A * currently not modified. 547893SN/A */ 557893SN/A 567893SN/Aclass AddrMapper : public MemObject 577893SN/A{ 587893SN/A 597893SN/A public: 607893SN/A 617893SN/A AddrMapper(const AddrMapperParams* params); 627893SN/A 637893SN/A virtual ~AddrMapper() { } 647893SN/A 657893SN/A Port &getPort(const std::string &if_name, 667893SN/A PortID idx=InvalidPortID) override; 677893SN/A 687893SN/A virtual void init(); 697893SN/A 707893SN/A protected: 717893SN/A 727893SN/A /** 737893SN/A * This function does the actual remapping of one address to another. 747893SN/A * It is pure virtual in this case to to allow any implementation 757893SN/A * required. 767893SN/A * @param addr the address to remap 777893SN/A * @return the new address (can be unchanged) 787893SN/A */ 797893SN/A virtual Addr remapAddr(Addr addr) const = 0; 807893SN/A 817893SN/A class AddrMapperSenderState : public Packet::SenderState 827893SN/A { 837893SN/A 847893SN/A public: 857893SN/A 867893SN/A /** 877893SN/A * Construct a new sender state to remember the original address. 887893SN/A * 897893SN/A * @param _origAddr Address before remapping 908252SN/A */ 918252SN/A AddrMapperSenderState(Addr _origAddr) : origAddr(_origAddr) 9210798Ssteve.reinhardt@amd.com { } 93 94 /** Destructor */ 95 ~AddrMapperSenderState() { } 96 97 /** The original address the packet was destined for */ 98 Addr origAddr; 99 100 }; 101 102 class MapperMasterPort : public MasterPort 103 { 104 105 public: 106 107 MapperMasterPort(const std::string& _name, AddrMapper& _mapper) 108 : MasterPort(_name, &_mapper), mapper(_mapper) 109 { } 110 111 protected: 112 113 void recvFunctionalSnoop(PacketPtr pkt) 114 { 115 mapper.recvFunctionalSnoop(pkt); 116 } 117 118 Tick recvAtomicSnoop(PacketPtr pkt) 119 { 120 return mapper.recvAtomicSnoop(pkt); 121 } 122 123 bool recvTimingResp(PacketPtr pkt) 124 { 125 return mapper.recvTimingResp(pkt); 126 } 127 128 void recvTimingSnoopReq(PacketPtr pkt) 129 { 130 mapper.recvTimingSnoopReq(pkt); 131 } 132 133 void recvRangeChange() 134 { 135 mapper.recvRangeChange(); 136 } 137 138 bool isSnooping() const 139 { 140 return mapper.isSnooping(); 141 } 142 143 void recvReqRetry() 144 { 145 mapper.recvReqRetry(); 146 } 147 148 private: 149 150 AddrMapper& mapper; 151 152 }; 153 154 /** Instance of master port, facing the memory side */ 155 MapperMasterPort masterPort; 156 157 class MapperSlavePort : public SlavePort 158 { 159 160 public: 161 162 MapperSlavePort(const std::string& _name, AddrMapper& _mapper) 163 : SlavePort(_name, &_mapper), mapper(_mapper) 164 { } 165 166 protected: 167 168 void recvFunctional(PacketPtr pkt) 169 { 170 mapper.recvFunctional(pkt); 171 } 172 173 Tick recvAtomic(PacketPtr pkt) 174 { 175 return mapper.recvAtomic(pkt); 176 } 177 178 bool recvTimingReq(PacketPtr pkt) 179 { 180 return mapper.recvTimingReq(pkt); 181 } 182 183 bool recvTimingSnoopResp(PacketPtr pkt) 184 { 185 return mapper.recvTimingSnoopResp(pkt); 186 } 187 188 AddrRangeList getAddrRanges() const 189 { 190 return mapper.getAddrRanges(); 191 } 192 193 void recvRespRetry() 194 { 195 mapper.recvRespRetry(); 196 } 197 198 private: 199 200 AddrMapper& mapper; 201 202 }; 203 204 /** Instance of slave port, i.e. on the CPU side */ 205 MapperSlavePort slavePort; 206 207 void recvFunctional(PacketPtr pkt); 208 209 void recvFunctionalSnoop(PacketPtr pkt); 210 211 Tick recvAtomic(PacketPtr pkt); 212 213 Tick recvAtomicSnoop(PacketPtr pkt); 214 215 bool recvTimingReq(PacketPtr pkt); 216 217 bool recvTimingResp(PacketPtr pkt); 218 219 void recvTimingSnoopReq(PacketPtr pkt); 220 221 bool recvTimingSnoopResp(PacketPtr pkt); 222 223 virtual AddrRangeList getAddrRanges() const = 0; 224 225 bool isSnooping() const; 226 227 void recvReqRetry(); 228 229 void recvRespRetry(); 230 231 void recvRangeChange(); 232}; 233 234/** 235 * Range address mapper that maps a set of original ranges to a set of 236 * remapped ranges, where a specific range is of the same size 237 * (original and remapped), only with an offset. It's useful for cases 238 * where memory is mapped to two different locations 239 */ 240class RangeAddrMapper : public AddrMapper 241{ 242 243 public: 244 245 RangeAddrMapper(const RangeAddrMapperParams* p); 246 247 ~RangeAddrMapper() { } 248 249 AddrRangeList getAddrRanges() const; 250 251 protected: 252 253 /** 254 * This contains a list of ranges the should be remapped. It must 255 * be the exact same length as remappedRanges which describes what 256 * manipulation should be done to each range. 257 */ 258 std::vector<AddrRange> originalRanges; 259 260 /** 261 * This contains a list of ranges that addresses should be 262 * remapped to. See the description for originalRanges above 263 */ 264 std::vector<AddrRange> remappedRanges; 265 266 Addr remapAddr(Addr addr) const; 267 268}; 269 270#endif //__MEM_ADDR_MAPPER_HH__ 271