acrn-hypervisor/hypervisor/common/trusty_hypercall.c
David B. Kinder f4122d99c5 license: Replace license text with SPDX tag
Replace the BSD-3-Clause boiler plate license text with an SPDX tag.

Fixes: #189

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-06-01 10:43:06 +08:00

57 lines
1.2 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <hypervisor.h>
#include <hypercall.h>
int64_t hcall_world_switch(struct vcpu *vcpu)
{
int next_world_id = !(vcpu->arch_vcpu.cur_context);
if (next_world_id >= NR_WORLD) {
pr_err("%s world_id %d exceed max number of Worlds\n",
__func__, next_world_id);
return -EINVAL;
}
if (!vcpu->vm->sworld_control.sworld_enabled) {
pr_err("%s, Secure World is not enabled!\n", __func__);
return -EPERM;
}
if (!vcpu->vm->arch_vm.sworld_eptp) {
pr_err("%s, Trusty is not initialized!\n", __func__);
return -EPERM;
}
switch_world(vcpu, next_world_id);
return 0;
}
int64_t hcall_initialize_trusty(struct vcpu *vcpu, uint64_t param)
{
if (!vcpu->vm->sworld_control.sworld_enabled) {
pr_err("%s, Secure World is not enabled!\n", __func__);
return -EPERM;
}
if (vcpu->vm->arch_vm.sworld_eptp) {
pr_err("%s, Trusty already initialized!\n", __func__);
return -EPERM;
}
if (vcpu->arch_vcpu.cur_context != NORMAL_WORLD) {
pr_err("%s, must initialize Trusty from Normal World!\n",
__func__);
return -EPERM;
}
if (!initialize_trusty(vcpu, param))
return -ENODEV;
return 0;
}