1 | /*
|
---|
2 | * CDDL HEADER START
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the terms of the
|
---|
5 | * Common Development and Distribution License (the "License").
|
---|
6 | * You may not use this file except in compliance with the License.
|
---|
7 | *
|
---|
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
---|
9 | * or http://www.opensolaris.org/os/licensing.
|
---|
10 | * See the License for the specific language governing permissions
|
---|
11 | * and limitations under the License.
|
---|
12 | *
|
---|
13 | * When distributing Covered Code, include this CDDL HEADER in each
|
---|
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
---|
15 | * If applicable, add the following below this CDDL HEADER, with the
|
---|
16 | * fields enclosed by brackets "[]" replaced with your own identifying
|
---|
17 | * information: Portions Copyright [yyyy] [name of copyright owner]
|
---|
18 | *
|
---|
19 | * CDDL HEADER END
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*
|
---|
23 | * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
---|
24 | * Use is subject to license terms.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef _SYS_VBI_H
|
---|
28 | #define _SYS_VBI_H
|
---|
29 |
|
---|
30 | #ifdef __cplusplus
|
---|
31 | extern "C" {
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * Private interfaces for VirtualBox access to Solaris kernel internal
|
---|
36 | * facilities. The interface uses limited types when crossing the kernel
|
---|
37 | * to hypervisor boundary. (void *) is for handles and function and other
|
---|
38 | * pointers. uint64 for physical addresses, size_t and int elsewhere.
|
---|
39 | * The goal is for this module to eventually be part of OpenSolaris once
|
---|
40 | * interfaces have become more stable.
|
---|
41 | */
|
---|
42 |
|
---|
43 | /*
|
---|
44 | * Allocate and free physically contiguous, page aligned memory.
|
---|
45 | *
|
---|
46 | *
|
---|
47 | * return value is a) NULL if contig memory not available or
|
---|
48 | * b) virtual address of memory in kernel heap
|
---|
49 | *
|
---|
50 | * *phys on input is set to the upper boundary of acceptable memory
|
---|
51 | * *phys on output returns the starting physical address
|
---|
52 | *
|
---|
53 | * size is the amount to allocate and must be a multiple of PAGESIZE
|
---|
54 | */
|
---|
55 | extern void *vbi_contig_alloc(uint64_t *phys, size_t size);
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * va is from vbi_contig_alloc() return value
|
---|
59 | * size must match from vbi_contig_alloc()
|
---|
60 | */
|
---|
61 | extern void vbi_contig_free(void *va, size_t size);
|
---|
62 |
|
---|
63 |
|
---|
64 | /*
|
---|
65 | * Map physical page into kernel heap space
|
---|
66 | *
|
---|
67 | * return value is a) NULL if out of kernel virtual address space or
|
---|
68 | * on success b) virtual address of memory in kernel heap
|
---|
69 | *
|
---|
70 | * pa is the starting physical address, must be PAGESIZE aligned
|
---|
71 | *
|
---|
72 | * size is the amount to map and must be a multiple of PAGESIZE
|
---|
73 | */
|
---|
74 | extern void *vbi_kernel_map(uint64_t pa, size_t size, uint_t prot);
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * Map physical pages into user part of the address space.
|
---|
78 | *
|
---|
79 | * returns 0 on success, non-zero on failure
|
---|
80 | */
|
---|
81 | extern int vbi_user_map(caddr_t *va, uint_t prot, uint64_t *palist, size_t len);
|
---|
82 |
|
---|
83 | /*
|
---|
84 | * Unmap physical memory from virtual address space. No freeing of physical
|
---|
85 | * memory is done.
|
---|
86 | *
|
---|
87 | * va is from a call to vbi_kernel_map() or vbi_user_map() that used sz
|
---|
88 | */
|
---|
89 | extern void vbi_unmap(void *va, size_t size);
|
---|
90 |
|
---|
91 |
|
---|
92 | /*
|
---|
93 | * return value is an OS handle for the current thread.
|
---|
94 | */
|
---|
95 | extern void *vbi_curthread(void);
|
---|
96 |
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * Yield thread.
|
---|
100 | * return value is an inexact value for:
|
---|
101 | * 0 - the thread probably didn't yield
|
---|
102 | * 1 - the thread probably did yield
|
---|
103 | */
|
---|
104 | extern int vbi_yield(void);
|
---|
105 |
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * Timer functions, times expressed in nanoseconds.
|
---|
109 | */
|
---|
110 | extern uint64_t vbi_timer_granularity(void);
|
---|
111 |
|
---|
112 | /* old timer funcs */
|
---|
113 | extern void *vbi_timer_create(void *callback, void *arg1, void *arg2,
|
---|
114 | uint64_t interval);
|
---|
115 | extern void vbi_timer_destroy(void *timer);
|
---|
116 | extern void vbi_timer_start(void *timer, uint64_t when);
|
---|
117 | extern void vbi_timer_stop(void *timer);
|
---|
118 |
|
---|
119 | /*
|
---|
120 | * Returns current time of day in nanoseconds.
|
---|
121 | */
|
---|
122 | extern uint64_t vbi_tod(void);
|
---|
123 |
|
---|
124 | /*
|
---|
125 | * Process handle
|
---|
126 | */
|
---|
127 | extern void *vbi_proc(void);
|
---|
128 |
|
---|
129 | /*
|
---|
130 | * thread functions
|
---|
131 | */
|
---|
132 | extern void vbi_set_priority(void *thread, int priority);
|
---|
133 | extern void *vbi_thread_create(void *func, void *arg, size_t len, int priority);
|
---|
134 | extern void vbi_thread_exit(void);
|
---|
135 |
|
---|
136 | /*
|
---|
137 | * Allocate and free kernel heap suitable for use as executable text
|
---|
138 | *
|
---|
139 | * return value is a) NULL if memory not available or
|
---|
140 | * b) virtual address of memory in kernel heap
|
---|
141 | *
|
---|
142 | * size is the amount to allocate
|
---|
143 | *
|
---|
144 | * Note that the virtual mappings to memory allocated by this interface are
|
---|
145 | * locked.
|
---|
146 | */
|
---|
147 | extern void *vbi_text_alloc(size_t size);
|
---|
148 |
|
---|
149 | /*
|
---|
150 | * va is from vbi_text_alloc() return value
|
---|
151 | * size must match from vbi_text_alloc()
|
---|
152 | */
|
---|
153 | extern void vbi_text_free(void *va, size_t size);
|
---|
154 |
|
---|
155 | /*
|
---|
156 | * CPU and cross call related functionality
|
---|
157 | *
|
---|
158 | * return current cpu identifier
|
---|
159 | */
|
---|
160 | extern int vbi_cpu_id(void);
|
---|
161 |
|
---|
162 | /*
|
---|
163 | * return maximum possible cpu identifier
|
---|
164 | */
|
---|
165 | extern int vbi_max_cpu_id(void);
|
---|
166 |
|
---|
167 | /*
|
---|
168 | * return max number of CPUs supported by OS
|
---|
169 | */
|
---|
170 | extern int vbi_cpu_maxcount(void);
|
---|
171 |
|
---|
172 | /*
|
---|
173 | * return number of CPUs actually in system
|
---|
174 | */
|
---|
175 | extern int vbi_cpu_count(void);
|
---|
176 |
|
---|
177 | /*
|
---|
178 | * returns 0 if cpu is offline, 1 if online
|
---|
179 | */
|
---|
180 | extern int vbi_cpu_online(int c);
|
---|
181 |
|
---|
182 | /*
|
---|
183 | * disable/enable thread preemption
|
---|
184 | */
|
---|
185 | extern void vbi_preempt_disable(void);
|
---|
186 | extern void vbi_preempt_enable(void);
|
---|
187 |
|
---|
188 | /*
|
---|
189 | * causes "func(arg)" to be invoked on all online CPUs.
|
---|
190 | */
|
---|
191 | extern void vbi_execute_on_all(void *func, void *arg);
|
---|
192 |
|
---|
193 | /*
|
---|
194 | * causes "func(arg)" to be invoked on all CPUs except the current one.
|
---|
195 | * should be called with preemption disabled.
|
---|
196 | */
|
---|
197 | extern void vbi_execute_on_others(void *func, void *arg);
|
---|
198 |
|
---|
199 | /*
|
---|
200 | * causes "func(arg)" to be invoked on just one CPU
|
---|
201 | */
|
---|
202 | extern void vbi_execute_on_one(void *func, void *arg, int c);
|
---|
203 |
|
---|
204 |
|
---|
205 | /*
|
---|
206 | * Lock/unlock pages in virtual address space. Pages behind the virtual
|
---|
207 | * mappings are pinned and virtual mappings are locked. Handles to the
|
---|
208 | * pages are returned in the array.
|
---|
209 | *
|
---|
210 | * returns 0 for success, non-zero errno on failure
|
---|
211 | */
|
---|
212 | extern int vbi_lock_va(void *addr, size_t len, void **handle);
|
---|
213 | extern void vbi_unlock_va(void *addr, size_t len, void *handle);
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * Return the physical address of memory behind a VA. If the
|
---|
217 | * memory is not locked, it may return -(uint64_t)1 to indicate that
|
---|
218 | * no physical page is at the address currently.
|
---|
219 | */
|
---|
220 | extern uint64_t vbi_va_to_pa(void *addr);
|
---|
221 |
|
---|
222 | /* end of interfaces defined for version 1 */
|
---|
223 |
|
---|
224 | extern uint_t vbi_revision_level;
|
---|
225 |
|
---|
226 | /* begin interfaces defined for version 2 */
|
---|
227 |
|
---|
228 | /*
|
---|
229 | * Install/remove a call back for CPU online/offline event notification.
|
---|
230 | *
|
---|
231 | * The call back func is invoked with 3 arguments:
|
---|
232 | * void func(void *arg, int cpu, int online);
|
---|
233 | * - arg is passed through from vbi_watch_cpus()
|
---|
234 | * - cpu is the CPU id involved
|
---|
235 | * - online is non-zero for a CPU that comes online and 0 for a CPU that is
|
---|
236 | * going offline.
|
---|
237 | *
|
---|
238 | * If current_too is non-zero, then a cpu online event will be invoked for all
|
---|
239 | * currently online CPUs.
|
---|
240 | *
|
---|
241 | * Note there is no guarantee about which CPU the function is invoked on.
|
---|
242 | */
|
---|
243 | typedef struct vbi_cpu_watch vbi_cpu_watch_t;
|
---|
244 | extern vbi_cpu_watch_t *vbi_watch_cpus(void (*func)(), void *arg,
|
---|
245 | int current_too);
|
---|
246 | extern void vbi_ignore_cpus(vbi_cpu_watch_t *);
|
---|
247 | #pragma weak vbi_watch_cpus
|
---|
248 | #pragma weak vbi_ignore_cpus
|
---|
249 |
|
---|
250 | /*
|
---|
251 | * New timer interfaces
|
---|
252 | *
|
---|
253 | * A simple timer fires just once and on only one cpu. It may be repeating or
|
---|
254 | * a one shot.
|
---|
255 | *
|
---|
256 | * Support for one shot (ie interval == 0) global timers is optional.
|
---|
257 | *
|
---|
258 | * For simple timers, if cpu is VBI_ANY_CPU, the timer may fire on any
|
---|
259 | * available cpu otherwise the timer will fire only on the given cpu
|
---|
260 | *
|
---|
261 | * The repeating call back, func, is invoked with 2 arguments:
|
---|
262 | * - arg is just passed through
|
---|
263 | * - a uint64_t counter that starts at 0 and increments with each timer event.
|
---|
264 | * The count is per-cpu and resets whenever a cpu goes offline and comes back
|
---|
265 | * online.
|
---|
266 | *
|
---|
267 | * The when parameter is time relative to now.
|
---|
268 | *
|
---|
269 | * vbi_stimer_begin() may return NULL if there was an error in
|
---|
270 | * creating the timer, for example if a requested cpu is not online.
|
---|
271 | *
|
---|
272 | * vbi_gtimer_begin() may return NULL when called if it does not
|
---|
273 | * support the requested kind of timer (ie interval == 0)
|
---|
274 | */
|
---|
275 | #define VBI_ANY_CPU (-1)
|
---|
276 |
|
---|
277 | typedef struct vbi_stimer vbi_stimer_t;
|
---|
278 | extern vbi_stimer_t *vbi_stimer_begin(void (*func)(void *, uint64_t), void *arg,
|
---|
279 | uint64_t when, uint64_t interval, int cpu);
|
---|
280 | extern void vbi_stimer_end(vbi_stimer_t *);
|
---|
281 | #pragma weak vbi_stimer_begin
|
---|
282 | #pragma weak vbi_stimer_end
|
---|
283 |
|
---|
284 | typedef struct vbi_gtimer vbi_gtimer_t;
|
---|
285 | extern vbi_gtimer_t *vbi_gtimer_begin(void (*func)(void *, uint64_t), void *arg,
|
---|
286 | uint64_t when, uint64_t interval);
|
---|
287 | extern void vbi_gtimer_end(vbi_gtimer_t *);
|
---|
288 | #pragma weak vbi_gtimer_begin
|
---|
289 | #pragma weak vbi_gtimer_end
|
---|
290 |
|
---|
291 |
|
---|
292 | /* end of interfaces defined for version 2 */
|
---|
293 |
|
---|
294 | /* begin interfaces defined for version 3 */
|
---|
295 |
|
---|
296 | /*
|
---|
297 | * returns non-zero if the thread might be preempted at any time
|
---|
298 | */
|
---|
299 | extern int vbi_is_preempt_enabled(void);
|
---|
300 |
|
---|
301 | /* end of interfaces defined for version 3 */
|
---|
302 |
|
---|
303 | /* begin interfaces defined for version 4 */
|
---|
304 |
|
---|
305 | /*
|
---|
306 | * poke the given cpu with an IPI
|
---|
307 | */
|
---|
308 | extern void vbi_poke_cpu(int);
|
---|
309 |
|
---|
310 | /* end of interfaces defined for version 4 */
|
---|
311 |
|
---|
312 | #ifdef __cplusplus
|
---|
313 | }
|
---|
314 | #endif
|
---|
315 |
|
---|
316 | #endif /* _SYS_VBI_H */
|
---|