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/hashmap.hh"
46 #include "base/range_map.hh"
47 #include "mem/mem_object.hh"
48 #include "mem/packet.hh"
49 #include "mem/port.hh"
50 #include "mem/request.hh"
51 #include "sim/eventq.hh"
53 class Bus : public MemObject
55 /** Declaration of the buses port type, one will be instantiated for each
56 of the interfaces connecting to the bus. */
57 class BusPort : public Port
61 /** A pointer to the bus to which this port belongs. */
64 /** A id to keep track of the intercafe ID this port is connected to. */
69 /** Constructor for the BusPort.*/
70 BusPort(const std::string &_name, Bus *_bus, int _id)
71 : Port(_name, _bus), _onRetryList(false), bus(_bus), id(_id)
75 { return _onRetryList; }
77 void onRetryList(bool newVal)
78 { _onRetryList = newVal; }
80 int getId() { return id; }
84 /** When reciving a timing request from the peer port (at id),
85 pass it to the bus. */
86 virtual bool recvTiming(PacketPtr pkt)
87 { pkt->setSrc(id); return bus->recvTiming(pkt); }
89 /** When reciving a Atomic requestfrom the peer port (at id),
90 pass it to the bus. */
91 virtual Tick recvAtomic(PacketPtr pkt)
92 { pkt->setSrc(id); return bus->recvAtomic(pkt); }
94 /** When reciving a Functional requestfrom the peer port (at id),
95 pass it to the bus. */
96 virtual void recvFunctional(PacketPtr pkt)
97 { pkt->setSrc(id); bus->recvFunctional(pkt); }
99 /** When reciving a status changefrom the peer port (at id),
100 pass it to the bus. */
101 virtual void recvStatusChange(Status status)
102 { bus->recvStatusChange(status, id); }
104 /** When reciving a retry from the peer port (at id),
105 pass it to the bus. */
106 virtual void recvRetry()
107 { bus->recvRetry(id); }
109 // This should return all the 'owned' addresses that are
110 // downstream from this bus, yes? That is, the union of all
111 // the 'owned' address ranges of all the other interfaces on
113 virtual void getDeviceAddressRanges(AddrRangeList &resp,
115 { bus->addressRanges(resp, snoop, id); }
117 // Ask the bus to ask everyone on the bus what their block size is and
118 // take the max of it. This might need to be changed a bit if we ever
119 // support multiple block sizes.
120 virtual int deviceBlockSize()
121 { return bus->findBlockSize(id); }
125 class BusFreeEvent : public Event
130 BusFreeEvent(Bus * _bus);
132 const char *description();
135 /** a globally unique id for this bus. */
137 /** the clock speed for the bus */
139 /** the width of the bus in bytes */
141 /** the next tick at which the bus will be idle */
147 static const int defaultId = -3; //Make it unique from Broadcast
149 typedef range_map<Addr,int>::iterator PortIter;
150 range_map<Addr, int> portMap;
152 AddrRangeList defaultRange;
154 typedef std::vector<BusPort*>::iterator SnoopIter;
155 std::vector<BusPort*> snoopPorts;
157 /** Function called by the port when the bus is recieving a Timing
159 bool recvTiming(PacketPtr pkt);
161 /** Function called by the port when the bus is recieving a Atomic
163 Tick recvAtomic(PacketPtr pkt);
165 /** Function called by the port when the bus is recieving a Functional
167 void recvFunctional(PacketPtr pkt);
169 /** Timing function called by port when it is once again able to process
171 void recvRetry(int id);
173 /** Function called by the port when the bus is recieving a status change.*/
174 void recvStatusChange(Port::Status status, int id);
176 /** Find which port connected to this bus (if any) should be given a packet
178 * @param addr Address to find port for.
179 * @return id of port that the packet should be sent out of.
181 int findPort(Addr addr);
183 /** Snoop all relevant ports functionally. */
184 void functionalSnoop(PacketPtr pkt, Port *responder);
186 /** Call snoop on caches, be sure to set SNOOP_COMMIT bit if you want
187 * the snoop to happen
188 * @return True if succeds.
190 bool timingSnoop(PacketPtr pkt, Port *responder);
192 /** Process address range request.
193 * @param resp addresses that we can respond to
194 * @param snoop addresses that we would like to snoop
195 * @param id ide of the busport that made the request.
197 void addressRanges(AddrRangeList &resp, bool &snoop, int id);
199 /** Occupy the bus with transmitting the packet pkt */
200 void occupyBus(PacketPtr pkt);
202 /** Ask everyone on the bus what their size is
203 * @param id id of the busport that made the request
204 * @return the max of all the sizes
206 int findBlockSize(int id);
208 BusFreeEvent busIdle;
212 /** max number of bus ids we've handed out so far */
215 /** An array of pointers to the peer port interfaces
216 connected to this bus.*/
217 m5::hash_map<short,BusPort*> interfaces;
219 /** An array of pointers to ports that retry should be called on because the
220 * original send failed for whatever reason.*/
221 std::list<BusPort*> retryList;
223 void addToRetryList(BusPort * port)
226 // The device wasn't retrying a packet, or wasn't at an appropriate
228 assert(!port->onRetryList());
229 port->onRetryList(true);
230 retryList.push_back(port);
232 if (port->onRetryList()) {
233 // The device was retrying a packet. It didn't work, so we'll leave
234 // it at the head of the retry list.
235 assert(port == retryList.front());
239 port->onRetryList(true);
240 retryList.push_back(port);
245 /** Port that handles requests that don't match any of the interfaces.*/
246 BusPort *defaultPort;
251 /** Has the user specified their own default responder? */
254 int defaultBlockSize;
256 bool cachedBlockSizeValid;
260 /** A function used to return the port associated with this bus object. */
261 virtual Port *getPort(const std::string &if_name, int idx = -1);
262 virtual void deletePortRefs(Port *p);
265 virtual void startup();
267 unsigned int drain(Event *de);
269 Bus(const std::string &n, int bus_id, int _clock, int _width,
270 bool responder_set, int dflt_blk_size)
271 : MemObject(n), busId(bus_id), clock(_clock), width(_width),
272 tickNextIdle(0), drainEvent(NULL), busIdle(this), inRetry(false),
273 maxId(0), defaultPort(NULL), funcPort(NULL), funcPortId(-4),
274 responderSet(responder_set), defaultBlockSize(dflt_blk_size),
275 cachedBlockSize(0), cachedBlockSizeValid(false)
277 //Both the width and clock period must be positive
279 fatal("Bus width must be positive\n");
281 fatal("Bus clock period must be positive\n");
286 #endif //__MEM_BUS_HH__