sbi_ecall_vendor.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2020 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. * Atish Patra <atish.patra@wdc.com>
  9. */
  10. #include <sbi/sbi_ecall.h>
  11. #include <sbi/sbi_ecall_interface.h>
  12. #include <sbi/sbi_error.h>
  13. #include <sbi/sbi_platform.h>
  14. #include <sbi/sbi_trap.h>
  15. #include <sbi/riscv_asm.h>
  16. static inline unsigned long sbi_ecall_vendor_id(void)
  17. {
  18. return SBI_EXT_VENDOR_START +
  19. (csr_read(CSR_MVENDORID) &
  20. (SBI_EXT_VENDOR_END - SBI_EXT_VENDOR_START));
  21. }
  22. static int sbi_ecall_vendor_probe(unsigned long extid,
  23. unsigned long *out_val)
  24. {
  25. if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) ||
  26. extid != sbi_ecall_vendor_id())
  27. *out_val = 0;
  28. else
  29. *out_val = 1;
  30. return 0;
  31. }
  32. static int sbi_ecall_vendor_handler(unsigned long extid, unsigned long funcid,
  33. const struct sbi_trap_regs *regs,
  34. unsigned long *out_val,
  35. struct sbi_trap_info *out_trap)
  36. {
  37. if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) ||
  38. extid != sbi_ecall_vendor_id())
  39. return SBI_ERR_NOT_SUPPORTED;
  40. return sbi_platform_vendor_ext_provider(sbi_platform_thishart_ptr(),
  41. funcid, regs,
  42. out_val, out_trap);
  43. }
  44. struct sbi_ecall_extension ecall_vendor = {
  45. .extid_start = SBI_EXT_VENDOR_START,
  46. .extid_end = SBI_EXT_VENDOR_END,
  47. .probe = sbi_ecall_vendor_probe,
  48. .handle = sbi_ecall_vendor_handler,
  49. };