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