xref: /illumos-gate/usr/src/uts/common/vm/seg_kpm.h (revision a31148363f598def767ac48c5d82e1572e44b935)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*a3114836SGerry Liu  * Common Development and Distribution License (the "License").
6*a3114836SGerry Liu  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
227c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_VM_SEG_KPM_H
277c478bd9Sstevel@tonic-gate #define	_VM_SEG_KPM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Kernel Physical Mapping (segkpm) segment driver.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <vm/kpm.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate struct segkpm_data {
407c478bd9Sstevel@tonic-gate 	ushort_t *skd_va_select; /* page_create_va kpm vaddr bin count */
417c478bd9Sstevel@tonic-gate 	short    skd_nvcolors;   /* VAC colors to deal with */
427c478bd9Sstevel@tonic-gate 	uchar_t  skd_prot;
437c478bd9Sstevel@tonic-gate };
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * segkpm create needs some platform knowledge
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate struct segkpm_crargs {
497c478bd9Sstevel@tonic-gate 	uint_t	prot;
507c478bd9Sstevel@tonic-gate 	short	nvcolors;	/* VAC # virtual colors, 0 for PAC. */
517c478bd9Sstevel@tonic-gate };
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate extern struct seg *segkpm;
547c478bd9Sstevel@tonic-gate extern u_offset_t kpm_pgoff;
557c478bd9Sstevel@tonic-gate extern size_t	kpm_pgsz;
567c478bd9Sstevel@tonic-gate extern uint_t	kpm_pgshft;
577c478bd9Sstevel@tonic-gate extern uint_t	kpmp2pshft;
587c478bd9Sstevel@tonic-gate extern pgcnt_t	kpmpnpgs;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* kpm controls */
617c478bd9Sstevel@tonic-gate extern int	kpm_enable;
627c478bd9Sstevel@tonic-gate extern int	kpm_smallpages;
637c478bd9Sstevel@tonic-gate extern int	segmap_kpm;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * kpm_page_t macros:
677c478bd9Sstevel@tonic-gate  * . bytes (b) to kpm pages (kpmp)
687c478bd9Sstevel@tonic-gate  * . pages (p) to kpm pages (kpmp), and back (with and without roundup)
697c478bd9Sstevel@tonic-gate  * . kpm page offset in bytes
707c478bd9Sstevel@tonic-gate  * . pages (p) modulo kpm pages (kpmp)
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	btokpmp(x)	((x) >> kpm_pgshft)
737c478bd9Sstevel@tonic-gate #define	btokpmpr(x)	(((x) + kpm_pgoff) >> kpm_pgshft)
747c478bd9Sstevel@tonic-gate #define	ptokpmp(x)	((x) >> kpmp2pshft)
757c478bd9Sstevel@tonic-gate #define	ptokpmpr(x)	(((x) + (kpmpnpgs - 1)) >> kpmp2pshft)
767c478bd9Sstevel@tonic-gate #define	kpmptop(x)	((x) << kpmp2pshft)
777c478bd9Sstevel@tonic-gate #define	kpmpageoff(x)	((x) & kpm_pgoff)
787c478bd9Sstevel@tonic-gate #define	pmodkpmp(x)	((x) & (kpmpnpgs - 1))
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #ifdef	SEGKPM_SUPPORT
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	IS_KPM_ADDR(addr) \
837c478bd9Sstevel@tonic-gate 	((addr) >= segkpm->s_base && (addr) < (segkpm->s_base + segkpm->s_size))
847c478bd9Sstevel@tonic-gate 
85*a3114836SGerry Liu #ifdef	__x86
86*a3114836SGerry Liu /* x86 systems use neither kpm_page_t nor kpm_spage_t when supporting kpm. */
87*a3114836SGerry Liu #define	KPMPAGE_T_SZ	(0)
88*a3114836SGerry Liu #else	/* __x86 */
897c478bd9Sstevel@tonic-gate #define	KPMPAGE_T_SZ \
907c478bd9Sstevel@tonic-gate 	((kpm_smallpages == 0) ? sizeof (kpm_page_t) : sizeof (kpm_spage_t))
91*a3114836SGerry Liu #endif	/* __x86 */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #else	/* SEGKPM_SUPPORT */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	IS_KPM_ADDR(addr) (segkpm != NULL)
967c478bd9Sstevel@tonic-gate #define	KPMPAGE_T_SZ	(0)
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #endif	/* SEGKPM_SUPPORT */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * Public seg_kpm segment operations.
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate extern int		segkpm_create(struct seg *, void *);
1057c478bd9Sstevel@tonic-gate extern faultcode_t	segkpm_fault(struct hat *, struct seg *, caddr_t,
1067c478bd9Sstevel@tonic-gate 				size_t, enum fault_type, enum seg_rw);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * Public seg_kpm interfaces.
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate extern caddr_t	segkpm_create_va(u_offset_t);
1127c478bd9Sstevel@tonic-gate extern void	segkpm_mapout_validkpme(struct kpme *);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate #endif
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #endif	/* _VM_SEG_KPM_H */
121