1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation;
5  * version 2.1 of the License.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; If not, see <http://www.gnu.org/licenses/>.
14  *
15  * Split out from xc_minios.c
16  *
17  * Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.com>.
18  */
19 
20 #include <mini-os/types.h>
21 #include <mini-os/os.h>
22 #include <mini-os/mm.h>
23 #include <mini-os/lib.h>
24 
25 #include <errno.h>
26 #include <malloc.h>
27 
28 #include "private.h"
29 
osdep_xencall_open(xencall_handle * xcall)30 int osdep_xencall_open(xencall_handle *xcall)
31 {
32     /* No fd required */
33     return 0;
34 }
35 
osdep_xencall_close(xencall_handle * xcall)36 int osdep_xencall_close(xencall_handle *xcall)
37 {
38     return 0;
39 }
40 
osdep_hypercall(xencall_handle * xcall,privcmd_hypercall_t * hypercall)41 int osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall)
42 {
43     multicall_entry_t call;
44     int i, ret;
45 
46     call.op = hypercall->op;
47     for (i = 0; i < 5; i++)
48         call.args[i] = hypercall->arg[i];
49 
50     ret = HYPERVISOR_multicall(&call, 1);
51 
52     if (ret < 0) {
53         errno = -ret;
54         return -1;
55     }
56     if ((long) call.result < 0) {
57         errno = - (long) call.result;
58         return -1;
59     }
60     return call.result;
61 }
62 
osdep_alloc_pages(xencall_handle * xcall,size_t npages)63 void *osdep_alloc_pages(xencall_handle *xcall, size_t npages)
64 {
65     return memalign(PAGE_SIZE, npages * PAGE_SIZE);
66 }
67 
osdep_free_pages(xencall_handle * xcall,void * ptr,size_t npages)68 void osdep_free_pages(xencall_handle *xcall, void *ptr, size_t npages)
69 {
70     free(ptr);
71 }
72 
xencall_buffers_never_fault(xencall_handle * xcall)73 int xencall_buffers_never_fault(xencall_handle *xcall)
74 {
75     return 1;
76 }
77 
78 /*
79  * Local variables:
80  * mode: C
81  * c-file-style: "BSD"
82  * c-basic-offset: 4
83  * tab-width: 4
84  * indent-tabs-mode: nil
85  * End:
86  */
87