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"
38 /** Get the ranges of anyone that we are connected to. */
42 std::vector
<Port
*>::iterator intIter
;
43 for (intIter
= interfaces
.begin(); intIter
!= interfaces
.end(); intIter
++)
44 (*intIter
)->sendStatusChange(Port::RangeChange
);
48 /** Function called by the port when the bus is recieving a Timing
51 Bus::recvTiming(Packet
*pkt
)
54 if (pkt
->dest
== Packet::Broadcast
) {
55 port
= findPort(pkt
->addr
, pkt
->src
);
57 assert(pkt
->dest
>= 0 && pkt
->dest
< interfaces
.size());
58 assert(pkt
->dest
!= pkt
->src
); // catch infinite loops
59 port
= interfaces
[pkt
->dest
];
61 return port
->sendTiming(pkt
);
65 Bus::findPort(Addr addr
, int id
)
67 /* An interval tree would be a better way to do this. --ali. */
72 while (i
< portList
.size() && !found
)
74 if (portList
[i
].range
== addr
) {
75 dest_id
= portList
[i
].portId
;
77 DPRINTF(Bus
, "Found Addr: %llx on device %d\n", addr
, dest_id
);
82 panic("Unable to find destination for addr: %llx", addr
);
84 // we shouldn't be sending this back to where it came from
85 assert(dest_id
!= id
);
87 return interfaces
[dest_id
];
90 /** Function called by the port when the bus is recieving a Atomic
93 Bus::recvAtomic(Packet
*pkt
)
95 assert(pkt
->dest
== Packet::Broadcast
);
96 return findPort(pkt
->addr
, pkt
->src
)->sendAtomic(pkt
);
99 /** Function called by the port when the bus is recieving a Functional
102 Bus::recvFunctional(Packet
*pkt
)
104 assert(pkt
->dest
== Packet::Broadcast
);
105 findPort(pkt
->addr
, pkt
->src
)->sendFunctional(pkt
);
108 /** Function called by the port when the bus is recieving a status change.*/
110 Bus::recvStatusChange(Port::Status status
, int id
)
112 DPRINTF(Bus
, "Bus %d recieved status change from device id %d\n",
114 assert(status
== Port::RangeChange
&&
115 "The other statuses need to be implemented.");
117 assert(id
< interfaces
.size() && id
>= 0);
119 Port
*port
= interfaces
[id
];
120 AddrRangeList ranges
;
121 AddrRangeList snoops
;
123 std::vector
<DevMap
>::iterator portIter
;
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
);
133 port
->getPeerAddressRanges(ranges
, snoops
);
135 // not dealing with snooping yet either
136 assert(snoops
.size() == 0);
137 for(iter
= ranges
.begin(); iter
!= ranges
.end(); iter
++) {
142 DPRINTF(MMU
, "Adding range %llx - %llx for id %d\n", dm
.range
.start
,
144 portList
.push_back(dm
);
146 DPRINTF(MMU
, "port list has %d entries\n", portList
.size());
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
++)
152 interfaces
[x
]->sendStatusChange(Port::RangeChange
);
156 Bus::addressRanges(AddrRangeList
&resp
, AddrRangeList
&snoop
, int id
)
158 std::vector
<DevMap
>::iterator portIter
;
163 DPRINTF(Bus
, "Bus id %d recieved address range request returning\n",
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
);
174 BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bus
)
178 END_DECLARE_SIM_OBJECT_PARAMS(Bus
)
180 BEGIN_INIT_SIM_OBJECT_PARAMS(Bus
)
181 INIT_PARAM(bus_id
, "a globally unique bus id")
182 END_INIT_SIM_OBJECT_PARAMS(Bus
)
184 CREATE_SIM_OBJECT(Bus
)
186 return new Bus(getInstanceName(), bus_id
);
189 REGISTER_SIM_OBJECT("Bus", Bus
)