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