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