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 return port
->sendTiming(pkt
);
79 Bus::findPort(Addr addr
, int id
)
81 /* An interval tree would be a better way to do this. --ali. */
86 while (i
< portList
.size() && !found
)
88 if (portList
[i
].range
== addr
) {
89 dest_id
= portList
[i
].portId
;
91 DPRINTF(Bus
, " found addr 0x%llx on device %d\n", addr
, dest_id
);
96 panic("Unable to find destination for addr: %llx", addr
);
98 // we shouldn't be sending this back to where it came from
99 assert(dest_id
!= id
);
101 return interfaces
[dest_id
];
104 /** Function called by the port when the bus is receiving a Atomic
107 Bus::recvAtomic(Packet
*pkt
)
109 DPRINTF(Bus
, "recvAtomic: packet src %d dest %d addr 0x%x cmd %s\n",
110 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr(), pkt
->cmdString());
111 assert(pkt
->getDest() == Packet::Broadcast
);
112 return findPort(pkt
->getAddr(), pkt
->getSrc())->sendAtomic(pkt
);
115 /** Function called by the port when the bus is receiving a Functional
118 Bus::recvFunctional(Packet
*pkt
)
120 DPRINTF(Bus
, "recvFunctional: packet src %d dest %d addr 0x%x cmd %s\n",
121 pkt
->getSrc(), pkt
->getDest(), pkt
->getAddr(), pkt
->cmdString());
122 assert(pkt
->getDest() == Packet::Broadcast
);
123 findPort(pkt
->getAddr(), pkt
->getSrc())->sendFunctional(pkt
);
126 /** Function called by the port when the bus is receiving a status change.*/
128 Bus::recvStatusChange(Port::Status status
, int id
)
130 assert(status
== Port::RangeChange
&&
131 "The other statuses need to be implemented.");
133 DPRINTF(BusAddrRanges
, "received RangeChange from device id %d\n", id
);
135 assert(id
< interfaces
.size() && id
>= 0);
137 Port
*port
= interfaces
[id
];
138 AddrRangeList ranges
;
139 AddrRangeList snoops
;
141 std::vector
<DevMap
>::iterator portIter
;
143 // Clean out any previously existent ids
144 for (portIter
= portList
.begin(); portIter
!= portList
.end(); ) {
145 if (portIter
->portId
== id
)
146 portIter
= portList
.erase(portIter
);
151 port
->getPeerAddressRanges(ranges
, snoops
);
153 // not dealing with snooping yet either
154 assert(snoops
.size() == 0);
155 for(iter
= ranges
.begin(); iter
!= ranges
.end(); iter
++) {
160 DPRINTF(BusAddrRanges
, "Adding range %llx - %llx for id %d\n",
161 dm
.range
.start
, dm
.range
.end
, id
);
162 portList
.push_back(dm
);
164 DPRINTF(MMU
, "port list has %d entries\n", portList
.size());
166 // tell all our peers that our address range has changed.
167 // Don't tell the device that caused this change, it already knows
168 for (x
= 0; x
< interfaces
.size(); x
++)
170 interfaces
[x
]->sendStatusChange(Port::RangeChange
);
174 Bus::addressRanges(AddrRangeList
&resp
, AddrRangeList
&snoop
, int id
)
176 std::vector
<DevMap
>::iterator portIter
;
181 DPRINTF(BusAddrRanges
, "received address range request, returning:\n");
182 for (portIter
= portList
.begin(); portIter
!= portList
.end(); portIter
++) {
183 if (portIter
->portId
!= id
) {
184 resp
.push_back(portIter
->range
);
185 DPRINTF(BusAddrRanges
, " -- %#llX : %#llX\n",
186 portIter
->range
.start
, portIter
->range
.end
);
191 BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bus
)
195 END_DECLARE_SIM_OBJECT_PARAMS(Bus
)
197 BEGIN_INIT_SIM_OBJECT_PARAMS(Bus
)
198 INIT_PARAM(bus_id
, "a globally unique bus id")
199 END_INIT_SIM_OBJECT_PARAMS(Bus
)
201 CREATE_SIM_OBJECT(Bus
)
203 return new Bus(getInstanceName(), bus_id
);
206 REGISTER_SIM_OBJECT("Bus", Bus
)