xbar.hh revision 2568
111731Sjason@lowepower.com/*
211731Sjason@lowepower.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
311731Sjason@lowepower.com * All rights reserved.
411731Sjason@lowepower.com *
511731Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without
611731Sjason@lowepower.com * modification, are permitted provided that the following conditions are
711731Sjason@lowepower.com * met: redistributions of source code must retain the above copyright
811731Sjason@lowepower.com * notice, this list of conditions and the following disclaimer;
911731Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright
1011731Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the
1111731Sjason@lowepower.com * documentation and/or other materials provided with the distribution;
1211731Sjason@lowepower.com * neither the name of the copyright holders nor the names of its
1311731Sjason@lowepower.com * contributors may be used to endorse or promote products derived from
1411731Sjason@lowepower.com * this software without specific prior written permission.
1511731Sjason@lowepower.com *
1611731Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1711731Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1811731Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1911731Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2011731Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2111731Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2211731Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2311731Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2411731Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2511731Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2611731Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711731Sjason@lowepower.com */
2811731Sjason@lowepower.com
2911731Sjason@lowepower.com/**
3011731Sjason@lowepower.com * @file Decleration of a bus object.
3111731Sjason@lowepower.com */
3211731Sjason@lowepower.com
3311731Sjason@lowepower.com#ifndef __MEM_BUS_HH__
3411731Sjason@lowepower.com#define __MEM_BUS_HH__
3511731Sjason@lowepower.com
3611731Sjason@lowepower.com#include <string>
3711731Sjason@lowepower.com#include <list>
3811731Sjason@lowepower.com#include <inttypes.h>
3911731Sjason@lowepower.com
4011731Sjason@lowepower.com#include "base/range.hh"
4111731Sjason@lowepower.com#include "mem/mem_object.hh"
4211731Sjason@lowepower.com#include "mem/packet.hh"
4311731Sjason@lowepower.com#include "mem/port.hh"
4411731Sjason@lowepower.com#include "mem/request.hh"
4511731Sjason@lowepower.com
4611731Sjason@lowepower.comclass Bus : public MemObject
4711731Sjason@lowepower.com{
4811731Sjason@lowepower.com    /** a globally unique id for this bus. */
4911731Sjason@lowepower.com    int busId;
5011731Sjason@lowepower.com
5111731Sjason@lowepower.com    struct DevMap {
5211731Sjason@lowepower.com        int portId;
5311731Sjason@lowepower.com        Range<Addr> range;
5411731Sjason@lowepower.com    };
5511731Sjason@lowepower.com    std::vector<DevMap> portList;
5611731Sjason@lowepower.com
5711731Sjason@lowepower.com
5811731Sjason@lowepower.com    /** Function called by the port when the bus is recieving a Timing
5911731Sjason@lowepower.com        transaction.*/
6011731Sjason@lowepower.com    bool recvTiming(Packet &pkt, int id);
6111731Sjason@lowepower.com
6211731Sjason@lowepower.com    /** Function called by the port when the bus is recieving a Atomic
6311731Sjason@lowepower.com        transaction.*/
6411731Sjason@lowepower.com    Tick recvAtomic(Packet &pkt, int id);
6511731Sjason@lowepower.com
6611731Sjason@lowepower.com    /** Function called by the port when the bus is recieving a Functional
6711731Sjason@lowepower.com        transaction.*/
6811731Sjason@lowepower.com    void recvFunctional(Packet &pkt, int id);
6911731Sjason@lowepower.com
7011731Sjason@lowepower.com    /** Function called by the port when the bus is recieving a status change.*/
7111731Sjason@lowepower.com    void recvStatusChange(Port::Status status, int id);
7211731Sjason@lowepower.com
7311731Sjason@lowepower.com    /** Find which port connected to this bus (if any) should be given a packet
7411731Sjason@lowepower.com     * with this address.
7511731Sjason@lowepower.com     * @param addr Address to find port for.
7611731Sjason@lowepower.com     * @param id Id of the port this packet was received from (to prevent
7711731Sjason@lowepower.com     *             loops)
7811731Sjason@lowepower.com     * @return pointer to port that the packet should be sent out of.
7911731Sjason@lowepower.com     */
8011731Sjason@lowepower.com    Port *
8111731Sjason@lowepower.com    Bus::findPort(Addr addr, int id);
8211731Sjason@lowepower.com
8311731Sjason@lowepower.com    /** Process address range request.
8411731Sjason@lowepower.com     * @param resp addresses that we can respond to
8511731Sjason@lowepower.com     * @param snoop addresses that we would like to snoop
8611731Sjason@lowepower.com     * @param id ide of the busport that made the request.
8711731Sjason@lowepower.com     */
8811731Sjason@lowepower.com    void addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id);
8911731Sjason@lowepower.com
9011731Sjason@lowepower.com
9111731Sjason@lowepower.com    /** Decleration of the buses port type, one will be instantiated for each
9211731Sjason@lowepower.com        of the interfaces connecting to the bus. */
9311731Sjason@lowepower.com    class BusPort : public Port
9411731Sjason@lowepower.com    {
9511731Sjason@lowepower.com        /** A pointer to the bus to which this port belongs. */
9611731Sjason@lowepower.com        Bus *bus;
9711731Sjason@lowepower.com
9811731Sjason@lowepower.com        /** A id to keep track of the intercafe ID this port is connected to. */
9911731Sjason@lowepower.com        int id;
10011731Sjason@lowepower.com
10111731Sjason@lowepower.com      public:
10211731Sjason@lowepower.com
10311731Sjason@lowepower.com        /** Constructor for the BusPort.*/
10411731Sjason@lowepower.com        BusPort(Bus *_bus, int _id)
10511731Sjason@lowepower.com            : bus(_bus), id(_id)
10611731Sjason@lowepower.com        { }
10711731Sjason@lowepower.com
10811731Sjason@lowepower.com      protected:
10911731Sjason@lowepower.com
11011731Sjason@lowepower.com        /** When reciving a timing request from the peer port (at id),
11111731Sjason@lowepower.com            pass it to the bus. */
11211731Sjason@lowepower.com        virtual bool recvTiming(Packet &pkt)
11311731Sjason@lowepower.com        { return bus->recvTiming(pkt, id); }
11411731Sjason@lowepower.com
11511731Sjason@lowepower.com        /** When reciving a Atomic requestfrom the peer port (at id),
11611731Sjason@lowepower.com            pass it to the bus. */
11711731Sjason@lowepower.com        virtual Tick recvAtomic(Packet &pkt)
11811731Sjason@lowepower.com        { return bus->recvAtomic(pkt, id); }
11912137Sar4jc@virginia.edu
12011731Sjason@lowepower.com        /** When reciving a Functional requestfrom the peer port (at id),
12111731Sjason@lowepower.com            pass it to the bus. */
12211731Sjason@lowepower.com        virtual void recvFunctional(Packet &pkt)
12312137Sar4jc@virginia.edu        { bus->recvFunctional(pkt, id); }
12411731Sjason@lowepower.com
12511731Sjason@lowepower.com        /** When reciving a status changefrom the peer port (at id),
12611731Sjason@lowepower.com            pass it to the bus. */
12711731Sjason@lowepower.com        virtual void recvStatusChange(Status status)
12811731Sjason@lowepower.com        { bus->recvStatusChange(status, id); }
12911731Sjason@lowepower.com
13011731Sjason@lowepower.com        // This should return all the 'owned' addresses that are
13111731Sjason@lowepower.com        // downstream from this bus, yes?  That is, the union of all
13211731Sjason@lowepower.com        // the 'owned' address ranges of all the other interfaces on
13311731Sjason@lowepower.com        // this bus...
13411731Sjason@lowepower.com        virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
13511731Sjason@lowepower.com        { bus->addressRanges(resp, snoop, id); }
13611731Sjason@lowepower.com
13711731Sjason@lowepower.com        // Hack to make translating port work without changes
13811731Sjason@lowepower.com        virtual int deviceBlockSize() { return 32; }
13911731Sjason@lowepower.com
14011731Sjason@lowepower.com    };
14111731Sjason@lowepower.com
14211731Sjason@lowepower.com    /** An array of pointers to the peer port interfaces
14311731Sjason@lowepower.com        connected to this bus.*/
14411731Sjason@lowepower.com    std::vector<Port*> interfaces;
14511731Sjason@lowepower.com
14611731Sjason@lowepower.com  public:
14711731Sjason@lowepower.com
14811731Sjason@lowepower.com    /** A function used to return the port associated with this bus object. */
14911731Sjason@lowepower.com    virtual Port *getPort(const std::string &if_name)
15011731Sjason@lowepower.com    {
15111731Sjason@lowepower.com        // if_name ignored?  forced to be empty?
15211731Sjason@lowepower.com        int id = interfaces.size();
15311731Sjason@lowepower.com        interfaces.push_back(new BusPort(this, id));
15411731Sjason@lowepower.com        return interfaces.back();
15511731Sjason@lowepower.com    }
15611731Sjason@lowepower.com
15711731Sjason@lowepower.com    virtual void init();
15811731Sjason@lowepower.com
15911731Sjason@lowepower.com    Bus(const std::string &n, int bus_id)
16011731Sjason@lowepower.com        : MemObject(n), busId(bus_id)  {}
16111731Sjason@lowepower.com
16211731Sjason@lowepower.com};
16311731Sjason@lowepower.com
16411731Sjason@lowepower.com#endif //__MEM_BUS_HH__
16511731Sjason@lowepower.com