blob: bfcd20495374a39fc431df565b2ecafbad8a5279 [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,
Bin Mengee3bcd02020-03-09 19:35:28 -070030};
Lukas Auer9c038452019-03-17 19:28:33 +010031
Bin Mengee3bcd02020-03-09 19:35:28 -070032enum sbi_ext_base_fid {
33 SBI_EXT_BASE_GET_SPEC_VERSION = 0,
34 SBI_EXT_BASE_GET_IMP_ID,
35 SBI_EXT_BASE_GET_IMP_VERSION,
36 SBI_EXT_BASE_PROBE_EXT,
37 SBI_EXT_BASE_GET_MVENDORID,
38 SBI_EXT_BASE_GET_MARCHID,
39 SBI_EXT_BASE_GET_MIMPID,
40};
Lukas Auer9c038452019-03-17 19:28:33 +010041
Bin Mengc20421b2020-03-09 19:35:29 -070042enum sbi_ext_time_fid {
43 SBI_EXT_TIME_SET_TIMER = 0,
44};
45
46enum sbi_ext_ipi_fid {
47 SBI_EXT_IPI_SEND_IPI = 0,
48};
49
50enum sbi_ext_rfence_fid {
51 SBI_EXT_RFENCE_REMOTE_FENCE_I = 0,
52 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
53 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
Heinrich Schuchardt2d1c6512021-09-12 21:11:44 +020054 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
55 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
56 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
57 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
58};
59
60enum sbi_ext_hsm_fid {
61 SBI_EXT_HSM_HART_START = 0,
62 SBI_EXT_HSM_HART_STOP,
63 SBI_EXT_HSM_HART_STATUS,
64 SBI_EXT_HSM_HART_SUSPEND,
65};
66
67enum sbi_hsm_hart_status {
68 SBI_HSM_HART_STATUS_STARTED = 0,
69 SBI_HSM_HART_STATUS_STOPPED,
70 SBI_HSM_HART_STATUS_START_PENDING,
71 SBI_HSM_HART_STATUS_STOP_PENDING,
72 SBI_HSM_HART_STATUS_SUSPEND_PENDING,
73 SBI_HSM_HART_STATUS_RESUME_PENDING,
74};
75
76enum sbi_ext_srst_fid {
77 SBI_EXT_SRST_RESET = 0,
78};
79
80enum sbi_srst_reset_type {
81 SBI_SRST_RESET_TYPE_SHUTDOWN = 0,
82 SBI_SRST_RESET_TYPE_COLD_REBOOT,
83 SBI_SRST_RESET_TYPE_WARM_REBOOT,
84};
85
86enum sbi_srst_reset_reason {
87 SBI_SRST_RESET_REASON_NONE = 0,
88 SBI_SRST_RESET_REASON_SYS_FAILURE,
Bin Mengc20421b2020-03-09 19:35:29 -070089};
90
Bin Mengf7e6d332020-03-09 19:35:31 -070091#ifdef CONFIG_SBI_V01
92#define SBI_EXT_SET_TIMER SBI_EXT_0_1_SET_TIMER
93#define SBI_FID_SET_TIMER 0
94#define SBI_EXT_SEND_IPI SBI_EXT_0_1_SEND_IPI
95#define SBI_FID_SEND_IPI 0
96#define SBI_EXT_REMOTE_FENCE_I SBI_EXT_0_1_REMOTE_FENCE_I
97#define SBI_FID_REMOTE_FENCE_I 0
98#define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_0_1_REMOTE_SFENCE_VMA
99#define SBI_FID_REMOTE_SFENCE_VMA 0
100#define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID
101#define SBI_FID_REMOTE_SFENCE_VMA_ASID 0
102#else
103#define SBI_EXT_SET_TIMER SBI_EXT_TIME
104#define SBI_FID_SET_TIMER SBI_EXT_TIME_SET_TIMER
105#define SBI_EXT_SEND_IPI SBI_EXT_IPI
106#define SBI_FID_SEND_IPI SBI_EXT_IPI_SEND_IPI
107#define SBI_EXT_REMOTE_FENCE_I SBI_EXT_RFENCE
108#define SBI_FID_REMOTE_FENCE_I SBI_EXT_RFENCE_REMOTE_FENCE_I
109#define SBI_EXT_REMOTE_SFENCE_VMA SBI_EXT_RFENCE
110#define SBI_FID_REMOTE_SFENCE_VMA SBI_EXT_RFENCE_REMOTE_SFENCE_VMA
111#define SBI_EXT_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE
112#define SBI_FID_REMOTE_SFENCE_VMA_ASID SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID
113#endif
114
Bin Mengee3bcd02020-03-09 19:35:28 -0700115#define SBI_SPEC_VERSION_MAJOR_SHIFT 24
116#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
117#define SBI_SPEC_VERSION_MINOR_MASK 0xffffff
Lukas Auer9c038452019-03-17 19:28:33 +0100118
Bin Mengee3bcd02020-03-09 19:35:28 -0700119/* SBI return error codes */
120#define SBI_SUCCESS 0
121#define SBI_ERR_FAILURE -1
122#define SBI_ERR_NOT_SUPPORTED -2
123#define SBI_ERR_INVALID_PARAM -3
124#define SBI_ERR_DENIED -4
125#define SBI_ERR_INVALID_ADDRESS -5
Lukas Auer9c038452019-03-17 19:28:33 +0100126
Bin Mengee3bcd02020-03-09 19:35:28 -0700127struct sbiret {
128 long error;
129 long value;
130};
Lukas Auer9c038452019-03-17 19:28:33 +0100131
Bin Mengee3bcd02020-03-09 19:35:28 -0700132struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
133 unsigned long arg1, unsigned long arg2,
134 unsigned long arg3, unsigned long arg4,
135 unsigned long arg5);
Lukas Auer9c038452019-03-17 19:28:33 +0100136
Bin Meng887d8092020-03-09 19:35:30 -0700137#ifdef CONFIG_SBI_V01
Bin Mengee3bcd02020-03-09 19:35:28 -0700138void sbi_console_putchar(int ch);
139int sbi_console_getchar(void);
140void sbi_clear_ipi(void);
141void sbi_shutdown(void);
Bin Mengee3bcd02020-03-09 19:35:28 -0700142void sbi_send_ipi(const unsigned long *hart_mask);
143void sbi_remote_fence_i(const unsigned long *hart_mask);
144void sbi_remote_sfence_vma(const unsigned long *hart_mask,
145 unsigned long start,
146 unsigned long size);
147void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
148 unsigned long start,
149 unsigned long size,
150 unsigned long asid);
Atish Patraa7edd072020-04-21 14:51:57 -0700151#endif
152void sbi_set_timer(uint64_t stime_value);
Heinrich Schuchardt95492ae2020-08-20 19:43:39 +0200153long sbi_get_spec_version(void);
154int sbi_get_impl_id(void);
Heinrich Schuchardt69c681e2021-10-25 15:09:34 +0200155int sbi_get_impl_version(long *version);
Bin Mengee3bcd02020-03-09 19:35:28 -0700156int sbi_probe_extension(int ext);
Heinrich Schuchardtcc382ff2021-09-12 21:11:46 +0200157void sbi_srst_reset(unsigned long type, unsigned long reason);
Lukas Auer9c038452019-03-17 19:28:33 +0100158
159#endif