blob: c0edd450e10459612e37cc292ad8585494d12773 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/*
2 * Original code:
3 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
4 * Author: Christoffer Dall <c.dall@virtualopensystems.com>
5 *
6 * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <asm/kvm_hyp.h>
22#include <asm/kvm_mmu.h>
23
24/**
25 * Flush per-VMID TLBs
26 *
27 * __kvm_tlb_flush_vmid(struct kvm *kvm);
28 *
29 * We rely on the hardware to broadcast the TLB invalidation to all CPUs
30 * inside the inner-shareable domain (which is the case for all v7
31 * implementations). If we come across a non-IS SMP implementation, we'll
32 * have to use an IPI based mechanism. Until then, we stick to the simple
33 * hardware assisted version.
34 *
35 * As v7 does not support flushing per IPA, just nuke the whole TLB
36 * instead, ignoring the ipa value.
37 */
38void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
39{
40 dsb(ishst);
41
42 /* Switch to requested VMID */
43 kvm = kern_hyp_va(kvm);
44 write_sysreg(kvm->arch.vttbr, VTTBR);
45 isb();
46
47 write_sysreg(0, TLBIALLIS);
48 dsb(ish);
49 isb();
50
51 write_sysreg(0, VTTBR);
52}
53
54void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
55{
56 __kvm_tlb_flush_vmid(kvm);
57}
58
59void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
60{
61 struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm);
62
63 /* Switch to requested VMID */
64 write_sysreg(kvm->arch.vttbr, VTTBR);
65 isb();
66
67 write_sysreg(0, TLBIALL);
68 dsb(nsh);
69 isb();
70
71 write_sysreg(0, VTTBR);
72}
73
74void __hyp_text __kvm_flush_vm_context(void)
75{
76 write_sysreg(0, TLBIALLNSNHIS);
77 write_sysreg(0, ICIALLUIS);
78 dsb(ish);
79}