io_device.hh (5386:5614618f4027) io_device.hh (5534:9eaf72819836)
1/*
2 * Copyright (c) 2004-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: Ali Saidi
29 * Nathan Binkert
30 */
31
32#ifndef __DEV_IO_DEVICE_HH__
33#define __DEV_IO_DEVICE_HH__
34
35#include "base/fast_alloc.hh"
36#include "mem/mem_object.hh"
37#include "mem/packet.hh"
38#include "mem/tport.hh"
39#include "params/BasicPioDevice.hh"
40#include "params/DmaDevice.hh"
41#include "params/PioDevice.hh"
42#include "sim/sim_object.hh"
43
44class Event;
45class Platform;
46class PioDevice;
47class DmaDevice;
48class System;
49
50/**
51 * The PioPort class is a programmed i/o port that all devices that are
52 * sensitive to an address range use. The port takes all the memory
53 * access types and roles them into one read() and write() call that the device
54 * must respond to. The device must also provide the addressRanges() function
55 * with which it returns the address ranges it is interested in.
56 */
57class PioPort : public SimpleTimingPort
58{
59 protected:
60 /** The device that this port serves. */
61 PioDevice *device;
62
63 virtual Tick recvAtomic(PacketPtr pkt);
64
65 virtual void getDeviceAddressRanges(AddrRangeList &resp,
66 bool &snoop);
67
68 public:
69
70 PioPort(PioDevice *dev, System *s, std::string pname = "-pioport");
71};
72
73
74class DmaPort : public Port
75{
76 protected:
77 struct DmaReqState : public Packet::SenderState, public FastAlloc
78 {
79 /** Event to call on the device when this transaction (all packets)
80 * complete. */
81 Event *completionEvent;
82
83 /** Where we came from for some sanity checking. */
84 Port *outPort;
85
86 /** Total number of bytes that this transaction involves. */
87 Addr totBytes;
88
89 /** Number of bytes that have been acked for this transaction. */
90 Addr numBytes;
91
1/*
2 * Copyright (c) 2004-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: Ali Saidi
29 * Nathan Binkert
30 */
31
32#ifndef __DEV_IO_DEVICE_HH__
33#define __DEV_IO_DEVICE_HH__
34
35#include "base/fast_alloc.hh"
36#include "mem/mem_object.hh"
37#include "mem/packet.hh"
38#include "mem/tport.hh"
39#include "params/BasicPioDevice.hh"
40#include "params/DmaDevice.hh"
41#include "params/PioDevice.hh"
42#include "sim/sim_object.hh"
43
44class Event;
45class Platform;
46class PioDevice;
47class DmaDevice;
48class System;
49
50/**
51 * The PioPort class is a programmed i/o port that all devices that are
52 * sensitive to an address range use. The port takes all the memory
53 * access types and roles them into one read() and write() call that the device
54 * must respond to. The device must also provide the addressRanges() function
55 * with which it returns the address ranges it is interested in.
56 */
57class PioPort : public SimpleTimingPort
58{
59 protected:
60 /** The device that this port serves. */
61 PioDevice *device;
62
63 virtual Tick recvAtomic(PacketPtr pkt);
64
65 virtual void getDeviceAddressRanges(AddrRangeList &resp,
66 bool &snoop);
67
68 public:
69
70 PioPort(PioDevice *dev, System *s, std::string pname = "-pioport");
71};
72
73
74class DmaPort : public Port
75{
76 protected:
77 struct DmaReqState : public Packet::SenderState, public FastAlloc
78 {
79 /** Event to call on the device when this transaction (all packets)
80 * complete. */
81 Event *completionEvent;
82
83 /** Where we came from for some sanity checking. */
84 Port *outPort;
85
86 /** Total number of bytes that this transaction involves. */
87 Addr totBytes;
88
89 /** Number of bytes that have been acked for this transaction. */
90 Addr numBytes;
91
92 DmaReqState(Event *ce, Port *p, Addr tb)
93 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0)
92 /** Amount to delay completion of dma by */
93 Tick delay;
94
95 DmaReqState(Event *ce, Port *p, Addr tb, Tick _delay)
96 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0),
97 delay(_delay)
94 {}
95 };
96
97 DmaDevice *device;
98 std::list<PacketPtr> transmitList;
99
100 /** The system that device/port are in. This is used to select which mode
101 * we are currently operating in. */
102 System *sys;
103
104 /** Number of outstanding packets the dma port has. */
105 int pendingCount;
106
107 /** If a dmaAction is in progress. */
108 int actionInProgress;
109
110 /** If we need to drain, keep the drain event around until we're done
111 * here.*/
112 Event *drainEvent;
113
114 /** time to wait between sending another packet, increases as NACKs are
115 * recived, decreases as responses are recived. */
116 Tick backoffTime;
117
118 /** If the port is currently waiting for a retry before it can send whatever
119 * it is that it's sending. */
120 bool inRetry;
121
122 virtual bool recvTiming(PacketPtr pkt);
123 virtual Tick recvAtomic(PacketPtr pkt)
124 { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN }
125 virtual void recvFunctional(PacketPtr pkt)
126 { panic("dma port shouldn't be used for pio access."); }
127
128 virtual void recvStatusChange(Status status)
129 { ; }
130
131 virtual void recvRetry() ;
132
133 virtual void getDeviceAddressRanges(AddrRangeList &resp,
134 bool &snoop)
135 { resp.clear(); snoop = false; }
136
137 void queueDma(PacketPtr pkt, bool front = false);
138 void sendDma();
139
140 /** event to give us a kick every time we backoff time is reached. */
141 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
142
143 public:
144 DmaPort(DmaDevice *dev, System *s);
145
146 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
98 {}
99 };
100
101 DmaDevice *device;
102 std::list<PacketPtr> transmitList;
103
104 /** The system that device/port are in. This is used to select which mode
105 * we are currently operating in. */
106 System *sys;
107
108 /** Number of outstanding packets the dma port has. */
109 int pendingCount;
110
111 /** If a dmaAction is in progress. */
112 int actionInProgress;
113
114 /** If we need to drain, keep the drain event around until we're done
115 * here.*/
116 Event *drainEvent;
117
118 /** time to wait between sending another packet, increases as NACKs are
119 * recived, decreases as responses are recived. */
120 Tick backoffTime;
121
122 /** If the port is currently waiting for a retry before it can send whatever
123 * it is that it's sending. */
124 bool inRetry;
125
126 virtual bool recvTiming(PacketPtr pkt);
127 virtual Tick recvAtomic(PacketPtr pkt)
128 { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN }
129 virtual void recvFunctional(PacketPtr pkt)
130 { panic("dma port shouldn't be used for pio access."); }
131
132 virtual void recvStatusChange(Status status)
133 { ; }
134
135 virtual void recvRetry() ;
136
137 virtual void getDeviceAddressRanges(AddrRangeList &resp,
138 bool &snoop)
139 { resp.clear(); snoop = false; }
140
141 void queueDma(PacketPtr pkt, bool front = false);
142 void sendDma();
143
144 /** event to give us a kick every time we backoff time is reached. */
145 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
146
147 public:
148 DmaPort(DmaDevice *dev, System *s);
149
150 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
147 uint8_t *data = NULL);
151 uint8_t *data, Tick delay);
148
149 bool dmaPending() { return pendingCount > 0; }
150
151 int cacheBlockSize() { return peerBlockSize(); }
152 unsigned int drain(Event *de);
153};
154
155/**
156 * This device is the base class which all devices senstive to an address range
157 * inherit from. There are three pure virtual functions which all devices must
158 * implement addressRanges(), read(), and write(). The magic do choose which
159 * mode we are in, etc is handled by the PioPort so the device doesn't have to
160 * bother.
161 */
162class PioDevice : public MemObject
163{
164 protected:
165
166 /** The platform we are in. This is used to decide what type of memory
167 * transaction we should perform. */
168 Platform *platform;
169
170 System *sys;
171
172 /** The pioPort that handles the requests for us and provides us requests
173 * that it sees. */
174 PioPort *pioPort;
175
176 virtual void addressRanges(AddrRangeList &range_list) = 0;
177
178 /** Pure virtual function that the device must implement. Called
179 * when a read command is recieved by the port.
180 * @param pkt Packet describing this request
181 * @return number of ticks it took to complete
182 */
183 virtual Tick read(PacketPtr pkt) = 0;
184
185 /** Pure virtual function that the device must implement. Called when a
186 * write command is recieved by the port.
187 * @param pkt Packet describing this request
188 * @return number of ticks it took to complete
189 */
190 virtual Tick write(PacketPtr pkt) = 0;
191
192 public:
193 typedef PioDeviceParams Params;
194 PioDevice(const Params *p);
195 virtual ~PioDevice();
196
197 const Params *
198 params() const
199 {
200 return dynamic_cast<const Params *>(_params);
201 }
202
203 virtual void init();
204
205 virtual unsigned int drain(Event *de);
206
207 virtual Port *getPort(const std::string &if_name, int idx = -1)
208 {
209 if (if_name == "pio") {
210 if (pioPort != NULL)
211 panic("pio port already connected to.");
212 pioPort = new PioPort(this, sys);
213 return pioPort;
214 } else
215 return NULL;
216 }
217 friend class PioPort;
218
219};
220
221class BasicPioDevice : public PioDevice
222{
223 protected:
224 /** Address that the device listens to. */
225 Addr pioAddr;
226
227 /** Size that the device's address range. */
228 Addr pioSize;
229
230 /** Delay that the device experinces on an access. */
231 Tick pioDelay;
232
233 public:
234 typedef BasicPioDeviceParams Params;
235 BasicPioDevice(const Params *p);
236
237 const Params *
238 params() const
239 {
240 return dynamic_cast<const Params *>(_params);
241 }
242
243 /** return the address ranges that this device responds to.
244 * @param range_list range list to populate with ranges
245 */
246 void addressRanges(AddrRangeList &range_list);
247
248};
249
250class DmaDevice : public PioDevice
251{
252 protected:
253 DmaPort *dmaPort;
254 Tick minBackoffDelay;
255 Tick maxBackoffDelay;
256
257 public:
258 typedef DmaDeviceParams Params;
259 DmaDevice(const Params *p);
260 virtual ~DmaDevice();
261
262 const Params *
263 params() const
264 {
265 return dynamic_cast<const Params *>(_params);
266 }
267
152
153 bool dmaPending() { return pendingCount > 0; }
154
155 int cacheBlockSize() { return peerBlockSize(); }
156 unsigned int drain(Event *de);
157};
158
159/**
160 * This device is the base class which all devices senstive to an address range
161 * inherit from. There are three pure virtual functions which all devices must
162 * implement addressRanges(), read(), and write(). The magic do choose which
163 * mode we are in, etc is handled by the PioPort so the device doesn't have to
164 * bother.
165 */
166class PioDevice : public MemObject
167{
168 protected:
169
170 /** The platform we are in. This is used to decide what type of memory
171 * transaction we should perform. */
172 Platform *platform;
173
174 System *sys;
175
176 /** The pioPort that handles the requests for us and provides us requests
177 * that it sees. */
178 PioPort *pioPort;
179
180 virtual void addressRanges(AddrRangeList &range_list) = 0;
181
182 /** Pure virtual function that the device must implement. Called
183 * when a read command is recieved by the port.
184 * @param pkt Packet describing this request
185 * @return number of ticks it took to complete
186 */
187 virtual Tick read(PacketPtr pkt) = 0;
188
189 /** Pure virtual function that the device must implement. Called when a
190 * write command is recieved by the port.
191 * @param pkt Packet describing this request
192 * @return number of ticks it took to complete
193 */
194 virtual Tick write(PacketPtr pkt) = 0;
195
196 public:
197 typedef PioDeviceParams Params;
198 PioDevice(const Params *p);
199 virtual ~PioDevice();
200
201 const Params *
202 params() const
203 {
204 return dynamic_cast<const Params *>(_params);
205 }
206
207 virtual void init();
208
209 virtual unsigned int drain(Event *de);
210
211 virtual Port *getPort(const std::string &if_name, int idx = -1)
212 {
213 if (if_name == "pio") {
214 if (pioPort != NULL)
215 panic("pio port already connected to.");
216 pioPort = new PioPort(this, sys);
217 return pioPort;
218 } else
219 return NULL;
220 }
221 friend class PioPort;
222
223};
224
225class BasicPioDevice : public PioDevice
226{
227 protected:
228 /** Address that the device listens to. */
229 Addr pioAddr;
230
231 /** Size that the device's address range. */
232 Addr pioSize;
233
234 /** Delay that the device experinces on an access. */
235 Tick pioDelay;
236
237 public:
238 typedef BasicPioDeviceParams Params;
239 BasicPioDevice(const Params *p);
240
241 const Params *
242 params() const
243 {
244 return dynamic_cast<const Params *>(_params);
245 }
246
247 /** return the address ranges that this device responds to.
248 * @param range_list range list to populate with ranges
249 */
250 void addressRanges(AddrRangeList &range_list);
251
252};
253
254class DmaDevice : public PioDevice
255{
256 protected:
257 DmaPort *dmaPort;
258 Tick minBackoffDelay;
259 Tick maxBackoffDelay;
260
261 public:
262 typedef DmaDeviceParams Params;
263 DmaDevice(const Params *p);
264 virtual ~DmaDevice();
265
266 const Params *
267 params() const
268 {
269 return dynamic_cast<const Params *>(_params);
270 }
271
268 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data)
272 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay = 0)
269 {
273 {
270 dmaPort->dmaAction(MemCmd::WriteReq, addr, size, event, data);
274 dmaPort->dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
271 }
272
275 }
276
273 void dmaRead(Addr addr, int size, Event *event, uint8_t *data)
277 void dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay = 0)
274 {
278 {
275 dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data);
279 dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
276 }
277
278 bool dmaPending() { return dmaPort->dmaPending(); }
279
280 virtual unsigned int drain(Event *de);
281
282 int cacheBlockSize() { return dmaPort->cacheBlockSize(); }
283
284 virtual Port *getPort(const std::string &if_name, int idx = -1)
285 {
286 if (if_name == "pio") {
287 if (pioPort != NULL)
288 panic("pio port already connected to.");
289 pioPort = new PioPort(this, sys);
290 return pioPort;
291 } else if (if_name == "dma") {
292 if (dmaPort != NULL)
293 panic("dma port already connected to.");
294 dmaPort = new DmaPort(this, sys);
295 return dmaPort;
296 } else
297 return NULL;
298 }
299
300 friend class DmaPort;
301};
302
303
304#endif // __DEV_IO_DEVICE_HH__
280 }
281
282 bool dmaPending() { return dmaPort->dmaPending(); }
283
284 virtual unsigned int drain(Event *de);
285
286 int cacheBlockSize() { return dmaPort->cacheBlockSize(); }
287
288 virtual Port *getPort(const std::string &if_name, int idx = -1)
289 {
290 if (if_name == "pio") {
291 if (pioPort != NULL)
292 panic("pio port already connected to.");
293 pioPort = new PioPort(this, sys);
294 return pioPort;
295 } else if (if_name == "dma") {
296 if (dmaPort != NULL)
297 panic("dma port already connected to.");
298 dmaPort = new DmaPort(this, sys);
299 return dmaPort;
300 } else
301 return NULL;
302 }
303
304 friend class DmaPort;
305};
306
307
308#endif // __DEV_IO_DEVICE_HH__