9c14e7ee243acdd517e97ce2a3c19260ac366253
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.
35 * Definition of a simple bus bridge without buffering.
40 #include "base/trace.hh"
41 #include "mem/bridge.hh"
42 #include "sim/builder.hh"
44 Bridge::BridgePort::BridgePort(const std::string
&_name
,
45 Bridge
*_bridge
, BridgePort
*_otherPort
,
46 int _delay
, int _queueLimit
)
47 : Port(_name
), bridge(_bridge
), otherPort(_otherPort
),
48 delay(_delay
), outstandingResponses(0),
49 queueLimit(_queueLimit
), sendEvent(this)
53 Bridge::Bridge(const std::string
&n
, int qsa
, int qsb
,
54 Tick _delay
, int write_ack
)
56 portA(n
+ "-portA", this, &portB
, _delay
, qsa
),
57 portB(n
+ "-portB", this, &portA
, _delay
, qsa
),
63 Bridge::getPort(const std::string
&if_name
, int idx
)
67 if (if_name
== "side_a")
69 else if (if_name
== "side_b")
74 if (port
->getPeer() != NULL
)
75 panic("bridge side %s already connected to.", if_name
);
83 // Make sure that both sides are connected to.
84 if (portA
.getPeer() == NULL
|| portB
.getPeer() == NULL
)
85 panic("Both ports of bus bridge are not connected to a bus.\n");
89 /** Function called by the port when the bus is receiving a Timing
92 Bridge::BridgePort::recvTiming(Packet
*pkt
)
94 DPRINTF(BusBridge
, "recvTiming: src %d dest %d addr 0x%x\n",
95 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr());
97 return otherPort
->queueForSendTiming(pkt
);
102 Bridge::BridgePort::queueForSendTiming(Packet
*pkt
)
107 if (pkt
->isResponse()) {
108 // This is a response for a request we forwarded earlier. The
109 // corresponding PacketBuffer should be stored in the packet's
110 // senderState field.
111 PacketBuffer
*buf
= dynamic_cast<PacketBuffer
*>(pkt
->senderState
);
113 // set up new packet dest & senderState based on values saved
114 // from original request
115 buf
->fixResponse(pkt
);
116 DPRINTF(BusBridge
, "restoring sender state: %#X, from packet buffer: %#X\n",
117 pkt
->senderState
, buf
);
118 DPRINTF(BusBridge
, " is response, new dest %d\n", pkt
->getDest());
122 Tick readyTime
= curTick
+ delay
;
123 PacketBuffer
*buf
= new PacketBuffer(pkt
, readyTime
);
124 DPRINTF(BusBridge
, "old sender state: %#X, new sender state: %#X\n",
125 buf
->origSenderState
, buf
);
127 // If we're about to put this packet at the head of the queue, we
128 // need to schedule an event to do the transmit. Otherwise there
129 // should already be an event scheduled for sending the head
131 if (sendQueue
.empty()) {
132 sendEvent
.schedule(readyTime
);
135 sendQueue
.push_back(buf
);
141 Bridge::BridgePort::trySend()
143 assert(!sendQueue
.empty());
145 bool was_full
= queueFull();
147 PacketBuffer
*buf
= sendQueue
.front();
149 assert(buf
->ready
<= curTick
);
151 Packet
*pkt
= buf
->pkt
;
153 DPRINTF(BusBridge
, "trySend: origSrc %d dest %d addr 0x%x\n",
154 buf
->origSrc
, pkt
->getDest(), pkt
->getAddr());
156 if (sendTiming(pkt
)) {
158 sendQueue
.pop_front();
159 buf
->pkt
= NULL
; // we no longer own packet, so it's not safe to look at it
161 if (buf
->expectResponse
) {
162 // Must wait for response. We just need to count outstanding
163 // responses (in case we want to cap them); PacketBuffer
164 // pointer will be recovered on response.
165 ++outstandingResponses
;
166 DPRINTF(BusBridge
, " successful: awaiting response (%d)\n",
167 outstandingResponses
);
169 // no response expected... deallocate packet buffer now.
170 DPRINTF(BusBridge
, " successful: no response expected\n");
174 // If there are more packets to send, schedule event to try again.
175 if (!sendQueue
.empty()) {
176 buf
= sendQueue
.front();
177 sendEvent
.schedule(std::max(buf
->ready
, curTick
+ 1));
179 // Let things start sending again
181 DPRINTF(BusBridge
, "Queue was full, sending retry\n");
182 otherPort
->sendRetry();
186 DPRINTF(BusBridge
, " unsuccessful\n");
192 Bridge::BridgePort::recvRetry()
197 /** Function called by the port when the bus is receiving a Atomic
200 Bridge::BridgePort::recvAtomic(Packet
*pkt
)
202 return otherPort
->sendAtomic(pkt
) + delay
;
205 /** Function called by the port when the bus is receiving a Functional
208 Bridge::BridgePort::recvFunctional(Packet
*pkt
)
210 std::list
<PacketBuffer
*>::iterator i
;
211 bool pktContinue
= true;
213 for (i
= sendQueue
.begin(); i
!= sendQueue
.end(); ++i
) {
214 if (pkt
->intersect((*i
)->pkt
)) {
215 pktContinue
&= fixPacket(pkt
, (*i
)->pkt
);
220 otherPort
->sendFunctional(pkt
);
224 /** Function called by the port when the bus is receiving a status change.*/
226 Bridge::BridgePort::recvStatusChange(Port::Status status
)
228 otherPort
->sendStatusChange(status
);
232 Bridge::BridgePort::getDeviceAddressRanges(AddrRangeList
&resp
,
233 AddrRangeList
&snoop
)
235 otherPort
->getPeerAddressRanges(resp
, snoop
);
238 BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bridge
)
240 Param
<int> queue_size_a
;
241 Param
<int> queue_size_b
;
243 Param
<bool> write_ack
;
245 END_DECLARE_SIM_OBJECT_PARAMS(Bridge
)
247 BEGIN_INIT_SIM_OBJECT_PARAMS(Bridge
)
249 INIT_PARAM(queue_size_a
, "The size of the queue for data coming into side a"),
250 INIT_PARAM(queue_size_b
, "The size of the queue for data coming into side b"),
251 INIT_PARAM(delay
, "The miminum delay to cross this bridge"),
252 INIT_PARAM(write_ack
, "Acknowledge any writes that are received.")
254 END_INIT_SIM_OBJECT_PARAMS(Bridge
)
256 CREATE_SIM_OBJECT(Bridge
)
258 return new Bridge(getInstanceName(), queue_size_a
, queue_size_b
, delay
,
262 REGISTER_SIM_OBJECT("Bridge", Bridge
)