sbi_ecall_susp.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: BSD-2-Clause
  2. #include <sbi/sbi_ecall.h>
  3. #include <sbi/sbi_ecall_interface.h>
  4. #include <sbi/sbi_error.h>
  5. #include <sbi/sbi_trap.h>
  6. #include <sbi/sbi_system.h>
  7. static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
  8. const struct sbi_trap_regs *regs,
  9. unsigned long *out_val,
  10. struct sbi_trap_info *out_trap)
  11. {
  12. int ret = SBI_ENOTSUPP;
  13. if (funcid == SBI_EXT_SUSP_SUSPEND)
  14. ret = sbi_system_suspend(regs->a0, regs->a1, regs->a2);
  15. if (ret >= 0) {
  16. *out_val = ret;
  17. ret = 0;
  18. }
  19. return ret;
  20. }
  21. static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
  22. {
  23. u32 type, count = 0;
  24. /*
  25. * At least one suspend type should be supported by the
  26. * platform for the SBI SUSP extension to be usable.
  27. */
  28. for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
  29. if (sbi_system_suspend_supported(type))
  30. count++;
  31. }
  32. *out_val = count ? 1 : 0;
  33. return 0;
  34. }
  35. struct sbi_ecall_extension ecall_susp = {
  36. .extid_start = SBI_EXT_SUSP,
  37. .extid_end = SBI_EXT_SUSP,
  38. .handle = sbi_ecall_susp_handler,
  39. .probe = sbi_ecall_susp_probe,
  40. };