sbi_ecall_hsm.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2020 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Atish Patra <atish.patra@wdc.com>
  8. */
  9. #include <sbi/sbi_domain.h>
  10. #include <sbi/sbi_ecall.h>
  11. #include <sbi/sbi_ecall_interface.h>
  12. #include <sbi/sbi_error.h>
  13. #include <sbi/sbi_trap.h>
  14. #include <sbi/sbi_hsm.h>
  15. #include <sbi/sbi_scratch.h>
  16. #include <sbi/riscv_asm.h>
  17. static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
  18. const struct sbi_trap_regs *regs,
  19. unsigned long *out_val,
  20. struct sbi_trap_info *out_trap)
  21. {
  22. int ret = 0;
  23. struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
  24. ulong smode = (csr_read(CSR_MSTATUS) & MSTATUS_MPP) >>
  25. MSTATUS_MPP_SHIFT;
  26. switch (funcid) {
  27. case SBI_EXT_HSM_HART_START:
  28. ret = sbi_hsm_hart_start(scratch, sbi_domain_thishart_ptr(),
  29. regs->a0, regs->a1, smode, regs->a2);
  30. break;
  31. case SBI_EXT_HSM_HART_STOP:
  32. ret = sbi_hsm_hart_stop(scratch, true);
  33. break;
  34. case SBI_EXT_HSM_HART_GET_STATUS:
  35. ret = sbi_hsm_hart_get_state(sbi_domain_thishart_ptr(),
  36. regs->a0);
  37. break;
  38. case SBI_EXT_HSM_HART_SUSPEND:
  39. ret = sbi_hsm_hart_suspend(scratch, regs->a0, regs->a1,
  40. smode, regs->a2);
  41. break;
  42. default:
  43. ret = SBI_ENOTSUPP;
  44. }
  45. if (ret >= 0) {
  46. *out_val = ret;
  47. ret = 0;
  48. }
  49. return ret;
  50. }
  51. struct sbi_ecall_extension ecall_hsm = {
  52. .extid_start = SBI_EXT_HSM,
  53. .extid_end = SBI_EXT_HSM,
  54. .handle = sbi_ecall_hsm_handler,
  55. };