3 * Copyright (c) 2015 Linaro Limited
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2 or later, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
17 * Emulate a virtual board which works by passing Linux all the information
18 * it needs about what devices are present via the device tree.
19 * There are some restrictions about what we can do here:
20 * + we can only present devices whose Linux drivers will work based
21 * purely on the device tree with no platform data at all
22 * + we want to present a very stripped-down minimalist platform,
23 * both because this reduces the security attack surface from the guest
24 * and also because it reduces our exposure to being broken when
25 * the kernel updates its device tree bindings and requires further
26 * information in a device binding that we aren't providing.
27 * This is essentially the same approach kvmtool uses.
30 #ifndef QEMU_ARM_VIRT_H
31 #define QEMU_ARM_VIRT_H
33 #include "exec/hwaddr.h"
34 #include "qemu/notify.h"
35 #include "hw/boards.h"
36 #include "hw/arm/boot.h"
37 #include "hw/block/flash.h"
38 #include "sysemu/kvm.h"
39 #include "hw/intc/arm_gicv3_common.h"
40 #include "qom/object.h"
42 #define NUM_GICV2M_SPIS 64
43 #define NUM_VIRTIO_TRANSPORTS 32
44 #define NUM_SMMU_IRQS 4
46 #define ARCH_GIC_MAINT_IRQ 9
48 #define ARCH_TIMER_VIRT_IRQ 11
49 #define ARCH_TIMER_S_EL1_IRQ 13
50 #define ARCH_TIMER_NS_EL1_IRQ 14
51 #define ARCH_TIMER_NS_EL2_IRQ 10
53 #define VIRTUAL_PMU_IRQ 7
55 #define PPI(irq) ((irq) + 16)
57 /* See Linux kernel arch/arm64/include/asm/pvclock-abi.h */
58 #define PVTIME_SIZE_PER_CPU 64
92 /* indices of IO regions located after the RAM */
94 VIRT_HIGH_GIC_REDIST2
= VIRT_LOWMEMMAP_LAST
,
99 typedef enum VirtIOMMUType
{
105 typedef enum VirtMSIControllerType
{
107 VIRT_MSI_CTRL_GICV2M
,
109 } VirtMSIControllerType
;
111 typedef enum VirtGICType
{
112 VIRT_GIC_VERSION_MAX
,
113 VIRT_GIC_VERSION_HOST
,
117 VIRT_GIC_VERSION_NOSEL
,
120 struct VirtMachineClass
{
122 bool disallow_affinity_adjustment
;
126 bool claim_edge_triggered_timers
;
127 bool smbios_old_sys_ver
;
128 bool no_highmem_ecam
;
129 bool no_ged
; /* Machines < 4.2 have no support for ACPI GED device */
130 bool kvm_no_adjvtime
;
131 bool no_kvm_steal_time
;
132 bool acpi_expose_flash
;
134 /* Machines < 6.2 have no support for describing cpu topology to guest */
135 bool no_cpu_topology
;
139 struct VirtMachineState
{
141 Notifier machine_done
;
142 DeviceState
*platform_bus_dev
;
144 PFlashCFI01
*flash
[2];
147 bool highmem_compact
;
150 bool highmem_redists
;
158 VirtGICType gic_version
;
160 bool default_bus_bypass_iommu
;
161 VirtMSIControllerType msi_controller
;
162 uint16_t virtio_iommu_bdf
;
163 struct arm_boot_info bootinfo
;
165 char *pciehb_nodename
;
168 uint32_t clock_phandle
;
169 uint32_t gic_phandle
;
170 uint32_t msi_phandle
;
171 uint32_t iommu_phandle
;
175 DeviceState
*acpi_dev
;
176 Notifier powerdown_notifier
;
182 #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
184 #define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
185 OBJECT_DECLARE_TYPE(VirtMachineState
, VirtMachineClass
, VIRT_MACHINE
)
187 void virt_acpi_setup(VirtMachineState
*vms
);
188 bool virt_is_acpi_enabled(VirtMachineState
*vms
);
190 /* Return number of redistributors that fit in the specified region */
191 static uint32_t virt_redist_capacity(VirtMachineState
*vms
, int region
)
193 uint32_t redist_size
;
195 if (vms
->gic_version
== VIRT_GIC_VERSION_3
) {
196 redist_size
= GICV3_REDIST_SIZE
;
198 redist_size
= GICV4_REDIST_SIZE
;
200 return vms
->memmap
[region
].size
/ redist_size
;
203 /* Return the number of used redistributor regions */
204 static inline int virt_gicv3_redist_region_count(VirtMachineState
*vms
)
206 uint32_t redist0_capacity
= virt_redist_capacity(vms
, VIRT_GIC_REDIST
);
208 assert(vms
->gic_version
!= VIRT_GIC_VERSION_2
);
210 return (MACHINE(vms
)->smp
.cpus
> redist0_capacity
&&
211 vms
->highmem_redists
) ? 2 : 1;
214 #endif /* QEMU_ARM_VIRT_H */