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