port.hh revision 8922:17f037ad8918
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 *          William Wang
43 */
44
45/**
46 * @file
47 * Port Object Declaration.
48 */
49
50#ifndef __MEM_PORT_HH__
51#define __MEM_PORT_HH__
52
53#include <list>
54
55#include "base/range.hh"
56#include "mem/packet.hh"
57
58/**
59 * This typedef is used to clean up getAddrRanges(). It's declared
60 * outside the Port object since it's also used by some mem objects.
61 * Eventually we should move this typedef to wherever Addr is
62 * defined.
63 */
64
65typedef std::list<Range<Addr> > AddrRangeList;
66typedef std::list<Range<Addr> >::iterator AddrRangeIter;
67
68class MemObject;
69
70/**
71 * Ports are used to interface memory objects to each other. A port is
72 * either a master or a slave and the connected peer is always of the
73 * opposite role.
74 *
75 * Each port has a name and an owner, and enables three basic types of
76 * accesses to the peer port: sendFunctional, sendAtomic and
77 * sendTiming.
78 */
79class Port
80{
81
82  private:
83
84    /** Descriptive name (for DPRINTF output) */
85    std::string portName;
86
87  protected:
88
89    /** A pointer to the peer port.  */
90    Port* peer;
91
92    /** A reference to the MemObject that owns this port. */
93    MemObject& owner;
94
95    /**
96     * Abstract base class for ports
97     *
98     * @param _name Port name including the owners name
99     * @param _owner The MemObject that is the structural owner of this port
100     */
101    Port(const std::string& _name, MemObject& _owner);
102
103    /**
104     * Virtual destructor due to inheritance.
105     */
106    virtual ~Port();
107
108  public:
109
110    /** Return port name (for DPRINTF). */
111    const std::string name() const { return portName; }
112
113  protected:
114
115    /** These functions are protected because they should only be
116     * called by a peer port, never directly by any outside object. */
117
118    /** Called to recive a timing call from the peer port. */
119    virtual bool recvTiming(PacketPtr pkt) = 0;
120
121    /** Called to recive a atomic call from the peer port. */
122    virtual Tick recvAtomic(PacketPtr pkt) = 0;
123
124    /** Called to recive a functional call from the peer port. */
125    virtual void recvFunctional(PacketPtr pkt) = 0;
126
127    /**
128     * Called by a peer port if sendTiming was unsuccesful, and had to
129     * wait.
130     */
131    virtual void recvRetry() = 0;
132
133  public:
134
135    /**
136     * Attempt to send a timing packet to the peer port by calling its
137     * receive function. If the send does not succeed, as indicated by
138     * the return value, then the sender must wait for a recvRetry at
139     * which point it can re-issue a sendTiming.
140     *
141     * @param pkt Packet to send.
142     *
143     * @return If the send was succesful or not.
144    */
145    bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
146
147    /**
148     * Send a retry to a peer port that previously attempted a sendTiming
149     * which was unsuccessful.
150     */
151    void sendRetry() { return peer->recvRetry(); }
152
153    /**
154     * Send an atomic packet, where the data is moved and the state
155     * is updated in zero time, without interleaving with other
156     * memory accesses.
157     *
158     * @param pkt Packet to send.
159     *
160     * @return Estimated latency of access.
161     */
162    Tick sendAtomic(PacketPtr pkt) { return peer->recvAtomic(pkt); }
163
164    /**
165     * Send a functional packet, where the data is instantly updated
166     * everywhere in the memory system, without affecting the current
167     * state of any block or moving the block.
168     *
169     * @param pkt Packet to send.
170     */
171    void sendFunctional(PacketPtr pkt) { return peer->recvFunctional(pkt); }
172
173};
174
175/** Forward declaration */
176class SlavePort;
177
178/**
179 * A MasterPort is a specialisation of a port. In addition to the
180 * basic functionality of sending packets to its slave peer, it also
181 * has functions specific to a master, e.g. to receive range changes
182 * or determine if the port is snooping or not.
183 */
184class MasterPort : public Port
185{
186
187  private:
188
189    SlavePort* _slavePort;
190
191  public:
192
193    MasterPort(const std::string& name, MemObject* owner);
194    virtual ~MasterPort();
195
196    void bind(SlavePort& slave_port);
197    SlavePort& getSlavePort() const;
198    bool isConnected() const;
199
200    /**
201     * Called to receive an address range change from the peer slave
202     * port. the default implementation ignored the change and does
203     * nothing. Override this function in a derived class if the owner
204     * needs to be aware of he laesddress ranges, e.g. in an
205     * interconnect component like a bus.
206     */
207    virtual void recvRangeChange() { }
208
209    /**
210     * Determine if this master port is snooping or not. The default
211     * implementation returns false and thus tells the neighbour we
212     * are not snooping. Any master port that wants to receive snoop
213     * requests (e.g. a cache connected to a bus) has to override this
214     * function.
215     *
216     * @return true if the port should be considered a snooper
217     */
218    virtual bool isSnooping() const { return false; }
219
220    /**
221     * Called by a peer port in order to determine the block size of
222     * the owner of this port.
223     */
224    virtual unsigned deviceBlockSize() const { return 0; }
225
226    /** Called by the associated device if it wishes to find out the blocksize
227        of the device on attached to the peer port.
228    */
229    unsigned peerBlockSize() const;
230
231    /** Inject a PrintReq for the given address to print the state of
232     * that address throughout the memory system.  For debugging.
233     */
234    void printAddr(Addr a);
235};
236
237/**
238 * A SlavePort is a specialisation of a port. In addition to the
239 * basic functionality of sending packets to its master peer, it also
240 * has functions specific to a slave, e.g. to send range changes
241 * and get the address ranges that the port responds to.
242 */
243class SlavePort : public Port
244{
245
246  private:
247
248    MasterPort* _masterPort;
249
250  public:
251
252    SlavePort(const std::string& name, MemObject* owner);
253    virtual ~SlavePort();
254
255    void bind(MasterPort& master_port);
256    MasterPort& getMasterPort() const;
257    bool isConnected() const;
258
259    /**
260     * Called by a peer port in order to determine the block size of
261     * the owner of this port.
262     */
263    virtual unsigned deviceBlockSize() const { return 0; }
264
265    /** Called by the associated device if it wishes to find out the blocksize
266        of the device on attached to the peer port.
267    */
268    unsigned peerBlockSize() const;
269
270    /**
271     * Called by the owner to send a range change
272     */
273    void sendRangeChange() const { _masterPort->recvRangeChange(); }
274
275    /**
276     * Get a list of the non-overlapping address ranges the owner is
277     * responsible for. All slave ports must override this function
278     * and return a populated list with at least one item.
279     *
280     * @return a list of ranges responded to
281     */
282    virtual AddrRangeList getAddrRanges() = 0;
283};
284
285#endif //__MEM_PORT_HH__
286