blob: d1c37479d828c1754178f0d5252b02ed164060ad [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>
Atish Patra26fb7512022-01-20 01:09:18 -080011#include <linux/cpumask.h>
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -070012
Christoph Hellwig3b03ac62019-10-28 13:10:34 +010013#ifdef CONFIG_RISCV_SBI
Atish Patrab9dcd9e2020-03-17 18:11:35 -070014enum sbi_ext_id {
Atish Patraefca1392020-03-17 18:11:37 -070015#ifdef CONFIG_RISCV_SBI_V01
Atish Patrab9dcd9e2020-03-17 18:11:35 -070016 SBI_EXT_0_1_SET_TIMER = 0x0,
17 SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1,
18 SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2,
19 SBI_EXT_0_1_CLEAR_IPI = 0x3,
20 SBI_EXT_0_1_SEND_IPI = 0x4,
21 SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,
22 SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6,
23 SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7,
24 SBI_EXT_0_1_SHUTDOWN = 0x8,
Atish Patraefca1392020-03-17 18:11:37 -070025#endif
Atish Patrab9dcd9e2020-03-17 18:11:35 -070026 SBI_EXT_BASE = 0x10,
Atish Patraecbacc22020-03-17 18:11:36 -070027 SBI_EXT_TIME = 0x54494D45,
28 SBI_EXT_IPI = 0x735049,
29 SBI_EXT_RFENCE = 0x52464E43,
Atish Patradb5a7942020-03-17 18:11:42 -070030 SBI_EXT_HSM = 0x48534D,
Anup Patelb579dfe2021-06-09 17:43:22 +053031 SBI_EXT_SRST = 0x53525354,
Atish Patrac62a7682021-11-18 00:39:10 -080032
33 /* Experimentals extensions must lie within this range */
34 SBI_EXT_EXPERIMENTAL_START = 0x08000000,
35 SBI_EXT_EXPERIMENTAL_END = 0x08FFFFFF,
36
37 /* Vendor extensions must lie within this range */
38 SBI_EXT_VENDOR_START = 0x09000000,
39 SBI_EXT_VENDOR_END = 0x09FFFFFF,
Atish Patrab9dcd9e2020-03-17 18:11:35 -070040};
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -070041
Atish Patrab9dcd9e2020-03-17 18:11:35 -070042enum sbi_ext_base_fid {
43 SBI_EXT_BASE_GET_SPEC_VERSION = 0,
44 SBI_EXT_BASE_GET_IMP_ID,
45 SBI_EXT_BASE_GET_IMP_VERSION,
46 SBI_EXT_BASE_PROBE_EXT,
47 SBI_EXT_BASE_GET_MVENDORID,
48 SBI_EXT_BASE_GET_MARCHID,
49 SBI_EXT_BASE_GET_MIMPID,
50};
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -070051
Atish Patraecbacc22020-03-17 18:11:36 -070052enum sbi_ext_time_fid {
53 SBI_EXT_TIME_SET_TIMER = 0,
54};
55
56enum sbi_ext_ipi_fid {
57 SBI_EXT_IPI_SEND_IPI = 0,
58};
59
60enum sbi_ext_rfence_fid {
61 SBI_EXT_RFENCE_REMOTE_FENCE_I = 0,
62 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
63 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
Atish Patraecbacc22020-03-17 18:11:36 -070064 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
Heinrich Schuchardt6dd48792021-03-06 06:48:01 +010065 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
Atish Patraecbacc22020-03-17 18:11:36 -070066 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
Heinrich Schuchardt6dd48792021-03-06 06:48:01 +010067 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
Atish Patraecbacc22020-03-17 18:11:36 -070068};
69
Atish Patradb5a7942020-03-17 18:11:42 -070070enum sbi_ext_hsm_fid {
71 SBI_EXT_HSM_HART_START = 0,
72 SBI_EXT_HSM_HART_STOP,
73 SBI_EXT_HSM_HART_STATUS,
74};
75
76enum sbi_hsm_hart_status {
77 SBI_HSM_HART_STATUS_STARTED = 0,
78 SBI_HSM_HART_STATUS_STOPPED,
79 SBI_HSM_HART_STATUS_START_PENDING,
80 SBI_HSM_HART_STATUS_STOP_PENDING,
81};
82
Anup Patelb579dfe2021-06-09 17:43:22 +053083enum sbi_ext_srst_fid {
84 SBI_EXT_SRST_RESET = 0,
85};
86
87enum sbi_srst_reset_type {
88 SBI_SRST_RESET_TYPE_SHUTDOWN = 0,
89 SBI_SRST_RESET_TYPE_COLD_REBOOT,
90 SBI_SRST_RESET_TYPE_WARM_REBOOT,
91};
92
93enum sbi_srst_reset_reason {
94 SBI_SRST_RESET_REASON_NONE = 0,
95 SBI_SRST_RESET_REASON_SYS_FAILURE,
96};
97
Atish Patrab9dcd9e2020-03-17 18:11:35 -070098#define SBI_SPEC_VERSION_DEFAULT 0x1
99#define SBI_SPEC_VERSION_MAJOR_SHIFT 24
100#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
101#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700102
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700103/* SBI return error codes */
104#define SBI_SUCCESS 0
105#define SBI_ERR_FAILURE -1
106#define SBI_ERR_NOT_SUPPORTED -2
107#define SBI_ERR_INVALID_PARAM -3
108#define SBI_ERR_DENIED -4
109#define SBI_ERR_INVALID_ADDRESS -5
Atish Patra3e1d8652021-11-18 00:39:12 -0800110#define SBI_ERR_ALREADY_AVAILABLE -6
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700111
112extern unsigned long sbi_spec_version;
113struct sbiret {
114 long error;
115 long value;
116};
117
Kefeng Wang641e8cd2020-11-26 10:40:38 +0800118void sbi_init(void);
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700119struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
120 unsigned long arg1, unsigned long arg2,
121 unsigned long arg3, unsigned long arg4,
122 unsigned long arg5);
123
124void sbi_console_putchar(int ch);
125int sbi_console_getchar(void);
Vincent Chen183787c2021-03-22 22:26:02 +0800126long sbi_get_mvendorid(void);
127long sbi_get_marchid(void);
128long sbi_get_mimpid(void);
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700129void sbi_set_timer(uint64_t stime_value);
130void sbi_shutdown(void);
131void sbi_clear_ipi(void);
Atish Patra26fb7512022-01-20 01:09:18 -0800132int sbi_send_ipi(const struct cpumask *cpu_mask);
133int sbi_remote_fence_i(const struct cpumask *cpu_mask);
134int sbi_remote_sfence_vma(const struct cpumask *cpu_mask,
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700135 unsigned long start,
136 unsigned long size);
137
Atish Patra26fb7512022-01-20 01:09:18 -0800138int sbi_remote_sfence_vma_asid(const struct cpumask *cpu_mask,
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700139 unsigned long start,
140 unsigned long size,
141 unsigned long asid);
Atish Patra26fb7512022-01-20 01:09:18 -0800142int sbi_remote_hfence_gvma(const struct cpumask *cpu_mask,
Atish Patra1ef46c22020-03-17 18:11:38 -0700143 unsigned long start,
144 unsigned long size);
Atish Patra26fb7512022-01-20 01:09:18 -0800145int sbi_remote_hfence_gvma_vmid(const struct cpumask *cpu_mask,
Atish Patra1ef46c22020-03-17 18:11:38 -0700146 unsigned long start,
147 unsigned long size,
148 unsigned long vmid);
Atish Patra26fb7512022-01-20 01:09:18 -0800149int sbi_remote_hfence_vvma(const struct cpumask *cpu_mask,
Atish Patra1ef46c22020-03-17 18:11:38 -0700150 unsigned long start,
151 unsigned long size);
Atish Patra26fb7512022-01-20 01:09:18 -0800152int sbi_remote_hfence_vvma_asid(const struct cpumask *cpu_mask,
Atish Patra1ef46c22020-03-17 18:11:38 -0700153 unsigned long start,
154 unsigned long size,
155 unsigned long asid);
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700156int sbi_probe_extension(int ext);
157
158/* Check if current SBI specification version is 0.1 or not */
159static inline int sbi_spec_is_0_1(void)
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700160{
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700161 return (sbi_spec_version == SBI_SPEC_VERSION_DEFAULT) ? 1 : 0;
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700162}
163
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700164/* Get the major version of SBI */
165static inline unsigned long sbi_major_version(void)
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700166{
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700167 return (sbi_spec_version >> SBI_SPEC_VERSION_MAJOR_SHIFT) &
168 SBI_SPEC_VERSION_MAJOR_MASK;
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700169}
170
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700171/* Get the minor version of SBI */
172static inline unsigned long sbi_minor_version(void)
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700173{
Atish Patrab9dcd9e2020-03-17 18:11:35 -0700174 return sbi_spec_version & SBI_SPEC_VERSION_MINOR_MASK;
Palmer Dabbelt6d60b6e2017-07-10 18:05:09 -0700175}
Atish Patraf90b43c2020-03-17 18:11:41 -0700176
Anup Patelb579dfe2021-06-09 17:43:22 +0530177/* Make SBI version */
178static inline unsigned long sbi_mk_version(unsigned long major,
179 unsigned long minor)
180{
181 return ((major & SBI_SPEC_VERSION_MAJOR_MASK) <<
182 SBI_SPEC_VERSION_MAJOR_SHIFT) | minor;
183}
184
Atish Patraf90b43c2020-03-17 18:11:41 -0700185int sbi_err_map_linux_errno(int err);
Christoph Hellwig8bf90f32019-10-28 13:10:36 +0100186#else /* CONFIG_RISCV_SBI */
Atish Patra26fb7512022-01-20 01:09:18 -0800187static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) { return -1; }
Kefeng Wang641e8cd2020-11-26 10:40:38 +0800188static inline void sbi_init(void) {}
Christoph Hellwig3b03ac62019-10-28 13:10:34 +0100189#endif /* CONFIG_RISCV_SBI */
190#endif /* _ASM_RISCV_SBI_H */