xref: /titanic_50/usr/src/uts/sun4/vm/mach_kpm.h (revision e07d9cb85217949d497b02d7211de8a197d2f2eb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_MACH_KPM_H
27 #define	_MACH_KPM_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /* kpm prototypes : routines defined in uts/sfmmu/vm/hat_sfmmu.c file */
36 extern kmutex_t *sfmmu_page_enter(page_t *);
37 extern void	sfmmu_page_exit(kmutex_t *);
38 extern void	sfmmu_cache_flush(pfn_t, int);
39 extern void	sfmmu_page_cache_array(page_t *, int, int, pgcnt_t);
40 extern cpuset_t	sfmmu_pageunload(page_t *, struct sf_hment *, int);
41 extern int	tst_tnc(page_t *pp, pgcnt_t);
42 extern void	conv_tnc(page_t *pp, int);
43 extern int	fnd_mapping_sz(page_t *);
44 extern int	sfmmu_page_spl_held(struct page *);
45 
46 /* kpm prototypes : routines defined in uts/sun4[uv]/vm/mach_kpm.c file */
47 extern void	sfmmu_kpm_pageunload(page_t *);
48 extern void	sfmmu_kpm_vac_unload(page_t *, caddr_t);
49 extern void	sfmmu_kpm_hme_unload(page_t *);
50 extern kpm_hlk_t *sfmmu_kpm_kpmp_enter(page_t *, pgcnt_t);
51 extern void	sfmmu_kpm_kpmp_exit(kpm_hlk_t *kpmp);
52 extern void	sfmmu_kpm_page_cache(page_t *, int, int);
53 
54 /* flags for hat_pagecachectl */
55 #define	HAT_CACHE	0x1
56 #define	HAT_UNCACHE	0x2
57 #define	HAT_TMPNC	0x4
58 
59 /*
60  * kstat data
61  */
62 struct sfmmu_global_stat sfmmu_global_stat;
63 
64 /* kpm globals */
65 #ifdef	DEBUG
66 /*
67  * Flush the TLB on kpm mapout. Note: Xcalls are used (again) for the
68  * required TLB shootdowns in this case, so handle w/ care. Off by default.
69  */
70 int	kpm_tlb_flush;
71 #endif	/* DEBUG */
72 
73 /*
74  * kpm_page lock hash.
75  * All slots should be used equally and 2 adjacent kpm_page_t's
76  * shouldn't have their mutexes in the same cache line.
77  */
78 #ifdef	DEBUG
79 int kpmp_hash_debug;
80 #define	KPMP_HASH(kpp)	(kpmp_hash_debug ? &kpmp_table[0] : &kpmp_table[ \
81 	((uintptr_t)(kpp) + ((uintptr_t)(kpp) >> kpmp_shift)) \
82 	& (kpmp_table_sz - 1)])
83 #else	/* !DEBUG */
84 #define	KPMP_HASH(kpp)	&kpmp_table[ \
85 	((uintptr_t)(kpp) + ((uintptr_t)(kpp) >> kpmp_shift)) \
86 	& (kpmp_table_sz - 1)]
87 #endif	/* DEBUG */
88 
89 #ifdef	DEBUG
90 #define	KPMP_SHASH(kpp)	(kpmp_hash_debug ? &kpmp_stable[0] : &kpmp_stable[ \
91 	(((uintptr_t)(kpp) << kpmp_shift) + (uintptr_t)(kpp)) \
92 	& (kpmp_stable_sz - 1)])
93 #else	/* !DEBUG */
94 #define	KPMP_SHASH(kpp)	&kpmp_stable[ \
95 	(((uintptr_t)(kpp) << kpmp_shift) + (uintptr_t)(kpp)) \
96 	& (kpmp_stable_sz - 1)]
97 #endif	/* DEBUG */
98 
99 /*
100  * kpm virtual address to physical address
101  */
102 #ifdef VAC
103 #define	SFMMU_KPM_VTOP(vaddr, paddr) {					\
104 	uintptr_t r, v;							\
105 									\
106 	r = ((vaddr) - kpm_vbase) >> (uintptr_t)kpm_size_shift;		\
107 	(paddr) = (vaddr) - kpm_vbase;					\
108 	if (r != 0) {							\
109 		v = ((uintptr_t)(vaddr) >> MMU_PAGESHIFT) &		\
110 		    vac_colors_mask;					\
111 		(paddr) -= r << kpm_size_shift;				\
112 		if (r > v)						\
113 			(paddr) += (r - v) << MMU_PAGESHIFT;		\
114 		else							\
115 			(paddr) -= r << MMU_PAGESHIFT;			\
116 	}								\
117 }
118 #else	/* VAC */
119 #define	SFMMU_KPM_VTOP(vaddr, paddr) {					\
120 	(paddr) = (vaddr) - kpm_vbase;					\
121 }
122 #endif	/* VAC */
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif	/* _MACH_KPM_H */
129