packet.hh (5745:6b0f8306704b) packet.hh (5764:f07df23e1fc8)
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;

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

402 bool hasData() const { return cmd.hasData(); }
403 bool isReadWrite() const { return cmd.isReadWrite(); }
404 bool isLocked() const { return cmd.isLocked(); }
405 bool isError() const { return cmd.isError(); }
406 bool isPrint() const { return cmd.isPrint(); }
407
408 // Snoop flags
409 void assertMemInhibit() { flags.set(MEM_INHIBIT); }
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;

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

402 bool hasData() const { return cmd.hasData(); }
403 bool isReadWrite() const { return cmd.isReadWrite(); }
404 bool isLocked() const { return cmd.isLocked(); }
405 bool isError() const { return cmd.isError(); }
406 bool isPrint() const { return cmd.isPrint(); }
407
408 // Snoop flags
409 void assertMemInhibit() { flags.set(MEM_INHIBIT); }
410 bool memInhibitAsserted() { return flags.any(MEM_INHIBIT); }
410 bool memInhibitAsserted() { return flags.isSet(MEM_INHIBIT); }
411 void assertShared() { flags.set(SHARED); }
411 void assertShared() { flags.set(SHARED); }
412 bool sharedAsserted() { return flags.any(SHARED); }
412 bool sharedAsserted() { return flags.isSet(SHARED); }
413
414 // Special control flags
415 void setExpressSnoop() { flags.set(EXPRESS_SNOOP); }
413
414 // Special control flags
415 void setExpressSnoop() { flags.set(EXPRESS_SNOOP); }
416 bool isExpressSnoop() { return flags.any(EXPRESS_SNOOP); }
416 bool isExpressSnoop() { return flags.isSet(EXPRESS_SNOOP); }
417 void setSupplyExclusive() { flags.set(SUPPLY_EXCLUSIVE); }
417 void setSupplyExclusive() { flags.set(SUPPLY_EXCLUSIVE); }
418 bool isSupplyExclusive() { return flags.any(SUPPLY_EXCLUSIVE); }
418 bool isSupplyExclusive() { return flags.isSet(SUPPLY_EXCLUSIVE); }
419
420 // Network error conditions... encapsulate them as methods since
421 // their encoding keeps changing (from result field to command
422 // field, etc.)
423 void
424 setNacked()
425 {
426 assert(isResponse());

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

434 cmd = MemCmd::BadAddressError;
435 }
436
437 bool wasNacked() const { return cmd == MemCmd::NetworkNackError; }
438 bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; }
439 void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
440
441 /// Accessor function to get the source index of the packet.
419
420 // Network error conditions... encapsulate them as methods since
421 // their encoding keeps changing (from result field to command
422 // field, etc.)
423 void
424 setNacked()
425 {
426 assert(isResponse());

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

434 cmd = MemCmd::BadAddressError;
435 }
436
437 bool wasNacked() const { return cmd == MemCmd::NetworkNackError; }
438 bool hadBadAddress() const { return cmd == MemCmd::BadAddressError; }
439 void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
440
441 /// Accessor function to get the source index of the packet.
442 NodeID getSrc() const { assert(flags.any(VALID_SRC)); return src; }
442 NodeID getSrc() const { assert(flags.isSet(VALID_SRC)); return src; }
443 /// Accessor function to set the source index of the packet.
444 void setSrc(NodeID _src) { src = _src; flags.set(VALID_SRC); }
445 /// Reset source field, e.g. to retransmit packet on different bus.
446 void clearSrc() { flags.clear(VALID_SRC); }
447
448 /// Accessor function for the destination index of the packet.
443 /// Accessor function to set the source index of the packet.
444 void setSrc(NodeID _src) { src = _src; flags.set(VALID_SRC); }
445 /// Reset source field, e.g. to retransmit packet on different bus.
446 void clearSrc() { flags.clear(VALID_SRC); }
447
448 /// Accessor function for the destination index of the packet.
449 NodeID getDest() const { assert(flags.any(VALID_DST)); return dest; }
449 NodeID getDest() const { assert(flags.isSet(VALID_DST)); return dest; }
450 /// Accessor function to set the destination index of the packet.
451 void setDest(NodeID _dest) { dest = _dest; flags.set(VALID_DST); }
452
450 /// Accessor function to set the destination index of the packet.
451 void setDest(NodeID _dest) { dest = _dest; flags.set(VALID_DST); }
452
453 Addr getAddr() const { assert(flags.all(VALID_ADDR)); return addr; }
454 int getSize() const { assert(flags.all(VALID_SIZE)); return size; }
453 Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; }
454 int getSize() const { assert(flags.isSet(VALID_SIZE)); return size; }
455 Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); }
456
457 /**
458 * Constructor. Note that a Request object must be constructed
459 * first, but the Requests's physical address and size fields need
460 * not be valid. The command and destination addresses must be
461 * supplied.
462 */
463 Packet(Request *_req, MemCmd _cmd, NodeID _dest)
464 : flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
465 addr(_req->paddr), size(_req->size), dest(_dest), time(curTick),
466 senderState(NULL)
467 {
455 Addr getOffset(int blkSize) const { return getAddr() & (Addr)(blkSize - 1); }
456
457 /**
458 * Constructor. Note that a Request object must be constructed
459 * first, but the Requests's physical address and size fields need
460 * not be valid. The command and destination addresses must be
461 * supplied.
462 */
463 Packet(Request *_req, MemCmd _cmd, NodeID _dest)
464 : flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
465 addr(_req->paddr), size(_req->size), dest(_dest), time(curTick),
466 senderState(NULL)
467 {
468 if (req->flags.any(Request::VALID_PADDR))
468 if (req->flags.isSet(Request::VALID_PADDR))
469 flags.set(VALID_ADDR|VALID_SIZE);
470 }
471
472 /**
473 * Alternate constructor if you are trying to create a packet with
474 * a request that is for a whole block, not the address from the
475 * req. this allows for overriding the size/addr of the req.
476 */
477 Packet(Request *_req, MemCmd _cmd, NodeID _dest, int _blkSize)
478 : flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
479 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), dest(_dest),
480 time(curTick), senderState(NULL)
481 {
469 flags.set(VALID_ADDR|VALID_SIZE);
470 }
471
472 /**
473 * Alternate constructor if you are trying to create a packet with
474 * a request that is for a whole block, not the address from the
475 * req. this allows for overriding the size/addr of the req.
476 */
477 Packet(Request *_req, MemCmd _cmd, NodeID _dest, int _blkSize)
478 : flags(VALID_DST), cmd(_cmd), req(_req), data(NULL),
479 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), dest(_dest),
480 time(curTick), senderState(NULL)
481 {
482 if (req->flags.any(Request::VALID_PADDR))
482 if (req->flags.isSet(Request::VALID_PADDR))
483 flags.set(VALID_ADDR|VALID_SIZE);
484 }
485
486 /**
487 * Alternate constructor for copying a packet. Copy all fields
488 * *except* if the original packet's data was dynamic, don't copy
489 * that, as we can't guarantee that the new packet's lifetime is
490 * less than that of the original packet. In this case the new
491 * packet should allocate its own data.
492 */
493 Packet(Packet *pkt, bool clearFlags = false)
494 : cmd(pkt->cmd), req(pkt->req),
483 flags.set(VALID_ADDR|VALID_SIZE);
484 }
485
486 /**
487 * Alternate constructor for copying a packet. Copy all fields
488 * *except* if the original packet's data was dynamic, don't copy
489 * that, as we can't guarantee that the new packet's lifetime is
490 * less than that of the original packet. In this case the new
491 * packet should allocate its own data.
492 */
493 Packet(Packet *pkt, bool clearFlags = false)
494 : cmd(pkt->cmd), req(pkt->req),
495 data(pkt->flags.any(STATIC_DATA) ? pkt->data : NULL),
495 data(pkt->flags.isSet(STATIC_DATA) ? pkt->data : NULL),
496 addr(pkt->addr), size(pkt->size), src(pkt->src), dest(pkt->dest),
497 time(curTick), senderState(pkt->senderState)
498 {
499 if (!clearFlags)
500 flags.set(pkt->flags & COPY_FLAGS);
501
502 flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE|VALID_SRC|VALID_DST));
503 flags.set(pkt->flags & STATIC_DATA);

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

