1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2015 Regents of the University of California
4 * Copyright (c) 2020 Western Digital Corporation or its affiliates.
6 * Taken from Linux arch/riscv/include/asm/sbi.h
9 #ifndef _ASM_RISCV_SBI_H
10 #define _ASM_RISCV_SBI_H
12 #include <linux/types.h>
14 #define SBI_EXT_0_1_SET_TIMER 0x0
15 #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
16 #define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2
17 #define SBI_EXT_0_1_CLEAR_IPI 0x3
18 #define SBI_EXT_0_1_SEND_IPI 0x4
19 #define SBI_EXT_0_1_REMOTE_FENCE_I 0x5
20 #define SBI_EXT_0_1_REMOTE_SFENCE_VMA 0x6
21 #define SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID 0x7
22 #define SBI_EXT_0_1_SHUTDOWN 0x8
24 #define SBI_CALL(which, arg0, arg1, arg2, arg3) ({ \
25 register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \
26 register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \
27 register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \
28 register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); \
29 register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \
30 asm volatile ("ecall" \
32 : "r" (a1), "r" (a2), "r" (a3), "r" (a7) \
37 /* Lazy implementations until SBI is finalized */
38 #define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0, 0)
39 #define SBI_CALL_1(which, arg0) SBI_CALL(which, arg0, 0, 0, 0)
40 #define SBI_CALL_2(which, arg0, arg1) SBI_CALL(which, arg0, arg1, 0, 0)
41 #define SBI_CALL_3(which, arg0, arg1, arg2) \
42 SBI_CALL(which, arg0, arg1, arg2, 0)
43 #define SBI_CALL_4(which, arg0, arg1, arg2, arg3) \
44 SBI_CALL(which, arg0, arg1, arg2, arg3)
46 static inline void sbi_console_putchar(int ch)
48 SBI_CALL_1(SBI_EXT_0_1_CONSOLE_PUTCHAR, ch);
51 static inline int sbi_console_getchar(void)
53 return SBI_CALL_0(SBI_EXT_0_1_CONSOLE_GETCHAR);
56 static inline void sbi_set_timer(uint64_t stime_value)
58 #if __riscv_xlen == 32
59 SBI_CALL_2(SBI_EXT_0_1_SET_TIMER, stime_value, stime_value >> 32);
61 SBI_CALL_1(SBI_EXT_0_1_SET_TIMER, stime_value);
65 static inline void sbi_shutdown(void)
67 SBI_CALL_0(SBI_EXT_0_1_SHUTDOWN);
70 static inline void sbi_clear_ipi(void)
72 SBI_CALL_0(SBI_EXT_0_1_CLEAR_IPI);
75 static inline void sbi_send_ipi(const unsigned long *hart_mask)
77 SBI_CALL_1(SBI_EXT_0_1_SEND_IPI, hart_mask);
80 static inline void sbi_remote_fence_i(const unsigned long *hart_mask)
82 SBI_CALL_1(SBI_EXT_0_1_REMOTE_FENCE_I, hart_mask);
85 static inline void sbi_remote_sfence_vma(const unsigned long *hart_mask,
89 SBI_CALL_3(SBI_EXT_0_1_REMOTE_SFENCE_VMA, hart_mask, start, size);
92 static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
97 SBI_CALL_4(SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, hart_mask,