You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hyperv.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef _BITS_HYPERV_H
  2. #define _BITS_HYPERV_H
  3. /** @file
  4. *
  5. * Hyper-V interface
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #include <ipxe/io.h>
  12. /**
  13. * Issue hypercall
  14. *
  15. * @v hv Hyper-V hypervisor
  16. * @v code Call code
  17. * @v in Input parameters
  18. * @v out Output parameters
  19. * @ret status Status code
  20. */
  21. static inline __attribute__ (( always_inline )) int
  22. hv_call ( struct hv_hypervisor *hv, unsigned int code, const void *in,
  23. void *out ) {
  24. void *hypercall = hv->hypercall;
  25. uint32_t in_phys;
  26. uint32_t out_phys;
  27. uint32_t discard_ecx;
  28. uint32_t discard_edx;
  29. uint16_t result;
  30. in_phys = ( ( __builtin_constant_p ( in ) && ( in == NULL ) )
  31. ? 0 : virt_to_phys ( in ) );
  32. out_phys = ( ( __builtin_constant_p ( out ) && ( out == NULL ) )
  33. ? 0 : virt_to_phys ( out ) );
  34. __asm__ __volatile__ ( "call *%9"
  35. : "=a" ( result ), "=c" ( discard_ecx ),
  36. "=d" ( discard_edx )
  37. : "d" ( 0 ), "a" ( code ),
  38. "b" ( 0 ), "c" ( in_phys ),
  39. "D" ( 0 ), "S" ( out_phys ),
  40. "m" ( hypercall ) );
  41. return result;
  42. }
  43. /**
  44. * Set bit atomically
  45. *
  46. * @v bits Bit field
  47. * @v bit Bit to set
  48. */
  49. static inline __attribute__ (( always_inline )) void
  50. hv_set_bit ( void *bits, unsigned int bit ) {
  51. struct {
  52. uint32_t dword[ ( bit / 32 ) + 1 ];
  53. } *dwords = bits;
  54. /* Set bit using "lock bts". Inform compiler that any memory
  55. * from the start of the bit field up to and including the
  56. * dword containing this bit may be modified. (This is
  57. * overkill but shouldn't matter in practice since we're
  58. * unlikely to subsequently read other bits from the same bit
  59. * field.)
  60. */
  61. __asm__ __volatile__ ( "lock bts %1, %0"
  62. : "+m" ( *dwords ) : "Ir" ( bit ) );
  63. }
  64. #endif /* _BITS_HYPERV_H */