sbi_ecall_hsm.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_version.h>
  15. #include <sbi/sbi_hsm.h>
  16. #include <sbi/sbi_scratch.h>
  17. #include <sbi/riscv_asm.h>
  18. static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
  19. const struct sbi_trap_regs *regs,
  20. unsigned long *out_val,
  21. struct sbi_trap_info *out_trap)
  22. {
  23. ulong smode;
  24. int ret = 0, hstate;
  25. struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
  26. switch (funcid) {
  27. case SBI_EXT_HSM_HART_START:
  28. smode = csr_read(CSR_MSTATUS);
  29. smode = (smode & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
  30. ret = sbi_hsm_hart_start(scratch, sbi_domain_thishart_ptr(),
  31. regs->a0, regs->a1, smode, regs->a2);
  32. break;
  33. case SBI_EXT_HSM_HART_STOP:
  34. ret = sbi_hsm_hart_stop(scratch, TRUE);
  35. break;
  36. case SBI_EXT_HSM_HART_GET_STATUS:
  37. hstate = sbi_hsm_hart_get_state(sbi_domain_thishart_ptr(),
  38. regs->a0);
  39. ret = sbi_hsm_hart_state_to_status(hstate);
  40. break;
  41. default:
  42. ret = SBI_ENOTSUPP;
  43. };
  44. if (ret >= 0) {
  45. *out_val = ret;
  46. ret = 0;
  47. }
  48. return ret;
  49. }
  50. struct sbi_ecall_extension ecall_hsm = {
  51. .extid_start = SBI_EXT_HSM,
  52. .extid_end = SBI_EXT_HSM,
  53. .handle = sbi_ecall_hsm_handler,
  54. };