gh_proxy_sched.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __GH_PROXY_SCHED_H
  6. #define __GH_PROXY_SCHED_H
  7. #include <linux/err.h>
  8. #include <linux/types.h>
  9. #include <linux/gunyah/hcall_common.h>
  10. #include <linux/gunyah/gh_common.h>
  11. #include <asm/gunyah/hcall.h>
  12. #define WATCHDOG_MANAGE_OP_FREEZE 0
  13. #define WATCHDOG_MANAGE_OP_FREEZE_AND_RESET 1
  14. #define WATCHDOG_MANAGE_OP_UNFREEZE 2
  15. struct gh_hcall_vcpu_run_resp {
  16. int ret;
  17. uint64_t vcpu_state;
  18. uint64_t vcpu_suspend_state;
  19. uint64_t state_data_0;
  20. uint64_t state_data_1;
  21. uint64_t state_data_2;
  22. };
  23. static inline int gh_hcall_wdog_manage(gh_capid_t wdog_capid, u16 operation)
  24. {
  25. int ret;
  26. struct gh_hcall_resp _resp = {0};
  27. ret = _gh_hcall(0x6063, (struct gh_hcall_args){ wdog_capid, operation }, &_resp);
  28. return ret;
  29. }
  30. static inline int gh_hcall_vcpu_run(gh_capid_t vcpu_capid, uint64_t resume_data_0,
  31. uint64_t resume_data_1, uint64_t resume_data_2,
  32. struct gh_hcall_vcpu_run_resp *resp)
  33. {
  34. int ret;
  35. struct gh_hcall_resp _resp = {0};
  36. ret = _gh_hcall(0x6065,
  37. (struct gh_hcall_args){ vcpu_capid, resume_data_0,
  38. resume_data_1, resume_data_2, 0 }, &_resp);
  39. resp->ret = ret;
  40. resp->vcpu_state = _resp.resp1;
  41. resp->vcpu_suspend_state = _resp.resp2;
  42. resp->state_data_0 = _resp.resp3;
  43. resp->state_data_1 = _resp.resp4;
  44. resp->state_data_2 = _resp.resp5;
  45. return ret;
  46. }
  47. static inline int gh_hcall_vpm_group_get_state(gh_capid_t vpmg_capid,
  48. uint64_t *vpmg_state)
  49. {
  50. int ret;
  51. struct gh_hcall_resp _resp = {0};
  52. ret = _gh_hcall(0x6045,
  53. (struct gh_hcall_args){ vpmg_capid, 0 },
  54. &_resp);
  55. *vpmg_state = _resp.resp1;
  56. return ret;
  57. }
  58. /*
  59. * proxy scheduler APIs called by gunyah driver
  60. */
  61. #if IS_ENABLED(CONFIG_GH_PROXY_SCHED)
  62. int gh_proxy_sched_init(void);
  63. void gh_proxy_sched_exit(void);
  64. int gh_get_nr_vcpus(gh_vmid_t vmid);
  65. bool gh_vm_supports_proxy_sched(gh_vmid_t vmid);
  66. int gh_vcpu_create_wq(gh_vmid_t vmid, unsigned int vcpu_id);
  67. int gh_vcpu_run(gh_vmid_t vmid, unsigned int vcpu_id, uint64_t resume_data_0,
  68. uint64_t resume_data_1, uint64_t resume_data_2,
  69. struct gh_hcall_vcpu_run_resp *resp);
  70. void gh_wakeup_all_vcpus(gh_vmid_t vmid);
  71. #else /* !CONFIG_GH_PROXY_SCHED */
  72. static inline int gh_proxy_sched_init(void)
  73. {
  74. return -EPERM;
  75. }
  76. static inline int gh_get_nr_vcpus(gh_vmid_t vmid)
  77. {
  78. return 0;
  79. }
  80. bool gh_vm_supports_proxy_sched(gh_vmid_t vmid)
  81. {
  82. return false;
  83. }
  84. static inline int gh_vcpu_run(gh_vmid_t vmid, unsigned int vcpu_id,
  85. uint64_t resume_data_0, uint64_t resume_data_1,
  86. uint64_t resume_data_2, struct gh_hcall_vcpu_run_resp *resp)
  87. {
  88. return -EPERM;
  89. }
  90. int gh_vcpu_create_wq(gh_vmid_t vmid, unsigned int vcpu_id)
  91. {
  92. return -EPERM;
  93. }
  94. static inline void gh_wakeup_all_vcpus(gh_vmid_t vmid) { }
  95. static inline void gh_proxy_sched_exit(void) { }
  96. #endif /* CONFIG_GH_PROXY_SCHED */
  97. #endif