Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (C) 2015 Regents of the University of California |
Bin Meng | 9da11d1 | 2020-03-09 19:35:27 -0700 | [diff] [blame] | 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. |
Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 5 | * |
| 6 | * Taken from Linux arch/riscv/include/asm/sbi.h |
| 7 | */ |
| 8 | |
| 9 | #ifndef _ASM_RISCV_SBI_H |
| 10 | #define _ASM_RISCV_SBI_H |
| 11 | |
| 12 | #include <linux/types.h> |
| 13 | |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 14 | enum sbi_ext_id { |
| 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 | SBI_EXT_BASE = 0x10, |
Bin Meng | c20421b | 2020-03-09 19:35:29 -0700 | [diff] [blame] | 25 | SBI_EXT_TIME = 0x54494D45, |
| 26 | SBI_EXT_IPI = 0x735049, |
| 27 | SBI_EXT_RFENCE = 0x52464E43, |
Heinrich Schuchardt | 2d1c651 | 2021-09-12 21:11:44 +0200 | [diff] [blame] | 28 | SBI_EXT_HSM = 0x48534D, |
| 29 | SBI_EXT_SRST = 0x53525354, |
Heinrich Schuchardt | 295e1ce | 2022-03-16 21:21:18 +0100 | [diff] [blame] | 30 | SBI_EXT_PMU = 0x504D55, |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 31 | }; |
Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 32 | |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 33 | enum sbi_ext_base_fid { |
| 34 | SBI_EXT_BASE_GET_SPEC_VERSION = 0, |
| 35 | SBI_EXT_BASE_GET_IMP_ID, |
| 36 | SBI_EXT_BASE_GET_IMP_VERSION, |
| 37 | SBI_EXT_BASE_PROBE_EXT, |
| 38 | SBI_EXT_BASE_GET_MVENDORID, |
| 39 | SBI_EXT_BASE_GET_MARCHID, |
| 40 | SBI_EXT_BASE_GET_MIMPID, |
| 41 | }; |
Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 42 | |
Bin Meng | c20421b | 2020-03-09 19:35:29 -0700 | [diff] [blame] | 43 | enum sbi_ext_time_fid { |
| 44 | SBI_EXT_TIME_SET_TIMER = 0, |
| 45 | }; |
| 46 | |
| 47 | enum sbi_ext_ipi_fid { |
| 48 | SBI_EXT_IPI_SEND_IPI = 0, |
| 49 | }; |
| 50 | |
| 51 | enum sbi_ext_rfence_fid { |
| 52 | SBI_EXT_RFENCE_REMOTE_FENCE_I = 0, |
| 53 | SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, |
| 54 | SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, |
Heinrich Schuchardt | 2d1c651 | 2021-09-12 21:11:44 +0200 | [diff] [blame] | 55 | SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID, |
| 56 | SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA, |
| 57 | SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID, |
| 58 | SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA, |
| 59 | }; |
| 60 | |
| 61 | enum sbi_ext_hsm_fid { |
| 62 | SBI_EXT_HSM_HART_START = 0, |
| 63 | SBI_EXT_HSM_HART_STOP, |
| 64 | SBI_EXT_HSM_HART_STATUS, |
| 65 | SBI_EXT_HSM_HART_SUSPEND, |
| 66 | }; |
| 67 | |
| 68 | enum sbi_hsm_hart_status { |
| 69 | SBI_HSM_HART_STATUS_STARTED = 0, |
| 70 | SBI_HSM_HART_STATUS_STOPPED, |
| 71 | SBI_HSM_HART_STATUS_START_PENDING, |
| 72 | SBI_HSM_HART_STATUS_STOP_PENDING, |
| 73 | SBI_HSM_HART_STATUS_SUSPEND_PENDING, |
| 74 | SBI_HSM_HART_STATUS_RESUME_PENDING, |
| 75 | }; |
| 76 | |
| 77 | enum sbi_ext_srst_fid { |
| 78 | SBI_EXT_SRST_RESET = 0, |
| 79 | }; |
| 80 | |
| 81 | enum sbi_srst_reset_type { |
| 82 | SBI_SRST_RESET_TYPE_SHUTDOWN = 0, |
| 83 | SBI_SRST_RESET_TYPE_COLD_REBOOT, |
| 84 | SBI_SRST_RESET_TYPE_WARM_REBOOT, |
| 85 | }; |
| 86 | |
| 87 | enum sbi_srst_reset_reason { |
| 88 | SBI_SRST_RESET_REASON_NONE = 0, |
| 89 | SBI_SRST_RESET_REASON_SYS_FAILURE, |
Bin Meng | c20421b | 2020-03-09 19:35:29 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Bin Meng | f7e6d33 | 2020-03-09 19:35:31 -0700 | [diff] [blame] | 92 | #ifdef CONFIG_SBI_V01 |
| 93 | #define SBI_EXT_SET_TIMER SBI_EXT_0_1_SET_TIMER |
| 94 | #define SBI_FID_SET_TIMER 0 |
| 95 | #define SBI_EXT_SEND_IPI SBI_EXT_0_1_SEND_IPI |
| 96 | #define SBI_FID_SEND_IPI 0 |
| 97 | #define SBI_EXT_REMOTE_FENCE_I SBI_EXT_0_1_REMOTE_FENCE_I |
| 98 | #define SBI_FID_REMOTE_FENCE_I 0 |
| 99 | #define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_0_1_REMOTE_SFENCE_VMA |
| 100 | #define SBI_FID_REMOTE_SFENCE_VMA 0 |
| 101 | #define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID |
| 102 | #define SBI_FID_REMOTE_SFENCE_VMA_ASID 0 |
| 103 | #else |
| 104 | #define SBI_EXT_SET_TIMER SBI_EXT_TIME |
| 105 | #define SBI_FID_SET_TIMER SBI_EXT_TIME_SET_TIMER |
| 106 | #define SBI_EXT_SEND_IPI SBI_EXT_IPI |
| 107 | #define SBI_FID_SEND_IPI SBI_EXT_IPI_SEND_IPI |
| 108 | #define SBI_EXT_REMOTE_FENCE_I SBI_EXT_RFENCE |
| 109 | #define SBI_FID_REMOTE_FENCE_I SBI_EXT_RFENCE_REMOTE_FENCE_I |
| 110 | #define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_RFENCE |
| 111 | #define SBI_FID_REMOTE_SFENCE_VMA SBI_EXT_RFENCE_REMOTE_SFENCE_VMA |
| 112 | #define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE |
| 113 | #define SBI_FID_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID |
| 114 | #endif |
| 115 | |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 116 | #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 |
| 117 | #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f |
| 118 | #define SBI_SPEC_VERSION_MINOR_MASK 0xffffff |
Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 119 | |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 120 | /* SBI return error codes */ |
| 121 | #define SBI_SUCCESS 0 |
| 122 | #define SBI_ERR_FAILURE -1 |
| 123 | #define SBI_ERR_NOT_SUPPORTED -2 |
| 124 | #define SBI_ERR_INVALID_PARAM -3 |
| 125 | #define SBI_ERR_DENIED -4 |
| 126 | #define SBI_ERR_INVALID_ADDRESS -5 |
Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 127 | |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 128 | struct sbiret { |
| 129 | long error; |
| 130 | long value; |
| 131 | }; |
Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 132 | |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 133 | struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, |
| 134 | unsigned long arg1, unsigned long arg2, |
| 135 | unsigned long arg3, unsigned long arg4, |
| 136 | unsigned long arg5); |
Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 137 | |
Bin Meng | 887d809 | 2020-03-09 19:35:30 -0700 | [diff] [blame] | 138 | #ifdef CONFIG_SBI_V01 |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 139 | void sbi_console_putchar(int ch); |
| 140 | int sbi_console_getchar(void); |
| 141 | void sbi_clear_ipi(void); |
| 142 | void sbi_shutdown(void); |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 143 | void sbi_send_ipi(const unsigned long *hart_mask); |
| 144 | void sbi_remote_fence_i(const unsigned long *hart_mask); |
| 145 | void sbi_remote_sfence_vma(const unsigned long *hart_mask, |
| 146 | unsigned long start, |
| 147 | unsigned long size); |
| 148 | void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, |
| 149 | unsigned long start, |
| 150 | unsigned long size, |
| 151 | unsigned long asid); |
Atish Patra | a7edd07 | 2020-04-21 14:51:57 -0700 | [diff] [blame] | 152 | #endif |
| 153 | void sbi_set_timer(uint64_t stime_value); |
Heinrich Schuchardt | 95492ae | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 154 | long sbi_get_spec_version(void); |
| 155 | int sbi_get_impl_id(void); |
Heinrich Schuchardt | 69c681e | 2021-10-25 15:09:34 +0200 | [diff] [blame] | 156 | int sbi_get_impl_version(long *version); |
Bin Meng | ee3bcd0 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 157 | int sbi_probe_extension(int ext); |
Heinrich Schuchardt | f4b4d75 | 2022-03-17 07:36:14 +0100 | [diff] [blame] | 158 | int sbi_get_mvendorid(long *mvendorid); |
| 159 | int sbi_get_marchid(long *marchid); |
| 160 | int sbi_get_mimpid(long *mimpid); |
Heinrich Schuchardt | cc382ff | 2021-09-12 21:11:46 +0200 | [diff] [blame] | 161 | void sbi_srst_reset(unsigned long type, unsigned long reason); |
Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 162 | |
| 163 | #endif |