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 "sim/sim_object.hh"
47 * The PioPort class is a programmed i/o port that all devices that are
48 * sensitive to an address range use. The port takes all the memory
49 * access types and roles them into one read() and write() call that the device
50 * must respond to. The device must also provide the addressRanges() function
51 * with which it returns the address ranges it is interested in.
53 class PioPort : public SimpleTimingPort
56 /** The device that this port serves. */
59 virtual Tick recvAtomic(PacketPtr pkt);
61 virtual void getDeviceAddressRanges(AddrRangeList &resp,
62 AddrRangeList &snoop);
66 PioPort(PioDevice *dev, System *s, std::string pname = "-pioport");
70 class DmaPort : public Port
73 struct DmaReqState : public Packet::SenderState
75 /** Event to call on the device when this transaction (all packets)
77 Event *completionEvent;
79 /** Where we came from for some sanity checking. */
82 /** Total number of bytes that this transaction involves. */
85 /** Number of bytes that have been acked for this transaction. */
88 DmaReqState(Event *ce, Port *p, Addr tb)
89 : completionEvent(ce), outPort(p), totBytes(tb), numBytes(0)
94 std::list<PacketPtr> transmitList;
96 /** The system that device/port are in. This is used to select which mode
97 * we are currently operating in. */
100 /** Number of outstanding packets the dma port has. */
103 /** If a dmaAction is in progress. */
104 int actionInProgress;
106 /** If we need to drain, keep the drain event around until we're done
110 /** time to wait between sending another packet, increases as NACKs are
111 * recived, decreases as responses are recived. */
114 /** If the port is currently waiting for a retry before it can send whatever
115 * it is that it's sending. */
118 virtual bool recvTiming(PacketPtr pkt);
119 virtual Tick recvAtomic(PacketPtr pkt)
120 { panic("dma port shouldn't be used for pio access."); M5_DUMMY_RETURN }
121 virtual void recvFunctional(PacketPtr pkt)
122 { panic("dma port shouldn't be used for pio access."); }
124 virtual void recvStatusChange(Status status)
127 virtual void recvRetry() ;
129 virtual void getDeviceAddressRanges(AddrRangeList &resp,
130 AddrRangeList &snoop)
131 { resp.clear(); snoop.clear(); }
133 void queueDma(PacketPtr pkt, bool front = false);
136 /** event to give us a kick every time we backoff time is reached. */
137 EventWrapper<DmaPort, &DmaPort::sendDma> backoffEvent;
140 DmaPort(DmaDevice *dev, System *s);
142 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
143 uint8_t *data = NULL);
145 bool dmaPending() { return pendingCount > 0; }
147 int cacheBlockSize() { return peerBlockSize(); }
148 unsigned int drain(Event *de);
152 * This device is the base class which all devices senstive to an address range
153 * inherit from. There are three pure virtual functions which all devices must
154 * implement addressRanges(), read(), and write(). The magic do choose which
155 * mode we are in, etc is handled by the PioPort so the device doesn't have to
158 class PioDevice : public MemObject
162 /** The platform we are in. This is used to decide what type of memory
163 * transaction we should perform. */
168 /** The pioPort that handles the requests for us and provides us requests
172 virtual void addressRanges(AddrRangeList &range_list) = 0;
174 /** Pure virtual function that the device must implement. Called
175 * when a read command is recieved by the port.
176 * @param pkt Packet describing this request
177 * @return number of ticks it took to complete
179 virtual Tick read(PacketPtr pkt) = 0;
181 /** Pure virtual function that the device must implement. Called when a
182 * write command is recieved by the port.
183 * @param pkt Packet describing this request
184 * @return number of ticks it took to complete
186 virtual Tick write(PacketPtr pkt) = 0;
189 /** Params struct which is extended through each device based on
190 * the parameters it needs. Since we are re-writing everything, we
191 * might as well start from the bottom this time. */
203 const Params *params() const { return _params; }
206 : MemObject(p->name), platform(p->platform), sys(p->system),
207 pioPort(NULL), _params(p)
210 virtual ~PioDevice();
214 virtual unsigned int drain(Event *de);
216 virtual Port *getPort(const std::string &if_name, int idx = -1)
218 if (if_name == "pio") {
220 panic("pio port already connected to.");
221 pioPort = new PioPort(this, sys);
226 friend class PioPort;
230 class BasicPioDevice : public PioDevice
233 struct Params : public PioDevice::Params
240 /** Address that the device listens to. */
243 /** Size that the device's address range. */
246 /** Delay that the device experinces on an access. */
250 BasicPioDevice(Params *p)
251 : PioDevice(p), pioAddr(p->pio_addr), pioSize(0),
252 pioDelay(p->pio_delay)
255 /** return the address ranges that this device responds to.
256 * @param range_list range list to populate with ranges
258 void addressRanges(AddrRangeList &range_list);
262 class DmaDevice : public PioDevice
265 struct Params : public PioDevice::Params
267 Tick min_backoff_delay;
268 Tick max_backoff_delay;
273 Tick minBackoffDelay;
274 Tick maxBackoffDelay;
277 DmaDevice(Params *p);
278 virtual ~DmaDevice();
280 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data)
282 dmaPort->dmaAction(MemCmd::WriteInvalidateReq,
283 addr, size, event, data);
286 void dmaRead(Addr addr, int size, Event *event, uint8_t *data)
288 dmaPort->dmaAction(MemCmd::ReadReq, addr, size, event, data);
291 bool dmaPending() { return dmaPort->dmaPending(); }
293 virtual unsigned int drain(Event *de);
295 int cacheBlockSize() { return dmaPort->cacheBlockSize(); }
297 virtual Port *getPort(const std::string &if_name, int idx = -1)
299 if (if_name == "pio") {
301 panic("pio port already connected to.");
302 pioPort = new PioPort(this, sys);
304 } else if (if_name == "dma") {
306 panic("dma port already connected to.");
307 dmaPort = new DmaPort(this, sys);
313 friend class DmaPort;
317 #endif // __DEV_IO_DEVICE_HH__