xref: /kvmtool/arm/include/arm-common/kvm-arch.h (revision b0d56e3c994a0feb3ffb519cecda5c1f6da8b1ab)
1 #ifndef ARM_COMMON__KVM_ARCH_H
2 #define ARM_COMMON__KVM_ARCH_H
3 
4 #include <stdbool.h>
5 #ifndef _GNU_SOURCE
6 #define _GNU_SOURCE
7 #endif
8 #include <sched.h>
9 
10 #include <linux/const.h>
11 #include <linux/types.h>
12 
13 #include "arm-common/gic.h"
14 
15 /*
16  * The memory map used for ARM guests (not to scale):
17  *
18  * 0      64K  16M     32M     48M            1GB       2GB
19  * +-------+----+-------+-------+--------+-----+---------+---......
20  * |  PCI  |////| plat  |       |        |     |         |
21  * |  I/O  |////| MMIO: | Flash | virtio | GIC |   PCI   |  DRAM
22  * | space |////| UART, |       |  MMIO  |     |  (AXI)  |
23  * |       |////| RTC,  |       |        |     |         |
24  * |       |////| PVTIME|       |        |     |         |
25  * +-------+----+-------+-------+--------+-----+---------+---......
26  */
27 
28 #define ARM_IOPORT_AREA		_AC(0x0000000000000000, UL)
29 #define ARM_MMIO_AREA		_AC(0x0000000001000000, UL)
30 #define ARM_AXI_AREA		_AC(0x0000000040000000, UL)
31 #define ARM_MEMORY_AREA		_AC(0x0000000080000000, UL)
32 
33 #define KVM_IOPORT_AREA		ARM_IOPORT_AREA
34 #define ARM_IOPORT_SIZE		(1U << 16)
35 
36 
37 #define ARM_UART_MMIO_BASE	ARM_MMIO_AREA
38 #define ARM_UART_MMIO_SIZE	0x10000
39 
40 #define ARM_RTC_MMIO_BASE	(ARM_UART_MMIO_BASE + ARM_UART_MMIO_SIZE)
41 #define ARM_RTC_MMIO_SIZE	0x10000
42 
43 #define ARM_PVTIME_BASE		(ARM_RTC_MMIO_BASE + ARM_RTC_MMIO_SIZE)
44 #define ARM_PVTIME_SIZE		SZ_64K
45 
46 #define KVM_FLASH_MMIO_BASE	(ARM_MMIO_AREA + 0x1000000)
47 #define KVM_FLASH_MAX_SIZE	0x1000000
48 
49 #define KVM_VIRTIO_MMIO_AREA	(KVM_FLASH_MMIO_BASE + KVM_FLASH_MAX_SIZE)
50 #define ARM_VIRTIO_MMIO_SIZE	(ARM_AXI_AREA - \
51 				(KVM_VIRTIO_MMIO_AREA + ARM_GIC_SIZE))
52 
53 #define ARM_GIC_DIST_BASE	(ARM_AXI_AREA - ARM_GIC_DIST_SIZE)
54 #define ARM_GIC_CPUI_BASE	(ARM_GIC_DIST_BASE - ARM_GIC_CPUI_SIZE)
55 #define ARM_GIC_SIZE		(ARM_GIC_DIST_SIZE + ARM_GIC_CPUI_SIZE)
56 #define ARM_GIC_DIST_SIZE	0x10000
57 #define ARM_GIC_CPUI_SIZE	0x20000
58 
59 
60 #define KVM_PCI_CFG_AREA	ARM_AXI_AREA
61 #define ARM_PCI_CFG_SIZE	(1ULL << 28)
62 #define KVM_PCI_MMIO_AREA	(KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE)
63 #define ARM_PCI_MMIO_SIZE	(ARM_MEMORY_AREA - \
64 				(ARM_AXI_AREA + ARM_PCI_CFG_SIZE))
65 
66 
67 #define ARM_LOMAP_MAX_MEMORY	((1ULL << 32) - ARM_MEMORY_AREA)
68 
69 
70 #define KVM_IOEVENTFD_HAS_PIO	0
71 
72 /*
73  * On a GICv3 there must be one redistributor per vCPU.
74  * The value here is the size for one, we multiply this at runtime with
75  * the number of requested vCPUs to get the actual size.
76  */
77 #define ARM_GIC_REDIST_SIZE	0x20000
78 
79 #define KVM_IRQ_OFFSET		GIC_SPI_IRQ_BASE
80 
81 #define KVM_VM_TYPE		0
82 
83 #define VIRTIO_DEFAULT_TRANS(kvm)					\
84 	((kvm)->cfg.arch.virtio_trans_pci ?				\
85 	 ((kvm)->cfg.virtio_legacy ? VIRTIO_PCI_LEGACY : VIRTIO_PCI) :	\
86 	 VIRTIO_MMIO)
87 
88 #define VIRTIO_RING_ENDIAN	(VIRTIO_ENDIAN_LE | VIRTIO_ENDIAN_BE)
89 
90 #define ARCH_HAS_PCI_EXP	1
91 
92 static inline bool arm_addr_in_ioport_region(u64 phys_addr)
93 {
94 	u64 limit = KVM_IOPORT_AREA + ARM_IOPORT_SIZE;
95 	return phys_addr >= KVM_IOPORT_AREA && phys_addr < limit;
96 }
97 
98 struct kvm_arch {
99 	/*
100 	 * We may have to align the guest memory for virtio, so keep the
101 	 * original pointers here for munmap.
102 	 */
103 	void	*ram_alloc_start;
104 	u64	ram_alloc_size;
105 
106 	/*
107 	 * Guest addresses for memory layout.
108 	 */
109 	u64	memory_guest_start;
110 	u64	kern_guest_start;
111 	u64	initrd_guest_start;
112 	u64	initrd_size;
113 	u64	dtb_guest_start;
114 
115 	cpu_set_t *vcpu_affinity_cpuset;
116 };
117 
118 #endif /* ARM_COMMON__KVM_ARCH_H */
119