io_device.cc (2641:6d9d837e2032) io_device.cc (2657:b119b774656b)
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
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 "base/trace.hh"
29#include "dev/io_device.hh"
30#include "sim/builder.hh"
31
32
33PioPort::PioPort(PioDevice *dev, Platform *p)
34 : Port(dev->name() + "-pioport"), 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
30#include "dev/io_device.hh"
31#include "sim/builder.hh"
32
33
34PioPort::PioPort(PioDevice *dev, Platform *p)
35 : Port(dev->name() + "-pioport"), device(dev), platform(p)
36{ }
37
38
39Tick
40PioPort::recvAtomic(Packet *pkt)
41{
42 return device->recvAtomic(pkt);
43}
44
45void
46PioPort::recvFunctional(Packet *pkt)
47{
48 device->recvAtomic(pkt);
49}
50
51void
52PioPort::getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
53{
54 snoop.clear();
55 device->addressRanges(resp);
56}
57
58
58Packet *
59void
59PioPort::recvRetry()
60{
61 Packet* pkt = transmitList.front();
60PioPort::recvRetry()
61{
62 Packet* pkt = transmitList.front();
62 transmitList.pop_front();
63 return pkt;
63 if (Port::sendTiming(pkt)) {
64 transmitList.pop_front();
65 }
64}
65
66
67void
68PioPort::SendEvent::process()
69{
70 if (port->Port::sendTiming(packet))
71 return;
72
73 port->transmitList.push_back(packet);
74}
75
76
66}
67
68
69void
70PioPort::SendEvent::process()
71{
72 if (port->Port::sendTiming(packet))
73 return;
74
75 port->transmitList.push_back(packet);
76}
77
78
79
77bool
78PioPort::recvTiming(Packet *pkt)
79{
80 device->recvAtomic(pkt);
81 // turn packet around to go back to requester
82 pkt->makeTimingResponse();
83 sendTiming(pkt, pkt->time - pkt->req->getTime());
84 return true;
85}
86
87PioDevice::~PioDevice()
88{
89 if (pioPort)
90 delete pioPort;
91}
92
93void
94PioDevice::init()
95{
96 if (!pioPort)
97 panic("Pio port not connected to anything!");
98 pioPort->sendStatusChange(Port::RangeChange);
99}
100
101void
102BasicPioDevice::addressRanges(AddrRangeList &range_list)
103{
104 assert(pioSize != 0);
105 range_list.clear();
106 range_list.push_back(RangeSize(pioAddr, pioSize));
107}
108
109
110DmaPort::DmaPort(DmaDevice *dev, Platform *p)
111 : Port(dev->name() + "-dmaport"), device(dev), platform(p), pendingCount(0)
112{ }
113
114bool
115DmaPort::recvTiming(Packet *pkt)
116{
117 if (pkt->senderState) {
118 DmaReqState *state;
80bool
81PioPort::recvTiming(Packet *pkt)
82{
83 device->recvAtomic(pkt);
84 // turn packet around to go back to requester
85 pkt->makeTimingResponse();
86 sendTiming(pkt, pkt->time - pkt->req->getTime());
87 return true;
88}
89
90PioDevice::~PioDevice()
91{
92 if (pioPort)
93 delete pioPort;
94}
95
96void
97PioDevice::init()
98{
99 if (!pioPort)
100 panic("Pio port not connected to anything!");
101 pioPort->sendStatusChange(Port::RangeChange);
102}
103
104void
105BasicPioDevice::addressRanges(AddrRangeList &range_list)
106{
107 assert(pioSize != 0);
108 range_list.clear();
109 range_list.push_back(RangeSize(pioAddr, pioSize));
110}
111
112
113DmaPort::DmaPort(DmaDevice *dev, Platform *p)
114 : Port(dev->name() + "-dmaport"), device(dev), platform(p), pendingCount(0)
115{ }
116
117bool
118DmaPort::recvTiming(Packet *pkt)
119{
120 if (pkt->senderState) {
121 DmaReqState *state;
122 DPRINTF(DMA, "Received response Packet %#x with senderState: %#x\n",
123 pkt, pkt->senderState);
119 state = dynamic_cast<DmaReqState*>(pkt->senderState);
124 state = dynamic_cast<DmaReqState*>(pkt->senderState);
120 state->completionEvent->schedule(pkt->time - pkt->req->getTime());
125 assert(state);
126 state->completionEvent->process();
121 delete pkt->req;
122 delete pkt;
123 } else {
127 delete pkt->req;
128 delete pkt;
129 } else {
130 DPRINTF(DMA, "Received response Packet %#x with no senderState\n", pkt);
124 delete pkt->req;
125 delete pkt;
126 }
127
131 delete pkt->req;
132 delete pkt;
133 }
134
128 return Packet::Success;
135 return true;
129}
130
131DmaDevice::DmaDevice(Params *p)
132 : PioDevice(p), dmaPort(NULL)
133{ }
134
135void
136}
137
138DmaDevice::DmaDevice(Params *p)
139 : PioDevice(p), dmaPort(NULL)
140{ }
141
142void
136DmaPort::SendEvent::process()
137{
138 if (port->Port::sendTiming(packet))
139 return;
140
141 port->transmitList.push_back(packet);
142}
143
144Packet *
145DmaPort::recvRetry()
146{
147 Packet* pkt = transmitList.front();
143DmaPort::recvRetry()
144{
145 Packet* pkt = transmitList.front();
148 transmitList.pop_front();
149 return pkt;
146 DPRINTF(DMA, "Retry on Packet %#x with senderState: %#x\n",
147 pkt, pkt->senderState);
148 if (sendTiming(pkt)) {
149 DPRINTF(DMA, "-- Done\n");
150 transmitList.pop_front();
151 pendingCount--;
152 assert(pendingCount >= 0);
153 } else {
154 DPRINTF(DMA, "-- Failed, queued\n");
155 }
150}
151
152
153void
154DmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
155 uint8_t *data)
156{
157 assert(event);
158
159 int prevSize = 0;
160
161 for (ChunkGenerator gen(addr, size, peerBlockSize());
162 !gen.done(); gen.next()) {
163 Request *req = new Request(false);
164 req->setPaddr(gen.addr());
165 req->setSize(gen.size());
166 req->setTime(curTick);
167 Packet *pkt = new Packet(req, cmd, Packet::Broadcast);
168
169 // Increment the data pointer on a write
170 if (data)
171 pkt->dataStatic(data + prevSize) ;
172
173 prevSize += gen.size();
174
175 // Set the last bit of the dma as the final packet for this dma
176 // and set it's completion event.
177 if (prevSize == size) {
178 pkt->senderState = new DmaReqState(event, true);
179 }
180 assert(pendingCount >= 0);
181 pendingCount++;
182 sendDma(pkt);
183 }
184}
185
186
187void
188DmaPort::sendDma(Packet *pkt)
189{
190 // some kind of selction between access methods
191 // more work is going to have to be done to make
192 // switching actually work
193 /* MemState state = device->platform->system->memState;
194
156}
157
158
159void
160DmaPort::dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
161 uint8_t *data)
162{
163 assert(event);
164
165 int prevSize = 0;
166
167 for (ChunkGenerator gen(addr, size, peerBlockSize());
168 !gen.done(); gen.next()) {
169 Request *req = new Request(false);
170 req->setPaddr(gen.addr());
171 req->setSize(gen.size());
172 req->setTime(curTick);
173 Packet *pkt = new Packet(req, cmd, Packet::Broadcast);
174
175 // Increment the data pointer on a write
176 if (data)
177 pkt->dataStatic(data + prevSize) ;
178
179 prevSize += gen.size();
180
181 // Set the last bit of the dma as the final packet for this dma
182 // and set it's completion event.
183 if (prevSize == size) {
184 pkt->senderState = new DmaReqState(event, true);
185 }
186 assert(pendingCount >= 0);
187 pendingCount++;
188 sendDma(pkt);
189 }
190}
191
192
193void
194DmaPort::sendDma(Packet *pkt)
195{
196 // some kind of selction between access methods
197 // more work is going to have to be done to make
198 // switching actually work
199 /* MemState state = device->platform->system->memState;
200
195 if (state == Timing) {
196 if (!sendTiming(pkt))
197 transmitList.push_back(&packet);
198 } else if (state == Atomic) {*/
201 if (state == Timing) { */
202 DPRINTF(DMA, "Attempting to send Packet %#x with senderState: %#x\n",
203 pkt, pkt->senderState);
204 if (!sendTiming(pkt)) {
205 transmitList.push_back(pkt);
206 DPRINTF(DMA, "-- Failed: queued\n");
207 } else {
208 DPRINTF(DMA, "-- Done\n");
209 pendingCount--;
210 assert(pendingCount >= 0);
211 }
212 /* } else if (state == Atomic) {
199 sendAtomic(pkt);
200 if (pkt->senderState) {
201 DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState);
213 sendAtomic(pkt);
214 if (pkt->senderState) {
215 DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState);
216 assert(state);
202 state->completionEvent->schedule(curTick + (pkt->time - pkt->req->getTime()) +1);
203 }
204 pendingCount--;
205 assert(pendingCount >= 0);
206 delete pkt->req;
207 delete pkt;
208
217 state->completionEvent->schedule(curTick + (pkt->time - pkt->req->getTime()) +1);
218 }
219 pendingCount--;
220 assert(pendingCount >= 0);
221 delete pkt->req;
222 delete pkt;
223
209/* } else if (state == Functional) {
224 } else if (state == Functional) {
210 sendFunctional(pkt);
211 // Is this correct???
212 completionEvent->schedule(pkt->req->responseTime - pkt->req->requestTime);
213 completionEvent == NULL;
214 } else
215 panic("Unknown memory command state.");
216 */
217}
218
219DmaDevice::~DmaDevice()
220{
221 if (dmaPort)
222 delete dmaPort;
223}
224
225
225 sendFunctional(pkt);
226 // Is this correct???
227 completionEvent->schedule(pkt->req->responseTime - pkt->req->requestTime);
228 completionEvent == NULL;
229 } else
230 panic("Unknown memory command state.");
231 */
232}
233
234DmaDevice::~DmaDevice()
235{
236 if (dmaPort)
237 delete dmaPort;
238}
239
240