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