bridge.hh (4918:3214e3694fb2) bridge.hh (4965:ad0e792a5c78)
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
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 bool fixPartialWrite;
73 /** Pass ranges from one side of the bridge to the other? */
74 std::vector<Range<Addr> > filterRanges;
74
75 class PacketBuffer : public Packet::SenderState {
76
77 public:
78 Tick ready;
79 PacketPtr pkt;
80 Packet::SenderState *origSenderState;
81 short origSrc;
82 bool expectResponse;
83
84 PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
85 : ready(t), pkt(_pkt),
86 origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
87 expectResponse(_pkt->needsResponse() && !nack)
88
89 {
90 if (!pkt->isResponse() && !nack && !pkt->wasNacked())
91 pkt->senderState = this;
92 }
93
94 void fixResponse(PacketPtr pkt)
95 {
96 assert(pkt->senderState == this);
97 pkt->setDest(origSrc);
98 pkt->senderState = origSenderState;
99 }
100 };
101
102 /**
103 * Outbound packet queue. Packets are held in this queue for a
104 * specified delay to model the processing delay of the
105 * bridge.
106 */
107 std::list<PacketBuffer*> sendQueue;
108
109 int outstandingResponses;
110 int queuedRequests;
111
112 /** If we're waiting for a retry to happen.*/
113 bool inRetry;
114
115 /** Max queue size for outbound packets */
116 int reqQueueLimit;
117
118 /** Max queue size for reserved responses. */
119 int respQueueLimit;
120
121 /**
122 * Is this side blocked from accepting outbound packets?
123 */
124 bool respQueueFull();
125 bool reqQueueFull();
126
127 void queueForSendTiming(PacketPtr pkt);
128
129 void finishSend(PacketBuffer *buf);
130
131 void nackRequest(PacketPtr pkt);
132
133 /**
134 * Handle send event, scheduled when the packet at the head of
135 * the outbound queue is ready to transmit (for timing
136 * accesses only).
137 */
138 void trySend();
139
140 class SendEvent : public Event
141 {
142 BridgePort *port;
143
144 public:
145 SendEvent(BridgePort *p)
146 : Event(&mainEventQueue), port(p) {}
147
148 virtual void process() { port->trySend(); }
149
150 virtual const char *description() { return "bridge send"; }
151 };
152
153 SendEvent sendEvent;
154
155 public:
156 /** Constructor for the BusPort.*/
157 BridgePort(const std::string &_name, Bridge *_bridge,
158 BridgePort *_otherPort, int _delay, int _nack_delay,
75
76 class PacketBuffer : public Packet::SenderState {
77
78 public:
79 Tick ready;
80 PacketPtr pkt;
81 Packet::SenderState *origSenderState;
82 short origSrc;
83 bool expectResponse;
84
85 PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
86 : ready(t), pkt(_pkt),
87 origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
88 expectResponse(_pkt->needsResponse() && !nack)
89
90 {
91 if (!pkt->isResponse() && !nack && !pkt->wasNacked())
92 pkt->senderState = this;
93 }
94
95 void fixResponse(PacketPtr pkt)
96 {
97 assert(pkt->senderState == this);
98 pkt->setDest(origSrc);
99 pkt->senderState = origSenderState;
100 }
101 };
102
103 /**
104 * Outbound packet queue. Packets are held in this queue for a
105 * specified delay to model the processing delay of the
106 * bridge.
107 */
108 std::list<PacketBuffer*> sendQueue;
109
110 int outstandingResponses;
111 int queuedRequests;
112
113 /** If we're waiting for a retry to happen.*/
114 bool inRetry;
115
116 /** Max queue size for outbound packets */
117 int reqQueueLimit;
118
119 /** Max queue size for reserved responses. */
120 int respQueueLimit;
121
122 /**
123 * Is this side blocked from accepting outbound packets?
124 */
125 bool respQueueFull();
126 bool reqQueueFull();
127
128 void queueForSendTiming(PacketPtr pkt);
129
130 void finishSend(PacketBuffer *buf);
131
132 void nackRequest(PacketPtr pkt);
133
134 /**
135 * Handle send event, scheduled when the packet at the head of
136 * the outbound queue is ready to transmit (for timing
137 * accesses only).
138 */
139 void trySend();
140
141 class SendEvent : public Event
142 {
143 BridgePort *port;
144
145 public:
146 SendEvent(BridgePort *p)
147 : Event(&mainEventQueue), port(p) {}
148
149 virtual void process() { port->trySend(); }
150
151 virtual const char *description() { return "bridge send"; }
152 };
153
154 SendEvent sendEvent;
155
156 public:
157 /** Constructor for the BusPort.*/
158 BridgePort(const std::string &_name, Bridge *_bridge,
159 BridgePort *_otherPort, int _delay, int _nack_delay,
159 int _req_limit, int _resp_limit, bool fix_partial_write);
160 int _req_limit, int _resp_limit,
161 std::vector<Range<Addr> > filter_ranges);
160
161 protected:
162
163 /** When receiving a timing request from the peer port,
164 pass it to the bridge. */
165 virtual bool recvTiming(PacketPtr pkt);
166
167 /** When receiving a retry request from the peer port,
168 pass it to the bridge. */
169 virtual void recvRetry();
170
171 /** When receiving a Atomic requestfrom the peer port,
172 pass it to the bridge. */
173 virtual Tick recvAtomic(PacketPtr pkt);
174
175 /** When receiving a Functional request from the peer port,
176 pass it to the bridge. */
177 virtual void recvFunctional(PacketPtr pkt);
178
179 /** When receiving a status changefrom the peer port,
180 pass it to the bridge. */
181 virtual void recvStatusChange(Status status);
182
183 /** When receiving a address range request the peer port,
184 pass it to the bridge. */
185 virtual void getDeviceAddressRanges(AddrRangeList &resp,
186 bool &snoop);
187 };
188
189 BridgePort portA, portB;
190
191 /** If this bridge should acknowledge writes. */
192 bool ackWrites;
193
194 public:
195 typedef BridgeParams Params;
196
197 protected:
198 Params *_params;
199
200 public:
201 const Params *params() const { return _params; }
202
203 /** A function used to return the port associated with this bus object. */
204 virtual Port *getPort(const std::string &if_name, int idx = -1);
205
206 virtual void init();
207
208 Bridge(Params *p);
209};
210
211#endif //__MEM_BUS_HH__
162
163 protected:
164
165 /** When receiving a timing request from the peer port,
166 pass it to the bridge. */
167 virtual bool recvTiming(PacketPtr pkt);
168
169 /** When receiving a retry request from the peer port,
170 pass it to the bridge. */
171 virtual void recvRetry();
172
173 /** When receiving a Atomic requestfrom the peer port,
174 pass it to the bridge. */
175 virtual Tick recvAtomic(PacketPtr pkt);
176
177 /** When receiving a Functional request from the peer port,
178 pass it to the bridge. */
179 virtual void recvFunctional(PacketPtr pkt);
180
181 /** When receiving a status changefrom the peer port,
182 pass it to the bridge. */
183 virtual void recvStatusChange(Status status);
184
185 /** When receiving a address range request the peer port,
186 pass it to the bridge. */
187 virtual void getDeviceAddressRanges(AddrRangeList &resp,
188 bool &snoop);
189 };
190
191 BridgePort portA, portB;
192
193 /** If this bridge should acknowledge writes. */
194 bool ackWrites;
195
196 public:
197 typedef BridgeParams Params;
198
199 protected:
200 Params *_params;
201
202 public:
203 const Params *params() const { return _params; }
204
205 /** A function used to return the port associated with this bus object. */
206 virtual Port *getPort(const std::string &if_name, int idx = -1);
207
208 virtual void init();
209
210 Bridge(Params *p);
211};
212
213#endif //__MEM_BUS_HH__