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