Statistics
| Branch: | Revision:

root / include / hw / xen / xen_common.h @ 0d09e41a

History | View | Annotate | Download (3.8 kB)

1
#ifndef QEMU_HW_XEN_COMMON_H
2
#define QEMU_HW_XEN_COMMON_H 1
3

    
4
#include "config-host.h"
5

    
6
#include <stddef.h>
7
#include <inttypes.h>
8

    
9
#include <xenctrl.h>
10
#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
11
#  include <xs.h>
12
#else
13
#  include <xenstore.h>
14
#endif
15
#include <xen/io/xenbus.h>
16

    
17
#include "hw/hw.h"
18
#include "hw/xen/xen.h"
19
#include "qemu/queue.h"
20

    
21
/*
22
 * We don't support Xen prior to 3.3.0.
23
 */
24

    
25
/* Xen before 4.0 */
26
#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
27
static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
28
                                        xen_pfn_t *arr, int *err,
29
                                        unsigned int num)
30
{
31
    return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
32
}
33
#endif
34

    
35

    
36
/* Xen before 4.1 */
37
#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
38

    
39
typedef int XenXC;
40
typedef int XenEvtchn;
41
typedef int XenGnttab;
42

    
43
#  define XC_INTERFACE_FMT "%i"
44
#  define XC_HANDLER_INITIAL_VALUE    -1
45

    
46
static inline XenEvtchn xen_xc_evtchn_open(void *logger,
47
                                           unsigned int open_flags)
48
{
49
    return xc_evtchn_open();
50
}
51

    
52
static inline XenGnttab xen_xc_gnttab_open(void *logger,
53
                                           unsigned int open_flags)
54
{
55
    return xc_gnttab_open();
56
}
57

    
58
static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
59
                                          unsigned int open_flags)
60
{
61
    return xc_interface_open();
62
}
63

    
64
static inline int xc_fd(int xen_xc)
65
{
66
    return xen_xc;
67
}
68

    
69

    
70
static inline int xc_domain_populate_physmap_exact
71
    (XenXC xc_handle, uint32_t domid, unsigned long nr_extents,
72
     unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start)
73
{
74
    return xc_domain_memory_populate_physmap
75
        (xc_handle, domid, nr_extents, extent_order, mem_flags, extent_start);
76
}
77

    
78
static inline int xc_domain_add_to_physmap(int xc_handle, uint32_t domid,
79
                                           unsigned int space, unsigned long idx,
80
                                           xen_pfn_t gpfn)
81
{
82
    struct xen_add_to_physmap xatp = {
83
        .domid = domid,
84
        .space = space,
85
        .idx = idx,
86
        .gpfn = gpfn,
87
    };
88

    
89
    return xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
90
}
91

    
92
static inline struct xs_handle *xs_open(unsigned long flags)
93
{
94
    return xs_daemon_open();
95
}
96

    
97
static inline void xs_close(struct xs_handle *xsh)
98
{
99
    if (xsh != NULL) {
100
        xs_daemon_close(xsh);
101
    }
102
}
103

    
104

    
105
/* Xen 4.1 */
106
#else
107

    
108
typedef xc_interface *XenXC;
109
typedef xc_evtchn *XenEvtchn;
110
typedef xc_gnttab *XenGnttab;
111

    
112
#  define XC_INTERFACE_FMT "%p"
113
#  define XC_HANDLER_INITIAL_VALUE    NULL
114

    
115
static inline XenEvtchn xen_xc_evtchn_open(void *logger,
116
                                           unsigned int open_flags)
117
{
118
    return xc_evtchn_open(logger, open_flags);
119
}
120

    
121
static inline XenGnttab xen_xc_gnttab_open(void *logger,
122
                                           unsigned int open_flags)
123
{
124
    return xc_gnttab_open(logger, open_flags);
125
}
126

    
127
static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
128
                                          unsigned int open_flags)
129
{
130
    return xc_interface_open(logger, dombuild_logger, open_flags);
131
}
132

    
133
/* FIXME There is now way to have the xen fd */
134
static inline int xc_fd(xc_interface *xen_xc)
135
{
136
    return -1;
137
}
138
#endif
139

    
140
/* Xen before 4.2 */
141
#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
142
static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom,
143
        uint64_t addr, uint32_t data)
144
{
145
    return -ENOSYS;
146
}
147
#else
148
static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom,
149
        uint64_t addr, uint32_t data)
150
{
151
    return xc_hvm_inject_msi(xen_xc, dom, addr, data);
152
}
153
#endif
154

    
155
void destroy_hvm_domain(bool reboot);
156

    
157
/* shutdown/destroy current domain because of an error */
158
void xen_shutdown_fatal_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
159

    
160
#endif /* QEMU_HW_XEN_COMMON_H */