bridge.hh revision 4870
1/* 2 * Copyright (c) 2006 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: Ali Saidi 29 * Steve Reinhardt 30 */ 31 32/** 33 * @file 34 * Declaration of a simple bus bridge object with no buffering 35 */ 36 37#ifndef __MEM_BRIDGE_HH__ 38#define __MEM_BRIDGE_HH__ 39 40#include <string> 41#include <list> 42#include <inttypes.h> 43#include <queue> 44 45#include "mem/mem_object.hh" 46#include "mem/packet.hh" 47#include "mem/port.hh" 48#include "sim/eventq.hh" 49 50class Bridge : public MemObject 51{ 52 protected: 53 /** Declaration of the buses port type, one will be instantiated for each 54 of the interfaces connecting to the bus. */ 55 class BridgePort : public Port 56 { 57 /** A pointer to the bridge to which this port belongs. */ 58 Bridge *bridge; 59 60 /** 61 * Pointer to the port on the other side of the bridge 62 * (connected to the other bus). 63 */ 64 BridgePort *otherPort; 65 66 /** Minimum delay though this bridge. */ 67 Tick delay; 68 69 /** Min delay to respond to a nack. */ 70 Tick nackDelay; 71 72 bool fixPartialWrite; 73 74 class PacketBuffer : public Packet::SenderState { 75 76 public: 77 Tick ready; 78 PacketPtr pkt; 79 Packet::SenderState *origSenderState; 80 short origSrc; 81 bool expectResponse; 82 83 PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false) 84 : ready(t), pkt(_pkt), 85 origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()), 86 expectResponse(_pkt->needsResponse() && !nack) 87 88 { 89 if (!pkt->isResponse() && !nack && !pkt->wasNacked()) 90 pkt->senderState = this; 91 } 92 93 void fixResponse(PacketPtr pkt) 94 { 95 assert(pkt->senderState == this); 96 pkt->setDest(origSrc); 97 pkt->senderState = origSenderState; 98 } 99 }; 100 101 /** 102 * Outbound packet queue. Packets are held in this queue for a 103 * specified delay to model the processing delay of the 104 * bridge. 105 */ 106 std::list<PacketBuffer*> sendQueue; 107 108 int outstandingResponses; 109 int queuedRequests; 110 111 /** If we're waiting for a retry to happen.*/ 112 bool inRetry; 113 114 /** Max queue size for outbound packets */ 115 int reqQueueLimit; 116 117 /** Max queue size for reserved responses. */ 118 int respQueueLimit; 119 120 /** 121 * Is this side blocked from accepting outbound packets? 122 */ 123 bool respQueueFull(); 124 bool reqQueueFull(); 125 126 void queueForSendTiming(PacketPtr pkt); 127 128 void finishSend(PacketBuffer *buf); 129 130 void nackRequest(PacketPtr pkt); 131 132 /** 133 * Handle send event, scheduled when the packet at the head of 134 * the outbound queue is ready to transmit (for timing 135 * accesses only). 136 */ 137 void trySend(); 138 139 class SendEvent : public Event 140 { 141 BridgePort *port; 142 143 public: 144 SendEvent(BridgePort *p) 145 : Event(&mainEventQueue), port(p) {} 146 147 virtual void process() { port->trySend(); } 148 149 virtual const char *description() { return "bridge send event"; } 150 }; 151 152 SendEvent sendEvent; 153 154 public: 155 /** Constructor for the BusPort.*/ 156 BridgePort(const std::string &_name, Bridge *_bridge, 157 BridgePort *_otherPort, int _delay, int _nack_delay, 158 int _req_limit, int _resp_limit, bool fix_partial_write); 159 160 protected: 161 162 /** When receiving a timing request from the peer port, 163 pass it to the bridge. */ 164 virtual bool recvTiming(PacketPtr pkt); 165 166 /** When receiving a retry request from the peer port, 167 pass it to the bridge. */ 168 virtual void recvRetry(); 169 170 /** When receiving a Atomic requestfrom the peer port, 171 pass it to the bridge. */ 172 virtual Tick recvAtomic(PacketPtr pkt); 173 174 /** When receiving a Functional request from the peer port, 175 pass it to the bridge. */ 176 virtual void recvFunctional(PacketPtr pkt); 177 178 /** When receiving a status changefrom the peer port, 179 pass it to the bridge. */ 180 virtual void recvStatusChange(Status status); 181 182 /** When receiving a address range request the peer port, 183 pass it to the bridge. */ 184 virtual void getDeviceAddressRanges(AddrRangeList &resp, 185 bool &snoop); 186 }; 187 188 BridgePort portA, portB; 189 190 /** If this bridge should acknowledge writes. */ 191 bool ackWrites; 192 193 public: 194 struct Params 195 { 196 std::string name; 197 int req_size_a; 198 int req_size_b; 199 int resp_size_a; 200 int resp_size_b; 201 Tick delay; 202 Tick nack_delay; 203 bool write_ack; 204 bool fix_partial_write_a; 205 bool fix_partial_write_b; 206 }; 207 208 protected: 209 Params *_params; 210 211 public: 212 const Params *params() const { return _params; } 213 214 /** A function used to return the port associated with this bus object. */ 215 virtual Port *getPort(const std::string &if_name, int idx = -1); 216 217 virtual void init(); 218 219 Bridge(Params *p); 220}; 221 222#endif //__MEM_BUS_HH__ 223