2020-02-12 09:32:39 +08:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Atish Patra <atish.patra@wdc.com>
|
|
|
|
*/
|
|
|
|
|
2020-09-24 20:19:27 +08:00
|
|
|
#include <sbi/sbi_domain.h>
|
2020-02-12 09:32:39 +08:00
|
|
|
#include <sbi/sbi_ecall.h>
|
|
|
|
#include <sbi/sbi_ecall_interface.h>
|
|
|
|
#include <sbi/sbi_error.h>
|
|
|
|
#include <sbi/sbi_version.h>
|
|
|
|
#include <sbi/sbi_hsm.h>
|
2020-03-20 00:25:12 +08:00
|
|
|
#include <sbi/sbi_scratch.h>
|
2020-02-12 09:32:39 +08:00
|
|
|
#include <sbi/riscv_asm.h>
|
|
|
|
|
2020-03-20 00:25:12 +08:00
|
|
|
static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
|
2020-02-12 09:32:39 +08:00
|
|
|
unsigned long *args, unsigned long *out_val,
|
|
|
|
struct sbi_trap_info *out_trap)
|
|
|
|
{
|
2020-09-07 13:41:29 +08:00
|
|
|
ulong smode;
|
2020-03-20 00:25:12 +08:00
|
|
|
int ret = 0, hstate;
|
|
|
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
2020-02-12 09:32:39 +08:00
|
|
|
|
|
|
|
switch (funcid) {
|
|
|
|
case SBI_EXT_HSM_HART_START:
|
2020-09-07 13:41:29 +08:00
|
|
|
smode = csr_read(CSR_MSTATUS);
|
|
|
|
smode = (smode & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
2020-09-19 16:56:52 +08:00
|
|
|
ret = sbi_hsm_hart_start(scratch, sbi_domain_thishart_ptr(),
|
|
|
|
args[0], args[1], smode, args[2]);
|
2020-02-12 09:32:39 +08:00
|
|
|
break;
|
|
|
|
case SBI_EXT_HSM_HART_STOP:
|
|
|
|
ret = sbi_hsm_hart_stop(scratch, TRUE);
|
|
|
|
break;
|
|
|
|
case SBI_EXT_HSM_HART_GET_STATUS:
|
2020-09-24 20:19:27 +08:00
|
|
|
hstate = sbi_hsm_hart_get_state(sbi_domain_thishart_ptr(),
|
|
|
|
args[0]);
|
2020-02-12 09:32:39 +08:00
|
|
|
ret = sbi_hsm_hart_state_to_status(hstate);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = SBI_ENOTSUPP;
|
|
|
|
};
|
|
|
|
if (ret >= 0) {
|
|
|
|
*out_val = ret;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sbi_ecall_extension ecall_hsm = {
|
|
|
|
.extid_start = SBI_EXT_HSM,
|
|
|
|
.extid_end = SBI_EXT_HSM,
|
|
|
|
.handle = sbi_ecall_hsm_handler,
|
|
|
|
};
|