Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awilliam
GitHub Repository: awilliam/linux-vfio
Path: blob/master/arch/ia64/kvm/misc.h
10817 views
1
#ifndef __KVM_IA64_MISC_H
2
#define __KVM_IA64_MISC_H
3
4
#include <linux/kvm_host.h>
5
/*
6
* misc.h
7
* Copyright (C) 2007, Intel Corporation.
8
* Xiantao Zhang ([email protected])
9
*
10
* This program is free software; you can redistribute it and/or modify it
11
* under the terms and conditions of the GNU General Public License,
12
* version 2, as published by the Free Software Foundation.
13
*
14
* This program is distributed in the hope it will be useful, but WITHOUT
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
* more details.
18
*
19
* You should have received a copy of the GNU General Public License along with
20
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21
* Place - Suite 330, Boston, MA 02111-1307 USA.
22
*
23
*/
24
25
/*
26
*Return p2m base address at host side!
27
*/
28
static inline uint64_t *kvm_host_get_pmt(struct kvm *kvm)
29
{
30
return (uint64_t *)(kvm->arch.vm_base +
31
offsetof(struct kvm_vm_data, kvm_p2m));
32
}
33
34
static inline void kvm_set_pmt_entry(struct kvm *kvm, gfn_t gfn,
35
u64 paddr, u64 mem_flags)
36
{
37
uint64_t *pmt_base = kvm_host_get_pmt(kvm);
38
unsigned long pte;
39
40
pte = PAGE_ALIGN(paddr) | mem_flags;
41
pmt_base[gfn] = pte;
42
}
43
44
/*Function for translating host address to guest address*/
45
46
static inline void *to_guest(struct kvm *kvm, void *addr)
47
{
48
return (void *)((unsigned long)(addr) - kvm->arch.vm_base +
49
KVM_VM_DATA_BASE);
50
}
51
52
/*Function for translating guest address to host address*/
53
54
static inline void *to_host(struct kvm *kvm, void *addr)
55
{
56
return (void *)((unsigned long)addr - KVM_VM_DATA_BASE
57
+ kvm->arch.vm_base);
58
}
59
60
/* Get host context of the vcpu */
61
static inline union context *kvm_get_host_context(struct kvm_vcpu *vcpu)
62
{
63
union context *ctx = &vcpu->arch.host;
64
return to_guest(vcpu->kvm, ctx);
65
}
66
67
/* Get guest context of the vcpu */
68
static inline union context *kvm_get_guest_context(struct kvm_vcpu *vcpu)
69
{
70
union context *ctx = &vcpu->arch.guest;
71
return to_guest(vcpu->kvm, ctx);
72
}
73
74
/* kvm get exit data from gvmm! */
75
static inline struct exit_ctl_data *kvm_get_exit_data(struct kvm_vcpu *vcpu)
76
{
77
return &vcpu->arch.exit_data;
78
}
79
80
/*kvm get vcpu ioreq for kvm module!*/
81
static inline struct kvm_mmio_req *kvm_get_vcpu_ioreq(struct kvm_vcpu *vcpu)
82
{
83
struct exit_ctl_data *p_ctl_data;
84
85
if (vcpu) {
86
p_ctl_data = kvm_get_exit_data(vcpu);
87
if (p_ctl_data->exit_reason == EXIT_REASON_MMIO_INSTRUCTION)
88
return &p_ctl_data->u.ioreq;
89
}
90
91
return NULL;
92
}
93
94
#endif
95
96