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_impl.hh"
37 #include "sim/sim_object.hh"
38 #include "mem/tport.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(Packet *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<Packet*> 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 virtual bool recvTiming(Packet *pkt);
111 virtual Tick recvAtomic(Packet *pkt)
112 { panic("dma port shouldn't be used for pio access."); }
113 virtual void recvFunctional(Packet *pkt)
114 { panic("dma port shouldn't be used for pio access."); }
116 virtual void recvStatusChange(Status status)
119 virtual void recvRetry() ;
121 virtual void getDeviceAddressRanges(AddrRangeList &resp,
122 AddrRangeList &snoop)
123 { resp.clear(); snoop.clear(); }
125 void sendDma(Packet *pkt, bool front = false);
128 DmaPort(DmaDevice *dev, System *s);
130 void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
131 uint8_t *data = NULL);
133 bool dmaPending() { return pendingCount > 0; }
135 unsigned int drain(Event *de);
139 * This device is the base class which all devices senstive to an address range
140 * inherit from. There are three pure virtual functions which all devices must
141 * implement addressRanges(), read(), and write(). The magic do choose which
142 * mode we are in, etc is handled by the PioPort so the device doesn't have to
145 class PioDevice : public MemObject
149 /** The platform we are in. This is used to decide what type of memory
150 * transaction we should perform. */
155 /** The pioPort that handles the requests for us and provides us requests
159 virtual void addressRanges(AddrRangeList &range_list) = 0;
161 /** Pure virtual function that the device must implement. Called
162 * when a read command is recieved by the port.
163 * @param pkt Packet describing this request
164 * @return number of ticks it took to complete
166 virtual Tick read(Packet *pkt) = 0;
168 /** Pure virtual function that the device must implement. Called when a
169 * write command is recieved by the port.
170 * @param pkt Packet describing this request
171 * @return number of ticks it took to complete
173 virtual Tick write(Packet *pkt) = 0;
176 /** Params struct which is extended through each device based on
177 * the parameters it needs. Since we are re-writing everything, we
178 * might as well start from the bottom this time. */
190 const Params *params() const { return _params; }
193 : MemObject(p->name), platform(p->platform), sys(p->system),
194 pioPort(NULL), _params(p)
197 virtual ~PioDevice();
201 virtual unsigned int drain(Event *de);
203 virtual Port *getPort(const std::string &if_name, int idx = -1)
205 if (if_name == "pio") {
207 panic("pio port already connected to.");
208 pioPort = new PioPort(this, sys);
213 friend class PioPort;
217 class BasicPioDevice : public PioDevice
220 struct Params : public PioDevice::Params
227 /** Address that the device listens to. */
230 /** Size that the device's address range. */
233 /** Delay that the device experinces on an access. */
237 BasicPioDevice(Params *p)
238 : PioDevice(p), pioAddr(p->pio_addr), pioSize(0),
239 pioDelay(p->pio_delay)
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
255 DmaDevice(Params *p);
256 virtual ~DmaDevice();
258 void dmaWrite(Addr addr, int size, Event *event, uint8_t *data)
259 { dmaPort->dmaAction(Packet::WriteReq, addr, size, event, data) ; }
261 void dmaRead(Addr addr, int size, Event *event, uint8_t *data = NULL)
262 { dmaPort->dmaAction(Packet::ReadReq, addr, size, event, data); }
264 bool dmaPending() { return dmaPort->dmaPending(); }
266 virtual unsigned int drain(Event *de);
268 virtual Port *getPort(const std::string &if_name, int idx = -1)
270 if (if_name == "pio") {
272 panic("pio port already connected to.");
273 pioPort = new PioPort(this, sys);
275 } else if (if_name == "dma") {
277 panic("dma port already connected to.");
278 dmaPort = new DmaPort(this, sys);
284 friend class DmaPort;
288 #endif // __DEV_IO_DEVICE_HH__