Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / kvm / lib / kvm_util_internal.h
blob542ed606b338c7884f3c9e4bd58abc8b0e6248bf
1 /*
2 * tools/testing/selftests/kvm/lib/kvm_util.c
4 * Copyright (C) 2018, Google LLC.
6 * This work is licensed under the terms of the GNU GPL, version 2.
7 */
9 #ifndef KVM_UTIL_INTERNAL_H
10 #define KVM_UTIL_INTERNAL_H 1
12 #include "sparsebit.h"
14 #ifndef BITS_PER_BYTE
15 #define BITS_PER_BYTE 8
16 #endif
18 #ifndef BITS_PER_LONG
19 #define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long))
20 #endif
22 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
23 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_LONG)
25 /* Concrete definition of struct kvm_vm. */
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;
37 struct vcpu {
38 struct vcpu *next, *prev;
39 uint32_t id;
40 int fd;
41 struct kvm_run *state;
44 struct kvm_vm {
45 int mode;
46 int kvm_fd;
47 int fd;
48 unsigned int page_size;
49 unsigned int page_shift;
50 uint64_t max_gfn;
51 struct vcpu *vcpu_head;
52 struct userspace_mem_region *userspace_mem_region_head;
53 struct sparsebit *vpages_valid;
54 struct sparsebit *vpages_mapped;
56 bool has_irqchip;
57 bool pgd_created;
58 vm_paddr_t pgd;
59 vm_vaddr_t gdt;
60 vm_vaddr_t tss;
63 struct vcpu *vcpu_find(struct kvm_vm *vm,
64 uint32_t vcpuid);
65 void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_memslot);
66 void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
67 void regs_dump(FILE *stream, struct kvm_regs *regs,
68 uint8_t indent);
69 void sregs_dump(FILE *stream, struct kvm_sregs *sregs,
70 uint8_t indent);
72 #endif