style: updated garnet to match M5 coding style
[gem5.git] / src / mem / ruby / network / garnet / fixed-pipeline / OutputUnit_d.hh
1 /*
2 * Copyright (c) 2008 Princeton University
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: Niket Agarwal
29 */
30
31 #ifndef __MEM_RUBY_NETWORK_GARNET_FIXED_PIPELINE_OUTPUT_UNIT_D_HH__
32 #define __MEM_RUBY_NETWORK_GARNET_FIXED_PIPELINE_OUTPUT_UNIT_D_HH__
33
34 #include <iostream>
35 #include <vector>
36
37 #include "mem/ruby/network/garnet/NetworkHeader.hh"
38 #include "mem/ruby/common/Consumer.hh"
39 #include "mem/ruby/network/garnet/fixed-pipeline/flitBuffer_d.hh"
40 #include "mem/ruby/network/garnet/fixed-pipeline/OutVcState_d.hh"
41 #include "mem/ruby/network/garnet/fixed-pipeline/NetworkLink_d.hh"
42 #include "mem/ruby/network/garnet/fixed-pipeline/CreditLink_d.hh"
43
44 class Router_d;
45
46 class OutputUnit_d : public Consumer
47 {
48 public:
49 OutputUnit_d(int id, Router_d *router);
50 ~OutputUnit_d();
51 void set_out_link(NetworkLink_d *link);
52 void set_credit_link(CreditLink_d *credit_link);
53 void wakeup();
54 flitBuffer_d* getOutQueue();
55 void printConfig(std::ostream& out);
56 void update_vc(int vc, int in_port, int in_vc);
57 void print(std::ostream& out) const {};
58 void decrement_credit(int out_vc);
59
60 int
61 get_credit_cnt(int vc)
62 {
63 return m_outvc_state[vc]->get_credit_count();
64 }
65
66 inline int
67 get_outlink_id()
68 {
69 return m_out_link->get_id();
70 }
71
72 inline void
73 set_vc_state(VC_state_type state, int vc)
74 {
75 m_outvc_state[vc]->setState(state, g_eventQueue_ptr->getTime() + 1);
76 }
77
78 inline bool
79 is_vc_idle(int vc)
80 {
81 return (m_outvc_state[vc]->isInState(IDLE_,
82 g_eventQueue_ptr->getTime()));
83 }
84
85 inline void
86 insert_flit(flit_d *t_flit)
87 {
88 m_out_buffer->insert(t_flit);
89 g_eventQueue_ptr->scheduleEvent(m_out_link, 1);
90 }
91
92 private:
93 int m_id;
94 int m_num_vcs;
95 Router_d *m_router;
96 NetworkLink_d *m_out_link;
97 CreditLink_d *m_credit_link;
98
99 flitBuffer_d *m_out_buffer; // This is for the network link to consume
100 std::vector<OutVcState_d *> m_outvc_state; // vc state of downstream router
101
102 };
103
104 #endif // __MEM_RUBY_NETWORK_GARNET_FIXED_PIPELINE_OUTPUT_UNIT_D_HH__