xref: /openbsd/sys/uvm/uvm.h (revision dda28197)
1 /*	$OpenBSD: uvm.h,v 1.68 2020/11/24 13:49:09 mpi Exp $	*/
2 /*	$NetBSD: uvm.h,v 1.24 2000/11/27 08:40:02 chs Exp $	*/
3 
4 /*
5  * Copyright (c) 1997 Charles D. Cranor and Washington University.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp
29  */
30 
31 #ifndef _UVM_UVM_H_
32 #define _UVM_UVM_H_
33 
34 #include <uvm/uvm_extern.h>
35 #include <uvm/uvm_amap.h>
36 #include <uvm/uvm_aobj.h>
37 #include <uvm/uvm_fault.h>
38 #include <uvm/uvm_glue.h>
39 #include <uvm/uvm_km.h>
40 #include <uvm/uvm_swap.h>
41 
42 #include <uvm/uvm_pmemrange.h>
43 
44 /*
45  * uvm structure (vm global state: collected in one structure for ease
46  * of reference...)
47  *
48  *  Locks used to protect struct members in this file:
49  *	Q	uvm.pageqlock
50  */
51 struct uvm {
52 	/* vm_page related parameters */
53 
54 	/* vm_page queues */
55 	struct pglist page_active;	/* [Q] allocated pages, in use */
56 	struct pglist page_inactive_swp;/* [Q] pages inactive (reclaim/free) */
57 	struct pglist page_inactive_obj;/* [Q] pages inactive (reclaim/free) */
58 	/* Lock order: pageqlock, then fpageqlock. */
59 	struct mutex pageqlock;		/* [] lock for active/inactive page q */
60 	struct mutex fpageqlock;	/* [] lock for free page q  + pdaemon */
61 	boolean_t page_init_done;	/* TRUE if uvm_page_init() finished */
62 	struct uvm_pmr_control pmr_control; /* pmemrange data */
63 
64 		/* page daemon trigger */
65 	int pagedaemon;			/* daemon sleeps on this */
66 	struct proc *pagedaemon_proc;	/* daemon's pid */
67 
68 		/* aiodone daemon trigger */
69 	int aiodoned;			/* daemon sleeps on this */
70 	struct proc *aiodoned_proc;	/* daemon's pid */
71 	struct mutex aiodoned_lock;
72 
73 	/* static kernel map entry pool */
74 	SLIST_HEAD(, vm_map_entry) kentry_free; /* free page pool */
75 
76 	/* aio_done is locked by uvm.aiodoned_lock. */
77 	TAILQ_HEAD(, buf) aio_done;		/* done async i/o reqs */
78 
79 	/* kernel object: to support anonymous pageable kernel memory */
80 	struct uvm_object *kernel_object;
81 };
82 
83 /*
84  * vm_map_entry etype bits:
85  *
86  * keep in sync with KVM_ET_*
87  */
88 #define UVM_ET_OBJ		0x0001	/* it is a uvm_object */
89 #define UVM_ET_SUBMAP		0x0002	/* it is a vm_map submap */
90 #define UVM_ET_COPYONWRITE 	0x0004	/* copy_on_write */
91 #define UVM_ET_NEEDSCOPY	0x0008	/* needs_copy */
92 #define UVM_ET_HOLE		0x0010	/* no backend */
93 #define UVM_ET_NOFAULT		0x0020	/* don't fault */
94 #define UVM_ET_STACK		0x0040	/* this is a stack */
95 #define UVM_ET_WC		0x0080	/* write combining */
96 #define UVM_ET_CONCEAL		0x0100	/* omit from dumps */
97 #define UVM_ET_SYSCALL		0x0200	/* syscall text segment */
98 #define UVM_ET_FREEMAPPED	0x8000	/* map entry is on free list (DEBUG) */
99 
100 #define UVM_ET_ISOBJ(E)		(((E)->etype & UVM_ET_OBJ) != 0)
101 #define UVM_ET_ISSUBMAP(E)	(((E)->etype & UVM_ET_SUBMAP) != 0)
102 #define UVM_ET_ISCOPYONWRITE(E)	(((E)->etype & UVM_ET_COPYONWRITE) != 0)
103 #define UVM_ET_ISNEEDSCOPY(E)	(((E)->etype & UVM_ET_NEEDSCOPY) != 0)
104 #define UVM_ET_ISHOLE(E)	(((E)->etype & UVM_ET_HOLE) != 0)
105 #define UVM_ET_ISNOFAULT(E)	(((E)->etype & UVM_ET_NOFAULT) != 0)
106 #define UVM_ET_ISSTACK(E)	(((E)->etype & UVM_ET_STACK) != 0)
107 #define UVM_ET_ISWC(E)		(((E)->etype & UVM_ET_WC) != 0)
108 #define UVM_ET_ISCONCEAL(E)	(((E)->etype & UVM_ET_CONCEAL) != 0)
109 
110 #ifdef _KERNEL
111 
112 /*
113  * holds all the internal UVM data
114  */
115 extern struct uvm uvm;
116 
117 /*
118  * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN)
119  */
120 
121 #if defined(UVM_PAGE_TRKOWN)
122 #define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG)
123 #else
124 #define UVM_PAGE_OWN(PG, TAG) /* nothing */
125 #endif /* UVM_PAGE_TRKOWN */
126 
127 /*
128  * uvm_map internal functions.
129  * Used by uvm_map address selectors.
130  */
131 struct vm_map_entry	*uvm_map_entrybyaddr(struct uvm_map_addr *, vaddr_t);
132 int			 uvm_map_isavail(struct vm_map *,
133 			    struct uvm_addr_state *,
134 			    struct vm_map_entry **, struct vm_map_entry**,
135 			    vaddr_t, vsize_t);
136 struct uvm_addr_state	*uvm_map_uaddr(struct vm_map *, vaddr_t);
137 struct uvm_addr_state	*uvm_map_uaddr_e(struct vm_map *, struct vm_map_entry *);
138 
139 #define VMMAP_FREE_START(_entry)	((_entry)->end + (_entry)->guard)
140 #define VMMAP_FREE_END(_entry)		((_entry)->end + (_entry)->guard + \
141 					    (_entry)->fspace)
142 
143 #endif /* _KERNEL */
144 
145 #endif /* _UVM_UVM_H_ */
146