bridge.hh (9128:6921ec2e77c4) bridge.hh (9164:d112473185ea)
1/*
2 * Copyright (c) 2011-2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 38 unchanged lines hidden (view full) ---

47 * Declaration of a memory-mapped bus bridge that connects a master
48 * and a slave through a request and response queue.
49 */
50
51#ifndef __MEM_BRIDGE_HH__
52#define __MEM_BRIDGE_HH__
53
54#include <list>
1/*
2 * Copyright (c) 2011-2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 38 unchanged lines hidden (view full) ---

47 * Declaration of a memory-mapped bus bridge that connects a master
48 * and a slave through a request and response queue.
49 */
50
51#ifndef __MEM_BRIDGE_HH__
52#define __MEM_BRIDGE_HH__
53
54#include <list>
55#include <queue>
56#include <string>
57
58#include "base/types.hh"
59#include "mem/mem_object.hh"
55
56#include "base/types.hh"
57#include "mem/mem_object.hh"
60#include "mem/packet.hh"
61#include "mem/port.hh"
62#include "params/Bridge.hh"
58#include "params/Bridge.hh"
63#include "sim/eventq.hh"
64
65/**
66 * A bridge is used to interface two different busses (or in general a
67 * memory-mapped master and slave), with buffering for requests and
68 * responses. The bridge has a fixed delay for packets passing through
69 * it and responds to a fixed set of address ranges.
70 *
71 * The bridge comprises a slave port and a master port, that buffer
72 * outgoing responses and requests respectively. Buffer space is
73 * reserved when a request arrives, also reserving response space
59
60/**
61 * A bridge is used to interface two different busses (or in general a
62 * memory-mapped master and slave), with buffering for requests and
63 * responses. The bridge has a fixed delay for packets passing through
64 * it and responds to a fixed set of address ranges.
65 *
66 * The bridge comprises a slave port and a master port, that buffer
67 * outgoing responses and requests respectively. Buffer space is
68 * reserved when a request arrives, also reserving response space
74 * before forwarding the request. An incoming request is always
75 * accepted (recvTiming returns true), but is potentially NACKed if
76 * there is no request space or response space.
69 * before forwarding the request. If there is no space present, then
70 * the bridge will delay accepting the packet until space becomes
71 * available.
77 */
78class Bridge : public MemObject
79{
80 protected:
81
82 /**
83 * A bridge request state stores packets along with their sender
84 * state and original source. It has enough information to also

--- 16 unchanged lines hidden (view full) ---

101 {
102 assert(pkt->senderState == this);
103 pkt->setDest(origSrc);
104 pkt->senderState = origSenderState;
105 }
106 };
107
108 /**
72 */
73class Bridge : public MemObject
74{
75 protected:
76
77 /**
78 * A bridge request state stores packets along with their sender
79 * state and original source. It has enough information to also

--- 16 unchanged lines hidden (view full) ---

96 {
97 assert(pkt->senderState == this);
98 pkt->setDest(origSrc);
99 pkt->senderState = origSenderState;
100 }
101 };
102
103 /**
109 * A deferred request stores a packet along with its scheduled
110 * transmission time, and whether we can expect to see a response
111 * or not.
104 * A deferred packet stores a packet along with its scheduled
105 * transmission time
112 */
106 */
113 class DeferredRequest
107 class DeferredPacket
114 {
115
116 public:
117
108 {
109
110 public:
111
118 Tick ready;
112 Tick tick;
119 PacketPtr pkt;
113 PacketPtr pkt;
120 bool expectResponse;
121
114
122 DeferredRequest(PacketPtr _pkt, Tick t)
123 : ready(t), pkt(_pkt), expectResponse(_pkt->needsResponse())
115 DeferredPacket(PacketPtr _pkt, Tick _tick) : tick(_tick), pkt(_pkt)
124 { }
125 };
126
116 { }
117 };
118
127 /**
128 * A deferred response stores a packet along with its scheduled
129 * transmission time. It also contains information of whether the
130 * bridge NACKed the packet to be able to correctly maintain
131 * counters of outstanding responses.
132 */
133 class DeferredResponse {
134
135 public:
136
137 Tick ready;
138 PacketPtr pkt;
139 bool nackedHere;
140
141 DeferredResponse(PacketPtr _pkt, Tick t, bool nack = false)
142 : ready(t), pkt(_pkt), nackedHere(nack)
143 { }
144 };
145
146 // Forward declaration to allow the slave port to have a pointer
147 class BridgeMasterPort;
148
149 /**
150 * The port on the side that receives requests and sends
151 * responses. The slave port has a set of address ranges that it
152 * is responsible for. The slave port also has a buffer for the
153 * responses not yet sent.
154 */
155 class BridgeSlavePort : public SlavePort
156 {
157
158 private:
159
119 // Forward declaration to allow the slave port to have a pointer
120 class BridgeMasterPort;
121
122 /**
123 * The port on the side that receives requests and sends
124 * responses. The slave port has a set of address ranges that it
125 * is responsible for. The slave port also has a buffer for the
126 * responses not yet sent.
127 */
128 class BridgeSlavePort : public SlavePort
129 {
130
131 private:
132
160 /** A pointer to the bridge to which this port belongs. */
161 Bridge *bridge;
133 /** The bridge to which this port belongs. */
134 Bridge& bridge;
162
163 /**
135
136 /**
164 * Master port on the other side of the bridge
165 * (connected to the other bus).
137 * Master port on the other side of the bridge (connected to
138 * the other bus).
166 */
167 BridgeMasterPort& masterPort;
168
169 /** Minimum request delay though this bridge. */
170 Tick delay;
171
139 */
140 BridgeMasterPort& masterPort;
141
142 /** Minimum request delay though this bridge. */
143 Tick delay;
144
172 /** Min delay to respond with a nack. */
173 Tick nackDelay;
174
175 /** Address ranges to pass through the bridge */
176 AddrRangeList ranges;
177
178 /**
179 * Response packet queue. Response packets are held in this
180 * queue for a specified delay to model the processing delay
181 * of the bridge.
182 */
145 /** Address ranges to pass through the bridge */
146 AddrRangeList ranges;
147
148 /**
149 * Response packet queue. Response packets are held in this
150 * queue for a specified delay to model the processing delay
151 * of the bridge.
152 */
183 std::list<DeferredResponse> responseQueue;
153 std::list<DeferredPacket> transmitList;
184
185 /** Counter to track the outstanding responses. */
186 unsigned int outstandingResponses;
187
154
155 /** Counter to track the outstanding responses. */
156 unsigned int outstandingResponses;
157
188 /** If we're waiting for a retry to happen. */
189 bool inRetry;
158 /** If we should send a retry when space becomes available. */
159 bool retryReq;
190
191 /** Max queue size for reserved responses. */
192 unsigned int respQueueLimit;
193
194 /**
195 * Is this side blocked from accepting new response packets.
196 *
197 * @return true if the reserved space has reached the set limit
198 */
199 bool respQueueFull();
200
201 /**
160
161 /** Max queue size for reserved responses. */
162 unsigned int respQueueLimit;
163
164 /**
165 * Is this side blocked from accepting new response packets.
166 *
167 * @return true if the reserved space has reached the set limit
168 */
169 bool respQueueFull();
170
171 /**
202 * Turn the request packet into a NACK response and put it in
203 * the response queue and schedule its transmission.
204 *
205 * @param pkt the request packet to NACK
206 */
207 void nackRequest(PacketPtr pkt);
208
209 /**
210 * Handle send event, scheduled when the packet at the head of
211 * the response queue is ready to transmit (for timing
212 * accesses only).
213 */
172 * Handle send event, scheduled when the packet at the head of
173 * the response queue is ready to transmit (for timing
174 * accesses only).
175 */
214 void trySend();
176 void trySendTiming();
215
216 /** Send event for the response queue. */
177
178 /** Send event for the response queue. */
217 EventWrapper<BridgeSlavePort, &BridgeSlavePort::trySend> sendEvent;
179 EventWrapper180 &BridgeSlavePort::trySendTiming> sendEvent;
218
219 public:
220
221 /**
222 * Constructor for the BridgeSlavePort.
223 *
224 * @param _name the port name including the owner
225 * @param _bridge the structural owner
226 * @param _masterPort the master port on the other side of the bridge
227 * @param _delay the delay from seeing a response to sending it
181
182 public:
183
184 /**
185 * Constructor for the BridgeSlavePort.
186 *
187 * @param _name the port name including the owner
188 * @param _bridge the structural owner
189 * @param _masterPort the master port on the other side of the bridge
190 * @param _delay the delay from seeing a response to sending it
228 * @param _nack_delay the delay from a NACK to sending the response
229 * @param _resp_limit the size of the response queue
230 * @param _ranges a number of address ranges to forward
231 */
191 * @param _resp_limit the size of the response queue
192 * @param _ranges a number of address ranges to forward
193 */
232 BridgeSlavePort(const std::string &_name, Bridge *_bridge,
194 BridgeSlavePort(const std::string& _name, Bridge& _bridge,
233 BridgeMasterPort& _masterPort, int _delay,
195 BridgeMasterPort& _masterPort, int _delay,
234 int _nack_delay, int _resp_limit,
235 std::vector<Range<Addr> > _ranges);
196 int _resp_limit, std::vector<Range<Addr> > _ranges);
236
237 /**
238 * Queue a response packet to be sent out later and also schedule
239 * a send if necessary.
240 *
241 * @param pkt a response to send out after a delay
197
198 /**
199 * Queue a response packet to be sent out later and also schedule
200 * a send if necessary.
201 *
202 * @param pkt a response to send out after a delay
203 * @param when tick when response packet should be sent
242 */
204 */
243 void queueForSendTiming(PacketPtr pkt);
205 void schedTimingResp(PacketPtr pkt, Tick when);
244
206
207 /**
208 * Retry any stalled request that we have failed to accept at
209 * an earlier point in time. This call will do nothing if no
210 * request is waiting.
211 */
212 void retryStalledReq();
213
245 protected:
246
247 /** When receiving a timing request from the peer port,
248 pass it to the bridge. */
214 protected:
215
216 /** When receiving a timing request from the peer port,
217 pass it to the bridge. */
249 virtual bool recvTimingReq(PacketPtr pkt);
218 bool recvTimingReq(PacketPtr pkt);
250
251 /** When receiving a retry request from the peer port,
252 pass it to the bridge. */
219
220 /** When receiving a retry request from the peer port,
221 pass it to the bridge. */
253 virtual void recvRetry();
222 void recvRetry();
254
255 /** When receiving a Atomic requestfrom the peer port,
256 pass it to the bridge. */
223
224 /** When receiving a Atomic requestfrom the peer port,
225 pass it to the bridge. */
257 virtual Tick recvAtomic(PacketPtr pkt);
226 Tick recvAtomic(PacketPtr pkt);
258
259 /** When receiving a Functional request from the peer port,
260 pass it to the bridge. */
227
228 /** When receiving a Functional request from the peer port,
229 pass it to the bridge. */
261 virtual void recvFunctional(PacketPtr pkt);
230 void recvFunctional(PacketPtr pkt);
262
263 /** When receiving a address range request the peer port,
264 pass it to the bridge. */
231
232 /** When receiving a address range request the peer port,
233 pass it to the bridge. */
265 virtual AddrRangeList getAddrRanges() const;
234 AddrRangeList getAddrRanges() const;
266 };
267
268
269 /**
270 * Port on the side that forwards requests and receives
271 * responses. The master port has a buffer for the requests not
272 * yet sent.
273 */
274 class BridgeMasterPort : public MasterPort
275 {
276
277 private:
278
235 };
236
237
238 /**
239 * Port on the side that forwards requests and receives
240 * responses. The master port has a buffer for the requests not
241 * yet sent.
242 */
243 class BridgeMasterPort : public MasterPort
244 {
245
246 private:
247
279 /** A pointer to the bridge to which this port belongs. */
280 Bridge* bridge;
248 /** The bridge to which this port belongs. */
249 Bridge& bridge;
281
282 /**
250
251 /**
283 * Pointer to the slave port on the other side of the bridge
284 * (connected to the other bus).
252 * The slave port on the other side of the bridge (connected
253 * to the other bus).
285 */
286 BridgeSlavePort& slavePort;
287
288 /** Minimum delay though this bridge. */
289 Tick delay;
290
291 /**
292 * Request packet queue. Request packets are held in this
293 * queue for a specified delay to model the processing delay
294 * of the bridge.
295 */
254 */
255 BridgeSlavePort& slavePort;
256
257 /** Minimum delay though this bridge. */
258 Tick delay;
259
260 /**
261 * Request packet queue. Request packets are held in this
262 * queue for a specified delay to model the processing delay
263 * of the bridge.
264 */
296 std::list<DeferredRequest> requestQueue;
265 std::list<DeferredPacket> transmitList;
297
266
298 /** If we're waiting for a retry to happen. */
299 bool inRetry;
300
301 /** Max queue size for request packets */
302 unsigned int reqQueueLimit;
303
304 /**
305 * Handle send event, scheduled when the packet at the head of
306 * the outbound queue is ready to transmit (for timing
307 * accesses only).
308 */
267 /** Max queue size for request packets */
268 unsigned int reqQueueLimit;
269
270 /**
271 * Handle send event, scheduled when the packet at the head of
272 * the outbound queue is ready to transmit (for timing
273 * accesses only).
274 */
309 void trySend();
275 void trySendTiming();
310
311 /** Send event for the request queue. */
276
277 /** Send event for the request queue. */
312 EventWrapper<BridgeMasterPort, &BridgeMasterPort::trySend> sendEvent;
278 EventWrapper279 &BridgeMasterPort::trySendTiming> sendEvent;
313
314 public:
315
316 /**
317 * Constructor for the BridgeMasterPort.
318 *
319 * @param _name the port name including the owner
320 * @param _bridge the structural owner
321 * @param _slavePort the slave port on the other side of the bridge
322 * @param _delay the delay from seeing a request to sending it
323 * @param _req_limit the size of the request queue
324 */
280
281 public:
282
283 /**
284 * Constructor for the BridgeMasterPort.
285 *
286 * @param _name the port name including the owner
287 * @param _bridge the structural owner
288 * @param _slavePort the slave port on the other side of the bridge
289 * @param _delay the delay from seeing a request to sending it
290 * @param _req_limit the size of the request queue
291 */
325 BridgeMasterPort(const std::string &_name, Bridge *_bridge,
292 BridgeMasterPort(const std::string& _name, Bridge& _bridge,
326 BridgeSlavePort& _slavePort, int _delay,
327 int _req_limit);
328
329 /**
330 * Is this side blocked from accepting new request packets.
331 *
332 * @return true if the occupied space has reached the set limit
333 */
334 bool reqQueueFull();
335
336 /**
337 * Queue a request packet to be sent out later and also schedule
338 * a send if necessary.
339 *
340 * @param pkt a request to send out after a delay
293 BridgeSlavePort& _slavePort, int _delay,
294 int _req_limit);
295
296 /**
297 * Is this side blocked from accepting new request packets.
298 *
299 * @return true if the occupied space has reached the set limit
300 */
301 bool reqQueueFull();
302
303 /**
304 * Queue a request packet to be sent out later and also schedule
305 * a send if necessary.
306 *
307 * @param pkt a request to send out after a delay
308 * @param when tick when response packet should be sent
341 */
309 */
342 void queueForSendTiming(PacketPtr pkt);
310 void schedTimingReq(PacketPtr pkt, Tick when);
343
344 /**
345 * Check a functional request against the packets in our
346 * request queue.
347 *
348 * @param pkt packet to check against
349 *
350 * @return true if we find a match
351 */
352 bool checkFunctional(PacketPtr pkt);
353
354 protected:
355
356 /** When receiving a timing request from the peer port,
357 pass it to the bridge. */
311
312 /**
313 * Check a functional request against the packets in our
314 * request queue.
315 *
316 * @param pkt packet to check against
317 *
318 * @return true if we find a match
319 */
320 bool checkFunctional(PacketPtr pkt);
321
322 protected:
323
324 /** When receiving a timing request from the peer port,
325 pass it to the bridge. */
358 virtual bool recvTimingResp(PacketPtr pkt);
326 bool recvTimingResp(PacketPtr pkt);
359
360 /** When receiving a retry request from the peer port,
361 pass it to the bridge. */
327
328 /** When receiving a retry request from the peer port,
329 pass it to the bridge. */
362 virtual void recvRetry();
330 void recvRetry();
363 };
364
365 /** Slave port of the bridge. */
366 BridgeSlavePort slavePort;
367
368 /** Master port of the bridge. */
369 BridgeMasterPort masterPort;
370
331 };
332
333 /** Slave port of the bridge. */
334 BridgeSlavePort slavePort;
335
336 /** Master port of the bridge. */
337 BridgeMasterPort masterPort;
338
371 /** If this bridge should acknowledge writes. */
372 bool ackWrites;
373
374 public:
339 public:
375 typedef BridgeParams Params;
376
340
377 protected:
378 Params *_params;
379
380 public:
381 const Params *params() const { return _params; }
382
383 virtual MasterPort& getMasterPort(const std::string& if_name,
384 int idx = -1);
385 virtual SlavePort& getSlavePort(const std::string& if_name, int idx = -1);
386
387 virtual void init();
388
341 virtual MasterPort& getMasterPort(const std::string& if_name,
342 int idx = -1);
343 virtual SlavePort& getSlavePort(const std::string& if_name, int idx = -1);
344
345 virtual void init();
346
347 typedef BridgeParams Params;
348
389 Bridge(Params *p);
390};
391
392#endif //__MEM_BUS_HH__
349 Bridge(Params *p);
350};
351
352#endif //__MEM_BUS_HH__