1
2
3
4
5
6
7
8 #ifndef SELFTEST_KVM_UTIL_INTERNAL_H
9 #define SELFTEST_KVM_UTIL_INTERNAL_H
10
11 #include "sparsebit.h"
12
13 #define KVM_DEV_PATH "/dev/kvm"
14
15 #ifndef BITS_PER_BYTE
16 #define BITS_PER_BYTE 8
17 #endif
18
19 #ifndef BITS_PER_LONG
20 #define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long))
21 #endif
22
23 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
24 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_LONG)
25
26 struct userspace_mem_region {
27 struct userspace_mem_region *next, *prev;
28 struct kvm_userspace_memory_region region;
29 struct sparsebit *unused_phy_pages;
30 int fd;
31 off_t offset;
32 void *host_mem;
33 void *mmap_start;
34 size_t mmap_size;
35 };
36
37 struct vcpu {
38 struct vcpu *next, *prev;
39 uint32_t id;
40 int fd;
41 struct kvm_run *state;
42 };
43
44 struct kvm_vm {
45 int mode;
46 unsigned long type;
47 int kvm_fd;
48 int fd;
49 unsigned int pgtable_levels;
50 unsigned int page_size;
51 unsigned int page_shift;
52 unsigned int pa_bits;
53 unsigned int va_bits;
54 uint64_t max_gfn;
55 struct vcpu *vcpu_head;
56 struct userspace_mem_region *userspace_mem_region_head;
57 struct sparsebit *vpages_valid;
58 struct sparsebit *vpages_mapped;
59 bool has_irqchip;
60 bool pgd_created;
61 vm_paddr_t pgd;
62 vm_vaddr_t gdt;
63 vm_vaddr_t tss;
64 };
65
66 struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid);
67 void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
68 void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent);
69 void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent);
70
71 struct userspace_mem_region *
72 memslot2region(struct kvm_vm *vm, uint32_t memslot);
73
74 #endif