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 class PacketBuffer : public Packet::SenderState {
74 Packet::SenderState *origSenderState;
78 PacketBuffer(PacketPtr _pkt, Tick t)
79 : ready(t), pkt(_pkt),
80 origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
81 expectResponse(_pkt->needsResponse())
83 if (!pkt->isResponse())
84 pkt->senderState = this;
87 void fixResponse(PacketPtr pkt)
89 assert(pkt->senderState == this);
90 pkt->setDest(origSrc);
91 pkt->senderState = origSenderState;
96 * Outbound packet queue. Packets are held in this queue for a
97 * specified delay to model the processing delay of the
100 std::list<PacketBuffer*> sendQueue;
102 int outstandingResponses;
104 /** Max queue size for outbound packets */
108 * Is this side blocked from accepting outbound packets?
110 bool queueFull() { return (sendQueue.size() == queueLimit); }
112 bool queueForSendTiming(PacketPtr pkt);
114 void finishSend(PacketBuffer *buf);
117 * Handle send event, scheduled when the packet at the head of
118 * the outbound queue is ready to transmit (for timing
123 class SendEvent : public Event
128 SendEvent(BridgePort *p)
129 : Event(&mainEventQueue), port(p) {}
131 virtual void process() { port->trySend(); }
133 virtual const char *description() { return "bridge send event"; }
140 /** Constructor for the BusPort.*/
141 BridgePort(const std::string &_name,
142 Bridge *_bridge, BridgePort *_otherPort,
143 int _delay, int _queueLimit);
147 /** When receiving a timing request from the peer port,
148 pass it to the bridge. */
149 virtual bool recvTiming(PacketPtr pkt);
151 /** When receiving a retry request from the peer port,
152 pass it to the bridge. */
153 virtual void recvRetry();
155 /** When receiving a Atomic requestfrom the peer port,
156 pass it to the bridge. */
157 virtual Tick recvAtomic(PacketPtr pkt);
159 /** When receiving a Functional request from the peer port,
160 pass it to the bridge. */
161 virtual void recvFunctional(PacketPtr pkt);
163 /** When receiving a status changefrom the peer port,
164 pass it to the bridge. */
165 virtual void recvStatusChange(Status status);
167 /** When receiving a address range request the peer port,
168 pass it to the bridge. */
169 virtual void getDeviceAddressRanges(AddrRangeList &resp,
170 AddrRangeList &snoop);
173 BridgePort portA, portB;
175 /** If this bridge should acknowledge writes. */
180 /** A function used to return the port associated with this bus object. */
181 virtual Port *getPort(const std::string &if_name, int idx = -1);
185 Bridge(const std::string &n, int qsa, int qsb, Tick _delay, int write_ack);
188 #endif //__MEM_BUS_HH__