blob: 2bbfd6bada9396693eaa07c4ee69decfe311acd6 [file] [log] [blame]
Thomas Gleixner50acfb22019-05-29 07:18:00 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -07002/*
3 * Copyright (C) 2015 Regents of the University of California
Atish Patra84469232020-03-17 18:11:34 -07004 * Copyright (c) 2020 Western Digital Corporation or its affiliates.
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -07005 */
6
7#ifndef _ASM_RISCV_SBI_H
8#define _ASM_RISCV_SBI_H
9
10#include <linux/types.h>
11
Christoph Hellwig3b03ac62019-10-28 13:10:34 +010012#ifdef CONFIG_RISCV_SBI
Atish Patrab9dcd9e2020-03-17 18:11:35 -070013enum sbi_ext_id {
Atish Patraefca1392020-03-17 18:11:37 -070014#ifdef CONFIG_RISCV_SBI_V01
Atish Patrab9dcd9e2020-03-17 18:11:35 -070015 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,
Atish Patraefca1392020-03-17 18:11:37 -070024#endif
Atish Patrab9dcd9e2020-03-17 18:11:35 -070025 SBI_EXT_BASE = 0x10,
Atish Patraecbacc22020-03-17 18:11:36 -070026 SBI_EXT_TIME = 0x54494D45,
27 SBI_EXT_IPI = 0x735049,
28 SBI_EXT_RFENCE = 0x52464E43,
Atish Patrab9dcd9e2020-03-17 18:11:35 -070029};
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -070030
Atish Patrab9dcd9e2020-03-17 18:11:35 -070031enum sbi_ext_base_fid {
32 SBI_EXT_BASE_GET_SPEC_VERSION = 0,
33 SBI_EXT_BASE_GET_IMP_ID,
34 SBI_EXT_BASE_GET_IMP_VERSION,
35 SBI_EXT_BASE_PROBE_EXT,
36 SBI_EXT_BASE_GET_MVENDORID,
37 SBI_EXT_BASE_GET_MARCHID,
38 SBI_EXT_BASE_GET_MIMPID,
39};
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -070040
Atish Patraecbacc22020-03-17 18:11:36 -070041enum sbi_ext_time_fid {
42 SBI_EXT_TIME_SET_TIMER = 0,
43};
44
45enum sbi_ext_ipi_fid {
46 SBI_EXT_IPI_SEND_IPI = 0,
47};
48
49enum sbi_ext_rfence_fid {
50 SBI_EXT_RFENCE_REMOTE_FENCE_I = 0,
51 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
52 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
53 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
54 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
55 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
56 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
57};
58
Atish Patrab9dcd9e2020-03-17 18:11:35 -070059#define SBI_SPEC_VERSION_DEFAULT 0x1
60#define SBI_SPEC_VERSION_MAJOR_SHIFT 24
61#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
62#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -070063
Atish Patrab9dcd9e2020-03-17 18:11:35 -070064/* SBI return error codes */
65#define SBI_SUCCESS 0
66#define SBI_ERR_FAILURE -1
67#define SBI_ERR_NOT_SUPPORTED -2
68#define SBI_ERR_INVALID_PARAM -3
69#define SBI_ERR_DENIED -4
70#define SBI_ERR_INVALID_ADDRESS -5
71
72extern unsigned long sbi_spec_version;
73struct sbiret {
74 long error;
75 long value;
76};
77
78int sbi_init(void);
79struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
80 unsigned long arg1, unsigned long arg2,
81 unsigned long arg3, unsigned long arg4,
82 unsigned long arg5);
83
84void sbi_console_putchar(int ch);
85int sbi_console_getchar(void);
86void sbi_set_timer(uint64_t stime_value);
87void sbi_shutdown(void);
88void sbi_clear_ipi(void);
89void sbi_send_ipi(const unsigned long *hart_mask);
90void sbi_remote_fence_i(const unsigned long *hart_mask);
91void sbi_remote_sfence_vma(const unsigned long *hart_mask,
92 unsigned long start,
93 unsigned long size);
94
95void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
96 unsigned long start,
97 unsigned long size,
98 unsigned long asid);
Atish Patra1ef46c22020-03-17 18:11:38 -070099int sbi_remote_hfence_gvma(const unsigned long *hart_mask,
100 unsigned long start,
101 unsigned long size);
102int sbi_remote_hfence_gvma_vmid(const unsigned long *hart_mask,
103 unsigned long start,
104 unsigned long size,
105 unsigned long vmid);
106int sbi_remote_hfence_vvma(const unsigned long *hart_mask,
107 unsigned long start,
108 unsigned long size);
109int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
110 unsigned long start,
111 unsigned long size,
112 unsigned long asid);
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700113int sbi_probe_extension(int ext);
114
115/* Check if current SBI specification version is 0.1 or not */
116static inline int sbi_spec_is_0_1(void)
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700117{
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700118 return (sbi_spec_version == SBI_SPEC_VERSION_DEFAULT) ? 1 : 0;
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700119}
120
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700121/* Get the major version of SBI */
122static inline unsigned long sbi_major_version(void)
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700123{
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700124 return (sbi_spec_version >> SBI_SPEC_VERSION_MAJOR_SHIFT) &
125 SBI_SPEC_VERSION_MAJOR_MASK;
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700126}
127
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700128/* Get the minor version of SBI */
129static inline unsigned long sbi_minor_version(void)
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700130{
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700131 return sbi_spec_version & SBI_SPEC_VERSION_MINOR_MASK;
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700132}
Atish Patraf90b43c2020-03-17 18:11:41 -0700133
134int sbi_err_map_linux_errno(int err);
Christoph Hellwig8bf90f32019-10-28 13:10:36 +0100135#else /* CONFIG_RISCV_SBI */
Christoph Hellwig4f9bbce2019-10-28 13:10:37 +0100136/* stubs for code that is only reachable under IS_ENABLED(CONFIG_RISCV_SBI): */
137void sbi_set_timer(uint64_t stime_value);
Christoph Hellwigfcdc6532019-10-28 13:10:38 +0100138void sbi_clear_ipi(void);
139void sbi_send_ipi(const unsigned long *hart_mask);
Christoph Hellwig8bf90f32019-10-28 13:10:36 +0100140void sbi_remote_fence_i(const unsigned long *hart_mask);
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700141void sbi_init(void);
Christoph Hellwig3b03ac62019-10-28 13:10:34 +0100142#endif /* CONFIG_RISCV_SBI */
143#endif /* _ASM_RISCV_SBI_H */