bridge.hh (5012:c0a28154d002) bridge.hh (5336:c7e21f4e5a2e)
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Ali Saidi
29 * Steve Reinhardt
30 */
31
32/**
33 * @file
34 * Declaration of a simple bus bridge object with no buffering
35 */
36
37#ifndef __MEM_BRIDGE_HH__
38#define __MEM_BRIDGE_HH__
39
40#include <string>
41#include <list>
42#include <inttypes.h>
43#include <queue>
44
45#include "mem/mem_object.hh"
46#include "mem/packet.hh"
47#include "mem/port.hh"
48#include "params/Bridge.hh"
49#include "sim/eventq.hh"
50
51class Bridge : public MemObject
52{
53 protected:
54 /** Declaration of the buses port type, one will be instantiated for each
55 of the interfaces connecting to the bus. */
56 class BridgePort : public Port
57 {
58 /** A pointer to the bridge to which this port belongs. */
59 Bridge *bridge;
60
61 /**
62 * Pointer to the port on the other side of the bridge
63 * (connected to the other bus).
64 */
65 BridgePort *otherPort;
66
67 /** Minimum delay though this bridge. */
68 Tick delay;
69
70 /** Min delay to respond to a nack. */
71 Tick nackDelay;
72
73 /** Pass ranges from one side of the bridge to the other? */
74 std::vector<Range<Addr> > filterRanges;
75
76 class PacketBuffer : public Packet::SenderState {
77
78 public:
79 Tick ready;
80 PacketPtr pkt;
81 bool nackedHere;
82 Packet::SenderState *origSenderState;
83 short origSrc;
84 bool expectResponse;
85
86 PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
87 : ready(t), pkt(_pkt), nackedHere(nack),
88 origSenderState(_pkt->senderState),
89 origSrc(nack ? _pkt->getDest() : _pkt->getSrc() ),
90 expectResponse(_pkt->needsResponse() && !nack)
91
92 {
93 if (!pkt->isResponse() && !nack)
94 pkt->senderState = this;
95 }
96
97 void fixResponse(PacketPtr pkt)
98 {
99 assert(pkt->senderState == this);
100 pkt->setDest(origSrc);
101 pkt->senderState = origSenderState;
102 }
103 };
104
105 /**
106 * Outbound packet queue. Packets are held in this queue for a
107 * specified delay to model the processing delay of the
108 * bridge.
109 */
110 std::list<PacketBuffer*> sendQueue;
111
112 int outstandingResponses;
113 int queuedRequests;
114
115 /** If we're waiting for a retry to happen.*/
116 bool inRetry;
117
118 /** Max queue size for outbound packets */
119 int reqQueueLimit;
120
121 /** Max queue size for reserved responses. */
122 int respQueueLimit;
123
124 /**
125 * Is this side blocked from accepting outbound packets?
126 */
127 bool respQueueFull();
128 bool reqQueueFull();
129
130 void queueForSendTiming(PacketPtr pkt);
131
132 void finishSend(PacketBuffer *buf);
133
134 void nackRequest(PacketPtr pkt);
135
136 /**
137 * Handle send event, scheduled when the packet at the head of
138 * the outbound queue is ready to transmit (for timing
139 * accesses only).
140 */
141 void trySend();
142
143 class SendEvent : public Event
144 {
145 BridgePort *port;
146
147 public:
148 SendEvent(BridgePort *p)
149 : Event(&mainEventQueue), port(p) {}
150
151 virtual void process() { port->trySend(); }
152
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Ali Saidi
29 * Steve Reinhardt
30 */
31
32/**
33 * @file
34 * Declaration of a simple bus bridge object with no buffering
35 */
36
37#ifndef __MEM_BRIDGE_HH__
38#define __MEM_BRIDGE_HH__
39
40#include <string>
41#include <list>
42#include <inttypes.h>
43#include <queue>
44
45#include "mem/mem_object.hh"
46#include "mem/packet.hh"
47#include "mem/port.hh"
48#include "params/Bridge.hh"
49#include "sim/eventq.hh"
50
51class Bridge : public MemObject
52{
53 protected:
54 /** Declaration of the buses port type, one will be instantiated for each
55 of the interfaces connecting to the bus. */
56 class BridgePort : public Port
57 {
58 /** A pointer to the bridge to which this port belongs. */
59 Bridge *bridge;
60
61 /**
62 * Pointer to the port on the other side of the bridge
63 * (connected to the other bus).
64 */
65 BridgePort *otherPort;
66
67 /** Minimum delay though this bridge. */
68 Tick delay;
69
70 /** Min delay to respond to a nack. */
71 Tick nackDelay;
72
73 /** Pass ranges from one side of the bridge to the other? */
74 std::vector<Range<Addr> > filterRanges;
75
76 class PacketBuffer : public Packet::SenderState {
77
78 public:
79 Tick ready;
80 PacketPtr pkt;
81 bool nackedHere;
82 Packet::SenderState *origSenderState;
83 short origSrc;
84 bool expectResponse;
85
86 PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
87 : ready(t), pkt(_pkt), nackedHere(nack),
88 origSenderState(_pkt->senderState),
89 origSrc(nack ? _pkt->getDest() : _pkt->getSrc() ),
90 expectResponse(_pkt->needsResponse() && !nack)
91
92 {
93 if (!pkt->isResponse() && !nack)
94 pkt->senderState = this;
95 }
96
97 void fixResponse(PacketPtr pkt)
98 {
99 assert(pkt->senderState == this);
100 pkt->setDest(origSrc);
101 pkt->senderState = origSenderState;
102 }
103 };
104
105 /**
106 * Outbound packet queue. Packets are held in this queue for a
107 * specified delay to model the processing delay of the
108 * bridge.
109 */
110 std::list<PacketBuffer*> sendQueue;
111
112 int outstandingResponses;
113 int queuedRequests;
114
115 /** If we're waiting for a retry to happen.*/
116 bool inRetry;
117
118 /** Max queue size for outbound packets */
119 int reqQueueLimit;
120
121 /** Max queue size for reserved responses. */
122 int respQueueLimit;
123
124 /**
125 * Is this side blocked from accepting outbound packets?
126 */
127 bool respQueueFull();
128 bool reqQueueFull();
129
130 void queueForSendTiming(PacketPtr pkt);
131
132 void finishSend(PacketBuffer *buf);
133
134 void nackRequest(PacketPtr pkt);
135
136 /**
137 * Handle send event, scheduled when the packet at the head of
138 * the outbound queue is ready to transmit (for timing
139 * accesses only).
140 */
141 void trySend();
142
143 class SendEvent : public Event
144 {
145 BridgePort *port;
146
147 public:
148 SendEvent(BridgePort *p)
149 : Event(&mainEventQueue), port(p) {}
150
151 virtual void process() { port->trySend(); }
152
153 virtual const char *description() { return "bridge send"; }
153 virtual const char *description() const { return "bridge send"; }
154 };
155
156 SendEvent sendEvent;
157
158 public:
159 /** Constructor for the BusPort.*/
160 BridgePort(const std::string &_name, Bridge *_bridge,
161 BridgePort *_otherPort, int _delay, int _nack_delay,
162 int _req_limit, int _resp_limit,
163 std::vector<Range<Addr> > filter_ranges);
164
165 protected:
166
167 /** When receiving a timing request from the peer port,
168 pass it to the bridge. */
169 virtual bool recvTiming(PacketPtr pkt);
170
171 /** When receiving a retry request from the peer port,
172 pass it to the bridge. */
173 virtual void recvRetry();
174
175 /** When receiving a Atomic requestfrom the peer port,
176 pass it to the bridge. */
177 virtual Tick recvAtomic(PacketPtr pkt);
178
179 /** When receiving a Functional request from the peer port,
180 pass it to the bridge. */
181 virtual void recvFunctional(PacketPtr pkt);
182
183 /** When receiving a status changefrom the peer port,
184 pass it to the bridge. */
185 virtual void recvStatusChange(Status status);
186
187 /** When receiving a address range request the peer port,
188 pass it to the bridge. */
189 virtual void getDeviceAddressRanges(AddrRangeList &resp,
190 bool &snoop);
191 };
192
193 BridgePort portA, portB;
194
195 /** If this bridge should acknowledge writes. */
196 bool ackWrites;
197
198 public:
199 typedef BridgeParams Params;
200
201 protected:
202 Params *_params;
203
204 public:
205 const Params *params() const { return _params; }
206
207 /** A function used to return the port associated with this bus object. */
208 virtual Port *getPort(const std::string &if_name, int idx = -1);
209
210 virtual void init();
211
212 Bridge(Params *p);
213};
214
215#endif //__MEM_BUS_HH__
154 };
155
156 SendEvent sendEvent;
157
158 public:
159 /** Constructor for the BusPort.*/
160 BridgePort(const std::string &_name, Bridge *_bridge,
161 BridgePort *_otherPort, int _delay, int _nack_delay,
162 int _req_limit, int _resp_limit,
163 std::vector<Range<Addr> > filter_ranges);
164
165 protected:
166
167 /** When receiving a timing request from the peer port,
168 pass it to the bridge. */
169 virtual bool recvTiming(PacketPtr pkt);
170
171 /** When receiving a retry request from the peer port,
172 pass it to the bridge. */
173 virtual void recvRetry();
174
175 /** When receiving a Atomic requestfrom the peer port,
176 pass it to the bridge. */
177 virtual Tick recvAtomic(PacketPtr pkt);
178
179 /** When receiving a Functional request from the peer port,
180 pass it to the bridge. */
181 virtual void recvFunctional(PacketPtr pkt);
182
183 /** When receiving a status changefrom the peer port,
184 pass it to the bridge. */
185 virtual void recvStatusChange(Status status);
186
187 /** When receiving a address range request the peer port,
188 pass it to the bridge. */
189 virtual void getDeviceAddressRanges(AddrRangeList &resp,
190 bool &snoop);
191 };
192
193 BridgePort portA, portB;
194
195 /** If this bridge should acknowledge writes. */
196 bool ackWrites;
197
198 public:
199 typedef BridgeParams Params;
200
201 protected:
202 Params *_params;
203
204 public:
205 const Params *params() const { return _params; }
206
207 /** A function used to return the port associated with this bus object. */
208 virtual Port *getPort(const std::string &if_name, int idx = -1);
209
210 virtual void init();
211
212 Bridge(Params *p);
213};
214
215#endif //__MEM_BUS_HH__