port.hh revision 8853:0216ed80991b
1/*
2 * Copyright (c) 2011-2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder.  You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ron Dreslinski
41 *          Andreas Hansson
42 */
43
44/**
45 * @file
46 * Port Object Declaration. Ports are used to interface memory objects to
47 * each other.  They will always come in pairs, and we refer to the other
48 * port object as the peer.  These are used to make the design more
49 * modular so that a specific interface between every type of objcet doesn't
50 * have to be created.
51 */
52
53#ifndef __MEM_PORT_HH__
54#define __MEM_PORT_HH__
55
56#include <list>
57
58#include "base/range.hh"
59#include "mem/packet.hh"
60
61/** This typedef is used to clean up getAddrRanges(). It's declared
62 * outside the Port object since it's also used by some mem objects.
63 * Eventually we should move this typedef to wherever Addr is
64 * defined.
65 */
66
67typedef std::list<Range<Addr> > AddrRangeList;
68typedef std::list<Range<Addr> >::iterator AddrRangeIter;
69
70class MemObject;
71
72/**
73 * Ports are used to interface memory objects to
74 * each other.  They will always come in pairs, and we refer to the other
75 * port object as the peer.  These are used to make the design more
76 * modular so that a specific interface between every type of objcet doesn't
77 * have to be created.
78 *
79 * Recv accesor functions are being called from the peer interface.
80 * Send accessor functions are being called from the device the port is
81 * associated with, and it will call the peer recv. accessor function.
82 */
83class Port
84{
85  protected:
86    /** Descriptive name (for DPRINTF output) */
87    mutable std::string portName;
88
89    /** A pointer to the peer port.  Ports always come in pairs, that way they
90        can use a standardized interface to communicate between different
91        memory objects. */
92    Port *peer;
93
94    /** A pointer to the MemObject that owns this port. This may not be set. */
95    MemObject *owner;
96
97  public:
98    /**
99     * Constructor.
100     *
101     * @param _name Port name for DPRINTF output.  Should include name
102     * of memory system object to which the port belongs.
103     * @param _owner Pointer to the MemObject that owns this port.
104     * Will not necessarily be set.
105     */
106    Port(const std::string &_name, MemObject *_owner);
107
108    /** Return port name (for DPRINTF). */
109    const std::string &name() const { return portName; }
110
111    virtual ~Port();
112
113    void setName(const std::string &name)
114    { portName = name; }
115
116    /** Function to set the pointer for the peer port. */
117    virtual void setPeer(Port *port);
118
119    /** Function to get the pointer to the peer port. */
120    Port *getPeer() { return peer; }
121
122    /** Function to set the owner of this port. */
123    void setOwner(MemObject *_owner);
124
125    /** Function to return the owner of this port. */
126    MemObject *getOwner() { return owner; }
127
128    bool isConnected() { return peer != NULL; }
129
130  protected:
131
132    /** These functions are protected because they should only be
133     * called by a peer port, never directly by any outside object. */
134
135    /** Called to recive a timing call from the peer port. */
136    virtual bool recvTiming(PacketPtr pkt) = 0;
137
138    /** Called to recive a atomic call from the peer port. */
139    virtual Tick recvAtomic(PacketPtr pkt) = 0;
140
141    /** Called to recive a functional call from the peer port. */
142    virtual void recvFunctional(PacketPtr pkt) = 0;
143
144    /** Called to recieve an address range change from the peer port. */
145    virtual void recvRangeChange() = 0;
146
147    /** Called by a peer port if the send was unsuccesful, and had to
148        wait.  This shouldn't be valid for response paths (IO Devices).
149        so it is set to panic if it isn't already defined.
150    */
151    virtual void recvRetry() { panic("??"); }
152
153    /** Called by a peer port in order to determine the block size of the
154        device connected to this port.  It sometimes doesn't make sense for
155        this function to be called, so it just returns 0. Anytthing that is
156        concerned with the size should just ignore that.
157    */
158    virtual unsigned deviceBlockSize() const { return 0; }
159
160  public:
161
162    /**
163     * Get a list of the non-overlapping address ranges we are
164     * responsible for. The default implementation returns an empty
165     * list and thus no address ranges. Any slave port must override
166     * this function and return a populated list with at least one
167     * item.
168     *
169     * @return a list of ranges responded to
170     */
171    virtual AddrRangeList getAddrRanges()
172    { AddrRangeList ranges; return ranges; }
173
174    /**
175     * Determine if this port is snooping or not. The default
176     * implementation returns false and thus tells the neighbour we
177     * are not snooping. Any port that is to snoop (e.g. a cache
178     * connected to a bus) has to override this function.
179     *
180     * @return true if the port should be considered a snooper
181     */
182    virtual bool isSnooping()
183    { return false; }
184
185    /** Function called by associated memory device (cache, memory, iodevice)
186        in order to send a timing request to the port.  Simply calls the peer
187        port receive function.
188        @return This function returns if the send was succesful in it's
189        recieve. If it was a failure, then the port will wait for a recvRetry
190        at which point it can possibly issue a successful sendTiming.  This is used in
191        case a cache has a higher priority request come in while waiting for
192        the bus to arbitrate.
193    */
194    bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
195
196    /** Function called by the associated device to send an atomic
197     *   access, an access in which the data is moved and the state is
198     *   updated in one cycle, without interleaving with other memory
199     *   accesses.  Returns estimated latency of access.
200     */
201    Tick sendAtomic(PacketPtr pkt)
202        { return peer->recvAtomic(pkt); }
203
204    /** Function called by the associated device to send a functional access,
205        an access in which the data is instantly updated everywhere in the
206        memory system, without affecting the current state of any block or
207        moving the block.
208    */
209    void sendFunctional(PacketPtr pkt)
210        { return peer->recvFunctional(pkt); }
211
212    /**
213     * Called by the associated device to send a status range to the
214     * peer interface.
215     */
216    void sendRangeChange() const { peer->recvRangeChange(); }
217
218    /** When a timing access doesn't return a success, some time later the
219        Retry will be sent.
220    */
221    void sendRetry() { return peer->recvRetry(); }
222
223    /** Called by the associated device if it wishes to find out the blocksize
224        of the device on attached to the peer port.
225    */
226    unsigned peerBlockSize() const { return peer->deviceBlockSize(); }
227
228    /** Inject a PrintReq for the given address to print the state of
229     * that address throughout the memory system.  For debugging.
230     */
231    void printAddr(Addr a);
232};
233
234#endif //__MEM_PORT_HH__
235