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