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