mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
xen/riscv: add RISC-V legacy SBI extension support for guests
Add support for legacy SBI extensions (version 0.1) in Xen for guest domains. The changes include: 1. Define all legacy SBI extension IDs (0x0 to 0x8) for better clarity and completeness. 2. Implement handling of legacy SBI extensions, starting with support for SBI_EXT_0_1_CONSOLE_PUTCHAR. SBI_EXT_0_1_CONSOLE_GETCHAR is marked as not supported as legacy SBI console related stuff is expected to be used only for early debugging of guest. The implementation uses the existing virtual SBI framework to handle legacy SBI ecalls, ensuring compatibility with older SBI specifications in RISC-V guests. Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com> Acked-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
1 parent
e717a5a4ae
commit
b367b2e9fa
3 files changed
+74
-2
No files matched your search
@@ -14,8 +14,15 @@
|
||||
|
||||
#include <xen/cpumask.h>
|
||||
|
||||
#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
|
||||
#define SBI_EXT_0_1_SHUTDOWN 0x8
|
||||
#define SBI_EXT_0_1_SET_TIMER 0x0
|
||||
#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
|
||||
#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2
|
||||
#define SBI_EXT_0_1_CLEAR_IPI 0x3
|
||||
#define SBI_EXT_0_1_SEND_IPI 0x4
|
||||
#define SBI_EXT_0_1_REMOTE_FENCE_I 0x5
|
||||
#define SBI_EXT_0_1_REMOTE_SFENCE_VMA 0x6
|
||||
#define SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID 0x7
|
||||
#define SBI_EXT_0_1_SHUTDOWN 0x8
|
||||
|
||||
#define SBI_EXT_BASE 0x10
|
||||
#define SBI_EXT_RFENCE 0x52464E43
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
obj-y += core.o
|
||||
obj-y += legacy-extension.o
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
#include <xen/console.h>
|
||||
#include <xen/lib.h>
|
||||
#include <xen/sched.h>
|
||||
|
||||
#include <asm/processor.h>
|
||||
#include <asm/vsbi.h>
|
||||
|
||||
static void vsbi_print_char(char c)
|
||||
{
|
||||
struct domain *currd = current->domain;
|
||||
struct domain_console *cons = currd->console;
|
||||
|
||||
if ( !is_console_printable(c) )
|
||||
return;
|
||||
|
||||
spin_lock(&cons->lock);
|
||||
ASSERT(cons->idx < ARRAY_SIZE(cons->buf));
|
||||
if ( c != '\n' )
|
||||
cons->buf[cons->idx++] = c;
|
||||
if ( (cons->idx == (ARRAY_SIZE(cons->buf) - 1)) || (c == '\n') )
|
||||
{
|
||||
cons->buf[cons->idx] = '\0';
|
||||
guest_printk(currd, XENLOG_G_DEBUG "%s\n", cons->buf);
|
||||
cons->idx = 0;
|
||||
}
|
||||
spin_unlock(&cons->lock);
|
||||
}
|
||||
|
||||
static int vsbi_legacy_ecall_handler(unsigned long eid, unsigned long fid,
|
||||
struct cpu_user_regs *regs)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch ( eid )
|
||||
{
|
||||
case SBI_EXT_0_1_CONSOLE_PUTCHAR:
|
||||
vsbi_print_char(regs->a0);
|
||||
break;
|
||||
|
||||
case SBI_EXT_0_1_CONSOLE_GETCHAR:
|
||||
ret = SBI_ERR_NOT_SUPPORTED;
|
||||
break;
|
||||
|
||||
default:
|
||||
/*
|
||||
* TODO: domain_crash() is acceptable here while things are still under
|
||||
* development.
|
||||
* It shouldn't stay like this in the end though: guests should not
|
||||
* be punished like this for something Xen hasn't implemented.
|
||||
*/
|
||||
domain_crash(current->domain,
|
||||
"%s: Unsupported legacy ecall: EID: #%#lx\n",
|
||||
__func__, eid);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
VSBI_EXT(legacy, SBI_EXT_0_1_SET_TIMER, SBI_EXT_0_1_SHUTDOWN,
|
||||
vsbi_legacy_ecall_handler);
|
||||