vcpu.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2023 MediaTek Inc.
  4. */
  5. #include <linux/arm-smccc.h>
  6. #include <linux/err.h>
  7. #include <linux/uaccess.h>
  8. #include <linux/gzvm.h>
  9. #include <linux/gzvm_drv.h>
  10. #include "gzvm_arch_common.h"
  11. int gzvm_arch_vcpu_update_one_reg(struct gzvm_vcpu *vcpu, __u64 reg_id,
  12. bool is_write, __u64 *data)
  13. {
  14. struct arm_smccc_res res;
  15. unsigned long a1;
  16. int ret;
  17. a1 = assemble_vm_vcpu_tuple(vcpu->gzvm->vm_id, vcpu->vcpuid);
  18. if (!is_write) {
  19. ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_GET_ONE_REG,
  20. a1, reg_id, 0, 0, 0, 0, 0, &res);
  21. if (ret == 0)
  22. *data = res.a1;
  23. } else {
  24. ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_SET_ONE_REG,
  25. a1, reg_id, *data, 0, 0, 0, 0, &res);
  26. }
  27. return ret;
  28. }
  29. int gzvm_arch_vcpu_run(struct gzvm_vcpu *vcpu, __u64 *exit_reason)
  30. {
  31. struct arm_smccc_res res;
  32. unsigned long a1;
  33. int ret;
  34. a1 = assemble_vm_vcpu_tuple(vcpu->gzvm->vm_id, vcpu->vcpuid);
  35. ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_RUN, a1, 0, 0, 0, 0, 0,
  36. 0, &res);
  37. *exit_reason = res.a1;
  38. return ret;
  39. }
  40. int gzvm_arch_destroy_vcpu(u16 vm_id, int vcpuid)
  41. {
  42. struct arm_smccc_res res;
  43. unsigned long a1;
  44. a1 = assemble_vm_vcpu_tuple(vm_id, vcpuid);
  45. gzvm_hypcall_wrapper(MT_HVC_GZVM_DESTROY_VCPU, a1, 0, 0, 0, 0, 0, 0,
  46. &res);
  47. return 0;
  48. }
  49. /**
  50. * gzvm_arch_create_vcpu() - Call smc to gz hypervisor to create vcpu
  51. * @vm_id: vm id
  52. * @vcpuid: vcpu id
  53. * @run: Virtual address of vcpu->run
  54. *
  55. * Return: The wrapper helps caller to convert geniezone errno to Linux errno.
  56. */
  57. int gzvm_arch_create_vcpu(u16 vm_id, int vcpuid, void *run)
  58. {
  59. struct arm_smccc_res res;
  60. unsigned long a1, a2;
  61. int ret;
  62. a1 = assemble_vm_vcpu_tuple(vm_id, vcpuid);
  63. a2 = (__u64)virt_to_phys(run);
  64. ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_CREATE_VCPU, a1, a2, 0, 0, 0, 0,
  65. 0, &res);
  66. return ret;
  67. }