2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Ron Dreslinski
34 * Declaration of a bus object.
37 #ifndef __MEM_BUS_HH__
38 #define __MEM_BUS_HH__
44 #include "base/range.hh"
45 #include "base/range_map.hh"
46 #include "mem/mem_object.hh"
47 #include "mem/packet.hh"
48 #include "mem/port.hh"
49 #include "mem/request.hh"
50 #include "sim/eventq.hh"
52 class Bus : public MemObject
54 /** a globally unique id for this bus. */
56 /** the clock speed for the bus */
58 /** the width of the bus in bytes */
60 /** the next tick at which the bus will be idle */
65 static const int defaultId = -3; //Make it unique from Broadcast
71 range_map<Addr, int> portMap;
72 AddrRangeList defaultRange;
73 std::vector<DevMap> portSnoopList;
75 /** Function called by the port when the bus is recieving a Timing
77 bool recvTiming(PacketPtr pkt);
79 /** Function called by the port when the bus is recieving a Atomic
81 Tick recvAtomic(PacketPtr pkt);
83 /** Function called by the port when the bus is recieving a Functional
85 void recvFunctional(PacketPtr pkt);
87 /** Timing function called by port when it is once again able to process
89 void recvRetry(int id);
91 /** Function called by the port when the bus is recieving a status change.*/
92 void recvStatusChange(Port::Status status, int id);
94 /** Find which port connected to this bus (if any) should be given a packet
96 * @param addr Address to find port for.
97 * @param id Id of the port this packet was received from (to prevent
99 * @return pointer to port that the packet should be sent out of.
101 Port *findPort(Addr addr, int id);
103 /** Find all ports with a matching snoop range, except src port. Keep in mind
104 * that the ranges shouldn't overlap or you will get a double snoop to the same
105 * interface.and the cache will assert out.
106 * @param addr Address to find snoop prts for.
107 * @param id Id of the src port of the request to avoid calling snoop on src
108 * @return vector of IDs to snoop on
110 std::vector<int> findSnoopPorts(Addr addr, int id);
112 /** Snoop all relevant ports atomicly. */
113 Tick atomicSnoop(PacketPtr pkt, Port* responder);
115 /** Snoop all relevant ports functionally. */
116 void functionalSnoop(PacketPtr pkt, Port *responder);
118 /** Call snoop on caches, be sure to set SNOOP_COMMIT bit if you want
119 * the snoop to happen
120 * @return True if succeds.
122 bool timingSnoop(PacketPtr pkt, Port *responder);
124 /** Process address range request.
125 * @param resp addresses that we can respond to
126 * @param snoop addresses that we would like to snoop
127 * @param id ide of the busport that made the request.
129 void addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id);
131 /** Occupy the bus with transmitting the packet pkt */
132 void occupyBus(PacketPtr pkt);
134 /** Declaration of the buses port type, one will be instantiated for each
135 of the interfaces connecting to the bus. */
136 class BusPort : public Port
140 /** A pointer to the bus to which this port belongs. */
143 /** A id to keep track of the intercafe ID this port is connected to. */
148 /** Constructor for the BusPort.*/
149 BusPort(const std::string &_name, Bus *_bus, int _id)
150 : Port(_name, _bus), _onRetryList(false), bus(_bus), id(_id)
154 { return _onRetryList; }
156 void onRetryList(bool newVal)
157 { _onRetryList = newVal; }
161 /** When reciving a timing request from the peer port (at id),
162 pass it to the bus. */
163 virtual bool recvTiming(PacketPtr pkt)
164 { pkt->setSrc(id); return bus->recvTiming(pkt); }
166 /** When reciving a Atomic requestfrom the peer port (at id),
167 pass it to the bus. */
168 virtual Tick recvAtomic(PacketPtr pkt)
169 { pkt->setSrc(id); return bus->recvAtomic(pkt); }
171 /** When reciving a Functional requestfrom the peer port (at id),
172 pass it to the bus. */
173 virtual void recvFunctional(PacketPtr pkt)
174 { pkt->setSrc(id); bus->recvFunctional(pkt); }
176 /** When reciving a status changefrom the peer port (at id),
177 pass it to the bus. */
178 virtual void recvStatusChange(Status status)
179 { bus->recvStatusChange(status, id); }
181 /** When reciving a retry from the peer port (at id),
182 pass it to the bus. */
183 virtual void recvRetry()
184 { bus->recvRetry(id); }
186 // This should return all the 'owned' addresses that are
187 // downstream from this bus, yes? That is, the union of all
188 // the 'owned' address ranges of all the other interfaces on
190 virtual void getDeviceAddressRanges(AddrRangeList &resp,
191 AddrRangeList &snoop)
192 { bus->addressRanges(resp, snoop, id); }
194 // Hack to make translating port work without changes
195 virtual int deviceBlockSize() { return 32; }
199 class BusFreeEvent : public Event
204 BusFreeEvent(Bus * _bus);
206 const char *description();
209 BusFreeEvent busIdle;
213 /** An array of pointers to the peer port interfaces
214 connected to this bus.*/
215 std::vector<BusPort*> interfaces;
217 /** An array of pointers to ports that retry should be called on because the
218 * original send failed for whatever reason.*/
219 std::list<BusPort*> retryList;
221 void addToRetryList(BusPort * port)
224 // The device wasn't retrying a packet, or wasn't at an appropriate
226 assert(!port->onRetryList());
227 port->onRetryList(true);
228 retryList.push_back(port);
230 if (port->onRetryList()) {
231 // The device was retrying a packet. It didn't work, so we'll leave
232 // it at the head of the retry list.
233 assert(port == retryList.front());
237 port->onRetryList(true);
238 retryList.push_back(port);
243 /** Port that handles requests that don't match any of the interfaces.*/
244 BusPort *defaultPort;
246 /** Has the user specified their own default responder? */
251 /** A function used to return the port associated with this bus object. */
252 virtual Port *getPort(const std::string &if_name, int idx = -1);
256 unsigned int drain(Event *de);
258 Bus(const std::string &n, int bus_id, int _clock, int _width,
260 : MemObject(n), busId(bus_id), clock(_clock), width(_width),
261 tickNextIdle(0), drainEvent(NULL), busIdle(this), inRetry(false),
262 defaultPort(NULL), responderSet(responder_set)
264 //Both the width and clock period must be positive
266 fatal("Bus width must be positive\n");
268 fatal("Bus clock period must be positive\n");
273 #endif //__MEM_BUS_HH__