xref: /kvmtool/arm/include/arm-common/kvm-arch.h (revision dbfef85064420f1e98d53eb63b17e3162fe0b7e6)
1 #ifndef ARM_COMMON__KVM_ARCH_H
2 #define ARM_COMMON__KVM_ARCH_H
3 
4 #include <stdbool.h>
5 #include <linux/const.h>
6 #include <linux/types.h>
7 
8 #define ARM_IOPORT_AREA		_AC(0x0000000000000000, UL)
9 #define ARM_MMIO_AREA		_AC(0x0000000000010000, UL)
10 #define ARM_AXI_AREA		_AC(0x0000000040000000, UL)
11 #define ARM_MEMORY_AREA		_AC(0x0000000080000000, UL)
12 
13 #define ARM_LOMAP_MAX_MEMORY	((1ULL << 32) - ARM_MEMORY_AREA)
14 #define ARM_HIMAP_MAX_MEMORY	((1ULL << 40) - ARM_MEMORY_AREA)
15 
16 #define ARM_GIC_DIST_BASE	(ARM_AXI_AREA - ARM_GIC_DIST_SIZE)
17 #define ARM_GIC_CPUI_BASE	(ARM_GIC_DIST_BASE - ARM_GIC_CPUI_SIZE)
18 #define ARM_GIC_SIZE		(ARM_GIC_DIST_SIZE + ARM_GIC_CPUI_SIZE)
19 
20 #define ARM_IOPORT_SIZE		(ARM_MMIO_AREA - ARM_IOPORT_AREA)
21 #define ARM_VIRTIO_MMIO_SIZE	(ARM_AXI_AREA - (ARM_MMIO_AREA + ARM_GIC_SIZE))
22 #define ARM_PCI_MMIO_SIZE	(ARM_MEMORY_AREA - ARM_AXI_AREA)
23 
24 #define KVM_IOPORT_AREA		ARM_IOPORT_AREA
25 #define KVM_PCI_MMIO_AREA	ARM_AXI_AREA
26 #define KVM_VIRTIO_MMIO_AREA	ARM_MMIO_AREA
27 
28 #define VIRTIO_DEFAULT_TRANS	VIRTIO_MMIO
29 
30 static inline bool arm_addr_in_ioport_region(u64 phys_addr)
31 {
32 	u64 limit = KVM_IOPORT_AREA + ARM_IOPORT_SIZE;
33 	return phys_addr >= KVM_IOPORT_AREA && phys_addr < limit;
34 }
35 
36 static inline bool arm_addr_in_virtio_mmio_region(u64 phys_addr)
37 {
38 	u64 limit = KVM_VIRTIO_MMIO_AREA + ARM_VIRTIO_MMIO_SIZE;
39 	return phys_addr >= KVM_VIRTIO_MMIO_AREA && phys_addr < limit;
40 }
41 
42 static inline bool arm_addr_in_pci_mmio_region(u64 phys_addr)
43 {
44 	u64 limit = KVM_PCI_MMIO_AREA + ARM_PCI_MMIO_SIZE;
45 	return phys_addr >= KVM_PCI_MMIO_AREA && phys_addr < limit;
46 }
47 
48 struct kvm_arch {
49 	/*
50 	 * We may have to align the guest memory for virtio, so keep the
51 	 * original pointers here for munmap.
52 	 */
53 	void	*ram_alloc_start;
54 	u64	ram_alloc_size;
55 
56 	/*
57 	 * Guest addresses for memory layout.
58 	 */
59 	u64	memory_guest_start;
60 	u64	kern_guest_start;
61 	u64	initrd_guest_start;
62 	u64	initrd_size;
63 	u64	dtb_guest_start;
64 };
65 
66 #endif /* ARM_COMMON__KVM_ARCH_H */
67