2015-05-29 18:28:54 +08: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 23:58:45 +08:00
|
|
|
#include "exec/hwaddr.h"
|
2017-01-09 19:40:22 +08:00
|
|
|
#include "qemu/notify.h"
|
2017-01-09 19:40:22 +08:00
|
|
|
#include "hw/boards.h"
|
2019-05-23 21:47:43 +08:00
|
|
|
#include "hw/arm/boot.h"
|
hw/arm/virt: Support firmware configuration with -blockdev
The ARM virt machines put firmware in flash memory. To configure it,
you use -drive if=pflash,unit=0,... and optionally -drive
if=pflash,unit=1,...
Why two -drive? This permits setting up one part of the flash memory
read-only, and the other part read/write. It also makes upgrading
firmware on the host easier. Below the hood, we get two separate
flash devices, because we were too lazy to improve our flash device
models to support sector protection.
The problem at hand is to do the same with -blockdev somehow, as one
more step towards deprecating -drive.
We recently solved this problem for x86 PC machines, in commit
ebc29e1beab. See the commit message for design rationale.
This commit solves it for ARM virt basically the same way: new machine
properties pflash0, pflash1 forward to the onboard flash devices'
properties. Requires creating the onboard devices in the
.instance_init() method virt_instance_init(). The existing code to
pick up drives defined with -drive if=pflash is replaced by code to
desugar into the machine properties.
There are a few behavioral differences, though:
* The flash devices are always present (x86: only present if
configured)
* Flash base addresses and sizes are fixed (x86: sizes depend on
images, mapped back to back below a fixed address)
* -bios configures contents of first pflash (x86: -bios configures ROM
contents)
* -bios is rejected when first pflash is also configured with -machine
pflash0=... (x86: bios is silently ignored then)
* -machine pflash1=... does not require -machine pflash0=... (x86: it
does).
The actual code is a bit simpler than for x86 mostly due to the first
two differences.
Before the patch, all the action is in create_flash(), called from the
machine's .init() method machvirt_init():
main()
machine_run_board_init()
machvirt_init()
create_flash()
create_one_flash() for flash[0]
create
configure
includes obeying -drive if=pflash,unit=0
realize
map
fall back to -bios
create_one_flash() for flash[1]
create
configure
includes obeying -drive if=pflash,unit=1
realize
map
update FDT
To make the machine properties work, we need to move device creation
to its .instance_init() method virt_instance_init().
Another complication is machvirt_init()'s computation of
@firmware_loaded: it predicts what create_flash() will do. Instead of
predicting what create_flash()'s replacement virt_firmware_init() will
do, I decided to have virt_firmware_init() return what it did.
Requires calling it a bit earlier.
Resulting call tree:
main()
current_machine = object_new()
...
virt_instance_init()
virt_flash_create()
virt_flash_create1() for flash[0]
create
configure: set defaults
become child of machine [NEW]
add machine prop pflash0 as alias for drive [NEW]
virt_flash_create1() for flash[1]
create
configure: set defaults
become child of machine [NEW]
add machine prop pflash1 as alias for drive [NEW]
for all machine props from the command line: machine_set_property()
...
property_set_alias() for machine props pflash0, pflash1
...
set_drive() for cfi.pflash01 prop drive
this is how -machine pflash0=... etc set
machine_run_board_init(current_machine);
virt_firmware_init()
pflash_cfi01_legacy_drive()
legacy -drive if=pflash,unit=0 and =1 [NEW]
virt_flash_map()
virt_flash_map1() for flash[0]
configure: num-blocks
realize
map
virt_flash_map1() for flash[1]
configure: num-blocks
realize
map
fall back to -bios
virt_flash_fdt()
update FDT
You have László to thank for making me explain this in detail.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Message-id: 20190416091348.26075-4-armbru@redhat.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2019-05-07 19:55:02 +08:00
|
|
|
#include "hw/block/flash.h"
|
2018-06-22 20:28:36 +08:00
|
|
|
#include "sysemu/kvm.h"
|
|
|
|
#include "hw/intc/arm_gicv3_common.h"
|
2015-05-29 18:28:54 +08:00
|
|
|
|
2015-06-02 21:56:23 +08:00
|
|
|
#define NUM_GICV2M_SPIS 64
|
2015-05-29 18:28:54 +08:00
|
|
|
#define NUM_VIRTIO_TRANSPORTS 32
|
2018-05-05 01:05:52 +08:00
|
|
|
#define NUM_SMMU_IRQS 4
|
2015-05-29 18:28:54 +08:00
|
|
|
|
2018-08-15 00:17:21 +08:00
|
|
|
#define ARCH_GIC_MAINT_IRQ 9
|
2017-01-20 19:15:09 +08:00
|
|
|
|
2015-05-29 18:28:56 +08:00
|
|
|
#define ARCH_TIMER_VIRT_IRQ 11
|
|
|
|
#define ARCH_TIMER_S_EL1_IRQ 13
|
|
|
|
#define ARCH_TIMER_NS_EL1_IRQ 14
|
|
|
|
#define ARCH_TIMER_NS_EL2_IRQ 10
|
|
|
|
|
2016-06-14 22:59:12 +08:00
|
|
|
#define VIRTUAL_PMU_IRQ 7
|
|
|
|
|
|
|
|
#define PPI(irq) ((irq) + 16)
|
|
|
|
|
2015-05-29 18:28:54 +08:00
|
|
|
enum {
|
|
|
|
VIRT_FLASH,
|
|
|
|
VIRT_MEM,
|
|
|
|
VIRT_CPUPERIPHS,
|
|
|
|
VIRT_GIC_DIST,
|
|
|
|
VIRT_GIC_CPU,
|
2015-09-24 08:29:37 +08:00
|
|
|
VIRT_GIC_V2M,
|
2018-08-15 00:17:21 +08:00
|
|
|
VIRT_GIC_HYP,
|
|
|
|
VIRT_GIC_VCPU,
|
2015-09-24 08:29:37 +08:00
|
|
|
VIRT_GIC_ITS,
|
|
|
|
VIRT_GIC_REDIST,
|
2018-05-05 01:05:52 +08:00
|
|
|
VIRT_SMMU,
|
2015-05-29 18:28:54 +08:00
|
|
|
VIRT_UART,
|
|
|
|
VIRT_MMIO,
|
|
|
|
VIRT_RTC,
|
|
|
|
VIRT_FW_CFG,
|
|
|
|
VIRT_PCIE,
|
2015-05-29 18:28:54 +08:00
|
|
|
VIRT_PCIE_MMIO,
|
|
|
|
VIRT_PCIE_PIO,
|
|
|
|
VIRT_PCIE_ECAM,
|
2015-06-02 19:29:13 +08:00
|
|
|
VIRT_PLATFORM_BUS,
|
2015-12-17 21:37:13 +08:00
|
|
|
VIRT_GPIO,
|
2016-01-21 22:15:07 +08:00
|
|
|
VIRT_SECURE_UART,
|
2016-03-04 19:30:17 +08:00
|
|
|
VIRT_SECURE_MEM,
|
2019-09-18 21:06:27 +08:00
|
|
|
VIRT_PCDIMM_ACPI,
|
|
|
|
VIRT_ACPI_GED,
|
2019-03-04 18:13:32 +08:00
|
|
|
VIRT_LOWMEMMAP_LAST,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* indices of IO regions located after the RAM */
|
|
|
|
enum {
|
|
|
|
VIRT_HIGH_GIC_REDIST2 = VIRT_LOWMEMMAP_LAST,
|
|
|
|
VIRT_HIGH_PCIE_ECAM,
|
|
|
|
VIRT_HIGH_PCIE_MMIO,
|
2015-05-29 18:28:54 +08:00
|
|
|
};
|
|
|
|
|
2018-05-05 01:05:52 +08:00
|
|
|
typedef enum VirtIOMMUType {
|
|
|
|
VIRT_IOMMU_NONE,
|
|
|
|
VIRT_IOMMU_SMMUV3,
|
|
|
|
VIRT_IOMMU_VIRTIO,
|
|
|
|
} VirtIOMMUType;
|
|
|
|
|
2015-05-29 18:28:54 +08:00
|
|
|
typedef struct MemMapEntry {
|
|
|
|
hwaddr base;
|
|
|
|
hwaddr size;
|
|
|
|
} MemMapEntry;
|
|
|
|
|
2017-01-09 19:40:22 +08:00
|
|
|
typedef struct {
|
|
|
|
MachineClass parent;
|
|
|
|
bool disallow_affinity_adjustment;
|
|
|
|
bool no_its;
|
|
|
|
bool no_pmu;
|
|
|
|
bool claim_edge_triggered_timers;
|
2018-03-24 02:26:46 +08:00
|
|
|
bool smbios_old_sys_ver;
|
2018-06-22 20:28:37 +08:00
|
|
|
bool no_highmem_ecam;
|
2019-09-18 21:06:27 +08:00
|
|
|
bool no_ged; /* Machines < 4.2 has no support for ACPI GED device */
|
2020-01-31 00:02:06 +08:00
|
|
|
bool kvm_no_adjvtime;
|
2017-01-09 19:40:22 +08:00
|
|
|
} VirtMachineClass;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MachineState parent;
|
|
|
|
Notifier machine_done;
|
2018-05-11 01:10:56 +08:00
|
|
|
DeviceState *platform_bus_dev;
|
2017-01-09 19:40:23 +08:00
|
|
|
FWCfgState *fw_cfg;
|
hw/arm/virt: Support firmware configuration with -blockdev
The ARM virt machines put firmware in flash memory. To configure it,
you use -drive if=pflash,unit=0,... and optionally -drive
if=pflash,unit=1,...
Why two -drive? This permits setting up one part of the flash memory
read-only, and the other part read/write. It also makes upgrading
firmware on the host easier. Below the hood, we get two separate
flash devices, because we were too lazy to improve our flash device
models to support sector protection.
The problem at hand is to do the same with -blockdev somehow, as one
more step towards deprecating -drive.
We recently solved this problem for x86 PC machines, in commit
ebc29e1beab. See the commit message for design rationale.
This commit solves it for ARM virt basically the same way: new machine
properties pflash0, pflash1 forward to the onboard flash devices'
properties. Requires creating the onboard devices in the
.instance_init() method virt_instance_init(). The existing code to
pick up drives defined with -drive if=pflash is replaced by code to
desugar into the machine properties.
There are a few behavioral differences, though:
* The flash devices are always present (x86: only present if
configured)
* Flash base addresses and sizes are fixed (x86: sizes depend on
images, mapped back to back below a fixed address)
* -bios configures contents of first pflash (x86: -bios configures ROM
contents)
* -bios is rejected when first pflash is also configured with -machine
pflash0=... (x86: bios is silently ignored then)
* -machine pflash1=... does not require -machine pflash0=... (x86: it
does).
The actual code is a bit simpler than for x86 mostly due to the first
two differences.
Before the patch, all the action is in create_flash(), called from the
machine's .init() method machvirt_init():
main()
machine_run_board_init()
machvirt_init()
create_flash()
create_one_flash() for flash[0]
create
configure
includes obeying -drive if=pflash,unit=0
realize
map
fall back to -bios
create_one_flash() for flash[1]
create
configure
includes obeying -drive if=pflash,unit=1
realize
map
update FDT
To make the machine properties work, we need to move device creation
to its .instance_init() method virt_instance_init().
Another complication is machvirt_init()'s computation of
@firmware_loaded: it predicts what create_flash() will do. Instead of
predicting what create_flash()'s replacement virt_firmware_init() will
do, I decided to have virt_firmware_init() return what it did.
Requires calling it a bit earlier.
Resulting call tree:
main()
current_machine = object_new()
...
virt_instance_init()
virt_flash_create()
virt_flash_create1() for flash[0]
create
configure: set defaults
become child of machine [NEW]
add machine prop pflash0 as alias for drive [NEW]
virt_flash_create1() for flash[1]
create
configure: set defaults
become child of machine [NEW]
add machine prop pflash1 as alias for drive [NEW]
for all machine props from the command line: machine_set_property()
...
property_set_alias() for machine props pflash0, pflash1
...
set_drive() for cfi.pflash01 prop drive
this is how -machine pflash0=... etc set
machine_run_board_init(current_machine);
virt_firmware_init()
pflash_cfi01_legacy_drive()
legacy -drive if=pflash,unit=0 and =1 [NEW]
virt_flash_map()
virt_flash_map1() for flash[0]
configure: num-blocks
realize
map
virt_flash_map1() for flash[1]
configure: num-blocks
realize
map
fall back to -bios
virt_flash_fdt()
update FDT
You have László to thank for making me explain this in detail.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Message-id: 20190416091348.26075-4-armbru@redhat.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2019-05-07 19:55:02 +08:00
|
|
|
PFlashCFI01 *flash[2];
|
2017-01-09 19:40:22 +08:00
|
|
|
bool secure;
|
|
|
|
bool highmem;
|
2018-06-22 20:28:37 +08:00
|
|
|
bool highmem_ecam;
|
2017-02-28 20:08:16 +08:00
|
|
|
bool its;
|
2017-01-20 19:15:11 +08:00
|
|
|
bool virt;
|
2017-01-09 19:40:22 +08:00
|
|
|
int32_t gic_version;
|
2018-05-05 01:05:52 +08:00
|
|
|
VirtIOMMUType iommu;
|
2017-01-09 19:40:22 +08:00
|
|
|
struct arm_boot_info bootinfo;
|
2019-03-04 18:13:32 +08:00
|
|
|
MemMapEntry *memmap;
|
2017-01-09 19:40:22 +08:00
|
|
|
const int *irqmap;
|
|
|
|
int smp_cpus;
|
|
|
|
void *fdt;
|
|
|
|
int fdt_size;
|
|
|
|
uint32_t clock_phandle;
|
|
|
|
uint32_t gic_phandle;
|
|
|
|
uint32_t msi_phandle;
|
2018-05-05 01:05:52 +08:00
|
|
|
uint32_t iommu_phandle;
|
2017-01-20 19:15:10 +08:00
|
|
|
int psci_conduit;
|
2019-03-04 18:13:36 +08:00
|
|
|
hwaddr highest_gpa;
|
2019-12-09 17:03:06 +08:00
|
|
|
DeviceState *gic;
|
2019-09-18 21:06:27 +08:00
|
|
|
DeviceState *acpi_dev;
|
2019-09-18 21:06:29 +08:00
|
|
|
Notifier powerdown_notifier;
|
2017-01-09 19:40:22 +08:00
|
|
|
} VirtMachineState;
|
|
|
|
|
2019-03-04 18:13:31 +08:00
|
|
|
#define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
|
2018-06-22 20:28:37 +08:00
|
|
|
|
2017-01-09 19:40:22 +08:00
|
|
|
#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
|
|
|
|
#define VIRT_MACHINE(obj) \
|
|
|
|
OBJECT_CHECK(VirtMachineState, (obj), TYPE_VIRT_MACHINE)
|
|
|
|
#define VIRT_MACHINE_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(VirtMachineClass, obj, TYPE_VIRT_MACHINE)
|
|
|
|
#define VIRT_MACHINE_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(VirtMachineClass, klass, TYPE_VIRT_MACHINE)
|
|
|
|
|
2017-01-09 19:40:22 +08:00
|
|
|
void virt_acpi_setup(VirtMachineState *vms);
|
2017-01-09 19:40:22 +08:00
|
|
|
|
2018-06-22 20:28:36 +08:00
|
|
|
/* Return the number of used redistributor regions */
|
|
|
|
static inline int virt_gicv3_redist_region_count(VirtMachineState *vms)
|
|
|
|
{
|
|
|
|
uint32_t redist0_capacity =
|
|
|
|
vms->memmap[VIRT_GIC_REDIST].size / GICV3_REDIST_SIZE;
|
|
|
|
|
|
|
|
assert(vms->gic_version == 3);
|
|
|
|
|
|
|
|
return vms->smp_cpus > redist0_capacity ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
2017-01-09 19:40:22 +08:00
|
|
|
#endif /* QEMU_ARM_VIRT_H */
|