xbar.hh revision 2568
17118Sgblack@eecs.umich.edu/*
27118Sgblack@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
37118Sgblack@eecs.umich.edu * All rights reserved.
47118Sgblack@eecs.umich.edu *
57118Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
67118Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
77118Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
87118Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
97118Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
107118Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
117118Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
127118Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
137118Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
147118Sgblack@eecs.umich.edu * this software without specific prior written permission.
156253Sgblack@eecs.umich.edu *
166253Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176253Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186253Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196253Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206253Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216253Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226253Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236253Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246253Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256253Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266253Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276253Sgblack@eecs.umich.edu */
286253Sgblack@eecs.umich.edu
296253Sgblack@eecs.umich.edu/**
306253Sgblack@eecs.umich.edu * @file Decleration of a bus object.
316253Sgblack@eecs.umich.edu */
326253Sgblack@eecs.umich.edu
336253Sgblack@eecs.umich.edu#ifndef __MEM_BUS_HH__
346253Sgblack@eecs.umich.edu#define __MEM_BUS_HH__
356253Sgblack@eecs.umich.edu
366253Sgblack@eecs.umich.edu#include <string>
376253Sgblack@eecs.umich.edu#include <list>
386253Sgblack@eecs.umich.edu#include <inttypes.h>
396253Sgblack@eecs.umich.edu
406253Sgblack@eecs.umich.edu#include "base/range.hh"
416253Sgblack@eecs.umich.edu#include "mem/mem_object.hh"
426253Sgblack@eecs.umich.edu#include "mem/packet.hh"
436253Sgblack@eecs.umich.edu#include "mem/port.hh"
446253Sgblack@eecs.umich.edu#include "mem/request.hh"
456253Sgblack@eecs.umich.edu
466253Sgblack@eecs.umich.educlass Bus : public MemObject
476253Sgblack@eecs.umich.edu{
486253Sgblack@eecs.umich.edu    /** a globally unique id for this bus. */
497118Sgblack@eecs.umich.edu    int busId;
507205Sgblack@eecs.umich.edu
517205Sgblack@eecs.umich.edu    struct DevMap {
527205Sgblack@eecs.umich.edu        int portId;
537205Sgblack@eecs.umich.edu        Range<Addr> range;
547205Sgblack@eecs.umich.edu    };
557205Sgblack@eecs.umich.edu    std::vector<DevMap> portList;
567205Sgblack@eecs.umich.edu
577205Sgblack@eecs.umich.edu
587205Sgblack@eecs.umich.edu    /** Function called by the port when the bus is recieving a Timing
597205Sgblack@eecs.umich.edu        transaction.*/
607205Sgblack@eecs.umich.edu    bool recvTiming(Packet &pkt, int id);
617205Sgblack@eecs.umich.edu
627205Sgblack@eecs.umich.edu    /** Function called by the port when the bus is recieving a Atomic
637205Sgblack@eecs.umich.edu        transaction.*/
647205Sgblack@eecs.umich.edu    Tick recvAtomic(Packet &pkt, int id);
657205Sgblack@eecs.umich.edu
667291Sgblack@eecs.umich.edu    /** Function called by the port when the bus is recieving a Functional
677291Sgblack@eecs.umich.edu        transaction.*/
687291Sgblack@eecs.umich.edu    void recvFunctional(Packet &pkt, int id);
697291Sgblack@eecs.umich.edu
707291Sgblack@eecs.umich.edu    /** Function called by the port when the bus is recieving a status change.*/
717291Sgblack@eecs.umich.edu    void recvStatusChange(Port::Status status, int id);
727291Sgblack@eecs.umich.edu
737291Sgblack@eecs.umich.edu    /** Find which port connected to this bus (if any) should be given a packet
747291Sgblack@eecs.umich.edu     * with this address.
757291Sgblack@eecs.umich.edu     * @param addr Address to find port for.
767291Sgblack@eecs.umich.edu     * @param id Id of the port this packet was received from (to prevent
777291Sgblack@eecs.umich.edu     *             loops)
787291Sgblack@eecs.umich.edu     * @return pointer to port that the packet should be sent out of.
797291Sgblack@eecs.umich.edu     */
807291Sgblack@eecs.umich.edu    Port *
817291Sgblack@eecs.umich.edu    Bus::findPort(Addr addr, int id);
827291Sgblack@eecs.umich.edu
837291Sgblack@eecs.umich.edu    /** Process address range request.
847291Sgblack@eecs.umich.edu     * @param resp addresses that we can respond to
857291Sgblack@eecs.umich.edu     * @param snoop addresses that we would like to snoop
867291Sgblack@eecs.umich.edu     * @param id ide of the busport that made the request.
877291Sgblack@eecs.umich.edu     */
887291Sgblack@eecs.umich.edu    void addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id);
897291Sgblack@eecs.umich.edu
907132Sgblack@eecs.umich.edu
917118Sgblack@eecs.umich.edu    /** Decleration of the buses port type, one will be instantiated for each
927118Sgblack@eecs.umich.edu        of the interfaces connecting to the bus. */
937118Sgblack@eecs.umich.edu    class BusPort : public Port
947118Sgblack@eecs.umich.edu    {
957118Sgblack@eecs.umich.edu        /** A pointer to the bus to which this port belongs. */
967118Sgblack@eecs.umich.edu        Bus *bus;
977118Sgblack@eecs.umich.edu
987118Sgblack@eecs.umich.edu        /** A id to keep track of the intercafe ID this port is connected to. */
997118Sgblack@eecs.umich.edu        int id;
1007118Sgblack@eecs.umich.edu
1017118Sgblack@eecs.umich.edu      public:
1027118Sgblack@eecs.umich.edu
1037118Sgblack@eecs.umich.edu        /** Constructor for the BusPort.*/
1047118Sgblack@eecs.umich.edu        BusPort(Bus *_bus, int _id)
1057132Sgblack@eecs.umich.edu            : bus(_bus), id(_id)
1067132Sgblack@eecs.umich.edu        { }
1077118Sgblack@eecs.umich.edu
1087118Sgblack@eecs.umich.edu      protected:
1097118Sgblack@eecs.umich.edu
1107118Sgblack@eecs.umich.edu        /** When reciving a timing request from the peer port (at id),
1117118Sgblack@eecs.umich.edu            pass it to the bus. */
1127118Sgblack@eecs.umich.edu        virtual bool recvTiming(Packet &pkt)
1137118Sgblack@eecs.umich.edu        { return bus->recvTiming(pkt, id); }
1147118Sgblack@eecs.umich.edu
1157279Sgblack@eecs.umich.edu        /** When reciving a Atomic requestfrom the peer port (at id),
1167279Sgblack@eecs.umich.edu            pass it to the bus. */
1177279Sgblack@eecs.umich.edu        virtual Tick recvAtomic(Packet &pkt)
1187279Sgblack@eecs.umich.edu        { return bus->recvAtomic(pkt, id); }
1197279Sgblack@eecs.umich.edu
1207279Sgblack@eecs.umich.edu        /** When reciving a Functional requestfrom the peer port (at id),
1217118Sgblack@eecs.umich.edu            pass it to the bus. */
1227118Sgblack@eecs.umich.edu        virtual void recvFunctional(Packet &pkt)
1237118Sgblack@eecs.umich.edu        { bus->recvFunctional(pkt, id); }
1247118Sgblack@eecs.umich.edu
1257132Sgblack@eecs.umich.edu        /** When reciving a status changefrom the peer port (at id),
1267118Sgblack@eecs.umich.edu            pass it to the bus. */
1277118Sgblack@eecs.umich.edu        virtual void recvStatusChange(Status status)
1287118Sgblack@eecs.umich.edu        { bus->recvStatusChange(status, id); }
1297118Sgblack@eecs.umich.edu
1307132Sgblack@eecs.umich.edu        // This should return all the 'owned' addresses that are
1317132Sgblack@eecs.umich.edu        // downstream from this bus, yes?  That is, the union of all
1327132Sgblack@eecs.umich.edu        // the 'owned' address ranges of all the other interfaces on
1337118Sgblack@eecs.umich.edu        // this bus...
1347118Sgblack@eecs.umich.edu        virtual void getDeviceAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
1357118Sgblack@eecs.umich.edu        { bus->addressRanges(resp, snoop, id); }
1367118Sgblack@eecs.umich.edu
1377118Sgblack@eecs.umich.edu        // Hack to make translating port work without changes
1387118Sgblack@eecs.umich.edu        virtual int deviceBlockSize() { return 32; }
1397118Sgblack@eecs.umich.edu
1407118Sgblack@eecs.umich.edu    };
1417118Sgblack@eecs.umich.edu
1427118Sgblack@eecs.umich.edu    /** An array of pointers to the peer port interfaces
1437118Sgblack@eecs.umich.edu        connected to this bus.*/
1447118Sgblack@eecs.umich.edu    std::vector<Port*> interfaces;
1457279Sgblack@eecs.umich.edu
1467279Sgblack@eecs.umich.edu  public:
1477279Sgblack@eecs.umich.edu
1487279Sgblack@eecs.umich.edu    /** A function used to return the port associated with this bus object. */
1497279Sgblack@eecs.umich.edu    virtual Port *getPort(const std::string &if_name)
1507279Sgblack@eecs.umich.edu    {
1517279Sgblack@eecs.umich.edu        // if_name ignored?  forced to be empty?
1527279Sgblack@eecs.umich.edu        int id = interfaces.size();
1537279Sgblack@eecs.umich.edu        interfaces.push_back(new BusPort(this, id));
1547279Sgblack@eecs.umich.edu        return interfaces.back();
1557279Sgblack@eecs.umich.edu    }
1567279Sgblack@eecs.umich.edu
1577279Sgblack@eecs.umich.edu    virtual void init();
1587279Sgblack@eecs.umich.edu
1597279Sgblack@eecs.umich.edu    Bus(const std::string &n, int bus_id)
1607279Sgblack@eecs.umich.edu        : MemObject(n), busId(bus_id)  {}
1617279Sgblack@eecs.umich.edu
1627279Sgblack@eecs.umich.edu};
1637279Sgblack@eecs.umich.edu
1647279Sgblack@eecs.umich.edu#endif //__MEM_BUS_HH__
1657279Sgblack@eecs.umich.edu