summaryrefslogtreecommitdiffstats
path: root/sys/sparc64/include/tsb.h
blob: b8093a6bcdbcec7d6319159e0a85f716a559ba2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*-
 * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Berkeley Software Design Inc's name may not be used to endorse or
 *    promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	from: BSDI: pmap.v9.h,v 1.10.2.6 1999/08/23 22:18:44 cp Exp
 * $FreeBSD$
 */

#ifndef	_MACHINE_TSB_H_
#define	_MACHINE_TSB_H_

#define	TSB_KERNEL_MIN_ADDRESS		(0xd0000000)
#define	TSB_USER_MIN_ADDRESS		(0xe0000000)

#define	TSB_MASK_WIDTH			(6)

#define	TSB_PRIMARY_BUCKET_SHIFT	(2)
#define	TSB_PRIMARY_BUCKET_SIZE		(1 << TSB_PRIMARY_BUCKET_SHIFT)
#define	TSB_PRIMARY_BUCKET_MASK		(TSB_PRIMARY_BUCKET_SIZE - 1)
#define	TSB_SECONDARY_BUCKET_SHIFT	(3)
#define	TSB_SECONDARY_BUCKET_SIZE	(1 << TSB_SECONDARY_BUCKET_SHIFT)
#define	TSB_SECONDARY_BUCKET_MASK	(TSB_SECONDARY_BUCKET_SIZE - 1)

#define	TSB_PRIMARY_STTE_SHIFT \
	(STTE_SHIFT + TSB_PRIMARY_BUCKET_SHIFT)
#define	TSB_PRIMARY_STTE_MASK		((1 << TSB_PRIMARY_STTE_SHIFT) - 1)

#define	TSB_LEVEL1_BUCKET_MASK \
	((TSB_SECONDARY_BUCKET_MASK & ~TSB_PRIMARY_BUCKET_MASK) << \
	    (PAGE_SHIFT - TSB_PRIMARY_BUCKET_SHIFT))
#define	TSB_LEVEL1_BUCKET_SHIFT \
	(TSB_BUCKET_SPREAD_SHIFT + \
	    (TSB_SECONDARY_BUCKET_SHIFT - TSB_PRIMARY_BUCKET_SHIFT))

#define	TSB_BUCKET_SPREAD_SHIFT		(2)

#define	TSB_DEPTH			(7)

#define	TSB_KERNEL_PAGES		(1)
#define	TSB_KERNEL_SIZE			(TSB_KERNEL_PAGES * PAGE_SIZE_4M)
#define	TSB_KERNEL_MB			(512)
#define	TSB_KERNEL_VM_RANGE		(TSB_KERNEL_MB * (1 << 20))
#define	TSB_KERNEL_RANGE \
	((TSB_KERNEL_VM_RANGE / PAGE_SIZE) * sizeof (struct stte))
#define	TSB_KERNEL_MASK \
	((TSB_KERNEL_RANGE / sizeof (struct stte)) - 1)

#define	TSB_1M_STTE_SHIFT		(21)
#define	TSB_1M_STTE_SIZE		(1 << TSB_1M_SHIFT)

#define	TSB_SIZE_REG			(7)

extern vm_offset_t tsb_kernel_phys;

static __inline struct stte *
tsb_base(u_int level)
{
	vm_offset_t base;
	size_t len;

	if (level == 0)
		base = TSB_USER_MIN_ADDRESS;
	else {
		len = 1UL << ((level * TSB_BUCKET_SPREAD_SHIFT) +
		    TSB_MASK_WIDTH + TSB_SECONDARY_BUCKET_SHIFT +
		    STTE_SHIFT);
		base = TSB_USER_MIN_ADDRESS + len;
	}
	return (struct stte *)base;
}

static __inline u_long
tsb_bucket_shift(u_int level)
{
	return (level == 0 ?
	    TSB_PRIMARY_BUCKET_SHIFT : TSB_SECONDARY_BUCKET_SHIFT);
}

static __inline u_long
tsb_bucket_size(u_int level)
{
	return (1UL << tsb_bucket_shift(level));
}

static __inline u_long
tsb_bucket_mask(u_int level)
{
	return (tsb_bucket_size(level) - 1);
}

static __inline u_long
tsb_mask_width(u_int level)
{
	return ((level * TSB_BUCKET_SPREAD_SHIFT) + TSB_MASK_WIDTH);
}

static __inline u_long
tsb_mask(u_int level)
{
	return ((1UL << tsb_mask_width(level)) - 1);
}

static __inline u_int
tsb_tlb_slot(u_int level)
{
	return (level == 0 ?
	    TLB_SLOT_TSB_USER_PRIMARY : TLB_SLOT_TSB_USER_SECONDARY);
}

static __inline vm_offset_t
tsb_stte_vtophys(pmap_t pm, struct stte *stp)
{
	vm_offset_t va;
	u_long data;

	va = (vm_offset_t)stp;
	if (pm == kernel_pmap)
		return (tsb_kernel_phys + (va - TSB_KERNEL_MIN_ADDRESS));

	if (trunc_page(va) == TSB_USER_MIN_ADDRESS)
		data = pm->pm_stte.st_tte.tte_data;
	else
		data = ldxa(TLB_DAR_SLOT(tsb_tlb_slot(1)),
		    ASI_DTLB_DATA_ACCESS_REG);
	return ((vm_offset_t)((TD_PA(data)) + (va & PAGE_MASK)));
}

static __inline struct stte *
tsb_vpntobucket(vm_offset_t vpn, u_int level)
{
	return (tsb_base(level) +
	    ((vpn & tsb_mask(level)) << tsb_bucket_shift(level)));
}

static __inline struct stte *
tsb_vtobucket(vm_offset_t va, u_int level)
{
	return (tsb_vpntobucket(va >> PAGE_SHIFT, level));
}

static __inline struct stte *
tsb_kvpntostte(vm_offset_t vpn)
{
	struct stte *stp;

	stp = (struct stte *)(TSB_KERNEL_MIN_ADDRESS +
	    ((vpn & TSB_KERNEL_MASK) << STTE_SHIFT));
	return (stp);
}

static __inline struct stte *
tsb_kvtostte(vm_offset_t va)
{
	return (tsb_kvpntostte(va >> PAGE_SHIFT));
}

struct	stte *tsb_get_bucket(pmap_t pm, u_int level, vm_offset_t va,
			     int allocate);
int	tsb_miss(pmap_t pm, u_int type, struct mmuframe *mf);
struct	tte tsb_page_alloc(pmap_t pm, vm_offset_t va);
void	tsb_page_fault(pmap_t pm, int level, vm_offset_t va, struct stte *stp);
void	tsb_page_init(void *va, int level);
struct	stte *tsb_stte_lookup(pmap_t pm, vm_offset_t va);
struct	stte *tsb_stte_promote(pmap_t pm, vm_offset_t va, struct stte *stp);
void	tsb_stte_remove(struct stte *stp);
struct	stte *tsb_tte_enter(pmap_t pm, vm_offset_t va, struct tte tte);
void	tsb_tte_local_remove(struct tte *tp);

extern vm_offset_t tsb_bootstrap_pages[];
extern int tsb_bootstrap_index;

#endif /* !_MACHINE_TSB_H_ */
OpenPOWER on IntegriCloud