mem-garnet: Upgrade garnet version to 3.0
[gem5.git] / src / mem / ruby / network / garnet / OutputUnit.hh
1 /*
2 * Copyright (c) 2020 Inria
3 * Copyright (c) 2016 Georgia Institute of Technology
4 * Copyright (c) 2008 Princeton University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32 #ifndef __MEM_RUBY_NETWORK_GARNET_0_OUTPUTUNIT_HH__
33 #define __MEM_RUBY_NETWORK_GARNET_0_OUTPUTUNIT_HH__
34
35 #include <iostream>
36 #include <vector>
37
38 #include "base/compiler.hh"
39 #include "mem/ruby/common/Consumer.hh"
40 #include "mem/ruby/network/garnet/CommonTypes.hh"
41 #include "mem/ruby/network/garnet/NetworkLink.hh"
42 #include "mem/ruby/network/garnet/OutVcState.hh"
43
44 class CreditLink;
45 class Router;
46
47 class OutputUnit : public Consumer
48 {
49 public:
50 OutputUnit(int id, PortDirection direction, Router *router,
51 uint32_t consumerVcs);
52 ~OutputUnit() = default;
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 outVcState[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, Tick curTime)
80 {
81 outVcState[vc].setState(state, curTime);
82 }
83
84 inline bool
85 is_vc_idle(int vc, Tick curTime)
86 {
87 return (outVcState[vc].isInState(IDLE_, curTime));
88 }
89
90 void insert_flit(flit *t_flit);
91
92 inline int
93 getVcsPerVnet()
94 {
95 return m_vc_per_vnet;
96 }
97
98 uint32_t functionalWrite(Packet *pkt);
99
100 private:
101 Router *m_router;
102 int M5_CLASS_VAR_USED m_id;
103 PortDirection m_direction;
104 int m_vc_per_vnet;
105 NetworkLink *m_out_link;
106 CreditLink *m_credit_link;
107
108 // This is for the network link to consume
109 flitBuffer outBuffer;
110 // vc state of downstream router
111 std::vector<OutVcState> outVcState;
112 };
113
114 #endif // __MEM_RUBY_NETWORK_GARNET_0_OUTPUTUNIT_HH__