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"
51 * The PioPort class is a programmed i/o port that all devices that are
52 * sensitive to an address range use. The port takes all the memory
53 * access types and roles them into one read() and write() call that the device
54 * must respond to. The device must also provide the addressRanges() function
55 * with which it returns the address ranges it is interested in.
57 class PioPort : public SimpleTimingPort
60 /** The device that this port serves. */
63 virtual Tick recvAtomic(PacketPtr pkt);
65 virtual void getDeviceAddressRanges(AddrRangeList &resp,
70 PioPort(PioDevice *dev, System *s, std::string pname = "-pioport");
74 class DmaPort : public Port
77 struct DmaReqState : public Packet::SenderState, public FastAlloc
79 /** Event to call on the device when this transaction (all packets)
81 Event *completionEvent;
83 /** Where we came from for some sanity checking. */
86 /** Total number of bytes that this transaction involves. */
89 /** Number of bytes that have been acked for this transaction. */
92 DmaReqState(Event *ce, Port *p, Addr tb)
93 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0)
98 std::list<PacketPtr> transmitList;
100 /** The system that device/port are in. This is used to select which mode
101 * we are currently operating in. */
104 /** Number of outstanding packets the dma port has. */
107 /** If a dmaAction is in progress. */
108 int actionInProgress;
110 /** If we need to drain, keep the drain event around until we're done
114 /** time to wait between sending another packet, increases as NACKs are
115 * recived, decreases as responses are recived. */
118 /** If the port is currently waiting for a retry before it can send whatever
119 * it is that it's sending. */
122 virtual bool recvTiming(PacketPtr pkt);
123 virtual Tick recvAtomic(PacketPtr pkt)
124 { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN }
125 virtual void recvFunctional(PacketPtr pkt)
126 { panic("dma port shouldn't be used for pio access."); }
128 virtual void recvStatusChange(Status status)
131 virtual void recvRetry() ;
133 virtual void getDeviceAddressRanges(AddrRangeList &resp,
135 { resp.clear(); snoop = false; }
137 void queueDma(PacketPtr pkt, bool front = false);
140 /** event to give us a kick every time we backoff time is reached. */
141 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
144 DmaPort(DmaDevice *dev, System *s);
146 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
147 uint8_t *data = NULL);
149 bool dmaPending() { return pendingCount > 0; }
151 int cacheBlockSize() { return peerBlockSize(); }
152 unsigned int drain(Event *de);
156 * This device is the base class which all devices senstive to an address range
157 * inherit from. There are three pure virtual functions which all devices must
158 * implement addressRanges(), read(), and write(). The magic do choose which
159 * mode we are in, etc is handled by the PioPort so the device doesn't have to
162 class PioDevice : public MemObject
166 /** The platform we are in. This is used to decide what type of memory
167 * transaction we should perform. */
172 /** The pioPort that handles the requests for us and provides us requests
176 virtual void addressRanges(AddrRangeList &range_list) = 0;
178 /** Pure virtual function that the device must implement. Called
179 * when a read command is recieved by the port.
180 * @param pkt Packet describing this request
181 * @return number of ticks it took to complete
183 virtual Tick read(PacketPtr pkt) = 0;
185 /** Pure virtual function that the device must implement. Called when a
186 * write command is recieved by the port.
187 * @param pkt Packet describing this request
188 * @return number of ticks it took to complete
190 virtual Tick write(PacketPtr pkt) = 0;
193 typedef PioDeviceParams Params;
194 PioDevice(const Params *p);
195 virtual ~PioDevice();
200 return dynamic_cast<const Params *>(_params);
205 virtual unsigned int drain(Event *de);
207 virtual Port *getPort(const std::string &if_name, int idx = -1)
209 if (if_name == "pio") {
211 panic("pio port already connected to.");
212 pioPort = new PioPort(this, sys);
217 friend class PioPort;
221 class BasicPioDevice : public PioDevice
224 /** Address that the device listens to. */
227 /** Size that the device's address range. */
230 /** Delay that the device experinces on an access. */
234 typedef BasicPioDeviceParams Params;
235 BasicPioDevice(const Params *p);
240 return dynamic_cast<const Params *>(_params);
243 /** return the address ranges that this device responds to.
244 * @param range_list range list to populate with ranges
246 void addressRanges(AddrRangeList &range_list);
250 class DmaDevice : public PioDevice
254 Tick minBackoffDelay;
255 Tick maxBackoffDelay;
258 typedef DmaDeviceParams Params;
259 DmaDevice(const Params *p);
260 virtual ~DmaDevice();
265 return dynamic_cast<const Params *>(_params);
268 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data)
270 dmaPort->dmaAction(MemCmd::WriteReq, 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__