blob: 0409ac79713b128a1f229421028889b651d93103 [file] [log] [blame]
aliguorid94f9482009-04-22 15:19:15 +00001#ifndef QEMU_HW_XEN_COMMON_H
2#define QEMU_HW_XEN_COMMON_H 1
3
Anthony PERARDd5b93dd2011-02-25 16:20:34 +00004#include "config-host.h"
5
aliguorid94f9482009-04-22 15:19:15 +00006#include <stddef.h>
7#include <inttypes.h>
8
9#include <xenctrl.h>
10#include <xs.h>
11#include <xen/io/xenbus.h>
12
13#include "hw.h"
14#include "xen.h"
Jan Kiszkad8becc32009-09-12 15:00:28 +000015#include "qemu-queue.h"
aliguorid94f9482009-04-22 15:19:15 +000016
17/*
Anthony PERARDd5b93dd2011-02-25 16:20:34 +000018 * We don't support Xen prior to 3.3.0.
aliguorid94f9482009-04-22 15:19:15 +000019 */
Anthony PERARDd5b93dd2011-02-25 16:20:34 +000020
21/* Xen before 4.0 */
22#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
23static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
24 xen_pfn_t *arr, int *err,
25 unsigned int num)
26{
27 return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
28}
aliguorid94f9482009-04-22 15:19:15 +000029#endif
Anthony PERARDd5b93dd2011-02-25 16:20:34 +000030
31
32/* Xen before 4.1 */
33#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
34
35typedef int XenXC;
36typedef int XenEvtchn;
37typedef int XenGnttab;
38
39# define XC_INTERFACE_FMT "%i"
40# define XC_HANDLER_INITIAL_VALUE -1
41
42static inline XenEvtchn xen_xc_evtchn_open(void *logger,
43 unsigned int open_flags)
44{
45 return xc_evtchn_open();
46}
47
48static inline XenGnttab xen_xc_gnttab_open(void *logger,
49 unsigned int open_flags)
50{
51 return xc_gnttab_open();
52}
53
54static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
55 unsigned int open_flags)
56{
57 return xc_interface_open();
58}
59
60static inline int xc_fd(int xen_xc)
61{
62 return xen_xc;
63}
64
65
Jun Nakajima432d2682010-08-31 16:41:25 +010066static inline int xc_domain_populate_physmap_exact
67 (XenXC xc_handle, uint32_t domid, unsigned long nr_extents,
68 unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start)
69{
70 return xc_domain_memory_populate_physmap
71 (xc_handle, domid, nr_extents, extent_order, mem_flags, extent_start);
72}
73
Anthony PERARDb87de242011-05-24 14:34:20 +010074static inline int xc_domain_add_to_physmap(int xc_handle, uint32_t domid,
75 unsigned int space, unsigned long idx,
76 xen_pfn_t gpfn)
77{
78 struct xen_add_to_physmap xatp = {
79 .domid = domid,
80 .space = space,
81 .idx = idx,
82 .gpfn = gpfn,
83 };
84
85 return xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
86}
87
Stefano Stabellini0f517262011-06-30 18:26:29 +010088static inline struct xs_handle *xs_open(unsigned long flags)
89{
90 return xs_daemon_open();
91}
92
93static inline void xs_close(struct xs_handle *xsh)
94{
95 if (xsh != NULL) {
96 xs_daemon_close(xsh);
97 }
98}
99
Jun Nakajima432d2682010-08-31 16:41:25 +0100100
Anthony PERARDd5b93dd2011-02-25 16:20:34 +0000101/* Xen 4.1 */
102#else
103
104typedef xc_interface *XenXC;
105typedef xc_evtchn *XenEvtchn;
106typedef xc_gnttab *XenGnttab;
107
108# define XC_INTERFACE_FMT "%p"
109# define XC_HANDLER_INITIAL_VALUE NULL
110
111static inline XenEvtchn xen_xc_evtchn_open(void *logger,
112 unsigned int open_flags)
113{
114 return xc_evtchn_open(logger, open_flags);
115}
116
117static inline XenGnttab xen_xc_gnttab_open(void *logger,
118 unsigned int open_flags)
119{
120 return xc_gnttab_open(logger, open_flags);
121}
122
123static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
124 unsigned int open_flags)
125{
126 return xc_interface_open(logger, dombuild_logger, open_flags);
127}
128
129/* FIXME There is now way to have the xen fd */
130static inline int xc_fd(xc_interface *xen_xc)
131{
132 return -1;
133}
aliguorid94f9482009-04-22 15:19:15 +0000134#endif
135
Arun Sharma9ce94e72010-09-06 20:07:14 +0100136void destroy_hvm_domain(void);
137
aliguorid94f9482009-04-22 15:19:15 +0000138#endif /* QEMU_HW_XEN_COMMON_H */