2015-05-29 11:28:54 +01:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2015 Linaro Limited
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Emulate a virtual board which works by passing Linux all the information
|
|
|
|
|
* it needs about what devices are present via the device tree.
|
|
|
|
|
* There are some restrictions about what we can do here:
|
|
|
|
|
* + we can only present devices whose Linux drivers will work based
|
|
|
|
|
* purely on the device tree with no platform data at all
|
|
|
|
|
* + we want to present a very stripped-down minimalist platform,
|
|
|
|
|
* both because this reduces the security attack surface from the guest
|
|
|
|
|
* and also because it reduces our exposure to being broken when
|
|
|
|
|
* the kernel updates its device tree bindings and requires further
|
|
|
|
|
* information in a device binding that we aren't providing.
|
|
|
|
|
* This is essentially the same approach kvmtool uses.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef QEMU_ARM_VIRT_H
|
|
|
|
|
#define QEMU_ARM_VIRT_H
|
|
|
|
|
|
2016-03-15 16:58:45 +01:00
|
|
|
#include "exec/hwaddr.h"
|
2017-01-09 11:40:22 +00:00
|
|
|
#include "qemu/notify.h"
|
2017-01-09 11:40:22 +00:00
|
|
|
#include "hw/boards.h"
|
2025-09-23 09:04:07 +02:00
|
|
|
#include "hw/acpi/ghes.h"
|
2019-05-23 14:47:43 +01:00
|
|
|
#include "hw/arm/boot.h"
|
2023-09-19 10:02:28 +01:00
|
|
|
#include "hw/arm/bsa.h"
|
2019-05-07 12:55:02 +01:00
|
|
|
#include "hw/block/flash.h"
|
2025-07-03 11:41:08 +01:00
|
|
|
#include "hw/cxl/cxl.h"
|
2024-12-03 15:20:13 +01:00
|
|
|
#include "system/kvm.h"
|
2018-06-22 13:28:36 +01:00
|
|
|
#include "hw/intc/arm_gicv3_common.h"
|
2020-09-03 16:43:22 -04:00
|
|
|
#include "qom/object.h"
|
2015-05-29 11:28:54 +01:00
|
|
|
|
2015-06-02 14:56:23 +01:00
|
|
|
#define NUM_GICV2M_SPIS 64
|
2015-05-29 11:28:54 +01:00
|
|
|
#define NUM_VIRTIO_TRANSPORTS 32
|
2018-05-04 18:05:52 +01:00
|
|
|
#define NUM_SMMU_IRQS 4
|
2015-05-29 11:28:54 +01:00
|
|
|
|
2020-10-01 08:17:18 +02:00
|
|
|
/* See Linux kernel arch/arm64/include/asm/pvclock-abi.h */
|
|
|
|
|
#define PVTIME_SIZE_PER_CPU 64
|
|
|
|
|
|
2024-08-09 17:37:56 +01:00
|
|
|
/* GPIO pins */
|
|
|
|
|
#define GPIO_PIN_POWER_BUTTON 3
|
|
|
|
|
|
2015-05-29 11:28:54 +01:00
|
|
|
enum {
|
|
|
|
|
VIRT_FLASH,
|
|
|
|
|
VIRT_MEM,
|
|
|
|
|
VIRT_CPUPERIPHS,
|
|
|
|
|
VIRT_GIC_DIST,
|
|
|
|
|
VIRT_GIC_CPU,
|
2015-09-24 01:29:37 +01:00
|
|
|
VIRT_GIC_V2M,
|
2018-08-14 17:17:21 +01:00
|
|
|
VIRT_GIC_HYP,
|
|
|
|
|
VIRT_GIC_VCPU,
|
2015-09-24 01:29:37 +01:00
|
|
|
VIRT_GIC_ITS,
|
|
|
|
|
VIRT_GIC_REDIST,
|
2018-05-04 18:05:52 +01:00
|
|
|
VIRT_SMMU,
|
2024-06-10 17:23:42 +01:00
|
|
|
VIRT_UART0,
|
2015-05-29 11:28:54 +01:00
|
|
|
VIRT_MMIO,
|
|
|
|
|
VIRT_RTC,
|
|
|
|
|
VIRT_FW_CFG,
|
|
|
|
|
VIRT_PCIE,
|
2015-05-29 11:28:54 +01:00
|
|
|
VIRT_PCIE_MMIO,
|
|
|
|
|
VIRT_PCIE_PIO,
|
|
|
|
|
VIRT_PCIE_ECAM,
|
2015-06-02 12:29:13 +01:00
|
|
|
VIRT_PLATFORM_BUS,
|
2015-12-17 13:37:13 +00:00
|
|
|
VIRT_GPIO,
|
2024-06-10 17:23:42 +01:00
|
|
|
VIRT_UART1,
|
2016-03-04 11:30:17 +00:00
|
|
|
VIRT_SECURE_MEM,
|
2021-01-28 12:00:11 +00:00
|
|
|
VIRT_SECURE_GPIO,
|
2019-09-18 14:06:27 +01:00
|
|
|
VIRT_PCDIMM_ACPI,
|
|
|
|
|
VIRT_ACPI_GED,
|
2020-04-21 13:59:30 +01:00
|
|
|
VIRT_NVDIMM_ACPI,
|
2020-10-01 08:17:18 +02:00
|
|
|
VIRT_PVTIME,
|
2025-07-14 10:05:07 +02:00
|
|
|
VIRT_ACPI_PCIHP,
|
2019-03-04 11:13:32 +01:00
|
|
|
VIRT_LOWMEMMAP_LAST,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* indices of IO regions located after the RAM */
|
|
|
|
|
enum {
|
|
|
|
|
VIRT_HIGH_GIC_REDIST2 = VIRT_LOWMEMMAP_LAST,
|
2025-07-03 11:41:08 +01:00
|
|
|
VIRT_CXL_HOST,
|
2019-03-04 11:13:32 +01:00
|
|
|
VIRT_HIGH_PCIE_ECAM,
|
|
|
|
|
VIRT_HIGH_PCIE_MMIO,
|
2015-05-29 11:28:54 +01:00
|
|
|
};
|
|
|
|
|
|
2018-05-04 18:05:52 +01:00
|
|
|
typedef enum VirtIOMMUType {
|
|
|
|
|
VIRT_IOMMU_NONE,
|
|
|
|
|
VIRT_IOMMU_SMMUV3,
|
|
|
|
|
VIRT_IOMMU_VIRTIO,
|
|
|
|
|
} VirtIOMMUType;
|
|
|
|
|
|
2020-07-03 16:59:42 +01:00
|
|
|
typedef enum VirtMSIControllerType {
|
|
|
|
|
VIRT_MSI_CTRL_NONE,
|
|
|
|
|
VIRT_MSI_CTRL_GICV2M,
|
|
|
|
|
VIRT_MSI_CTRL_ITS,
|
|
|
|
|
} VirtMSIControllerType;
|
|
|
|
|
|
2020-03-11 14:16:14 +01:00
|
|
|
typedef enum VirtGICType {
|
2022-12-23 10:01:06 +01:00
|
|
|
VIRT_GIC_VERSION_MAX = 0,
|
|
|
|
|
VIRT_GIC_VERSION_HOST = 1,
|
|
|
|
|
/* The concrete GIC values have to match the GIC version number */
|
|
|
|
|
VIRT_GIC_VERSION_2 = 2,
|
|
|
|
|
VIRT_GIC_VERSION_3 = 3,
|
|
|
|
|
VIRT_GIC_VERSION_4 = 4,
|
2020-03-11 14:16:15 +01:00
|
|
|
VIRT_GIC_VERSION_NOSEL,
|
2020-03-11 14:16:14 +01:00
|
|
|
} VirtGICType;
|
|
|
|
|
|
2022-12-23 10:01:06 +01:00
|
|
|
#define VIRT_GIC_VERSION_2_MASK BIT(VIRT_GIC_VERSION_2)
|
|
|
|
|
#define VIRT_GIC_VERSION_3_MASK BIT(VIRT_GIC_VERSION_3)
|
|
|
|
|
#define VIRT_GIC_VERSION_4_MASK BIT(VIRT_GIC_VERSION_4)
|
|
|
|
|
|
2020-09-03 16:43:22 -04:00
|
|
|
struct VirtMachineClass {
|
2017-01-09 11:40:22 +00:00
|
|
|
MachineClass parent;
|
2021-09-13 16:07:24 +01:00
|
|
|
bool no_tcg_its;
|
2022-12-14 14:27:06 +00:00
|
|
|
bool no_highmem_compact;
|
2020-10-01 08:17:18 +02:00
|
|
|
bool no_kvm_steal_time;
|
2020-07-03 16:59:43 +01:00
|
|
|
bool acpi_expose_flash;
|
2021-01-28 12:00:11 +00:00
|
|
|
bool no_secure_gpio;
|
2021-10-20 22:21:18 +08:00
|
|
|
/* Machines < 6.2 have no support for describing cpu topology to guest */
|
|
|
|
|
bool no_cpu_topology;
|
2022-03-01 11:59:58 -10:00
|
|
|
bool no_tcg_lpa2;
|
2024-01-22 14:35:36 +00:00
|
|
|
bool no_ns_el2_virt_timer_irq;
|
2024-09-03 17:22:17 +01:00
|
|
|
bool no_nested_smmu;
|
2020-09-03 16:43:22 -04:00
|
|
|
};
|
2017-01-09 11:40:22 +00:00
|
|
|
|
2020-09-03 16:43:22 -04:00
|
|
|
struct VirtMachineState {
|
2017-01-09 11:40:22 +00:00
|
|
|
MachineState parent;
|
|
|
|
|
Notifier machine_done;
|
2018-05-10 18:10:56 +01:00
|
|
|
DeviceState *platform_bus_dev;
|
2017-01-09 11:40:23 +00:00
|
|
|
FWCfgState *fw_cfg;
|
2019-05-07 12:55:02 +01:00
|
|
|
PFlashCFI01 *flash[2];
|
2017-01-09 11:40:22 +00:00
|
|
|
bool secure;
|
|
|
|
|
bool highmem;
|
2022-12-14 14:27:06 +00:00
|
|
|
bool highmem_compact;
|
2025-07-03 11:41:08 +01:00
|
|
|
bool highmem_cxl;
|
2018-06-22 13:28:37 +01:00
|
|
|
bool highmem_ecam;
|
2022-01-14 14:07:36 +00:00
|
|
|
bool highmem_mmio;
|
2022-01-14 14:07:37 +00:00
|
|
|
bool highmem_redists;
|
2017-02-28 12:08:16 +00:00
|
|
|
bool its;
|
2021-09-13 16:07:24 +01:00
|
|
|
bool tcg_its;
|
2017-01-20 11:15:11 +00:00
|
|
|
bool virt;
|
2020-05-12 11:06:01 +08:00
|
|
|
bool ras;
|
2020-07-20 10:25:36 +01:00
|
|
|
bool mte;
|
2022-07-07 11:36:07 +01:00
|
|
|
bool dtb_randomness;
|
2024-06-10 17:23:43 +01:00
|
|
|
bool second_ns_uart_present;
|
2020-03-20 11:01:36 +01:00
|
|
|
OnOffAuto acpi;
|
2020-03-11 14:16:14 +01:00
|
|
|
VirtGICType gic_version;
|
2018-05-04 18:05:52 +01:00
|
|
|
VirtIOMMUType iommu;
|
2021-07-08 12:55:13 +00:00
|
|
|
bool default_bus_bypass_iommu;
|
2020-07-03 16:59:42 +01:00
|
|
|
VirtMSIControllerType msi_controller;
|
2020-02-14 14:27:44 +01:00
|
|
|
uint16_t virtio_iommu_bdf;
|
2017-01-09 11:40:22 +00:00
|
|
|
struct arm_boot_info bootinfo;
|
2019-03-04 11:13:32 +01:00
|
|
|
MemMapEntry *memmap;
|
2020-02-14 14:27:44 +01:00
|
|
|
char *pciehb_nodename;
|
2017-01-09 11:40:22 +00:00
|
|
|
const int *irqmap;
|
|
|
|
|
int fdt_size;
|
|
|
|
|
uint32_t clock_phandle;
|
|
|
|
|
uint32_t gic_phandle;
|
|
|
|
|
uint32_t msi_phandle;
|
2018-05-04 18:05:52 +01:00
|
|
|
uint32_t iommu_phandle;
|
2017-01-20 11:15:10 +00:00
|
|
|
int psci_conduit;
|
2019-03-04 11:13:36 +01:00
|
|
|
hwaddr highest_gpa;
|
2019-12-09 10:03:06 +01:00
|
|
|
DeviceState *gic;
|
2019-09-18 14:06:27 +01:00
|
|
|
DeviceState *acpi_dev;
|
2019-09-18 14:06:29 +01:00
|
|
|
Notifier powerdown_notifier;
|
2025-09-23 09:04:06 +02:00
|
|
|
Notifier generic_error_notifier;
|
2020-11-19 09:48:35 +08:00
|
|
|
PCIBus *bus;
|
2021-01-19 02:32:13 +02:00
|
|
|
char *oem_id;
|
|
|
|
|
char *oem_table_id;
|
2024-01-22 14:35:36 +00:00
|
|
|
bool ns_el2_virt_timer_irq;
|
2025-07-03 11:41:08 +01:00
|
|
|
CXLState cxl_devices_state;
|
2025-08-29 09:25:24 +01:00
|
|
|
bool legacy_smmuv3_present;
|
2020-09-03 16:43:22 -04:00
|
|
|
};
|
2017-01-09 11:40:22 +00:00
|
|
|
|
2019-03-04 11:13:31 +01:00
|
|
|
#define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
|
2018-06-22 13:28:37 +01:00
|
|
|
|
2017-01-09 11:40:22 +00:00
|
|
|
#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
|
2020-09-16 14:25:18 -04:00
|
|
|
OBJECT_DECLARE_TYPE(VirtMachineState, VirtMachineClass, VIRT_MACHINE)
|
2017-01-09 11:40:22 +00:00
|
|
|
|
2017-01-09 11:40:22 +00:00
|
|
|
void virt_acpi_setup(VirtMachineState *vms);
|
2020-03-20 11:01:36 +01:00
|
|
|
bool virt_is_acpi_enabled(VirtMachineState *vms);
|
2017-01-09 11:40:22 +00:00
|
|
|
|
2022-04-08 15:15:49 +01:00
|
|
|
/* Return number of redistributors that fit in the specified region */
|
|
|
|
|
static uint32_t virt_redist_capacity(VirtMachineState *vms, int region)
|
|
|
|
|
{
|
2022-04-08 15:15:50 +01:00
|
|
|
uint32_t redist_size;
|
|
|
|
|
|
|
|
|
|
if (vms->gic_version == VIRT_GIC_VERSION_3) {
|
|
|
|
|
redist_size = GICV3_REDIST_SIZE;
|
|
|
|
|
} else {
|
|
|
|
|
redist_size = GICV4_REDIST_SIZE;
|
|
|
|
|
}
|
|
|
|
|
return vms->memmap[region].size / redist_size;
|
2022-04-08 15:15:49 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 13:28:36 +01:00
|
|
|
/* Return the number of used redistributor regions */
|
|
|
|
|
static inline int virt_gicv3_redist_region_count(VirtMachineState *vms)
|
|
|
|
|
{
|
2022-04-08 15:15:49 +01:00
|
|
|
uint32_t redist0_capacity = virt_redist_capacity(vms, VIRT_GIC_REDIST);
|
2018-06-22 13:28:36 +01:00
|
|
|
|
2022-04-08 15:15:50 +01:00
|
|
|
assert(vms->gic_version != VIRT_GIC_VERSION_2);
|
2018-06-22 13:28:36 +01:00
|
|
|
|
2022-01-14 14:07:37 +00:00
|
|
|
return (MACHINE(vms)->smp.cpus > redist0_capacity &&
|
|
|
|
|
vms->highmem_redists) ? 2 : 1;
|
2018-06-22 13:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-09 11:40:22 +00:00
|
|
|
#endif /* QEMU_ARM_VIRT_H */
|