packet.hh revision 2394
1/*
2 * Copyright (c) 2003 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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @file
31 * Declaration of the Packet Class, a packet is a transaction occuring
32 * between a single level of the memory heirarchy (ie L1->L2).
33 */
34
35#ifndef __MEM_PACKET_HH__
36#define __MEM_PACKET_HH__
37
38#include "mem/request.hh"
39#include "targetarch/isa_traits.hh"
40#include "sim/root.hh"
41
42struct Packet;
43typedef Packet* PacketPtr;
44typedef uint8_t* PacketDataPtr;
45
46/** List of all commands associated with a packet. */
47enum Command
48{
49    Read,
50    Write
51};
52
53/** The result of a particular pakets request. */
54enum PacketResult
55{
56    Success,
57    BadAddress
58};
59
60class SenderState{};
61class Coherence{};
62
63/**
64 * A Packet is the structure to handle requests between two levels
65 * of the memory system.  The Request is a global object that trancends
66 * all of the memory heirarchy, but at each levels interface a packet
67 * is created to transfer data/requests.  For example, a request would
68 * be used to initiate a request to go to memory/IOdevices, as the request
69 * passes through the memory system several packets will be created.  One
70 * will be created to go between the L1 and L2 caches and another to go to
71 * the next level and so forth.
72 *
73 * Packets are assumed to be returned in the case of a single response.  If
74 * the transaction has no response, then the consumer will delete the packet.
75 */
76struct Packet
77{
78    /** The address of the request, could be virtual or physical (depending on
79        cache configurations). */
80    Addr addr;
81
82    /** Flag structure to hold flags for this particular packet */
83    uint64_t flags;
84
85    /** A pointer to the overall request. */
86    RequestPtr req;
87
88    /** A virtual base opaque structure used to hold
89        coherence status messages. */
90    Coherence *coherence;  // virtual base opaque,
91                           // assert(dynamic_cast<Foo>) etc.
92
93    /** A virtual base opaque structure used to hold the senders state. */
94    SenderState *senderState; // virtual base opaque,
95                           // assert(dynamic_cast<Foo>) etc.
96
97    /** A pointer to the data being transfered.  It can be differnt sizes
98        at each level of the heirarchy so it belongs in the packet,
99        not request*/
100    PacketDataPtr data;
101
102    /** Indicates the size of the request. */
103    int size;
104
105    /** A index of the source of the transaction. */
106    short src;
107
108    /** A index to the destination of the transaction. */
109    short dest;
110
111    /** The command of the transaction. */
112    Command cmd;
113
114    /** The result of the packet transaction. */
115    PacketResult result;
116
117    /** Accessor function that returns the source index of the packet. */
118    short getSrc() const { return src; }
119
120    /** Accessor function that returns the destination index of
121        the packet. */
122    short getDest() const { return dest; }
123};
124
125#endif //__MEM_PACKET_HH
126