sbi.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2015 Regents of the University of California
  4. * Copyright (c) 2020 Western Digital Corporation or its affiliates.
  5. */
  6. #ifndef _ASM_RISCV_SBI_H
  7. #define _ASM_RISCV_SBI_H
  8. #include <linux/types.h>
  9. #ifdef CONFIG_RISCV_SBI
  10. enum sbi_ext_id {
  11. #ifdef CONFIG_RISCV_SBI_V01
  12. SBI_EXT_0_1_SET_TIMER = 0x0,
  13. SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1,
  14. SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2,
  15. SBI_EXT_0_1_CLEAR_IPI = 0x3,
  16. SBI_EXT_0_1_SEND_IPI = 0x4,
  17. SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,
  18. SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6,
  19. SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7,
  20. SBI_EXT_0_1_SHUTDOWN = 0x8,
  21. #endif
  22. SBI_EXT_BASE = 0x10,
  23. SBI_EXT_TIME = 0x54494D45,
  24. SBI_EXT_IPI = 0x735049,
  25. SBI_EXT_RFENCE = 0x52464E43,
  26. SBI_EXT_HSM = 0x48534D,
  27. };
  28. enum sbi_ext_base_fid {
  29. SBI_EXT_BASE_GET_SPEC_VERSION = 0,
  30. SBI_EXT_BASE_GET_IMP_ID,
  31. SBI_EXT_BASE_GET_IMP_VERSION,
  32. SBI_EXT_BASE_PROBE_EXT,
  33. SBI_EXT_BASE_GET_MVENDORID,
  34. SBI_EXT_BASE_GET_MARCHID,
  35. SBI_EXT_BASE_GET_MIMPID,
  36. };
  37. enum sbi_ext_time_fid {
  38. SBI_EXT_TIME_SET_TIMER = 0,
  39. };
  40. enum sbi_ext_ipi_fid {
  41. SBI_EXT_IPI_SEND_IPI = 0,
  42. };
  43. enum sbi_ext_rfence_fid {
  44. SBI_EXT_RFENCE_REMOTE_FENCE_I = 0,
  45. SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
  46. SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
  47. SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
  48. SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
  49. SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
  50. SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
  51. };
  52. enum sbi_ext_hsm_fid {
  53. SBI_EXT_HSM_HART_START = 0,
  54. SBI_EXT_HSM_HART_STOP,
  55. SBI_EXT_HSM_HART_STATUS,
  56. };
  57. enum sbi_hsm_hart_status {
  58. SBI_HSM_HART_STATUS_STARTED = 0,
  59. SBI_HSM_HART_STATUS_STOPPED,
  60. SBI_HSM_HART_STATUS_START_PENDING,
  61. SBI_HSM_HART_STATUS_STOP_PENDING,
  62. };
  63. #define SBI_SPEC_VERSION_DEFAULT 0x1
  64. #define SBI_SPEC_VERSION_MAJOR_SHIFT 24
  65. #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
  66. #define SBI_SPEC_VERSION_MINOR_MASK 0xffffff
  67. /* SBI return error codes */
  68. #define SBI_SUCCESS 0
  69. #define SBI_ERR_FAILURE -1
  70. #define SBI_ERR_NOT_SUPPORTED -2
  71. #define SBI_ERR_INVALID_PARAM -3
  72. #define SBI_ERR_DENIED -4
  73. #define SBI_ERR_INVALID_ADDRESS -5
  74. extern unsigned long sbi_spec_version;
  75. struct sbiret {
  76. long error;
  77. long value;
  78. };
  79. int sbi_init(void);
  80. struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
  81. unsigned long arg1, unsigned long arg2,
  82. unsigned long arg3, unsigned long arg4,
  83. unsigned long arg5);
  84. void sbi_console_putchar(int ch);
  85. int sbi_console_getchar(void);
  86. long sbi_get_mvendorid(void);
  87. long sbi_get_marchid(void);
  88. long sbi_get_mimpid(void);
  89. void sbi_set_timer(uint64_t stime_value);
  90. void sbi_shutdown(void);
  91. void sbi_clear_ipi(void);
  92. void sbi_send_ipi(const unsigned long *hart_mask);
  93. void sbi_remote_fence_i(const unsigned long *hart_mask);
  94. void sbi_remote_sfence_vma(const unsigned long *hart_mask,
  95. unsigned long start,
  96. unsigned long size);
  97. void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
  98. unsigned long start,
  99. unsigned long size,
  100. unsigned long asid);
  101. int sbi_remote_hfence_gvma(const unsigned long *hart_mask,
  102. unsigned long start,
  103. unsigned long size);
  104. int sbi_remote_hfence_gvma_vmid(const unsigned long *hart_mask,
  105. unsigned long start,
  106. unsigned long size,
  107. unsigned long vmid);
  108. int sbi_remote_hfence_vvma(const unsigned long *hart_mask,
  109. unsigned long start,
  110. unsigned long size);
  111. int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
  112. unsigned long start,
  113. unsigned long size,
  114. unsigned long asid);
  115. int sbi_probe_extension(int ext);
  116. /* Check if current SBI specification version is 0.1 or not */
  117. static inline int sbi_spec_is_0_1(void)
  118. {
  119. return (sbi_spec_version == SBI_SPEC_VERSION_DEFAULT) ? 1 : 0;
  120. }
  121. /* Get the major version of SBI */
  122. static inline unsigned long sbi_major_version(void)
  123. {
  124. return (sbi_spec_version >> SBI_SPEC_VERSION_MAJOR_SHIFT) &
  125. SBI_SPEC_VERSION_MAJOR_MASK;
  126. }
  127. /* Get the minor version of SBI */
  128. static inline unsigned long sbi_minor_version(void)
  129. {
  130. return sbi_spec_version & SBI_SPEC_VERSION_MINOR_MASK;
  131. }
  132. int sbi_err_map_linux_errno(int err);
  133. #else /* CONFIG_RISCV_SBI */
  134. /* stubs for code that is only reachable under IS_ENABLED(CONFIG_RISCV_SBI): */
  135. void sbi_set_timer(uint64_t stime_value);
  136. void sbi_clear_ipi(void);
  137. void sbi_send_ipi(const unsigned long *hart_mask);
  138. void sbi_remote_fence_i(const unsigned long *hart_mask);
  139. void sbi_init(void);
  140. #endif /* CONFIG_RISCV_SBI */
  141. #endif /* _ASM_RISCV_SBI_H */