xref: /haiku/headers/private/kernel/platform/sbi/sbi_syscalls.h (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  * Copyright 2021, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _SBI_SYSCALLS_H_
6 #define _SBI_SYSCALLS_H_
7 
8 
9 #include <stdint.h>
10 
11 
12 enum {
13 	SBI_SUCCESS               =  0,
14 	SBI_ERR_FAILED            = -1,
15 	SBI_ERR_NOT_SUPPORTED     = -2,
16 	SBI_ERR_INVALID_PARAM     = -3,
17 	SBI_ERR_DENIED            = -4,
18 	SBI_ERR_INVALID_ADDRESS   = -5,
19 	SBI_ERR_ALREADY_AVAILABLE = -6,
20 };
21 
22 struct sbiret {
23 	long error; // a0
24 	long value; // a1
25 };
26 
27 enum {
28 	SBI_HART_STATE_STARTED         = 0,
29 	SBI_HART_STATE_STOPPED         = 1,
30 	SBI_HART_STATE_START_PENDING   = 2,
31 	SBI_HART_STATE_STOP_PENDING    = 3,
32 	SBI_HART_STATE_SUSPENDED       = 4,
33 	SBI_HART_STATE_SUSPEND_PENDING = 5,
34 	SBI_HART_STATE_RESUME_PENDING  = 6,
35 };
36 
37 enum {
38 	SBI_RESET_TYPE_SHUTDOWN    = 0,
39 	SBI_RESET_TYPE_COLD_REBOOT = 1,
40 	SBI_RESET_TYPE_WARM_REBOOT = 2,
41 };
42 
43 enum {
44 	SBI_RESET_REASON_NONE           = 0,
45 	SBI_RESET_REASON_SYSTEM_FAILURE = 1,
46 };
47 
48 // a7: EID, a6: FID
49 
50 extern "C" {
51 
52 // Base Extension (EID #0x10)
53 struct sbiret sbi_get_spec_version(void);             // FID #0
54 struct sbiret sbi_get_impl_id(void);                  // FID #1
55 struct sbiret sbi_get_impl_version(void);             // FID #2
56 struct sbiret sbi_probe_extension(long extension_id); // FID #3
57 struct sbiret sbi_get_mvendorid(void);                // FID #4
58 struct sbiret sbi_get_marchid(void);                  // FID #5
59 struct sbiret sbi_get_mimpid(void);                   // FID #6
60 
61 // Legacy Extensions (EIDs #0x00 - #0x0F)
62 void sbi_set_timer_legacy(uint64_t stime_value);                // EID #0x00
63 void sbi_console_putchar_legacy(int ch);                        // EID #0x01
64 int sbi_console_getchar_legacy(void);                           // EID #0x02
65 void sbi_clear_ipi_legacy(void);                                // EID #0x03
66 void sbi_send_ipi_legacy(const unsigned long *hart_mask);       // EID #0x04
67 void sbi_remote_fence_i_legacy(const unsigned long *hart_mask); // EID #0x05
68 void sbi_remote_sfence_vma_legacy(                              // EID #0x06
69 	const unsigned long *hart_mask,
70 	unsigned long start,
71 	unsigned long size);
72 void sbi_remote_sfence_vma_asid_legacy(                         // EID #0x07
73 	const unsigned long *hart_mask,
74 	unsigned long start,
75 	unsigned long size,
76 	unsigned long asid);
77 void sbi_shutdown_legacy(void);                                 // EID #0x08
78 
79 // Timer Extension (EID #0x54494D45 "TIME")
80 struct sbiret sbi_set_timer(uint64_t stime_value); // FID #0
81 
82 // IPI Extension (EID #0x735049 "sPI: s-mode IPI")
83 struct sbiret sbi_send_ipi( // FID #0
84 	unsigned long hart_mask,
85 	unsigned long hart_mask_base);
86 
87 // RFENCE Extension (EID #0x52464E43 "RFNC")
88 struct sbiret sbi_remote_fence_i( // FID #0
89 	unsigned long hart_mask,
90 	unsigned long hart_mask_base);
91 struct sbiret sbi_remote_sfence_vma( // FID #1
92 	unsigned long hart_mask,
93 	unsigned long hart_mask_base,
94 	unsigned long start_addr,
95 	unsigned long size);
96 struct sbiret sbi_remote_sfence_vma_asid( // FID #2
97 	unsigned long hart_mask,
98 	unsigned long hart_mask_base,
99 	unsigned long start_addr,
100 	unsigned long size,
101 	unsigned long asid);
102 struct sbiret sbi_remote_hfence_gvma_vmid( // FID #3
103 	unsigned long hart_mask,
104 	unsigned long hart_mask_base,
105 	unsigned long start_addr,
106 	unsigned long size,
107 	unsigned long vmid);
108 struct sbiret sbi_remote_hfence_gvma( // FID #4
109 	unsigned long hart_mask,
110 	unsigned long hart_mask_base,
111 	unsigned long start_addr,
112 	unsigned long size);
113 struct sbiret sbi_remote_hfence_vvma_asid( // FID #5
114 	unsigned long hart_mask,
115 	unsigned long hart_mask_base,
116 	unsigned long start_addr,
117 	unsigned long size,
118 	unsigned long asid);
119 struct sbiret sbi_remote_hfence_vvma( // FID #6
120 	unsigned long hart_mask,
121 	unsigned long hart_mask_base,
122 	unsigned long start_addr,
123 	unsigned long size);
124 
125 // Hart State Management Extension (EID #0x48534D "HSM")
126 struct sbiret sbi_hart_start( // FID #0
127 	unsigned long hartid,
128 	unsigned long start_addr,
129 	unsigned long opaque);
130 struct sbiret sbi_hart_stop(void); // FID #1
131 struct sbiret sbi_hart_get_status(unsigned long hartid); // FID #2
132 struct sbiret sbi_hart_suspend( // FID #3
133 	uint32_t suspend_type,
134 	unsigned long resume_addr,
135 	unsigned long opaque);
136 
137 // System Reset Extension (EID #0x53525354 "SRST")
138 struct sbiret sbi_system_reset(uint32_t reset_type, uint32_t reset_reason); // FID #0
139 
140 }
141 
142 
143 #endif	// _SBI_SYSCALLS_H_
144