uvm_physseg.h revision 1.6 1 /* $NetBSD: uvm_physseg.h,v 1.6 2016/12/26 18:47:00 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 (at) 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 (at) 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 #ifdef _KERNEL
49 /*
50 * No APIs are explicitly #included in uvm_physseg.c
51 */
52
53 #if defined(UVM_HOTPLUG) /* rbtree impementation */
54 #define PRIxPHYSSEG "p"
55
56 /*
57 * These are specific values of invalid constants for uvm_physseg_t.
58 * uvm_physseg_valid_p() == false on any of the below constants.
59 *
60 * Specific invalid constants encapsulate specific explicit failure
61 * scenarios (see the comments next to them)
62 */
63
64 #define UVM_PHYSSEG_TYPE_INVALID NULL /* Generic invalid value */
65 #define UVM_PHYSSEG_TYPE_INVALID_EMPTY NULL /* empty segment access */
66 #define UVM_PHYSSEG_TYPE_INVALID_OVERFLOW NULL /* ran off the end of the last segment */
67
68 typedef struct uvm_physseg * uvm_physseg_t;
69
70 #else /* UVM_HOTPLUG */
71
72 #define PRIxPHYSSEG "d"
73
74 /*
75 * These are specific values of invalid constants for uvm_physseg_t.
76 * uvm_physseg_valid_p() == false on any of the below constants.
77 *
78 * Specific invalid constants encapsulate specific explicit failure
79 * scenarios (see the comments next to them)
80 */
81
82 #define UVM_PHYSSEG_TYPE_INVALID -1 /* Generic invalid value */
83 #define UVM_PHYSSEG_TYPE_INVALID_EMPTY -1 /* empty segment access */
84 #define UVM_PHYSSEG_TYPE_INVALID_OVERFLOW (uvm_physseg_get_last() + 1) /* ran off the end of the last segment */
85
86 typedef int uvm_physseg_t;
87 #endif /* UVM_HOTPLUG */
88
89 void uvm_physseg_init(void);
90
91 bool uvm_physseg_valid_p(uvm_physseg_t);
92
93 /*
94 * Return start/end pfn of given segment
95 * Returns: -1 if the segment number is invalid
96 */
97 paddr_t uvm_physseg_get_start(uvm_physseg_t);
98 paddr_t uvm_physseg_get_end(uvm_physseg_t);
99
100 paddr_t uvm_physseg_get_avail_start(uvm_physseg_t);
101 paddr_t uvm_physseg_get_avail_end(uvm_physseg_t);
102
103 struct vm_page * uvm_physseg_get_pg(uvm_physseg_t, paddr_t);
104
105 #ifdef __HAVE_PMAP_PHYSSEG
106 struct pmap_physseg * uvm_physseg_get_pmseg(uvm_physseg_t);
107 #endif
108
109 int uvm_physseg_get_free_list(uvm_physseg_t);
110 u_int uvm_physseg_get_start_hint(uvm_physseg_t);
111 bool uvm_physseg_set_start_hint(uvm_physseg_t, u_int);
112
113 /*
114 * Functions to help walk the list of segments.
115 * Returns: NULL if the segment number is invalid
116 */
117 uvm_physseg_t uvm_physseg_get_next(uvm_physseg_t);
118 uvm_physseg_t uvm_physseg_get_prev(uvm_physseg_t);
119 uvm_physseg_t uvm_physseg_get_first(void);
120 uvm_physseg_t uvm_physseg_get_last(void);
121
122
123 /* Return the frame number of the highest registered physical page frame */
124 paddr_t uvm_physseg_get_highest_frame(void);
125
126 /* Actually, uvm_page_physload takes PF#s which need their own type */
127 uvm_physseg_t uvm_page_physload(paddr_t, paddr_t, paddr_t,
128 paddr_t, int);
129
130 bool uvm_page_physunload(uvm_physseg_t, int, paddr_t *);
131 bool uvm_page_physunload_force(uvm_physseg_t, int, paddr_t *);
132
133 uvm_physseg_t uvm_physseg_find(paddr_t, psize_t *);
134
135 bool uvm_physseg_plug(paddr_t, size_t, uvm_physseg_t *);
136 bool uvm_physseg_unplug(paddr_t, size_t);
137
138 #if defined(PMAP_STEAL_MEMORY)
139 /*
140 * XXX: Legacy: This needs to be upgraded to a full pa management
141 * layer.
142 */
143 void uvm_physseg_set_avail_start(uvm_physseg_t, paddr_t);
144 void uvm_physseg_set_avail_end(uvm_physseg_t, paddr_t);
145 #endif /* PMAP_STEAL_MEMORY */
146
147 #endif /* _KERNEL */
148
149 #endif /* _UVM_UVM_PHYSSEG_H_ */
150