Merge iceaxe.:/Volumes/work/research/m5/head
[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 */
30
31 /**
32 * @file Decleration of a bus object.
33 */
34
35 #ifndef __MEM_BUS_HH__
36 #define __MEM_BUS_HH__
37
38 #include <string>
39 #include <list>
40 #include <inttypes.h>
41
42 #include "base/range.hh"
43 #include "mem/mem_object.hh"
44 #include "mem/packet.hh"
45 #include "mem/port.hh"
46 #include "mem/request.hh"
47
48 class Bus : public MemObject
49 {
50 /** a globally unique id for this bus. */
51 int busId;
52
53 struct DevMap {
54 int portId;
55 Range<Addr> range;
56 };
57 std::vector<DevMap> portList;
58
59
60 /** Function called by the port when the bus is recieving a Timing
61 transaction.*/
62 bool recvTiming(Packet *pkt);
63
64 /** Function called by the port when the bus is recieving a Atomic
65 transaction.*/
66 Tick recvAtomic(Packet *pkt);
67
68 /** Function called by the port when the bus is recieving a Functional
69 transaction.*/
70 void recvFunctional(Packet *pkt);
71
72 /** Timing function called by port when it is once again able to process
73 * requests. */
74 void recvRetry(int id);
75
76 /** Function called by the port when the bus is recieving a status change.*/
77 void recvStatusChange(Port::Status status, int id);
78
79 /** Find which port connected to this bus (if any) should be given a packet
80 * with this address.
81 * @param addr Address to find port for.
82 * @param id Id of the port this packet was received from (to prevent
83 * loops)
84 * @return pointer to port that the packet should be sent out of.
85 */
86 Port *findPort(Addr addr, int id);
87
88 /** Process address range request.
89 * @param resp addresses that we can respond to
90 * @param snoop addresses that we would like to snoop
91 * @param id ide of the busport that made the request.
92 */
93 void addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id);
94
95
96 /** Decleration of the buses port type, one will be instantiated for each
97 of the interfaces connecting to the bus. */
98 class BusPort : public Port
99 {
100 /** A pointer to the bus to which this port belongs. */
101 Bus *bus;
102
103 /** A id to keep track of the intercafe ID this port is connected to. */
104 int id;
105
106 public:
107
108 /** Constructor for the BusPort.*/
109 BusPort(const std::string &_name, Bus *_bus, int _id)
110 : Port(_name), bus(_bus), id(_id)
111 { }
112
113 protected:
114
115 /** When reciving a timing request from the peer port (at id),
116 pass it to the bus. */
117 virtual bool recvTiming(Packet *pkt)
118 { pkt->setSrc(id); return bus->recvTiming(pkt); }
119
120 /** When reciving a Atomic requestfrom the peer port (at id),
121 pass it to the bus. */
122 virtual Tick recvAtomic(Packet *pkt)
123 { pkt->setSrc(id); return bus->recvAtomic(pkt); }
124
125 /** When reciving a Functional requestfrom the peer port (at id),
126 pass it to the bus. */
127 virtual void recvFunctional(Packet *pkt)
128 { pkt->setSrc(id); bus->recvFunctional(pkt); }
129
130 /** When reciving a status changefrom the peer port (at id),
131 pass it to the bus. */
132 virtual void recvStatusChange(Status status)
133 { bus->recvStatusChange(status, id); }
134
135 /** When reciving a retry from the peer port (at id),
136 pass it to the bus. */
137 virtual void recvRetry()
138 { bus->recvRetry(id); }
139
140 // This should return all the 'owned' addresses that are
141 // downstream from this bus, yes? That is, the union of all
142 // the 'owned' address ranges of all the other interfaces on
143 // this bus...
144 virtual void getDeviceAddressRanges(AddrRangeList &resp,
145 AddrRangeList &snoop)
146 { bus->addressRanges(resp, snoop, id); }
147
148 // Hack to make translating port work without changes
149 virtual int deviceBlockSize() { return 32; }
150
151 };
152
153 /** An array of pointers to the peer port interfaces
154 connected to this bus.*/
155 std::vector<Port*> interfaces;
156
157 /** An array of pointers to ports that retry should be called on because the
158 * original send failed for whatever reason.*/
159 std::list<Port*> retryList;
160
161 public:
162
163 /** A function used to return the port associated with this bus object. */
164 virtual Port *getPort(const std::string &if_name);
165
166 virtual void init();
167
168 Bus(const std::string &n, int bus_id)
169 : MemObject(n), busId(bus_id) {}
170
171 };
172
173 #endif //__MEM_BUS_HH__