Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: AccessorBase.vr | |
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 | #include <vera_defines.vrh> | |
36 | #include "general_csr_defines.vri" | |
37 | #include "base_access_define.vri" | |
38 | #include "CSRAccessMethod.vrh" | |
39 | //#include "StubAccessMethod.vrh" | |
40 | //#include "CSRField.vrh" | |
41 | //#include "CSRState.vrh" | |
42 | #include "cReport.vrh" | |
43 | #include "report_macros.vri" | |
44 | ||
45 | class AccessorBase { | |
46 | CSRAccessMethod access_methods[]; | |
47 | ||
48 | protected integer access_level[]; | |
49 | protected BOOLEAN csr_check_enabled; | |
50 | protected integer DefaultMethod; | |
51 | protected CSRField reg_field[]; | |
52 | protected ReportClass CSRReport = new; | |
53 | protected CSRState ShadowState; | |
54 | protected string AccessName[]; | |
55 | ||
56 | ||
57 | local bit [CSRT_ADDR_OFFSET_WIDTH-1:0] addr_offset; | |
58 | local bit [CSRT_DATA_WIDTH-1:0] por_value; | |
59 | local bit [CSRT_DATA_WIDTH-1:0] rmask; | |
60 | local bit [CSRT_DATA_WIDTH-1:0] read_only_mask; | |
61 | local bit [CSRT_DATA_WIDTH-1:0] write_mask; | |
62 | local bit [CSRT_DATA_WIDTH-1:0] clear_mask; | |
63 | local bit [CSRT_DATA_WIDTH-1:0] set_mask; | |
64 | local bit [CSRT_DATA_WIDTH-1:0] toggle_mask; | |
65 | local string name; | |
66 | local integer max_num_fields; | |
67 | ||
68 | ||
69 | //================================================= | |
70 | // Constructor | |
71 | //================================================= | |
72 | ||
73 | task new ( CSRState ShadowState, | |
74 | bit [CSRT_ADDR_OFFSET_WIDTH-1:0] input_addr_offset, | |
75 | bit [CSRT_DATA_WIDTH-1:0] input_por_value, | |
76 | bit [CSRT_DATA_WIDTH-1:0] input_rmask, | |
77 | bit [CSRT_DATA_WIDTH-1:0] input_read_only_mask, | |
78 | bit [CSRT_DATA_WIDTH-1:0] input_write_mask, | |
79 | bit [CSRT_DATA_WIDTH-1:0] input_clear_mask, | |
80 | bit [CSRT_DATA_WIDTH-1:0] input_set_mask, | |
81 | bit [CSRT_DATA_WIDTH-1:0] input_toggle_mask, | |
82 | string input_name, | |
83 | integer input_num_fields ) { | |
84 | ||
85 | integer ii; | |
86 | ||
87 | this.ShadowState = ShadowState; | |
88 | this.addr_offset = input_addr_offset; | |
89 | this.por_value = input_por_value; | |
90 | this.rmask = input_rmask; | |
91 | this.read_only_mask = input_read_only_mask; | |
92 | this.write_mask = input_write_mask; | |
93 | this.clear_mask = input_clear_mask; | |
94 | this.set_mask = input_set_mask; | |
95 | this.toggle_mask = input_toggle_mask; | |
96 | ||
97 | sprintf (this.name, "%s", input_name); | |
98 | ||
99 | this.max_num_fields = input_num_fields; | |
100 | ||
101 | for (ii = 0; ii < max_num_fields; ii++) { | |
102 | this.reg_field[ii] = new (); | |
103 | } | |
104 | } //end task new | |
105 | ||
106 | //================================================= | |
107 | // Set Accessor Mode Task | |
108 | //================================================= | |
109 | ||
110 | task set_accessor_mode (bit [CSRT_MODE_WIDTH-1:0] new_accessor_mode, integer method = CSRT_USE_DEFAULT_METHOD) { | |
111 | if (method == CSRT_USE_DEFAULT_METHOD) | |
112 | method = DefaultMethod; | |
113 | ||
114 | QuickReport(CSRReport, RTYP_CSR_DEBUG_1,"CSRAccessor: Changing mode of accessor to %0h by way of %s register: ", | |
115 | new_accessor_mode, | |
116 | get_name()); | |
117 | ||
118 | access_methods[method].set_accessor_mode(new_accessor_mode); | |
119 | } // end task set_accessor_mode() | |
120 | ||
121 | //================================================= | |
122 | // Enable Checking Task | |
123 | //================================================= | |
124 | ||
125 | task enable_checking() { | |
126 | ||
127 | QuickReport(CSRReport, RTYP_CSR_DEBUG_1,"CSR enable_checking(): %s register:\t%0d",get_name()); | |
128 | ||
129 | csr_check_enabled = CSRT_CHECK_ENABLED; | |
130 | ||
131 | } // end task enable_checking | |
132 | ||
133 | //================================================= | |
134 | // Disable Checking Task | |
135 | //================================================= | |
136 | ||
137 | task disable_checking() { | |
138 | csr_check_enabled = CSRT_CHECK_DISABLED; | |
139 | } // end task disable_checking() | |
140 | ||
141 | ||
142 | //================================================= | |
143 | // Get Accessor Mode Function | |
144 | //================================================= | |
145 | function bit [CSRT_MODE_WIDTH-1:0] get_accessor_mode (integer method = CSRT_USE_DEFAULT_METHOD) { | |
146 | if (method == CSRT_USE_DEFAULT_METHOD) | |
147 | method = DefaultMethod; | |
148 | ||
149 | get_accessor_mode = access_methods[method].get_accessor_mode(); | |
150 | } // end function get_accessor_mode() | |
151 | ||
152 | ||
153 | // This task is used to change the default access method. | |
154 | // The initial setting of default method is Omni. | |
155 | task set_default_access_method (integer method) { | |
156 | DefaultMethod = method; | |
157 | } | |
158 | ||
159 | ||
160 | //================================================= | |
161 | // init_field_info task | |
162 | //================================================= | |
163 | ||
164 | task init_field_info ( integer field_id, | |
165 | bit [CSRT_DATA_WIDTH-1:0] input_field_mask, | |
166 | integer input_field_position, | |
167 | string input_field_name) { | |
168 | ||
169 | reg_field[field_id].init ( input_field_mask, | |
170 | input_field_position, | |
171 | input_field_name); | |
172 | ||
173 | } // end task init_field_info | |
174 | ||
175 | ||
176 | //================================================= | |
177 | // Set Field Function | |
178 | //================================================= | |
179 | ||
180 | function bit [CSRT_DATA_WIDTH-1:0] set_field ( integer field_id, | |
181 | bit [CSRT_DATA_WIDTH-1:0] field_data, | |
182 | bit [CSRT_DATA_WIDTH-1:0] csr_data ) | |
183 | { | |
184 | bit [CSRT_DATA_WIDTH-1:0] field_positioned_data; | |
185 | bit [CSRT_DATA_WIDTH-1:0] zero_field_mask; | |
186 | bit [CSRT_DATA_WIDTH-1:0] refresh_bit_mask; | |
187 | ||
188 | if (field_id < get_max_num_fields()) { | |
189 | ||
190 | field_positioned_data = reg_field[field_id].get_field_mask() & (field_data << reg_field[field_id].get_field_position()); | |
191 | zero_field_mask = ~(reg_field[field_id].get_field_mask()); | |
192 | refresh_bit_mask = zero_field_mask & get_write_mask (); | |
193 | ||
194 | set_field = (csr_data & refresh_bit_mask) | field_positioned_data; | |
195 | } | |
196 | else { | |
197 | QuickReport(CSRReport, RTYP_CSR_ERROR, "AccessorBase::set_field: Invalid field_id %0h", field_id); | |
198 | set_field = 64'hx; | |
199 | } | |
200 | ||
201 | } // end set_field | |
202 | ||
203 | ||
204 | //================================================= | |
205 | // set_shadow_data task | |
206 | //================================================= | |
207 | ||
208 | //This task allows shadow data to be set to any arbitrary value, independently | |
209 | //of any mask (i.e. access permissions). It is the basis of the public set_shadow_csr | |
210 | //task. | |
211 | protected task set_shadow_data (bit [CSRT_DATA_WIDTH-1:0] new_data) { | |
212 | bit [CSRT_DATA_WIDTH-1:0] rmask = get_rmask(); | |
213 | bit [CSRT_DATA_WIDTH-1:0] next_state; | |
214 | ||
215 | //Prohibit a verifier from setting non-existent bits to non-zero | |
216 | // this.data = new_data & rmask; | |
217 | next_state = new_data & rmask; | |
218 | ShadowState.SetState(next_state); | |
219 | } // end task set_shadow_data | |
220 | ||
221 | ||
222 | //================================================= | |
223 | // get_shadow_data task | |
224 | //================================================= | |
225 | ||
226 | protected function bit [CSRT_DATA_WIDTH-1:0] get_shadow_data () { | |
227 | // get_shadow_data = this.data; | |
228 | get_shadow_data = ShadowState.GetState(); | |
229 | } // end function get_shadow_data | |
230 | ||
231 | ||
232 | //================================================= | |
233 | // update_shadow_data task | |
234 | //================================================= | |
235 | ||
236 | protected task update_shadow_data (bit [CSRT_DATA_WIDTH-1:0] new_data) { | |
237 | ||
238 | bit [CSRT_DATA_WIDTH-1:0] tmp_data; | |
239 | bit [CSRT_DATA_WIDTH-1:0] rmask; | |
240 | bit [CSRT_DATA_WIDTH-1:0] read_mask; | |
241 | bit [CSRT_DATA_WIDTH-1:0] write_mask; | |
242 | bit [CSRT_DATA_WIDTH-1:0] clear_mask; | |
243 | bit [CSRT_DATA_WIDTH-1:0] set_mask; | |
244 | bit [CSRT_DATA_WIDTH-1:0] toggle_mask; | |
245 | ||
246 | ||
247 | rmask = get_rmask(); | |
248 | new_data &= rmask; //This will set bits corresponding to non-existant bit positions to zero | |
249 | ||
250 | read_mask = get_read_only_mask(); | |
251 | write_mask = get_write_mask(); | |
252 | clear_mask = get_clear_mask(); | |
253 | set_mask = get_set_mask(); | |
254 | toggle_mask = get_toggle_mask(); | |
255 | ||
256 | //Read-only bits in shadow data should always retain their current values. | |
257 | //This current value could result from: | |
258 | // 1. The POR state of the register | |
259 | // 2. A value set by a verifier using the set_shadow_csr task | |
260 | ||
261 | //The use of write_mask below should deal with read-only bits in a similar way. | |
262 | ||
263 | tmp_data = ShadowState.GetState(); | |
264 | tmp_data = ((tmp_data & ~write_mask) | (new_data & write_mask)); | |
265 | tmp_data = (tmp_data & ~(tmp_data & new_data & clear_mask)) ; | |
266 | tmp_data = (tmp_data | (new_data & set_mask)) ; //Write one to set | |
267 | tmp_data = (tmp_data ^ (new_data & toggle_mask)); | |
268 | ShadowState.SetState(tmp_data); | |
269 | } // end task update_shadow_data | |
270 | ||
271 | ||
272 | //================================================= | |
273 | // get_addr_offset function | |
274 | //================================================= | |
275 | ||
276 | protected function bit [CSRT_ADDR_OFFSET_WIDTH-1:0] get_addr_offset() { | |
277 | get_addr_offset = this.addr_offset; | |
278 | } // end function get_addr_offset | |
279 | ||
280 | ||
281 | ||
282 | //================================================= | |
283 | // get_por_value function | |
284 | //================================================= | |
285 | ||
286 | protected function bit [CSRT_DATA_WIDTH-1:0] get_por_value() { | |
287 | get_por_value = this.por_value; | |
288 | } // end function get_por_value | |
289 | ||
290 | ||
291 | //================================================= | |
292 | // get_rmask function | |
293 | //================================================= | |
294 | ||
295 | protected function bit [CSRT_DATA_WIDTH-1:0] get_rmask() { | |
296 | get_rmask = this.rmask; | |
297 | } // end function get_rmask | |
298 | ||
299 | ||
300 | //================================================= | |
301 | // get_read_only_mask function | |
302 | //================================================= | |
303 | ||
304 | protected function bit [CSRT_DATA_WIDTH-1:0] get_read_only_mask() { | |
305 | get_read_only_mask = this.read_only_mask; | |
306 | } // end function get_read_only_mask | |
307 | ||
308 | ||
309 | ||
310 | //================================================= | |
311 | // get_write_mask function | |
312 | //================================================= | |
313 | ||
314 | protected function bit [CSRT_DATA_WIDTH-1:0] get_write_mask() { | |
315 | get_write_mask = this.write_mask; | |
316 | } // end function get_write_mask | |
317 | ||
318 | ||
319 | ||
320 | //================================================= | |
321 | // get_clear_mask function | |
322 | //================================================= | |
323 | ||
324 | protected function bit [CSRT_DATA_WIDTH-1:0] get_clear_mask() { | |
325 | get_clear_mask = this.clear_mask; | |
326 | } // end function get_clear_mask | |
327 | ||
328 | ||
329 | //================================================= | |
330 | // get_set_mask function | |
331 | //================================================= | |
332 | ||
333 | protected function bit [CSRT_DATA_WIDTH-1:0] get_set_mask() { | |
334 | get_set_mask = this.set_mask; | |
335 | } // end function get_set_mask | |
336 | ||
337 | ||
338 | ||
339 | //================================================= | |
340 | // get_toggle_mask function | |
341 | //================================================= | |
342 | ||
343 | protected function bit [CSRT_DATA_WIDTH-1:0] get_toggle_mask() { | |
344 | get_toggle_mask = this.toggle_mask; | |
345 | } // end function get_toggle_mask | |
346 | ||
347 | ||
348 | ||
349 | //================================================= | |
350 | // get_name function | |
351 | //================================================= | |
352 | ||
353 | virtual function string get_name() { | |
354 | sprintf (get_name, "%s", this.name); | |
355 | } // end function get_name | |
356 | ||
357 | ||
358 | ||
359 | //================================================= | |
360 | // get_max_num_fields function | |
361 | //================================================= | |
362 | ||
363 | protected function integer get_max_num_fields() { | |
364 | get_max_num_fields = this.max_num_fields; | |
365 | } // end function get_name | |
366 | ||
367 | ||
368 | ||
369 | //================================================= | |
370 | // set_por_value task | |
371 | //================================================= | |
372 | ||
373 | protected task set_por_value (bit [CSRT_DATA_WIDTH-1:0] new_por_value) { | |
374 | this.por_value = new_por_value; | |
375 | } // end task set_por_value | |
376 | ||
377 | ||
378 | //================================================= | |
379 | // Check Method Task | |
380 | //================================================= | |
381 | ||
382 | protected task check_method (integer method) { | |
383 | if (!assoc_index(CHECK, access_methods, method)) | |
384 | QuickReport(CSRReport, RTYP_CSR_ERROR, "AccessorBase::check_method(): %s :Invalid method %0d", | |
385 | get_name(), method); | |
386 | ||
387 | } // end task check_method() | |
388 | ||
389 | ||
390 | protected task set_method_array ( CSRAccessMethod input_access_methods[], | |
391 | integer input_access_levels[], | |
392 | string input_access_name[] | |
393 | ) { | |
394 | integer MethodIndex; | |
395 | integer success; | |
396 | integer ii; | |
397 | ||
398 | ||
399 | //Set first location of each array | |
400 | success = assoc_index(FIRST, input_access_methods, MethodIndex); | |
401 | ||
402 | if (!success) { | |
403 | QuickReport(CSRReport, RTYP_CSR_ERROR, | |
404 | "AccessorBase::set_method_array: Empty or badly formed access method array passed to CSRAccessor"); | |
405 | } | |
406 | ||
407 | access_methods[MethodIndex] = input_access_methods[MethodIndex]; | |
408 | access_level[MethodIndex] = input_access_levels[MethodIndex]; | |
409 | AccessName[MethodIndex] = input_access_name[MethodIndex]; | |
410 | ||
411 | //Set remaining index of each array | |
412 | while (assoc_index(NEXT, input_access_methods, MethodIndex)) { | |
413 | access_methods[MethodIndex] = input_access_methods[MethodIndex]; | |
414 | access_level[MethodIndex] = input_access_levels[MethodIndex]; | |
415 | AccessName[MethodIndex] = input_access_name[MethodIndex]; | |
416 | } | |
417 | ||
418 | } | |
419 | ||
420 | protected function string get_method_name ( integer method) { | |
421 | if (method == CSRT_OMNI) | |
422 | get_method_name = "OMNI"; | |
423 | else | |
424 | get_method_name = AccessName[method]; | |
425 | } | |
426 | ||
427 | } | |
428 | ||
429 | ||
430 |