io_device.cc revision 2542
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29#include "dev/io_device.hh"
30#include "sim/builder.hh"
31
32
33PioPort::PioPort(PioDevice *dev, Platform *p)
34        : device(dev), platform(p)
35{ }
36
37
38Tick
39PioPort::recvAtomic(Packet &pkt)
40{
41    return device->recvAtomic(pkt);
42}
43
44void
45PioPort::recvFunctional(Packet &pkt)
46{
47    device->recvAtomic(pkt);
48}
49
50void
51PioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
52{
53    snoop.clear();
54    device->addressRanges(resp);
55}
56
57
58Packet *
59PioPort::recvRetry()
60{
61    Packet* pkt = transmitList.front();
62    transmitList.pop_front();
63    return pkt;
64}
65
66
67void
68PioPort::SendEvent::process()
69{
70    if (port->Port::sendTiming(packet) == Success)
71        return;
72
73    port->transmitList.push_back(&packet);
74}
75
76
77bool
78PioPort::recvTiming(Packet &pkt)
79{
80    device->recvAtomic(pkt);
81    sendTiming(pkt, pkt.time-pkt.req->getTime());
82    return Success;
83}
84
85PioDevice::~PioDevice()
86{
87    if (pioPort)
88        delete pioPort;
89}
90
91void
92PioDevice::init()
93{
94    if (!pioPort)
95        panic("Pio port not connected to anything!");
96    pioPort->sendStatusChange(Port::RangeChange);
97}
98
99void
100BasicPioDevice::addressRanges(AddrRangeList &range_list)
101{
102    assert(pioSize != 0);
103    range_list.clear();
104    range_list.push_back(RangeSize(pioAddr, pioSize));
105}
106
107
108DmaPort::DmaPort(DmaDevice *dev)
109        : device(dev)
110{ }
111
112bool
113DmaPort::recvTiming(Packet &pkt)
114{
115    completionEvent->schedule(curTick+1);
116    completionEvent = NULL;
117    return Success;
118}
119
120DmaDevice::DmaDevice(Params *p)
121    : PioDevice(p)
122{
123    dmaPort = new DmaPort(this);
124}
125
126void
127DmaPort::SendEvent::process()
128{
129    if (port->Port::sendTiming(packet) == Success)
130        return;
131
132    port->transmitList.push_back(&packet);
133}
134
135Packet *
136DmaPort::recvRetry()
137{
138    Packet* pkt = transmitList.front();
139    transmitList.pop_front();
140    return pkt;
141}
142void
143DmaPort::dmaAction(Command cmd, DmaPort port, Addr addr, int size,
144                     Event *event, uint8_t *data)
145{
146
147    assert(event);
148
149    int prevSize = 0;
150    Packet basePkt;
151    Request baseReq(false);
152
153    basePkt.flags = 0;
154    basePkt.coherence = NULL;
155    basePkt.senderState = NULL;
156    basePkt.src = 0;
157    basePkt.dest = 0;
158    basePkt.cmd = cmd;
159    basePkt.result = Unknown;
160    basePkt.req = NULL;
161//    baseReq.nicReq = true;
162    baseReq.setTime(curTick);
163
164    completionEvent = event;
165
166    for (ChunkGenerator gen(addr, size, peerBlockSize());
167         !gen.done(); gen.next()) {
168            Packet *pkt = new Packet(basePkt);
169            Request *req = new Request(baseReq);
170            pkt->addr = gen.addr();
171            pkt->size = gen.size();
172            pkt->req = req;
173            pkt->req->setPaddr(pkt->addr);
174            pkt->req->setSize(pkt->size);
175            // Increment the data pointer on a write
176            pkt->data = data ? data + prevSize : NULL ;
177            prevSize += pkt->size;
178
179            sendDma(*pkt);
180    }
181}
182
183
184void
185DmaPort::sendDma(Packet &pkt)
186{
187   // some kind of selction between access methods
188   // more work is going to have to be done to make
189   // switching actually work
190  /* MemState state = device->platform->system->memState;
191
192   if (state == Timing) {
193       if (sendTiming(pkt) == Failure)
194           transmitList.push_back(&packet);
195   } else if (state == Atomic) {*/
196       sendAtomic(pkt);
197       completionEvent->schedule(pkt.time - pkt.req->getTime());
198       completionEvent = NULL;
199/*   } else if (state == Functional) {
200       sendFunctional(pkt);
201       // Is this correct???
202       completionEvent->schedule(pkt.req->responseTime - pkt.req->requestTime);
203       completionEvent == NULL;
204   } else
205       panic("Unknown memory command state.");
206  */
207}
208
209DmaDevice::~DmaDevice()
210{
211    if (dmaPort)
212        delete dmaPort;
213}
214
215
216