Commiting a version of the multi-phase snoop atomic bus so people can see the framewo...
[gem5.git] / src / mem / bus.hh
1 /*
2 * Copyright (c) 2002-2005 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: Ron Dreslinski
29 * Ali Saidi
30 */
31
32 /**
33 * @file
34 * Declaration of a bus object.
35 */
36
37 #ifndef __MEM_BUS_HH__
38 #define __MEM_BUS_HH__
39
40 #include <string>
41 #include <list>
42 #include <inttypes.h>
43
44 #include "base/range.hh"
45 #include "mem/mem_object.hh"
46 #include "mem/packet.hh"
47 #include "mem/port.hh"
48 #include "mem/request.hh"
49
50 class Bus : public MemObject
51 {
52 /** a globally unique id for this bus. */
53 int busId;
54
55 static const int defaultId = -1;
56
57 struct DevMap {
58 int portId;
59 Range<Addr> range;
60 };
61 std::vector<DevMap> portList;
62 AddrRangeList defaultRange;
63 std::vector<DevMap> portSnoopList;
64
65 std::vector<int> snoopCallbacks;
66
67
68 /** Function called by the port when the bus is recieving a Timing
69 transaction.*/
70 bool recvTiming(Packet *pkt);
71
72 /** Function called by the port when the bus is recieving a Atomic
73 transaction.*/
74 Tick recvAtomic(Packet *pkt);
75
76 /** Function called by the port when the bus is recieving a Functional
77 transaction.*/
78 void recvFunctional(Packet *pkt);
79
80 /** Timing function called by port when it is once again able to process
81 * requests. */
82 void recvRetry(int id);
83
84 /** Function called by the port when the bus is recieving a status change.*/
85 void recvStatusChange(Port::Status status, int id);
86
87 /** Find which port connected to this bus (if any) should be given a packet
88 * with this address.
89 * @param addr Address to find port for.
90 * @param id Id of the port this packet was received from (to prevent
91 * loops)
92 * @return pointer to port that the packet should be sent out of.
93 */
94 Port *findPort(Addr addr, int id);
95
96 /** Find all ports with a matching snoop range, except src port. Keep in mind
97 * that the ranges shouldn't overlap or you will get a double snoop to the same
98 * interface.and the cache will assert out.
99 * @param addr Address to find snoop prts for.
100 * @param id Id of the src port of the request to avoid calling snoop on src
101 * @return vector of IDs to snoop on
102 */
103 std::vector<int> findSnoopPorts(Addr addr, int id);
104
105 /** Snoop all relevant ports atomicly. */
106 void atomicSnoop(Packet *pkt);
107
108 /** Snoop for NACK and Blocked in phase 1
109 * @return True if succeds.
110 */
111 bool timingSnoopPhase1(Packet *pkt);
112
113 /** @todo Don't need to commit all snoops just those that need it
114 *(register somehow). */
115 /** Commit all snoops now that we know if any of them would have blocked.
116 */
117 void timingSnoopPhase2(Packet *pkt);
118
119 /** Process address range request.
120 * @param resp addresses that we can respond to
121 * @param snoop addresses that we would like to snoop
122 * @param id ide of the busport that made the request.
123 */
124 void addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id);
125
126
127 /** Declaration of the buses port type, one will be instantiated for each
128 of the interfaces connecting to the bus. */
129 class BusPort : public Port
130 {
131 /** A pointer to the bus to which this port belongs. */
132 Bus *bus;
133
134 /** A id to keep track of the intercafe ID this port is connected to. */
135 int id;
136
137 public:
138
139 /** Constructor for the BusPort.*/
140 BusPort(const std::string &_name, Bus *_bus, int _id)
141 : Port(_name), bus(_bus), id(_id)
142 { }
143
144 protected:
145
146 /** When reciving a timing request from the peer port (at id),
147 pass it to the bus. */
148 virtual bool recvTiming(Packet *pkt)
149 { pkt->setSrc(id); return bus->recvTiming(pkt); }
150
151 /** When reciving a Atomic requestfrom the peer port (at id),
152 pass it to the bus. */
153 virtual Tick recvAtomic(Packet *pkt)
154 { pkt->setSrc(id); return bus->recvAtomic(pkt); }
155
156 /** When reciving a Functional requestfrom the peer port (at id),
157 pass it to the bus. */
158 virtual void recvFunctional(Packet *pkt)
159 { pkt->setSrc(id); bus->recvFunctional(pkt); }
160
161 /** When reciving a status changefrom the peer port (at id),
162 pass it to the bus. */
163 virtual void recvStatusChange(Status status)
164 { bus->recvStatusChange(status, id); }
165
166 /** When reciving a retry from the peer port (at id),
167 pass it to the bus. */
168 virtual void recvRetry()
169 { bus->recvRetry(id); }
170
171 // This should return all the 'owned' addresses that are
172 // downstream from this bus, yes? That is, the union of all
173 // the 'owned' address ranges of all the other interfaces on
174 // this bus...
175 virtual void getDeviceAddressRanges(AddrRangeList &resp,
176 AddrRangeList &snoop)
177 { bus->addressRanges(resp, snoop, id); }
178
179 // Hack to make translating port work without changes
180 virtual int deviceBlockSize() { return 32; }
181
182 };
183
184 /** An array of pointers to the peer port interfaces
185 connected to this bus.*/
186 std::vector<Port*> interfaces;
187
188 /** An array of pointers to ports that retry should be called on because the
189 * original send failed for whatever reason.*/
190 std::list<Port*> retryList;
191
192 /** Port that handles requests that don't match any of the interfaces.*/
193 Port *defaultPort;
194
195 public:
196
197 /** A function used to return the port associated with this bus object. */
198 virtual Port *getPort(const std::string &if_name, int idx = -1);
199
200 virtual void init();
201
202 Bus(const std::string &n, int bus_id)
203 : MemObject(n), busId(bus_id), defaultPort(NULL) {}
204
205 };
206
207 #endif //__MEM_BUS_HH__