e05783ca9cd5edb5b0feb049fb709cce6ea75b77
2 * Copyright (c) 2011-2016 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 * Copyright (c) 2006 The Regents of The University of Michigan
15 * Copyright (c) 2010,2015 Advanced Micro Devices, Inc.
16 * All rights reserved.
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.
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.
47 * Definition of the Packet Class, a packet is a transaction occuring
48 * between a single level of the memory heirarchy (ie L1->L2).
51 #include "mem/packet.hh"
56 #include "base/cprintf.hh"
57 #include "base/logging.hh"
58 #include "base/trace.hh"
62 // The one downside to bitsets is that static initializers can get ugly.
63 #define SET1(a1) (1 << (a1))
64 #define SET2(a1, a2) (SET1(a1) | SET1(a2))
65 #define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3))
66 #define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4))
67 #define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5))
68 #define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
69 #define SET7(a1, a2, a3, a4, a5, a6, a7) (SET6(a1, a2, a3, a4, a5, a6) | \
72 const MemCmd::CommandInfo
73 MemCmd::commandInfo
[] =
76 { 0, InvalidCmd
, "InvalidCmd" },
77 /* ReadReq - Read issued by a non-caching agent such as a CPU or
78 * device, with no restrictions on alignment. */
79 { SET3(IsRead
, IsRequest
, NeedsResponse
), ReadResp
, "ReadReq" },
81 { SET3(IsRead
, IsResponse
, HasData
), InvalidCmd
, "ReadResp" },
82 /* ReadRespWithInvalidate */
83 { SET4(IsRead
, IsResponse
, HasData
, IsInvalidate
),
84 InvalidCmd
, "ReadRespWithInvalidate" },
86 { SET5(IsWrite
, NeedsWritable
, IsRequest
, NeedsResponse
, HasData
),
87 WriteResp
, "WriteReq" },
89 { SET2(IsWrite
, IsResponse
), InvalidCmd
, "WriteResp" },
91 { SET5(IsWrite
, IsRequest
, IsEviction
, HasData
, FromCache
),
92 InvalidCmd
, "WritebackDirty" },
93 /* WritebackClean - This allows the upstream cache to writeback a
94 * line to the downstream cache without it being considered
96 { SET5(IsWrite
, IsRequest
, IsEviction
, HasData
, FromCache
),
97 InvalidCmd
, "WritebackClean" },
99 { SET3(IsRequest
, IsEviction
, FromCache
), InvalidCmd
, "CleanEvict" },
101 { SET4(IsRead
, IsRequest
, IsSWPrefetch
, NeedsResponse
),
102 SoftPFResp
, "SoftPFReq" },
104 { SET5(IsRead
, IsRequest
, IsHWPrefetch
, NeedsResponse
, FromCache
),
105 HardPFResp
, "HardPFReq" },
107 { SET4(IsRead
, IsResponse
, IsSWPrefetch
, HasData
),
108 InvalidCmd
, "SoftPFResp" },
110 { SET4(IsRead
, IsResponse
, IsHWPrefetch
, HasData
),
111 InvalidCmd
, "HardPFResp" },
113 { SET5(IsWrite
, NeedsWritable
, IsRequest
, NeedsResponse
, HasData
),
114 WriteResp
, "WriteLineReq" },
116 { SET6(IsInvalidate
, NeedsWritable
, IsUpgrade
, IsRequest
, NeedsResponse
,
118 UpgradeResp
, "UpgradeReq" },
119 /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
120 { SET7(IsInvalidate
, NeedsWritable
, IsUpgrade
, IsLlsc
,
121 IsRequest
, NeedsResponse
, FromCache
),
122 UpgradeResp
, "SCUpgradeReq" },
124 { SET2(IsUpgrade
, IsResponse
),
125 InvalidCmd
, "UpgradeResp" },
126 /* SCUpgradeFailReq: generates UpgradeFailResp but still gets the data */
127 { SET7(IsRead
, NeedsWritable
, IsInvalidate
,
128 IsLlsc
, IsRequest
, NeedsResponse
, FromCache
),
129 UpgradeFailResp
, "SCUpgradeFailReq" },
130 /* UpgradeFailResp - Behaves like a ReadExReq, but notifies an SC
131 * that it has failed, acquires line as Dirty*/
132 { SET3(IsRead
, IsResponse
, HasData
),
133 InvalidCmd
, "UpgradeFailResp" },
134 /* ReadExReq - Read issues by a cache, always cache-line aligned,
135 * and the response is guaranteed to be writeable (exclusive or
137 { SET6(IsRead
, NeedsWritable
, IsInvalidate
, IsRequest
, NeedsResponse
,
139 ReadExResp
, "ReadExReq" },
140 /* ReadExResp - Response matching a read exclusive, as we check
141 * the need for exclusive also on responses */
142 { SET3(IsRead
, IsResponse
, HasData
),
143 InvalidCmd
, "ReadExResp" },
144 /* ReadCleanReq - Read issued by a cache, always cache-line
145 * aligned, and the response is guaranteed to not contain dirty data
146 * (exclusive or shared).*/
147 { SET4(IsRead
, IsRequest
, NeedsResponse
, FromCache
),
148 ReadResp
, "ReadCleanReq" },
149 /* ReadSharedReq - Read issued by a cache, always cache-line
150 * aligned, response is shared, possibly exclusive, owned or even
152 { SET4(IsRead
, IsRequest
, NeedsResponse
, FromCache
),
153 ReadResp
, "ReadSharedReq" },
154 /* LoadLockedReq: note that we use plain ReadResp as response, so that
155 * we can also use ReadRespWithInvalidate when needed */
156 { SET4(IsRead
, IsLlsc
, IsRequest
, NeedsResponse
),
157 ReadResp
, "LoadLockedReq" },
159 { SET6(IsWrite
, NeedsWritable
, IsLlsc
,
160 IsRequest
, NeedsResponse
, HasData
),
161 StoreCondResp
, "StoreCondReq" },
162 /* StoreCondFailReq: generates failing StoreCondResp */
163 { SET6(IsWrite
, NeedsWritable
, IsLlsc
,
164 IsRequest
, NeedsResponse
, HasData
),
165 StoreCondResp
, "StoreCondFailReq" },
167 { SET3(IsWrite
, IsLlsc
, IsResponse
),
168 InvalidCmd
, "StoreCondResp" },
169 /* SwapReq -- for Swap ldstub type operations */
170 { SET6(IsRead
, IsWrite
, NeedsWritable
, IsRequest
, HasData
, NeedsResponse
),
171 SwapResp
, "SwapReq" },
172 /* SwapResp -- for Swap ldstub type operations */
173 { SET4(IsRead
, IsWrite
, IsResponse
, HasData
),
174 InvalidCmd
, "SwapResp" },
175 /* IntReq -- for interrupts */
176 { SET4(IsWrite
, IsRequest
, NeedsResponse
, HasData
),
177 MessageResp
, "MessageReq" },
178 /* IntResp -- for interrupts */
179 { SET2(IsWrite
, IsResponse
), InvalidCmd
, "MessageResp" },
180 /* MemFenceReq -- for synchronization requests */
181 {SET2(IsRequest
, NeedsResponse
), MemFenceResp
, "MemFenceReq"},
182 /* MemFenceResp -- for synchronization responses */
183 {SET1(IsResponse
), InvalidCmd
, "MemFenceResp"},
184 /* InvalidDestError -- packet dest field invalid */
185 { SET2(IsResponse
, IsError
), InvalidCmd
, "InvalidDestError" },
186 /* BadAddressError -- memory address invalid */
187 { SET2(IsResponse
, IsError
), InvalidCmd
, "BadAddressError" },
188 /* FunctionalReadError */
189 { SET3(IsRead
, IsResponse
, IsError
), InvalidCmd
, "FunctionalReadError" },
190 /* FunctionalWriteError */
191 { SET3(IsWrite
, IsResponse
, IsError
), InvalidCmd
, "FunctionalWriteError" },
193 { SET2(IsRequest
, IsPrint
), InvalidCmd
, "PrintReq" },
195 { SET3(IsRequest
, IsFlush
, NeedsWritable
), InvalidCmd
, "FlushReq" },
196 /* Invalidation Request */
197 { SET5(IsInvalidate
, IsRequest
, NeedsWritable
, NeedsResponse
, FromCache
),
198 InvalidateResp
, "InvalidateReq" },
199 /* Invalidation Response */
200 { SET2(IsInvalidate
, IsResponse
),
201 InvalidCmd
, "InvalidateResp" }
205 Packet::checkFunctional(Printable
*obj
, Addr addr
, bool is_secure
, int size
,
208 Addr func_start
= getAddr();
209 Addr func_end
= getAddr() + getSize() - 1;
210 Addr val_start
= addr
;
211 Addr val_end
= val_start
+ size
- 1;
213 if (is_secure
!= _isSecure
|| func_start
> val_end
||
214 val_start
> func_end
) {
219 // check print first since it doesn't require data
222 safe_cast
<PrintReqState
*>(senderState
)->printObj(obj
);
226 // we allow the caller to pass NULL to signify the other packet
232 // offset of functional request into supplied value (could be
233 // negative if partial overlap)
234 int offset
= func_start
- val_start
;
237 if (func_start
>= val_start
&& func_end
<= val_end
) {
238 memcpy(getPtr
<uint8_t>(), _data
+ offset
, getSize());
239 if (bytesValid
.empty())
240 bytesValid
.resize(getSize(), true);
241 // complete overlap, and as the current packet is a read
245 // Offsets and sizes to copy in case of partial overlap
250 // calculate offsets and copy sizes for the two byte arrays
251 if (val_start
< func_start
&& val_end
<= func_end
) {
252 // the one we are checking against starts before and
253 // ends before or the same
254 val_offset
= func_start
- val_start
;
256 overlap_size
= val_end
- func_start
;
257 } else if (val_start
>= func_start
&& val_end
> func_end
) {
258 // the one we are checking against starts after or the
259 // same, and ends after
261 func_offset
= val_start
- func_start
;
262 overlap_size
= func_end
- val_start
;
263 } else if (val_start
>= func_start
&& val_end
<= func_end
) {
264 // the one we are checking against is completely
265 // subsumed in the current packet, possibly starting
266 // and ending at the same address
268 func_offset
= val_start
- func_start
;
270 } else if (val_start
< func_start
&& val_end
> func_end
) {
271 // the current packet is completely subsumed in the
272 // one we are checking against
273 val_offset
= func_start
- val_start
;
275 overlap_size
= func_end
- func_start
;
277 panic("Missed a case for checkFunctional with "
278 " %s 0x%x size %d, against 0x%x size %d\n",
279 cmdString(), getAddr(), getSize(), addr
, size
);
282 // copy partial data into the packet's data array
283 uint8_t *dest
= getPtr
<uint8_t>() + func_offset
;
284 uint8_t *src
= _data
+ val_offset
;
285 memcpy(dest
, src
, overlap_size
);
287 // initialise the tracking of valid bytes if we have not
289 if (bytesValid
.empty())
290 bytesValid
.resize(getSize(), false);
292 // track if we are done filling the functional access
293 bool all_bytes_valid
= true;
297 // check up to func_offset
298 for (; all_bytes_valid
&& i
< func_offset
; ++i
)
299 all_bytes_valid
&= bytesValid
[i
];
301 // update the valid bytes
302 for (i
= func_offset
; i
< func_offset
+ overlap_size
; ++i
)
303 bytesValid
[i
] = true;
305 // check the bit after the update we just made
306 for (; all_bytes_valid
&& i
< getSize(); ++i
)
307 all_bytes_valid
&= bytesValid
[i
];
309 return all_bytes_valid
;
311 } else if (isWrite()) {
313 memcpy(_data
+ offset
, getConstPtr
<uint8_t>(),
314 (min(func_end
, val_end
) - func_start
) + 1);
316 // val_start > func_start
317 memcpy(_data
, getConstPtr
<uint8_t>() - offset
,
318 (min(func_end
, val_end
) - val_start
) + 1);
321 panic("Don't know how to handle command %s\n", cmdString());
324 // keep going with request by default
329 Packet::pushSenderState(Packet::SenderState
*sender_state
)
331 assert(sender_state
!= NULL
);
332 sender_state
->predecessor
= senderState
;
333 senderState
= sender_state
;
336 Packet::SenderState
*
337 Packet::popSenderState()
339 assert(senderState
!= NULL
);
340 SenderState
*sender_state
= senderState
;
341 senderState
= sender_state
->predecessor
;
342 sender_state
->predecessor
= NULL
;
347 Packet::print(ostream
&o
, const int verbosity
, const string
&prefix
) const
349 ccprintf(o
, "%s%s [%x:%x]%s%s%s%s", prefix
, cmdString(),
350 getAddr(), getAddr() + getSize() - 1,
351 req
->isSecure() ? " (s)" : "",
352 req
->isInstFetch() ? " IF" : "",
353 req
->isUncacheable() ? " UC" : "",
354 isExpressSnoop() ? " ES" : "");
358 Packet::print() const {
364 Packet::PrintReqState::PrintReqState(ostream
&_os
, int _verbosity
)
365 : curPrefixPtr(new string("")), os(_os
), verbosity(_verbosity
)
367 labelStack
.push_back(LabelStackEntry("", curPrefixPtr
));
370 Packet::PrintReqState::~PrintReqState()
372 labelStack
.pop_back();
373 assert(labelStack
.empty());
377 Packet::PrintReqState::
378 LabelStackEntry::LabelStackEntry(const string
&_label
, string
*_prefix
)
379 : label(_label
), prefix(_prefix
), labelPrinted(false)
384 Packet::PrintReqState::pushLabel(const string
&lbl
, const string
&prefix
)
386 labelStack
.push_back(LabelStackEntry(lbl
, curPrefixPtr
));
387 curPrefixPtr
= new string(*curPrefixPtr
);
388 *curPrefixPtr
+= prefix
;
392 Packet::PrintReqState::popLabel()
395 curPrefixPtr
= labelStack
.back().prefix
;
396 labelStack
.pop_back();
397 assert(!labelStack
.empty());
401 Packet::PrintReqState::printLabels()
403 if (!labelStack
.back().labelPrinted
) {
404 LabelStack::iterator i
= labelStack
.begin();
405 LabelStack::iterator end
= labelStack
.end();
407 if (!i
->labelPrinted
) {
408 ccprintf(os
, "%s%s\n", *(i
->prefix
), i
->label
);
409 i
->labelPrinted
= true;
418 Packet::PrintReqState::printObj(Printable
*obj
)
421 obj
->print(os
, verbosity
, curPrefix());