xbar.cc revision 2565
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/** Function called by the port when the bus is recieving a Timing
39 * transaction.*/
40bool
41Bus::recvTiming(Packet &pkt, int id)
42{
43
44    panic("I need to be implemented, but not right now.");
45}
46
47Port *
48Bus::findPort(Addr addr, int id)
49{
50    /* An interval tree would be a better way to do this. --ali. */
51    int dest_id = -1;
52    int i = 0;
53    bool found = false;
54
55    while (i < portList.size() && !found)
56    {
57        if (portList[i].range == addr) {
58            dest_id = portList[i].portId;
59            found = true;
60            DPRINTF(Bus, "Found Addr: %llx on device %d\n", addr, dest_id);
61        }
62        i++;
63    }
64    if (dest_id == -1)
65        panic("Unable to find destination for addr: %llx", addr);
66
67    // we shouldn't be sending this back to where it came from
68    assert(dest_id != id);
69
70    return interfaces[dest_id];
71}
72
73/** Function called by the port when the bus is recieving a Atomic
74 * transaction.*/
75Tick
76Bus::recvAtomic(Packet &pkt, int id)
77{
78    return findPort(pkt.addr, id)->sendAtomic(pkt);
79}
80
81/** Function called by the port when the bus is recieving a Functional
82 * transaction.*/
83void
84Bus::recvFunctional(Packet &pkt, int id)
85{
86    findPort(pkt.addr, id)->sendFunctional(pkt);
87}
88
89/** Function called by the port when the bus is recieving a status change.*/
90void
91Bus::recvStatusChange(Port::Status status, int id)
92{
93    assert(status == Port::RangeChange &&
94           "The other statuses need to be implemented.");
95
96    assert(id < interfaces.size() && id >= 0);
97    Port *port = interfaces[id];
98    AddrRangeList ranges;
99    AddrRangeList snoops;
100    AddrRangeIter iter;
101    std::vector<DevMap>::iterator portIter;
102
103    // Clean out any previously existent ids
104    for (portIter = portList.begin(); portIter != portList.end(); ) {
105        if (portIter->portId == id)
106            portIter = portList.erase(portIter);
107        else
108            portIter++;
109    }
110
111    port->getPeerAddressRanges(ranges, snoops);
112
113    // not dealing with snooping yet either
114    assert(snoops.size() == 0);
115    for(iter = ranges.begin(); iter != ranges.end(); iter++) {
116        DevMap dm;
117        dm.portId = id;
118        dm.range = *iter;
119
120        DPRINTF(MMU, "Adding range %llx - %llx for id %d\n", dm.range.start,
121                dm.range.end, id);
122        portList.push_back(dm);
123    }
124    DPRINTF(MMU, "port list has %d entries\n", portList.size());
125}
126
127void
128Bus::BusPort::addressRanges(AddrRangeList &resp, AddrRangeList &snoop)
129{
130    panic("I'm not implemented.\n");
131}
132
133BEGIN_DECLARE_SIM_OBJECT_PARAMS(Bus)
134
135    Param<int> bus_id;
136
137END_DECLARE_SIM_OBJECT_PARAMS(Bus)
138
139BEGIN_INIT_SIM_OBJECT_PARAMS(Bus)
140    INIT_PARAM(bus_id, "junk bus id")
141END_INIT_SIM_OBJECT_PARAMS(PhysicalMemory)
142
143CREATE_SIM_OBJECT(Bus)
144{
145    return new Bus(getInstanceName());
146}
147
148REGISTER_SIM_OBJECT("Bus", Bus)
149