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 7 #ifndef _ASM_RISCV_SBI_H 8 #define _ASM_RISCV_SBI_H 9 10 #include <linux/types.h> 11 12 #ifdef CONFIG_RISCV_SBI 13 enum sbi_ext_id { 14 #ifdef CONFIG_RISCV_SBI_V01 15 SBI_EXT_0_1_SET_TIMER = 0x0, 16 SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, 17 SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, 18 SBI_EXT_0_1_CLEAR_IPI = 0x3, 19 SBI_EXT_0_1_SEND_IPI = 0x4, 20 SBI_EXT_0_1_REMOTE_FENCE_I = 0x5, 21 SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6, 22 SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7, 23 SBI_EXT_0_1_SHUTDOWN = 0x8, 24 #endif 25 SBI_EXT_BASE = 0x10, 26 SBI_EXT_TIME = 0x54494D45, 27 SBI_EXT_IPI = 0x735049, 28 SBI_EXT_RFENCE = 0x52464E43, 29 SBI_EXT_HSM = 0x48534D, 30 SBI_EXT_SRST = 0x53525354, 31 32 /* Experimentals extensions must lie within this range */ 33 SBI_EXT_EXPERIMENTAL_START = 0x08000000, 34 SBI_EXT_EXPERIMENTAL_END = 0x08FFFFFF, 35 36 /* Vendor extensions must lie within this range */ 37 SBI_EXT_VENDOR_START = 0x09000000, 38 SBI_EXT_VENDOR_END = 0x09FFFFFF, 39 }; 40 41 enum sbi_ext_base_fid { 42 SBI_EXT_BASE_GET_SPEC_VERSION = 0, 43 SBI_EXT_BASE_GET_IMP_ID, 44 SBI_EXT_BASE_GET_IMP_VERSION, 45 SBI_EXT_BASE_PROBE_EXT, 46 SBI_EXT_BASE_GET_MVENDORID, 47 SBI_EXT_BASE_GET_MARCHID, 48 SBI_EXT_BASE_GET_MIMPID, 49 }; 50 51 enum sbi_ext_time_fid { 52 SBI_EXT_TIME_SET_TIMER = 0, 53 }; 54 55 enum sbi_ext_ipi_fid { 56 SBI_EXT_IPI_SEND_IPI = 0, 57 }; 58 59 enum sbi_ext_rfence_fid { 60 SBI_EXT_RFENCE_REMOTE_FENCE_I = 0, 61 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, 62 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, 63 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID, 64 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA, 65 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID, 66 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA, 67 }; 68 69 enum sbi_ext_hsm_fid { 70 SBI_EXT_HSM_HART_START = 0, 71 SBI_EXT_HSM_HART_STOP, 72 SBI_EXT_HSM_HART_STATUS, 73 }; 74 75 enum sbi_hsm_hart_status { 76 SBI_HSM_HART_STATUS_STARTED = 0, 77 SBI_HSM_HART_STATUS_STOPPED, 78 SBI_HSM_HART_STATUS_START_PENDING, 79 SBI_HSM_HART_STATUS_STOP_PENDING, 80 }; 81 82 enum sbi_ext_srst_fid { 83 SBI_EXT_SRST_RESET = 0, 84 }; 85 86 enum sbi_srst_reset_type { 87 SBI_SRST_RESET_TYPE_SHUTDOWN = 0, 88 SBI_SRST_RESET_TYPE_COLD_REBOOT, 89 SBI_SRST_RESET_TYPE_WARM_REBOOT, 90 }; 91 92 enum sbi_srst_reset_reason { 93 SBI_SRST_RESET_REASON_NONE = 0, 94 SBI_SRST_RESET_REASON_SYS_FAILURE, 95 }; 96 97 #define SBI_SPEC_VERSION_DEFAULT 0x1 98 #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 99 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f 100 #define SBI_SPEC_VERSION_MINOR_MASK 0xffffff 101 102 /* SBI return error codes */ 103 #define SBI_SUCCESS 0 104 #define SBI_ERR_FAILURE -1 105 #define SBI_ERR_NOT_SUPPORTED -2 106 #define SBI_ERR_INVALID_PARAM -3 107 #define SBI_ERR_DENIED -4 108 #define SBI_ERR_INVALID_ADDRESS -5 109 #define SBI_ERR_ALREADY_AVAILABLE -6 110 111 extern unsigned long sbi_spec_version; 112 struct sbiret { 113 long error; 114 long value; 115 }; 116 117 void sbi_init(void); 118 struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, 119 unsigned long arg1, unsigned long arg2, 120 unsigned long arg3, unsigned long arg4, 121 unsigned long arg5); 122 123 void sbi_console_putchar(int ch); 124 int sbi_console_getchar(void); 125 long sbi_get_mvendorid(void); 126 long sbi_get_marchid(void); 127 long sbi_get_mimpid(void); 128 void sbi_set_timer(uint64_t stime_value); 129 void sbi_shutdown(void); 130 void sbi_clear_ipi(void); 131 int sbi_send_ipi(const unsigned long *hart_mask); 132 int sbi_remote_fence_i(const unsigned long *hart_mask); 133 int sbi_remote_sfence_vma(const unsigned long *hart_mask, 134 unsigned long start, 135 unsigned long size); 136 137 int sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, 138 unsigned long start, 139 unsigned long size, 140 unsigned long asid); 141 int sbi_remote_hfence_gvma(const unsigned long *hart_mask, 142 unsigned long start, 143 unsigned long size); 144 int sbi_remote_hfence_gvma_vmid(const unsigned long *hart_mask, 145 unsigned long start, 146 unsigned long size, 147 unsigned long vmid); 148 int sbi_remote_hfence_vvma(const unsigned long *hart_mask, 149 unsigned long start, 150 unsigned long size); 151 int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask, 152 unsigned long start, 153 unsigned long size, 154 unsigned long asid); 155 int sbi_probe_extension(int ext); 156 157 /* Check if current SBI specification version is 0.1 or not */ 158 static inline int sbi_spec_is_0_1(void) 159 { 160 return (sbi_spec_version == SBI_SPEC_VERSION_DEFAULT) ? 1 : 0; 161 } 162 163 /* Get the major version of SBI */ 164 static inline unsigned long sbi_major_version(void) 165 { 166 return (sbi_spec_version >> SBI_SPEC_VERSION_MAJOR_SHIFT) & 167 SBI_SPEC_VERSION_MAJOR_MASK; 168 } 169 170 /* Get the minor version of SBI */ 171 static inline unsigned long sbi_minor_version(void) 172 { 173 return sbi_spec_version & SBI_SPEC_VERSION_MINOR_MASK; 174 } 175 176 /* Make SBI version */ 177 static inline unsigned long sbi_mk_version(unsigned long major, 178 unsigned long minor) 179 { 180 return ((major & SBI_SPEC_VERSION_MAJOR_MASK) << 181 SBI_SPEC_VERSION_MAJOR_SHIFT) | minor; 182 } 183 184 int sbi_err_map_linux_errno(int err); 185 #else /* CONFIG_RISCV_SBI */ 186 static inline int sbi_remote_fence_i(const unsigned long *hart_mask) { return -1; } 187 static inline void sbi_init(void) {} 188 #endif /* CONFIG_RISCV_SBI */ 189 #endif /* _ASM_RISCV_SBI_H */ 190