riscv: Add SBI v0.2 extension definitions
[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         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,
25         SBI_EXT_TIME = 0x54494D45,
26         SBI_EXT_IPI = 0x735049,
27         SBI_EXT_RFENCE = 0x52464E43,
28 };
29
30 enum sbi_ext_base_fid {
31         SBI_EXT_BASE_GET_SPEC_VERSION = 0,
32         SBI_EXT_BASE_GET_IMP_ID,
33         SBI_EXT_BASE_GET_IMP_VERSION,
34         SBI_EXT_BASE_PROBE_EXT,
35         SBI_EXT_BASE_GET_MVENDORID,
36         SBI_EXT_BASE_GET_MARCHID,
37         SBI_EXT_BASE_GET_MIMPID,
38 };
39
40 enum sbi_ext_time_fid {
41         SBI_EXT_TIME_SET_TIMER = 0,
42 };
43
44 enum sbi_ext_ipi_fid {
45         SBI_EXT_IPI_SEND_IPI = 0,
46 };
47
48 enum sbi_ext_rfence_fid {
49         SBI_EXT_RFENCE_REMOTE_FENCE_I = 0,
50         SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
51         SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
52 };
53
54 #define SBI_SPEC_VERSION_DEFAULT        0x1
55 #define SBI_SPEC_VERSION_MAJOR_SHIFT    24
56 #define SBI_SPEC_VERSION_MAJOR_MASK     0x7f
57 #define SBI_SPEC_VERSION_MINOR_MASK     0xffffff
58
59 /* SBI return error codes */
60 #define SBI_SUCCESS                     0
61 #define SBI_ERR_FAILURE                 -1
62 #define SBI_ERR_NOT_SUPPORTED           -2
63 #define SBI_ERR_INVALID_PARAM           -3
64 #define SBI_ERR_DENIED                  -4
65 #define SBI_ERR_INVALID_ADDRESS         -5
66
67 extern unsigned long sbi_spec_version;
68 struct sbiret {
69         long error;
70         long value;
71 };
72
73 struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
74                         unsigned long arg1, unsigned long arg2,
75                         unsigned long arg3, unsigned long arg4,
76                         unsigned long arg5);
77
78 void sbi_console_putchar(int ch);
79 int sbi_console_getchar(void);
80 void sbi_clear_ipi(void);
81 void sbi_shutdown(void);
82 void sbi_set_timer(uint64_t stime_value);
83 void sbi_send_ipi(const unsigned long *hart_mask);
84 void sbi_remote_fence_i(const unsigned long *hart_mask);
85 void sbi_remote_sfence_vma(const unsigned long *hart_mask,
86                            unsigned long start,
87                            unsigned long size);
88 void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
89                                 unsigned long start,
90                                 unsigned long size,
91                                 unsigned long asid);
92
93 int sbi_probe_extension(int ext);
94
95 #endif