blob: ad32dedb5896cf97b7bbb25604323659f7cc2abe [file] [log] [blame]
Lukas Auer9c038452019-03-17 19:28:33 +01001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2015 Regents of the University of California
Bin Meng9da11d12020-03-09 19:35:27 -07004 * Copyright (c) 2020 Western Digital Corporation or its affiliates.
Lukas Auer9c038452019-03-17 19:28:33 +01005 *
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
Bin Mengee3bcd02020-03-09 19:35:28 -070014enum 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,
Bin Mengc20421b2020-03-09 19:35:29 -070025 SBI_EXT_TIME = 0x54494D45,
26 SBI_EXT_IPI = 0x735049,
27 SBI_EXT_RFENCE = 0x52464E43,
Heinrich Schuchardt2d1c6512021-09-12 21:11:44 +020028 SBI_EXT_HSM = 0x48534D,
29 SBI_EXT_SRST = 0x53525354,
Heinrich Schuchardt295e1ce2022-03-16 21:21:18 +010030 SBI_EXT_PMU = 0x504D55,
Heinrich Schuchardtcd464d12023-04-12 10:38:16 +020031 SBI_EXT_DBCN = 0x4442434E,
32 SBI_EXT_SUSP = 0x53555350,
33 SBI_EXT_CPPC = 0x43505043,
Heinrich Schuchardt70884d72023-08-02 22:39:46 +020034 SBI_EXT_NACL = 0x4E41434C,
35 SBI_EXT_STA = 0x535441,
Heinrich Schuchardt35b0d182024-01-17 17:46:52 +010036 SBI_EXT_DBTR = 0x44425452,
Heinrich Schuchardt85efa4e2024-04-17 16:01:27 +020037 SBI_EXT_SSE = 0x535345,
Bin Mengee3bcd02020-03-09 19:35:28 -070038};
Lukas Auer9c038452019-03-17 19:28:33 +010039
Bin Mengee3bcd02020-03-09 19:35:28 -070040enum sbi_ext_base_fid {
41 SBI_EXT_BASE_GET_SPEC_VERSION = 0,
42 SBI_EXT_BASE_GET_IMP_ID,
43 SBI_EXT_BASE_GET_IMP_VERSION,
44 SBI_EXT_BASE_PROBE_EXT,
45 SBI_EXT_BASE_GET_MVENDORID,
46 SBI_EXT_BASE_GET_MARCHID,
47 SBI_EXT_BASE_GET_MIMPID,
48};
Lukas Auer9c038452019-03-17 19:28:33 +010049
Bin Mengc20421b2020-03-09 19:35:29 -070050enum sbi_ext_time_fid {
51 SBI_EXT_TIME_SET_TIMER = 0,
52};
53
54enum sbi_ext_ipi_fid {
55 SBI_EXT_IPI_SEND_IPI = 0,
56};
57
58enum sbi_ext_rfence_fid {
59 SBI_EXT_RFENCE_REMOTE_FENCE_I = 0,
60 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
61 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
Heinrich Schuchardt2d1c6512021-09-12 21:11:44 +020062 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
63 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
64 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
65 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
66};
67
68enum sbi_ext_hsm_fid {
69 SBI_EXT_HSM_HART_START = 0,
70 SBI_EXT_HSM_HART_STOP,
71 SBI_EXT_HSM_HART_STATUS,
72 SBI_EXT_HSM_HART_SUSPEND,
73};
74
75enum sbi_hsm_hart_status {
76 SBI_HSM_HART_STATUS_STARTED = 0,
77 SBI_HSM_HART_STATUS_STOPPED,
78 SBI_HSM_HART_STATUS_START_PENDING,
79 SBI_HSM_HART_STATUS_STOP_PENDING,
80 SBI_HSM_HART_STATUS_SUSPEND_PENDING,
81 SBI_HSM_HART_STATUS_RESUME_PENDING,
82};
83
84enum sbi_ext_srst_fid {
85 SBI_EXT_SRST_RESET = 0,
86};
87
88enum sbi_srst_reset_type {
89 SBI_SRST_RESET_TYPE_SHUTDOWN = 0,
90 SBI_SRST_RESET_TYPE_COLD_REBOOT,
91 SBI_SRST_RESET_TYPE_WARM_REBOOT,
92};
93
94enum sbi_srst_reset_reason {
95 SBI_SRST_RESET_REASON_NONE = 0,
96 SBI_SRST_RESET_REASON_SYS_FAILURE,
Bin Mengc20421b2020-03-09 19:35:29 -070097};
98
Heinrich Schuchardtcd464d12023-04-12 10:38:16 +020099enum sbi_ext_dbcn_fid {
100 SBI_EXT_DBCN_CONSOLE_WRITE = 0,
101 SBI_EXT_DBCN_CONSOLE_READ,
102 SBI_EXT_DBCN_CONSOLE_WRITE_BYTE,
103};
104
Bin Mengf7e6d332020-03-09 19:35:31 -0700105#ifdef CONFIG_SBI_V01
106#define SBI_EXT_SET_TIMER SBI_EXT_0_1_SET_TIMER
107#define SBI_FID_SET_TIMER 0
108#define SBI_EXT_SEND_IPI SBI_EXT_0_1_SEND_IPI
109#define SBI_FID_SEND_IPI 0
110#define SBI_EXT_REMOTE_FENCE_I SBI_EXT_0_1_REMOTE_FENCE_I
111#define SBI_FID_REMOTE_FENCE_I 0
112#define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_0_1_REMOTE_SFENCE_VMA
113#define SBI_FID_REMOTE_SFENCE_VMA 0
114#define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID
115#define SBI_FID_REMOTE_SFENCE_VMA_ASID 0
116#else
117#define SBI_EXT_SET_TIMER SBI_EXT_TIME
118#define SBI_FID_SET_TIMER SBI_EXT_TIME_SET_TIMER
119#define SBI_EXT_SEND_IPI SBI_EXT_IPI
120#define SBI_FID_SEND_IPI SBI_EXT_IPI_SEND_IPI
121#define SBI_EXT_REMOTE_FENCE_I SBI_EXT_RFENCE
122#define SBI_FID_REMOTE_FENCE_I SBI_EXT_RFENCE_REMOTE_FENCE_I
123#define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_RFENCE
124#define SBI_FID_REMOTE_SFENCE_VMA SBI_EXT_RFENCE_REMOTE_SFENCE_VMA
125#define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE
126#define SBI_FID_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID
127#endif
128
Bin Mengee3bcd02020-03-09 19:35:28 -0700129#define SBI_SPEC_VERSION_MAJOR_SHIFT 24
130#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
131#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff
Lukas Auer9c038452019-03-17 19:28:33 +0100132
Bin Mengee3bcd02020-03-09 19:35:28 -0700133/* SBI return error codes */
134#define SBI_SUCCESS 0
135#define SBI_ERR_FAILURE -1
136#define SBI_ERR_NOT_SUPPORTED -2
137#define SBI_ERR_INVALID_PARAM -3
138#define SBI_ERR_DENIED -4
139#define SBI_ERR_INVALID_ADDRESS -5
Lukas Auer9c038452019-03-17 19:28:33 +0100140
Bin Mengee3bcd02020-03-09 19:35:28 -0700141struct sbiret {
142 long error;
143 long value;
144};
Lukas Auer9c038452019-03-17 19:28:33 +0100145
Bin Mengee3bcd02020-03-09 19:35:28 -0700146struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
147 unsigned long arg1, unsigned long arg2,
148 unsigned long arg3, unsigned long arg4,
149 unsigned long arg5);
Lukas Auer9c038452019-03-17 19:28:33 +0100150
Bin Meng887d8092020-03-09 19:35:30 -0700151#ifdef CONFIG_SBI_V01
Bin Mengee3bcd02020-03-09 19:35:28 -0700152void sbi_console_putchar(int ch);
153int sbi_console_getchar(void);
154void sbi_clear_ipi(void);
155void sbi_shutdown(void);
Bin Mengee3bcd02020-03-09 19:35:28 -0700156void sbi_send_ipi(const unsigned long *hart_mask);
157void sbi_remote_fence_i(const unsigned long *hart_mask);
158void sbi_remote_sfence_vma(const unsigned long *hart_mask,
159 unsigned long start,
160 unsigned long size);
161void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
162 unsigned long start,
163 unsigned long size,
164 unsigned long asid);
Atish Patraa7edd072020-04-21 14:51:57 -0700165#endif
166void sbi_set_timer(uint64_t stime_value);
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +0200167long sbi_get_spec_version(void);
168int sbi_get_impl_id(void);
Heinrich Schuchardt69c681e2021-10-25 15:09:34 +0200169int sbi_get_impl_version(long *version);
Bin Mengee3bcd02020-03-09 19:35:28 -0700170int sbi_probe_extension(int ext);
Heinrich Schuchardtf4b4d752022-03-17 07:36:14 +0100171int sbi_get_mvendorid(long *mvendorid);
172int sbi_get_marchid(long *marchid);
173int sbi_get_mimpid(long *mimpid);
Heinrich Schuchardtcc382ff2021-09-12 21:11:46 +0200174void sbi_srst_reset(unsigned long type, unsigned long reason);
Heinrich Schuchardta7289b62023-09-04 13:24:03 +0200175int sbi_dbcn_write_byte(unsigned char ch);
Lukas Auer9c038452019-03-17 19:28:33 +0100176
177#endif