xen_common.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #include <xs.h>
  8. #include <xen/io/xenbus.h>
  9. #include "hw.h"
  10. #include "xen.h"
  11. #include "qemu-queue.h"
  12. /*
  13. * We don't support Xen prior to 3.3.0.
  14. */
  15. /* Xen before 4.0 */
  16. #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
  17. static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
  18. xen_pfn_t *arr, int *err,
  19. unsigned int num)
  20. {
  21. return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
  22. }
  23. #endif
  24. /* Xen before 4.1 */
  25. #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
  26. typedef int XenXC;
  27. typedef int XenEvtchn;
  28. typedef int XenGnttab;
  29. # define XC_INTERFACE_FMT "%i"
  30. # define XC_HANDLER_INITIAL_VALUE -1
  31. static inline XenEvtchn xen_xc_evtchn_open(void *logger,
  32. unsigned int open_flags)
  33. {
  34. return xc_evtchn_open();
  35. }
  36. static inline XenGnttab xen_xc_gnttab_open(void *logger,
  37. unsigned int open_flags)
  38. {
  39. return xc_gnttab_open();
  40. }
  41. static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
  42. unsigned int open_flags)
  43. {
  44. return xc_interface_open();
  45. }
  46. static inline int xc_fd(int xen_xc)
  47. {
  48. return xen_xc;
  49. }
  50. static inline int xc_domain_populate_physmap_exact
  51. (XenXC xc_handle, uint32_t domid, unsigned long nr_extents,
  52. unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start)
  53. {
  54. return xc_domain_memory_populate_physmap
  55. (xc_handle, domid, nr_extents, extent_order, mem_flags, extent_start);
  56. }
  57. static inline int xc_domain_add_to_physmap(int xc_handle, uint32_t domid,
  58. unsigned int space, unsigned long idx,
  59. xen_pfn_t gpfn)
  60. {
  61. struct xen_add_to_physmap xatp = {
  62. .domid = domid,
  63. .space = space,
  64. .idx = idx,
  65. .gpfn = gpfn,
  66. };
  67. return xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
  68. }
  69. static inline struct xs_handle *xs_open(unsigned long flags)
  70. {
  71. return xs_daemon_open();
  72. }
  73. static inline void xs_close(struct xs_handle *xsh)
  74. {
  75. if (xsh != NULL) {
  76. xs_daemon_close(xsh);
  77. }
  78. }
  79. /* Xen 4.1 */
  80. #else
  81. typedef xc_interface *XenXC;
  82. typedef xc_evtchn *XenEvtchn;
  83. typedef xc_gnttab *XenGnttab;
  84. # define XC_INTERFACE_FMT "%p"
  85. # define XC_HANDLER_INITIAL_VALUE NULL
  86. static inline XenEvtchn xen_xc_evtchn_open(void *logger,
  87. unsigned int open_flags)
  88. {
  89. return xc_evtchn_open(logger, open_flags);
  90. }
  91. static inline XenGnttab xen_xc_gnttab_open(void *logger,
  92. unsigned int open_flags)
  93. {
  94. return xc_gnttab_open(logger, open_flags);
  95. }
  96. static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
  97. unsigned int open_flags)
  98. {
  99. return xc_interface_open(logger, dombuild_logger, open_flags);
  100. }
  101. /* FIXME There is now way to have the xen fd */
  102. static inline int xc_fd(xc_interface *xen_xc)
  103. {
  104. return -1;
  105. }
  106. #endif
  107. void destroy_hvm_domain(void);
  108. #endif /* QEMU_HW_XEN_COMMON_H */