hcall.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __ASM_GH_HCALL_H
  6. #define __ASM_GH_HCALL_H
  7. #include <linux/types.h>
  8. #include <linux/gunyah/hcall_common.h>
  9. /**
  10. * _gh_hcall: Performs an AArch64-specific call into hypervisor using Gunyah ABI
  11. * @hcall_num: Hypercall function ID to invoke
  12. * @args: Hypercall argument registers
  13. * @resp: Pointer to location to store response
  14. */
  15. static inline int _gh_hcall(const gh_hcall_fnid_t hcall_num,
  16. const struct gh_hcall_args args,
  17. struct gh_hcall_resp *resp)
  18. {
  19. uint64_t _x18;
  20. register uint64_t _x0 asm("x0") = args.arg0;
  21. register uint64_t _x1 asm("x1") = args.arg1;
  22. register uint64_t _x2 asm("x2") = args.arg2;
  23. register uint64_t _x3 asm("x3") = args.arg3;
  24. register uint64_t _x4 asm("x4") = args.arg4;
  25. register uint64_t _x5 asm("x5") = args.arg5;
  26. register uint64_t _x6 asm("x6") = args.arg6;
  27. register uint64_t _x7 asm("x7") = args.arg7;
  28. asm volatile (
  29. #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK)
  30. "str x18, [%[_x18]]\n"
  31. #endif
  32. "hvc %[num]\n"
  33. #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK)
  34. "ldr x18, [%[_x18]]\n"
  35. "str xzr, [%[_x18]]\n"
  36. #endif
  37. : "+r"(_x0), "+r"(_x1), "+r"(_x2), "+r"(_x3), "+r"(_x4),
  38. "+r"(_x5), "+r"(_x6), "+r"(_x7)
  39. : [num] "i" (hcall_num), [_x18] "r"(&_x18)
  40. : "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17",
  41. #if !IS_ENABLED(CONFIG_SHADOW_CALL_STACK)
  42. "x18",
  43. #endif
  44. "memory"
  45. );
  46. resp->resp0 = _x0;
  47. resp->resp1 = _x1;
  48. resp->resp2 = _x2;
  49. resp->resp3 = _x3;
  50. resp->resp4 = _x4;
  51. resp->resp5 = _x5;
  52. resp->resp6 = _x6;
  53. resp->resp7 = _x7;
  54. return _x0;
  55. }
  56. #endif