aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xenctrlosdep.h
blob: e610a245ed4c2a8bc6bd0285141745b90489d7df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/******************************************************************************
 *
 * Interface to OS specific low-level operations
 *
 * Copyright (c) 2010, Citrix Systems Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * This interface defines the interactions between the Xen control
 * libraries and the OS facilities used to communicate with the
 * hypervisor.
 *
 * It is possible to override the default (native) implementation by
 * setting the XENCTRL_OSDEP environment variable to point to a
 * plugin library. Userspace can use this facility to intercept
 * hypervisor operations. This can be used e.g. to implement a
 * userspace simulator for Xen hypercalls.
 *
 * The plugin must contain a data structure:
 *  xc_osdep_info_t xc_osdep_info;
 *
 * xc_osdep_init:
 *   Must return a suitable struct xc_osdep_ops pointer or NULL on failure.
 */

#ifndef XC_OSDEP_H
#define XC_OSDEP_H

/* Tell the Xen public headers we are a user-space tools build. */
#ifndef __XEN_TOOLS__
#define __XEN_TOOLS__ 1
#endif

#include <sys/mman.h>
#include <sys/types.h>

#include <xen/sys/privcmd.h>

enum xc_osdep_type {
    XC_OSDEP_PRIVCMD,
    XC_OSDEP_EVTCHN,
    XC_OSDEP_GNTTAB,
    XC_OSDEP_GNTSHR,
};

/* Opaque handle internal to the backend */
typedef unsigned long xc_osdep_handle;

#define XC_OSDEP_OPEN_ERROR ((xc_osdep_handle)-1)

struct xc_osdep_ops
{
    /* Opens an interface.
     *
     * Must return an opaque handle on success or
     * XC_OSDEP_OPEN_ERROR on failure
     */
    xc_osdep_handle (*open)(xc_interface *xch);

    int (*close)(xc_interface *xch, xc_osdep_handle h);

    union {
        struct {
            void *(*alloc_hypercall_buffer)(xc_interface *xch, xc_osdep_handle h, int npages);
            void (*free_hypercall_buffer)(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages);

            int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall);

            void *(*map_foreign_batch)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
                                       xen_pfn_t *arr, int num);
            void *(*map_foreign_bulk)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
                                      const xen_pfn_t *arr, int *err, unsigned int num);
            void *(*map_foreign_range)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot,
                                       unsigned long mfn);
            void *(*map_foreign_ranges)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, size_t size, int prot,
                                        size_t chunksize, privcmd_mmap_entry_t entries[],
                                        int nentries);
        } privcmd;
        struct {
            int (*fd)(xc_evtchn *xce, xc_osdep_handle h);

            int (*notify)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port);

            evtchn_port_or_error_t (*bind_unbound_port)(xc_evtchn *xce, xc_osdep_handle h, int domid);
            evtchn_port_or_error_t (*bind_interdomain)(xc_evtchn *xce, xc_osdep_handle h, int domid,
                                                       evtchn_port_t remote_port);
            evtchn_port_or_error_t (*bind_virq)(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq);

            int (*unbind)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port);

            evtchn_port_or_error_t (*pending)(xc_evtchn *xce, xc_osdep_handle h);
            int (*unmask)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port);
        } evtchn;
        struct {
#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1
            void *(*grant_map)(xc_gnttab *xcg, xc_osdep_handle h,
                               uint32_t count, int flags, int prot,
                               uint32_t *domids, uint32_t *refs,
                               uint32_t notify_offset,
                               evtchn_port_t notify_port);
            int (*munmap)(xc_gnttab *xcg, xc_osdep_handle h,
                          void *start_address,
                          uint32_t count);
            int (*set_max_grants)(xc_gnttab *xcg, xc_osdep_handle h, uint32_t count);
        } gnttab;
        struct {
            void *(*share_pages)(xc_gntshr *xcg, xc_osdep_handle h,
                                 uint32_t domid, int count,
                                 uint32_t *refs, int writable,
                                 uint32_t notify_offset,
                                 evtchn_port_t notify_port);
            int (*munmap)(xc_gntshr *xcg, xc_osdep_handle h,
                          void *start_address, uint32_t count);
        } gntshr;
    } u;
};
typedef struct xc_osdep_ops xc_osdep_ops;

typedef xc_osdep_ops *(*xc_osdep_init_fn)(xc_interface *xch, enum xc_osdep_type);

struct xc_osdep_info
{
    /* Describes this backend. */
    const char *name;

    /* Returns ops function. */
    xc_osdep_init_fn init;

    /* True if this interface backs onto a fake Xen. */
    int fake;

    /* For internal use by loader. */
    void *dl_handle;
};
typedef struct xc_osdep_info xc_osdep_info_t;

/* All backends, including the builtin backend, must supply this structure. */
extern xc_osdep_info_t xc_osdep_info;

/* Stub for not yet converted OSes */
void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
                                 uint32_t dom, int prot,
                                 const xen_pfn_t *arr, int *err, unsigned int num);

/* Report errors through xc_interface */
void xc_osdep_log(xc_interface *xch, xentoollog_level level, int code, const char *fmt, ...);

#endif

/*
 * Local variables:
 * mode: C
 * c-file-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */