1 1.9 tnn /* $NetBSD: uvm_physseg.h,v 1.9 2024/01/13 09:44:42 tnn Exp $ */ 2 1.6 cherry 3 1.6 cherry /*- 4 1.6 cherry * Copyright (c) 2016 The NetBSD Foundation, Inc. 5 1.6 cherry * All rights reserved. 6 1.6 cherry * 7 1.6 cherry * This code is derived from software contributed to The NetBSD Foundation 8 1.6 cherry * by Cherry G. Mathew <cherry (at) NetBSD.org> 9 1.6 cherry * 10 1.6 cherry * Redistribution and use in source and binary forms, with or without 11 1.6 cherry * modification, are permitted provided that the following conditions 12 1.6 cherry * are met: 13 1.6 cherry * 1. Redistributions of source code must retain the above copyright 14 1.6 cherry * notice, this list of conditions and the following disclaimer. 15 1.6 cherry * 2. Redistributions in binary form must reproduce the above copyright 16 1.6 cherry * notice, this list of conditions and the following disclaimer in the 17 1.6 cherry * documentation and/or other materials provided with the distribution. 18 1.6 cherry * 19 1.6 cherry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.6 cherry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.6 cherry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.6 cherry * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.6 cherry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.6 cherry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.6 cherry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.6 cherry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.6 cherry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.6 cherry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.6 cherry * POSSIBILITY OF SUCH DAMAGE. 30 1.6 cherry */ 31 1.1 cherry 32 1.1 cherry /* 33 1.1 cherry * Consolidated API from uvm_page.c and others. 34 1.6 cherry * Consolidated and designed by Cherry G. Mathew <cherry (at) NetBSD.org> 35 1.1 cherry */ 36 1.1 cherry 37 1.1 cherry #ifndef _UVM_UVM_PHYSSEG_H_ 38 1.1 cherry #define _UVM_UVM_PHYSSEG_H_ 39 1.1 cherry 40 1.1 cherry #if defined(_KERNEL_OPT) 41 1.1 cherry #include "opt_uvm_hotplug.h" 42 1.1 cherry #endif 43 1.1 cherry 44 1.1 cherry #include <sys/cdefs.h> 45 1.1 cherry #include <sys/param.h> 46 1.1 cherry #include <sys/types.h> 47 1.1 cherry 48 1.1 cherry /* 49 1.1 cherry * No APIs are explicitly #included in uvm_physseg.c 50 1.1 cherry */ 51 1.1 cherry 52 1.1 cherry #if defined(UVM_HOTPLUG) /* rbtree impementation */ 53 1.1 cherry #define PRIxPHYSSEG "p" 54 1.1 cherry 55 1.1 cherry /* 56 1.1 cherry * These are specific values of invalid constants for uvm_physseg_t. 57 1.2 cherry * uvm_physseg_valid_p() == false on any of the below constants. 58 1.1 cherry * 59 1.1 cherry * Specific invalid constants encapsulate specific explicit failure 60 1.1 cherry * scenarios (see the comments next to them) 61 1.1 cherry */ 62 1.1 cherry 63 1.1 cherry #define UVM_PHYSSEG_TYPE_INVALID NULL /* Generic invalid value */ 64 1.1 cherry #define UVM_PHYSSEG_TYPE_INVALID_EMPTY NULL /* empty segment access */ 65 1.1 cherry #define UVM_PHYSSEG_TYPE_INVALID_OVERFLOW NULL /* ran off the end of the last segment */ 66 1.1 cherry 67 1.1 cherry typedef struct uvm_physseg * uvm_physseg_t; 68 1.1 cherry 69 1.1 cherry #else /* UVM_HOTPLUG */ 70 1.1 cherry 71 1.1 cherry #define PRIxPHYSSEG "d" 72 1.1 cherry 73 1.1 cherry /* 74 1.1 cherry * These are specific values of invalid constants for uvm_physseg_t. 75 1.2 cherry * uvm_physseg_valid_p() == false on any of the below constants. 76 1.1 cherry * 77 1.1 cherry * Specific invalid constants encapsulate specific explicit failure 78 1.1 cherry * scenarios (see the comments next to them) 79 1.1 cherry */ 80 1.1 cherry 81 1.1 cherry #define UVM_PHYSSEG_TYPE_INVALID -1 /* Generic invalid value */ 82 1.1 cherry #define UVM_PHYSSEG_TYPE_INVALID_EMPTY -1 /* empty segment access */ 83 1.1 cherry #define UVM_PHYSSEG_TYPE_INVALID_OVERFLOW (uvm_physseg_get_last() + 1) /* ran off the end of the last segment */ 84 1.1 cherry 85 1.1 cherry typedef int uvm_physseg_t; 86 1.1 cherry #endif /* UVM_HOTPLUG */ 87 1.1 cherry 88 1.1 cherry void uvm_physseg_init(void); 89 1.1 cherry 90 1.2 cherry bool uvm_physseg_valid_p(uvm_physseg_t); 91 1.1 cherry 92 1.1 cherry /* 93 1.1 cherry * Return start/end pfn of given segment 94 1.1 cherry * Returns: -1 if the segment number is invalid 95 1.1 cherry */ 96 1.1 cherry paddr_t uvm_physseg_get_start(uvm_physseg_t); 97 1.1 cherry paddr_t uvm_physseg_get_end(uvm_physseg_t); 98 1.1 cherry 99 1.1 cherry paddr_t uvm_physseg_get_avail_start(uvm_physseg_t); 100 1.1 cherry paddr_t uvm_physseg_get_avail_end(uvm_physseg_t); 101 1.1 cherry 102 1.1 cherry struct vm_page * uvm_physseg_get_pg(uvm_physseg_t, paddr_t); 103 1.1 cherry 104 1.1 cherry #ifdef __HAVE_PMAP_PHYSSEG 105 1.1 cherry struct pmap_physseg * uvm_physseg_get_pmseg(uvm_physseg_t); 106 1.1 cherry #endif 107 1.1 cherry 108 1.1 cherry int uvm_physseg_get_free_list(uvm_physseg_t); 109 1.9 tnn u_long uvm_physseg_get_start_hint(uvm_physseg_t); 110 1.9 tnn bool uvm_physseg_set_start_hint(uvm_physseg_t, u_long); 111 1.1 cherry 112 1.1 cherry /* 113 1.1 cherry * Functions to help walk the list of segments. 114 1.1 cherry * Returns: NULL if the segment number is invalid 115 1.1 cherry */ 116 1.1 cherry uvm_physseg_t uvm_physseg_get_next(uvm_physseg_t); 117 1.1 cherry uvm_physseg_t uvm_physseg_get_prev(uvm_physseg_t); 118 1.1 cherry uvm_physseg_t uvm_physseg_get_first(void); 119 1.1 cherry uvm_physseg_t uvm_physseg_get_last(void); 120 1.1 cherry 121 1.1 cherry 122 1.1 cherry /* Return the frame number of the highest registered physical page frame */ 123 1.1 cherry paddr_t uvm_physseg_get_highest_frame(void); 124 1.1 cherry 125 1.1 cherry /* Actually, uvm_page_physload takes PF#s which need their own type */ 126 1.1 cherry uvm_physseg_t uvm_page_physload(paddr_t, paddr_t, paddr_t, 127 1.1 cherry paddr_t, int); 128 1.1 cherry 129 1.1 cherry bool uvm_page_physunload(uvm_physseg_t, int, paddr_t *); 130 1.1 cherry bool uvm_page_physunload_force(uvm_physseg_t, int, paddr_t *); 131 1.1 cherry 132 1.1 cherry uvm_physseg_t uvm_physseg_find(paddr_t, psize_t *); 133 1.1 cherry 134 1.1 cherry bool uvm_physseg_plug(paddr_t, size_t, uvm_physseg_t *); 135 1.1 cherry bool uvm_physseg_unplug(paddr_t, size_t); 136 1.1 cherry 137 1.7 rin #if defined(UVM_PHYSSEG_LEGACY) 138 1.1 cherry /* 139 1.1 cherry * XXX: Legacy: This needs to be upgraded to a full pa management 140 1.1 cherry * layer. 141 1.1 cherry */ 142 1.1 cherry void uvm_physseg_set_avail_start(uvm_physseg_t, paddr_t); 143 1.1 cherry void uvm_physseg_set_avail_end(uvm_physseg_t, paddr_t); 144 1.7 rin #endif /* UVM_PHYSSEG_LEGACY */ 145 1.1 cherry 146 1.1 cherry #endif /* _UVM_UVM_PHYSSEG_H_ */ 147