521 * Request object, and reset other fields that may have been
522 * modified by a previous transaction. Typically called when a
523 * statically allocated Request/Packet pair is reused for multiple
524 * transactions.
525 */
526 void
527 reinitFromRequest()
528 {
496 addr(pkt->addr), size(pkt->size), src(pkt->src), dest(pkt->dest),
497 time(curTick), senderState(pkt->senderState)
498 {
499 if (!clearFlags)
500 flags.set(pkt->flags & COPY_FLAGS);
501
502 flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE|VALID_SRC|VALID_DST));
503 flags.set(pkt->flags & STATIC_DATA);

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

521 * Request object, and reset other fields that may have been
522 * modified by a previous transaction. Typically called when a
523 * statically allocated Request/Packet pair is reused for multiple
524 * transactions.
525 */
526 void
527 reinitFromRequest()
528 {
529 assert(req->flags.any(Request::VALID_PADDR));
529 assert(req->flags.isSet(Request::VALID_PADDR));
530 flags = 0;
531 addr = req->paddr;
532 size = req->size;
533 time = req->time;
534
535 flags.set(VALID_ADDR|VALID_SIZE);
536 deleteData();
537 }

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

546 makeResponse()
547 {
548 assert(needsResponse());
549 assert(isRequest());
550 origCmd = cmd;
551 cmd = cmd.responseCommand();
552
553 dest = src;
530 flags = 0;
531 addr = req->paddr;
532 size = req->size;
533 time = req->time;
534
535 flags.set(VALID_ADDR|VALID_SIZE);
536 deleteData();
537 }

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

