Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / lib / cpu / src / SS_Tsb.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: SS_Tsb.h
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23#ifndef __SS_Tsb_h__
24#define __SS_Tsb_h__
25
26#include "SS_Types.h"
27
28class SS_TsbConfig
29{
30 public:
31 SS_TsbConfig( ) : valid(false), tsb_size_check(0)
32 {
33 // even if tsb_config is not enabled, we still need the proper values
34 // to calculate tsb_pointer in case like tlb miss, so set up the init
35 // value properly.
36 update(false, 0, 9, 13, false, 0);
37 }
38
39 // update() recomputes the tsb access values: tsb_base is the base address,
40 // the tsb size is 2^tsb_size, page size is number of 2^page_size
41 void update( bool _valid, SS_Paddr tsb_base, uint_t tsb_size, uint_t page_size, bool _ra1pa, uint_t _use_ctx )
42 {
43 valid = _valid;
44 ra1pa = _ra1pa;
45 use_ctx = _use_ctx;
46 match_mask = ((~((SS_Vaddr(1) << page_size) - SS_Vaddr(1))) >> 22) << 22;
47 index_base = (tsb_base >> (tsb_size + 4)) << (tsb_size + 4); // TSB is aligned to its own size and
48 // the combination of page_size and tsb_size may cover a bigger VA
49 // range than is supported by a particular architecture, so may have
50 // to adjust a bit.
51 int tsb_size_adjust = tsb_size;
52 if (tsb_size_check &&
53 ((page_size == page_size_check) && (tsb_size > tsb_size_check)))
54 {
55 tsb_size_adjust = tsb_size_check;
56 }
57 index_mask = (SS_Paddr(0x10) << tsb_size_adjust) - 0x10; // one entry is 16 bytes ...
58 index_shft = page_size - 4;
59 tsb_psz = (page_size - 13) / 3; // Ahum ... convert back to 0..7
60 }
61
62 bool is_valid() { return valid; }
63 bool is_ra_not_pa() { return ra1pa; }
64 int use_context() { return use_ctx; }
65 int use_context_0() { return use_ctx & 2; }
66 int use_context_1() { return use_ctx & 1; }
67 bool match( SS_Vaddr va, SS_Vaddr tag ) { return (va & match_mask) == tag; }
68 SS_Paddr index( SS_Vaddr va ) { return index_base | ((va >> index_shft) & index_mask); }
69 uint_t get_page_size() { return tsb_psz; }
70
71 void set_attr( uint_t _page_size_check, uint_t _tsb_size_check )
72 {
73 page_size_check = _page_size_check;
74 tsb_size_check = _tsb_size_check;
75 }
76
77 protected:
78 bool valid;
79 bool ra1pa;
80 uint_t index_shft;
81 SS_Paddr index_mask;
82 SS_Paddr index_base;
83 SS_Vaddr match_mask;
84 uint_t use_ctx;
85 uint_t tsb_psz;
86 uint_t page_size_check;
87 uint_t tsb_size_check;
88};
89
90class SS_TsbRaToPa
91{
92 public:
93 SS_TsbRaToPa() : valid(false) {}
94
95 void update( bool v, SS_Paddr _beg, SS_Paddr _end, SS_Paddr _ofs )
96 {
97 valid = v;
98 rpn_beg = _beg;
99 rpn_end = _end;
100 ppn_ofs = _ofs;
101 }
102
103 bool valid;
104 SS_Paddr rpn_beg;
105 SS_Paddr rpn_end;
106 SS_Paddr ppn_ofs;
107};
108
109
110#endif
111