1 /* $OpenBSD: uvm.h,v 1.73 2024/04/02 08:39:17 deraadt 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 * F uvm.fpageqlock 51 */ 52 struct uvm { 53 /* vm_page related parameters */ 54 55 /* vm_page queues */ 56 struct pglist page_active; /* [Q] allocated pages, in use */ 57 struct pglist page_inactive; /* [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; /* [F] 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 #define UVM_ET_OBJ 0x0001 /* it is a uvm_object */ 87 #define UVM_ET_SUBMAP 0x0002 /* it is a vm_map submap */ 88 #define UVM_ET_COPYONWRITE 0x0004 /* copy_on_write */ 89 #define UVM_ET_NEEDSCOPY 0x0008 /* needs_copy */ 90 #define UVM_ET_HOLE 0x0010 /* no backend */ 91 #define UVM_ET_NOFAULT 0x0020 /* don't fault */ 92 #define UVM_ET_STACK 0x0040 /* this is a stack */ 93 #define UVM_ET_WC 0x0080 /* write combining */ 94 #define UVM_ET_CONCEAL 0x0100 /* omit from dumps */ 95 #define UVM_ET_IMMUTABLE 0x0400 /* entry may not be changed */ 96 #define UVM_ET_FREEMAPPED 0x8000 /* map entry is on free list (DEBUG) */ 97 98 #define UVM_ET_ISOBJ(E) (((E)->etype & UVM_ET_OBJ) != 0) 99 #define UVM_ET_ISSUBMAP(E) (((E)->etype & UVM_ET_SUBMAP) != 0) 100 #define UVM_ET_ISCOPYONWRITE(E) (((E)->etype & UVM_ET_COPYONWRITE) != 0) 101 #define UVM_ET_ISNEEDSCOPY(E) (((E)->etype & UVM_ET_NEEDSCOPY) != 0) 102 #define UVM_ET_ISHOLE(E) (((E)->etype & UVM_ET_HOLE) != 0) 103 #define UVM_ET_ISNOFAULT(E) (((E)->etype & UVM_ET_NOFAULT) != 0) 104 #define UVM_ET_ISSTACK(E) (((E)->etype & UVM_ET_STACK) != 0) 105 #define UVM_ET_ISWC(E) (((E)->etype & UVM_ET_WC) != 0) 106 #define UVM_ET_ISCONCEAL(E) (((E)->etype & UVM_ET_CONCEAL) != 0) 107 108 #ifdef _KERNEL 109 110 /* 111 * holds all the internal UVM data 112 */ 113 extern struct uvm uvm; 114 115 /* 116 * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN) 117 */ 118 119 #if defined(UVM_PAGE_TRKOWN) 120 #define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG) 121 #else 122 #define UVM_PAGE_OWN(PG, TAG) /* nothing */ 123 #endif /* UVM_PAGE_TRKOWN */ 124 125 /* 126 * uvm_map internal functions. 127 * Used by uvm_map address selectors. 128 */ 129 struct vm_map_entry *uvm_map_entrybyaddr(struct uvm_map_addr *, vaddr_t); 130 int uvm_map_isavail(struct vm_map *, 131 struct uvm_addr_state *, 132 struct vm_map_entry **, struct vm_map_entry**, 133 vaddr_t, vsize_t); 134 struct uvm_addr_state *uvm_map_uaddr(struct vm_map *, vaddr_t); 135 struct uvm_addr_state *uvm_map_uaddr_e(struct vm_map *, struct vm_map_entry *); 136 137 #define VMMAP_FREE_START(_entry) ((_entry)->end + (_entry)->guard) 138 #define VMMAP_FREE_END(_entry) ((_entry)->end + (_entry)->guard + \ 139 (_entry)->fspace) 140 141 #endif /* _KERNEL */ 142 143 #endif /* _UVM_UVM_H_ */ 144