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 the addressRanges() 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 void getDeviceAddressRanges(AddrRangeList &resp,
69 PioPort(PioDevice *dev, System *s, std::string pname = "-pioport");
73 class DmaPort : public Port
76 struct DmaReqState : public Packet::SenderState, public FastAlloc
78 /** Event to call on the device when this transaction (all packets)
80 Event *completionEvent;
82 /** Where we came from for some sanity checking. */
85 /** Total number of bytes that this transaction involves. */
88 /** Number of bytes that have been acked for this transaction. */
91 /** Amount to delay completion of dma by */
95 DmaReqState(Event *ce, Port *p, Addr tb, Tick _delay)
96 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0),
102 std::list<PacketPtr> transmitList;
104 /** The system that device/port are in. This is used to select which mode
105 * we are currently operating in. */
108 /** Number of outstanding packets the dma port has. */
111 /** If a dmaAction is in progress. */
112 int actionInProgress;
114 /** If we need to drain, keep the drain event around until we're done
118 /** time to wait between sending another packet, increases as NACKs are
119 * recived, decreases as responses are recived. */
122 /** Minimum time that device should back off for after failed sendTiming */
123 Tick minBackoffDelay;
125 /** Maximum time that device should back off for after failed sendTiming */
126 Tick maxBackoffDelay;
128 /** If the port is currently waiting for a retry before it can send whatever
129 * it is that it's sending. */
132 virtual bool recvTiming(PacketPtr pkt);
133 virtual Tick recvAtomic(PacketPtr pkt)
134 { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN }
135 virtual void recvFunctional(PacketPtr pkt)
136 { panic("dma port shouldn't be used for pio access."); }
138 virtual void recvStatusChange(Status status)
141 virtual void recvRetry() ;
143 virtual void getDeviceAddressRanges(AddrRangeList &resp,
145 { resp.clear(); snoop = false; }
147 void queueDma(PacketPtr pkt, bool front = false);
150 /** event to give us a kick every time we backoff time is reached. */
151 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
154 DmaPort(MemObject *dev, System *s, Tick min_backoff, Tick max_backoff);
156 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
157 uint8_t *data, Tick delay, Request::Flags flag = 0);
159 bool dmaPending() { return pendingCount > 0; }
161 unsigned cacheBlockSize() const { return peerBlockSize(); }
162 unsigned int drain(Event *de);
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
168 * implement addressRanges(), read(), and write(). The magic do choose which
169 * mode we are in, etc is handled by the PioPort so the device doesn't have to
172 class PioDevice : public MemObject
177 /** The pioPort that handles the requests for us and provides us requests
181 virtual void addressRanges(AddrRangeList &range_list) = 0;
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
188 virtual Tick read(PacketPtr pkt) = 0;
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
195 virtual Tick write(PacketPtr pkt) = 0;
198 typedef PioDeviceParams Params;
199 PioDevice(const Params *p);
200 virtual ~PioDevice();
205 return dynamic_cast<const Params *>(_params);
210 virtual unsigned int drain(Event *de);
212 virtual Port *getPort(const std::string &if_name, int idx = -1)
214 if (if_name == "pio") {
216 fatal("%s: pio port already connected to %s",
217 name(), pioPort->getPeer()->name());
218 pioPort = new PioPort(this, sys);
223 friend class PioPort;
227 class BasicPioDevice : public PioDevice
230 /** Address that the device listens to. */
233 /** Size that the device's address range. */
236 /** Delay that the device experinces on an access. */
240 typedef BasicPioDeviceParams Params;
241 BasicPioDevice(const Params *p);
246 return dynamic_cast<const Params *>(_params);
249 /** return the address ranges that this device responds to.
250 * @param range_list range list to populate with ranges
252 void addressRanges(AddrRangeList &range_list);
256 class DmaDevice : public PioDevice
262 typedef DmaDeviceParams Params;
263 DmaDevice(const Params *p);
264 virtual ~DmaDevice();
269 return dynamic_cast<const Params *>(_params);
272 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay = 0)
274 dmaPort->dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
277 void dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay = 0)
279 dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
282 bool dmaPending() { return dmaPort->dmaPending(); }
284 virtual unsigned int drain(Event *de);
286 unsigned cacheBlockSize() const { return dmaPort->cacheBlockSize(); }
288 virtual Port *getPort(const std::string &if_name, int idx = -1)
290 if (if_name == "pio") {
292 fatal("%s: pio port already connected to %s",
293 name(), pioPort->getPeer()->name());
294 pioPort = new PioPort(this, sys);
296 } else if (if_name == "dma") {
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);
307 friend class DmaPort;
311 #endif // __DEV_IO_DEVICE_HH__