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.
34 * @file Definition of a simple bus bridge without buffering.
39 #include "base/trace.hh"
40 #include "mem/bridge.hh"
41 #include "sim/builder.hh"
43 Bridge::BridgePort::BridgePort(const std::string
&_name
,
44 Bridge
*_bridge
, BridgePort
*_otherPort
,
45 int _delay
, int _queueLimit
)
46 : Port(_name
), bridge(_bridge
), otherPort(_otherPort
),
47 delay(_delay
), outstandingResponses(0),
48 queueLimit(_queueLimit
), sendEvent(this)
52 Bridge::Bridge(const std::string
&n
, int qsa
, int qsb
,
53 Tick _delay
, int write_ack
)
55 portA(n
+ "-portA", this, &portB
, _delay
, qsa
),
56 portB(n
+ "-portB", this, &portA
, _delay
, qsa
),
62 Bridge::getPort(const std::string
&if_name
, int idx
)
66 if (if_name
== "side_a")
68 else if (if_name
== "side_b")
73 if (port
->getPeer() != NULL
)
74 panic("bridge side %s already connected to.", if_name
);
82 // Make sure that both sides are connected to.
83 if (portA
.getPeer() == NULL
|| portB
.getPeer() == NULL
)
84 panic("Both ports of bus bridge are not connected to a bus.\n");
88 /** Function called by the port when the bus is receiving a Timing
91 Bridge::BridgePort::recvTiming(Packet
*pkt
)
93 DPRINTF(BusBridge
, "recvTiming: src %d dest %d addr 0x%x\n",
94 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr());
96 return otherPort
->queueForSendTiming(pkt
);
101 Bridge::BridgePort::queueForSendTiming(Packet
*pkt
)
106 if (pkt
->isResponse()) {
107 // This is a response for a request we forwarded earlier. The
108 // corresponding PacketBuffer should be stored in the packet's
109 // senderState field.
110 PacketBuffer
*buf
= dynamic_cast<PacketBuffer
*>(pkt
->senderState
);
112 // set up new packet dest & senderState based on values saved
113 // from original request
114 buf
->fixResponse(pkt
);
115 DPRINTF(BusBridge
, "restoring sender state: %#X, from packet buffer: %#X\n",
116 pkt
->senderState
, buf
);
117 DPRINTF(BusBridge
, " is response, new dest %d\n", pkt
->getDest());
121 Tick readyTime
= curTick
+ delay
;
122 PacketBuffer
*buf
= new PacketBuffer(pkt
, readyTime
);
123 DPRINTF(BusBridge
, "old sender state: %#X, new sender state: %#X\n",
124 buf
->origSenderState
, buf
);
126 // If we're about to put this packet at the head of the queue, we
127 // need to schedule an event to do the transmit. Otherwise there
128 // should already be an event scheduled for sending the head
130 if (sendQueue
.empty()) {
131 sendEvent
.schedule(readyTime
);
134 sendQueue
.push_back(buf
);
140 Bridge::BridgePort::trySend()
142 assert(!sendQueue
.empty());
144 bool was_full
= queueFull();
146 PacketBuffer
*buf
= sendQueue
.front();
148 assert(buf
->ready
<= curTick
);
150 Packet
*pkt
= buf
->pkt
;
152 DPRINTF(BusBridge
, "trySend: origSrc %d dest %d addr 0x%x\n",
153 buf
->origSrc
, pkt
->getDest(), pkt
->getAddr());
155 if (sendTiming(pkt
)) {
157 sendQueue
.pop_front();
158 buf
->pkt
= NULL
; // we no longer own packet, so it's not safe to look at it
160 if (buf
->expectResponse
) {
161 // Must wait for response. We just need to count outstanding
162 // responses (in case we want to cap them); PacketBuffer
163 // pointer will be recovered on response.
164 ++outstandingResponses
;
165 DPRINTF(BusBridge
, " successful: awaiting response (%d)\n",
166 outstandingResponses
);
168 // no response expected... deallocate packet buffer now.
169 DPRINTF(BusBridge
, " successful: no response expected\n");
173 // If there are more packets to send, schedule event to try again.
174 if (!sendQueue
.empty()) {
175 buf
= sendQueue
.front();
176 sendEvent
.schedule(std::max(buf
->ready
, curTick
+ 1));
178 // Let things start sending again
180 DPRINTF(BusBridge
, "Queue was full, sending retry\n");
181 otherPort
->sendRetry();
185 DPRINTF(BusBridge
, " unsuccessful\n");
191 Bridge::BridgePort::recvRetry()
196 /** Function called by the port when the bus is receiving a Atomic
199 Bridge::BridgePort::recvAtomic(Packet
*pkt
)
201 return otherPort
->sendAtomic(pkt
) + delay
;
204 /** Function called by the port when the bus is receiving a Functional
207 Bridge::BridgePort::recvFunctional(Packet
*pkt
)
209 std::list
<PacketBuffer
*>::iterator i
;
210 bool pktContinue
= true;
212 for (i
= sendQueue
.begin(); i
!= sendQueue
.end(); ++i
) {
213 if (pkt
->intersect((*i
)->pkt
)) {
214 pktContinue
&= fixPacket(pkt
, (*i
)->pkt
);
219 otherPort
->sendFunctional(pkt
);
223 /** Function called by the port when the bus is receiving a status change.*/
225 Bridge::BridgePort::recvStatusChange(Port::Status status
)
227 otherPort
->sendStatusChange(status
);
231 Bridge::BridgePort::getDeviceAddressRanges(AddrRangeList
&resp
,
232 AddrRangeList
&snoop
)
234 otherPort
->getPeerAddressRanges(resp
, snoop
);
237 BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bridge
)
239 Param
<int> queue_size_a
;
240 Param
<int> queue_size_b
;
242 Param
<bool> write_ack
;
244 END_DECLARE_SIM_OBJECT_PARAMS(Bridge
)
246 BEGIN_INIT_SIM_OBJECT_PARAMS(Bridge
)
248 INIT_PARAM(queue_size_a
, "The size of the queue for data coming into side a"),
249 INIT_PARAM(queue_size_b
, "The size of the queue for data coming into side b"),
250 INIT_PARAM(delay
, "The miminum delay to cross this bridge"),
251 INIT_PARAM(write_ack
, "Acknowledge any writes that are received.")
253 END_INIT_SIM_OBJECT_PARAMS(Bridge
)
255 CREATE_SIM_OBJECT(Bridge
)
257 return new Bridge(getInstanceName(), queue_size_a
, queue_size_b
, delay
,
261 REGISTER_SIM_OBJECT("Bridge", Bridge
)