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