io_device.hh (8711:c7e14f52c682) io_device.hh (8742:9df38d259935)
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;
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
45class PioDevice;
46class DmaDevice;
47class System;
48
49/**
50 * The PioPort class is a programmed i/o port that all devices that are
51 * sensitive to an address range use. The port takes all the memory
52 * access types and roles them into one read() and write() call that the device
54 * must respond to. The device must also provide getAddrRanges() function
53 * 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
54 * with which it returns the address ranges it is interested in.
55 */
56class PioPort : public SimpleTimingPort
57{
58 protected:
59 /** The device that this port serves. */
60 PioDevice *device;
61
62 virtual Tick recvAtomic(PacketPtr pkt);
63
65 virtual AddrRangeList getAddrRanges();
64 virtual void getDeviceAddressRanges(AddrRangeList &resp,
65 bool &snoop);
66
67 public:
68
69 PioPort(PioDevice *dev, System *s, std::string pname = "-pioport");
70};
71
72
73class DmaPort : public Port
74{
75 protected:
76 struct DmaReqState : public Packet::SenderState, public FastAlloc
77 {
78 /** Event to call on the device when this transaction (all packets)
79 * complete. */
80 Event *completionEvent;
81
82 /** Where we came from for some sanity checking. */
83 Port *outPort;
84
85 /** Total number of bytes that this transaction involves. */
86 Addr totBytes;
87
88 /** Number of bytes that have been acked for this transaction. */
89 Addr numBytes;
90
91 /** Amount to delay completion of dma by */
92 Tick delay;
93
94
95 DmaReqState(Event *ce, Port *p, Addr tb, Tick _delay)
96 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0),
97 delay(_delay)
98 {}
99 };
100
101 MemObject *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 /** Minimum time that device should back off for after failed sendTiming */
123 Tick minBackoffDelay;
124
125 /** Maximum time that device should back off for after failed sendTiming */
126 Tick maxBackoffDelay;
127
128 /** If the port is currently waiting for a retry before it can send whatever
129 * it is that it's sending. */
130 bool inRetry;
131
66
67 public:
68
69 PioPort(PioDevice *dev, System *s, std::string pname = "-pioport");
70};
71
72
73class DmaPort : public Port
74{
75 protected:
76 struct DmaReqState : public Packet::SenderState, public FastAlloc
77 {
78 /** Event to call on the device when this transaction (all packets)
79 * complete. */
80 Event *completionEvent;
81
82 /** Where we came from for some sanity checking. */
83 Port *outPort;
84
85 /** Total number of bytes that this transaction involves. */
86 Addr totBytes;
87
88 /** Number of bytes that have been acked for this transaction. */
89 Addr numBytes;
90
91 /** Amount to delay completion of dma by */
92 Tick delay;
93
94
95 DmaReqState(Event *ce, Port *p, Addr tb, Tick _delay)
96 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0),
97 delay(_delay)
98 {}
99 };
100
101 MemObject *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 /** Minimum time that device should back off for after failed sendTiming */
123 Tick minBackoffDelay;
124
125 /** Maximum time that device should back off for after failed sendTiming */
126 Tick maxBackoffDelay;
127
128 /** If the port is currently waiting for a retry before it can send whatever
129 * it is that it's sending. */
130 bool inRetry;
131
132 /** Port accesses a cache which requires snooping */
133 bool recvSnoops;
134
135 virtual bool recvTiming(PacketPtr pkt);
136 virtual Tick recvAtomic(PacketPtr pkt)
132 virtual bool recvTiming(PacketPtr pkt);
133 virtual Tick recvAtomic(PacketPtr pkt)
137 {
138 if (recvSnoops) return 0;
139
140 panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN
141 }
134 { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN }
142 virtual void recvFunctional(PacketPtr pkt)
135 virtual void recvFunctional(PacketPtr pkt)
143 {
144 if (recvSnoops) return;
136 { panic("dma port shouldn't be used for pio access."); }
145
137
146 panic("dma port shouldn't be used for pio access.");
147 }
138 virtual void recvStatusChange(Status status)
139 { ; }
148
140
149 virtual void recvRangeChange()
150 {
151 // DMA port is a master with a single slave so there is no choice and
152 // thus no need to worry about any address changes
153 }
154
155 virtual void recvRetry() ;
156
141 virtual void recvRetry() ;
142
157 virtual bool isSnooping()
158 { return recvSnoops; }
143 virtual void getDeviceAddressRanges(AddrRangeList &resp,
144 bool &snoop)
145 { resp.clear(); snoop = false; }
159
160 void queueDma(PacketPtr pkt, bool front = false);
161 void sendDma();
162
163 /** event to give us a kick every time we backoff time is reached. */
164 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
165
166 public:
146
147 void queueDma(PacketPtr pkt, bool front = false);
148 void sendDma();
149
150 /** event to give us a kick every time we backoff time is reached. */
151 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
152
153 public:
167 DmaPort(MemObject *dev, System *s, Tick min_backoff, Tick max_backoff,
168 bool recv_snoops = false);
154 DmaPort(MemObject *dev, System *s, Tick min_backoff, Tick max_backoff);
169
170 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
171 uint8_t *data, Tick delay, Request::Flags flag = 0);
172
173 bool dmaPending() { return pendingCount > 0; }
174
175 unsigned cacheBlockSize() const { return peerBlockSize(); }
176 unsigned int drain(Event *de);
177};
178
179/**
180 * This device is the base class which all devices senstive to an address range
181 * inherit from. There are three pure virtual functions which all devices must
155
156 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
157 uint8_t *data, Tick delay, Request::Flags flag = 0);
158
159 bool dmaPending() { return pendingCount > 0; }
160
161 unsigned cacheBlockSize() const { return peerBlockSize(); }
162 unsigned int drain(Event *de);
163};
164
165/**
166 * This device is the base class which all devices senstive to an address range
167 * inherit from. There are three pure virtual functions which all devices must
182 * implement getAddrRanges(), read(), and write(). The magic do choose which
168 * implement addressRanges(), read(), and write(). The magic do choose which
183 * mode we are in, etc is handled by the PioPort so the device doesn't have to
184 * bother.
185 */
186class PioDevice : public MemObject
187{
188 protected:
169 * mode we are in, etc is handled by the PioPort so the device doesn't have to
170 * bother.
171 */
172class PioDevice : public MemObject
173{
174 protected:
189
190 /** The platform we are in. This is used to decide what type of memory
191 * transaction we should perform. */
192 Platform *platform;
193
194 System *sys;
195
196 /** The pioPort that handles the requests for us and provides us requests
197 * that it sees. */
198 PioPort *pioPort;
199
175 System *sys;
176
177 /** The pioPort that handles the requests for us and provides us requests
178 * that it sees. */
179 PioPort *pioPort;
180
200 /**
201 * Every PIO device is obliged to provide an implementation that
202 * returns the address ranges the device responds to.
203 *
204 * @return a list of non-overlapping address ranges
205 */
206 virtual AddrRangeList getAddrRanges() = 0;
181 virtual void addressRanges(AddrRangeList &range_list) = 0;
207
208 /** Pure virtual function that the device must implement. Called
209 * when a read command is recieved by the port.
210 * @param pkt Packet describing this request
211 * @return number of ticks it took to complete
212 */
213 virtual Tick read(PacketPtr pkt) = 0;
214
215 /** Pure virtual function that the device must implement. Called when a
216 * write command is recieved by the port.
217 * @param pkt Packet describing this request
218 * @return number of ticks it took to complete
219 */
220 virtual Tick write(PacketPtr pkt) = 0;
221
222 public:
223 typedef PioDeviceParams Params;
224 PioDevice(const Params *p);
225 virtual ~PioDevice();
226
227 const Params *
228 params() const
229 {
230 return dynamic_cast<const Params *>(_params);
231 }
232
233 virtual void init();
234
235 virtual unsigned int drain(Event *de);
236
182
183 /** Pure virtual function that the device must implement. Called
184 * when a read command is recieved by the port.
185 * @param pkt Packet describing this request
186 * @return number of ticks it took to complete
187 */
188 virtual Tick read(PacketPtr pkt) = 0;
189
190 /** Pure virtual function that the device must implement. Called when a
191 * write command is recieved by the port.
192 * @param pkt Packet describing this request
193 * @return number of ticks it took to complete
194 */
195 virtual Tick write(PacketPtr pkt) = 0;
196
197 public:
198 typedef PioDeviceParams Params;
199 PioDevice(const Params *p);
200 virtual ~PioDevice();
201
202 const Params *
203 params() const
204 {
205 return dynamic_cast<const Params *>(_params);
206 }
207
208 virtual void init();
209
210 virtual unsigned int drain(Event *de);
211
237 virtual Port *getPort(const std::string &if_name, int idx = -1);
238
212 virtual Port *getPort(const std::string &if_name, int idx = -1)
213 {
214 if (if_name == "pio") {
215 if (pioPort != NULL)
216 fatal("%s: pio port already connected to %s",
217 name(), pioPort->getPeer()->name());
218 pioPort = new PioPort(this, sys);
219 return pioPort;
220 } else
221 return NULL;
222 }
239 friend class PioPort;
240
241};
242
243class BasicPioDevice : public PioDevice
244{
245 protected:
246 /** Address that the device listens to. */
247 Addr pioAddr;
248
249 /** Size that the device's address range. */
250 Addr pioSize;
251
252 /** Delay that the device experinces on an access. */
253 Tick pioDelay;
254
255 public:
256 typedef BasicPioDeviceParams Params;
257 BasicPioDevice(const Params *p);
258
259 const Params *
260 params() const
261 {
262 return dynamic_cast<const Params *>(_params);
263 }
264
223 friend class PioPort;
224
225};
226
227class BasicPioDevice : public PioDevice
228{
229 protected:
230 /** Address that the device listens to. */
231 Addr pioAddr;
232
233 /** Size that the device's address range. */
234 Addr pioSize;
235
236 /** Delay that the device experinces on an access. */
237 Tick pioDelay;
238
239 public:
240 typedef BasicPioDeviceParams Params;
241 BasicPioDevice(const Params *p);
242
243 const Params *
244 params() const
245 {
246 return dynamic_cast<const Params *>(_params);
247 }
248
265 /**
266 * Determine the address ranges that this device responds to.
267 *
268 * @return a list of non-overlapping address ranges
249 /** return the address ranges that this device responds to.
250 * @param range_list range list to populate with ranges
269 */
251 */
270 virtual AddrRangeList getAddrRanges();
252 void addressRanges(AddrRangeList &range_list);
271
272};
273
274class DmaDevice : public PioDevice
275{
276 protected:
277 DmaPort *dmaPort;
278
279 public:
280 typedef DmaDeviceParams Params;
281 DmaDevice(const Params *p);
282 virtual ~DmaDevice();
283
284 const Params *
285 params() const
286 {
287 return dynamic_cast<const Params *>(_params);
288 }
289
290 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay = 0)
291 {
292 dmaPort->dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
293 }
294
295 void dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay = 0)
296 {
297 dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
298 }
299
300 bool dmaPending() { return dmaPort->dmaPending(); }
301
302 virtual unsigned int drain(Event *de);
303
304 unsigned cacheBlockSize() const { return dmaPort->cacheBlockSize(); }
305
253
254};
255
256class DmaDevice : public PioDevice
257{
258 protected:
259 DmaPort *dmaPort;
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
272 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay = 0)
273 {
274 dmaPort->dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
275 }
276
277 void dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay = 0)
278 {
279 dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
280 }
281
282 bool dmaPending() { return dmaPort->dmaPending(); }
283
284 virtual unsigned int drain(Event *de);
285
286 unsigned cacheBlockSize() const { return dmaPort->cacheBlockSize(); }
287
306 virtual Port *getPort(const std::string &if_name, int idx = -1);
288 virtual Port *getPort(const std::string &if_name, int idx = -1)
289 {
290 if (if_name == "pio") {
291 if (pioPort != NULL)
292 fatal("%s: pio port already connected to %s",
293 name(), pioPort->getPeer()->name());
294 pioPort = new PioPort(this, sys);
295 return pioPort;
296 } else if (if_name == "dma") {
297 if (dmaPort != NULL)
298 fatal("%s: dma port already connected to %s",
299 name(), dmaPort->getPeer()->name());
300 dmaPort = new DmaPort(this, sys, params()->min_backoff_delay,
301 params()->max_backoff_delay);
302 return dmaPort;
303 } else
304 return NULL;
305 }
307
308 friend class DmaPort;
309};
310
311
312#endif // __DEV_IO_DEVICE_HH__
306
307 friend class DmaPort;
308};
309
310
311#endif // __DEV_IO_DEVICE_HH__