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> |
| 11 | |
Christoph Hellwig | 3b03ac6 | 2019-10-28 13:10:34 +0100 | [diff] [blame] | 12 | #ifdef CONFIG_RISCV_SBI |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 13 | enum sbi_ext_id { |
Atish Patra | efca139 | 2020-03-17 18:11:37 -0700 | [diff] [blame] | 14 | #ifdef CONFIG_RISCV_SBI_V01 |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 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, |
Atish Patra | efca139 | 2020-03-17 18:11:37 -0700 | [diff] [blame] | 24 | #endif |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 25 | SBI_EXT_BASE = 0x10, |
Atish Patra | ecbacc2 | 2020-03-17 18:11:36 -0700 | [diff] [blame] | 26 | SBI_EXT_TIME = 0x54494D45, |
| 27 | SBI_EXT_IPI = 0x735049, |
| 28 | SBI_EXT_RFENCE = 0x52464E43, |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 29 | }; |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 30 | |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 31 | enum sbi_ext_base_fid { |
| 32 | SBI_EXT_BASE_GET_SPEC_VERSION = 0, |
| 33 | SBI_EXT_BASE_GET_IMP_ID, |
| 34 | SBI_EXT_BASE_GET_IMP_VERSION, |
| 35 | SBI_EXT_BASE_PROBE_EXT, |
| 36 | SBI_EXT_BASE_GET_MVENDORID, |
| 37 | SBI_EXT_BASE_GET_MARCHID, |
| 38 | SBI_EXT_BASE_GET_MIMPID, |
| 39 | }; |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 40 | |
Atish Patra | ecbacc2 | 2020-03-17 18:11:36 -0700 | [diff] [blame] | 41 | enum sbi_ext_time_fid { |
| 42 | SBI_EXT_TIME_SET_TIMER = 0, |
| 43 | }; |
| 44 | |
| 45 | enum sbi_ext_ipi_fid { |
| 46 | SBI_EXT_IPI_SEND_IPI = 0, |
| 47 | }; |
| 48 | |
| 49 | enum sbi_ext_rfence_fid { |
| 50 | SBI_EXT_RFENCE_REMOTE_FENCE_I = 0, |
| 51 | SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, |
| 52 | SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, |
| 53 | SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA, |
| 54 | SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID, |
| 55 | SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA, |
| 56 | SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID, |
| 57 | }; |
| 58 | |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 59 | #define SBI_SPEC_VERSION_DEFAULT 0x1 |
| 60 | #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 |
| 61 | #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f |
| 62 | #define SBI_SPEC_VERSION_MINOR_MASK 0xffffff |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 63 | |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 64 | /* SBI return error codes */ |
| 65 | #define SBI_SUCCESS 0 |
| 66 | #define SBI_ERR_FAILURE -1 |
| 67 | #define SBI_ERR_NOT_SUPPORTED -2 |
| 68 | #define SBI_ERR_INVALID_PARAM -3 |
| 69 | #define SBI_ERR_DENIED -4 |
| 70 | #define SBI_ERR_INVALID_ADDRESS -5 |
| 71 | |
| 72 | extern unsigned long sbi_spec_version; |
| 73 | struct sbiret { |
| 74 | long error; |
| 75 | long value; |
| 76 | }; |
| 77 | |
| 78 | int sbi_init(void); |
| 79 | struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, |
| 80 | unsigned long arg1, unsigned long arg2, |
| 81 | unsigned long arg3, unsigned long arg4, |
| 82 | unsigned long arg5); |
| 83 | |
| 84 | void sbi_console_putchar(int ch); |
| 85 | int sbi_console_getchar(void); |
| 86 | void sbi_set_timer(uint64_t stime_value); |
| 87 | void sbi_shutdown(void); |
| 88 | void sbi_clear_ipi(void); |
| 89 | void sbi_send_ipi(const unsigned long *hart_mask); |
| 90 | void sbi_remote_fence_i(const unsigned long *hart_mask); |
| 91 | void sbi_remote_sfence_vma(const unsigned long *hart_mask, |
| 92 | unsigned long start, |
| 93 | unsigned long size); |
| 94 | |
| 95 | void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, |
| 96 | unsigned long start, |
| 97 | unsigned long size, |
| 98 | unsigned long asid); |
Atish Patra | 1ef46c2 | 2020-03-17 18:11:38 -0700 | [diff] [blame] | 99 | int sbi_remote_hfence_gvma(const unsigned long *hart_mask, |
| 100 | unsigned long start, |
| 101 | unsigned long size); |
| 102 | int sbi_remote_hfence_gvma_vmid(const unsigned long *hart_mask, |
| 103 | unsigned long start, |
| 104 | unsigned long size, |
| 105 | unsigned long vmid); |
| 106 | int sbi_remote_hfence_vvma(const unsigned long *hart_mask, |
| 107 | unsigned long start, |
| 108 | unsigned long size); |
| 109 | int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask, |
| 110 | unsigned long start, |
| 111 | unsigned long size, |
| 112 | unsigned long asid); |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 113 | int sbi_probe_extension(int ext); |
| 114 | |
| 115 | /* Check if current SBI specification version is 0.1 or not */ |
| 116 | static inline int sbi_spec_is_0_1(void) |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 117 | { |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 118 | return (sbi_spec_version == SBI_SPEC_VERSION_DEFAULT) ? 1 : 0; |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 121 | /* Get the major version of SBI */ |
| 122 | static inline unsigned long sbi_major_version(void) |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 123 | { |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 124 | return (sbi_spec_version >> SBI_SPEC_VERSION_MAJOR_SHIFT) & |
| 125 | SBI_SPEC_VERSION_MAJOR_MASK; |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 128 | /* Get the minor version of SBI */ |
| 129 | static inline unsigned long sbi_minor_version(void) |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 130 | { |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 131 | return sbi_spec_version & SBI_SPEC_VERSION_MINOR_MASK; |
Palmer Dabbelt | 6d60b6e | 2017-07-10 18:05:09 -0700 | [diff] [blame] | 132 | } |
Atish Patra | f90b43c | 2020-03-17 18:11:41 -0700 | [diff] [blame^] | 133 | |
| 134 | int sbi_err_map_linux_errno(int err); |
Christoph Hellwig | 8bf90f3 | 2019-10-28 13:10:36 +0100 | [diff] [blame] | 135 | #else /* CONFIG_RISCV_SBI */ |
Christoph Hellwig | 4f9bbce | 2019-10-28 13:10:37 +0100 | [diff] [blame] | 136 | /* stubs for code that is only reachable under IS_ENABLED(CONFIG_RISCV_SBI): */ |
| 137 | void sbi_set_timer(uint64_t stime_value); |
Christoph Hellwig | fcdc653 | 2019-10-28 13:10:38 +0100 | [diff] [blame] | 138 | void sbi_clear_ipi(void); |
| 139 | void sbi_send_ipi(const unsigned long *hart_mask); |
Christoph Hellwig | 8bf90f3 | 2019-10-28 13:10:36 +0100 | [diff] [blame] | 140 | void sbi_remote_fence_i(const unsigned long *hart_mask); |
Atish Patra | b9dcd9e | 2020-03-17 18:11:35 -0700 | [diff] [blame] | 141 | void sbi_init(void); |
Christoph Hellwig | 3b03ac6 | 2019-10-28 13:10:34 +0100 | [diff] [blame] | 142 | #endif /* CONFIG_RISCV_SBI */ |
| 143 | #endif /* _ASM_RISCV_SBI_H */ |