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