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