xref: /illumos-gate/usr/src/uts/common/vm/seg_dev.h (revision 2c5ec7a875dcd76853e6618614e990f1e8cdd56d)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  * Copyright 2018 Joyent, Inc.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef	_VM_SEG_DEV_H
41 #define	_VM_SEG_DEV_H
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 struct proc;
48 
49 /*
50  * Structure whose pointer is passed to the segdev_create routine
51  */
52 struct segdev_crargs {
53 	offset_t	offset;		/* starting offset */
54 	int	(*mapfunc)(dev_t dev, off_t off, int prot); /* map function */
55 	dev_t	dev;		/* device number */
56 	uchar_t	type;		/* type of sharing done */
57 	uchar_t	prot;		/* protection */
58 	uchar_t	maxprot;	/* maximum protection */
59 	uint_t	hat_attr;	/* hat attr */
60 	uint_t	hat_flags;	/* currently, hat_flags is used ONLY for */
61 				/* HAT_LOAD_NOCONSIST; in future, it can be */
62 				/* expanded to include any flags that are */
63 				/* not already part of hat_attr */
64 	void    *devmap_data;   /* devmap_handle private data */
65 };
66 
67 /*
68  * (Semi) private data maintained by the seg_dev driver per segment mapping
69  *
70  * The segment lock is necessary to protect fields that are modified
71  * when the "read" version of the address space lock is held.  This lock
72  * is not needed when the segment operation has the "write" version of
73  * the address space lock (it would be redundant).
74  *
75  * The following fields in segdev_data are read-only when the address
76  * space is "read" locked, and don't require the segment lock:
77  *
78  *	vp
79  *	offset
80  *	mapfunc
81  *	maxprot
82  */
83 struct	segdev_data {
84 	offset_t	offset;		/* device offset for start of mapping */
85 	krwlock_t	lock;		/* protects segdev_data */
86 	int	(*mapfunc)(dev_t dev, off_t off, int prot);
87 	struct	vnode *vp;	/* vnode associated with device */
88 	uchar_t	pageprot;	/* true if per page protections present */
89 	uchar_t	prot;		/* current segment prot if pageprot == 0 */
90 	uchar_t	maxprot;	/* maximum segment protections */
91 	uchar_t	type;		/* type of sharing done */
92 	struct	vpage *vpage;	/* per-page information, if needed */
93 	uint_t	hat_attr;	/* hat attr - pass to attr in hat_devload */
94 	uint_t	hat_flags;	/* set HAT_LOAD_NOCONSIST flag in hat_devload */
95 				/* see comments above in segdev_crargs */
96 	size_t	softlockcnt;	/* # of SOFTLOCKED in seg */
97 	void    *devmap_data;   /* devmap_handle private data */
98 };
99 
100 /* Direct physical-userland mapping, without occupying kernel address space */
101 #define	DEVMAP_PMEM_COOKIE	((ddi_umem_cookie_t)0x2)
102 
103 /*
104  * pmem_cookie:
105  * Records physical memory pages to be exported to userland.
106  */
107 struct devmap_pmem_cookie {
108 	pgcnt_t	dp_npages;		/* number of allocated mem pages */
109 	page_t  **dp_pparray;		/* pages allocated for this cookie */
110 	vnode_t *dp_vnp;		/* vnode associated with this cookie */
111 	proc_t *dp_proc;		/* proc ptr for resource control */
112 };
113 
114 #ifdef _KERNEL
115 
116 /*
117  * Mappings of /dev/null come from segdev and have no mapping type.
118  */
119 
120 #define	SEG_IS_DEVNULL_MAPPING(seg)	\
121 	((seg)->s_ops == &segdev_ops &&	\
122 	((SEGOP_GETTYPE(seg, (seg)->s_base) & (MAP_SHARED | MAP_PRIVATE)) == 0))
123 
124 extern void segdev_init(void);
125 
126 extern int segdev_create(struct seg **, void *);
127 
128 extern int segdev_copyto(struct seg *, caddr_t, const void *, void *, size_t);
129 extern int segdev_copyfrom(struct seg *, caddr_t, const void *, void *, size_t);
130 extern struct seg_ops segdev_ops;
131 
132 #endif	/* _KERNEL */
133 
134 #ifdef	__cplusplus
135 }
136 #endif
137 
138 #endif	/* _VM_SEG_DEV_H */
139