546 makeResponse()
547 {
548 assert(needsResponse());
549 assert(isRequest());
550 origCmd = cmd;
551 cmd = cmd.responseCommand();
552
553 dest = src;
554 flags.set(VALID_DST, flags.any(VALID_SRC));
554 flags.set(VALID_DST, flags.isSet(VALID_SRC));
555 flags.clear(VALID_SRC);
556 }
557
558 void
559 makeAtomicResponse()
560 {
561 makeResponse();
562 }

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

585 /**
586 * Set the data pointer to the following value that should not be
587 * freed.
588 */
589 template <typename T>
590 void
591 dataStatic(T *p)
592 {
555 flags.clear(VALID_SRC);
556 }
557
558 void
559 makeAtomicResponse()
560 {
561 makeResponse();
562 }

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

585 /**
586 * Set the data pointer to the following value that should not be
587 * freed.
588 */
589 template <typename T>
590 void
591 dataStatic(T *p)
592 {
593 assert(flags.none(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
593 assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
594 data = (PacketDataPtr)p;
595 flags.set(STATIC_DATA);
596 }
597
598 /**
599 * Set the data pointer to a value that should have delete []
600 * called on it.
601 */
602 template <typename T>
603 void
604 dataDynamicArray(T *p)
605 {
594 data = (PacketDataPtr)p;
595 flags.set(STATIC_DATA);
596 }
597
598 /**
599 * Set the data pointer to a value that should have delete []
600 * called on it.
601 */
602 template <typename T>
603 void
604 dataDynamicArray(T *p)
605 {
606 assert(flags.none(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
606 assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
607 data = (PacketDataPtr)p;
608 flags.set(DYNAMIC_DATA|ARRAY_DATA);
609 }
610
611 /**
612 * set the data pointer to a value that should have delete called
613 * on it.
614 */
615 template <typename T>
616 void
617 dataDynamic(T *p)
618 {
607 data = (PacketDataPtr)p;
608 flags.set(DYNAMIC_DATA|ARRAY_DATA);
609 }
610
611 /**
612 * set the data pointer to a value that should have delete called
613 * on it.
614 */
615 template <typename T>
616 void
617 dataDynamic(T *p)
618 {
619 assert(flags.none(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
619 assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
620 data = (PacketDataPtr)p;
621 flags.set(DYNAMIC_DATA);
622 }
623
624 /**
625 * get a pointer to the data ptr.
626 */
627 template <typename T>
628 T*
629 getPtr()
630 {
620 data = (PacketDataPtr)p;
621 flags.set(DYNAMIC_DATA);
622 }
623
624 /**
625 * get a pointer to the data ptr.
626 */
627 template <typename T>
628 T*
629 getPtr()
630 {
631 assert(flags.any(STATIC_DATA|DYNAMIC_DATA));
631 assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
632 return (T*)data;
633 }
634
635 /**
636 * return the value of what is pointed to in the packet.
637 */
638 template <typename T>
639 T get();

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

684
685 /**
686 * delete the data pointed to in the data pointer. Ok to call to
687 * matter how data was allocted.
688 */
689 void
690 deleteData()
691 {
632 return (T*)data;
633 }
634
635 /**
636 * return the value of what is pointed to in the packet.
637 */
638 template <typename T>
639 T get();

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

684
685 /**
686 * delete the data pointed to in the data pointer. Ok to call to
687 * matter how data was allocted.
688 */
689 void
690 deleteData()
691 {
692 if (flags.any(ARRAY_DATA))
692 if (flags.isSet(ARRAY_DATA))
693 delete [] data;
693 delete [] data;
694 else if (flags.any(DYNAMIC_DATA))
694 else if (flags.isSet(DYNAMIC_DATA))
695 delete data;
696
697 flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA);
698 data = NULL;
699 }
700
701 /** If there isn't data in the packet, allocate some. */
702 void
703 allocate()
704 {
705 if (data) {
695 delete data;
696
697 flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA);
698 data = NULL;
699 }
700
701 /** If there isn't data in the packet, allocate some. */
702 void
703 allocate()
704 {
705 if (data) {
706 assert(flags.any(STATIC_DATA|DYNAMIC_DATA));
706 assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
707 return;
708 }
709
707 return;
708 }
709
710 assert(flags.none(STATIC_DATA|DYNAMIC_DATA));
710 assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
711 flags.set(DYNAMIC_DATA|ARRAY_DATA);
712 data = new uint8_t[getSize()];
713 }
714
715
716 /**
717 * Check a functional request against a memory value represented
718 * by a base/size pair and an associated data array. If the

--- 43 unchanged lines hidden ---
711 flags.set(DYNAMIC_DATA|ARRAY_DATA);
712 data = new uint8_t[getSize()];
713 }
714
715
716 /**
717 * Check a functional request against a memory value represented
718 * by a base/size pair and an associated data array. If the

--- 43 unchanged lines hidden ---