5b8b9164b314d58c19d938c4655054992a850cbd
3 * Copyright (c) 2006 The Regents of The University of Michigan
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * @file Definition of a simple bus bridge without buffering.
36 #include "base/trace.hh"
37 #include "mem/bridge.hh"
38 #include "sim/builder.hh"
40 Bridge::BridgePort::BridgePort(const std::string
&_name
,
41 Bridge
*_bridge
, BridgePort
*_otherPort
,
42 int _delay
, int _queueLimit
)
43 : Port(_name
), bridge(_bridge
), otherPort(_otherPort
),
44 delay(_delay
), outstandingResponses(0),
45 queueLimit(_queueLimit
), sendEvent(this)
49 Bridge::Bridge(const std::string
&n
, int qsa
, int qsb
,
50 Tick _delay
, int write_ack
)
52 portA(n
+ "-portA", this, &portB
, _delay
, qsa
),
53 portB(n
+ "-portB", this, &portA
, _delay
, qsa
),
59 Bridge::getPort(const std::string
&if_name
)
63 if (if_name
== "side_a")
65 else if (if_name
== "side_b")
70 if (port
->getPeer() != NULL
)
71 panic("bridge side %s already connected to.", if_name
);
79 // Make sure that both sides are connected to.
80 if (portA
.getPeer() == NULL
|| portB
.getPeer() == NULL
)
81 panic("Both ports of bus bridge are not connected to a bus.\n");
85 /** Function called by the port when the bus is receiving a Timing
88 Bridge::BridgePort::recvTiming(Packet
*pkt
)
90 DPRINTF(BusBridge
, "recvTiming: src %d dest %d addr 0x%x\n",
91 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr());
93 return otherPort
->queueForSendTiming(pkt
);
98 Bridge::BridgePort::queueForSendTiming(Packet
*pkt
)
103 if (pkt
->isResponse()) {
104 // This is a response for a request we forwarded earlier. The
105 // corresponding PacketBuffer should be stored in the packet's
106 // senderState field.
107 PacketBuffer
*buf
= dynamic_cast<PacketBuffer
*>(pkt
->senderState
);
109 // set up new packet dest & senderState based on values saved
110 // from original request
111 buf
->fixResponse(pkt
);
112 DPRINTF(BusBridge
, "restoring sender state: %#X, from packet buffer: %#X\n",
113 pkt
->senderState
, buf
);
114 DPRINTF(BusBridge
, " is response, new dest %d\n", pkt
->getDest());
118 Tick readyTime
= curTick
+ delay
;
119 PacketBuffer
*buf
= new PacketBuffer(pkt
, readyTime
);
120 DPRINTF(BusBridge
, "old sender state: %#X, new sender state: %#X\n",
121 buf
->origSenderState
, buf
);
123 // If we're about to put this packet at the head of the queue, we
124 // need to schedule an event to do the transmit. Otherwise there
125 // should already be an event scheduled for sending the head
127 if (sendQueue
.empty()) {
128 sendEvent
.schedule(readyTime
);
131 sendQueue
.push_back(buf
);
137 Bridge::BridgePort::trySend()
139 assert(!sendQueue
.empty());
141 bool was_full
= queueFull();
143 PacketBuffer
*buf
= sendQueue
.front();
145 assert(buf
->ready
<= curTick
);
147 Packet
*pkt
= buf
->pkt
;
149 DPRINTF(BusBridge
, "trySend: origSrc %d dest %d addr 0x%x\n",
150 buf
->origSrc
, pkt
->getDest(), pkt
->getAddr());
152 if (sendTiming(pkt
)) {
154 sendQueue
.pop_front();
155 buf
->pkt
= NULL
; // we no longer own packet, so it's not safe to look at it
157 if (buf
->expectResponse
) {
158 // Must wait for response. We just need to count outstanding
159 // responses (in case we want to cap them); PacketBuffer
160 // pointer will be recovered on response.
161 ++outstandingResponses
;
162 DPRINTF(BusBridge
, " successful: awaiting response (%d)\n",
163 outstandingResponses
);
165 // no response expected... deallocate packet buffer now.
166 DPRINTF(BusBridge
, " successful: no response expected\n");
170 // If there are more packets to send, schedule event to try again.
171 if (!sendQueue
.empty()) {
172 buf
= sendQueue
.front();
173 sendEvent
.schedule(std::max(buf
->ready
, curTick
+ 1));
175 // Let things start sending again
177 DPRINTF(BusBridge
, "Queue was full, sending retry\n");
178 otherPort
->sendRetry();
182 DPRINTF(BusBridge
, " unsuccessful\n");
188 Bridge::BridgePort::recvRetry()
193 /** Function called by the port when the bus is receiving a Atomic
196 Bridge::BridgePort::recvAtomic(Packet
*pkt
)
198 return otherPort
->sendAtomic(pkt
) + delay
;
201 /** Function called by the port when the bus is receiving a Functional
204 Bridge::BridgePort::recvFunctional(Packet
*pkt
)
206 std::list
<PacketBuffer
*>::iterator i
;
207 bool pktContinue
= true;
209 for (i
= sendQueue
.begin(); i
!= sendQueue
.end(); ++i
) {
210 if (pkt
->intersect((*i
)->pkt
)) {
211 pktContinue
&= fixPacket(pkt
, (*i
)->pkt
);
216 otherPort
->sendFunctional(pkt
);
220 /** Function called by the port when the bus is receiving a status change.*/
222 Bridge::BridgePort::recvStatusChange(Port::Status status
)
224 otherPort
->sendStatusChange(status
);
228 Bridge::BridgePort::getDeviceAddressRanges(AddrRangeList
&resp
,
229 AddrRangeList
&snoop
)
231 otherPort
->getPeerAddressRanges(resp
, snoop
);
234 BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bridge
)
236 Param
<int> queue_size_a
;
237 Param
<int> queue_size_b
;
239 Param
<bool> write_ack
;
241 END_DECLARE_SIM_OBJECT_PARAMS(Bridge
)
243 BEGIN_INIT_SIM_OBJECT_PARAMS(Bridge
)
245 INIT_PARAM(queue_size_a
, "The size of the queue for data coming into side a"),
246 INIT_PARAM(queue_size_b
, "The size of the queue for data coming into side b"),
247 INIT_PARAM(delay
, "The miminum delay to cross this bridge"),
248 INIT_PARAM(write_ack
, "Acknowledge any writes that are received.")
250 END_INIT_SIM_OBJECT_PARAMS(Bridge
)
252 CREATE_SIM_OBJECT(Bridge
)
254 return new Bridge(getInstanceName(), queue_size_a
, queue_size_b
, delay
,
258 REGISTER_SIM_OBJECT("Bridge", Bridge
)