2012-10-26 14:40:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
* Author: Marc Zyngier <marc.zyngier@arm.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ASM__VIRT_H
|
|
|
|
#define __ASM__VIRT_H
|
|
|
|
|
2016-04-27 16:47:03 +00:00
|
|
|
/*
|
2017-04-03 18:37:38 +00:00
|
|
|
* The arm64 hcall implementation uses x0 to specify the hcall
|
|
|
|
* number. A value less than HVC_STUB_HCALL_NR indicates a special
|
|
|
|
* hcall, such as set vector. Any other value is handled in a
|
|
|
|
* hypervisor specific way.
|
|
|
|
*
|
|
|
|
* The hypercall is allowed to clobber any of the caller-saved
|
|
|
|
* registers (x0-x18), so it is advisable to use it through the
|
|
|
|
* indirection of a function call (as implemented in hyp-stub.S).
|
2016-04-27 16:47:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HVC_SET_VECTORS - Set the value of the vbar_el2 register.
|
|
|
|
*
|
|
|
|
* @x1: Physical address of the new vector table.
|
|
|
|
*/
|
2017-04-03 18:38:04 +00:00
|
|
|
#define HVC_SET_VECTORS 0
|
2016-04-27 16:47:03 +00:00
|
|
|
|
2016-06-23 17:54:48 +00:00
|
|
|
/*
|
|
|
|
* HVC_SOFT_RESTART - CPU soft reset, used by the cpu_soft_restart routine.
|
|
|
|
*/
|
2017-04-03 18:38:04 +00:00
|
|
|
#define HVC_SOFT_RESTART 1
|
2016-06-23 17:54:48 +00:00
|
|
|
|
2017-04-03 18:37:39 +00:00
|
|
|
/*
|
|
|
|
* HVC_RESET_VECTORS - Restore the vectors to the original HYP stubs
|
|
|
|
*/
|
2017-04-03 18:38:04 +00:00
|
|
|
#define HVC_RESET_VECTORS 2
|
2017-04-03 18:37:39 +00:00
|
|
|
|
|
|
|
/* Max number of HYP stub hypercalls */
|
2017-04-03 18:38:04 +00:00
|
|
|
#define HVC_STUB_HCALL_NR 3
|
2017-04-03 18:37:39 +00:00
|
|
|
|
2017-04-03 18:37:37 +00:00
|
|
|
/* Error returned when an invalid stub number is passed into x0 */
|
|
|
|
#define HVC_STUB_ERR 0xbadca11
|
|
|
|
|
2013-10-11 13:52:16 +00:00
|
|
|
#define BOOT_CPU_MODE_EL1 (0xe11)
|
|
|
|
#define BOOT_CPU_MODE_EL2 (0xe12)
|
2012-10-26 14:40:05 +00:00
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
2014-06-09 18:47:09 +00:00
|
|
|
#include <asm/ptrace.h>
|
2016-08-24 17:27:28 +00:00
|
|
|
#include <asm/sections.h>
|
2016-09-08 12:55:37 +00:00
|
|
|
#include <asm/sysreg.h>
|
2016-12-01 19:32:05 +00:00
|
|
|
#include <asm/cpufeature.h>
|
2014-06-09 18:47:09 +00:00
|
|
|
|
2012-10-26 14:40:05 +00:00
|
|
|
/*
|
|
|
|
* __boot_cpu_mode records what mode CPUs were booted in.
|
|
|
|
* A correctly-implemented bootloader must start all CPUs in the same mode:
|
|
|
|
* In this case, both 32bit halves of __boot_cpu_mode will contain the
|
|
|
|
* same value (either 0 if booted in EL1, BOOT_CPU_MODE_EL2 if booted in EL2).
|
|
|
|
*
|
|
|
|
* Should the bootloader fail to do this, the two values will be different.
|
|
|
|
* This allows the kernel to flag an error when the secondaries have come up.
|
|
|
|
*/
|
|
|
|
extern u32 __boot_cpu_mode[2];
|
|
|
|
|
2012-10-19 16:46:27 +00:00
|
|
|
void __hyp_set_vectors(phys_addr_t phys_vector_base);
|
2017-04-03 18:37:39 +00:00
|
|
|
void __hyp_reset_vectors(void);
|
2012-10-19 16:46:27 +00:00
|
|
|
|
2012-10-26 14:40:05 +00:00
|
|
|
/* Reports the availability of HYP mode */
|
|
|
|
static inline bool is_hyp_mode_available(void)
|
|
|
|
{
|
|
|
|
return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
|
|
|
|
__boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the bootloader has booted CPUs in different modes */
|
|
|
|
static inline bool is_hyp_mode_mismatched(void)
|
|
|
|
{
|
|
|
|
return __boot_cpu_mode[0] != __boot_cpu_mode[1];
|
|
|
|
}
|
|
|
|
|
2014-06-09 18:47:09 +00:00
|
|
|
static inline bool is_kernel_in_hyp_mode(void)
|
|
|
|
{
|
2016-09-08 12:55:37 +00:00
|
|
|
return read_sysreg(CurrentEL) == CurrentEL_EL2;
|
2014-06-09 18:47:09 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 19:32:05 +00:00
|
|
|
static inline bool has_vhe(void)
|
|
|
|
{
|
|
|
|
if (cpus_have_const_cap(ARM64_HAS_VIRT_HOST_EXTN))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-26 14:40:05 +00:00
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
|
|
|
|
#endif /* ! __ASM__VIRT_H */
|