2006-01-31 18:12:49 +01:00
|
|
|
/*
|
2006-05-02 00:53:28 +02:00
|
|
|
* Copyright (c) 2006 The Regents of The University of Michigan
|
2006-01-31 18:12:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Declaration of the Packet Class, a packet is a transaction occuring
|
|
|
|
* between a single level of the memory heirarchy (ie L1->L2).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MEM_PACKET_HH__
|
|
|
|
#define __MEM_PACKET_HH__
|
|
|
|
|
2006-02-07 23:33:03 +01:00
|
|
|
#include "mem/request.hh"
|
2006-03-10 01:21:35 +01:00
|
|
|
#include "arch/isa_traits.hh"
|
2006-02-15 20:21:09 +01:00
|
|
|
#include "sim/root.hh"
|
|
|
|
|
|
|
|
struct Packet;
|
|
|
|
typedef Packet* PacketPtr;
|
|
|
|
typedef uint8_t* PacketDataPtr;
|
2006-01-31 20:09:43 +01:00
|
|
|
|
2006-01-31 18:12:49 +01:00
|
|
|
/**
|
|
|
|
* A Packet is the structure to handle requests between two levels
|
|
|
|
* of the memory system. The Request is a global object that trancends
|
|
|
|
* all of the memory heirarchy, but at each levels interface a packet
|
|
|
|
* is created to transfer data/requests. For example, a request would
|
|
|
|
* be used to initiate a request to go to memory/IOdevices, as the request
|
|
|
|
* passes through the memory system several packets will be created. One
|
|
|
|
* will be created to go between the L1 and L2 caches and another to go to
|
|
|
|
* the next level and so forth.
|
|
|
|
*
|
|
|
|
* Packets are assumed to be returned in the case of a single response. If
|
|
|
|
* the transaction has no response, then the consumer will delete the packet.
|
|
|
|
*/
|
2006-05-26 20:17:33 +02:00
|
|
|
class Packet
|
2006-01-31 18:12:49 +01:00
|
|
|
{
|
2006-04-25 01:31:50 +02:00
|
|
|
private:
|
|
|
|
/** A pointer to the data being transfered. It can be differnt sizes
|
|
|
|
at each level of the heirarchy so it belongs in the packet,
|
|
|
|
not request. This may or may not be populated when a responder recieves
|
|
|
|
the packet. If not populated it memory should be allocated.
|
|
|
|
*/
|
|
|
|
PacketDataPtr data;
|
|
|
|
|
|
|
|
/** Is the data pointer set to a value that shouldn't be freed when the
|
|
|
|
* packet is destroyed? */
|
|
|
|
bool staticData;
|
|
|
|
/** The data pointer points to a value that should be freed when the packet
|
|
|
|
* is destroyed. */
|
|
|
|
bool dynamicData;
|
|
|
|
/** the data pointer points to an array (thus delete [] ) needs to be called
|
|
|
|
* on it rather than simply delete.*/
|
|
|
|
bool arrayData;
|
|
|
|
|
|
|
|
|
2006-01-31 18:12:49 +01:00
|
|
|
/** The address of the request, could be virtual or physical (depending on
|
|
|
|
cache configurations). */
|
|
|
|
Addr addr;
|
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
/** Indicates the size of the request. */
|
|
|
|
int size;
|
|
|
|
|
|
|
|
/** A index of the source of the transaction. */
|
|
|
|
short src;
|
|
|
|
|
|
|
|
/** A index to the destination of the transaction. */
|
|
|
|
short dest;
|
|
|
|
|
|
|
|
bool addrValid;
|
|
|
|
bool sizeValid;
|
|
|
|
bool srcValid;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static const short Broadcast = -1;
|
2006-01-31 18:12:49 +01:00
|
|
|
|
|
|
|
/** A pointer to the overall request. */
|
|
|
|
RequestPtr req;
|
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
class CoherenceState {
|
|
|
|
public:
|
|
|
|
virtual ~CoherenceState() {}
|
|
|
|
};
|
|
|
|
|
2006-01-31 18:12:49 +01:00
|
|
|
/** A virtual base opaque structure used to hold
|
|
|
|
coherence status messages. */
|
2006-05-26 20:17:33 +02:00
|
|
|
CoherenceState *coherence; // virtual base opaque,
|
2006-01-31 18:12:49 +01:00
|
|
|
// assert(dynamic_cast<Foo>) etc.
|
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
class SenderState {
|
|
|
|
public:
|
|
|
|
virtual ~SenderState() {}
|
|
|
|
};
|
2006-01-31 18:12:49 +01:00
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
/** A virtual base opaque structure used to hold the senders state. */
|
|
|
|
SenderState *senderState; // virtual base opaque,
|
|
|
|
// assert(dynamic_cast<Foo>) etc.
|
2006-01-31 18:12:49 +01:00
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
private:
|
|
|
|
/** List of command attributes. */
|
|
|
|
enum CommandAttribute
|
|
|
|
{
|
|
|
|
IsRead = 1 << 0,
|
|
|
|
IsWrite = 1 << 1,
|
|
|
|
IsPrefetch = 1 << 2,
|
|
|
|
IsInvalidate = 1 << 3,
|
|
|
|
IsRequest = 1 << 4,
|
|
|
|
IsResponse = 1 << 5,
|
|
|
|
NeedsResponse = 1 << 6,
|
|
|
|
};
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
public:
|
|
|
|
/** List of all commands associated with a packet. */
|
|
|
|
enum Command
|
|
|
|
{
|
|
|
|
ReadReq = IsRead | IsRequest | NeedsResponse,
|
|
|
|
WriteReq = IsWrite | IsRequest | NeedsResponse,
|
|
|
|
WriteReqNoAck = IsWrite | IsRequest,
|
|
|
|
ReadResp = IsRead | IsResponse,
|
|
|
|
WriteResp = IsWrite | IsResponse
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::string &cmdString() const;
|
2006-01-31 18:12:49 +01:00
|
|
|
|
|
|
|
/** The command of the transaction. */
|
|
|
|
Command cmd;
|
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
bool isRead() { return (cmd & IsRead) != 0; }
|
|
|
|
bool isRequest() { return (cmd & IsRequest) != 0; }
|
|
|
|
bool isResponse() { return (cmd & IsResponse) != 0; }
|
|
|
|
bool needsResponse() { return (cmd & NeedsResponse) != 0; }
|
|
|
|
|
|
|
|
void makeTimingResponse() {
|
|
|
|
assert(needsResponse());
|
|
|
|
int icmd = (int)cmd;
|
|
|
|
icmd &= ~(IsRequest | NeedsResponse);
|
|
|
|
icmd |= IsResponse;
|
|
|
|
cmd = (Command)icmd;
|
|
|
|
dest = src;
|
|
|
|
srcValid = false;
|
|
|
|
}
|
|
|
|
|
2006-03-26 00:31:20 +01:00
|
|
|
/** The time this request was responded to. Used to calculate latencies. */
|
|
|
|
Tick time;
|
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
/** The result of a particular packets request. */
|
|
|
|
enum Result
|
|
|
|
{
|
|
|
|
Success,
|
|
|
|
BadAddress,
|
|
|
|
Unknown
|
|
|
|
};
|
|
|
|
|
2006-01-31 18:12:49 +01:00
|
|
|
/** The result of the packet transaction. */
|
2006-05-26 20:17:33 +02:00
|
|
|
Result result;
|
2006-01-31 18:12:49 +01:00
|
|
|
|
|
|
|
/** Accessor function that returns the source index of the packet. */
|
2006-05-26 20:17:33 +02:00
|
|
|
short getSrc() const { assert(srcValid); return src; }
|
|
|
|
void setSrc(short _src) { src = _src; srcValid = true; }
|
2006-01-31 18:12:49 +01:00
|
|
|
|
|
|
|
/** Accessor function that returns the destination index of
|
|
|
|
the packet. */
|
|
|
|
short getDest() const { return dest; }
|
2006-05-26 20:17:33 +02:00
|
|
|
void setDest(short _dest) { dest = _dest; }
|
2006-04-12 23:46:25 +02:00
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
Addr getAddr() const { assert(addrValid); return addr; }
|
|
|
|
void setAddr(Addr _addr) { addr = _addr; addrValid = true; }
|
|
|
|
|
|
|
|
int getSize() const { assert(sizeValid); return size; }
|
|
|
|
void setSize(int _size) { size = _size; sizeValid = true; }
|
|
|
|
|
|
|
|
|
|
|
|
Packet(Request *_req, Command _cmd, short _dest)
|
2006-04-25 01:31:50 +02:00
|
|
|
: data(NULL), staticData(false), dynamicData(false), arrayData(false),
|
2006-05-26 20:17:33 +02:00
|
|
|
addr(_req->paddr), size(_req->size), dest(_dest),
|
|
|
|
addrValid(_req->validPaddr), sizeValid(_req->validSize),
|
|
|
|
srcValid(false),
|
|
|
|
req(_req), coherence(NULL), senderState(NULL), cmd(_cmd),
|
2006-04-28 21:37:48 +02:00
|
|
|
time(curTick), result(Unknown)
|
2006-05-26 20:17:33 +02:00
|
|
|
{
|
|
|
|
}
|
2006-04-12 23:46:25 +02:00
|
|
|
|
2006-04-25 01:31:50 +02:00
|
|
|
~Packet()
|
|
|
|
{ deleteData(); }
|
|
|
|
|
|
|
|
|
|
|
|
/** Minimally reset a packet so something like simple cpu can reuse it. */
|
2006-05-02 00:53:28 +02:00
|
|
|
void reset();
|
2006-04-25 01:31:50 +02:00
|
|
|
|
2006-05-26 20:17:33 +02:00
|
|
|
void reinitFromRequest() {
|
|
|
|
if (req->validPaddr) setAddr(req->paddr);
|
|
|
|
if (req->validSize) setSize(req->size);
|
|
|
|
}
|
|
|
|
|
2006-04-25 01:31:50 +02:00
|
|
|
/** Set the data pointer to the following value that should not be freed. */
|
|
|
|
template <typename T>
|
2006-05-02 00:53:28 +02:00
|
|
|
void dataStatic(T *p);
|
2006-04-25 01:31:50 +02:00
|
|
|
|
|
|
|
/** Set the data pointer to a value that should have delete [] called on it.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
2006-05-02 00:53:28 +02:00
|
|
|
void dataDynamicArray(T *p);
|
2006-04-25 01:31:50 +02:00
|
|
|
|
|
|
|
/** set the data pointer to a value that should have delete called on it. */
|
|
|
|
template <typename T>
|
2006-05-02 00:53:28 +02:00
|
|
|
void dataDynamic(T *p);
|
2006-04-25 01:31:50 +02:00
|
|
|
|
|
|
|
/** return the value of what is pointed to in the packet. */
|
|
|
|
template <typename T>
|
2006-05-02 00:53:28 +02:00
|
|
|
T get();
|
2006-04-25 01:31:50 +02:00
|
|
|
|
|
|
|
/** get a pointer to the data ptr. */
|
|
|
|
template <typename T>
|
2006-05-02 00:53:28 +02:00
|
|
|
T* getPtr();
|
2006-04-25 01:31:50 +02:00
|
|
|
|
|
|
|
/** set the value in the data pointer to v. */
|
|
|
|
template <typename T>
|
2006-05-02 00:53:28 +02:00
|
|
|
void set(T v);
|
2006-04-25 01:31:50 +02:00
|
|
|
|
|
|
|
/** delete the data pointed to in the data pointer. Ok to call to matter how
|
|
|
|
* data was allocted. */
|
2006-05-02 00:53:28 +02:00
|
|
|
void deleteData();
|
2006-04-25 01:31:50 +02:00
|
|
|
|
|
|
|
/** If there isn't data in the packet, allocate some. */
|
2006-05-02 00:53:28 +02:00
|
|
|
void allocate();
|
2006-04-28 21:37:48 +02:00
|
|
|
|
|
|
|
/** Do the packet modify the same addresses. */
|
2006-05-02 00:53:28 +02:00
|
|
|
bool intersect(Packet *p);
|
2006-01-31 18:12:49 +01:00
|
|
|
};
|
|
|
|
|
2006-05-19 04:32:21 +02:00
|
|
|
bool fixPacket(Packet *func, Packet *timing);
|
2006-01-31 18:12:49 +01:00
|
|
|
#endif //__MEM_PACKET_HH
|