bridge.hh revision 4432
12568SN/A/* 22568SN/A * Copyright (c) 2006 The Regents of The University of Michigan 32568SN/A * All rights reserved. 42568SN/A * 52568SN/A * Redistribution and use in source and binary forms, with or without 62568SN/A * modification, are permitted provided that the following conditions are 72568SN/A * met: redistributions of source code must retain the above copyright 82568SN/A * notice, this list of conditions and the following disclaimer; 92568SN/A * redistributions in binary form must reproduce the above copyright 102568SN/A * notice, this list of conditions and the following disclaimer in the 112568SN/A * documentation and/or other materials provided with the distribution; 122568SN/A * neither the name of the copyright holders nor the names of its 132568SN/A * contributors may be used to endorse or promote products derived from 142568SN/A * this software without specific prior written permission. 152568SN/A * 162568SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172568SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182568SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192568SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202568SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212568SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222568SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232568SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242568SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252568SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262568SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 292665Ssaidi@eecs.umich.edu * Steve Reinhardt 302568SN/A */ 312568SN/A 322568SN/A/** 332982Sstever@eecs.umich.edu * @file 342982Sstever@eecs.umich.edu * Declaration of a simple bus bridge object with no buffering 352568SN/A */ 362568SN/A 372568SN/A#ifndef __MEM_BRIDGE_HH__ 382568SN/A#define __MEM_BRIDGE_HH__ 392568SN/A 402568SN/A#include <string> 412568SN/A#include <list> 422568SN/A#include <inttypes.h> 432568SN/A#include <queue> 442568SN/A 452568SN/A#include "mem/mem_object.hh" 462568SN/A#include "mem/packet.hh" 472568SN/A#include "mem/port.hh" 482568SN/A#include "sim/eventq.hh" 492568SN/A 502568SN/Aclass Bridge : public MemObject 512568SN/A{ 522568SN/A protected: 532982Sstever@eecs.umich.edu /** Declaration of the buses port type, one will be instantiated for each 542568SN/A of the interfaces connecting to the bus. */ 552568SN/A class BridgePort : public Port 562568SN/A { 572643Sstever@eecs.umich.edu /** A pointer to the bridge to which this port belongs. */ 582568SN/A Bridge *bridge; 592568SN/A 602643Sstever@eecs.umich.edu /** 612643Sstever@eecs.umich.edu * Pointer to the port on the other side of the bridge 622643Sstever@eecs.umich.edu * (connected to the other bus). 632643Sstever@eecs.umich.edu */ 642643Sstever@eecs.umich.edu BridgePort *otherPort; 652643Sstever@eecs.umich.edu 662643Sstever@eecs.umich.edu /** Minimum delay though this bridge. */ 672643Sstever@eecs.umich.edu Tick delay; 682643Sstever@eecs.umich.edu 694432Ssaidi@eecs.umich.edu bool fixPartialWrite; 704432Ssaidi@eecs.umich.edu 712643Sstever@eecs.umich.edu class PacketBuffer : public Packet::SenderState { 722643Sstever@eecs.umich.edu 732643Sstever@eecs.umich.edu public: 742643Sstever@eecs.umich.edu Tick ready; 753349Sbinkertn@umich.edu PacketPtr pkt; 762643Sstever@eecs.umich.edu Packet::SenderState *origSenderState; 772643Sstever@eecs.umich.edu short origSrc; 782643Sstever@eecs.umich.edu bool expectResponse; 792643Sstever@eecs.umich.edu 804432Ssaidi@eecs.umich.edu bool partialWriteFixed; 814432Ssaidi@eecs.umich.edu PacketPtr oldPkt; 824432Ssaidi@eecs.umich.edu 833349Sbinkertn@umich.edu PacketBuffer(PacketPtr _pkt, Tick t) 842643Sstever@eecs.umich.edu : ready(t), pkt(_pkt), 852643Sstever@eecs.umich.edu origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()), 864432Ssaidi@eecs.umich.edu expectResponse(_pkt->needsResponse()), partialWriteFixed(false) 872643Sstever@eecs.umich.edu { 882657Ssaidi@eecs.umich.edu if (!pkt->isResponse()) 892657Ssaidi@eecs.umich.edu pkt->senderState = this; 902643Sstever@eecs.umich.edu } 912643Sstever@eecs.umich.edu 923349Sbinkertn@umich.edu void fixResponse(PacketPtr pkt) 932643Sstever@eecs.umich.edu { 942643Sstever@eecs.umich.edu assert(pkt->senderState == this); 952643Sstever@eecs.umich.edu pkt->setDest(origSrc); 962643Sstever@eecs.umich.edu pkt->senderState = origSenderState; 974432Ssaidi@eecs.umich.edu if (partialWriteFixed) 984432Ssaidi@eecs.umich.edu delete oldPkt; 992643Sstever@eecs.umich.edu } 1004432Ssaidi@eecs.umich.edu 1014432Ssaidi@eecs.umich.edu void partialWriteFix(Port *port) 1024432Ssaidi@eecs.umich.edu { 1034432Ssaidi@eecs.umich.edu assert(!partialWriteFixed); 1044432Ssaidi@eecs.umich.edu assert(expectResponse); 1054432Ssaidi@eecs.umich.edu 1064432Ssaidi@eecs.umich.edu int pbs = port->peerBlockSize(); 1074432Ssaidi@eecs.umich.edu partialWriteFixed = true; 1084432Ssaidi@eecs.umich.edu PacketDataPtr data; 1094432Ssaidi@eecs.umich.edu 1104432Ssaidi@eecs.umich.edu data = new uint8_t[pbs]; 1114432Ssaidi@eecs.umich.edu PacketPtr funcPkt = new Packet(pkt->req, MemCmd::ReadReq, 1124432Ssaidi@eecs.umich.edu Packet::Broadcast, pbs); 1134432Ssaidi@eecs.umich.edu 1144432Ssaidi@eecs.umich.edu funcPkt->dataStatic(data); 1154432Ssaidi@eecs.umich.edu port->sendFunctional(funcPkt); 1164432Ssaidi@eecs.umich.edu assert(funcPkt->result == Packet::Success); 1174432Ssaidi@eecs.umich.edu delete funcPkt; 1184432Ssaidi@eecs.umich.edu 1194432Ssaidi@eecs.umich.edu oldPkt = pkt; 1204432Ssaidi@eecs.umich.edu memcpy(data + oldPkt->getOffset(pbs), pkt->getPtr<uint8_t>(), 1214432Ssaidi@eecs.umich.edu pkt->getSize()); 1224432Ssaidi@eecs.umich.edu pkt = new Packet(oldPkt->req, MemCmd::WriteInvalidateReq, 1234432Ssaidi@eecs.umich.edu Packet::Broadcast, pbs); 1244432Ssaidi@eecs.umich.edu pkt->dataDynamicArray(data); 1254432Ssaidi@eecs.umich.edu pkt->senderState = oldPkt->senderState; 1264432Ssaidi@eecs.umich.edu } 1274432Ssaidi@eecs.umich.edu 1284432Ssaidi@eecs.umich.edu void undoPartialWriteFix() 1294432Ssaidi@eecs.umich.edu { 1304432Ssaidi@eecs.umich.edu if (!partialWriteFixed) 1314432Ssaidi@eecs.umich.edu return; 1324432Ssaidi@eecs.umich.edu delete pkt; 1334432Ssaidi@eecs.umich.edu pkt = oldPkt; 1344432Ssaidi@eecs.umich.edu partialWriteFixed = false; 1354432Ssaidi@eecs.umich.edu } 1364432Ssaidi@eecs.umich.edu 1372643Sstever@eecs.umich.edu }; 1382643Sstever@eecs.umich.edu 1392643Sstever@eecs.umich.edu /** 1402643Sstever@eecs.umich.edu * Outbound packet queue. Packets are held in this queue for a 1412643Sstever@eecs.umich.edu * specified delay to model the processing delay of the 1422643Sstever@eecs.umich.edu * bridge. 1432643Sstever@eecs.umich.edu */ 1442643Sstever@eecs.umich.edu std::list<PacketBuffer*> sendQueue; 1452643Sstever@eecs.umich.edu 1462643Sstever@eecs.umich.edu int outstandingResponses; 1472643Sstever@eecs.umich.edu 1482643Sstever@eecs.umich.edu /** Max queue size for outbound packets */ 1492643Sstever@eecs.umich.edu int queueLimit; 1502643Sstever@eecs.umich.edu 1512643Sstever@eecs.umich.edu /** 1522643Sstever@eecs.umich.edu * Is this side blocked from accepting outbound packets? 1532643Sstever@eecs.umich.edu */ 1542643Sstever@eecs.umich.edu bool queueFull() { return (sendQueue.size() == queueLimit); } 1552643Sstever@eecs.umich.edu 1563349Sbinkertn@umich.edu bool queueForSendTiming(PacketPtr pkt); 1572643Sstever@eecs.umich.edu 1582643Sstever@eecs.umich.edu void finishSend(PacketBuffer *buf); 1592643Sstever@eecs.umich.edu 1602643Sstever@eecs.umich.edu /** 1612643Sstever@eecs.umich.edu * Handle send event, scheduled when the packet at the head of 1622643Sstever@eecs.umich.edu * the outbound queue is ready to transmit (for timing 1632643Sstever@eecs.umich.edu * accesses only). 1642643Sstever@eecs.umich.edu */ 1652643Sstever@eecs.umich.edu void trySend(); 1662643Sstever@eecs.umich.edu 1672643Sstever@eecs.umich.edu class SendEvent : public Event 1682643Sstever@eecs.umich.edu { 1692643Sstever@eecs.umich.edu BridgePort *port; 1702643Sstever@eecs.umich.edu 1712643Sstever@eecs.umich.edu public: 1722643Sstever@eecs.umich.edu SendEvent(BridgePort *p) 1732643Sstever@eecs.umich.edu : Event(&mainEventQueue), port(p) {} 1742643Sstever@eecs.umich.edu 1752643Sstever@eecs.umich.edu virtual void process() { port->trySend(); } 1762643Sstever@eecs.umich.edu 1772643Sstever@eecs.umich.edu virtual const char *description() { return "bridge send event"; } 1782643Sstever@eecs.umich.edu }; 1792643Sstever@eecs.umich.edu 1802643Sstever@eecs.umich.edu SendEvent sendEvent; 1812568SN/A 1822568SN/A public: 1832568SN/A 1842568SN/A /** Constructor for the BusPort.*/ 1852643Sstever@eecs.umich.edu BridgePort(const std::string &_name, 1862643Sstever@eecs.umich.edu Bridge *_bridge, BridgePort *_otherPort, 1874432Ssaidi@eecs.umich.edu int _delay, int _queueLimit, bool fix_partial_write); 1882568SN/A 1892568SN/A protected: 1902568SN/A 1912643Sstever@eecs.umich.edu /** When receiving a timing request from the peer port, 1922643Sstever@eecs.umich.edu pass it to the bridge. */ 1933349Sbinkertn@umich.edu virtual bool recvTiming(PacketPtr pkt); 1942568SN/A 1952643Sstever@eecs.umich.edu /** When receiving a retry request from the peer port, 1962568SN/A pass it to the bridge. */ 1972657Ssaidi@eecs.umich.edu virtual void recvRetry(); 1982568SN/A 1992643Sstever@eecs.umich.edu /** When receiving a Atomic requestfrom the peer port, 2002568SN/A pass it to the bridge. */ 2013349Sbinkertn@umich.edu virtual Tick recvAtomic(PacketPtr pkt); 2022568SN/A 2032643Sstever@eecs.umich.edu /** When receiving a Functional request from the peer port, 2042568SN/A pass it to the bridge. */ 2053349Sbinkertn@umich.edu virtual void recvFunctional(PacketPtr pkt); 2062568SN/A 2072643Sstever@eecs.umich.edu /** When receiving a status changefrom the peer port, 2082568SN/A pass it to the bridge. */ 2092643Sstever@eecs.umich.edu virtual void recvStatusChange(Status status); 2102568SN/A 2112643Sstever@eecs.umich.edu /** When receiving a address range request the peer port, 2122568SN/A pass it to the bridge. */ 2132643Sstever@eecs.umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 2142643Sstever@eecs.umich.edu AddrRangeList &snoop); 2152568SN/A }; 2162568SN/A 2172643Sstever@eecs.umich.edu BridgePort portA, portB; 2182568SN/A 2192568SN/A /** If this bridge should acknowledge writes. */ 2202568SN/A bool ackWrites; 2212568SN/A 2222568SN/A public: 2232568SN/A 2242568SN/A /** A function used to return the port associated with this bus object. */ 2252738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1); 2262568SN/A 2272568SN/A virtual void init(); 2282568SN/A 2294432Ssaidi@eecs.umich.edu Bridge(const std::string &n, int qsa, int qsb, Tick _delay, int write_ack, 2304432Ssaidi@eecs.umich.edu bool fix_partial_write_a, bool fix_partial_write_b); 2312568SN/A}; 2322568SN/A 2332568SN/A#endif //__MEM_BUS_HH__ 234