Deleted Added
sdiff udiff text old ( 4660:8ba283606f48 ) new ( 4870:fcc39d001154 )
full compact
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 70 unchanged lines hidden (view full) ---

79 ReadExReq,
80 ReadExResp,
81 LoadLockedReq,
82 LoadLockedResp,
83 StoreCondReq,
84 StoreCondResp,
85 SwapReq,
86 SwapResp,
87 NUM_MEM_CMDS
88 };
89
90 private:
91 /** List of command attributes. */
92 enum Attribute
93 {
94 IsRead, //!< Data flows from responder to requester
95 IsWrite, //!< Data flows from requester to responder
96 IsPrefetch, //!< Not a demand access
97 IsInvalidate,
98 NeedsExclusive, //!< Requires exclusive copy to complete in-cache
99 IsRequest, //!< Issued by requester
100 IsResponse, //!< Issue by responder
101 NeedsResponse, //!< Requester needs response from target
102 IsSWPrefetch,
103 IsHWPrefetch,
104 IsLocked, //!< Alpha/MIPS LL or SC access
105 HasData, //!< There is an associated payload
106 NUM_COMMAND_ATTRIBUTES
107 };
108
109 /** Structure that defines attributes and other data associated
110 * with a Command. */
111 struct CommandInfo {
112 /** Set of attribute flags. */
113 const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;

--- 16 unchanged lines hidden (view full) ---

130 }
131
132 public:
133
134 bool isRead() const { return testCmdAttrib(IsRead); }
135 bool isWrite() const { return testCmdAttrib(IsWrite); }
136 bool isRequest() const { return testCmdAttrib(IsRequest); }
137 bool isResponse() const { return testCmdAttrib(IsResponse); }
138 bool needsExclusive() const { return testCmdAttrib(NeedsExclusive); }
139 bool needsResponse() const { return testCmdAttrib(NeedsResponse); }
140 bool isInvalidate() const { return testCmdAttrib(IsInvalidate); }
141 bool hasData() const { return testCmdAttrib(HasData); }
142 bool isReadWrite() const { return isRead() && isWrite(); }
143 bool isLocked() const { return testCmdAttrib(IsLocked); }
144
145 const Command responseCommand() const {
146 return commandInfo[cmd].response;
147 }
148
149 /** Return the string to a cmd given by idx. */
150 const std::string &toString() const {
151 return commandInfo[cmd].str;

--- 27 unchanged lines hidden (view full) ---

179 * different Packets along the way.)
180 */
181class Packet : public FastAlloc
182{
183 public:
184
185 typedef MemCmd::Command Command;
186
187 private:
188 /** A pointer to the data being transfered. It can be differnt
189 * sizes at each level of the heirarchy so it belongs in the
190 * packet, not request. This may or may not be populated when a
191 * responder recieves the packet. If not populated it memory
192 * should be allocated.
193 */
194 PacketDataPtr data;

--- 23 unchanged lines hidden (view full) ---

218
219 /** Device address (e.g., bus ID) of the destination of the
220 * transaction. The special value Broadcast indicates that the
221 * packet should be routed based on its address. This field is
222 * initialized in the constructor and is thus always valid
223 * (unlike * addr, size, and src). */
224 short dest;
225
226 /** Are the 'addr' and 'size' fields valid? */
227 bool addrSizeValid;
228 /** Is the 'src' field valid? */
229 bool srcValid;
230
231 enum SnoopFlag {
232 MemInhibit,
233 Shared,
234 NUM_SNOOP_FLAGS
235 };
236
237 /** Coherence snoopFlags for snooping */
238 std::bitset<NUM_SNOOP_FLAGS> snoopFlags;
239
240 public:
241
242 /** Used to calculate latencies for each packet.*/
243 Tick time;
244
245 /** The time at which the packet will be fully transmitted */
246 Tick finishTime;
247
248 /** The time at which the first chunk of the packet will be transmitted */
249 Tick firstWordTime;
250
251 /** The special destination address indicating that the packet
252 * should be routed based on its address. */
253 static const short Broadcast = -1;
254
255 /** A pointer to the original request. */
256 RequestPtr req;
257
258 /** A virtual base opaque structure used to hold coherence-related
259 * state. A specific subclass would be derived from this to
260 * carry state specific to a particular coherence protocol. */
261 class CoherenceState : public FastAlloc {
262 public:
263 virtual ~CoherenceState() {}
264 };
265
266 /** This packet's coherence state. Caches should use
267 * dynamic_cast<> to cast to the state appropriate for the
268 * system's coherence protocol. */
269 CoherenceState *coherence;
270
271 /** A virtual base opaque structure used to hold state associated
272 * with the packet but specific to the sending device (e.g., an
273 * MSHR). A pointer to this state is returned in the packet's
274 * response so that the sender can quickly look up the state
275 * needed to process it. A specific subclass would be derived
276 * from this to carry state specific to a particular sending
277 * device. */
278 class SenderState : public FastAlloc {
279 public:
280 virtual ~SenderState() {}
281 };
282
283 /** This packet's sender state. Devices should use dynamic_cast<>
284 * to cast to the state appropriate to the sender. */
285 SenderState *senderState;
286
287 public:
288
289 /** The command field of the packet. */
290 MemCmd cmd;
291
292 /** Return the string name of the cmd field (for debugging and
293 * tracing). */
294 const std::string &cmdString() const { return cmd.toString(); }
295
296 /** Return the index of this command. */
297 inline int cmdToIndex() const { return cmd.toInt(); }
298
299 public:
300
301 bool isRead() const { return cmd.isRead(); }
302 bool isWrite() const { return cmd.isWrite(); }
303 bool isRequest() const { return cmd.isRequest(); }
304 bool isResponse() const { return cmd.isResponse(); }
305 bool needsExclusive() const { return cmd.needsExclusive(); }
306 bool needsResponse() const { return cmd.needsResponse(); }
307 bool isInvalidate() const { return cmd.isInvalidate(); }
308 bool hasData() const { return cmd.hasData(); }
309 bool isReadWrite() const { return cmd.isReadWrite(); }
310 bool isLocked() const { return cmd.isLocked(); }
311
312 void assertMemInhibit() { snoopFlags[MemInhibit] = true; }
313 void assertShared() { snoopFlags[Shared] = true; }
314 bool memInhibitAsserted() { return snoopFlags[MemInhibit]; }
315 bool sharedAsserted() { return snoopFlags[Shared]; }
316
317 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN }
318
319 /** Possible results of a packet's request. */
320 enum Result
321 {
322 Success,
323 BadAddress,
324 Nacked,
325 Unknown
326 };
327
328 /** The result of this packet's request. */
329 Result result;
330
331 /** Accessor function that returns the source index of the packet. */
332 short getSrc() const { assert(srcValid); return src; }
333 void setSrc(short _src) { src = _src; srcValid = true; }
334 /** Reset source field, e.g. to retransmit packet on different bus. */
335 void clearSrc() { srcValid = false; }
336
337 /** Accessor function that returns the destination index of
338 the packet. */
339 short getDest() const { return dest; }
340 void setDest(short _dest) { dest = _dest; }
341
342 Addr getAddr() const { assert(addrSizeValid); return addr; }
343 int getSize() const { assert(addrSizeValid); return size; }
344 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); }
345
346 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; }
347 void cmdOverride(MemCmd newCmd) { cmd = newCmd; }
348
349 /** Constructor. Note that a Request object must be constructed
350 * first, but the Requests's physical address and size fields
351 * need not be valid. The command and destination addresses
352 * must be supplied. */
353 Packet(Request *_req, MemCmd _cmd, short _dest)
354 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
355 addr(_req->paddr), size(_req->size), dest(_dest),
356 addrSizeValid(_req->validPaddr), srcValid(false),
357 snoopFlags(0),
358 time(curTick),
359 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
360 result(Unknown)
361 {
362 }
363
364 /** Alternate constructor if you are trying to create a packet with
365 * a request that is for a whole block, not the address from the req.
366 * this allows for overriding the size/addr of the req.*/
367 Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize)
368 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
369 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), dest(_dest),
370 addrSizeValid(_req->validPaddr), srcValid(false),
371 snoopFlags(0),
372 time(curTick),
373 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
374 result(Unknown)
375 {
376 }
377
378 /** Alternate constructor for copying a packet. Copy all fields
379 * *except* set data allocation as static... even if the original
380 * packet's data was dynamic, we don't want to free it when the
381 * new packet is deallocated. Note that if original packet used
382 * dynamic data, user must guarantee that the new packet's
383 * lifetime is less than that of the original packet. */
384 Packet(Packet *origPkt)
385 : data(NULL), staticData(false), dynamicData(false), arrayData(false),
386 addr(origPkt->addr), size(origPkt->size),
387 src(origPkt->src), dest(origPkt->dest),
388 addrSizeValid(origPkt->addrSizeValid), srcValid(origPkt->srcValid),
389 snoopFlags(origPkt->snoopFlags),
390 time(curTick),
391 req(origPkt->req), coherence(origPkt->coherence),
392 senderState(origPkt->senderState), cmd(origPkt->cmd),
393 result(origPkt->result)
394 {
395 }
396
397 /** Destructor. */
398 ~Packet()
399 { if (staticData || dynamicData) deleteData(); }
400
401 /** Reinitialize packet address and size from the associated
402 * Request object, and reset other fields that may have been
403 * modified by a previous transaction. Typically called when a
404 * statically allocated Request/Packet pair is reused for
405 * multiple transactions. */
406 void reinitFromRequest() {
407 assert(req->validPaddr);
408 snoopFlags = 0;
409 addr = req->paddr;
410 size = req->size;
411 time = req->time;
412 addrSizeValid = true;
413 result = Unknown;
414 if (dynamicData) {
415 deleteData();
416 dynamicData = false;
417 arrayData = false;
418 }
419 }
420
421 /**
422 * Take a request packet and modify it in place to be suitable for
423 * returning as a response to that request. The source and
424 * destination fields are *not* modified, as is appropriate for
425 * atomic accesses.
426 */
427 void makeAtomicResponse()
428 {
429 assert(needsResponse());
430 assert(isRequest());
431 assert(result == Unknown);
432 cmd = cmd.responseCommand();
433 result = Success;
434 }
435
436 /**
437 * Perform the additional work required for timing responses above
438 * and beyond atomic responses; i.e., change the destination to
439 * point back to the requester and clear the source field.
440 */
441 void convertAtomicToTimingResponse()
442 {
443 dest = getSrc();
444 srcValid = false;
445 }
446
447 /**
448 * Take a request packet and modify it in place to be suitable for
449 * returning as a response to a timing request.
450 */
451 void makeTimingResponse()
452 {
453 makeAtomicResponse();
454 convertAtomicToTimingResponse();
455 }
456
457 /**
458 * Take a request packet that has been returned as NACKED and
459 * modify it so that it can be sent out again. Only packets that
460 * need a response can be NACKED, so verify that that is true.
461 */
462 void
463 reinitNacked()
464 {
465 assert(needsResponse() && result == Nacked);
466 dest = Broadcast;
467 result = Unknown;
468 }
469
470
471 /**
472 * Set the data pointer to the following value that should not be
473 * freed.
474 */
475 template <typename T>

--- 139 unchanged lines hidden ---