| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: data_port.hpp |
| 4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved |
| 5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. |
| 6 | // |
| 7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 8 | // |
| 9 | // This program is free software; you can redistribute it and/or modify |
| 10 | // it under the terms of the GNU General Public License as published by |
| 11 | // the Free Software Foundation; version 2 of the License. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | // |
| 22 | // For the avoidance of doubt, and except that if any non-GPL license |
| 23 | // choice is available it will apply instead, Sun elects to use only |
| 24 | // the General Public License version 2 (GPLv2) at this time for any |
| 25 | // software where a choice of GPL license versions is made |
| 26 | // available with the language indicating that GPLv2 or any later version |
| 27 | // may be used, or where a choice of which version of the GPL is applied is |
| 28 | // otherwise unspecified. |
| 29 | // |
| 30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 31 | // CA 95054 USA or visit www.sun.com if you need additional information or |
| 32 | // have any questions. |
| 33 | // |
| 34 | // ========== Copyright Header End ============================================ |
| 35 | #ifndef INC_data_port_hpp__ |
| 36 | #define INC_data_port_hpp__ |
| 37 | |
| 38 | #include <systemc.h> |
| 39 | |
| 40 | #include "pcie_common/packet_if.hpp" |
| 41 | #include "pcie_common/logger.hpp" |
| 42 | |
| 43 | #include "tlm.h" |
| 44 | #include "pcie_common/pciePacket.hpp" |
| 45 | namespace pcie { |
| 46 | USING_NAMESPACE(tlm); |
| 47 | USING_NAMESPACE(Logger); |
| 48 | |
| 49 | /** In port interface receive the Packet information */ |
| 50 | template< typename PACKET, int N = 1 > |
| 51 | class data_in_port : public sc_port< packet_in_if < PACKET >, N > |
| 52 | { |
| 53 | public: |
| 54 | typedef packet_in_if < PACKET > if_type; |
| 55 | |
| 56 | data_in_port( const char* port_name ) : sc_port< if_type, N > (port_name) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | /// Blocking interface to get the next packet over the intf |
| 61 | virtual int get_packet(PACKET &p) { |
| 62 | |
| 63 | int rt_val = (*this)->get_packet(p); |
| 64 | if (rt_val == 0) { |
| 65 | RefPciePacket pref; |
| 66 | pref = (RefPciePacket) p; |
| 67 | LOG_DEBUG << "GET_PACKET on Channel : " << name() << "PktId= " << pref->to_string() << "\n"; |
| 68 | } else { |
| 69 | // throw sc_exception(); |
| 70 | return rt_val; |
| 71 | } |
| 72 | return rt_val; |
| 73 | } |
| 74 | |
| 75 | /// Non blocking interface to get the next packet over the intf |
| 76 | virtual bool get_packet_nb(PACKET &p) { |
| 77 | |
| 78 | |
| 79 | return (*this)->get_packet_nb(p); |
| 80 | } |
| 81 | |
| 82 | /// Returns true if next packet is ready on the interface to get |
| 83 | virtual bool is_packet_ready() { |
| 84 | // return (*this)->nb_can_get(); |
| 85 | return (*this)->is_packet_ready(); |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | |
| 90 | /** In port interface receive the Packet information */ |
| 91 | template< typename PACKET, int N = 1 > |
| 92 | class data_out_port : public sc_port< packet_out_if< PACKET > , N > |
| 93 | |
| 94 | { |
| 95 | public: |
| 96 | typedef packet_out_if < PACKET > if_type; |
| 97 | |
| 98 | data_out_port( const char* port_name ) : sc_port< if_type, N > (port_name) |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | /// Blocking interface to send a packet over the intf |
| 103 | virtual int send_packet(const PACKET &p) { |
| 104 | |
| 105 | RefPciePacket pref; |
| 106 | pref = (RefPciePacket) p; |
| 107 | LOG_DEBUG << "SEND_PACKET on Channel : " << name() << " Packet : " << pref->to_string() << "\n"; |
| 108 | // (*this)->put(p); |
| 109 | return (*this)->send_packet(p); |
| 110 | } |
| 111 | |
| 112 | /// Purges data channel |
| 113 | virtual void purge_channel() { |
| 114 | (*this)->purge_channel(); |
| 115 | return ; |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | } // namespace pcie |
| 120 | |
| 121 | #endif // INC_data_port_hpp__ |