Deleted Added
sdiff udiff text old ( 2640:266b80dd5eca ) new ( 2641:6d9d837e2032 )
full compact
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 <list>
42#include <inttypes.h>
43
44#include "base/misc.hh"
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;
57typedef std::list<Range<Addr> >::iterator AddrRangeIter;
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 private:
73
74 /** Descriptive name (for DPRINTF output) */
75 const std::string portName;
76
77 public:
78
79 /**
80 * Constructor.
81 *
82 * @param _name Port name for DPRINTF output. Should include name
83 * of memory system object to which the port belongs.
84 */
85 Port(const std::string &_name)
86 : portName(_name)
87 { }
88
89 /** Return port name (for DPRINTF). */
90 const std::string &name() const { return portName; }
91
92 virtual ~Port() {};
93
94 // mey be better to use subclasses & RTTI?
95 /** Holds the ports status. Keeps track if it is blocked, or has
96 calculated a range change. */
97 enum Status {
98 Blocked,
99 Unblocked,
100 RangeChange
101 };
102
103 private:
104
105 /** A pointer to the peer port. Ports always come in pairs, that way they
106 can use a standardized interface to communicate between different
107 memory objects. */
108 Port *peer;
109
110 public:
111
112 /** Function to set the pointer for the peer port.
113 @todo should be called by the configuration stuff (python).
114 */
115 void setPeer(Port *port) { peer = port; }
116
117 /** Function to set the pointer for the peer port.
118 @todo should be called by the configuration stuff (python).
119 */
120 Port *getPeer() { return peer; }
121
122 protected:
123
124 /** These functions are protected because they should only be
125 * called by a peer port, never directly by any outside object. */
126
127 /** Called to recive a timing call from the peer port. */
128 virtual bool recvTiming(Packet *pkt) = 0;
129
130 /** Called to recive a atomic call from the peer port. */
131 virtual Tick recvAtomic(Packet *pkt) = 0;
132
133 /** Called to recive a functional call from the peer port. */
134 virtual void recvFunctional(Packet *pkt) = 0;
135
136 /** Called to recieve a status change from the peer port. */
137 virtual void recvStatusChange(Status status) = 0;
138
139 /** Called by a peer port if the send was unsuccesful, and had to
140 wait. This shouldn't be valid for response paths (IO Devices).
141 so it is set to panic if it isn't already defined.
142 */
143 virtual Packet *recvRetry() { panic("??"); }
144
145 /** Called by a peer port in order to determine the block size of the
146 device connected to this port. It sometimes doesn't make sense for
147 this function to be called, a DMA interface doesn't really have a
148 block size, so it is defaulted to a panic.
149 */
150 virtual int deviceBlockSize() { panic("??"); }
151
152 /** The peer port is requesting us to reply with a list of the ranges we
153 are responsible for.
154 @param resp is a list of ranges responded to
155 @param snoop is a list of ranges snooped
156 */
157 virtual void getDeviceAddressRanges(AddrRangeList &resp,
158 AddrRangeList &snoop)
159 { panic("??"); }
160
161 public:
162
163 /** Function called by associated memory device (cache, memory, iodevice)
164 in order to send a timing request to the port. Simply calls the peer
165 port receive function.
166 @return This function returns if the send was succesful in it's
167 recieve. If it was a failure, then the port will wait for a recvRetry
168 at which point it can issue a successful sendTiming. This is used in
169 case a cache has a higher priority request come in while waiting for
170 the bus to arbitrate.
171 */
172 bool sendTiming(Packet *pkt) { return peer->recvTiming(pkt); }
173
174 /** Function called by the associated device to send an atomic access,
175 an access in which the data is moved and the state is updated in one
176 cycle, without interleaving with other memory accesses.
177 */
178 Tick sendAtomic(Packet *pkt)
179 { return peer->recvAtomic(pkt); }
180
181 /** Function called by the associated device to send a functional access,
182 an access in which the data is instantly updated everywhere in the
183 memory system, without affecting the current state of any block or
184 moving the block.
185 */
186 void sendFunctional(Packet *pkt)
187 { return peer->recvFunctional(pkt); }
188
189 /** Called by the associated device to send a status change to the device
190 connected to the peer interface.
191 */
192 void sendStatusChange(Status status) {peer->recvStatusChange(status); }
193
194 /** When a timing access doesn't return a success, some time later the
195 Retry will be sent.
196 */
197 Packet *sendRetry() { return peer->recvRetry(); }
198
199 /** Called by the associated device if it wishes to find out the blocksize
200 of the device on attached to the peer port.
201 */
202 int peerBlockSize() { return peer->deviceBlockSize(); }
203
204 /** Called by the associated device if it wishes to find out the address
205 ranges connected to the peer ports devices.
206 */
207 void getPeerAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
208 { peer->getDeviceAddressRanges(resp, snoop); }
209
210 /** This function is a wrapper around sendFunctional()
211 that breaks a larger, arbitrarily aligned access into
212 appropriate chunks. The default implementation can use
213 getBlockSize() to determine the block size and go from there.
214 */
215 virtual void readBlob(Addr addr, uint8_t *p, int size);
216
217 /** This function is a wrapper around sendFunctional()
218 that breaks a larger, arbitrarily aligned access into
219 appropriate chunks. The default implementation can use
220 getBlockSize() to determine the block size and go from there.
221 */
222 virtual void writeBlob(Addr addr, uint8_t *p, int size);
223
224 /** Fill size bytes starting at addr with byte value val. This
225 should not need to be virtual, since it can be implemented in
226 terms of writeBlob(). However, it shouldn't be
227 performance-critical either, so it could be if we wanted to.
228 */
229 virtual void memsetBlob(Addr addr, uint8_t val, int size);
230
231 private:
232
233 /** Internal helper function for read/writeBlob().
234 */
235 void blobHelper(Addr addr, uint8_t *p, int size, Packet::Command cmd);
236};
237
238/** A simple functional port that is only meant for one way communication to
239 * physical memory. It is only meant to be used to load data into memory before
240 * the simulation begins.
241 */
242
243class FunctionalPort : public Port
244{
245 public:
246 FunctionalPort(const std::string &_name)
247 : Port(_name)
248 {}
249
250 virtual bool recvTiming(Packet *pkt) { panic("FuncPort is UniDir"); }
251 virtual Tick recvAtomic(Packet *pkt) { panic("FuncPort is UniDir"); }
252 virtual void recvFunctional(Packet *pkt) { panic("FuncPort is UniDir"); }
253 virtual void recvStatusChange(Status status) {}
254
255 template <typename T>
256 inline void write(Addr addr, T d)
257 {
258 writeBlob(addr, (uint8_t*)&d, sizeof(T));
259 }
260
261 template <typename T>
262 inline T read(Addr addr)
263 {
264 T d;
265 readBlob(addr, (uint8_t*)&d, sizeof(T));
266 return d;
267 }
268};
269
270#endif //__MEM_PORT_HH__