coherent_xbar.hh revision 2568
13691Shsul@eecs.umich.edu/*
23691Shsul@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
33691Shsul@eecs.umich.edu * All rights reserved.
43691Shsul@eecs.umich.edu *
53691Shsul@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
63691Shsul@eecs.umich.edu * modification, are permitted provided that the following conditions are
73691Shsul@eecs.umich.edu * met: redistributions of source code must retain the above copyright
83691Shsul@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
93691Shsul@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
103691Shsul@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
113691Shsul@eecs.umich.edu * documentation and/or other materials provided with the distribution;
123691Shsul@eecs.umich.edu * neither the name of the copyright holders nor the names of its
133691Shsul@eecs.umich.edu * contributors may be used to endorse or promote products derived from
143691Shsul@eecs.umich.edu * this software without specific prior written permission.
153691Shsul@eecs.umich.edu *
163691Shsul@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173691Shsul@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183691Shsul@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193691Shsul@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203691Shsul@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213691Shsul@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223691Shsul@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233691Shsul@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243691Shsul@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253691Shsul@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263691Shsul@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273691Shsul@eecs.umich.edu */
283691Shsul@eecs.umich.edu
293691Shsul@eecs.umich.edu/**
303691Shsul@eecs.umich.edu * @file Decleration of a bus object.
316654Snate@binkert.org */
323691Shsul@eecs.umich.edu
333691Shsul@eecs.umich.edu#ifndef __MEM_BUS_HH__
343691Shsul@eecs.umich.edu#define __MEM_BUS_HH__
353691Shsul@eecs.umich.edu
363691Shsul@eecs.umich.edu#include <string>
373691Shsul@eecs.umich.edu#include <list>
387876Sgblack@eecs.umich.edu#include <inttypes.h>
398713Sandreas.hansson@arm.com
408713Sandreas.hansson@arm.com#include "base/range.hh"
418713Sandreas.hansson@arm.com#include "mem/mem_object.hh"
428713Sandreas.hansson@arm.com#include "mem/packet.hh"
438713Sandreas.hansson@arm.com#include "mem/port.hh"
448839Sandreas.hansson@arm.com#include "mem/request.hh"
458839Sandreas.hansson@arm.com
463691Shsul@eecs.umich.educlass Bus : public MemObject
473691Shsul@eecs.umich.edu{
483691Shsul@eecs.umich.edu    /** a globally unique id for this bus. */
493691Shsul@eecs.umich.edu    int busId;
507876Sgblack@eecs.umich.edu
518713Sandreas.hansson@arm.com    struct DevMap {
528713Sandreas.hansson@arm.com        int portId;
538839Sandreas.hansson@arm.com        Range<Addr> range;
548839Sandreas.hansson@arm.com    };
553691Shsul@eecs.umich.edu    std::vector<DevMap> portList;
568801Sgblack@eecs.umich.edu
573691Shsul@eecs.umich.edu
583691Shsul@eecs.umich.edu    /** Function called by the port when the bus is recieving a Timing
59        transaction.*/
60    bool recvTiming(Packet &pkt, int id);
61
62    /** Function called by the port when the bus is recieving a Atomic
63        transaction.*/
64    Tick recvAtomic(Packet &pkt, int id);
65
66    /** Function called by the port when the bus is recieving a Functional
67        transaction.*/
68    void recvFunctional(Packet &pkt, int id);
69
70    /** Function called by the port when the bus is recieving a status change.*/
71    void recvStatusChange(Port::Status status, int id);
72
73    /** Find which port connected to this bus (if any) should be given a packet
74     * with this address.
75     * @param addr Address to find port for.
76     * @param id Id of the port this packet was received from (to prevent
77     *             loops)
78     * @return pointer to port that the packet should be sent out of.
79     */
80    Port *
81    Bus::findPort(Addr addr, int id);
82
83    /** Process address range request.
84     * @param resp addresses that we can respond to
85     * @param snoop addresses that we would like to snoop
86     * @param id ide of the busport that made the request.
87     */
88    void addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id);
89
90
91    /** Decleration of the buses port type, one will be instantiated for each
92        of the interfaces connecting to the bus. */
93    class BusPort : public Port
94    {
95        /** A pointer to the bus to which this port belongs. */
96        Bus *bus;
97
98        /** A id to keep track of the intercafe ID this port is connected to. */
99        int id;
100
101      public:
102
103        /** Constructor for the BusPort.*/
104        BusPort(Bus *_bus, int _id)
105            : bus(_bus), id(_id)
106        { }
107
108      protected:
109
110        /** When reciving a timing request from the peer port (at id),
111            pass it to the bus. */
112        virtual bool recvTiming(Packet &pkt)
113        { return bus->recvTiming(pkt, id); }
114
115        /** When reciving a Atomic requestfrom the peer port (at id),
116            pass it to the bus. */
117        virtual Tick recvAtomic(Packet &pkt)
118        { return bus->recvAtomic(pkt, id); }
119
120        /** When reciving a Functional requestfrom the peer port (at id),
121            pass it to the bus. */
122        virtual void recvFunctional(Packet &pkt)
123        { bus->recvFunctional(pkt, id); }
124
125        /** When reciving a status changefrom the peer port (at id),
126            pass it to the bus. */
127        virtual void recvStatusChange(Status status)
128        { bus->recvStatusChange(status, id); }
129
130        // This should return all the 'owned' addresses that are
131        // downstream from this bus, yes?  That is, the union of all
132        // the 'owned' address ranges of all the other interfaces on
133        // this bus...
134        virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
135        { bus->addressRanges(resp, snoop, id); }
136
137        // Hack to make translating port work without changes
138        virtual int deviceBlockSize() { return 32; }
139
140    };
141
142    /** An array of pointers to the peer port interfaces
143        connected to this bus.*/
144    std::vector<Port*> interfaces;
145
146  public:
147
148    /** A function used to return the port associated with this bus object. */
149    virtual Port *getPort(const std::string &if_name)
150    {
151        // if_name ignored?  forced to be empty?
152        int id = interfaces.size();
153        interfaces.push_back(new BusPort(this, id));
154        return interfaces.back();
155    }
156
157    virtual void init();
158
159    Bus(const std::string &n, int bus_id)
160        : MemObject(n), busId(bus_id)  {}
161
162};
163
164#endif //__MEM_BUS_HH__
165