riscv64: add SBI syscall interface

Change-Id: Ifab2a65fdad1de807e2334ec94137b992d6fe19d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4300
Reviewed-by: Alex von Gluck IV <[email protected]>
This commit is contained in:
X512
2021-08-06 15:51:16 +00:00
committed by Alex von Gluck IV
parent c15bf9b792
commit 1deede7388
3 changed files with 206 additions and 0 deletions
@@ -0,0 +1,143 @@
/*
* Copyright 2021, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SBI_SYSCALLS_H_
#define _SBI_SYSCALLS_H_
#include <stdint.h>
enum {
SBI_SUCCESS = 0,
SBI_ERR_FAILED = -1,
SBI_ERR_NOT_SUPPORTED = -2,
SBI_ERR_INVALID_PARAM = -3,
SBI_ERR_DENIED = -4,
SBI_ERR_INVALID_ADDRESS = -5,
SBI_ERR_ALREADY_AVAILABLE = -6,
};
struct sbiret {
long error; // a0
long value; // a1
};
enum {
SBI_HART_STATE_STARTED = 0,
SBI_HART_STATE_STOPPED = 1,
SBI_HART_STATE_START_PENDING = 2,
SBI_HART_STATE_STOP_PENDING = 3,
SBI_HART_STATE_SUSPENDED = 4,
SBI_HART_STATE_SUSPEND_PENDING = 5,
SBI_HART_STATE_RESUME_PENDING = 6,
};
enum {
SBI_RESET_TYPE_SHUTDOWN = 0,
SBI_RESET_TYPE_COLD_REBOOT = 1,
SBI_RESET_TYPE_WARM_REBOOT = 2,
};
enum {
SBI_RESET_REASON_NONE = 0,
SBI_RESET_REASON_SYSTEM_FAILURE = 1,
};
// a7: EID, a6: FID
extern "C" {
// Base Extension (EID #0x10)
struct sbiret sbi_get_spec_version(void); // FID #0
struct sbiret sbi_get_impl_id(void); // FID #1
struct sbiret sbi_get_impl_version(void); // FID #2
struct sbiret sbi_probe_extension(long extension_id); // FID #3
struct sbiret sbi_get_mvendorid(void); // FID #4
struct sbiret sbi_get_marchid(void); // FID #5
struct sbiret sbi_get_mimpid(void); // FID #6
// Legacy Extensions (EIDs #0x00 - #0x0F)
void sbi_set_timer_legacy(uint64_t stime_value); // EID #0x00
void sbi_console_putchar_legacy(int ch); // EID #0x01
int sbi_console_getchar_legacy(void); // EID #0x02
void sbi_clear_ipi_legacy(void); // EID #0x03
void sbi_send_ipi_legacy(const unsigned long *hart_mask); // EID #0x04
void sbi_remote_fence_i_legacy(const unsigned long *hart_mask); // EID #0x05
void sbi_remote_sfence_vma_legacy( // EID #0x06
const unsigned long *hart_mask,
unsigned long start,
unsigned long size);
void sbi_remote_sfence_vma_asid_legacy( // EID #0x07
const unsigned long *hart_mask,
unsigned long start,
unsigned long size,
unsigned long asid);
void sbi_shutdown_legacy(void); // EID #0x08
// Timer Extension (EID #0x54494D45 "TIME")
struct sbiret sbi_set_timer(uint64_t stime_value); // FID #0
// IPI Extension (EID #0x735049 "sPI: s-mode IPI")
struct sbiret sbi_send_ipi( // FID #0
unsigned long hart_mask,
unsigned long hart_mask_base);
// RFENCE Extension (EID #0x52464E43 "RFNC")
struct sbiret sbi_remote_fence_i( // FID #0
unsigned long hart_mask,
unsigned long hart_mask_base);
struct sbiret sbi_remote_sfence_vma( // FID #1
unsigned long hart_mask,
unsigned long hart_mask_base,
unsigned long start_addr,
unsigned long size);
struct sbiret sbi_remote_sfence_vma_asid( // FID #2
unsigned long hart_mask,
unsigned long hart_mask_base,
unsigned long start_addr,
unsigned long size,
unsigned long asid);
struct sbiret sbi_remote_hfence_gvma_vmid( // FID #3
unsigned long hart_mask,
unsigned long hart_mask_base,
unsigned long start_addr,
unsigned long size,
unsigned long vmid);
struct sbiret sbi_remote_hfence_gvma( // FID #4
unsigned long hart_mask,
unsigned long hart_mask_base,
unsigned long start_addr,
unsigned long size);
struct sbiret sbi_remote_hfence_vvma_asid( // FID #5
unsigned long hart_mask,
unsigned long hart_mask_base,
unsigned long start_addr,
unsigned long size,
unsigned long asid);
struct sbiret sbi_remote_hfence_vvma( // FID #6
unsigned long hart_mask,
unsigned long hart_mask_base,
unsigned long start_addr,
unsigned long size);
// Hart State Management Extension (EID #0x48534D "HSM")
struct sbiret sbi_hart_start( // FID #0
unsigned long hartid,
unsigned long start_addr,
unsigned long opaque);
struct sbiret sbi_hart_stop(void); // FID #1
struct sbiret sbi_hart_get_status(unsigned long hartid); // FID #2
struct sbiret sbi_hart_suspend( // FID #3
uint32_t suspend_type,
unsigned long resume_addr,
unsigned long opaque);
// System Reset Extension (EID #0x53525354 "SRST")
struct sbiret sbi_system_reset(uint32_t reset_type, uint32_t reset_reason); // FID #0
}
#endif // _SBI_SYSCALLS_H_
+1
View File
@@ -22,6 +22,7 @@ KernelMergeObject kernel_arch_riscv64.o :
arch_vm_translation_map.cpp arch_vm_translation_map.cpp
RISCV64VMTranslationMap.cpp RISCV64VMTranslationMap.cpp
Htif.cpp Htif.cpp
sbi_syscalls.S
: :
$(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused
: :
@@ -0,0 +1,62 @@
/*
* Copyright 2021, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#define SBI_SYSCALL(name, eid, fid) \
.globl name; \
.type name,%function; \
name: \
li a7, eid; \
li a6, fid; \
ecall; \
ret; \
.size name, .-name
#define SBI_SYSCALL_LEGACY(name, eid) \
.globl name; \
.type name,%function; \
name: \
li a7, eid; \
ecall; \
ret; \
.size name, .-name
SBI_SYSCALL(sbi_get_spec_version, 0x10, 0)
SBI_SYSCALL(sbi_get_impl_id, 0x10, 1)
SBI_SYSCALL(sbi_get_impl_version, 0x10, 2)
SBI_SYSCALL(sbi_probe_extension, 0x10, 3)
SBI_SYSCALL(sbi_get_mvendorid, 0x10, 4)
SBI_SYSCALL(sbi_get_marchid, 0x10, 5)
SBI_SYSCALL(sbi_get_mimpid, 0x10, 6)
SBI_SYSCALL_LEGACY(sbi_set_timer_legacy, 0)
SBI_SYSCALL_LEGACY(sbi_console_putchar_legacy, 1)
SBI_SYSCALL_LEGACY(sbi_console_getchar_legacy, 2)
SBI_SYSCALL_LEGACY(sbi_clear_ipi_legacy, 3)
SBI_SYSCALL_LEGACY(sbi_send_ipi_legacy, 4)
SBI_SYSCALL_LEGACY(sbi_remote_fence_i_legacy, 5)
SBI_SYSCALL_LEGACY(sbi_remote_sfence_vma_legacy, 6)
SBI_SYSCALL_LEGACY(sbi_remote_sfence_vma_asid_legacy, 7)
SBI_SYSCALL_LEGACY(sbi_shutdown_legacy, 8)
SBI_SYSCALL(sbi_set_timer, 0x54494D45, 0)
SBI_SYSCALL(sbi_send_ipi, 0x735049, 0)
SBI_SYSCALL(sbi_remote_fence_i, 0x52464E43, 0)
SBI_SYSCALL(sbi_remote_sfence_vma, 0x52464E43, 1)
SBI_SYSCALL(sbi_remote_sfence_vma_asid, 0x52464E43, 2)
SBI_SYSCALL(sbi_remote_hfence_gvma_vmid, 0x52464E43, 3)
SBI_SYSCALL(sbi_remote_hfence_gvma, 0x52464E43, 4)
SBI_SYSCALL(sbi_remote_hfence_vvma_asid, 0x52464E43, 5)
SBI_SYSCALL(sbi_remote_hfence_vvma, 0x52464E43, 6)
SBI_SYSCALL(sbi_hart_start, 0x48534D, 0)
SBI_SYSCALL(sbi_hart_stop, 0x48534D, 1)
SBI_SYSCALL(sbi_hart_get_status, 0x48534D, 2)
SBI_SYSCALL(sbi_hart_suspend, 0x48534D, 3)
SBI_SYSCALL(sbi_system_reset, 0x53525354, 0)