io_device.cc revision 2626
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 2006 The Regents of The University of Michigan
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296154Snate@binkert.org#include "dev/io_device.hh"
306145Snate@binkert.org#include "sim/builder.hh"
316145Snate@binkert.org
326145Snate@binkert.org
337039Snate@binkert.orgPioPort::PioPort(PioDevice *dev, Platform *p)
347039Snate@binkert.org        : device(dev), platform(p)
357039Snate@binkert.org{ }
367039Snate@binkert.org
377039Snate@binkert.org
386145Snate@binkert.orgTick
396145Snate@binkert.orgPioPort::recvAtomic(Packet &pkt)
407039Snate@binkert.org{
417039Snate@binkert.org    return device->recvAtomic(pkt);
426145Snate@binkert.org}
437039Snate@binkert.org
447039Snate@binkert.orgvoid
457039Snate@binkert.orgPioPort::recvFunctional(Packet &pkt)
467039Snate@binkert.org{
477039Snate@binkert.org    device->recvAtomic(pkt);
487039Snate@binkert.org}
496145Snate@binkert.org
506145Snate@binkert.orgvoid
517039Snate@binkert.orgPioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
527039Snate@binkert.org{
536145Snate@binkert.org    snoop.clear();
547039Snate@binkert.org    device->addressRanges(resp);
557039Snate@binkert.org}
567039Snate@binkert.org
577039Snate@binkert.org
587039Snate@binkert.orgPacket *
597039Snate@binkert.orgPioPort::recvRetry()
607039Snate@binkert.org{
616145Snate@binkert.org    Packet* pkt = transmitList.front();
626145Snate@binkert.org    transmitList.pop_front();
637039Snate@binkert.org    return pkt;
647055Snate@binkert.org}
656145Snate@binkert.org
667039Snate@binkert.org
676145Snate@binkert.orgvoid
686145Snate@binkert.orgPioPort::SendEvent::process()
696145Snate@binkert.org{
706145Snate@binkert.org    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, Platform *p)
109        : device(dev), platform(p), pendingCount(0)
110{ }
111
112bool
113DmaPort::recvTiming(Packet &pkt)
114{
115    if (pkt.senderState) {
116        DmaReqState *state;
117        state = (DmaReqState*)pkt.senderState;
118        state->completionEvent->schedule(pkt.time - pkt.req->getTime());
119        delete pkt.req;
120        delete &pkt;
121    }  else {
122        delete pkt.req;
123        delete &pkt;
124    }
125
126    return Success;
127}
128
129DmaDevice::DmaDevice(Params *p)
130    : PioDevice(p), dmaPort(NULL)
131{ }
132
133void
134DmaPort::SendEvent::process()
135{
136    if (port->Port::sendTiming(packet) == Success)
137        return;
138
139    port->transmitList.push_back(&packet);
140}
141
142Packet *
143DmaPort::recvRetry()
144{
145    Packet* pkt = transmitList.front();
146    transmitList.pop_front();
147    return pkt;
148}
149void
150DmaPort::dmaAction(Command cmd, Addr addr, int size, Event *event,
151        uint8_t *data)
152{
153
154    assert(event);
155
156    int prevSize = 0;
157    Packet basePkt;
158    Request baseReq(false);
159
160    basePkt.flags = 0;
161    basePkt.coherence = NULL;
162    basePkt.senderState = NULL;
163    basePkt.dest = Packet::Broadcast;
164    basePkt.cmd = cmd;
165    basePkt.result = Unknown;
166    basePkt.req = NULL;
167//    baseReq.nicReq = true;
168    baseReq.setTime(curTick);
169
170    for (ChunkGenerator gen(addr, size, peerBlockSize());
171         !gen.done(); gen.next()) {
172            Packet *pkt = new Packet(basePkt);
173            Request *req = new Request(baseReq);
174            pkt->addr = gen.addr();
175            pkt->size = gen.size();
176            pkt->req = req;
177            pkt->req->setPaddr(pkt->addr);
178            pkt->req->setSize(pkt->size);
179            // Increment the data pointer on a write
180            if (data)
181                pkt->dataStatic(data + prevSize) ;
182            prevSize += pkt->size;
183            // Set the last bit of the dma as the final packet for this dma
184            // and set it's completion event.
185            if (prevSize == size) {
186                DmaReqState *state = new DmaReqState(event, true);
187
188                pkt->senderState = (void*)state;
189            }
190            assert(pendingCount >= 0);
191            pendingCount++;
192            sendDma(pkt);
193    }
194    // since this isn't getting used and we want a check to make sure that all
195    // packets had data in them at some point.
196    basePkt.dataStatic((uint8_t*)NULL);
197}
198
199
200void
201DmaPort::sendDma(Packet *pkt)
202{
203   // some kind of selction between access methods
204   // more work is going to have to be done to make
205   // switching actually work
206  /* MemState state = device->platform->system->memState;
207
208   if (state == Timing) {
209       if (sendTiming(pkt) == Failure)
210           transmitList.push_back(&packet);
211    } else if (state == Atomic) {*/
212       sendAtomic(*pkt);
213       if (pkt->senderState) {
214           DmaReqState *state = (DmaReqState*)pkt->senderState;
215           state->completionEvent->schedule(curTick + (pkt->time - pkt->req->getTime()) +1);
216       }
217       pendingCount--;
218       assert(pendingCount >= 0);
219       delete pkt->req;
220       delete pkt;
221
222/*   } else if (state == Functional) {
223       sendFunctional(pkt);
224       // Is this correct???
225       completionEvent->schedule(pkt.req->responseTime - pkt.req->requestTime);
226       completionEvent == NULL;
227   } else
228       panic("Unknown memory command state.");
229  */
230}
231
232DmaDevice::~DmaDevice()
233{
234    if (dmaPort)
235        delete dmaPort;
236}
237
238
239