Files
Haoyu Tang 3b5847a67b hv: riscv add SBI interface to query machine IDs
Add wrapper functions to query machine vendor ID (mvendorid),
architecture ID (marchid), and implementation ID (mimpid) through
the SBI base extension.

These IDs identify the RISC-V processor vendor, microarchitecture,
and specific implementation respectively. The hypervisor needs to
retrieve these values from the underlying SBI firmware to forward
them to the Service VM via vSBI, allowing the Service VM to see
the actual hardware characteristics.

Tracked-On: #8851
Signed-off-by: Haoyu Tang <haoyu.tang@intel.com>
Acked-by: Wang Yu1 <yu1.wang@intel.com>
2025-12-26 07:57:51 +08:00

142 lines
4.0 KiB
C

/*
* Copyright (C) 2023-2025 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Authors:
* Haicheng Li <haicheng.li@intel.com>
*/
#ifndef RISCV_SBI_H
#define RISCV_SBI_H
#include <types.h>
enum sbi_eid {
SBI_EID_BASE = 0x10,
SBI_EID_TIMER = 0x54494D45,
SBI_EID_IPI = 0x735049,
SBI_EID_RFENCE = 0x52464E43,
SBI_EID_HSM = 0x48534D,
SBI_EID_SRST = 0x53525354,
SBI_EID_PMU = 0x504D55,
SBI_EID_DBCN = 0x4442434E,
SBI_EID_MPXY = 0x4D505859,
/* Experimental extensions must lie within this range */
SBI_EID_EXPER_START = 0x08000000,
SBI_EID_EXPER_END = 0x08FFFFFF,
/* Vendor extensions must lie within this range */
SBI_EID_VENDOR_START = 0x09000000,
SBI_EID_VENDOR_END = 0x09FFFFFF,
SBI_EID_FIRMWARE_START = 0x0A000000,
SBI_EID_FIRMWARE_END = 0x0AFFFFFF,
};
#define SBI_BASE_FID_GET_SPEC_VERSION 0x0
#define SBI_BASE_FID_GET_IMP_ID 0x1
#define SBI_BASE_FID_GET_IMP_VERSION 0x2
#define SBI_BASE_FID_PROBE_EXT 0x3
#define SBI_BASE_FID_GET_MVENDORID 0x4
#define SBI_BASE_FID_GET_MARCHID 0x5
#define SBI_BASE_FID_GET_MIMPID 0x6
/* SBI function IDs for TIME extension*/
#define SBI_TIMER_FID_SET_TIMER 0x0
/* SBI function IDs for IPI extension*/
#define SBI_IPI_FID_SEND_IPI 0x0
/* SBI function IDs for RFENCE extension*/
#define SBI_RFENCE_FID_FNECE_I 0x0
#define SBI_RFENCE_FID_SFNECE_VMA 0x1
#define SBI_RFENCE_FID_SFNECE_VMA_ASID 0x2
#define SBI_RFENCE_FID_HFNECE_GVMA 0x3
#define SBI_RFENCE_FID_HFNECE_GVMA_ASID 0x4
#define SBI_RFENCE_FID_HFNECE_VVMA 0x5
#define SBI_RFENCE_FID_HFNECE_VVMA_ASID 0x6
/* SBI function IDs for HSM extension*/
#define SBI_HSM_FID_HART_START 0x0
#define SBI_HSM_FID_HART_STOP 0x1
#define SBI_HSM_FID_HART_GET_STATUS 0x2
#define SBI_HSM_FID_HART_SUSPEND 0x3
#define SBI_HSM_STATE_STARTED 0x0
#define SBI_HSM_STATE_STOPPED 0x1
#define SBI_HSM_STATE_START_PENDING 0x2
#define SBI_HSM_STATE_STOP_PENDING 0x3
#define SBI_HSM_STATE_SUSPENDED 0x4
#define SBI_HSM_STATE_SUSPEND_PENDING 0x5
#define SBI_HSM_STATE_RESUME_PENDING 0x6
/* SBI function IDs for MPXY extension*/
#define SBI_MPXY_FID_GET_SHM_SIZE 0x0
#define SBI_MPXY_FID_SET_SHM 0x1
#define SBI_MPXY_FID_GET_CHANNEL_IDS 0x2
#define SBI_MPXY_FID_READ_ATTRS 0x3
#define SBI_MPXY_FID_WRITE_ATTRS 0x4
#define SBI_MPXY_FID_SEND_MSG_WITH_RESP 0x5
#define SBI_MPXY_FID_SEND_MSG_WITHOUT_RESP 0x6
#define SBI_MPXY_FID_GET_NOTFICATION_EVENTS 0x7
/* SBI function IDs for SRST extension */
#define SBI_EXT_SRST_RESET 0x0
#define SBI_SRST_RESET_TYPE_SHUTDOWN 0x0
#define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1
#define SBI_SRST_RESET_TYPE_WARM_REBOOT 0x2
#define SBI_SRST_RESET_TYPE_LAST SBI_SRST_RESET_TYPE_WARM_REBOOT
#define SBI_SRST_RESET_REASON_NONE 0x0
#define SBI_SRST_RESET_REASON_SYSFAIL 0x1
/* SBI function IDs for DBCN extension */
#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0
#define SBI_EXT_DBCN_CONSOLE_READ 0x1
#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2
/* SBI return error codes */
#define SBI_SUCCESS 0
#define SBI_ERR_FAILED -1
#define SBI_ERR_NOT_SUPPORTED -2
#define SBI_ERR_INVALID_PARAM -3
#define SBI_ERR_DENIED -4
#define SBI_ERR_INVALID_ADDRESS -5
#define SBI_ERR_ALREADY_AVAILABLE -6
#define SBI_ERR_ALREADY_STARTED -7
#define SBI_ERR_ALREADY_STOPPED -8
#define SBI_ERR_NO_SHMEM -9
#define SBI_ERR_INVALID_STATE -10
#define SBI_ERR_BAD_RANGE -11
#define SBI_ERR_TIMEOUT -12
#define SBI_ERR_IO -13
#define SBI_ERR_DENIED_LOCKED -14
#define SBI_RFENCE_FLUSH_ALL ((uint64_t)-1)
typedef struct {
int64_t error;
union {
int64_t value;
uint64_t uvalue;
};
} sbiret;
int64_t sbi_hsm_start_hart(uint64_t hartid, uint64_t addr, uint64_t arg);
void send_single_ipi(uint16_t pcpu_id, __unused uint32_t msg_type);
void send_dest_ipi_mask(uint64_t dest_mask, __unused uint32_t msg_type);
int sbi_set_timer(uint64_t stime_value);
sbiret sbi_ecall(uint64_t arg0, uint64_t arg1, uint64_t arg2,
uint64_t arg3, uint64_t arg4, uint64_t arg5,
uint64_t func, uint64_t ext);
uint64_t sbi_get_mvendorid(void);
uint64_t sbi_get_marchid(void);
uint64_t sbi_get_mimpid(void);
#endif /* RISCV_SBI_H */