blob: 35491af879852dda8b69c85db662757366e91a94 [file] [log] [blame]
Christoffer Dall749cf76c2013-01-20 18:28:06 -05001/*
2 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
3 * Author: Christoffer Dall <c.dall@virtualopensystems.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef __ARM_KVM_ASM_H__
20#define __ARM_KVM_ASM_H__
21
Marc Zyngier1a61ae72016-01-02 13:57:18 +000022#include <asm/virt.h>
23
Marc Zyngier435bca52016-09-06 14:02:11 +010024#define ARM_EXIT_WITH_ABORT_BIT 31
25#define ARM_EXCEPTION_CODE(x) ((x) & ~(1U << ARM_EXIT_WITH_ABORT_BIT))
Marc Zyngier58466762018-12-19 08:28:38 +000026#define ARM_EXCEPTION_IS_TRAP(x) \
27 (ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_PREF_ABORT || \
28 ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_DATA_ABORT || \
29 ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_HVC)
Marc Zyngier435bca52016-09-06 14:02:11 +010030#define ARM_ABORT_PENDING(x) !!((x) & (1U << ARM_EXIT_WITH_ABORT_BIT))
31
Christoffer Dall749cf76c2013-01-20 18:28:06 -050032#define ARM_EXCEPTION_RESET 0
33#define ARM_EXCEPTION_UNDEFINED 1
34#define ARM_EXCEPTION_SOFTWARE 2
35#define ARM_EXCEPTION_PREF_ABORT 3
36#define ARM_EXCEPTION_DATA_ABORT 4
37#define ARM_EXCEPTION_IRQ 5
38#define ARM_EXCEPTION_FIQ 6
Christoffer Dall342cd0a2013-01-20 18:28:06 -050039#define ARM_EXCEPTION_HVC 7
Marc Zyngier386627d2017-04-03 19:37:58 +010040#define ARM_EXCEPTION_HYP_GONE HVC_STUB_ERR
Victor Kamensky19b0e602014-06-12 09:30:02 -070041/*
42 * The rr_lo_hi macro swaps a pair of registers depending on
43 * current endianness. It is used in conjunction with ldrd and strd
44 * instructions that load/store a 64-bit value from/to memory to/from
45 * a pair of registers which are used with the mrrc and mcrr instructions.
46 * If used with the ldrd/strd instructions, the a1 parameter is the first
47 * source/destination register and the a2 parameter is the second
48 * source/destination register. Note that the ldrd/strd instructions
49 * already swap the bytes within the words correctly according to the
50 * endianness setting, but the order of the registers need to be effectively
51 * swapped when used with the mrrc/mcrr instructions.
52 */
53#ifdef CONFIG_CPU_ENDIAN_BE8
54#define rr_lo_hi(a1, a2) a2, a1
55#else
56#define rr_lo_hi(a1, a2) a1, a2
57#endif
58
Ard Biesheuvela0bf9772016-02-16 13:52:39 +010059#define kvm_ksym_ref(kva) (kva)
60
Christoffer Dall342cd0a2013-01-20 18:28:06 -050061#ifndef __ASSEMBLY__
Christoffer Dalld5d81842013-01-20 18:28:07 -050062struct kvm;
Christoffer Dall342cd0a2013-01-20 18:28:06 -050063struct kvm_vcpu;
64
65extern char __kvm_hyp_init[];
66extern char __kvm_hyp_init_end[];
67
Christoffer Dall342cd0a2013-01-20 18:28:06 -050068extern void __kvm_flush_vm_context(void);
Marc Zyngier48762762013-01-28 15:27:00 +000069extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
Mario Smarduch72fc36b2015-01-15 15:58:55 -080070extern void __kvm_tlb_flush_vmid(struct kvm *kvm);
Marc Zyngier94d0e592016-10-18 18:37:49 +010071extern void __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu);
Christoffer Dall342cd0a2013-01-20 18:28:06 -050072
Christoffer Dall688c50a2017-01-04 16:10:28 +010073extern void __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high);
74
Christoffer Dall3f5c90b2017-10-03 14:02:12 +020075/* no VHE on 32-bit :( */
76static inline int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) { BUG(); return 0; }
77
78extern int __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu);
Marc Zyngierd4c76882016-02-01 19:56:31 +000079
80extern void __init_stage2_translation(void);
Marc Zyngiere537ecd2016-06-30 18:40:48 +010081
Vladimir Murzinacda5432016-09-12 15:49:24 +010082extern u64 __vgic_v3_get_ich_vtr_el2(void);
Christoffer Dall328e5662016-03-24 11:21:04 +010083extern u64 __vgic_v3_read_vmcr(void);
84extern void __vgic_v3_write_vmcr(u32 vmcr);
Vladimir Murzinacda5432016-09-12 15:49:24 +010085extern void __vgic_v3_init_lrs(void);
Christoffer Dall328e5662016-03-24 11:21:04 +010086
Christoffer Dall342cd0a2013-01-20 18:28:06 -050087#endif
Christoffer Dall749cf76c2013-01-20 18:28:06 -050088
89#endif /* __ARM_KVM_ASM_H__ */