io_device.cc revision 2640:266b80dd5eca
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    : Port(dev->name() + "-pioport"), 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    // turn packet around to go back to requester
82    pkt->dest = pkt->src;
83    sendTiming(pkt, pkt->time - pkt->req->getTime());
84    return Success;
85}
86
87PioDevice::~PioDevice()
88{
89    if (pioPort)
90        delete pioPort;
91}
92
93void
94PioDevice::init()
95{
96    if (!pioPort)
97        panic("Pio port not connected to anything!");
98    pioPort->sendStatusChange(Port::RangeChange);
99}
100
101void
102BasicPioDevice::addressRanges(AddrRangeList &range_list)
103{
104    assert(pioSize != 0);
105    range_list.clear();
106    range_list.push_back(RangeSize(pioAddr, pioSize));
107}
108
109
110DmaPort::DmaPort(DmaDevice *dev, Platform *p)
111    : Port(dev->name() + "-dmaport"), device(dev), platform(p), pendingCount(0)
112{ }
113
114bool
115DmaPort::recvTiming(Packet *pkt)
116{
117    if (pkt->senderState) {
118        DmaReqState *state;
119        state = (DmaReqState*)pkt->senderState;
120        state->completionEvent->schedule(pkt->time - pkt->req->getTime());
121        delete pkt->req;
122        delete pkt;
123    }  else {
124        delete pkt->req;
125        delete pkt;
126    }
127
128    return Success;
129}
130
131DmaDevice::DmaDevice(Params *p)
132    : PioDevice(p), dmaPort(NULL)
133{ }
134
135void
136DmaPort::SendEvent::process()
137{
138    if (port->Port::sendTiming(packet) == Success)
139        return;
140
141    port->transmitList.push_back(packet);
142}
143
144Packet *
145DmaPort::recvRetry()
146{
147    Packet* pkt = transmitList.front();
148    transmitList.pop_front();
149    return pkt;
150}
151void
152DmaPort::dmaAction(Command cmd, Addr addr, int size, Event *event,
153        uint8_t *data)
154{
155
156    assert(event);
157
158    int prevSize = 0;
159    Packet basePkt;
160    Request baseReq(false);
161
162    basePkt.flags = 0;
163    basePkt.coherence = NULL;
164    basePkt.senderState = NULL;
165    basePkt.dest = Packet::Broadcast;
166    basePkt.cmd = cmd;
167    basePkt.result = Unknown;
168    basePkt.req = NULL;
169//    baseReq.nicReq = true;
170    baseReq.setTime(curTick);
171
172    for (ChunkGenerator gen(addr, size, peerBlockSize());
173         !gen.done(); gen.next()) {
174            Packet *pkt = new Packet(basePkt);
175            Request *req = new Request(baseReq);
176            pkt->addr = gen.addr();
177            pkt->size = gen.size();
178            pkt->req = req;
179            pkt->req->setPaddr(pkt->addr);
180            pkt->req->setSize(pkt->size);
181            // Increment the data pointer on a write
182            if (data)
183                pkt->dataStatic(data + prevSize) ;
184            prevSize += pkt->size;
185            // Set the last bit of the dma as the final packet for this dma
186            // and set it's completion event.
187            if (prevSize == size) {
188                DmaReqState *state = new DmaReqState(event, true);
189
190                pkt->senderState = (void*)state;
191            }
192            assert(pendingCount >= 0);
193            pendingCount++;
194            sendDma(pkt);
195    }
196    // since this isn't getting used and we want a check to make sure that all
197    // packets had data in them at some point.
198    basePkt.dataStatic((uint8_t*)NULL);
199}
200
201
202void
203DmaPort::sendDma(Packet *pkt)
204{
205   // some kind of selction between access methods
206   // more work is going to have to be done to make
207   // switching actually work
208  /* MemState state = device->platform->system->memState;
209
210   if (state == Timing) {
211       if (sendTiming(pkt) == Failure)
212           transmitList.push_back(&packet);
213    } else if (state == Atomic) {*/
214       sendAtomic(pkt);
215       if (pkt->senderState) {
216           DmaReqState *state = (DmaReqState*)pkt->senderState;
217           state->completionEvent->schedule(curTick + (pkt->time - pkt->req->getTime()) +1);
218       }
219       pendingCount--;
220       assert(pendingCount >= 0);
221       delete pkt->req;
222       delete pkt;
223
224/*   } else if (state == Functional) {
225       sendFunctional(pkt);
226       // Is this correct???
227       completionEvent->schedule(pkt->req->responseTime - pkt->req->requestTime);
228       completionEvent == NULL;
229   } else
230       panic("Unknown memory command state.");
231  */
232}
233
234DmaDevice::~DmaDevice()
235{
236    if (dmaPort)
237        delete dmaPort;
238}
239
240
241