c65104f4921ce0d6e8742ded82edcb08dca7d2ed
[oweals/u-boot.git] / arch / riscv / include / asm / sbi.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2015 Regents of the University of California
4  * Copyright (c) 2020 Western Digital Corporation or its affiliates.
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
14 enum sbi_ext_id {
15 #ifdef CONFIG_SBI_V01
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,
25 #endif
26         SBI_EXT_BASE = 0x10,
27         SBI_EXT_TIME = 0x54494D45,
28         SBI_EXT_IPI = 0x735049,
29         SBI_EXT_RFENCE = 0x52464E43,
30 };
31
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 };
41
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
56 #define SBI_SPEC_VERSION_DEFAULT        0x1
57 #define SBI_SPEC_VERSION_MAJOR_SHIFT    24
58 #define SBI_SPEC_VERSION_MAJOR_MASK     0x7f
59 #define SBI_SPEC_VERSION_MINOR_MASK     0xffffff
60
61 /* SBI return error codes */
62 #define SBI_SUCCESS                     0
63 #define SBI_ERR_FAILURE                 -1
64 #define SBI_ERR_NOT_SUPPORTED           -2
65 #define SBI_ERR_INVALID_PARAM           -3
66 #define SBI_ERR_DENIED                  -4
67 #define SBI_ERR_INVALID_ADDRESS         -5
68
69 extern unsigned long sbi_spec_version;
70 struct sbiret {
71         long error;
72         long value;
73 };
74
75 struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
76                         unsigned long arg1, unsigned long arg2,
77                         unsigned long arg3, unsigned long arg4,
78                         unsigned long arg5);
79
80 #ifdef CONFIG_SBI_V01
81 void sbi_console_putchar(int ch);
82 int sbi_console_getchar(void);
83 void sbi_clear_ipi(void);
84 void sbi_shutdown(void);
85 #endif
86 void sbi_set_timer(uint64_t stime_value);
87 void sbi_send_ipi(const unsigned long *hart_mask);
88 void sbi_remote_fence_i(const unsigned long *hart_mask);
89 void sbi_remote_sfence_vma(const unsigned long *hart_mask,
90                            unsigned long start,
91                            unsigned long size);
92 void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
93                                 unsigned long start,
94                                 unsigned long size,
95                                 unsigned long asid);
96
97 int sbi_probe_extension(int ext);
98
99 #endif