mem: Consistently use ISO prefixes
[gem5.git] / src / mem / addr_mapper.hh
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 #ifndef __MEM_ADDR_MAPPER_HH__
39 #define __MEM_ADDR_MAPPER_HH__
40
41 #include "mem/port.hh"
42 #include "params/AddrMapper.hh"
43 #include "params/RangeAddrMapper.hh"
44 #include "sim/sim_object.hh"
45
46 /**
47 * An address mapper changes the packet addresses in going from the
48 * response port side of the mapper to the request port side. When the
49 * response port is queried for the address ranges, it also performs the
50 * necessary range updates. Note that snoop requests that travel from
51 * the request port (i.e. the memory side) to the response port are
52 * currently not modified.
53 */
54
55 class AddrMapper : public SimObject
56 {
57
58 public:
59
60 AddrMapper(const AddrMapperParams &params);
61
62 virtual ~AddrMapper() { }
63
64 Port &getPort(const std::string &if_name,
65 PortID idx=InvalidPortID) override;
66
67 void init() override;
68
69 protected:
70
71 /**
72 * This function does the actual remapping of one address to another.
73 * It is pure virtual in this case to to allow any implementation
74 * required.
75 * @param addr the address to remap
76 * @return the new address (can be unchanged)
77 */
78 virtual Addr remapAddr(Addr addr) const = 0;
79
80 class AddrMapperSenderState : public Packet::SenderState
81 {
82
83 public:
84
85 /**
86 * Construct a new sender state to remember the original address.
87 *
88 * @param _origAddr Address before remapping
89 */
90 AddrMapperSenderState(Addr _origAddr) : origAddr(_origAddr)
91 { }
92
93 /** Destructor */
94 ~AddrMapperSenderState() { }
95
96 /** The original address the packet was destined for */
97 Addr origAddr;
98
99 };
100
101 class MapperRequestPort : public RequestPort
102 {
103
104 public:
105
106 MapperRequestPort(const std::string& _name, AddrMapper& _mapper)
107 : RequestPort(_name, &_mapper), mapper(_mapper)
108 { }
109
110 protected:
111
112 void recvFunctionalSnoop(PacketPtr pkt)
113 {
114 mapper.recvFunctionalSnoop(pkt);
115 }
116
117 Tick recvAtomicSnoop(PacketPtr pkt)
118 {
119 return mapper.recvAtomicSnoop(pkt);
120 }
121
122 bool recvTimingResp(PacketPtr pkt)
123 {
124 return mapper.recvTimingResp(pkt);
125 }
126
127 void recvTimingSnoopReq(PacketPtr pkt)
128 {
129 mapper.recvTimingSnoopReq(pkt);
130 }
131
132 void recvRangeChange()
133 {
134 mapper.recvRangeChange();
135 }
136
137 bool isSnooping() const
138 {
139 return mapper.isSnooping();
140 }
141
142 void recvReqRetry()
143 {
144 mapper.recvReqRetry();
145 }
146
147 private:
148
149 AddrMapper& mapper;
150
151 };
152
153 /** Instance of request port, facing the memory side */
154 MapperRequestPort memSidePort;
155
156 class MapperResponsePort : public ResponsePort
157 {
158
159 public:
160
161 MapperResponsePort(const std::string& _name, AddrMapper& _mapper)
162 : ResponsePort(_name, &_mapper), mapper(_mapper)
163 { }
164
165 protected:
166
167 void recvFunctional(PacketPtr pkt)
168 {
169 mapper.recvFunctional(pkt);
170 }
171
172 Tick recvAtomic(PacketPtr pkt)
173 {
174 return mapper.recvAtomic(pkt);
175 }
176
177 bool recvTimingReq(PacketPtr pkt)
178 {
179 return mapper.recvTimingReq(pkt);
180 }
181
182 bool recvTimingSnoopResp(PacketPtr pkt)
183 {
184 return mapper.recvTimingSnoopResp(pkt);
185 }
186
187 AddrRangeList getAddrRanges() const
188 {
189 return mapper.getAddrRanges();
190 }
191
192 void recvRespRetry()
193 {
194 mapper.recvRespRetry();
195 }
196
197 private:
198
199 AddrMapper& mapper;
200
201 };
202
203 /** Instance of response port, i.e. on the CPU side */
204 MapperResponsePort cpuSidePort;
205
206 void recvFunctional(PacketPtr pkt);
207
208 void recvFunctionalSnoop(PacketPtr pkt);
209
210 Tick recvAtomic(PacketPtr pkt);
211
212 Tick recvAtomicSnoop(PacketPtr pkt);
213
214 bool recvTimingReq(PacketPtr pkt);
215
216 bool recvTimingResp(PacketPtr pkt);
217
218 void recvTimingSnoopReq(PacketPtr pkt);
219
220 bool recvTimingSnoopResp(PacketPtr pkt);
221
222 virtual AddrRangeList getAddrRanges() const = 0;
223
224 bool isSnooping() const;
225
226 void recvReqRetry();
227
228 void recvRespRetry();
229
230 void recvRangeChange();
231 };
232
233 /**
234 * Range address mapper that maps a set of original ranges to a set of
235 * remapped ranges, where a specific range is of the same size
236 * (original and remapped), only with an offset. It's useful for cases
237 * where memory is mapped to two different locations
238 */
239 class RangeAddrMapper : public AddrMapper
240 {
241
242 public:
243
244 RangeAddrMapper(const RangeAddrMapperParams &p);
245
246 ~RangeAddrMapper() { }
247
248 AddrRangeList getAddrRanges() const;
249
250 protected:
251
252 /**
253 * This contains a list of ranges the should be remapped. It must
254 * be the exact same length as remappedRanges which describes what
255 * manipulation should be done to each range.
256 */
257 std::vector<AddrRange> originalRanges;
258
259 /**
260 * This contains a list of ranges that addresses should be
261 * remapped to. See the description for originalRanges above
262 */
263 std::vector<AddrRange> remappedRanges;
264
265 Addr remapAddr(Addr addr) const;
266
267 };
268
269 #endif //__MEM_ADDR_MAPPER_HH__