1/* 2 * Copyright (c) 2008 Princeton University 3 * Copyright (c) 2016 Georgia Institute of Technology 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Niket Agarwal 30 * Tushar Krishna 31 */ 32 33 34#ifndef __MEM_RUBY_NETWORK_GARNET2_0_OUTPUTUNIT_HH__ 35#define __MEM_RUBY_NETWORK_GARNET2_0_OUTPUTUNIT_HH__ 36 37#include <iostream> 38#include <vector> 39 40#include "mem/ruby/common/Consumer.hh" 41#include "mem/ruby/network/garnet2.0/CommonTypes.hh" 42#include "mem/ruby/network/garnet2.0/CreditLink.hh" 43#include "mem/ruby/network/garnet2.0/NetworkLink.hh" 44#include "mem/ruby/network/garnet2.0/OutVcState.hh" 45#include "mem/ruby/network/garnet2.0/Router.hh" 46#include "mem/ruby/network/garnet2.0/flitBuffer.hh" 47 48class OutputUnit : public Consumer 49{ 50 public: 51 OutputUnit(int id, PortDirection direction, Router *router); 52 ~OutputUnit(); 53 void set_out_link(NetworkLink *link); 54 void set_credit_link(CreditLink *credit_link); 55 void wakeup(); 56 flitBuffer* getOutQueue(); 57 void print(std::ostream& out) const {}; 58 void decrement_credit(int out_vc); 59 void increment_credit(int out_vc); 60 bool has_credit(int out_vc); 61 bool has_free_vc(int vnet); 62 int select_free_vc(int vnet); 63 64 inline PortDirection get_direction() { return m_direction; } 65 66 int 67 get_credit_count(int vc) 68 { 69 return m_outvc_state[vc]->get_credit_count(); 70 } 71 72 inline int 73 get_outlink_id() 74 { 75 return m_out_link->get_id(); 76 } 77 78 inline void 79 set_vc_state(VC_state_type state, int vc, Cycles curTime) 80 { 81 m_outvc_state[vc]->setState(state, curTime); 82 } 83 84 inline bool 85 is_vc_idle(int vc, Cycles curTime) 86 { 87 return (m_outvc_state[vc]->isInState(IDLE_, curTime)); 88 } 89 90 inline void 91 insert_flit(flit *t_flit) 92 { 93 m_out_buffer->insert(t_flit); 94 m_out_link->scheduleEventAbsolute(m_router->clockEdge(Cycles(1))); 95 } 96 97 uint32_t functionalWrite(Packet *pkt); 98 99 private: 100 int m_id; 101 PortDirection m_direction; 102 int m_num_vcs; 103 int m_vc_per_vnet; 104 Router *m_router; 105 NetworkLink *m_out_link; 106 CreditLink *m_credit_link; 107 108 flitBuffer *m_out_buffer; // This is for the network link to consume 109 std::vector<OutVcState *> m_outvc_state; // vc state of downstream router 110 111}; 112 113#endif // __MEM_RUBY_NETWORK_GARNET2_0_OUTPUTUNIT_HH__ 114