ParaNut SystemC Model
A SystemC Model of the ParaNut architecture
tlb.h
Go to the documentation of this file.
1 /*************************************************************************
2 
3  This file is part of the ParaNut project.
4 
5  Copyright (C) 2021-2022 Christian H. Meyer <christian.meyer@hs-augsburg.de>
6  Hochschule Augsburg, University of Applied Sciences
7 
8  Description:
9  This is a SystemC model of the Translation Lookaside Buffer (TLB)
10  of the ParaNut project. It interacts only with the MMU and buffers
11  page table entries to speed up virtual address translation.
12 
13  This program is free software: you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program. If not, see <http://www.gnu.org/licenses/>.
25 
26  *************************************************************************/
27 
28 #ifndef _TLB_
29 #define _TLB_
30 
31 #include "base.h"
32 #include "paranut-config.h"
33 
34 #include <systemc.h>
35 
36 struct STlbTag {
37  bool valid;
38  bool superpage;
39 
40  sc_uint<10> vpn1;
41  sc_uint<10> vpn0;
42 
44  valid = t.valid;
45  superpage = t.superpage;
46  vpn1 = t.vpn1;
47  vpn0 = t.vpn0;
48  return *this;
49  }
50 
51  // Necessary operators for using this structure as signals...
52  bool operator== (const STlbTag &t) const {
53  return valid == t.valid && superpage == t.superpage && vpn1 == t.vpn1 && vpn0 == t.vpn0;
54  }
55 
56  //Overload function
57  friend void sc_trace( sc_trace_file* f, const STlbTag& t, const std::string& _s ) {
58  sc_trace( f, t.valid, _s + ".valid" );
59  sc_trace( f, t.superpage, _s + ".superpage" );
60  sc_trace( f, t.vpn1, _s + ".vpn1" );
61  sc_trace( f, t.vpn0, _s + ".vpn0" );
62  }
63 
64  // Displaying
65  friend ostream& operator << ( ostream& os, const STlbTag &t ) {
66  os << "valid:" << t.valid << " superpage:" << t.superpage << " vpn1:" << t.vpn1 << " vpn0:" << t.vpn0;
67 
68  return os;
69  }
70 };
71 
72 
73 struct STlbData {
74  sc_uint<20> padr;
75  bool ac_r;
76  bool ac_w;
77  bool ac_x;
78  bool ac_u;
79  bool ac_a;
80  bool ac_d;
81 
82  // Necessary operators for using this structure as signals...
83  bool operator== (const STlbData &t) const {
84  return padr == t.padr && ac_r == t.ac_r && ac_w == t.ac_w && ac_x == t.ac_x && ac_u == t.ac_u && ac_a == t.ac_a && ac_d == t.ac_d;
85  }
86 
87  STlbData operator= (const sc_uint<26> &t) {
88  padr = t.range(19, 0);
89  ac_r = t[20];
90  ac_w = t[21];
91  ac_x = t[22];
92  ac_u = t[23];
93  ac_a = t[24];
94  ac_d = t[25];
95  return *this;
96  }
97 
98  operator sc_uint<26>() {
99  sc_uint<26> out = padr;
100  out[20] = ac_r;
101  out[21] = ac_w;
102  out[22] = ac_x;
103  out[23] = ac_u;
104  out[24] = ac_a;
105  out[25] = ac_d;
106  return out;
107  }
108 
110  padr = t.padr;
111  ac_r = t.ac_r;
112  ac_w = t.ac_w;
113  ac_x = t.ac_x;
114  ac_u = t.ac_u;
115  ac_a = t.ac_a;
116  ac_d = t.ac_d;
117  return *this;
118  }
119 
120  // Displaying
121  friend ostream& operator << ( ostream& os, const STlbData &t ) {
122  os << " padr:" << t.padr << " ac_r:" << t.ac_r << " ac_w:" << t.ac_w << " ac_x:" << t.ac_x << " ac_u:" << t.ac_u << " ac_a:" << t.ac_a << " ac_d:" << t.ac_d;
123 
124  return os;
125  }
126 
127  //Overload function
128  friend void sc_trace( sc_trace_file* f, const STlbData& t, const std::string& _s ) {
129  sc_trace( f, t.padr, _s + ".padr" );
130  sc_trace( f, t.ac_r, _s + ".ac_r" );
131  sc_trace( f, t.ac_w, _s + ".ac_w" );
132  sc_trace( f, t.ac_x, _s + ".ac_x" );
133  sc_trace( f, t.ac_u, _s + ".ac_u" );
134  sc_trace( f, t.ac_a, _s + ".ac_a" );
135  sc_trace( f, t.ac_d, _s + ".ac_d" );
136  }
137 };
138 
139 class MTlb : ::sc_core::sc_module {
140 public:
141  // Ports ...
142  sc_in<bool> clk, reset;
143 
144  // from
145  sc_in<bool> flush;
146 
147  // from/to PTW
148  sc_in<bool> ptw_req, ptw_wr;
149  sc_in<sc_uint<20> > ptw_va_i;
150  sc_in<sc_uint<20> > ptw_pa_i;
151  sc_in<bool> ptw_superpage_i;
152  sc_in<bool> ptw_ac_r_i;
153  sc_in<bool> ptw_ac_w_i;
154  sc_in<bool> ptw_ac_x_i;
155  sc_in<bool> ptw_ac_u_i;
156  sc_in<bool> ptw_ac_a_i;
157  sc_in<bool> ptw_ac_d_i;
158 
159  sc_out<bool> ptw_superpage_o;
160  sc_out<sc_uint<20> > ptw_adr_o;
161  sc_out<bool> ptw_hit_o;
162  sc_out<bool> ptw_miss_o;
163 
164  sc_out<bool> ptw_ac_r_o;
165  sc_out<bool> ptw_ac_w_o;
166  sc_out<bool> ptw_ac_x_o;
167  sc_out<bool> ptw_ac_u_o;
168  sc_out<bool> ptw_ac_a_o;
169  sc_out<bool> ptw_ac_d_o;
170 
171  // Constructor...
172  SC_HAS_PROCESS (MTlb);
173  MTlb (sc_module_name name)
174  : sc_module (name) {
175  SC_METHOD (TransitionMethod);
176  sensitive << clk.pos ();
177  }
178 
179  // Functions...
180  void Trace (sc_trace_file * tf, int level = 1);
181 
182  // Processes...
183  void TransitionMethod ();
184 
185 protected:
186  // Registers...
187  sc_signal<STlbTag> tlb_tag[CFG_MMU_TLB_ENTRIES];
188  sc_signal<STlbData> tlb_data[CFG_MMU_TLB_ENTRIES];
189 
190  // regs
191  sc_signal<sc_uint<CFG_MMU_TLB_ENTRIES-1> > plru_reg;
192  sc_signal<sc_uint<CFG_MMU_TLB_ENTRIES_LD> > latest_hit;
193  sc_signal<bool> update_plru_reg;
194  sc_signal<bool> wr_done_reg;
195 
196  // internal signals
197  sc_signal<bool> superpage_sig;
198  sc_signal<bool> hit_sig;
199  sc_signal<bool> miss_sig;
200 };
201 
202 
203 #endif
Helpers, Makros and performance measuring Classes used in most ParaNut files.
Definition: tlb.h:139
sc_signal< bool > hit_sig
Definition: tlb.h:198
sc_in< bool > ptw_ac_d_i
Definition: tlb.h:157
sc_signal< STlbData > tlb_data[CFG_MMU_TLB_ENTRIES]
Definition: tlb.h:188
MTlb(sc_module_name name)
Definition: tlb.h:173
sc_in< sc_uint< 20 > > ptw_va_i
Definition: tlb.h:149
sc_out< bool > ptw_hit_o
Definition: tlb.h:161
sc_signal< bool > superpage_sig
Definition: tlb.h:197
sc_signal< STlbTag > tlb_tag[CFG_MMU_TLB_ENTRIES]
Definition: tlb.h:187
sc_out< bool > ptw_ac_u_o
Definition: tlb.h:167
sc_in< bool > ptw_superpage_i
Definition: tlb.h:151
sc_in< bool > ptw_ac_x_i
Definition: tlb.h:154
void TransitionMethod()
Definition: tlb.cpp:77
sc_in< bool > ptw_ac_u_i
Definition: tlb.h:155
sc_out< bool > ptw_miss_o
Definition: tlb.h:162
sc_in< bool > flush
Definition: tlb.h:145
sc_in< bool > clk
Definition: tlb.h:142
sc_in< sc_uint< 20 > > ptw_pa_i
Definition: tlb.h:150
sc_out< sc_uint< 20 > > ptw_adr_o
Definition: tlb.h:160
sc_out< bool > ptw_ac_d_o
Definition: tlb.h:169
sc_signal< bool > update_plru_reg
Definition: tlb.h:193
sc_out< bool > ptw_ac_w_o
Definition: tlb.h:165
sc_in< bool > reset
Definition: tlb.h:142
sc_in< bool > ptw_ac_a_i
Definition: tlb.h:156
sc_out< bool > ptw_ac_r_o
Definition: tlb.h:164
sc_signal< bool > miss_sig
Definition: tlb.h:199
sc_in< bool > ptw_req
Definition: tlb.h:148
sc_out< bool > ptw_ac_x_o
Definition: tlb.h:166
sc_out< bool > ptw_superpage_o
Definition: tlb.h:159
sc_in< bool > ptw_wr
Definition: tlb.h:148
sc_signal< sc_uint< CFG_MMU_TLB_ENTRIES_LD > > latest_hit
Definition: tlb.h:192
sc_in< bool > ptw_ac_w_i
Definition: tlb.h:153
sc_signal< bool > wr_done_reg
Definition: tlb.h:194
sc_signal< sc_uint< CFG_MMU_TLB_ENTRIES-1 > > plru_reg
Definition: tlb.h:191
void Trace(sc_trace_file *tf, int level=1)
Definition: tlb.cpp:37
sc_out< bool > ptw_ac_a_o
Definition: tlb.h:168
sc_in< bool > ptw_ac_r_i
Definition: tlb.h:152
#define CFG_MMU_TLB_ENTRIES
Number of TLB entries (derived).
Definition: paranut-config.h:258
Configuration Makros used in most ParaNut files.
Definition: tlb.h:73
bool ac_r
Definition: tlb.h:75
bool ac_a
Definition: tlb.h:79
bool ac_u
Definition: tlb.h:78
friend ostream & operator<<(ostream &os, const STlbData &t)
Definition: tlb.h:121
bool ac_w
Definition: tlb.h:76
sc_uint< 20 > padr
Definition: tlb.h:74
STlbData operator=(const sc_uint< 26 > &t)
Definition: tlb.h:87
bool ac_d
Definition: tlb.h:80
bool operator==(const STlbData &t) const
Definition: tlb.h:83
friend void sc_trace(sc_trace_file *f, const STlbData &t, const std::string &_s)
Definition: tlb.h:128
bool ac_x
Definition: tlb.h:77
Definition: tlb.h:36
bool valid
Definition: tlb.h:37
friend ostream & operator<<(ostream &os, const STlbTag &t)
Definition: tlb.h:65
friend void sc_trace(sc_trace_file *f, const STlbTag &t, const std::string &_s)
Definition: tlb.h:57
sc_uint< 10 > vpn1
Definition: tlb.h:40
bool operator==(const STlbTag &t) const
Definition: tlb.h:52
bool superpage
Definition: tlb.h:38
sc_uint< 10 > vpn0
Definition: tlb.h:41
STlbTag operator=(const STlbTag &t)
Definition: tlb.h:43
sc_trace_file * tf
Definition: tlb_tb.cpp:94