io_device.cc revision 2541
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
91PioDevice::init()
92{
93    if (!pioPort)
94        panic("Pio port not connected to anything!");
95    pioPort->sendStatusChange(Port::RangeChange);
96}
97
98void
99BasicPioDevice::addressRanges(AddrRangeList &range_list)
100{
101    assert(pioSize != 0);
102    range_list.clear();
103    range_list.push_back(RangeSize(pioAddr, pioSize));
104}
105
106
107DmaPort::DmaPort(DmaDevice *dev)
108        : device(dev)
109{ }
110
111bool
112DmaPort::recvTiming(Packet &pkt)
113{
114    completionEvent->schedule(curTick+1);
115    completionEvent = NULL;
116    return Success;
117}
118
119DmaDevice::DmaDevice(Params *p)
120    : PioDevice(p)
121{
122    dmaPort = new DmaPort(this);
123}
124
125void
126DmaPort::SendEvent::process()
127{
128    if (port->Port::sendTiming(packet) == Success)
129        return;
130
131    port->transmitList.push_back(&packet);
132}
133
134Packet *
135DmaPort::recvRetry()
136{
137    Packet* pkt = transmitList.front();
138    transmitList.pop_front();
139    return pkt;
140}
141void
142DmaPort::dmaAction(Command cmd, DmaPort port, Addr addr, int size,
143                     Event *event, uint8_t *data)
144{
145
146    assert(event);
147
148    int prevSize = 0;
149    Packet basePkt;
150    Request baseReq(false);
151
152    basePkt.flags = 0;
153    basePkt.coherence = NULL;
154    basePkt.senderState = NULL;
155    basePkt.src = 0;
156    basePkt.dest = 0;
157    basePkt.cmd = cmd;
158    basePkt.result = Unknown;
159    basePkt.req = NULL;
160//    baseReq.nicReq = true;
161    baseReq.setTime(curTick);
162
163    completionEvent = event;
164
165    for (ChunkGenerator gen(addr, size, peerBlockSize());
166         !gen.done(); gen.next()) {
167            Packet *pkt = new Packet(basePkt);
168            Request *req = new Request(baseReq);
169            pkt->addr = gen.addr();
170            pkt->size = gen.size();
171            pkt->req = req;
172            pkt->req->setPaddr(pkt->addr);
173            pkt->req->setSize(pkt->size);
174            // Increment the data pointer on a write
175            pkt->data = data ? data + prevSize : NULL ;
176            prevSize += pkt->size;
177
178            sendDma(*pkt);
179    }
180}
181
182
183void
184DmaPort::sendDma(Packet &pkt)
185{
186   // some kind of selction between access methods
187   // more work is going to have to be done to make
188   // switching actually work
189  /* MemState state = device->platform->system->memState;
190
191   if (state == Timing) {
192       if (sendTiming(pkt) == Failure)
193           transmitList.push_back(&packet);
194   } else if (state == Atomic) {*/
195       sendAtomic(pkt);
196       completionEvent->schedule(pkt.time - pkt.req->getTime());
197       completionEvent = NULL;
198/*   } else if (state == Functional) {
199       sendFunctional(pkt);
200       // Is this correct???
201       completionEvent->schedule(pkt.req->responseTime - pkt.req->requestTime);
202       completionEvent == NULL;
203   } else
204       panic("Unknown memory command state.");
205  */
206}
207
208DmaDevice::~DmaDevice()
209{
210    if (dmaPort)
211        delete dmaPort;
212}
213
214
215