2 * Copyright (c) 2006 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.
30 * @file Definition of a bus object.
34 #include "base/trace.hh"
36 #include "sim/builder.hh"
39 Bus::getPort(const std::string
&if_name
)
41 // if_name ignored? forced to be empty?
42 int id
= interfaces
.size();
43 BusPort
*bp
= new BusPort(csprintf("%s-p%d", name(), id
), this, id
);
44 interfaces
.push_back(bp
);
48 /** Get the ranges of anyone that we are connected to. */
52 std::vector
<Port
*>::iterator intIter
;
53 for (intIter
= interfaces
.begin(); intIter
!= interfaces
.end(); intIter
++)
54 (*intIter
)->sendStatusChange(Port::RangeChange
);
58 /** Function called by the port when the bus is receiving a Timing
61 Bus::recvTiming(Packet
*pkt
)
64 DPRINTF(Bus
, "recvTiming: packet src %d dest %d addr 0x%x cmd %s\n",
65 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr(), pkt
->cmdString());
67 short dest
= pkt
->getDest();
68 if (dest
== Packet::Broadcast
) {
69 port
= findPort(pkt
->getAddr(), pkt
->getSrc());
71 assert(dest
>= 0 && dest
< interfaces
.size());
72 assert(dest
!= pkt
->getSrc()); // catch infinite loops
73 port
= interfaces
[dest
];
75 if (port
->sendTiming(pkt
)) {
76 // packet was successfully sent, just return true.
80 // packet not successfully sent
81 retryList
.push_back(interfaces
[pkt
->getSrc()]);
86 Bus::recvRetry(int id
)
88 // Go through all the elements on the list calling sendRetry on each
89 // This is not very efficient at all but it works. Ultimately we should end
90 // up with something that is more intelligent.
91 int initialSize
= retryList
.size();
95 for (i
= 0; i
< initialSize
; i
++) {
96 assert(retryList
.size() > 0);
97 p
= retryList
.front();
98 retryList
.pop_front();
105 Bus::findPort(Addr addr
, int id
)
107 /* An interval tree would be a better way to do this. --ali. */
112 while (i
< portList
.size() && !found
)
114 if (portList
[i
].range
== addr
) {
115 dest_id
= portList
[i
].portId
;
117 DPRINTF(Bus
, " found addr 0x%llx on device %d\n", addr
, dest_id
);
122 panic("Unable to find destination for addr: %llx", addr
);
124 // we shouldn't be sending this back to where it came from
125 assert(dest_id
!= id
);
127 return interfaces
[dest_id
];
130 /** Function called by the port when the bus is receiving a Atomic
133 Bus::recvAtomic(Packet
*pkt
)
135 DPRINTF(Bus
, "recvAtomic: packet src %d dest %d addr 0x%x cmd %s\n",
136 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr(), pkt
->cmdString());
137 assert(pkt
->getDest() == Packet::Broadcast
);
138 return findPort(pkt
->getAddr(), pkt
->getSrc())->sendAtomic(pkt
);
141 /** Function called by the port when the bus is receiving a Functional
144 Bus::recvFunctional(Packet
*pkt
)
146 DPRINTF(Bus
, "recvFunctional: packet src %d dest %d addr 0x%x cmd %s\n",
147 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr(), pkt
->cmdString());
148 assert(pkt
->getDest() == Packet::Broadcast
);
149 findPort(pkt
->getAddr(), pkt
->getSrc())->sendFunctional(pkt
);
152 /** Function called by the port when the bus is receiving a status change.*/
154 Bus::recvStatusChange(Port::Status status
, int id
)
156 assert(status
== Port::RangeChange
&&
157 "The other statuses need to be implemented.");
159 DPRINTF(BusAddrRanges
, "received RangeChange from device id %d\n", id
);
161 assert(id
< interfaces
.size() && id
>= 0);
163 Port
*port
= interfaces
[id
];
164 AddrRangeList ranges
;
165 AddrRangeList snoops
;
167 std::vector
<DevMap
>::iterator portIter
;
169 // Clean out any previously existent ids
170 for (portIter
= portList
.begin(); portIter
!= portList
.end(); ) {
171 if (portIter
->portId
== id
)
172 portIter
= portList
.erase(portIter
);
177 port
->getPeerAddressRanges(ranges
, snoops
);
179 // not dealing with snooping yet either
180 assert(snoops
.size() == 0);
181 for(iter
= ranges
.begin(); iter
!= ranges
.end(); iter
++) {
186 DPRINTF(BusAddrRanges
, "Adding range %llx - %llx for id %d\n",
187 dm
.range
.start
, dm
.range
.end
, id
);
188 portList
.push_back(dm
);
190 DPRINTF(MMU
, "port list has %d entries\n", portList
.size());
192 // tell all our peers that our address range has changed.
193 // Don't tell the device that caused this change, it already knows
194 for (x
= 0; x
< interfaces
.size(); x
++)
196 interfaces
[x
]->sendStatusChange(Port::RangeChange
);
200 Bus::addressRanges(AddrRangeList
&resp
, AddrRangeList
&snoop
, int id
)
202 std::vector
<DevMap
>::iterator portIter
;
207 DPRINTF(BusAddrRanges
, "received address range request, returning:\n");
208 for (portIter
= portList
.begin(); portIter
!= portList
.end(); portIter
++) {
209 if (portIter
->portId
!= id
) {
210 resp
.push_back(portIter
->range
);
211 DPRINTF(BusAddrRanges
, " -- %#llX : %#llX\n",
212 portIter
->range
.start
, portIter
->range
.end
);
217 BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bus
)
221 END_DECLARE_SIM_OBJECT_PARAMS(Bus
)
223 BEGIN_INIT_SIM_OBJECT_PARAMS(Bus
)
224 INIT_PARAM(bus_id
, "a globally unique bus id")
225 END_INIT_SIM_OBJECT_PARAMS(Bus
)
227 CREATE_SIM_OBJECT(Bus
)
229 return new Bus(getInstanceName(), bus_id
);
232 REGISTER_SIM_OBJECT("Bus", Bus
)