xbar.hh revision 2846
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 * Authors: Ron Dreslinski
29 *          Ali Saidi
30 */
31
32/**
33 * @file Decleration of a bus object.
34 */
35
36#ifndef __MEM_BUS_HH__
37#define __MEM_BUS_HH__
38
39#include <string>
40#include <list>
41#include <inttypes.h>
42
43#include "base/range.hh"
44#include "mem/mem_object.hh"
45#include "mem/packet.hh"
46#include "mem/port.hh"
47#include "mem/request.hh"
48
49class Bus : public MemObject
50{
51    /** a globally unique id for this bus. */
52    int busId;
53
54    static const int defaultId = -1;
55
56    struct DevMap {
57        int portId;
58        Range<Addr> range;
59    };
60    std::vector<DevMap> portList;
61    AddrRangeList defaultRange;
62
63
64    /** Function called by the port when the bus is recieving a Timing
65      transaction.*/
66    bool recvTiming(Packet *pkt);
67
68    /** Function called by the port when the bus is recieving a Atomic
69      transaction.*/
70    Tick recvAtomic(Packet *pkt);
71
72    /** Function called by the port when the bus is recieving a Functional
73        transaction.*/
74    void recvFunctional(Packet *pkt);
75
76    /** Timing function called by port when it is once again able to process
77     * requests. */
78    void recvRetry(int id);
79
80    /** Function called by the port when the bus is recieving a status change.*/
81    void recvStatusChange(Port::Status status, int id);
82
83    /** Find which port connected to this bus (if any) should be given a packet
84     * with this address.
85     * @param addr Address to find port for.
86     * @param id Id of the port this packet was received from (to prevent
87     *             loops)
88     * @return pointer to port that the packet should be sent out of.
89     */
90    Port *findPort(Addr addr, int id);
91
92    /** Process address range request.
93     * @param resp addresses that we can respond to
94     * @param snoop addresses that we would like to snoop
95     * @param id ide of the busport that made the request.
96     */
97    void addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id);
98
99
100    /** Decleration of the buses port type, one will be instantiated for each
101        of the interfaces connecting to the bus. */
102    class BusPort : public Port
103    {
104        /** A pointer to the bus to which this port belongs. */
105        Bus *bus;
106
107        /** A id to keep track of the intercafe ID this port is connected to. */
108        int id;
109
110      public:
111
112        /** Constructor for the BusPort.*/
113        BusPort(const std::string &_name, Bus *_bus, int _id)
114            : Port(_name), bus(_bus), id(_id)
115        { }
116
117      protected:
118
119        /** When reciving a timing request from the peer port (at id),
120            pass it to the bus. */
121        virtual bool recvTiming(Packet *pkt)
122        { pkt->setSrc(id); return bus->recvTiming(pkt); }
123
124        /** When reciving a Atomic requestfrom the peer port (at id),
125            pass it to the bus. */
126        virtual Tick recvAtomic(Packet *pkt)
127        { pkt->setSrc(id); return bus->recvAtomic(pkt); }
128
129        /** When reciving a Functional requestfrom the peer port (at id),
130            pass it to the bus. */
131        virtual void recvFunctional(Packet *pkt)
132        { pkt->setSrc(id); bus->recvFunctional(pkt); }
133
134        /** When reciving a status changefrom the peer port (at id),
135            pass it to the bus. */
136        virtual void recvStatusChange(Status status)
137        { bus->recvStatusChange(status, id); }
138
139        /** When reciving a retry from the peer port (at id),
140            pass it to the bus. */
141        virtual void recvRetry()
142        { bus->recvRetry(id); }
143
144        // This should return all the 'owned' addresses that are
145        // downstream from this bus, yes?  That is, the union of all
146        // the 'owned' address ranges of all the other interfaces on
147        // this bus...
148        virtual void getDeviceAddressRanges(AddrRangeList &resp,
149                                            AddrRangeList &snoop)
150        { bus->addressRanges(resp, snoop, id); }
151
152        // Hack to make translating port work without changes
153        virtual int deviceBlockSize() { return 32; }
154
155    };
156
157    /** An array of pointers to the peer port interfaces
158        connected to this bus.*/
159    std::vector<Port*> interfaces;
160
161    /** An array of pointers to ports that retry should be called on because the
162     * original send failed for whatever reason.*/
163    std::list<Port*> retryList;
164
165    /** Port that handles requests that don't match any of the interfaces.*/
166    Port *defaultPort;
167
168  public:
169
170    /** A function used to return the port associated with this bus object. */
171    virtual Port *getPort(const std::string &if_name, int idx = -1);
172
173    virtual void init();
174
175    Bus(const std::string &n, int bus_id)
176        : MemObject(n), busId(bus_id), defaultPort(NULL)  {}
177
178};
179
180#endif //__MEM_BUS_HH__
181