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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. register uint64_t rcx asm ( "rcx" );
  26. register uint64_t rdx asm ( "rdx" );
  27. register uint64_t r8 asm ( "r8" );
  28. uint64_t in_phys;
  29. uint64_t out_phys;
  30. uint16_t result;
  31. in_phys = ( ( __builtin_constant_p ( in ) && ( in == NULL ) )
  32. ? 0 : virt_to_phys ( in ) );
  33. out_phys = ( ( __builtin_constant_p ( out ) && ( out == NULL ) )
  34. ? 0 : virt_to_phys ( out ) );
  35. rcx = code;
  36. rdx = in_phys;
  37. r8 = out_phys;
  38. __asm__ __volatile__ ( "call *%4"
  39. : "=a" ( result ), "+r" ( rcx ), "+r" ( rdx ),
  40. "+r" ( r8 )
  41. : "m" ( hypercall )
  42. : "r9", "r10", "r11" );
  43. return result;
  44. }
  45. #endif /* _BITS_HYPERV_H */