Lukas Auer | 34a0626 | 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 | 215c3a7 | 2020-03-09 19:35:27 -0700 | [diff] [blame] | 4 | * Copyright (c) 2020 Western Digital Corporation or its affiliates. |
Lukas Auer | 34a0626 | 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 | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 14 | enum sbi_ext_id { |
Bin Meng | 1b3c8d6 | 2020-03-09 19:35:30 -0700 | [diff] [blame] | 15 | #ifdef CONFIG_SBI_V01 |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -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, |
Bin Meng | 1b3c8d6 | 2020-03-09 19:35:30 -0700 | [diff] [blame] | 25 | #endif |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 26 | SBI_EXT_BASE = 0x10, |
Bin Meng | 1e32715 | 2020-03-09 19:35:29 -0700 | [diff] [blame] | 27 | SBI_EXT_TIME = 0x54494D45, |
| 28 | SBI_EXT_IPI = 0x735049, |
| 29 | SBI_EXT_RFENCE = 0x52464E43, |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 30 | }; |
Lukas Auer | 34a0626 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 31 | |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 32 | enum sbi_ext_base_fid { |
| 33 | SBI_EXT_BASE_GET_SPEC_VERSION = 0, |
| 34 | SBI_EXT_BASE_GET_IMP_ID, |
| 35 | SBI_EXT_BASE_GET_IMP_VERSION, |
| 36 | SBI_EXT_BASE_PROBE_EXT, |
| 37 | SBI_EXT_BASE_GET_MVENDORID, |
| 38 | SBI_EXT_BASE_GET_MARCHID, |
| 39 | SBI_EXT_BASE_GET_MIMPID, |
| 40 | }; |
Lukas Auer | 34a0626 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 41 | |
Bin Meng | 1e32715 | 2020-03-09 19:35:29 -0700 | [diff] [blame] | 42 | enum sbi_ext_time_fid { |
| 43 | SBI_EXT_TIME_SET_TIMER = 0, |
| 44 | }; |
| 45 | |
| 46 | enum sbi_ext_ipi_fid { |
| 47 | SBI_EXT_IPI_SEND_IPI = 0, |
| 48 | }; |
| 49 | |
| 50 | enum sbi_ext_rfence_fid { |
| 51 | SBI_EXT_RFENCE_REMOTE_FENCE_I = 0, |
| 52 | SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, |
| 53 | SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, |
| 54 | }; |
| 55 | |
Bin Meng | 5bde215 | 2020-03-09 19:35:31 -0700 | [diff] [blame] | 56 | #ifdef CONFIG_SBI_V01 |
| 57 | #define SBI_EXT_SET_TIMER SBI_EXT_0_1_SET_TIMER |
| 58 | #define SBI_FID_SET_TIMER 0 |
| 59 | #define SBI_EXT_SEND_IPI SBI_EXT_0_1_SEND_IPI |
| 60 | #define SBI_FID_SEND_IPI 0 |
| 61 | #define SBI_EXT_REMOTE_FENCE_I SBI_EXT_0_1_REMOTE_FENCE_I |
| 62 | #define SBI_FID_REMOTE_FENCE_I 0 |
| 63 | #define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_0_1_REMOTE_SFENCE_VMA |
| 64 | #define SBI_FID_REMOTE_SFENCE_VMA 0 |
| 65 | #define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID |
| 66 | #define SBI_FID_REMOTE_SFENCE_VMA_ASID 0 |
| 67 | #else |
| 68 | #define SBI_EXT_SET_TIMER SBI_EXT_TIME |
| 69 | #define SBI_FID_SET_TIMER SBI_EXT_TIME_SET_TIMER |
| 70 | #define SBI_EXT_SEND_IPI SBI_EXT_IPI |
| 71 | #define SBI_FID_SEND_IPI SBI_EXT_IPI_SEND_IPI |
| 72 | #define SBI_EXT_REMOTE_FENCE_I SBI_EXT_RFENCE |
| 73 | #define SBI_FID_REMOTE_FENCE_I SBI_EXT_RFENCE_REMOTE_FENCE_I |
| 74 | #define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_RFENCE |
| 75 | #define SBI_FID_REMOTE_SFENCE_VMA SBI_EXT_RFENCE_REMOTE_SFENCE_VMA |
| 76 | #define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE |
| 77 | #define SBI_FID_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID |
| 78 | #endif |
| 79 | |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 80 | #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 |
| 81 | #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f |
| 82 | #define SBI_SPEC_VERSION_MINOR_MASK 0xffffff |
Lukas Auer | 34a0626 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 83 | |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 84 | /* SBI return error codes */ |
| 85 | #define SBI_SUCCESS 0 |
| 86 | #define SBI_ERR_FAILURE -1 |
| 87 | #define SBI_ERR_NOT_SUPPORTED -2 |
| 88 | #define SBI_ERR_INVALID_PARAM -3 |
| 89 | #define SBI_ERR_DENIED -4 |
| 90 | #define SBI_ERR_INVALID_ADDRESS -5 |
Lukas Auer | 34a0626 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 91 | |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 92 | struct sbiret { |
| 93 | long error; |
| 94 | long value; |
| 95 | }; |
Lukas Auer | 34a0626 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 96 | |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 97 | struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, |
| 98 | unsigned long arg1, unsigned long arg2, |
| 99 | unsigned long arg3, unsigned long arg4, |
| 100 | unsigned long arg5); |
Lukas Auer | 34a0626 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 101 | |
Bin Meng | 1b3c8d6 | 2020-03-09 19:35:30 -0700 | [diff] [blame] | 102 | #ifdef CONFIG_SBI_V01 |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 103 | void sbi_console_putchar(int ch); |
| 104 | int sbi_console_getchar(void); |
| 105 | void sbi_clear_ipi(void); |
| 106 | void sbi_shutdown(void); |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 107 | void sbi_send_ipi(const unsigned long *hart_mask); |
| 108 | void sbi_remote_fence_i(const unsigned long *hart_mask); |
| 109 | void sbi_remote_sfence_vma(const unsigned long *hart_mask, |
| 110 | unsigned long start, |
| 111 | unsigned long size); |
| 112 | void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, |
| 113 | unsigned long start, |
| 114 | unsigned long size, |
| 115 | unsigned long asid); |
Atish Patra | 7e249bc | 2020-04-21 14:51:57 -0700 | [diff] [blame] | 116 | #endif |
| 117 | void sbi_set_timer(uint64_t stime_value); |
Heinrich Schuchardt | c92b50a | 2020-08-20 19:43:39 +0200 | [diff] [blame] | 118 | long sbi_get_spec_version(void); |
| 119 | int sbi_get_impl_id(void); |
Bin Meng | f58fc34 | 2020-03-09 19:35:28 -0700 | [diff] [blame] | 120 | int sbi_probe_extension(int ext); |
Lukas Auer | 34a0626 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 121 | |
| 122 | #endif |