port.hh revision 2408
1/*
2 * Copyright (c) 2002-2005 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 * Port Object Decleration. Ports are used to interface memory objects to
32 * each other.  They will always come in pairs, and we refer to the other
33 * port object as the peer.  These are used to make the design more
34 * modular so that a specific interface between every type of objcet doesn't
35 * have to be created.
36 */
37
38#ifndef __MEM_PORT_HH__
39#define __MEM_PORT_HH__
40
41#include <string>
42#include <list>
43#include <inttypes.h>
44
45#include "base/range.hh"
46#include "mem/packet.hh"
47#include "mem/request.hh"
48
49/** This typedef is used to clean up the parameter list of
50 * getDeviceAddressRanges() and getPeerAddressRanges().  It's declared
51 * outside the Port object since it's also used by some mem objects.
52 * Eventually we should move this typedef to wherever Addr is
53 * defined.
54 */
55
56typedef std::list<Range<Addr> > AddrRangeList;
57
58/**
59 * Ports are used to interface memory objects to
60 * each other.  They will always come in pairs, and we refer to the other
61 * port object as the peer.  These are used to make the design more
62 * modular so that a specific interface between every type of objcet doesn't
63 * have to be created.
64 *
65 * Recv accesor functions are being called from the peer interface.
66 * Send accessor functions are being called from the device the port is
67 * associated with, and it will call the peer recv. accessor function.
68 */
69class Port
70{
71  public:
72
73    // mey be better to use subclasses & RTTI?
74    /** Holds the ports status.  Keeps track if it is blocked, or has
75        calculated a range change. */
76    enum Status {
77        Blocked,
78        Unblocked,
79        RangeChange
80    };
81
82  private:
83
84    /** A pointer to the peer port.  Ports always come in pairs, that way they
85        can use a standardized interface to communicate between different
86        memory objects. */
87    Port *peer;
88
89  public:
90
91    /** Function to set the pointer for the peer port.
92        @todo should be called by the configuration stuff (python).
93    */
94    void setPeer(Port *port) { peer = port; }
95
96        /** Function to set the pointer for the peer port.
97        @todo should be called by the configuration stuff (python).
98    */
99    Port *getPeer(Port *port) { return peer; }
100
101  protected:
102
103    /** These functions are protected because they should only be
104     * called by a peer port, never directly by any outside object. */
105
106    /** Called to recive a timing call from the peer port. */
107    virtual bool recvTiming(Packet &pkt) = 0;
108
109    /** Called to recive a atomic call from the peer port. */
110    virtual Tick recvAtomic(Packet &pkt) = 0;
111
112    /** Called to recive a functional call from the peer port. */
113    virtual void recvFunctional(Packet &pkt) = 0;
114
115    /** Called to recieve a status change from the peer port. */
116    virtual void recvStatusChange(Status status) = 0;
117
118    /** Called by a peer port if the send was unsuccesful, and had to
119        wait.  This shouldn't be valid for response paths (IO Devices).
120        so it is set to panic if it isn't already defined.
121    */
122    virtual Packet *recvRetry() { panic("??"); }
123
124    /** Called by a peer port in order to determine the block size of the
125        device connected to this port.  It sometimes doesn't make sense for
126        this function to be called, a DMA interface doesn't really have a
127        block size, so it is defaulted to a panic.
128    */
129    virtual int deviceBlockSize() { panic("??"); }
130
131    /** The peer port is requesting us to reply with a list of the ranges we
132        are responsible for.
133        @param owner is an output param that, if set, indicates that the
134        port is the owner of the specified ranges (i.e., slave, default
135        responder, etc.).  If 'owner' is false, the interface is
136        interested in the specified ranges for snooping purposes.  If
137        an object wants to own some ranges and snoop on others, it will
138        need to use two different ports.
139    */
140    virtual void getDeviceAddressRanges(AddrRangeList &range_list,
141                                        bool &owner)
142    { panic("??"); }
143
144  public:
145
146    /** Function called by associated memory device (cache, memory, iodevice)
147        in order to send a timing request to the port.  Simply calls the peer
148        port receive function.
149        @return This function returns if the send was succesful in it's
150        recieve. If it was a failure, then the port will wait for a recvRetry
151        at which point it can issue a successful sendTiming.  This is used in
152        case a cache has a higher priority request come in while waiting for
153        the bus to arbitrate.
154    */
155    bool sendTiming(Packet &pkt) { return peer->recvTiming(pkt); }
156
157    /** Function called by the associated device to send an atomic access,
158        an access in which the data is moved and the state is updated in one
159        cycle, without interleaving with other memory accesses.
160    */
161    Tick sendAtomic(Packet &pkt)
162        { return peer->recvAtomic(pkt); }
163
164    /** Function called by the associated device to send a functional access,
165        an access in which the data is instantly updated everywhere in the
166        memory system, without affecting the current state of any block
167        or moving the block.
168    */
169    void sendFunctional(Packet &pkt)
170        { return peer->recvFunctional(pkt); }
171
172    /** Called by the associated device to send a status change to the device
173        connected to the peer interface.
174    */
175    void sendStatusChange(Status status) {peer->recvStatusChange(status); }
176
177    /** When a timing access doesn't return a success, some time later the
178        Retry will be sent.
179    */
180    Packet *sendRetry() { return peer->recvRetry(); }
181
182    /** Called by the associated device if it wishes to find out the blocksize
183        of the device on attached to the peer port.
184    */
185    int peerBlockSize() { return peer->deviceBlockSize(); }
186
187    /** Called by the associated device if it wishes to find out the address
188        ranges connected to the peer ports devices.
189    */
190    void getPeerAddressRanges(AddrRangeList &range_list, bool &owner)
191    { peer->getDeviceAddressRanges(range_list, owner); }
192
193    // Do we need similar wrappers for sendAtomic()?  If not, should
194    // we drop the "Functional" from the names?
195
196    /** This function is a wrapper around sendFunctional()
197        that breaks a larger, arbitrarily aligned access into
198        appropriate chunks.  The default implementation can use
199        getBlockSize() to determine the block size and go from there.
200    */
201    void readBlobFunctional(Addr addr, uint8_t *p, int size);
202
203    /** This function is a wrapper around sendFunctional()
204        that breaks a larger, arbitrarily aligned access into
205        appropriate chunks.  The default implementation can use
206        getBlockSize() to determine the block size and go from there.
207    */
208    void writeBlobFunctional(Addr addr, uint8_t *p, int size);
209
210    /** Fill size bytes starting at addr with byte value val.  This
211        should not need to be virtual, since it can be implemented in
212        terms of writeBlobFunctional().  However, it shouldn't be
213        performance-critical either, so it could be if we wanted to.
214        Not even sure if this is actually needed anywhere (there's a
215        prot_memset on the old functional memory that's never used),
216        but Nate claims it is.
217    */
218    void memsetBlobFunctional(Addr addr, uint8_t val, int size);
219
220  private:
221
222    /** Internal helper function for read/writeBlob().
223     */
224    void blobHelper(Addr addr, uint8_t *p, int size, Command cmd);
225};
226
227#endif //__MEM_PORT_HH__
228