packet.cc (10885:3ac92bf1f31f) packet.cc (10886:fdd4a895f325)
1/*
2 * Copyright (c) 2011-2015 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 * Copyright (c) 2006 The Regents of The University of Michigan
15 * Copyright (c) 2010 Advanced Micro Devices, Inc.
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Ali Saidi
42 * Steve Reinhardt
43 */
44
45/**
46 * @file
47 * Definition of the Packet Class, a packet is a transaction occuring
48 * between a single level of the memory heirarchy (ie L1->L2).
49 */
50
51#include <cstring>
52#include <iostream>
53
54#include "base/cprintf.hh"
55#include "base/misc.hh"
56#include "base/trace.hh"
57#include "mem/packet.hh"
58
59using namespace std;
60
61// The one downside to bitsets is that static initializers can get ugly.
62#define SET1(a1) (1 << (a1))
63#define SET2(a1, a2) (SET1(a1) | SET1(a2))
64#define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3))
65#define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4))
66#define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5))
67#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
68
69const MemCmd::CommandInfo
70MemCmd::commandInfo[] =
71{
72 /* InvalidCmd */
73 { 0, InvalidCmd, "InvalidCmd" },
74 /* ReadReq - Read issued by a non-caching agent such as a CPU or
75 * device, with no restrictions on alignment. */
76 { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" },
77 /* ReadResp */
78 { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" },
79 /* ReadRespWithInvalidate */
80 { SET4(IsRead, IsResponse, HasData, IsInvalidate),
81 InvalidCmd, "ReadRespWithInvalidate" },
82 /* WriteReq */
83 { SET5(IsWrite, NeedsExclusive, IsRequest, NeedsResponse, HasData),
84 WriteResp, "WriteReq" },
85 /* WriteResp */
86 { SET3(IsWrite, NeedsExclusive, IsResponse), InvalidCmd, "WriteResp" },
87 /* Writeback */
88 { SET4(IsWrite, NeedsExclusive, IsRequest, HasData),
89 InvalidCmd, "Writeback" },
90 /* CleanEvict */
91 { SET2(IsWrite, IsRequest), InvalidCmd, "CleanEvict" },
92 /* SoftPFReq */
93 { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse),
94 SoftPFResp, "SoftPFReq" },
95 /* HardPFReq */
96 { SET4(IsRead, IsRequest, IsHWPrefetch, NeedsResponse),
97 HardPFResp, "HardPFReq" },
98 /* SoftPFResp */
99 { SET4(IsRead, IsResponse, IsSWPrefetch, HasData),
100 InvalidCmd, "SoftPFResp" },
101 /* HardPFResp */
102 { SET4(IsRead, IsResponse, IsHWPrefetch, HasData),
103 InvalidCmd, "HardPFResp" },
1/*
2 * Copyright (c) 2011-2015 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 * Copyright (c) 2006 The Regents of The University of Michigan
15 * Copyright (c) 2010 Advanced Micro Devices, Inc.
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Ali Saidi
42 * Steve Reinhardt
43 */
44
45/**
46 * @file
47 * Definition of the Packet Class, a packet is a transaction occuring
48 * between a single level of the memory heirarchy (ie L1->L2).
49 */
50
51#include <cstring>
52#include <iostream>
53
54#include "base/cprintf.hh"
55#include "base/misc.hh"
56#include "base/trace.hh"
57#include "mem/packet.hh"
58
59using namespace std;
60
61// The one downside to bitsets is that static initializers can get ugly.
62#define SET1(a1) (1 << (a1))
63#define SET2(a1, a2) (SET1(a1) | SET1(a2))
64#define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3))
65#define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4))
66#define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5))
67#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
68
69const MemCmd::CommandInfo
70MemCmd::commandInfo[] =
71{
72 /* InvalidCmd */
73 { 0, InvalidCmd, "InvalidCmd" },
74 /* ReadReq - Read issued by a non-caching agent such as a CPU or
75 * device, with no restrictions on alignment. */
76 { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" },
77 /* ReadResp */
78 { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" },
79 /* ReadRespWithInvalidate */
80 { SET4(IsRead, IsResponse, HasData, IsInvalidate),
81 InvalidCmd, "ReadRespWithInvalidate" },
82 /* WriteReq */
83 { SET5(IsWrite, NeedsExclusive, IsRequest, NeedsResponse, HasData),
84 WriteResp, "WriteReq" },
85 /* WriteResp */
86 { SET3(IsWrite, NeedsExclusive, IsResponse), InvalidCmd, "WriteResp" },
87 /* Writeback */
88 { SET4(IsWrite, NeedsExclusive, IsRequest, HasData),
89 InvalidCmd, "Writeback" },
90 /* CleanEvict */
91 { SET2(IsWrite, IsRequest), InvalidCmd, "CleanEvict" },
92 /* SoftPFReq */
93 { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse),
94 SoftPFResp, "SoftPFReq" },
95 /* HardPFReq */
96 { SET4(IsRead, IsRequest, IsHWPrefetch, NeedsResponse),
97 HardPFResp, "HardPFReq" },
98 /* SoftPFResp */
99 { SET4(IsRead, IsResponse, IsSWPrefetch, HasData),
100 InvalidCmd, "SoftPFResp" },
101 /* HardPFResp */
102 { SET4(IsRead, IsResponse, IsHWPrefetch, HasData),
103 InvalidCmd, "HardPFResp" },
104 /* WriteInvalidateReq */
105 { SET6(IsWrite, NeedsExclusive, IsInvalidate,
106 IsRequest, HasData, NeedsResponse),
107 WriteInvalidateResp, "WriteInvalidateReq" },
108 /* WriteInvalidateResp */
109 { SET3(IsWrite, NeedsExclusive, IsResponse),
110 InvalidCmd, "WriteInvalidateResp" },
104 /* WriteLineReq */
105 { SET5(IsWrite, NeedsExclusive, IsRequest, NeedsResponse, HasData),
106 WriteResp, "WriteLineReq" },
111 /* UpgradeReq */
112 { SET5(IsInvalidate, NeedsExclusive, IsUpgrade, IsRequest, NeedsResponse),
113 UpgradeResp, "UpgradeReq" },
114 /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
115 { SET6(IsInvalidate, NeedsExclusive, IsUpgrade, IsLlsc,
116 IsRequest, NeedsResponse),
117 UpgradeResp, "SCUpgradeReq" },
118 /* UpgradeResp */
119 { SET3(NeedsExclusive, IsUpgrade, IsResponse),
120 InvalidCmd, "UpgradeResp" },
121 /* SCUpgradeFailReq: generates UpgradeFailResp but still gets the data */
122 { SET6(IsRead, NeedsExclusive, IsInvalidate,
123 IsLlsc, IsRequest, NeedsResponse),
124 UpgradeFailResp, "SCUpgradeFailReq" },
125 /* UpgradeFailResp - Behaves like a ReadExReq, but notifies an SC
126 * that it has failed, acquires line as Dirty*/
127 { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
128 InvalidCmd, "UpgradeFailResp" },
129 /* ReadExReq - Read issues by a cache, always cache-line aligned,
130 * and the response is guaranteed to be writeable (exclusive or
131 * even modified) */
132 { SET5(IsRead, NeedsExclusive, IsInvalidate, IsRequest, NeedsResponse),
133 ReadExResp, "ReadExReq" },
134 /* ReadExResp - Response matching a read exclusive, as we check
135 * the need for exclusive also on responses */
136 { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
137 InvalidCmd, "ReadExResp" },
138 /* ReadCleanReq - Read issued by a cache, always cache-line
139 * aligned, and the response is guaranteed to not contain dirty data
140 * (exclusive or shared).*/
141 { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadCleanReq" },
142 /* ReadSharedReq - Read issued by a cache, always cache-line
143 * aligned, response is shared, possibly exclusive, owned or even
144 * modified. */
145 { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadSharedReq" },
146 /* LoadLockedReq: note that we use plain ReadResp as response, so that
147 * we can also use ReadRespWithInvalidate when needed */
148 { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse),
149 ReadResp, "LoadLockedReq" },
150 /* StoreCondReq */
151 { SET6(IsWrite, NeedsExclusive, IsLlsc,
152 IsRequest, NeedsResponse, HasData),
153 StoreCondResp, "StoreCondReq" },
154 /* StoreCondFailReq: generates failing StoreCondResp */
155 { SET6(IsWrite, NeedsExclusive, IsLlsc,
156 IsRequest, NeedsResponse, HasData),
157 StoreCondResp, "StoreCondFailReq" },
158 /* StoreCondResp */
159 { SET4(IsWrite, NeedsExclusive, IsLlsc, IsResponse),
160 InvalidCmd, "StoreCondResp" },
161 /* SwapReq -- for Swap ldstub type operations */
162 { SET6(IsRead, IsWrite, NeedsExclusive, IsRequest, HasData, NeedsResponse),
163 SwapResp, "SwapReq" },
164 /* SwapResp -- for Swap ldstub type operations */
165 { SET5(IsRead, IsWrite, NeedsExclusive, IsResponse, HasData),
166 InvalidCmd, "SwapResp" },
167 /* IntReq -- for interrupts */
168 { SET4(IsWrite, IsRequest, NeedsResponse, HasData),
169 MessageResp, "MessageReq" },
170 /* IntResp -- for interrupts */
171 { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" },
172 /* InvalidDestError -- packet dest field invalid */
173 { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
174 /* BadAddressError -- memory address invalid */
175 { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
176 /* FunctionalReadError */
177 { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" },
178 /* FunctionalWriteError */
179 { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" },
180 /* PrintReq */
181 { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" },
182 /* Flush Request */
183 { SET3(IsRequest, IsFlush, NeedsExclusive), InvalidCmd, "FlushReq" },
184 /* Invalidation Request */
107 /* UpgradeReq */
108 { SET5(IsInvalidate, NeedsExclusive, IsUpgrade, IsRequest, NeedsResponse),
109 UpgradeResp, "UpgradeReq" },
110 /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
111 { SET6(IsInvalidate, NeedsExclusive, IsUpgrade, IsLlsc,
112 IsRequest, NeedsResponse),
113 UpgradeResp, "SCUpgradeReq" },
114 /* UpgradeResp */
115 { SET3(NeedsExclusive, IsUpgrade, IsResponse),
116 InvalidCmd, "UpgradeResp" },
117 /* SCUpgradeFailReq: generates UpgradeFailResp but still gets the data */
118 { SET6(IsRead, NeedsExclusive, IsInvalidate,
119 IsLlsc, IsRequest, NeedsResponse),
120 UpgradeFailResp, "SCUpgradeFailReq" },
121 /* UpgradeFailResp - Behaves like a ReadExReq, but notifies an SC
122 * that it has failed, acquires line as Dirty*/
123 { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
124 InvalidCmd, "UpgradeFailResp" },
125 /* ReadExReq - Read issues by a cache, always cache-line aligned,
126 * and the response is guaranteed to be writeable (exclusive or
127 * even modified) */
128 { SET5(IsRead, NeedsExclusive, IsInvalidate, IsRequest, NeedsResponse),
129 ReadExResp, "ReadExReq" },
130 /* ReadExResp - Response matching a read exclusive, as we check
131 * the need for exclusive also on responses */
132 { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
133 InvalidCmd, "ReadExResp" },
134 /* ReadCleanReq - Read issued by a cache, always cache-line
135 * aligned, and the response is guaranteed to not contain dirty data
136 * (exclusive or shared).*/
137 { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadCleanReq" },
138 /* ReadSharedReq - Read issued by a cache, always cache-line
139 * aligned, response is shared, possibly exclusive, owned or even
140 * modified. */
141 { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadSharedReq" },
142 /* LoadLockedReq: note that we use plain ReadResp as response, so that
143 * we can also use ReadRespWithInvalidate when needed */
144 { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse),
145 ReadResp, "LoadLockedReq" },
146 /* StoreCondReq */
147 { SET6(IsWrite, NeedsExclusive, IsLlsc,
148 IsRequest, NeedsResponse, HasData),
149 StoreCondResp, "StoreCondReq" },
150 /* StoreCondFailReq: generates failing StoreCondResp */
151 { SET6(IsWrite, NeedsExclusive, IsLlsc,
152 IsRequest, NeedsResponse, HasData),
153 StoreCondResp, "StoreCondFailReq" },
154 /* StoreCondResp */
155 { SET4(IsWrite, NeedsExclusive, IsLlsc, IsResponse),
156 InvalidCmd, "StoreCondResp" },
157 /* SwapReq -- for Swap ldstub type operations */
158 { SET6(IsRead, IsWrite, NeedsExclusive, IsRequest, HasData, NeedsResponse),
159 SwapResp, "SwapReq" },
160 /* SwapResp -- for Swap ldstub type operations */
161 { SET5(IsRead, IsWrite, NeedsExclusive, IsResponse, HasData),
162 InvalidCmd, "SwapResp" },
163 /* IntReq -- for interrupts */
164 { SET4(IsWrite, IsRequest, NeedsResponse, HasData),
165 MessageResp, "MessageReq" },
166 /* IntResp -- for interrupts */
167 { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" },
168 /* InvalidDestError -- packet dest field invalid */
169 { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
170 /* BadAddressError -- memory address invalid */
171 { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
172 /* FunctionalReadError */
173 { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" },
174 /* FunctionalWriteError */
175 { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" },
176 /* PrintReq */
177 { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" },
178 /* Flush Request */
179 { SET3(IsRequest, IsFlush, NeedsExclusive), InvalidCmd, "FlushReq" },
180 /* Invalidation Request */
185 { SET3(NeedsExclusive, IsInvalidate, IsRequest),
186 InvalidCmd, "InvalidationReq" },
181 { SET4(IsInvalidate, IsRequest, NeedsExclusive, NeedsResponse),
182 InvalidateResp, "InvalidateReq" },
183 /* Invalidation Response */
184 { SET3(IsInvalidate, IsResponse, NeedsExclusive),
185 InvalidCmd, "InvalidateResp" }
187};
188
189bool
190Packet::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size,
191 uint8_t *_data)
192{
193 Addr func_start = getAddr();
194 Addr func_end = getAddr() + getSize() - 1;
195 Addr val_start = addr;
196 Addr val_end = val_start + size - 1;
197
198 if (is_secure != _isSecure || func_start > val_end ||
199 val_start > func_end) {
200 // no intersection
201 return false;
202 }
203
204 // check print first since it doesn't require data
205 if (isPrint()) {
206 assert(!_data);
207 safe_cast<PrintReqState*>(senderState)->printObj(obj);
208 return false;
209 }
210
211 // we allow the caller to pass NULL to signify the other packet
212 // has no data
213 if (!_data) {
214 return false;
215 }
216
217 // offset of functional request into supplied value (could be
218 // negative if partial overlap)
219 int offset = func_start - val_start;
220
221 if (isRead()) {
222 if (func_start >= val_start && func_end <= val_end) {
223 memcpy(getPtr<uint8_t>(), _data + offset, getSize());
224 if (bytesValid.empty())
225 bytesValid.resize(getSize(), true);
226 // complete overlap, and as the current packet is a read
227 // we are done
228 return true;
229 } else {
230 // Offsets and sizes to copy in case of partial overlap
231 int func_offset;
232 int val_offset;
233 int overlap_size;
234
235 // calculate offsets and copy sizes for the two byte arrays
236 if (val_start < func_start && val_end <= func_end) {
237 // the one we are checking against starts before and
238 // ends before or the same
239 val_offset = func_start - val_start;
240 func_offset = 0;
241 overlap_size = val_end - func_start;
242 } else if (val_start >= func_start && val_end > func_end) {
243 // the one we are checking against starts after or the
244 // same, and ends after
245 val_offset = 0;
246 func_offset = val_start - func_start;
247 overlap_size = func_end - val_start;
248 } else if (val_start >= func_start && val_end <= func_end) {
249 // the one we are checking against is completely
250 // subsumed in the current packet, possibly starting
251 // and ending at the same address
252 val_offset = 0;
253 func_offset = val_start - func_start;
254 overlap_size = size;
255 } else if (val_start < func_start && val_end > func_end) {
256 // the current packet is completely subsumed in the
257 // one we are checking against
258 val_offset = func_start - val_start;
259 func_offset = 0;
260 overlap_size = func_end - func_start;
261 } else {
262 panic("Missed a case for checkFunctional with "
263 " %s 0x%x size %d, against 0x%x size %d\n",
264 cmdString(), getAddr(), getSize(), addr, size);
265 }
266
267 // copy partial data into the packet's data array
268 uint8_t *dest = getPtr<uint8_t>() + func_offset;
269 uint8_t *src = _data + val_offset;
270 memcpy(dest, src, overlap_size);
271
272 // initialise the tracking of valid bytes if we have not
273 // used it already
274 if (bytesValid.empty())
275 bytesValid.resize(getSize(), false);
276
277 // track if we are done filling the functional access
278 bool all_bytes_valid = true;
279
280 int i = 0;
281
282 // check up to func_offset
283 for (; all_bytes_valid && i < func_offset; ++i)
284 all_bytes_valid &= bytesValid[i];
285
286 // update the valid bytes
287 for (i = func_offset; i < func_offset + overlap_size; ++i)
288 bytesValid[i] = true;
289
290 // check the bit after the update we just made
291 for (; all_bytes_valid && i < getSize(); ++i)
292 all_bytes_valid &= bytesValid[i];
293
294 return all_bytes_valid;
295 }
296 } else if (isWrite()) {
297 if (offset >= 0) {
298 memcpy(_data + offset, getConstPtr<uint8_t>(),
299 (min(func_end, val_end) - func_start) + 1);
300 } else {
301 // val_start > func_start
302 memcpy(_data, getConstPtr<uint8_t>() - offset,
303 (min(func_end, val_end) - val_start) + 1);
304 }
305 } else {
306 panic("Don't know how to handle command %s\n", cmdString());
307 }
308
309 // keep going with request by default
310 return false;
311}
312
313void
314Packet::pushSenderState(Packet::SenderState *sender_state)
315{
316 assert(sender_state != NULL);
317 sender_state->predecessor = senderState;
318 senderState = sender_state;
319}
320
321Packet::SenderState *
322Packet::popSenderState()
323{
324 assert(senderState != NULL);
325 SenderState *sender_state = senderState;
326 senderState = sender_state->predecessor;
327 sender_state->predecessor = NULL;
328 return sender_state;
329}
330
331void
332Packet::print(ostream &o, const int verbosity, const string &prefix) const
333{
334 ccprintf(o, "%s[%x:%x] %s\n", prefix,
335 getAddr(), getAddr() + getSize() - 1, cmdString());
336}
337
338std::string
339Packet::print() const {
340 ostringstream str;
341 print(str);
342 return str.str();
343}
344
345Packet::PrintReqState::PrintReqState(ostream &_os, int _verbosity)
346 : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity)
347{
348 labelStack.push_back(LabelStackEntry("", curPrefixPtr));
349}
350
351Packet::PrintReqState::~PrintReqState()
352{
353 labelStack.pop_back();
354 assert(labelStack.empty());
355 delete curPrefixPtr;
356}
357
358Packet::PrintReqState::
359LabelStackEntry::LabelStackEntry(const string &_label, string *_prefix)
360 : label(_label), prefix(_prefix), labelPrinted(false)
361{
362}
363
364void
365Packet::PrintReqState::pushLabel(const string &lbl, const string &prefix)
366{
367 labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
368 curPrefixPtr = new string(*curPrefixPtr);
369 *curPrefixPtr += prefix;
370}
371
372void
373Packet::PrintReqState::popLabel()
374{
375 delete curPrefixPtr;
376 curPrefixPtr = labelStack.back().prefix;
377 labelStack.pop_back();
378 assert(!labelStack.empty());
379}
380
381void
382Packet::PrintReqState::printLabels()
383{
384 if (!labelStack.back().labelPrinted) {
385 LabelStack::iterator i = labelStack.begin();
386 LabelStack::iterator end = labelStack.end();
387 while (i != end) {
388 if (!i->labelPrinted) {
389 ccprintf(os, "%s%s\n", *(i->prefix), i->label);
390 i->labelPrinted = true;
391 }
392 i++;
393 }
394 }
395}
396
397
398void
399Packet::PrintReqState::printObj(Printable *obj)
400{
401 printLabels();
402 obj->print(os, verbosity, curPrefix());
403}
186};
187
188bool
189Packet::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size,
190 uint8_t *_data)
191{
192 Addr func_start = getAddr();
193 Addr func_end = getAddr() + getSize() - 1;
194 Addr val_start = addr;
195 Addr val_end = val_start + size - 1;
196
197 if (is_secure != _isSecure || func_start > val_end ||
198 val_start > func_end) {
199 // no intersection
200 return false;
201 }
202
203 // check print first since it doesn't require data
204 if (isPrint()) {
205 assert(!_data);
206 safe_cast<PrintReqState*>(senderState)->printObj(obj);
207 return false;
208 }
209
210 // we allow the caller to pass NULL to signify the other packet
211 // has no data
212 if (!_data) {
213 return false;
214 }
215
216 // offset of functional request into supplied value (could be
217 // negative if partial overlap)
218 int offset = func_start - val_start;
219
220 if (isRead()) {
221 if (func_start >= val_start && func_end <= val_end) {
222 memcpy(getPtr<uint8_t>(), _data + offset, getSize());
223 if (bytesValid.empty())
224 bytesValid.resize(getSize(), true);
225 // complete overlap, and as the current packet is a read
226 // we are done
227 return true;
228 } else {
229 // Offsets and sizes to copy in case of partial overlap
230 int func_offset;
231 int val_offset;
232 int overlap_size;
233
234 // calculate offsets and copy sizes for the two byte arrays
235 if (val_start < func_start && val_end <= func_end) {
236 // the one we are checking against starts before and
237 // ends before or the same
238 val_offset = func_start - val_start;
239 func_offset = 0;
240 overlap_size = val_end - func_start;
241 } else if (val_start >= func_start && val_end > func_end) {
242 // the one we are checking against starts after or the
243 // same, and ends after
244 val_offset = 0;
245 func_offset = val_start - func_start;
246 overlap_size = func_end - val_start;
247 } else if (val_start >= func_start && val_end <= func_end) {
248 // the one we are checking against is completely
249 // subsumed in the current packet, possibly starting
250 // and ending at the same address
251 val_offset = 0;
252 func_offset = val_start - func_start;
253 overlap_size = size;
254 } else if (val_start < func_start && val_end > func_end) {
255 // the current packet is completely subsumed in the
256 // one we are checking against
257 val_offset = func_start - val_start;
258 func_offset = 0;
259 overlap_size = func_end - func_start;
260 } else {
261 panic("Missed a case for checkFunctional with "
262 " %s 0x%x size %d, against 0x%x size %d\n",
263 cmdString(), getAddr(), getSize(), addr, size);
264 }
265
266 // copy partial data into the packet's data array
267 uint8_t *dest = getPtr<uint8_t>() + func_offset;
268 uint8_t *src = _data + val_offset;
269 memcpy(dest, src, overlap_size);
270
271 // initialise the tracking of valid bytes if we have not
272 // used it already
273 if (bytesValid.empty())
274 bytesValid.resize(getSize(), false);
275
276 // track if we are done filling the functional access
277 bool all_bytes_valid = true;
278
279 int i = 0;
280
281 // check up to func_offset
282 for (; all_bytes_valid && i < func_offset; ++i)
283 all_bytes_valid &= bytesValid[i];
284
285 // update the valid bytes
286 for (i = func_offset; i < func_offset + overlap_size; ++i)
287 bytesValid[i] = true;
288
289 // check the bit after the update we just made
290 for (; all_bytes_valid && i < getSize(); ++i)
291 all_bytes_valid &= bytesValid[i];
292
293 return all_bytes_valid;
294 }
295 } else if (isWrite()) {
296 if (offset >= 0) {
297 memcpy(_data + offset, getConstPtr<uint8_t>(),
298 (min(func_end, val_end) - func_start) + 1);
299 } else {
300 // val_start > func_start
301 memcpy(_data, getConstPtr<uint8_t>() - offset,
302 (min(func_end, val_end) - val_start) + 1);
303 }
304 } else {
305 panic("Don't know how to handle command %s\n", cmdString());
306 }
307
308 // keep going with request by default
309 return false;
310}
311
312void
313Packet::pushSenderState(Packet::SenderState *sender_state)
314{
315 assert(sender_state != NULL);
316 sender_state->predecessor = senderState;
317 senderState = sender_state;
318}
319
320Packet::SenderState *
321Packet::popSenderState()
322{
323 assert(senderState != NULL);
324 SenderState *sender_state = senderState;
325 senderState = sender_state->predecessor;
326 sender_state->predecessor = NULL;
327 return sender_state;
328}
329
330void
331Packet::print(ostream &o, const int verbosity, const string &prefix) const
332{
333 ccprintf(o, "%s[%x:%x] %s\n", prefix,
334 getAddr(), getAddr() + getSize() - 1, cmdString());
335}
336
337std::string
338Packet::print() const {
339 ostringstream str;
340 print(str);
341 return str.str();
342}
343
344Packet::PrintReqState::PrintReqState(ostream &_os, int _verbosity)
345 : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity)
346{
347 labelStack.push_back(LabelStackEntry("", curPrefixPtr));
348}
349
350Packet::PrintReqState::~PrintReqState()
351{
352 labelStack.pop_back();
353 assert(labelStack.empty());
354 delete curPrefixPtr;
355}
356
357Packet::PrintReqState::
358LabelStackEntry::LabelStackEntry(const string &_label, string *_prefix)
359 : label(_label), prefix(_prefix), labelPrinted(false)
360{
361}
362
363void
364Packet::PrintReqState::pushLabel(const string &lbl, const string &prefix)
365{
366 labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
367 curPrefixPtr = new string(*curPrefixPtr);
368 *curPrefixPtr += prefix;
369}
370
371void
372Packet::PrintReqState::popLabel()
373{
374 delete curPrefixPtr;
375 curPrefixPtr = labelStack.back().prefix;
376 labelStack.pop_back();
377 assert(!labelStack.empty());
378}
379
380void
381Packet::PrintReqState::printLabels()
382{
383 if (!labelStack.back().labelPrinted) {
384 LabelStack::iterator i = labelStack.begin();
385 LabelStack::iterator end = labelStack.end();
386 while (i != end) {
387 if (!i->labelPrinted) {
388 ccprintf(os, "%s%s\n", *(i->prefix), i->label);
389 i->labelPrinted = true;
390 }
391 i++;
392 }
393 }
394}
395
396
397void
398Packet::PrintReqState::printObj(Printable *obj)
399{
400 printLabels();
401 obj->print(os, verbosity, curPrefix());
402}