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