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