bridge.hh (2738:5d7a31c7fa29) bridge.hh (2982:0ecdb0879b14)
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/**
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 Decleration of a simple bus bridge object with no buffering
33 * @file
34 * Declaration of a simple bus bridge object with no buffering
34 */
35
36#ifndef __MEM_BRIDGE_HH__
37#define __MEM_BRIDGE_HH__
38
39#include <string>
40#include <list>
41#include <inttypes.h>
42#include <queue>
43
44#include "mem/mem_object.hh"
45#include "mem/packet.hh"
46#include "mem/port.hh"
47#include "sim/eventq.hh"
48
49class Bridge : public MemObject
50{
51 protected:
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 "sim/eventq.hh"
49
50class Bridge : public MemObject
51{
52 protected:
52 /** Decleration of the buses port type, one will be instantiated for each
53 /** Declaration of the buses port type, one will be instantiated for each
53 of the interfaces connecting to the bus. */
54 class BridgePort : public Port
55 {
56 /** A pointer to the bridge to which this port belongs. */
57 Bridge *bridge;
58
59 /**
60 * Pointer to the port on the other side of the bridge
61 * (connected to the other bus).
62 */
63 BridgePort *otherPort;
64
65 /** Minimum delay though this bridge. */
66 Tick delay;
67
68 class PacketBuffer : public Packet::SenderState {
69
70 public:
71 Tick ready;
72 Packet *pkt;
73 Packet::SenderState *origSenderState;
74 short origSrc;
75 bool expectResponse;
76
77 PacketBuffer(Packet *_pkt, Tick t)
78 : ready(t), pkt(_pkt),
79 origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
80 expectResponse(_pkt->needsResponse())
81 {
82 if (!pkt->isResponse())
83 pkt->senderState = this;
84 }
85
86 void fixResponse(Packet *pkt)
87 {
88 assert(pkt->senderState == this);
89 pkt->setDest(origSrc);
90 pkt->senderState = origSenderState;
91 }
92 };
93
94 /**
95 * Outbound packet queue. Packets are held in this queue for a
96 * specified delay to model the processing delay of the
97 * bridge.
98 */
99 std::list<PacketBuffer*> sendQueue;
100
101 int outstandingResponses;
102
103 /** Max queue size for outbound packets */
104 int queueLimit;
105
106 /**
107 * Is this side blocked from accepting outbound packets?
108 */
109 bool queueFull() { return (sendQueue.size() == queueLimit); }
110
111 bool queueForSendTiming(Packet *pkt);
112
113 void finishSend(PacketBuffer *buf);
114
115 /**
116 * Handle send event, scheduled when the packet at the head of
117 * the outbound queue is ready to transmit (for timing
118 * accesses only).
119 */
120 void trySend();
121
122 class SendEvent : public Event
123 {
124 BridgePort *port;
125
126 public:
127 SendEvent(BridgePort *p)
128 : Event(&mainEventQueue), port(p) {}
129
130 virtual void process() { port->trySend(); }
131
132 virtual const char *description() { return "bridge send event"; }
133 };
134
135 SendEvent sendEvent;
136
137 public:
138
139 /** Constructor for the BusPort.*/
140 BridgePort(const std::string &_name,
141 Bridge *_bridge, BridgePort *_otherPort,
142 int _delay, int _queueLimit);
143
144 protected:
145
146 /** When receiving a timing request from the peer port,
147 pass it to the bridge. */
148 virtual bool recvTiming(Packet *pkt);
149
150 /** When receiving a retry request from the peer port,
151 pass it to the bridge. */
152 virtual void recvRetry();
153
154 /** When receiving a Atomic requestfrom the peer port,
155 pass it to the bridge. */
156 virtual Tick recvAtomic(Packet *pkt);
157
158 /** When receiving a Functional request from the peer port,
159 pass it to the bridge. */
160 virtual void recvFunctional(Packet *pkt);
161
162 /** When receiving a status changefrom the peer port,
163 pass it to the bridge. */
164 virtual void recvStatusChange(Status status);
165
166 /** When receiving a address range request the peer port,
167 pass it to the bridge. */
168 virtual void getDeviceAddressRanges(AddrRangeList &resp,
169 AddrRangeList &snoop);
170 };
171
172 BridgePort portA, portB;
173
174 /** If this bridge should acknowledge writes. */
175 bool ackWrites;
176
177 public:
178
179 /** A function used to return the port associated with this bus object. */
180 virtual Port *getPort(const std::string &if_name, int idx = -1);
181
182 virtual void init();
183
184 Bridge(const std::string &n, int qsa, int qsb, Tick _delay, int write_ack);
185};
186
187#endif //__MEM_BUS_HH__
54 of the interfaces connecting to the bus. */
55 class BridgePort : public Port
56 {
57 /** A pointer to the bridge to which this port belongs. */
58 Bridge *bridge;
59
60 /**
61 * Pointer to the port on the other side of the bridge
62 * (connected to the other bus).
63 */
64 BridgePort *otherPort;
65
66 /** Minimum delay though this bridge. */
67 Tick delay;
68
69 class PacketBuffer : public Packet::SenderState {
70
71 public:
72 Tick ready;
73 Packet *pkt;
74 Packet::SenderState *origSenderState;
75 short origSrc;
76 bool expectResponse;
77
78 PacketBuffer(Packet *_pkt, Tick t)
79 : ready(t), pkt(_pkt),
80 origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
81 expectResponse(_pkt->needsResponse())
82 {
83 if (!pkt->isResponse())
84 pkt->senderState = this;
85 }
86
87 void fixResponse(Packet *pkt)
88 {
89 assert(pkt->senderState == this);
90 pkt->setDest(origSrc);
91 pkt->senderState = origSenderState;
92 }
93 };
94
95 /**
96 * Outbound packet queue. Packets are held in this queue for a
97 * specified delay to model the processing delay of the
98 * bridge.
99 */
100 std::list<PacketBuffer*> sendQueue;
101
102 int outstandingResponses;
103
104 /** Max queue size for outbound packets */
105 int queueLimit;
106
107 /**
108 * Is this side blocked from accepting outbound packets?
109 */
110 bool queueFull() { return (sendQueue.size() == queueLimit); }
111
112 bool queueForSendTiming(Packet *pkt);
113
114 void finishSend(PacketBuffer *buf);
115
116 /**
117 * Handle send event, scheduled when the packet at the head of
118 * the outbound queue is ready to transmit (for timing
119 * accesses only).
120 */
121 void trySend();
122
123 class SendEvent : public Event
124 {
125 BridgePort *port;
126
127 public:
128 SendEvent(BridgePort *p)
129 : Event(&mainEventQueue), port(p) {}
130
131 virtual void process() { port->trySend(); }
132
133 virtual const char *description() { return "bridge send event"; }
134 };
135
136 SendEvent sendEvent;
137
138 public:
139
140 /** Constructor for the BusPort.*/
141 BridgePort(const std::string &_name,
142 Bridge *_bridge, BridgePort *_otherPort,
143 int _delay, int _queueLimit);
144
145 protected:
146
147 /** When receiving a timing request from the peer port,
148 pass it to the bridge. */
149 virtual bool recvTiming(Packet *pkt);
150
151 /** When receiving a retry request from the peer port,
152 pass it to the bridge. */
153 virtual void recvRetry();
154
155 /** When receiving a Atomic requestfrom the peer port,
156 pass it to the bridge. */
157 virtual Tick recvAtomic(Packet *pkt);
158
159 /** When receiving a Functional request from the peer port,
160 pass it to the bridge. */
161 virtual void recvFunctional(Packet *pkt);
162
163 /** When receiving a status changefrom the peer port,
164 pass it to the bridge. */
165 virtual void recvStatusChange(Status status);
166
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);
171 };
172
173 BridgePort portA, portB;
174
175 /** If this bridge should acknowledge writes. */
176 bool ackWrites;
177
178 public:
179
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);
182
183 virtual void init();
184
185 Bridge(const std::string &n, int qsa, int qsb, Tick _delay, int write_ack);
186};
187
188#endif //__MEM_BUS_HH__