1*05aecacfSpooka /*	$NetBSD: rumpuser_component.c,v 1.6 2013/05/07 15:18:35 pooka Exp $	*/
2d27812a7Spooka 
3d27812a7Spooka /*
4d27812a7Spooka  * Copyright (c) 2013 Antti Kantee.  All Rights Reserved.
5d27812a7Spooka  *
6d27812a7Spooka  * Redistribution and use in source and binary forms, with or without
7d27812a7Spooka  * modification, are permitted provided that the following conditions
8d27812a7Spooka  * are met:
9d27812a7Spooka  * 1. Redistributions of source code must retain the above copyright
10d27812a7Spooka  *    notice, this list of conditions and the following disclaimer.
11d27812a7Spooka  * 2. Redistributions in binary form must reproduce the above copyright
12d27812a7Spooka  *    notice, this list of conditions and the following disclaimer in the
13d27812a7Spooka  *    documentation and/or other materials provided with the distribution.
14d27812a7Spooka  *
15d27812a7Spooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16d27812a7Spooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17d27812a7Spooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18d27812a7Spooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19d27812a7Spooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20d27812a7Spooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21d27812a7Spooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22d27812a7Spooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23d27812a7Spooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24d27812a7Spooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25d27812a7Spooka  * SUCH DAMAGE.
26d27812a7Spooka  */
27d27812a7Spooka 
28d27812a7Spooka #include "rumpuser_port.h"
29d27812a7Spooka 
30d27812a7Spooka #if !defined(lint)
31*05aecacfSpooka __RCSID("$NetBSD: rumpuser_component.c,v 1.6 2013/05/07 15:18:35 pooka Exp $");
32d27812a7Spooka #endif /* !lint */
33d27812a7Spooka 
34*05aecacfSpooka #include <stdint.h>
35*05aecacfSpooka 
36d27812a7Spooka /*
37d27812a7Spooka  * These interfaces affect the shlib major/minor; they can be called from
38d27812a7Spooka  * any program when applicable.  The rest of the interfaces provided
39d27812a7Spooka  * by rumpuser are part of the rump kernel/hypervisor contract and
40d27812a7Spooka  * are versioned by RUMPUSER_VERSION.
41d27812a7Spooka  */
42d27812a7Spooka 
43d27812a7Spooka #include <rump/rumpuser_component.h>
44d27812a7Spooka 
45d27812a7Spooka #include "rumpuser_int.h"
46d27812a7Spooka 
47d27812a7Spooka void *
rumpuser_component_unschedule(void)48d27812a7Spooka rumpuser_component_unschedule(void)
49d27812a7Spooka {
50d27812a7Spooka 	int nlocks;
51d27812a7Spooka 
52799b0098Spooka 	rumpkern_unsched(&nlocks, NULL);
53d27812a7Spooka 	return (void *)(intptr_t)nlocks;
54d27812a7Spooka }
55d27812a7Spooka 
56d27812a7Spooka void
rumpuser_component_schedule(void * cookie)57d27812a7Spooka rumpuser_component_schedule(void *cookie)
58d27812a7Spooka {
59d27812a7Spooka 	int nlocks = (int)(intptr_t)cookie;
60d27812a7Spooka 
61799b0098Spooka 	rumpkern_sched(nlocks, NULL);
62d27812a7Spooka }
63f9b6aa94Spooka 
64f9b6aa94Spooka void
rumpuser_component_kthread(void)65f9b6aa94Spooka rumpuser_component_kthread(void)
66f9b6aa94Spooka {
67f9b6aa94Spooka 
68f9b6aa94Spooka 	rumpuser__hyp.hyp_schedule();
69f9b6aa94Spooka 	rumpuser__hyp.hyp_lwproc_newlwp(0);
70f9b6aa94Spooka 	rumpuser__hyp.hyp_unschedule();
71f9b6aa94Spooka }
72f9b6aa94Spooka 
73f9b6aa94Spooka struct lwp *
rumpuser_component_curlwp(void)74f9b6aa94Spooka rumpuser_component_curlwp(void)
75f9b6aa94Spooka {
76f9b6aa94Spooka 	struct lwp *l;
77f9b6aa94Spooka 
78f9b6aa94Spooka 	rumpuser__hyp.hyp_schedule();
79f9b6aa94Spooka 	l = rumpuser__hyp.hyp_lwproc_curlwp();
80f9b6aa94Spooka 	rumpuser__hyp.hyp_unschedule();
81f9b6aa94Spooka 
82f9b6aa94Spooka 	return l;
83f9b6aa94Spooka }
84f9b6aa94Spooka 
85f9b6aa94Spooka void
rumpuser_component_switchlwp(struct lwp * l)86f9b6aa94Spooka rumpuser_component_switchlwp(struct lwp *l)
87f9b6aa94Spooka {
88f9b6aa94Spooka 
89f9b6aa94Spooka 	rumpuser__hyp.hyp_schedule();
90f9b6aa94Spooka 	rumpuser__hyp.hyp_lwproc_switch(l);
91f9b6aa94Spooka 	rumpuser__hyp.hyp_unschedule();
92f9b6aa94Spooka }
93f9b6aa94Spooka 
94f9b6aa94Spooka void
rumpuser_component_kthread_release(void)95f9b6aa94Spooka rumpuser_component_kthread_release(void)
96f9b6aa94Spooka {
97f9b6aa94Spooka 
98f9b6aa94Spooka 	rumpuser__hyp.hyp_schedule();
99f9b6aa94Spooka 	rumpuser__hyp.hyp_lwproc_release();
100f9b6aa94Spooka 	rumpuser__hyp.hyp_unschedule();
101f9b6aa94Spooka }
1020d08a130Spooka 
1030d08a130Spooka int
rumpuser_component_errtrans(int hosterr)1040d08a130Spooka rumpuser_component_errtrans(int hosterr)
1050d08a130Spooka {
1060d08a130Spooka 
1070d08a130Spooka 	return rumpuser__errtrans(hosterr);
1080d08a130Spooka }
109