2 * Copyright (c) 2006 The Regents of The University of Michigan
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.
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.
34 * Declaration of a simple bus bridge object with no buffering
37 #ifndef __MEM_BRIDGE_HH__
38 #define __MEM_BRIDGE_HH__
45 #include "mem/mem_object.hh"
46 #include "mem/packet.hh"
47 #include "mem/port.hh"
48 #include "sim/eventq.hh"
50 class Bridge : public MemObject
53 /** Declaration of the buses port type, one will be instantiated for each
54 of the interfaces connecting to the bus. */
55 class BridgePort : public Port
57 /** A pointer to the bridge to which this port belongs. */
61 * Pointer to the port on the other side of the bridge
62 * (connected to the other bus).
64 BridgePort *otherPort;
66 /** Minimum delay though this bridge. */
69 /** Min delay to respond to a nack. */
74 class PacketBuffer : public Packet::SenderState {
79 Packet::SenderState *origSenderState;
83 bool partialWriteFixed;
86 PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
87 : ready(t), pkt(_pkt),
88 origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
89 expectResponse(_pkt->needsResponse() && !nack),
90 partialWriteFixed(false)
93 if (!pkt->isResponse() && !nack && pkt->result != Packet::Nacked)
94 pkt->senderState = this;
97 void fixResponse(PacketPtr pkt)
99 assert(pkt->senderState == this);
100 pkt->setDest(origSrc);
101 pkt->senderState = origSenderState;
102 if (partialWriteFixed)
106 void partialWriteFix(Port *port)
108 assert(!partialWriteFixed);
109 assert(expectResponse);
111 Addr pbs = port->peerBlockSize();
112 Addr blockAddr = pkt->getAddr() & ~(pbs-1);
113 partialWriteFixed = true;
116 data = new uint8_t[pbs];
117 RequestPtr funcReq = new Request(blockAddr, 4, 0);
118 PacketPtr funcPkt = new Packet(funcReq, MemCmd::ReadReq,
120 for (int x = 0; x < pbs; x+=4) {
121 funcReq->setPhys(blockAddr + x, 4, 0);
122 funcPkt->reinitFromRequest();
123 funcPkt->dataStatic(data + x);
124 port->sendFunctional(funcPkt);
125 assert(funcPkt->result == Packet::Success);
131 memcpy(data + oldPkt->getOffset(pbs), pkt->getPtr<uint8_t>(),
133 pkt = new Packet(oldPkt->req, MemCmd::WriteInvalidateReq,
134 Packet::Broadcast, pbs);
135 pkt->dataDynamicArray(data);
136 pkt->senderState = oldPkt->senderState;
139 void undoPartialWriteFix()
141 if (!partialWriteFixed)
145 partialWriteFixed = false;
151 * Outbound packet queue. Packets are held in this queue for a
152 * specified delay to model the processing delay of the
155 std::list<PacketBuffer*> sendQueue;
157 int outstandingResponses;
160 /** If we're waiting for a retry to happen.*/
163 /** Max queue size for outbound packets */
166 /** Max queue size for reserved responses. */
170 * Is this side blocked from accepting outbound packets?
172 bool respQueueFull();
175 void queueForSendTiming(PacketPtr pkt);
177 void finishSend(PacketBuffer *buf);
179 void nackRequest(PacketPtr pkt);
182 * Handle send event, scheduled when the packet at the head of
183 * the outbound queue is ready to transmit (for timing
188 class SendEvent : public Event
193 SendEvent(BridgePort *p)
194 : Event(&mainEventQueue), port(p) {}
196 virtual void process() { port->trySend(); }
198 virtual const char *description() { return "bridge send event"; }
204 /** Constructor for the BusPort.*/
205 BridgePort(const std::string &_name, Bridge *_bridge,
206 BridgePort *_otherPort, int _delay, int _nack_delay,
207 int _req_limit, int _resp_limit, bool fix_partial_write);
211 /** When receiving a timing request from the peer port,
212 pass it to the bridge. */
213 virtual bool recvTiming(PacketPtr pkt);
215 /** When receiving a retry request from the peer port,
216 pass it to the bridge. */
217 virtual void recvRetry();
219 /** When receiving a Atomic requestfrom the peer port,
220 pass it to the bridge. */
221 virtual Tick recvAtomic(PacketPtr pkt);
223 /** When receiving a Functional request from the peer port,
224 pass it to the bridge. */
225 virtual void recvFunctional(PacketPtr pkt);
227 /** When receiving a status changefrom the peer port,
228 pass it to the bridge. */
229 virtual void recvStatusChange(Status status);
231 /** When receiving a address range request the peer port,
232 pass it to the bridge. */
233 virtual void getDeviceAddressRanges(AddrRangeList &resp,
234 AddrRangeList &snoop);
237 BridgePort portA, portB;
239 /** If this bridge should acknowledge writes. */
253 bool fix_partial_write_a;
254 bool fix_partial_write_b;
261 const Params *params() const { return _params; }
263 /** A function used to return the port associated with this bus object. */
264 virtual Port *getPort(const std::string &if_name, int idx = -1);
271 #endif //__MEM_BUS_HH__