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.
32 #ifndef __DEV_IO_DEVICE_HH__
33 #define __DEV_IO_DEVICE_HH__
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"
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
53 * must respond to. The device must also provide getAddrRanges() function
54 * with which it returns the address ranges it is interested in.
56 class PioPort : public SimpleTimingPort
59 /** The device that this port serves. */
62 virtual Tick recvAtomic(PacketPtr pkt);
64 virtual AddrRangeList getAddrRanges();
68 PioPort(PioDevice *dev);
72 class DmaPort : public MasterPort
75 struct DmaReqState : public Packet::SenderState, public FastAlloc
77 /** Event to call on the device when this transaction (all packets)
79 Event *completionEvent;
81 /** Where we came from for some sanity checking. */
84 /** Total number of bytes that this transaction involves. */
87 /** Number of bytes that have been acked for this transaction. */
90 /** Amount to delay completion of dma by */
94 DmaReqState(Event *ce, Port *p, Addr tb, Tick _delay)
95 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0),
101 std::list<PacketPtr> transmitList;
103 /** The system that device/port are in. This is used to select which mode
104 * we are currently operating in. */
107 /** Id for all requests */
110 /** Number of outstanding packets the dma port has. */
113 /** If a dmaAction is in progress. */
114 int actionInProgress;
116 /** If we need to drain, keep the drain event around until we're done
120 /** time to wait between sending another packet, increases as NACKs are
121 * recived, decreases as responses are recived. */
124 /** Minimum time that device should back off for after failed sendTiming */
125 Tick minBackoffDelay;
127 /** Maximum time that device should back off for after failed sendTiming */
128 Tick maxBackoffDelay;
130 /** If the port is currently waiting for a retry before it can send whatever
131 * it is that it's sending. */
134 /** Port accesses a cache which requires snooping */
137 virtual bool recvTiming(PacketPtr pkt);
138 virtual Tick recvAtomic(PacketPtr pkt)
140 if (recvSnoops) return 0;
142 panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN
144 virtual void recvFunctional(PacketPtr pkt)
146 if (recvSnoops) return;
148 panic("dma port shouldn't be used for pio access.");
151 virtual void recvRetry() ;
153 virtual bool isSnooping() const { return recvSnoops; }
155 void queueDma(PacketPtr pkt, bool front = false);
158 /** event to give us a kick every time we backoff time is reached. */
159 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
162 DmaPort(MemObject *dev, System *s, Tick min_backoff, Tick max_backoff,
163 bool recv_snoops = false);
165 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
166 uint8_t *data, Tick delay, Request::Flags flag = 0);
168 bool dmaPending() { return pendingCount > 0; }
170 unsigned cacheBlockSize() const { return peerBlockSize(); }
171 unsigned int drain(Event *de);
175 * This device is the base class which all devices senstive to an address range
176 * inherit from. There are three pure virtual functions which all devices must
177 * implement getAddrRanges(), read(), and write(). The magic do choose which
178 * mode we are in, etc is handled by the PioPort so the device doesn't have to
181 class PioDevice : public MemObject
186 /** The pioPort that handles the requests for us and provides us requests
191 * Every PIO device is obliged to provide an implementation that
192 * returns the address ranges the device responds to.
194 * @return a list of non-overlapping address ranges
196 virtual AddrRangeList getAddrRanges() = 0;
198 /** Pure virtual function that the device must implement. Called
199 * when a read command is recieved by the port.
200 * @param pkt Packet describing this request
201 * @return number of ticks it took to complete
203 virtual Tick read(PacketPtr pkt) = 0;
205 /** Pure virtual function that the device must implement. Called when a
206 * write command is recieved by the port.
207 * @param pkt Packet describing this request
208 * @return number of ticks it took to complete
210 virtual Tick write(PacketPtr pkt) = 0;
213 typedef PioDeviceParams Params;
214 PioDevice(const Params *p);
215 virtual ~PioDevice();
220 return dynamic_cast<const Params *>(_params);
225 virtual unsigned int drain(Event *de);
227 virtual SlavePort &getSlavePort(const std::string &if_name, int idx = -1);
229 friend class PioPort;
233 class BasicPioDevice : public PioDevice
236 /** Address that the device listens to. */
239 /** Size that the device's address range. */
242 /** Delay that the device experinces on an access. */
246 typedef BasicPioDeviceParams Params;
247 BasicPioDevice(const Params *p);
252 return dynamic_cast<const Params *>(_params);
256 * Determine the address ranges that this device responds to.
258 * @return a list of non-overlapping address ranges
260 virtual AddrRangeList getAddrRanges();
264 class DmaDevice : public PioDevice
270 typedef DmaDeviceParams Params;
271 DmaDevice(const Params *p);
272 virtual ~DmaDevice();
277 return dynamic_cast<const Params *>(_params);
280 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
283 dmaPort.dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
286 void dmaRead(Addr addr, int size, Event *event, uint8_t *data,
289 dmaPort.dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
292 bool dmaPending() { return dmaPort.dmaPending(); }
296 virtual unsigned int drain(Event *de);
298 unsigned cacheBlockSize() const { return dmaPort.cacheBlockSize(); }
300 virtual MasterPort &getMasterPort(const std::string &if_name,
303 friend class DmaPort;
307 #endif // __DEV_IO_DEVICE_HH__