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