Minor fixes for full-system timing memory.
[gem5.git] / src / mem / bus.cc
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 Definition of a bus object.
31 */
32
33
34 #include "base/trace.hh"
35 #include "mem/bus.hh"
36 #include "sim/builder.hh"
37
38 /** Get the ranges of anyone that we are connected to. */
39 void
40 Bus::init()
41 {
42 std::vector<Port*>::iterator intIter;
43 for (intIter = interfaces.begin(); intIter != interfaces.end(); intIter++)
44 (*intIter)->sendStatusChange(Port::RangeChange);
45 }
46
47
48 /** Function called by the port when the bus is recieving a Timing
49 * transaction.*/
50 bool
51 Bus::recvTiming(Packet *pkt)
52 {
53 Port *port;
54 if (pkt->dest == Packet::Broadcast) {
55 port = findPort(pkt->addr, pkt->src);
56 } else {
57 assert(pkt->dest >= 0 && pkt->dest < interfaces.size());
58 assert(pkt->dest != pkt->src); // catch infinite loops
59 port = interfaces[pkt->dest];
60 }
61 return port->sendTiming(pkt);
62 }
63
64 Port *
65 Bus::findPort(Addr addr, int id)
66 {
67 /* An interval tree would be a better way to do this. --ali. */
68 int dest_id = -1;
69 int i = 0;
70 bool found = false;
71
72 while (i < portList.size() && !found)
73 {
74 if (portList[i].range == addr) {
75 dest_id = portList[i].portId;
76 found = true;
77 DPRINTF(Bus, "Found Addr: %llx on device %d\n", addr, dest_id);
78 }
79 i++;
80 }
81 if (dest_id == -1)
82 panic("Unable to find destination for addr: %llx", addr);
83
84 // we shouldn't be sending this back to where it came from
85 assert(dest_id != id);
86
87 return interfaces[dest_id];
88 }
89
90 /** Function called by the port when the bus is recieving a Atomic
91 * transaction.*/
92 Tick
93 Bus::recvAtomic(Packet *pkt)
94 {
95 assert(pkt->dest == Packet::Broadcast);
96 return findPort(pkt->addr, pkt->src)->sendAtomic(pkt);
97 }
98
99 /** Function called by the port when the bus is recieving a Functional
100 * transaction.*/
101 void
102 Bus::recvFunctional(Packet *pkt)
103 {
104 assert(pkt->dest == Packet::Broadcast);
105 findPort(pkt->addr, pkt->src)->sendFunctional(pkt);
106 }
107
108 /** Function called by the port when the bus is recieving a status change.*/
109 void
110 Bus::recvStatusChange(Port::Status status, int id)
111 {
112 DPRINTF(Bus, "Bus %d recieved status change from device id %d\n",
113 busId, id);
114 assert(status == Port::RangeChange &&
115 "The other statuses need to be implemented.");
116
117 assert(id < interfaces.size() && id >= 0);
118 int x;
119 Port *port = interfaces[id];
120 AddrRangeList ranges;
121 AddrRangeList snoops;
122 AddrRangeIter iter;
123 std::vector<DevMap>::iterator portIter;
124
125 // Clean out any previously existent ids
126 for (portIter = portList.begin(); portIter != portList.end(); ) {
127 if (portIter->portId == id)
128 portIter = portList.erase(portIter);
129 else
130 portIter++;
131 }
132
133 port->getPeerAddressRanges(ranges, snoops);
134
135 // not dealing with snooping yet either
136 assert(snoops.size() == 0);
137 for(iter = ranges.begin(); iter != ranges.end(); iter++) {
138 DevMap dm;
139 dm.portId = id;
140 dm.range = *iter;
141
142 DPRINTF(MMU, "Adding range %llx - %llx for id %d\n", dm.range.start,
143 dm.range.end, id);
144 portList.push_back(dm);
145 }
146 DPRINTF(MMU, "port list has %d entries\n", portList.size());
147
148 // tell all our peers that our address range has changed.
149 // Don't tell the device that caused this change, it already knows
150 for (x = 0; x < interfaces.size(); x++)
151 if (x != id)
152 interfaces[x]->sendStatusChange(Port::RangeChange);
153 }
154
155 void
156 Bus::addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id)
157 {
158 std::vector<DevMap>::iterator portIter;
159
160 resp.clear();
161 snoop.clear();
162
163 DPRINTF(Bus, "Bus id %d recieved address range request returning\n",
164 busId);
165 for (portIter = portList.begin(); portIter != portList.end(); portIter++) {
166 if (portIter->portId != id) {
167 resp.push_back(portIter->range);
168 DPRINTF(Bus, "-- %#llX : %#llX\n", portIter->range.start,
169 portIter->range.end);
170 }
171 }
172 }
173
174 BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bus)
175
176 Param<int> bus_id;
177
178 END_DECLARE_SIM_OBJECT_PARAMS(Bus)
179
180 BEGIN_INIT_SIM_OBJECT_PARAMS(Bus)
181 INIT_PARAM(bus_id, "a globally unique bus id")
182 END_INIT_SIM_OBJECT_PARAMS(Bus)
183
184 CREATE_SIM_OBJECT(Bus)
185 {
186 return new Bus(getInstanceName(), bus_id);
187 }
188
189 REGISTER_SIM_OBJECT("Bus", Bus)