xref: /illumos-gate/usr/src/uts/common/vm/seg_dev.h (revision 284ce987)
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
5c6939658Ssl  * Common Development and Distribution License (the "License").
6c6939658Ssl  * 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 /*
2240688216SSudheer A  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*284ce987SPatrick Mooney  * Copyright 2018 Joyent, Inc.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28b4203d75SMarcel Telka /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifndef	_VM_SEG_DEV_H
417c478bd9Sstevel@tonic-gate #define	_VM_SEG_DEV_H
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
47c6939658Ssl struct proc;
48c6939658Ssl 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * Structure whose pointer is passed to the segdev_create routine
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate struct segdev_crargs {
537c478bd9Sstevel@tonic-gate 	offset_t	offset;		/* starting offset */
547c478bd9Sstevel@tonic-gate 	int	(*mapfunc)(dev_t dev, off_t off, int prot); /* map function */
557c478bd9Sstevel@tonic-gate 	dev_t	dev;		/* device number */
567c478bd9Sstevel@tonic-gate 	uchar_t	type;		/* type of sharing done */
577c478bd9Sstevel@tonic-gate 	uchar_t	prot;		/* protection */
587c478bd9Sstevel@tonic-gate 	uchar_t	maxprot;	/* maximum protection */
597c478bd9Sstevel@tonic-gate 	uint_t	hat_attr;	/* hat attr */
607c478bd9Sstevel@tonic-gate 	uint_t	hat_flags;	/* currently, hat_flags is used ONLY for */
617c478bd9Sstevel@tonic-gate 				/* HAT_LOAD_NOCONSIST; in future, it can be */
627c478bd9Sstevel@tonic-gate 				/* expanded to include any flags that are */
637c478bd9Sstevel@tonic-gate 				/* not already part of hat_attr */
647c478bd9Sstevel@tonic-gate 	void    *devmap_data;   /* devmap_handle private data */
657c478bd9Sstevel@tonic-gate };
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * (Semi) private data maintained by the seg_dev driver per segment mapping
697c478bd9Sstevel@tonic-gate  *
707c478bd9Sstevel@tonic-gate  * The segment lock is necessary to protect fields that are modified
717c478bd9Sstevel@tonic-gate  * when the "read" version of the address space lock is held.  This lock
727c478bd9Sstevel@tonic-gate  * is not needed when the segment operation has the "write" version of
737c478bd9Sstevel@tonic-gate  * the address space lock (it would be redundant).
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  * The following fields in segdev_data are read-only when the address
767c478bd9Sstevel@tonic-gate  * space is "read" locked, and don't require the segment lock:
777c478bd9Sstevel@tonic-gate  *
787c478bd9Sstevel@tonic-gate  *	vp
797c478bd9Sstevel@tonic-gate  *	offset
807c478bd9Sstevel@tonic-gate  *	mapfunc
817c478bd9Sstevel@tonic-gate  *	maxprot
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate struct	segdev_data {
847c478bd9Sstevel@tonic-gate 	offset_t	offset;		/* device offset for start of mapping */
8544374aaeSsvemuri 	krwlock_t	lock;		/* protects segdev_data */
867c478bd9Sstevel@tonic-gate 	int	(*mapfunc)(dev_t dev, off_t off, int prot);
877c478bd9Sstevel@tonic-gate 	struct	vnode *vp;	/* vnode associated with device */
887c478bd9Sstevel@tonic-gate 	uchar_t	pageprot;	/* true if per page protections present */
897c478bd9Sstevel@tonic-gate 	uchar_t	prot;		/* current segment prot if pageprot == 0 */
907c478bd9Sstevel@tonic-gate 	uchar_t	maxprot;	/* maximum segment protections */
917c478bd9Sstevel@tonic-gate 	uchar_t	type;		/* type of sharing done */
927c478bd9Sstevel@tonic-gate 	struct	vpage *vpage;	/* per-page information, if needed */
937c478bd9Sstevel@tonic-gate 	uint_t	hat_attr;	/* hat attr - pass to attr in hat_devload */
947c478bd9Sstevel@tonic-gate 	uint_t	hat_flags;	/* set HAT_LOAD_NOCONSIST flag in hat_devload */
957c478bd9Sstevel@tonic-gate 				/* see comments above in segdev_crargs */
967c478bd9Sstevel@tonic-gate 	size_t	softlockcnt;	/* # of SOFTLOCKED in seg */
977c478bd9Sstevel@tonic-gate 	void    *devmap_data;   /* devmap_handle private data */
987c478bd9Sstevel@tonic-gate };
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /* Direct physical-userland mapping, without occupying kernel address space */
1017c478bd9Sstevel@tonic-gate #define	DEVMAP_PMEM_COOKIE	((ddi_umem_cookie_t)0x2)
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * pmem_cookie:
1057c478bd9Sstevel@tonic-gate  * Records physical memory pages to be exported to userland.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate struct devmap_pmem_cookie {
1087c478bd9Sstevel@tonic-gate 	pgcnt_t	dp_npages;		/* number of allocated mem pages */
1097c478bd9Sstevel@tonic-gate 	page_t  **dp_pparray;		/* pages allocated for this cookie */
1107c478bd9Sstevel@tonic-gate 	vnode_t *dp_vnp;		/* vnode associated with this cookie */
111c6939658Ssl 	proc_t *dp_proc;		/* proc ptr for resource control */
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1157c478bd9Sstevel@tonic-gate 
11640688216SSudheer A /*
11740688216SSudheer A  * Mappings of /dev/null come from segdev and have no mapping type.
11840688216SSudheer A  */
11940688216SSudheer A 
12040688216SSudheer A #define	SEG_IS_DEVNULL_MAPPING(seg)	\
12140688216SSudheer A 	((seg)->s_ops == &segdev_ops &&	\
12240688216SSudheer A 	((SEGOP_GETTYPE(seg, (seg)->s_base) & (MAP_SHARED | MAP_PRIVATE)) == 0))
12340688216SSudheer A 
1247c478bd9Sstevel@tonic-gate extern void segdev_init(void);
1257c478bd9Sstevel@tonic-gate 
126*284ce987SPatrick Mooney extern int segdev_create(struct seg **, void *);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate extern int segdev_copyto(struct seg *, caddr_t, const void *, void *, size_t);
1297c478bd9Sstevel@tonic-gate extern int segdev_copyfrom(struct seg *, caddr_t, const void *, void *, size_t);
1300616c1c3SMichael Corcoran extern struct seg_ops segdev_ops;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate #endif
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate #endif	/* _VM_SEG_DEV_H */
139