2
0

xen_common.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #ifndef QEMU_HW_XEN_COMMON_H
  2. #define QEMU_HW_XEN_COMMON_H 1
  3. #include "config-host.h"
  4. #include <stddef.h>
  5. #include <inttypes.h>
  6. #include <xenctrl.h>
  7. #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
  8. # include <xs.h>
  9. #else
  10. # include <xenstore.h>
  11. #endif
  12. #include <xen/io/xenbus.h>
  13. #include "hw.h"
  14. #include "xen.h"
  15. #include "qemu/queue.h"
  16. /*
  17. * We don't support Xen prior to 3.3.0.
  18. */
  19. /* Xen before 4.0 */
  20. #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
  21. static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
  22. xen_pfn_t *arr, int *err,
  23. unsigned int num)
  24. {
  25. return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
  26. }
  27. #endif
  28. /* Xen before 4.1 */
  29. #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
  30. typedef int XenXC;
  31. typedef int XenEvtchn;
  32. typedef int XenGnttab;
  33. # define XC_INTERFACE_FMT "%i"
  34. # define XC_HANDLER_INITIAL_VALUE -1
  35. static inline XenEvtchn xen_xc_evtchn_open(void *logger,
  36. unsigned int open_flags)
  37. {
  38. return xc_evtchn_open();
  39. }
  40. static inline XenGnttab xen_xc_gnttab_open(void *logger,
  41. unsigned int open_flags)
  42. {
  43. return xc_gnttab_open();
  44. }
  45. static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
  46. unsigned int open_flags)
  47. {
  48. return xc_interface_open();
  49. }
  50. static inline int xc_fd(int xen_xc)
  51. {
  52. return xen_xc;
  53. }
  54. static inline int xc_domain_populate_physmap_exact
  55. (XenXC xc_handle, uint32_t domid, unsigned long nr_extents,
  56. unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start)
  57. {
  58. return xc_domain_memory_populate_physmap
  59. (xc_handle, domid, nr_extents, extent_order, mem_flags, extent_start);
  60. }
  61. static inline int xc_domain_add_to_physmap(int xc_handle, uint32_t domid,
  62. unsigned int space, unsigned long idx,
  63. xen_pfn_t gpfn)
  64. {
  65. struct xen_add_to_physmap xatp = {
  66. .domid = domid,
  67. .space = space,
  68. .idx = idx,
  69. .gpfn = gpfn,
  70. };
  71. return xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
  72. }
  73. static inline struct xs_handle *xs_open(unsigned long flags)
  74. {
  75. return xs_daemon_open();
  76. }
  77. static inline void xs_close(struct xs_handle *xsh)
  78. {
  79. if (xsh != NULL) {
  80. xs_daemon_close(xsh);
  81. }
  82. }
  83. /* Xen 4.1 */
  84. #else
  85. typedef xc_interface *XenXC;
  86. typedef xc_evtchn *XenEvtchn;
  87. typedef xc_gnttab *XenGnttab;
  88. # define XC_INTERFACE_FMT "%p"
  89. # define XC_HANDLER_INITIAL_VALUE NULL
  90. static inline XenEvtchn xen_xc_evtchn_open(void *logger,
  91. unsigned int open_flags)
  92. {
  93. return xc_evtchn_open(logger, open_flags);
  94. }
  95. static inline XenGnttab xen_xc_gnttab_open(void *logger,
  96. unsigned int open_flags)
  97. {
  98. return xc_gnttab_open(logger, open_flags);
  99. }
  100. static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
  101. unsigned int open_flags)
  102. {
  103. return xc_interface_open(logger, dombuild_logger, open_flags);
  104. }
  105. /* FIXME There is now way to have the xen fd */
  106. static inline int xc_fd(xc_interface *xen_xc)
  107. {
  108. return -1;
  109. }
  110. #endif
  111. /* Xen before 4.2 */
  112. #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
  113. static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom,
  114. uint64_t addr, uint32_t data)
  115. {
  116. return -ENOSYS;
  117. }
  118. #else
  119. static inline int xen_xc_hvm_inject_msi(XenXC xen_xc, domid_t dom,
  120. uint64_t addr, uint32_t data)
  121. {
  122. return xc_hvm_inject_msi(xen_xc, dom, addr, data);
  123. }
  124. #endif
  125. void destroy_hvm_domain(bool reboot);
  126. /* shutdown/destroy current domain because of an error */
  127. void xen_shutdown_fatal_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
  128. #endif /* QEMU_HW_XEN_COMMON_H */