xen-os.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /******************************************************************************
  2. * xen/xen-os.h
  3. *
  4. * Random collection of macros and definition
  5. *
  6. * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
  7. * All rights reserved.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to
  11. * deal in the Software without restriction, including without limitation the
  12. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  13. * sell copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. * DEALINGS IN THE SOFTWARE.
  26. *
  27. * $FreeBSD$
  28. */
  29. #ifndef _XEN_XEN_OS_H_
  30. #define _XEN_XEN_OS_H_
  31. #if !defined(__XEN_INTERFACE_VERSION__)
  32. #define __XEN_INTERFACE_VERSION__ 0x00030208
  33. #endif
  34. #define GRANT_REF_INVALID 0xffffffff
  35. #ifdef LOCORE
  36. #define __ASSEMBLY__
  37. #endif
  38. #include <xen/interface/xen.h>
  39. #ifndef __ASSEMBLY__
  40. #include <xen/interface/event_channel.h>
  41. struct hypervisor_info {
  42. vm_paddr_t (*get_xenstore_mfn)(void);
  43. evtchn_port_t (*get_xenstore_evtchn)(void);
  44. vm_paddr_t (*get_console_mfn)(void);
  45. evtchn_port_t (*get_console_evtchn)(void);
  46. uint32_t (*get_start_flags)(void);
  47. };
  48. extern struct hypervisor_info hypervisor_info;
  49. static inline vm_paddr_t
  50. xen_get_xenstore_mfn(void)
  51. {
  52. return (hypervisor_info.get_xenstore_mfn());
  53. }
  54. static inline evtchn_port_t
  55. xen_get_xenstore_evtchn(void)
  56. {
  57. return (hypervisor_info.get_xenstore_evtchn());
  58. }
  59. static inline vm_paddr_t
  60. xen_get_console_mfn(void)
  61. {
  62. return (hypervisor_info.get_console_mfn());
  63. }
  64. static inline evtchn_port_t
  65. xen_get_console_evtchn(void)
  66. {
  67. return (hypervisor_info.get_console_evtchn());
  68. }
  69. static inline uint32_t
  70. xen_get_start_flags(void)
  71. {
  72. return (hypervisor_info.get_start_flags());
  73. }
  74. #endif
  75. #include <machine/xen/xen-os.h>
  76. /* Everything below this point is not included by assembler (.S) files. */
  77. #ifndef __ASSEMBLY__
  78. extern shared_info_t *HYPERVISOR_shared_info;
  79. extern int xen_disable_pv_disks;
  80. extern int xen_disable_pv_nics;
  81. extern bool xen_suspend_cancelled;
  82. enum xen_domain_type {
  83. XEN_NATIVE, /* running on bare hardware */
  84. XEN_PV_DOMAIN, /* running in a PV domain */
  85. XEN_HVM_DOMAIN, /* running in a Xen hvm domain */
  86. };
  87. extern enum xen_domain_type xen_domain_type;
  88. static inline int
  89. xen_domain(void)
  90. {
  91. return (xen_domain_type != XEN_NATIVE);
  92. }
  93. static inline int
  94. xen_pv_domain(void)
  95. {
  96. return (xen_domain_type == XEN_PV_DOMAIN);
  97. }
  98. static inline int
  99. xen_hvm_domain(void)
  100. {
  101. return (xen_domain_type == XEN_HVM_DOMAIN);
  102. }
  103. static inline bool
  104. xen_initial_domain(void)
  105. {
  106. return (xen_domain() && (xen_get_start_flags() & SIF_INITDOMAIN) != 0);
  107. }
  108. /*
  109. * Based on ofed/include/linux/bitops.h
  110. *
  111. * Those helpers are prefixed by xen_ because xen-os.h is widely included
  112. * and we don't want the other drivers using them.
  113. *
  114. */
  115. #define NBPL (NBBY * sizeof(long))
  116. static inline bool
  117. xen_test_bit(int bit, volatile long *addr)
  118. {
  119. unsigned long mask = 1UL << (bit % NBPL);
  120. return !!(atomic_load_acq_long(&addr[bit / NBPL]) & mask);
  121. }
  122. static inline void
  123. xen_set_bit(int bit, volatile long *addr)
  124. {
  125. atomic_set_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
  126. }
  127. static inline void
  128. xen_clear_bit(int bit, volatile long *addr)
  129. {
  130. atomic_clear_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
  131. }
  132. #undef NBPL
  133. /*
  134. * Functions to allocate/free unused memory in order
  135. * to map memory from other domains.
  136. */
  137. struct resource *xenmem_alloc(device_t dev, int *res_id, size_t size);
  138. int xenmem_free(device_t dev, int res_id, struct resource *res);
  139. /* Debug/emergency function, prints directly to hypervisor console */
  140. void xc_printf(const char *, ...) __printflike(1, 2);
  141. #ifndef xen_mb
  142. #define xen_mb() mb()
  143. #endif
  144. #ifndef xen_rmb
  145. #define xen_rmb() rmb()
  146. #endif
  147. #ifndef xen_wmb
  148. #define xen_wmb() wmb()
  149. #endif
  150. #endif /* !__ASSEMBLY__ */
  151. #endif /* _XEN_XEN_OS_H_ */