kern.h revision 1.3 1 1.3 pooka /* $NetBSD: kern.h,v 1.3 2016/02/08 18:18:19 pooka Exp $ */
2 1.1 pooka
3 1.1 pooka /*
4 1.1 pooka * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
5 1.1 pooka *
6 1.1 pooka * Redistribution and use in source and binary forms, with or without
7 1.1 pooka * modification, are permitted provided that the following conditions
8 1.1 pooka * are met:
9 1.1 pooka * 1. Redistributions of source code must retain the above copyright
10 1.1 pooka * notice, this list of conditions and the following disclaimer.
11 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 pooka * notice, this list of conditions and the following disclaimer in the
13 1.1 pooka * documentation and/or other materials provided with the distribution.
14 1.1 pooka *
15 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 1.1 pooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1 pooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1 pooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 pooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 pooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1 pooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 pooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 pooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 pooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 pooka * SUCH DAMAGE.
26 1.1 pooka */
27 1.1 pooka
28 1.1 pooka #ifndef _SYS_RUMP_PRIVATE_H_
29 1.1 pooka #define _SYS_RUMP_PRIVATE_H_
30 1.1 pooka
31 1.1 pooka #include <sys/param.h>
32 1.1 pooka #include <sys/cpu.h>
33 1.1 pooka #include <sys/device.h>
34 1.1 pooka #include <sys/lwp.h>
35 1.1 pooka #include <sys/proc.h>
36 1.1 pooka #include <sys/systm.h>
37 1.1 pooka #include <sys/types.h>
38 1.1 pooka
39 1.1 pooka #include <uvm/uvm.h>
40 1.1 pooka #include <uvm/uvm_object.h>
41 1.1 pooka #include <uvm/uvm_page.h>
42 1.1 pooka
43 1.1 pooka #include <rump/rump.h>
44 1.1 pooka #include <rump/rumpuser.h>
45 1.1 pooka
46 1.1 pooka #include <rump-sys/kern_if.h>
47 1.1 pooka
48 1.1 pooka extern struct rumpuser_mtx *rump_giantlock;
49 1.1 pooka
50 1.1 pooka extern int rump_threads;
51 1.1 pooka extern struct device rump_rootdev;
52 1.1 pooka
53 1.1 pooka extern struct sysent rump_sysent[];
54 1.1 pooka
55 1.1 pooka enum rump_component_type {
56 1.1 pooka RUMP_COMPONENT_DEV,
57 1.1 pooka RUMP_COMPONENT_DEV_AFTERMAINBUS,
58 1.1 pooka RUMP_COMPONENT_NET,
59 1.1 pooka RUMP_COMPONENT_NET_ROUTE,
60 1.1 pooka RUMP_COMPONENT_NET_IF,
61 1.1 pooka RUMP_COMPONENT_NET_IFCFG,
62 1.1 pooka RUMP_COMPONENT_VFS,
63 1.1 pooka RUMP_COMPONENT_KERN,
64 1.1 pooka RUMP_COMPONENT_KERN_VFS,
65 1.1 pooka RUMP_COMPONENT_POSTINIT,
66 1.1 pooka RUMP_COMPONENT_SYSCALL,
67 1.1 pooka
68 1.1 pooka RUMP__FACTION_DEV,
69 1.1 pooka RUMP__FACTION_VFS,
70 1.1 pooka RUMP__FACTION_NET,
71 1.1 pooka
72 1.1 pooka RUMP_COMPONENT_MAX,
73 1.1 pooka };
74 1.1 pooka struct rump_component {
75 1.1 pooka enum rump_component_type rc_type;
76 1.1 pooka void (*rc_init)(void);
77 1.1 pooka LIST_ENTRY(rump_component) rc_entries;
78 1.1 pooka };
79 1.1 pooka
80 1.1 pooka /*
81 1.1 pooka * If RUMP_USE_CTOR is defined, we use __attribute__((constructor)) to
82 1.1 pooka * determine which components are present when rump_init() is called.
83 1.1 pooka * Otherwise, we use link sets and the __start/__stop symbols generated
84 1.1 pooka * by the toolchain.
85 1.1 pooka */
86 1.1 pooka
87 1.1 pooka #ifdef RUMP_USE_CTOR
88 1.1 pooka #define _RUMP_COMPONENT_REGISTER(type) \
89 1.1 pooka static void rumpcomp_ctor##type(void) __attribute__((constructor)); \
90 1.1 pooka static void rumpcomp_ctor##type(void) \
91 1.1 pooka { \
92 1.1 pooka rump_component_load(&rumpcomp##type); \
93 1.1 pooka } \
94 1.1 pooka static void rumpcomp_dtor##type(void) __attribute__((destructor)); \
95 1.1 pooka static void rumpcomp_dtor##type(void) \
96 1.1 pooka { \
97 1.1 pooka rump_component_unload(&rumpcomp##type); \
98 1.1 pooka }
99 1.1 pooka
100 1.1 pooka #else /* RUMP_USE_CTOR */
101 1.1 pooka
102 1.1 pooka #define _RUMP_COMPONENT_REGISTER(type) \
103 1.1 pooka __link_set_add_rodata(rump_components, rumpcomp##type);
104 1.1 pooka #endif /* RUMP_USE_CTOR */
105 1.1 pooka
106 1.1 pooka #define RUMP_COMPONENT(type) \
107 1.1 pooka static void rumpcompinit##type(void); \
108 1.1 pooka static struct rump_component rumpcomp##type = { \
109 1.1 pooka .rc_type = type, \
110 1.1 pooka .rc_init = rumpcompinit##type, \
111 1.1 pooka }; \
112 1.1 pooka _RUMP_COMPONENT_REGISTER(type) \
113 1.1 pooka static void rumpcompinit##type(void)
114 1.1 pooka
115 1.1 pooka #define FLAWLESSCALL(call) \
116 1.1 pooka do { \
117 1.1 pooka int att_error; \
118 1.1 pooka if ((att_error = call) != 0) \
119 1.1 pooka panic("\"%s\" failed", #call); \
120 1.1 pooka } while (/*CONSTCOND*/0)
121 1.1 pooka
122 1.1 pooka #define RUMPMEM_UNLIMITED ((unsigned long)-1)
123 1.1 pooka extern unsigned long rump_physmemlimit;
124 1.1 pooka
125 1.1 pooka extern struct vmspace *rump_vmspace_local;
126 1.1 pooka extern struct pmap rump_pmap_local;
127 1.1 pooka #define RUMP_LOCALPROC_P(p) \
128 1.1 pooka (p->p_vmspace == vmspace_kernel() || p->p_vmspace == rump_vmspace_local)
129 1.1 pooka
130 1.1 pooka /* vm bundle for remote clients. the last member is the hypercall cookie */
131 1.1 pooka struct rump_spctl {
132 1.1 pooka struct vmspace spctl_vm;
133 1.1 pooka void *spctl;
134 1.1 pooka };
135 1.1 pooka #define RUMP_SPVM2CTL(vm) (((struct rump_spctl *)vm)->spctl)
136 1.1 pooka
137 1.1 pooka void rump_component_load(const struct rump_component *);
138 1.1 pooka void rump_component_unload(struct rump_component *);
139 1.1 pooka void rump_component_init(enum rump_component_type);
140 1.1 pooka int rump_component_count(enum rump_component_type);
141 1.1 pooka
142 1.1 pooka typedef void (*rump_proc_vfs_init_fn)(struct proc *);
143 1.1 pooka typedef void (*rump_proc_vfs_release_fn)(struct proc *);
144 1.1 pooka extern rump_proc_vfs_init_fn rump_proc_vfs_init;
145 1.1 pooka extern rump_proc_vfs_release_fn rump_proc_vfs_release;
146 1.1 pooka
147 1.3 pooka extern struct cpu_info rump_bootcpu;
148 1.1 pooka
149 1.1 pooka extern bool rump_ttycomponent;
150 1.1 pooka
151 1.1 pooka struct lwp * rump__lwproc_alloclwp(struct proc *);
152 1.1 pooka void rump__lwproc_lwphold(void);
153 1.1 pooka void rump__lwproc_lwprele(void);
154 1.1 pooka
155 1.1 pooka void rump_cpus_bootstrap(int *);
156 1.1 pooka void rump_biglock_init(void);
157 1.1 pooka void rump_scheduler_init(int);
158 1.1 pooka void rump_schedule(void);
159 1.1 pooka void rump_unschedule(void);
160 1.1 pooka void rump_schedule_cpu(struct lwp *);
161 1.1 pooka void rump_schedule_cpu_interlock(struct lwp *, void *);
162 1.1 pooka void rump_unschedule_cpu(struct lwp *);
163 1.1 pooka void rump_unschedule_cpu_interlock(struct lwp *, void *);
164 1.1 pooka void rump_unschedule_cpu1(struct lwp *, void *);
165 1.1 pooka int rump_syscall(int, void *, size_t, register_t *);
166 1.1 pooka
167 1.1 pooka struct rump_onesyscall {
168 1.1 pooka int ros_num;
169 1.1 pooka sy_call_t *ros_handler;
170 1.1 pooka };
171 1.1 pooka void rump_syscall_boot_establish(const struct rump_onesyscall *, size_t);
172 1.1 pooka
173 1.1 pooka void rump_schedlock_cv_wait(struct rumpuser_cv *);
174 1.1 pooka int rump_schedlock_cv_timedwait(struct rumpuser_cv *,
175 1.1 pooka const struct timespec *);
176 1.1 pooka
177 1.1 pooka void rump_user_schedule(int, void *);
178 1.1 pooka void rump_user_unschedule(int, int *, void *);
179 1.1 pooka
180 1.1 pooka void rump_cpu_attach(struct cpu_info *);
181 1.1 pooka
182 1.1 pooka struct clockframe *rump_cpu_makeclockframe(void);
183 1.1 pooka
184 1.1 pooka void rump_kernel_bigwrap(int *);
185 1.1 pooka void rump_kernel_bigunwrap(int);
186 1.1 pooka
187 1.1 pooka void rump_tsleep_init(void);
188 1.1 pooka
189 1.1 pooka void rump_intr_init(int);
190 1.1 pooka void rump_softint_run(struct cpu_info *);
191 1.1 pooka
192 1.1 pooka void *rump_hypermalloc(size_t, int, bool, const char *);
193 1.1 pooka void rump_hyperfree(void *, size_t);
194 1.1 pooka
195 1.1 pooka void rump_xc_highpri(struct cpu_info *);
196 1.1 pooka
197 1.1 pooka void rump_thread_init(void);
198 1.1 pooka void rump_thread_allow(struct lwp *);
199 1.1 pooka
200 1.1 pooka void rump_consdev_init(void);
201 1.1 pooka
202 1.1 pooka void rump_hyperentropy_init(void);
203 1.1 pooka
204 1.1 pooka void rump_lwproc_init(void);
205 1.1 pooka void rump_lwproc_curlwp_set(struct lwp *);
206 1.1 pooka void rump_lwproc_curlwp_clear(struct lwp *);
207 1.1 pooka int rump_lwproc_rfork_vmspace(struct vmspace *, int);
208 1.1 pooka
209 1.1 pooka /*
210 1.1 pooka * sysproxy is an optional component. The interfaces with "hyp"
211 1.1 pooka * in the name come into the rump kernel from the client or sysproxy
212 1.1 pooka * stub, the rest go out of the rump kernel.
213 1.1 pooka */
214 1.1 pooka struct rump_sysproxy_ops {
215 1.1 pooka int (*rspo_copyin)(void *, const void *, void *, size_t);
216 1.1 pooka int (*rspo_copyinstr)(void *, const void *, void *, size_t *);
217 1.1 pooka int (*rspo_copyout)(void *, const void *, void *, size_t);
218 1.1 pooka int (*rspo_copyoutstr)(void *, const void *, void *, size_t *);
219 1.1 pooka int (*rspo_anonmmap)(void *, size_t, void **);
220 1.1 pooka int (*rspo_raise)(void *, int);
221 1.1 pooka void (*rspo_fini)(void *);
222 1.1 pooka
223 1.1 pooka pid_t (*rspo_hyp_getpid)(void);
224 1.1 pooka int (*rspo_hyp_syscall)(int, void *, long *);
225 1.1 pooka int (*rspo_hyp_rfork)(void *, int, const char *);
226 1.1 pooka void (*rspo_hyp_lwpexit)(void);
227 1.1 pooka void (*rspo_hyp_execnotify)(const char *);
228 1.1 pooka };
229 1.1 pooka extern struct rump_sysproxy_ops rump_sysproxy_ops;
230 1.1 pooka #define rump_sysproxy_copyin(arg, raddr, laddr, len) \
231 1.2 pooka rump_sysproxy_ops.rspo_copyin(arg, raddr, laddr, len)
232 1.1 pooka #define rump_sysproxy_copyinstr(arg, raddr, laddr, lenp) \
233 1.2 pooka rump_sysproxy_ops.rspo_copyinstr(arg, raddr, laddr, lenp)
234 1.1 pooka #define rump_sysproxy_copyout(arg, laddr, raddr, len) \
235 1.2 pooka rump_sysproxy_ops.rspo_copyout(arg, laddr, raddr, len)
236 1.1 pooka #define rump_sysproxy_copyoutstr(arg, laddr, raddr, lenp) \
237 1.2 pooka rump_sysproxy_ops.rspo_copyoutstr(arg, laddr, raddr, lenp)
238 1.1 pooka #define rump_sysproxy_anonmmap(arg, howmuch, addr) \
239 1.1 pooka rump_sysproxy_ops.rspo_anonmmap(arg, howmuch, addr)
240 1.1 pooka #define rump_sysproxy_raise(arg, signo) \
241 1.1 pooka rump_sysproxy_ops.rspo_raise(arg, signo)
242 1.1 pooka #define rump_sysproxy_fini(arg) \
243 1.1 pooka rump_sysproxy_ops.rspo_fini(arg)
244 1.1 pooka #define rump_sysproxy_hyp_getpid() \
245 1.1 pooka rump_sysproxy_ops.rspo_hyp_getpid()
246 1.1 pooka #define rump_sysproxy_hyp_syscall(num, arg, retval) \
247 1.1 pooka rump_sysproxy_ops.rspo_hyp_syscall(num, arg, retval)
248 1.1 pooka #define rump_sysproxy_hyp_rfork(priv, flag, comm) \
249 1.1 pooka rump_sysproxy_ops.rspo_hyp_rfork(priv, flag, comm)
250 1.1 pooka #define rump_sysproxy_hyp_lwpexit() \
251 1.1 pooka rump_sysproxy_ops.rspo_hyp_lwpexit()
252 1.1 pooka #define rump_sysproxy_hyp_execnotify(comm) \
253 1.1 pooka rump_sysproxy_ops.rspo_hyp_execnotify(comm)
254 1.1 pooka
255 1.1 pooka #endif /* _SYS_RUMP_PRIVATE_H_ */
256