xref: /openbmc/qemu/hw/arm/xen-pvh.c (revision 637b0aa1)
1 /*
2  * QEMU ARM Xen PVH Machine
3  *
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #include "qemu/osdep.h"
8 #include "qemu/error-report.h"
9 #include "qapi/qapi-commands-migration.h"
10 #include "hw/boards.h"
11 #include "sysemu/sysemu.h"
12 #include "hw/xen/xen-pvh-common.h"
13 #include "hw/xen/arch_hvm.h"
14 
15 #define TYPE_XEN_ARM  MACHINE_TYPE_NAME("xenpvh")
16 
17 /*
18  * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen
19  * repository.
20  *
21  * Origin: git://xenbits.xen.org/xen.git 2128143c114c
22  */
23 #define VIRTIO_MMIO_DEV_SIZE   0x200
24 
25 #define NR_VIRTIO_MMIO_DEVICES   \
26    (GUEST_VIRTIO_MMIO_SPI_LAST - GUEST_VIRTIO_MMIO_SPI_FIRST)
27 
28 static void xen_arm_instance_init(Object *obj)
29 {
30     XenPVHMachineState *s = XEN_PVH_MACHINE(obj);
31 
32     /* Default values.  */
33     s->cfg.ram_low = (MemMapEntry) { GUEST_RAM0_BASE, GUEST_RAM0_SIZE };
34     s->cfg.ram_high = (MemMapEntry) { GUEST_RAM1_BASE, GUEST_RAM1_SIZE };
35 
36     s->cfg.virtio_mmio_num = NR_VIRTIO_MMIO_DEVICES;
37     s->cfg.virtio_mmio_irq_base = GUEST_VIRTIO_MMIO_SPI_FIRST;
38     s->cfg.virtio_mmio = (MemMapEntry) { GUEST_VIRTIO_MMIO_BASE,
39                                          VIRTIO_MMIO_DEV_SIZE };
40 }
41 
42 static void xen_arm_machine_class_init(ObjectClass *oc, void *data)
43 {
44     XenPVHMachineClass *xpc = XEN_PVH_MACHINE_CLASS(oc);
45     MachineClass *mc = MACHINE_CLASS(oc);
46 
47     mc->desc = "Xen PVH ARM machine";
48 
49     /*
50      * mc->max_cpus holds the MAX value allowed in the -smp command-line opts.
51      *
52      * 1. If users don't pass any -smp option:
53      *   ms->smp.cpus will default to 1.
54      *   ms->smp.max_cpus will default to 1.
55      *
56      * 2. If users pass -smp X:
57      *   ms->smp.cpus will be set to X.
58      *   ms->smp.max_cpus will also be set to X.
59      *
60      * 3. If users pass -smp X,maxcpus=Y:
61      *   ms->smp.cpus will be set to X.
62      *   ms->smp.max_cpus will be set to Y.
63      *
64      * In scenarios 2 and 3, if X or Y are set to something larger than
65      * mc->max_cpus, QEMU will bail out with an error message.
66      */
67     mc->max_cpus = GUEST_MAX_VCPUS;
68 
69     /* List of supported features known to work on PVH ARM.  */
70     xpc->has_tpm = true;
71     xpc->has_virtio_mmio = true;
72 
73     xen_pvh_class_setup_common_props(xpc);
74 }
75 
76 static const TypeInfo xen_arm_machine_type = {
77     .name = TYPE_XEN_ARM,
78     .parent = TYPE_XEN_PVH_MACHINE,
79     .class_init = xen_arm_machine_class_init,
80     .instance_size = sizeof(XenPVHMachineState),
81     .instance_init = xen_arm_instance_init,
82 };
83 
84 static void xen_arm_machine_register_types(void)
85 {
86     type_register_static(&xen_arm_machine_type);
87 }
88 
89 type_init(xen_arm_machine_register_types)
90