coherent_xbar.hh revision 2381
1/*
2 * Copyright (c) 2002-2005 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 Decleration of a bus object.
31 */
32
33#ifndef __MEM_BUS_HH__
34#define __MEM_BUS_HH__
35
36#include <string>
37#include <list>
38#include <inttypes.h>
39
40#include "base/range.hh"
41#include "mem/mem_object.hh"
42#include "mem/packet.hh"
43
44class Bus : public MemObject
45{
46    /** Function called by the port when the bus is recieving a Timing
47        transaction.*/
48    SendResult recvTiming(Packet &pkt, int id);
49
50    /** Function called by the port when the bus is recieving a Atomic
51        transaction.*/
52    SendResult recvAtomic(Packet &pkt, int id);
53
54    /** Function called by the port when the bus is recieving a Functional
55        transaction.*/
56    SendResult recvFunctional(Packet &pkt, int id);
57
58    /** Function called by the port when the bus is recieving a status change.*/
59    void recvStatusChange(Port::Status status, int id);
60
61    /** Decleration of the buses port type, one will be instantiated for each
62        of the interfaces connecting to the bus. */
63    class BusPort : public Port
64    {
65        /** A pointer to the bus to which this port belongs. */
66        Bus *bus;
67
68        /** A id to keep track of the intercafe ID this port is connected to. */
69        int id;
70
71      public:
72
73        /** Constructor for the BusPort.*/
74        BusPort(Bus *_bus, int _id)
75            : bus(_bus), id(_id)
76        { }
77
78      protected:
79
80        /** When reciving a timing request from the peer port (at id),
81            pass it to the bus. */
82        virtual SendResult recvTiming(Packet &pkt)
83        { return bus->recvTiming(pkt, id); }
84
85        /** When reciving a Atomic requestfrom the peer port (at id),
86            pass it to the bus. */
87        virtual SendResult recvAtomic(Packet &pkt)
88        { return bus->recvAtomic(pkt, id); }
89
90        /** When reciving a Functional requestfrom the peer port (at id),
91            pass it to the bus. */
92        virtual SendResult recvFunctional(Packet &pkt)
93        { return bus->recvFunctional(pkt, id); }
94
95        /** When reciving a status changefrom the peer port (at id),
96            pass it to the bus. */
97        virtual void recvStatusChange(Status status)
98        { bus->recvStatusChange(status, id); }
99
100        // This should return all the 'owned' addresses that are
101        // downstream from this bus, yes?  That is, the union of all
102        // the 'owned' address ranges of all the other interfaces on
103        // this bus...
104        virtual void addressRanges(std::list<Range<Addr> > &range_list,
105                                   bool &owner);
106    };
107
108    /** A count of the number of interfaces connected to this bus. */
109    int num_interfaces;
110
111    /** An array of pointers to the peer port interfaces
112        connected to this bus.*/
113    Port *interfaces[];
114
115  public:
116
117    /** A function used to return the port associated with this bus object. */
118    virtual Port *getPort(const char *if_name)
119    {
120        // if_name ignored?  forced to be empty?
121        int id = num_interfaces++;
122        interfaces[id] = new BusPort(this, id);
123        return interfaces[id];
124    }
125};
126
127#endif //__MEM_BUS_HH__
128