xref: /titanic_50/usr/src/uts/sun4/vm/mach_kpm.h (revision d29f5a711240f866521445b1656d114da090335e)
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 2008 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 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 /* kpm prototypes : routines defined in uts/sfmmu/vm/hat_sfmmu.c file */
34 extern kmutex_t *sfmmu_page_enter(page_t *);
35 extern void	sfmmu_page_exit(kmutex_t *);
36 extern void	sfmmu_cache_flush(pfn_t, int);
37 extern void	sfmmu_page_cache_array(page_t *, int, int, pgcnt_t);
38 extern cpuset_t	sfmmu_pageunload(page_t *, struct sf_hment *, int);
39 extern int	tst_tnc(page_t *pp, pgcnt_t);
40 extern void	conv_tnc(page_t *pp, int);
41 extern int	fnd_mapping_sz(page_t *);
42 extern int	sfmmu_page_spl_held(struct page *);
43 
44 /* kpm prototypes : routines defined in uts/sun4[uv]/vm/mach_kpm.c file */
45 extern void	sfmmu_kpm_pageunload(page_t *);
46 extern void	sfmmu_kpm_vac_unload(page_t *, caddr_t);
47 extern void	sfmmu_kpm_hme_unload(page_t *);
48 extern kpm_hlk_t *sfmmu_kpm_kpmp_enter(page_t *, pgcnt_t);
49 extern void	sfmmu_kpm_kpmp_exit(kpm_hlk_t *kpmp);
50 extern void	sfmmu_kpm_page_cache(page_t *, int, int);
51 
52 /* flags for hat_pagecachectl */
53 #define	HAT_CACHE	0x1
54 #define	HAT_UNCACHE	0x2
55 #define	HAT_TMPNC	0x4
56 
57 /*
58  * kstat data
59  */
60 struct sfmmu_global_stat sfmmu_global_stat;
61 
62 /* kpm globals */
63 #ifdef	DEBUG
64 /*
65  * Flush the TLB on kpm mapout. Note: Xcalls are used (again) for the
66  * required TLB shootdowns in this case, so handle w/ care. Off by default.
67  */
68 int	kpm_tlb_flush;
69 #endif	/* DEBUG */
70 
71 /*
72  * kpm_page lock hash.
73  * All slots should be used equally and 2 adjacent kpm_page_t's
74  * shouldn't have their mutexes in the same cache line.
75  */
76 #ifdef	DEBUG
77 int kpmp_hash_debug;
78 #define	KPMP_HASH(kpp)	(kpmp_hash_debug ? &kpmp_table[0] : &kpmp_table[ \
79 	((uintptr_t)(kpp) + ((uintptr_t)(kpp) >> kpmp_shift)) \
80 	& (kpmp_table_sz - 1)])
81 #else	/* !DEBUG */
82 #define	KPMP_HASH(kpp)	&kpmp_table[ \
83 	((uintptr_t)(kpp) + ((uintptr_t)(kpp) >> kpmp_shift)) \
84 	& (kpmp_table_sz - 1)]
85 #endif	/* DEBUG */
86 
87 #ifdef	DEBUG
88 #define	KPMP_SHASH(kpp)	(kpmp_hash_debug ? &kpmp_stable[0] : &kpmp_stable[ \
89 	(((uintptr_t)(kpp) << kpmp_shift) + (uintptr_t)(kpp)) \
90 	& (kpmp_stable_sz - 1)])
91 #else	/* !DEBUG */
92 #define	KPMP_SHASH(kpp)	&kpmp_stable[ \
93 	(((uintptr_t)(kpp) << kpmp_shift) + (uintptr_t)(kpp)) \
94 	& (kpmp_stable_sz - 1)]
95 #endif	/* DEBUG */
96 
97 /*
98  * kpm virtual address to physical address. Any changes in this macro must
99  * also be ported to the assembly implementation in sfmmu_asm.s
100  */
101 #ifdef VAC
102 #define	SFMMU_KPM_VTOP(vaddr, paddr) {					\
103 	uintptr_t r, v;							\
104 									\
105 	r = ((vaddr) - kpm_vbase) >> (uintptr_t)kpm_size_shift;		\
106 	(paddr) = (vaddr) - kpm_vbase;					\
107 	if (r != 0) {							\
108 		v = ((uintptr_t)(vaddr) >> MMU_PAGESHIFT) &		\
109 		    vac_colors_mask;					\
110 		(paddr) -= r << kpm_size_shift;				\
111 		if (r > v)						\
112 			(paddr) += (r - v) << MMU_PAGESHIFT;		\
113 		else							\
114 			(paddr) -= r << MMU_PAGESHIFT;			\
115 	}								\
116 }
117 #else	/* VAC */
118 #define	SFMMU_KPM_VTOP(vaddr, paddr) {					\
119 	(paddr) = (vaddr) - kpm_vbase;					\
120 }
121 #endif	/* VAC */
122 
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif	/* _MACH_KPM_H */
128