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