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 "mem/mem_object.hh"
36 #include "mem/packet.hh"
37 #include "mem/tport.hh"
38 #include "params/BasicPioDevice.hh"
39 #include "params/DmaDevice.hh"
40 #include "params/PioDevice.hh"
41 #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
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 DmaReqState(Event *ce, Port *p, Addr tb)
92 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0)
97 std::list<PacketPtr> transmitList;
99 /** The system that device/port are in. This is used to select which mode
100 * we are currently operating in. */
103 /** Number of outstanding packets the dma port has. */
106 /** If a dmaAction is in progress. */
107 int actionInProgress;
109 /** If we need to drain, keep the drain event around until we're done
113 /** time to wait between sending another packet, increases as NACKs are
114 * recived, decreases as responses are recived. */
117 /** If the port is currently waiting for a retry before it can send whatever
118 * it is that it's sending. */
121 virtual bool recvTiming(PacketPtr pkt);
122 virtual Tick recvAtomic(PacketPtr pkt)
123 { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN }
124 virtual void recvFunctional(PacketPtr pkt)
125 { panic("dma port shouldn't be used for pio access."); }
127 virtual void recvStatusChange(Status status)
130 virtual void recvRetry() ;
132 virtual void getDeviceAddressRanges(AddrRangeList &resp,
134 { resp.clear(); snoop = false; }
136 void queueDma(PacketPtr pkt, bool front = false);
139 /** event to give us a kick every time we backoff time is reached. */
140 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
143 DmaPort(DmaDevice *dev, System *s);
145 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
146 uint8_t *data = NULL);
148 bool dmaPending() { return pendingCount > 0; }
150 int cacheBlockSize() { return peerBlockSize(); }
151 unsigned int drain(Event *de);
155 * This device is the base class which all devices senstive to an address range
156 * inherit from. There are three pure virtual functions which all devices must
157 * implement addressRanges(), read(), and write(). The magic do choose which
158 * mode we are in, etc is handled by the PioPort so the device doesn't have to
161 class PioDevice : public MemObject
165 /** The platform we are in. This is used to decide what type of memory
166 * transaction we should perform. */
171 /** The pioPort that handles the requests for us and provides us requests
175 virtual void addressRanges(AddrRangeList &range_list) = 0;
177 /** Pure virtual function that the device must implement. Called
178 * when a read command is recieved by the port.
179 * @param pkt Packet describing this request
180 * @return number of ticks it took to complete
182 virtual Tick read(PacketPtr pkt) = 0;
184 /** Pure virtual function that the device must implement. Called when a
185 * write command is recieved by the port.
186 * @param pkt Packet describing this request
187 * @return number of ticks it took to complete
189 virtual Tick write(PacketPtr pkt) = 0;
192 typedef PioDeviceParams Params;
193 PioDevice(const Params *p);
194 virtual ~PioDevice();
199 return dynamic_cast<const Params *>(_params);
204 virtual unsigned int drain(Event *de);
206 virtual Port *getPort(const std::string &if_name, int idx = -1)
208 if (if_name == "pio") {
210 panic("pio port already connected to.");
211 pioPort = new PioPort(this, sys);
216 friend class PioPort;
220 class BasicPioDevice : public PioDevice
223 /** Address that the device listens to. */
226 /** Size that the device's address range. */
229 /** Delay that the device experinces on an access. */
233 typedef BasicPioDeviceParams Params;
234 BasicPioDevice(const Params *p);
239 return dynamic_cast<const Params *>(_params);
242 /** return the address ranges that this device responds to.
243 * @param range_list range list to populate with ranges
245 void addressRanges(AddrRangeList &range_list);
249 class DmaDevice : public PioDevice
253 Tick minBackoffDelay;
254 Tick maxBackoffDelay;
257 typedef DmaDeviceParams Params;
258 DmaDevice(const Params *p);
259 virtual ~DmaDevice();
264 return dynamic_cast<const Params *>(_params);
267 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data)
269 dmaPort->dmaAction(MemCmd::WriteInvalidateReq,
270 addr, size, event, data);
273 void dmaRead(Addr addr, int size, Event *event, uint8_t *data)
275 dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data);
278 bool dmaPending() { return dmaPort->dmaPending(); }
280 virtual unsigned int drain(Event *de);
282 int cacheBlockSize() { return dmaPort->cacheBlockSize(); }
284 virtual Port *getPort(const std::string &if_name, int idx = -1)
286 if (if_name == "pio") {
288 panic("pio port already connected to.");
289 pioPort = new PioPort(this, sys);
291 } else if (if_name == "dma") {
293 panic("dma port already connected to.");
294 dmaPort = new DmaPort(this, sys);
300 friend class DmaPort;
304 #endif // __DEV_IO_DEVICE_HH__