[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 01/16] hw/arm/arm: Introduce ArmMachineState and ArmMachineCl
From: |
Xu Yandong |
Subject: |
[PATCH RFC 01/16] hw/arm/arm: Introduce ArmMachineState and ArmMachineClass |
Date: |
Mon, 17 Feb 2020 02:51:13 -0500 |
In the following patches, VirtMachineState and VirtMachineClass will
splited to and deriving ArmMachineState and ArmMachineClass.
This allows sharing code with other arm machine types.
Signed-off-by: Xu Yandong <address@hidden>
---
hw/arm/Makefile.objs | 2 +-
hw/arm/arm.c | 77 ++++++++++++++++++++++++++++++++
hw/arm/virt.c | 11 +----
include/hw/arm/arm.h | 100 ++++++++++++++++++++++++++++++++++++++++++
include/hw/arm/virt.h | 61 ++------------------------
5 files changed, 183 insertions(+), 68 deletions(-)
create mode 100644 hw/arm/arm.c
create mode 100644 include/hw/arm/arm.h
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 336f6dd374..51fcee2ac8 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -1,6 +1,6 @@
obj-y += boot.o
obj-$(CONFIG_PLATFORM_BUS) += sysbus-fdt.o
-obj-$(CONFIG_ARM_VIRT) += virt.o
+obj-$(CONFIG_ARM_VIRT) += arm.o virt.o
obj-$(CONFIG_ACPI) += virt-acpi-build.o
obj-$(CONFIG_DIGIC) += digic_boards.o
obj-$(CONFIG_EXYNOS4) += exynos4_boards.o
diff --git a/hw/arm/arm.c b/hw/arm/arm.c
new file mode 100644
index 0000000000..4261d56832
--- /dev/null
+++ b/hw/arm/arm.c
@@ -0,0 +1,77 @@
+/*
+ * ARM mach-virt emulation
+ * Copyright (c) 2013 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
+ * This is essentially the same approach kvmtool uses.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/arm/arm.h"
+#include "sysemu/device_tree.h"
+#include "sysemu/numa.h"
+#include "hw/loader.h"
+#include "exec/address-spaces.h"
+#include "qemu/bitops.h"
+#include "qemu/error-report.h"
+#include "qemu/module.h"
+#include "hw/arm/sysbus-fdt.h"
+#include "hw/platform-bus.h"
+#include "hw/qdev-properties.h"
+#include "hw/arm/fdt.h"
+#include "hw/intc/arm_gic.h"
+#include "kvm_arm.h"
+
+static void arm_machine_class_init(ObjectClass *oc, void *data)
+{
+ MachineClass *mc = MACHINE_CLASS(oc);
+
+ mc->block_default_type = IF_VIRTIO;
+ mc->no_cdrom = 1;
+ mc->pci_allow_0_address = true;
+ /* We know we will never create a pre-ARMv7 CPU which needs 1K pages */
+ mc->minimum_page_bits = 12;
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15");
+ mc->numa_mem_supported = true;
+ mc->auto_enable_numa_with_memhp = true;
+}
+
+static void arm_instance_init(Object *obj)
+{
+}
+
+static const TypeInfo arm_machine_info = {
+ .name = TYPE_ARM_MACHINE,
+ .parent = TYPE_MACHINE,
+ .abstract = true,
+ .instance_size = sizeof(ArmMachineState),
+ .class_size = sizeof(ArmMachineClass),
+ .class_init = arm_machine_class_init,
+ .instance_init = arm_instance_init,
+ .interfaces = (InterfaceInfo[]) {
+ { }
+ },
+};
+
+static void macharm_machine_init(void)
+{
+ type_register_static(&arm_machine_info);
+}
+type_init(macharm_machine_init);
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index f788fe27d6..355007fd32 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -37,6 +37,7 @@
#include "hw/boards.h"
#include "hw/arm/boot.h"
#include "hw/arm/primecell.h"
+#include "hw/arm/arm.h"
#include "hw/arm/virt.h"
#include "hw/block/flash.h"
#include "hw/vfio/vfio-calxeda-xgmac.h"
@@ -2041,14 +2042,8 @@ static void virt_machine_class_init(ObjectClass *oc,
void *data)
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_AMD_XGBE);
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_PLATFORM);
- mc->block_default_type = IF_VIRTIO;
- mc->no_cdrom = 1;
- mc->pci_allow_0_address = true;
- /* We know we will never create a pre-ARMv7 CPU which needs 1K pages */
- mc->minimum_page_bits = 12;
mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
- mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15");
mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
mc->kvm_type = virt_kvm_type;
assert(!mc->get_hotplug_handler);
@@ -2056,8 +2051,6 @@ static void virt_machine_class_init(ObjectClass *oc, void
*data)
hc->pre_plug = virt_machine_device_pre_plug_cb;
hc->plug = virt_machine_device_plug_cb;
hc->unplug_request = virt_machine_device_unplug_request_cb;
- mc->numa_mem_supported = true;
- mc->auto_enable_numa_with_memhp = true;
}
static void virt_instance_init(Object *obj)
@@ -2133,7 +2126,7 @@ static void virt_instance_init(Object *obj)
static const TypeInfo virt_machine_info = {
.name = TYPE_VIRT_MACHINE,
- .parent = TYPE_MACHINE,
+ .parent = TYPE_ARM_MACHINE,
.abstract = true,
.instance_size = sizeof(VirtMachineState),
.class_size = sizeof(VirtMachineClass),
diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h
new file mode 100644
index 0000000000..2aa9ee3d05
--- /dev/null
+++ b/include/hw/arm/arm.h
@@ -0,0 +1,100 @@
+/*
+ * 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/>.*
+ */
+
+#ifndef QEMU_ARM_ARM_H
+#define QEMU_ARM_ARM_H
+
+#include "exec/hwaddr.h"
+#include "hw/boards.h"
+#include "hw/arm/boot.h"
+#include "hw/intc/arm_gicv3_common.h"
+
+#define NUM_GICV2M_SPIS 64
+#define NUM_VIRTIO_TRANSPORTS 32
+#define NUM_SMMU_IRQS 4
+
+#define ARCH_GIC_MAINT_IRQ 9
+
+#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
+
+#define VIRTUAL_PMU_IRQ 7
+
+#define PPI(irq) ((irq) + 16)
+
+
+enum {
+ VIRT_FLASH,
+ VIRT_MEM,
+ VIRT_CPUPERIPHS,
+ VIRT_GIC_DIST,
+ VIRT_GIC_CPU,
+ VIRT_GIC_V2M,
+ VIRT_GIC_HYP,
+ VIRT_GIC_VCPU,
+ VIRT_GIC_ITS,
+ VIRT_GIC_REDIST,
+ VIRT_SMMU,
+ VIRT_UART,
+ VIRT_MMIO,
+ VIRT_RTC,
+ VIRT_FW_CFG,
+ VIRT_PCIE,
+ VIRT_PCIE_MMIO,
+ VIRT_PCIE_PIO,
+ VIRT_PCIE_ECAM,
+ VIRT_PLATFORM_BUS,
+ VIRT_GPIO,
+ VIRT_SECURE_UART,
+ VIRT_SECURE_MEM,
+ VIRT_PCDIMM_ACPI,
+ VIRT_ACPI_GED,
+ 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,
+};
+
+/* indices of IO regions located after the RAM */
+
+typedef struct MemMapEntry {
+ hwaddr base;
+ hwaddr size;
+} MemMapEntry;
+
+typedef struct {
+ MachineClass parent;
+} ArmMachineClass;
+
+typedef struct {
+ MachineState parent;
+} ArmMachineState;
+
+#define TYPE_ARM_MACHINE MACHINE_TYPE_NAME("arm")
+#define ARM_MACHINE(obj) \
+ OBJECT_CHECK(ArmMachineState, (obj), TYPE_ARM_MACHINE)
+#define ARM_MACHINE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(ArmMachineClass, obj, TYPE_ARM_MACHINE)
+#define ARM_MACHINE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(ArmMachineClass, klass, TYPE_ARM_MACHINE)
+
+#endif /* QEMU_ARM_ARM_H */
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
index 71508bf40c..aa0cc852a5 100644
--- a/include/hw/arm/virt.h
+++ b/include/hw/arm/virt.h
@@ -37,57 +37,7 @@
#include "hw/block/flash.h"
#include "sysemu/kvm.h"
#include "hw/intc/arm_gicv3_common.h"
-
-#define NUM_GICV2M_SPIS 64
-#define NUM_VIRTIO_TRANSPORTS 32
-#define NUM_SMMU_IRQS 4
-
-#define ARCH_GIC_MAINT_IRQ 9
-
-#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
-
-#define VIRTUAL_PMU_IRQ 7
-
-#define PPI(irq) ((irq) + 16)
-
-enum {
- VIRT_FLASH,
- VIRT_MEM,
- VIRT_CPUPERIPHS,
- VIRT_GIC_DIST,
- VIRT_GIC_CPU,
- VIRT_GIC_V2M,
- VIRT_GIC_HYP,
- VIRT_GIC_VCPU,
- VIRT_GIC_ITS,
- VIRT_GIC_REDIST,
- VIRT_SMMU,
- VIRT_UART,
- VIRT_MMIO,
- VIRT_RTC,
- VIRT_FW_CFG,
- VIRT_PCIE,
- VIRT_PCIE_MMIO,
- VIRT_PCIE_PIO,
- VIRT_PCIE_ECAM,
- VIRT_PLATFORM_BUS,
- VIRT_GPIO,
- VIRT_SECURE_UART,
- VIRT_SECURE_MEM,
- VIRT_PCDIMM_ACPI,
- VIRT_ACPI_GED,
- 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,
-};
+#include "hw/arm/arm.h"
typedef enum VirtIOMMUType {
VIRT_IOMMU_NONE,
@@ -95,13 +45,8 @@ typedef enum VirtIOMMUType {
VIRT_IOMMU_VIRTIO,
} VirtIOMMUType;
-typedef struct MemMapEntry {
- hwaddr base;
- hwaddr size;
-} MemMapEntry;
-
typedef struct {
- MachineClass parent;
+ ArmMachineClass parent;
bool disallow_affinity_adjustment;
bool no_its;
bool no_pmu;
@@ -113,7 +58,7 @@ typedef struct {
} VirtMachineClass;
typedef struct {
- MachineState parent;
+ ArmMachineState parent;
Notifier machine_done;
DeviceState *platform_bus_dev;
FWCfgState *fw_cfg;
--
2.18.1
- [PATCH RFC 00/16] Implement Microvm for aarch64 architecture, Xu Yandong, 2020/02/17
- Re: [PATCH RFC 00/16] Implement Microvm for aarch64 architecture, no-reply, 2020/02/17
- Re: [PATCH RFC 00/16] Implement Microvm for aarch64 architecture, Peter Maydell, 2020/02/17
- [PATCH RFC 09/16] hw/arm: move shared gic member to ArmMachine, Xu Yandong, 2020/02/17
- [PATCH RFC 14/16] hw/arm: move shared bootinfo member to ArmMachine, Xu Yandong, 2020/02/17
- [PATCH RFC 05/16] hw/arm: move shared smp_cpus member to ArmMachine, Xu Yandong, 2020/02/17
- [PATCH RFC 15/16] hw/arm: move shared cpu related functions to arm.c and export them, Xu Yandong, 2020/02/17
- [PATCH RFC 10/16] hw/arm: split create_gic function, Xu Yandong, 2020/02/17
- [PATCH RFC 04/16] hw/arm: move shared irqmap member to ArmMachine, Xu Yandong, 2020/02/17
- [PATCH RFC 01/16] hw/arm/arm: Introduce ArmMachineState and ArmMachineClass,
Xu Yandong <=
- [PATCH RFC 07/16] hw/arm/virt: split virt extension related codes from create_gic, Xu Yandong, 2020/02/17
- [PATCH RFC 11/16] hw/arm: move shared psci_enable and claim_edge_triggered_timers member to ArmMachine, Xu Yandong, 2020/02/17
- [PATCH RFC 03/16] hw/arm: move shared memmap member to ArmMachine, Xu Yandong, 2020/02/17
- [PATCH RFC 06/16] hw/arm/virt: split MSI related codes from create_gic, Xu Yandong, 2020/02/17
- [PATCH RFC 08/16] hw/arm/virt: split secure extension related codes from create_gic, Xu Yandong, 2020/02/17
- [PATCH RFC 02/16] hw/arm: move shared fdt member to ArmMachine, Xu Yandong, 2020/02/17
- [PATCH RFC 12/16] hw/arm: move shared devices related functions to arm.c and export them, Xu Yandong, 2020/02/17
- [PATCH RFC 13/16] hw/arm: move shared fdt related functions to arm.c and export them, Xu Yandong, 2020/02/17
- [PATCH RFC 16/16] hw/arm: Introduce the microvm machine type, Xu Yandong, 2020/02/17