Lukas Auer | 9c03845 | 2019-03-17 19:28:33 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (C) 2015 Regents of the University of California |
| 4 | * |
| 5 | * Taken from Linux arch/riscv/include/asm/sbi.h |
| 6 | */ |
| 7 | |
| 8 | #ifndef _ASM_RISCV_SBI_H |
| 9 | #define _ASM_RISCV_SBI_H |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | |
| 13 | #define SBI_SET_TIMER 0 |
| 14 | #define SBI_CONSOLE_PUTCHAR 1 |
| 15 | #define SBI_CONSOLE_GETCHAR 2 |
| 16 | #define SBI_CLEAR_IPI 3 |
| 17 | #define SBI_SEND_IPI 4 |
| 18 | #define SBI_REMOTE_FENCE_I 5 |
| 19 | #define SBI_REMOTE_SFENCE_VMA 6 |
| 20 | #define SBI_REMOTE_SFENCE_VMA_ASID 7 |
| 21 | #define SBI_SHUTDOWN 8 |
| 22 | |
| 23 | #define SBI_CALL(which, arg0, arg1, arg2) ({ \ |
| 24 | register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \ |
| 25 | register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \ |
| 26 | register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \ |
| 27 | register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \ |
| 28 | asm volatile ("ecall" \ |
| 29 | : "+r" (a0) \ |
| 30 | : "r" (a1), "r" (a2), "r" (a7) \ |
| 31 | : "memory"); \ |
| 32 | a0; \ |
| 33 | }) |
| 34 | |
| 35 | /* Lazy implementations until SBI is finalized */ |
| 36 | #define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0) |
| 37 | #define SBI_CALL_1(which, arg0) SBI_CALL(which, arg0, 0, 0) |
| 38 | #define SBI_CALL_2(which, arg0, arg1) SBI_CALL(which, arg0, arg1, 0) |
| 39 | |
| 40 | static inline void sbi_console_putchar(int ch) |
| 41 | { |
| 42 | SBI_CALL_1(SBI_CONSOLE_PUTCHAR, ch); |
| 43 | } |
| 44 | |
| 45 | static inline int sbi_console_getchar(void) |
| 46 | { |
| 47 | return SBI_CALL_0(SBI_CONSOLE_GETCHAR); |
| 48 | } |
| 49 | |
| 50 | static inline void sbi_set_timer(uint64_t stime_value) |
| 51 | { |
| 52 | #if __riscv_xlen == 32 |
| 53 | SBI_CALL_2(SBI_SET_TIMER, stime_value, stime_value >> 32); |
| 54 | #else |
| 55 | SBI_CALL_1(SBI_SET_TIMER, stime_value); |
| 56 | #endif |
| 57 | } |
| 58 | |
| 59 | static inline void sbi_shutdown(void) |
| 60 | { |
| 61 | SBI_CALL_0(SBI_SHUTDOWN); |
| 62 | } |
| 63 | |
| 64 | static inline void sbi_clear_ipi(void) |
| 65 | { |
| 66 | SBI_CALL_0(SBI_CLEAR_IPI); |
| 67 | } |
| 68 | |
| 69 | static inline void sbi_send_ipi(const unsigned long *hart_mask) |
| 70 | { |
| 71 | SBI_CALL_1(SBI_SEND_IPI, hart_mask); |
| 72 | } |
| 73 | |
| 74 | static inline void sbi_remote_fence_i(const unsigned long *hart_mask) |
| 75 | { |
| 76 | SBI_CALL_1(SBI_REMOTE_FENCE_I, hart_mask); |
| 77 | } |
| 78 | |
| 79 | static inline void sbi_remote_sfence_vma(const unsigned long *hart_mask, |
| 80 | unsigned long start, |
| 81 | unsigned long size) |
| 82 | { |
| 83 | SBI_CALL_1(SBI_REMOTE_SFENCE_VMA, hart_mask); |
| 84 | } |
| 85 | |
| 86 | static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, |
| 87 | unsigned long start, |
| 88 | unsigned long size, |
| 89 | unsigned long asid) |
| 90 | { |
| 91 | SBI_CALL_1(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask); |
| 92 | } |
| 93 | |
| 94 | #endif |