Skip to content

Commit 6a216f4

Browse files
committed
feat(riscv/sbi): add sbi_rst support
Signed-off-by: Jose Martins <[email protected]>
1 parent 94871af commit 6a216f4

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/arch/riscv/sbi.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#define SBI_REMOTE_HFENCE_VVMA_FID (5)
4141
#define SBI_REMOTE_HFENCE_VVMA_ASID_FID (6)
4242

43+
#define SBI_EXTID_SRST (0x53525354)
44+
#define SBI_SYSTEM_RESET_FID (0)
45+
#define SBI_RST_TYPE_COLD_REBOOT (0x00000001)
46+
4347
/**
4448
* For now we're defining bao specific ecalls, ie, hypercall, under the experimental extension id
4549
* space.
@@ -166,7 +170,7 @@ struct sbiret sbi_hart_status(unsigned long hartid)
166170
}
167171

168172
static unsigned long ext_table[] = { SBI_EXTID_BASE, SBI_EXTID_TIME, SBI_EXTID_IPI, SBI_EXTID_RFNC,
169-
SBI_EXTID_HSM };
173+
SBI_EXTID_HSM, SBI_EXTID_SRST };
170174

171175
static const size_t NUM_EXT = sizeof(ext_table) / sizeof(unsigned long);
172176

@@ -256,7 +260,7 @@ static struct sbiret sbi_base_handler(unsigned long fid)
256260

257261
switch (fid) {
258262
case SBI_GET_SBI_SPEC_VERSION_FID:
259-
ret.value = 2;
263+
ret.value = 3;
260264
break;
261265
case SBI_PROBE_EXTENSION_FID:
262266
ret.value = 0;
@@ -391,6 +395,32 @@ static struct sbiret sbi_hsm_handler(unsigned long fid)
391395
return ret;
392396
}
393397

398+
static struct sbiret sbi_srst_handler(unsigned long fid)
399+
{
400+
struct sbiret ret;
401+
402+
uint32_t reset_type = (uint32_t)vcpu_readreg(cpu()->vcpu, REG_A0);
403+
404+
switch (fid) {
405+
case SBI_SYSTEM_RESET_FID:
406+
if (reset_type == SBI_RST_TYPE_COLD_REBOOT) {
407+
if (vm_reset(cpu()->vcpu->vm)) {
408+
ret.error = SBI_SUCCESS;
409+
} else {
410+
ret.error = SBI_ERR_FAILURE;
411+
}
412+
} else {
413+
ret.error = SBI_ERR_INVALID_PARAM;
414+
}
415+
break;
416+
default:
417+
ret.error = SBI_ERR_NOT_SUPPORTED;
418+
break;
419+
}
420+
421+
return ret;
422+
}
423+
394424
static struct sbiret sbi_bao_handler(unsigned long fid)
395425
{
396426
struct sbiret ret;
@@ -422,6 +452,9 @@ size_t sbi_vs_handler()
422452
case SBI_EXTID_HSM:
423453
ret = sbi_hsm_handler(fid);
424454
break;
455+
case SBI_EXTID_SRST:
456+
ret = sbi_srst_handler(fid);
457+
break;
425458
case SBI_EXTID_BAO:
426459
ret = sbi_bao_handler(fid);
427460
break;

0 commit comments

Comments
 (0)