io_device.hh (2784:6cff1a1c2935) io_device.hh (2846:89fbe74d8ea8)
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/chunk_generator.hh"
36#include "mem/mem_object.hh"
37#include "mem/packet_impl.hh"
38#include "sim/eventq.hh"
39#include "sim/sim_object.hh"
40
41class Platform;
42class PioDevice;
43class DmaDevice;
44class System;
45
46/**
47 * The PioPort class is a programmed i/o port that all devices that are
48 * sensitive to an address range use. The port takes all the memory
49 * access types and roles them into one read() and write() call that the device
50 * must respond to. The device must also provide the addressRanges() function
51 * with which it returns the address ranges it is interested in. An extra
52 * sendTiming() function is implemented which takes an delay. In this way the
53 * device can immediatly call sendTiming(pkt, time) after processing a request
54 * and the request will be handled by the port even if the port bus the device
55 * connects to is blocked.
56 */
57class PioPort : public Port
58{
59 protected:
60 /** The device that this port serves. */
61 PioDevice *device;
62
63 /** The platform that device/port are in. This is used to select which mode
64 * we are currently operating in. */
65 Platform *platform;
66
67 /** A list of outgoing timing response packets that haven't been serviced
68 * yet. */
69 std::list<Packet*> transmitList;
70
71 /** The current status of the peer(bus) that we are connected to. */
72 Status peerStatus;
73
74 virtual bool recvTiming(Packet *pkt);
75
76 virtual Tick recvAtomic(Packet *pkt);
77
78 virtual void recvFunctional(Packet *pkt) ;
79
80 virtual void recvStatusChange(Status status)
81 { peerStatus = status; }
82
83 virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop);
84
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/chunk_generator.hh"
36#include "mem/mem_object.hh"
37#include "mem/packet_impl.hh"
38#include "sim/eventq.hh"
39#include "sim/sim_object.hh"
40
41class Platform;
42class PioDevice;
43class DmaDevice;
44class System;
45
46/**
47 * The PioPort class is a programmed i/o port that all devices that are
48 * sensitive to an address range use. The port takes all the memory
49 * access types and roles them into one read() and write() call that the device
50 * must respond to. The device must also provide the addressRanges() function
51 * with which it returns the address ranges it is interested in. An extra
52 * sendTiming() function is implemented which takes an delay. In this way the
53 * device can immediatly call sendTiming(pkt, time) after processing a request
54 * and the request will be handled by the port even if the port bus the device
55 * connects to is blocked.
56 */
57class PioPort : public Port
58{
59 protected:
60 /** The device that this port serves. */
61 PioDevice *device;
62
63 /** The platform that device/port are in. This is used to select which mode
64 * we are currently operating in. */
65 Platform *platform;
66
67 /** A list of outgoing timing response packets that haven't been serviced
68 * yet. */
69 std::list<Packet*> transmitList;
70
71 /** The current status of the peer(bus) that we are connected to. */
72 Status peerStatus;
73
74 virtual bool recvTiming(Packet *pkt);
75
76 virtual Tick recvAtomic(Packet *pkt);
77
78 virtual void recvFunctional(Packet *pkt) ;
79
80 virtual void recvStatusChange(Status status)
81 { peerStatus = status; }
82
83 virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop);
84
85 void resendNacked(Packet *pkt);
86
85 /**
86 * This class is used to implemented sendTiming() with a delay. When a delay
87 * is requested a new event is created. When the event time expires it
88 * attempts to send the packet. If it cannot, the packet is pushed onto the
89 * transmit list to be sent when recvRetry() is called. */
90 class SendEvent : public Event
91 {
92 PioPort *port;
93 Packet *packet;
94
95 SendEvent(PioPort *p, Packet *pkt, Tick t)
96 : Event(&mainEventQueue), port(p), packet(pkt)
97 { schedule(curTick + t); }
98
99 virtual void process();
100
101 virtual const char *description()
102 { return "Future scheduled sendTiming event"; }
103
104 friend class PioPort;
105 };
106
107 /** Schedule a sendTiming() event to be called in the future. */
108 void sendTiming(Packet *pkt, Tick time)
109 { new PioPort::SendEvent(this, pkt, time); }
110
111 /** This function is notification that the device should attempt to send a
112 * packet again. */
113 virtual void recvRetry();
114
115 public:
87 /**
88 * This class is used to implemented sendTiming() with a delay. When a delay
89 * is requested a new event is created. When the event time expires it
90 * attempts to send the packet. If it cannot, the packet is pushed onto the
91 * transmit list to be sent when recvRetry() is called. */
92 class SendEvent : public Event
93 {
94 PioPort *port;
95 Packet *packet;
96
97 SendEvent(PioPort *p, Packet *pkt, Tick t)
98 : Event(&mainEventQueue), port(p), packet(pkt)
99 { schedule(curTick + t); }
100
101 virtual void process();
102
103 virtual const char *description()
104 { return "Future scheduled sendTiming event"; }
105
106 friend class PioPort;
107 };
108
109 /** Schedule a sendTiming() event to be called in the future. */
110 void sendTiming(Packet *pkt, Tick time)
111 { new PioPort::SendEvent(this, pkt, time); }
112
113 /** This function is notification that the device should attempt to send a
114 * packet again. */
115 virtual void recvRetry();
116
117 public:
116 PioPort(PioDevice *dev, Platform *p);
118 PioPort(PioDevice *dev, Platform *p, std::string pname = "-pioport");
117
118 friend class PioPort::SendEvent;
119};
120
121
122class DmaPort : public Port
123{
124 protected:
125 struct DmaReqState : public Packet::SenderState
126 {
127 /** Event to call on the device when this transaction (all packets)
128 * complete. */
129 Event *completionEvent;
130
131 /** Where we came from for some sanity checking. */
132 Port *outPort;
133
134 /** Total number of bytes that this transaction involves. */
135 Addr totBytes;
136
137 /** Number of bytes that have been acked for this transaction. */
138 Addr numBytes;
139
140 DmaReqState(Event *ce, Port *p, Addr tb)
141 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0)
142 {}
143 };
144
145 DmaDevice *device;
146 std::list<Packet*> transmitList;
147
148 /** The platform that device/port are in. This is used to select which mode
149 * we are currently operating in. */
150 Platform *platform;
151
152 /** Number of outstanding packets the dma port has. */
153 int pendingCount;
154
155 virtual bool recvTiming(Packet *pkt);
156 virtual Tick recvAtomic(Packet *pkt)
157 { panic("dma port shouldn't be used for pio access."); }
158 virtual void recvFunctional(Packet *pkt)
159 { panic("dma port shouldn't be used for pio access."); }
160
161 virtual void recvStatusChange(Status status)
162 { ; }
163
164 virtual void recvRetry() ;
165
166 virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
167 { resp.clear(); snoop.clear(); }
168
169 void sendDma(Packet *pkt, bool front = false);
170
171 public:
172 DmaPort(DmaDevice *dev, Platform *p);
173
174 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
175 uint8_t *data = NULL);
176
177 bool dmaPending() { return pendingCount > 0; }
178
179};
180
181/**
182 * This device is the base class which all devices senstive to an address range
183 * inherit from. There are three pure virtual functions which all devices must
184 * implement addressRanges(), read(), and write(). The magic do choose which
185 * mode we are in, etc is handled by the PioPort so the device doesn't have to
186 * bother.
187 */
188
189class PioDevice : public MemObject
190{
191 protected:
192
193 /** The platform we are in. This is used to decide what type of memory
194 * transaction we should perform. */
195 Platform *platform;
196
197 /** The pioPort that handles the requests for us and provides us requests
198 * that it sees. */
199 PioPort *pioPort;
200
201 virtual void addressRanges(AddrRangeList &range_list) = 0;
202
203 /** As far as the devices are concerned they only accept atomic transactions
204 * which are converted to either a write or a read. */
205 Tick recvAtomic(Packet *pkt)
206 { return pkt->isRead() ? this->read(pkt) : this->write(pkt); }
207
208 /** Pure virtual function that the device must implement. Called when a read
209 * 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(Packet *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(Packet *pkt) = 0;
221
222 public:
223 /** Params struct which is extended through each device based on the
224 * parameters it needs. Since we are re-writing everything, we might as well
225 * start from the bottom this time. */
226
227 struct Params
228 {
229 std::string name;
230 Platform *platform;
231 System *system;
232 };
233
234 protected:
235 Params *_params;
236
237 public:
238 const Params *params() const { return _params; }
239
240 PioDevice(Params *p)
241 : MemObject(p->name), platform(p->platform), pioPort(NULL),
242 _params(p)
243 {}
244
245 virtual ~PioDevice();
246
247 virtual void init();
248
249 virtual Port *getPort(const std::string &if_name, int idx = -1)
250 {
251 if (if_name == "pio") {
252 if (pioPort != NULL)
253 panic("pio port already connected to.");
254 pioPort = new PioPort(this, params()->platform);
255 return pioPort;
256 } else
257 return NULL;
258 }
259 friend class PioPort;
260
261};
262
263class BasicPioDevice : public PioDevice
264{
265 public:
266 struct Params : public PioDevice::Params
267 {
268 Addr pio_addr;
269 Tick pio_delay;
270 };
271
272 protected:
273 /** Address that the device listens to. */
274 Addr pioAddr;
275
276 /** Size that the device's address range. */
277 Addr pioSize;
278
279 /** Delay that the device experinces on an access. */
280 Tick pioDelay;
281
282 public:
283 BasicPioDevice(Params *p)
284 : PioDevice(p), pioAddr(p->pio_addr), pioSize(0), pioDelay(p->pio_delay)
285 {}
286
287 /** return the address ranges that this device responds to.
288 * @params range_list range list to populate with ranges
289 */
290 void addressRanges(AddrRangeList &range_list);
291
292};
293
294class DmaDevice : public PioDevice
295{
296 protected:
297 DmaPort *dmaPort;
298
299 public:
300 DmaDevice(Params *p);
301 virtual ~DmaDevice();
302
303 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data)
304 { dmaPort->dmaAction(Packet::WriteReq, addr, size, event, data) ; }
305
306 void dmaRead(Addr addr, int size, Event *event, uint8_t *data = NULL)
307 { dmaPort->dmaAction(Packet::ReadReq, addr, size, event, data); }
308
309 bool dmaPending() { return dmaPort->dmaPending(); }
310
311 virtual Port *getPort(const std::string &if_name, int idx = -1)
312 {
313 if (if_name == "pio") {
314 if (pioPort != NULL)
315 panic("pio port already connected to.");
316 pioPort = new PioPort(this, params()->platform);
317 return pioPort;
318 } else if (if_name == "dma") {
319 if (dmaPort != NULL)
320 panic("dma port already connected to.");
321 dmaPort = new DmaPort(this, params()->platform);
322 return dmaPort;
323 } else
324 return NULL;
325 }
326
327 friend class DmaPort;
328};
329
330
331#endif // __DEV_IO_DEVICE_HH__
119
120 friend class PioPort::SendEvent;
121};
122
123
124class DmaPort : public Port
125{
126 protected:
127 struct DmaReqState : public Packet::SenderState
128 {
129 /** Event to call on the device when this transaction (all packets)
130 * complete. */
131 Event *completionEvent;
132
133 /** Where we came from for some sanity checking. */
134 Port *outPort;
135
136 /** Total number of bytes that this transaction involves. */
137 Addr totBytes;
138
139 /** Number of bytes that have been acked for this transaction. */
140 Addr numBytes;
141
142 DmaReqState(Event *ce, Port *p, Addr tb)
143 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0)
144 {}
145 };
146
147 DmaDevice *device;
148 std::list<Packet*> transmitList;
149
150 /** The platform that device/port are in. This is used to select which mode
151 * we are currently operating in. */
152 Platform *platform;
153
154 /** Number of outstanding packets the dma port has. */
155 int pendingCount;
156
157 virtual bool recvTiming(Packet *pkt);
158 virtual Tick recvAtomic(Packet *pkt)
159 { panic("dma port shouldn't be used for pio access."); }
160 virtual void recvFunctional(Packet *pkt)
161 { panic("dma port shouldn't be used for pio access."); }
162
163 virtual void recvStatusChange(Status status)
164 { ; }
165
166 virtual void recvRetry() ;
167
168 virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
169 { resp.clear(); snoop.clear(); }
170
171 void sendDma(Packet *pkt, bool front = false);
172
173 public:
174 DmaPort(DmaDevice *dev, Platform *p);
175
176 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
177 uint8_t *data = NULL);
178
179 bool dmaPending() { return pendingCount > 0; }
180
181};
182
183/**
184 * This device is the base class which all devices senstive to an address range
185 * inherit from. There are three pure virtual functions which all devices must
186 * implement addressRanges(), read(), and write(). The magic do choose which
187 * mode we are in, etc is handled by the PioPort so the device doesn't have to
188 * bother.
189 */
190
191class PioDevice : public MemObject
192{
193 protected:
194
195 /** The platform we are in. This is used to decide what type of memory
196 * transaction we should perform. */
197 Platform *platform;
198
199 /** The pioPort that handles the requests for us and provides us requests
200 * that it sees. */
201 PioPort *pioPort;
202
203 virtual void addressRanges(AddrRangeList &range_list) = 0;
204
205 /** As far as the devices are concerned they only accept atomic transactions
206 * which are converted to either a write or a read. */
207 Tick recvAtomic(Packet *pkt)
208 { return pkt->isRead() ? this->read(pkt) : this->write(pkt); }
209
210 /** Pure virtual function that the device must implement. Called when a read
211 * command is recieved by the port.
212 * @param pkt Packet describing this request
213 * @return number of ticks it took to complete
214 */
215 virtual Tick read(Packet *pkt) = 0;
216
217 /** Pure virtual function that the device must implement. Called when a
218 * write command is recieved by the port.
219 * @param pkt Packet describing this request
220 * @return number of ticks it took to complete
221 */
222 virtual Tick write(Packet *pkt) = 0;
223
224 public:
225 /** Params struct which is extended through each device based on the
226 * parameters it needs. Since we are re-writing everything, we might as well
227 * start from the bottom this time. */
228
229 struct Params
230 {
231 std::string name;
232 Platform *platform;
233 System *system;
234 };
235
236 protected:
237 Params *_params;
238
239 public:
240 const Params *params() const { return _params; }
241
242 PioDevice(Params *p)
243 : MemObject(p->name), platform(p->platform), pioPort(NULL),
244 _params(p)
245 {}
246
247 virtual ~PioDevice();
248
249 virtual void init();
250
251 virtual Port *getPort(const std::string &if_name, int idx = -1)
252 {
253 if (if_name == "pio") {
254 if (pioPort != NULL)
255 panic("pio port already connected to.");
256 pioPort = new PioPort(this, params()->platform);
257 return pioPort;
258 } else
259 return NULL;
260 }
261 friend class PioPort;
262
263};
264
265class BasicPioDevice : public PioDevice
266{
267 public:
268 struct Params : public PioDevice::Params
269 {
270 Addr pio_addr;
271 Tick pio_delay;
272 };
273
274 protected:
275 /** Address that the device listens to. */
276 Addr pioAddr;
277
278 /** Size that the device's address range. */
279 Addr pioSize;
280
281 /** Delay that the device experinces on an access. */
282 Tick pioDelay;
283
284 public:
285 BasicPioDevice(Params *p)
286 : PioDevice(p), pioAddr(p->pio_addr), pioSize(0), pioDelay(p->pio_delay)
287 {}
288
289 /** return the address ranges that this device responds to.
290 * @params range_list range list to populate with ranges
291 */
292 void addressRanges(AddrRangeList &range_list);
293
294};
295
296class DmaDevice : public PioDevice
297{
298 protected:
299 DmaPort *dmaPort;
300
301 public:
302 DmaDevice(Params *p);
303 virtual ~DmaDevice();
304
305 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data)
306 { dmaPort->dmaAction(Packet::WriteReq, addr, size, event, data) ; }
307
308 void dmaRead(Addr addr, int size, Event *event, uint8_t *data = NULL)
309 { dmaPort->dmaAction(Packet::ReadReq, addr, size, event, data); }
310
311 bool dmaPending() { return dmaPort->dmaPending(); }
312
313 virtual Port *getPort(const std::string &if_name, int idx = -1)
314 {
315 if (if_name == "pio") {
316 if (pioPort != NULL)
317 panic("pio port already connected to.");
318 pioPort = new PioPort(this, params()->platform);
319 return pioPort;
320 } else if (if_name == "dma") {
321 if (dmaPort != NULL)
322 panic("dma port already connected to.");
323 dmaPort = new DmaPort(this, params()->platform);
324 return dmaPort;
325 } else
326 return NULL;
327 }
328
329 friend class DmaPort;
330};
331
332
333#endif // __DEV_IO_DEVICE_HH__