]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/arm/virt.h
Merge tag 'mips-20230113' of https://github.com/philmd/qemu into staging
[mirror_qemu.git] / include / hw / arm / virt.h
CommitLineData
afe0b380
SZ
1/*
2 *
3 * Copyright (c) 2015 Linaro Limited
4 *
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.
8 *
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
12 * more details.
13 *
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/>.
16 *
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.
28 */
29
30#ifndef QEMU_ARM_VIRT_H
31#define QEMU_ARM_VIRT_H
32
33c11879 33#include "exec/hwaddr.h"
d05fdab4 34#include "qemu/notify.h"
a72d4363 35#include "hw/boards.h"
12ec8bd5 36#include "hw/arm/boot.h"
e0561e60 37#include "hw/block/flash.h"
f90747c4
EA
38#include "sysemu/kvm.h"
39#include "hw/intc/arm_gicv3_common.h"
db1015e9 40#include "qom/object.h"
afe0b380 41
bd204e63 42#define NUM_GICV2M_SPIS 64
afe0b380 43#define NUM_VIRTIO_TRANSPORTS 32
584105ea 44#define NUM_SMMU_IRQS 4
afe0b380 45
55ef3233 46#define ARCH_GIC_MAINT_IRQ 9
5454006a 47
ee246400
SZ
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
52
01fe6b60
SZ
53#define VIRTUAL_PMU_IRQ 7
54
55#define PPI(irq) ((irq) + 16)
56
68970d1e
AJ
57/* See Linux kernel arch/arm64/include/asm/pvclock-abi.h */
58#define PVTIME_SIZE_PER_CPU 64
59
afe0b380
SZ
60enum {
61 VIRT_FLASH,
62 VIRT_MEM,
63 VIRT_CPUPERIPHS,
64 VIRT_GIC_DIST,
65 VIRT_GIC_CPU,
b92ad394 66 VIRT_GIC_V2M,
55ef3233
LM
67 VIRT_GIC_HYP,
68 VIRT_GIC_VCPU,
b92ad394
PF
69 VIRT_GIC_ITS,
70 VIRT_GIC_REDIST,
584105ea 71 VIRT_SMMU,
afe0b380
SZ
72 VIRT_UART,
73 VIRT_MMIO,
74 VIRT_RTC,
75 VIRT_FW_CFG,
76 VIRT_PCIE,
6a1f001b
SZ
77 VIRT_PCIE_MMIO,
78 VIRT_PCIE_PIO,
79 VIRT_PCIE_ECAM,
5f7a5a0e 80 VIRT_PLATFORM_BUS,
b0a3721e 81 VIRT_GPIO,
3df708eb 82 VIRT_SECURE_UART,
83ec1923 83 VIRT_SECURE_MEM,
daa726d9 84 VIRT_SECURE_GPIO,
cff51ac9
SK
85 VIRT_PCDIMM_ACPI,
86 VIRT_ACPI_GED,
b5a60bee 87 VIRT_NVDIMM_ACPI,
68970d1e 88 VIRT_PVTIME,
350a9c9e
EA
89 VIRT_LOWMEMMAP_LAST,
90};
91
92/* indices of IO regions located after the RAM */
93enum {
94 VIRT_HIGH_GIC_REDIST2 = VIRT_LOWMEMMAP_LAST,
95 VIRT_HIGH_PCIE_ECAM,
96 VIRT_HIGH_PCIE_MMIO,
afe0b380
SZ
97};
98
584105ea
PM
99typedef enum VirtIOMMUType {
100 VIRT_IOMMU_NONE,
101 VIRT_IOMMU_SMMUV3,
102 VIRT_IOMMU_VIRTIO,
103} VirtIOMMUType;
104
1b6f99d8
EA
105typedef enum VirtMSIControllerType {
106 VIRT_MSI_CTRL_NONE,
107 VIRT_MSI_CTRL_GICV2M,
108 VIRT_MSI_CTRL_ITS,
109} VirtMSIControllerType;
110
d04460e5
EA
111typedef enum VirtGICType {
112 VIRT_GIC_VERSION_MAX,
113 VIRT_GIC_VERSION_HOST,
114 VIRT_GIC_VERSION_2,
115 VIRT_GIC_VERSION_3,
7cf3f8d2 116 VIRT_GIC_VERSION_4,
36bf4ec8 117 VIRT_GIC_VERSION_NOSEL,
d04460e5
EA
118} VirtGICType;
119
db1015e9 120struct VirtMachineClass {
a72d4363
AJ
121 MachineClass parent;
122 bool disallow_affinity_adjustment;
123 bool no_its;
0e5c1c9a 124 bool no_tcg_its;
a72d4363
AJ
125 bool no_pmu;
126 bool claim_edge_triggered_timers;
dfadc3bf 127 bool smbios_old_sys_ver;
f40408a9 128 bool no_highmem_compact;
17ec075a 129 bool no_highmem_ecam;
31511b6f 130 bool no_ged; /* Machines < 4.2 have no support for ACPI GED device */
dea101a1 131 bool kvm_no_adjvtime;
68970d1e 132 bool no_kvm_steal_time;
2c1fb4d5 133 bool acpi_expose_flash;
daa726d9 134 bool no_secure_gpio;
31511b6f
YW
135 /* Machines < 6.2 have no support for describing cpu topology to guest */
136 bool no_cpu_topology;
09428204 137 bool no_tcg_lpa2;
db1015e9 138};
a72d4363 139
db1015e9 140struct VirtMachineState {
a72d4363 141 MachineState parent;
a72d4363 142 Notifier machine_done;
a3fc8396 143 DeviceState *platform_bus_dev;
af1f60a4 144 FWCfgState *fw_cfg;
e0561e60 145 PFlashCFI01 *flash[2];
a72d4363
AJ
146 bool secure;
147 bool highmem;
4a4ff9ed 148 bool highmem_compact;
601d626d 149 bool highmem_ecam;
c8f008c4 150 bool highmem_mmio;
a63618b1 151 bool highmem_redists;
ccc11b02 152 bool its;
0e5c1c9a 153 bool tcg_its;
f29cacfb 154 bool virt;
2afa8c85 155 bool ras;
6f4e1405 156 bool mte;
5242876f 157 bool dtb_randomness;
17e89077 158 OnOffAuto acpi;
d04460e5 159 VirtGICType gic_version;
584105ea 160 VirtIOMMUType iommu;
6d7a8548 161 bool default_bus_bypass_iommu;
1b6f99d8 162 VirtMSIControllerType msi_controller;
70e89132 163 uint16_t virtio_iommu_bdf;
a72d4363 164 struct arm_boot_info bootinfo;
350a9c9e 165 MemMapEntry *memmap;
70e89132 166 char *pciehb_nodename;
a72d4363 167 const int *irqmap;
a72d4363
AJ
168 int fdt_size;
169 uint32_t clock_phandle;
170 uint32_t gic_phandle;
171 uint32_t msi_phandle;
584105ea 172 uint32_t iommu_phandle;
2013c566 173 int psci_conduit;
957e32cf 174 hwaddr highest_gpa;
b8b69f4c 175 DeviceState *gic;
cff51ac9 176 DeviceState *acpi_dev;
c345680c 177 Notifier powerdown_notifier;
09fad167 178 PCIBus *bus;
602b4582
MP
179 char *oem_id;
180 char *oem_table_id;
db1015e9 181};
a72d4363 182
bf424a12 183#define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
601d626d 184
a72d4363 185#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
a489d195 186OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)
a72d4363 187
e9a8e474 188void virt_acpi_setup(VirtMachineState *vms);
17e89077 189bool virt_is_acpi_enabled(VirtMachineState *vms);
d05fdab4 190
f31985a7
PM
191/* Return number of redistributors that fit in the specified region */
192static uint32_t virt_redist_capacity(VirtMachineState *vms, int region)
193{
7cf3f8d2
PM
194 uint32_t redist_size;
195
196 if (vms->gic_version == VIRT_GIC_VERSION_3) {
197 redist_size = GICV3_REDIST_SIZE;
198 } else {
199 redist_size = GICV4_REDIST_SIZE;
200 }
201 return vms->memmap[region].size / redist_size;
f31985a7
PM
202}
203
f90747c4
EA
204/* Return the number of used redistributor regions */
205static inline int virt_gicv3_redist_region_count(VirtMachineState *vms)
206{
f31985a7 207 uint32_t redist0_capacity = virt_redist_capacity(vms, VIRT_GIC_REDIST);
f90747c4 208
7cf3f8d2 209 assert(vms->gic_version != VIRT_GIC_VERSION_2);
f90747c4 210
a63618b1
MZ
211 return (MACHINE(vms)->smp.cpus > redist0_capacity &&
212 vms->highmem_redists) ? 2 : 1;
f90747c4
EA
213}
214
d05fdab4 215#endif /* QEMU_ARM_VIRT_H */