xref: /onnv-gate/usr/src/uts/common/vm/seg_dev.h (revision 10169:116daeae7223)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52768Ssl108498  * Common Development and Distribution License (the "License").
62768Ssl108498  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*10169SSudheer.Abdul-Salam@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate  * The Regents of the University of California
320Sstevel@tonic-gate  * All Rights Reserved
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate  * contributors.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifndef	_VM_SEG_DEV_H
400Sstevel@tonic-gate #define	_VM_SEG_DEV_H
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	__cplusplus
430Sstevel@tonic-gate extern "C" {
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
462768Ssl108498 struct proc;
472768Ssl108498 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * Structure whose pointer is passed to the segdev_create routine
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate struct segdev_crargs {
520Sstevel@tonic-gate 	offset_t	offset;		/* starting offset */
530Sstevel@tonic-gate 	int	(*mapfunc)(dev_t dev, off_t off, int prot); /* map function */
540Sstevel@tonic-gate 	dev_t	dev;		/* device number */
550Sstevel@tonic-gate 	uchar_t	type;		/* type of sharing done */
560Sstevel@tonic-gate 	uchar_t	prot;		/* protection */
570Sstevel@tonic-gate 	uchar_t	maxprot;	/* maximum protection */
580Sstevel@tonic-gate 	uint_t	hat_attr;	/* hat attr */
590Sstevel@tonic-gate 	uint_t	hat_flags;	/* currently, hat_flags is used ONLY for */
600Sstevel@tonic-gate 				/* HAT_LOAD_NOCONSIST; in future, it can be */
610Sstevel@tonic-gate 				/* expanded to include any flags that are */
620Sstevel@tonic-gate 				/* not already part of hat_attr */
630Sstevel@tonic-gate 	void    *devmap_data;   /* devmap_handle private data */
640Sstevel@tonic-gate };
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * (Semi) private data maintained by the seg_dev driver per segment mapping
680Sstevel@tonic-gate  *
690Sstevel@tonic-gate  * The segment lock is necessary to protect fields that are modified
700Sstevel@tonic-gate  * when the "read" version of the address space lock is held.  This lock
710Sstevel@tonic-gate  * is not needed when the segment operation has the "write" version of
720Sstevel@tonic-gate  * the address space lock (it would be redundant).
730Sstevel@tonic-gate  *
740Sstevel@tonic-gate  * The following fields in segdev_data are read-only when the address
750Sstevel@tonic-gate  * space is "read" locked, and don't require the segment lock:
760Sstevel@tonic-gate  *
770Sstevel@tonic-gate  *	vp
780Sstevel@tonic-gate  *	offset
790Sstevel@tonic-gate  *	mapfunc
800Sstevel@tonic-gate  *	maxprot
810Sstevel@tonic-gate  */
820Sstevel@tonic-gate struct	segdev_data {
830Sstevel@tonic-gate 	offset_t	offset;		/* device offset for start of mapping */
845667Ssvemuri 	krwlock_t	lock;		/* protects segdev_data */
850Sstevel@tonic-gate 	int	(*mapfunc)(dev_t dev, off_t off, int prot);
860Sstevel@tonic-gate 	struct	vnode *vp;	/* vnode associated with device */
870Sstevel@tonic-gate 	uchar_t	pageprot;	/* true if per page protections present */
880Sstevel@tonic-gate 	uchar_t	prot;		/* current segment prot if pageprot == 0 */
890Sstevel@tonic-gate 	uchar_t	maxprot;	/* maximum segment protections */
900Sstevel@tonic-gate 	uchar_t	type;		/* type of sharing done */
910Sstevel@tonic-gate 	struct	vpage *vpage;	/* per-page information, if needed */
920Sstevel@tonic-gate 	uint_t	hat_attr;	/* hat attr - pass to attr in hat_devload */
930Sstevel@tonic-gate 	uint_t	hat_flags;	/* set HAT_LOAD_NOCONSIST flag in hat_devload */
940Sstevel@tonic-gate 				/* see comments above in segdev_crargs */
950Sstevel@tonic-gate 	size_t	softlockcnt;	/* # of SOFTLOCKED in seg */
960Sstevel@tonic-gate 	void    *devmap_data;   /* devmap_handle private data */
970Sstevel@tonic-gate };
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /* Direct physical-userland mapping, without occupying kernel address space */
1000Sstevel@tonic-gate #define	DEVMAP_PMEM_COOKIE	((ddi_umem_cookie_t)0x2)
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * pmem_cookie:
1040Sstevel@tonic-gate  * Records physical memory pages to be exported to userland.
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate struct devmap_pmem_cookie {
1070Sstevel@tonic-gate 	pgcnt_t	dp_npages;		/* number of allocated mem pages */
1080Sstevel@tonic-gate 	page_t  **dp_pparray;		/* pages allocated for this cookie */
1090Sstevel@tonic-gate 	vnode_t *dp_vnp;		/* vnode associated with this cookie */
1102768Ssl108498 	proc_t *dp_proc;		/* proc ptr for resource control */
1110Sstevel@tonic-gate };
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate #ifdef _KERNEL
1140Sstevel@tonic-gate 
115*10169SSudheer.Abdul-Salam@Sun.COM /*
116*10169SSudheer.Abdul-Salam@Sun.COM  * Mappings of /dev/null come from segdev and have no mapping type.
117*10169SSudheer.Abdul-Salam@Sun.COM  */
118*10169SSudheer.Abdul-Salam@Sun.COM 
119*10169SSudheer.Abdul-Salam@Sun.COM #define	SEG_IS_DEVNULL_MAPPING(seg)	\
120*10169SSudheer.Abdul-Salam@Sun.COM 	((seg)->s_ops == &segdev_ops &&	\
121*10169SSudheer.Abdul-Salam@Sun.COM 	((SEGOP_GETTYPE(seg, (seg)->s_base) & (MAP_SHARED | MAP_PRIVATE)) == 0))
122*10169SSudheer.Abdul-Salam@Sun.COM 
1230Sstevel@tonic-gate extern void segdev_init(void);
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate extern int segdev_create(struct seg *, void *);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate extern int segdev_copyto(struct seg *, caddr_t, const void *, void *, size_t);
1280Sstevel@tonic-gate extern int segdev_copyfrom(struct seg *, caddr_t, const void *, void *, size_t);
1298212SMichael.Corcoran@Sun.COM extern struct seg_ops segdev_ops;
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate #endif	/* _KERNEL */
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate #ifdef	__cplusplus
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate #endif
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate #endif	/* _VM_SEG_DEV_H */
138