2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
29 #ifndef __DEV_IO_DEVICE_HH__
30 #define __DEV_IO_DEVICE_HH__
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"
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.
54 class PioPort : public Port
57 /** The device that this port serves. */
60 /** The platform that device/port are in. This is used to select which mode
61 * we are currently operating in. */
64 /** A list of outgoing timing response packets that haven't been serviced
66 std::list<Packet*> transmitList;
68 /** The current status of the peer(bus) that we are connected to. */
71 virtual bool recvTiming(Packet *pkt);
73 virtual Tick recvAtomic(Packet *pkt);
75 virtual void recvFunctional(Packet *pkt) ;
77 virtual void recvStatusChange(Status status)
78 { peerStatus = status; }
80 virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop);
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
92 SendEvent(PioPort *p, Packet *pkt, Tick t)
93 : Event(&mainEventQueue), port(p), packet(pkt)
94 { schedule(curTick + t); }
96 virtual void process();
98 virtual const char *description()
99 { return "Future scheduled sendTiming event"; }
101 friend class PioPort;
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); }
108 /** This function pops the last element off the transmit list and sends it.*/
109 virtual Packet *recvRetry();
112 PioPort(PioDevice *dev, Platform *p);
114 friend class PioPort::SendEvent;
120 Event *completionEvent;
122 DmaReqState(Event *ce, bool f)
123 : completionEvent(ce), final(f)
127 class DmaPort : public Port
131 std::list<Packet*> transmitList;
133 /** The platform that device/port are in. This is used to select which mode
134 * we are currently operating in. */
137 /** Number of outstanding packets the dma port has. */
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."); }
146 virtual void recvStatusChange(Status status)
149 virtual Packet *recvRetry() ;
151 virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
152 { resp.clear(); snoop.clear(); }
154 class SendEvent : public Event
159 SendEvent(PioPort *p, Packet *pkt, Tick t)
160 : Event(&mainEventQueue), packet(pkt)
161 { schedule(curTick + t); }
163 virtual void process();
165 virtual const char *description()
166 { return "Future scheduled sendTiming event"; }
168 friend class DmaPort;
171 void sendDma(Packet *pkt);
174 DmaPort(DmaDevice *dev, Platform *p);
176 void dmaAction(Command cmd, Addr addr, int size, Event *event,
177 uint8_t *data = NULL);
179 bool dmaPending() { return pendingCount > 0; }
181 friend class DmaPort::SendEvent;
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
193 class PioDevice : public MemObject
197 /** The platform we are in. This is used to decide what type of memory
198 * transaction we should perform. */
201 /** The pioPort that handles the requests for us and provides us requests
205 virtual void addressRanges(AddrRangeList &range_list) = 0;
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->cmd == Read ? this->read(pkt) : this->write(pkt); }
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
217 virtual Tick read(Packet *pkt) = 0;
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
224 virtual Tick write(Packet *pkt) = 0;
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. */
242 const Params *params() const { return _params; }
245 : MemObject(p->name), platform(p->platform), pioPort(NULL),
249 virtual ~PioDevice();
253 virtual Port *getPort(const std::string &if_name)
255 if (if_name == "pio") {
257 panic("pio port already connected to.");
258 pioPort = new PioPort(this, params()->platform);
263 friend class PioPort;
267 class BasicPioDevice : public PioDevice
270 struct Params : public PioDevice::Params
277 /** Address that the device listens to. */
280 /** Size that the device's address range. */
283 /** Delay that the device experinces on an access. */
287 BasicPioDevice(Params *p)
288 : PioDevice(p), pioAddr(p->pio_addr), pioSize(0), pioDelay(p->pio_delay)
291 /** return the address ranges that this device responds to.
292 * @params range_list range list to populate with ranges
294 void addressRanges(AddrRangeList &range_list);
298 class DmaDevice : public PioDevice
304 DmaDevice(Params *p);
305 virtual ~DmaDevice();
307 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data)
308 { dmaPort->dmaAction(Write, addr, size, event, data) ; }
310 void dmaRead(Addr addr, int size, Event *event, uint8_t *data = NULL)
311 { dmaPort->dmaAction(Read, addr, size, event, data); }
313 bool dmaPending() { return dmaPort->dmaPending(); }
315 virtual Port *getPort(const std::string &if_name)
317 if (if_name == "pio") {
319 panic("pio port already connected to.");
320 pioPort = new PioPort(this, params()->platform);
322 } else if (if_name == "dma") {
324 panic("dma port already connected to.");
325 dmaPort = new DmaPort(this, params()->platform);
331 friend class DmaPort;
335 #endif // __DEV_IO_DEVICE_HH__