2018-03-27 17:26:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
|
|
|
*
|
2018-05-26 01:49:13 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-27 17:26:38 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <hypervisor.h>
|
|
|
|
#include <hypercall.h>
|
|
|
|
|
2018-06-16 14:46:51 +08:00
|
|
|
/* this hcall is only come from trusty enabled vcpu itself, and cannot be
|
|
|
|
* called from other vcpus
|
|
|
|
*/
|
2018-03-27 17:26:38 +08:00
|
|
|
int64_t hcall_world_switch(struct vcpu *vcpu)
|
|
|
|
{
|
2018-06-28 16:27:12 +08:00
|
|
|
int32_t next_world_id = !(vcpu->arch_vcpu.cur_context);
|
2018-03-27 17:26:38 +08:00
|
|
|
|
2018-05-29 15:47:23 +08:00
|
|
|
if (next_world_id >= NR_WORLD) {
|
|
|
|
pr_err("%s world_id %d exceed max number of Worlds\n",
|
|
|
|
__func__, next_world_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-03-27 17:26:38 +08:00
|
|
|
if (!vcpu->vm->sworld_control.sworld_enabled) {
|
2018-05-29 15:47:23 +08:00
|
|
|
pr_err("%s, Secure World is not enabled!\n", __func__);
|
|
|
|
return -EPERM;
|
2018-03-27 17:26:38 +08:00
|
|
|
}
|
|
|
|
|
2018-06-19 14:25:22 +08:00
|
|
|
if (vcpu->vm->arch_vm.sworld_eptp == 0U) {
|
2018-05-29 15:47:23 +08:00
|
|
|
pr_err("%s, Trusty is not initialized!\n", __func__);
|
|
|
|
return -EPERM;
|
2018-03-27 17:26:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch_world(vcpu, next_world_id);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-27 17:27:51 +08:00
|
|
|
|
2018-06-16 14:46:51 +08:00
|
|
|
/* this hcall is only come from trusty enabled vcpu itself, and cannot be
|
|
|
|
* called from other vcpus
|
|
|
|
*/
|
2018-03-27 17:27:51 +08:00
|
|
|
int64_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param)
|
|
|
|
{
|
|
|
|
if (!vcpu->vm->sworld_control.sworld_enabled) {
|
2018-05-29 15:47:23 +08:00
|
|
|
pr_err("%s, Secure World is not enabled!\n", __func__);
|
|
|
|
return -EPERM;
|
2018-03-27 17:27:51 +08:00
|
|
|
}
|
|
|
|
|
2018-06-19 14:25:22 +08:00
|
|
|
if (vcpu->vm->arch_vm.sworld_eptp != 0U) {
|
2018-05-29 15:47:23 +08:00
|
|
|
pr_err("%s, Trusty already initialized!\n", __func__);
|
|
|
|
return -EPERM;
|
2018-03-27 17:27:51 +08:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:47:23 +08:00
|
|
|
if (vcpu->arch_vcpu.cur_context != NORMAL_WORLD) {
|
|
|
|
pr_err("%s, must initialize Trusty from Normal World!\n",
|
|
|
|
__func__);
|
|
|
|
return -EPERM;
|
2018-03-27 17:27:51 +08:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:47:23 +08:00
|
|
|
if (!initialize_trusty(vcpu, param))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2018-03-27 17:27:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|