xref: /kvmtool/arm/include/arm-common/kvm-arch.h (revision fc9d8ec3e459b744c012b9c82924aa397099ab19)
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 #include "arm-common/gic.h"
9 
10 #define ARM_IOPORT_AREA		_AC(0x0000000000000000, UL)
11 #define ARM_MMIO_AREA		_AC(0x0000000000010000, UL)
12 #define ARM_AXI_AREA		_AC(0x0000000040000000, UL)
13 #define ARM_MEMORY_AREA		_AC(0x0000000080000000, UL)
14 
15 #define ARM_LOMAP_MAX_MEMORY	((1ULL << 32) - ARM_MEMORY_AREA)
16 #define ARM_HIMAP_MAX_MEMORY	((1ULL << 40) - ARM_MEMORY_AREA)
17 
18 #define ARM_GIC_DIST_BASE	(ARM_AXI_AREA - ARM_GIC_DIST_SIZE)
19 #define ARM_GIC_CPUI_BASE	(ARM_GIC_DIST_BASE - ARM_GIC_CPUI_SIZE)
20 #define ARM_GIC_SIZE		(ARM_GIC_DIST_SIZE + ARM_GIC_CPUI_SIZE)
21 
22 #define ARM_IOPORT_SIZE		(ARM_MMIO_AREA - ARM_IOPORT_AREA)
23 #define ARM_VIRTIO_MMIO_SIZE	(ARM_AXI_AREA - (ARM_MMIO_AREA + ARM_GIC_SIZE))
24 #define ARM_PCI_CFG_SIZE	(1ULL << 24)
25 #define ARM_PCI_MMIO_SIZE	(ARM_MEMORY_AREA - \
26 				(ARM_AXI_AREA + ARM_PCI_CFG_SIZE))
27 
28 #define KVM_IOPORT_AREA		ARM_IOPORT_AREA
29 #define KVM_PCI_CFG_AREA	ARM_AXI_AREA
30 #define KVM_PCI_MMIO_AREA	(KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE)
31 #define KVM_VIRTIO_MMIO_AREA	ARM_MMIO_AREA
32 
33 #define KVM_IRQ_OFFSET		GIC_SPI_IRQ_BASE
34 
35 #define VIRTIO_DEFAULT_TRANS(kvm)	\
36 	((kvm)->cfg.arch.virtio_trans_pci ? VIRTIO_PCI : VIRTIO_MMIO)
37 
38 #define VIRTIO_RING_ENDIAN	(VIRTIO_ENDIAN_LE | VIRTIO_ENDIAN_BE)
39 
40 static inline bool arm_addr_in_ioport_region(u64 phys_addr)
41 {
42 	u64 limit = KVM_IOPORT_AREA + ARM_IOPORT_SIZE;
43 	return phys_addr >= KVM_IOPORT_AREA && phys_addr < limit;
44 }
45 
46 static inline bool arm_addr_in_virtio_mmio_region(u64 phys_addr)
47 {
48 	u64 limit = KVM_VIRTIO_MMIO_AREA + ARM_VIRTIO_MMIO_SIZE;
49 	return phys_addr >= KVM_VIRTIO_MMIO_AREA && phys_addr < limit;
50 }
51 
52 static inline bool arm_addr_in_pci_region(u64 phys_addr)
53 {
54 	u64 limit = KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE + ARM_PCI_MMIO_SIZE;
55 	return phys_addr >= KVM_PCI_CFG_AREA && phys_addr < limit;
56 }
57 
58 struct kvm_arch {
59 	/*
60 	 * We may have to align the guest memory for virtio, so keep the
61 	 * original pointers here for munmap.
62 	 */
63 	void	*ram_alloc_start;
64 	u64	ram_alloc_size;
65 
66 	/*
67 	 * Guest addresses for memory layout.
68 	 */
69 	u64	memory_guest_start;
70 	u64	kern_guest_start;
71 	u64	initrd_guest_start;
72 	u64	initrd_size;
73 	u64	dtb_guest_start;
74 };
75 
76 #endif /* ARM_COMMON__KVM_ARCH_H */
77