xref: /openbmc/qemu/hw/arm/xen-pvh.c (revision ca9275a4)
10e14c9ebSEdgar E. Iglesias /*
20e14c9ebSEdgar E. Iglesias  * QEMU ARM Xen PVH Machine
30e14c9ebSEdgar E. Iglesias  *
40e14c9ebSEdgar E. Iglesias  * SPDX-License-Identifier: MIT
50e14c9ebSEdgar E. Iglesias  */
60e14c9ebSEdgar E. Iglesias 
70e14c9ebSEdgar E. Iglesias #include "qemu/osdep.h"
80e14c9ebSEdgar E. Iglesias #include "qemu/error-report.h"
90e14c9ebSEdgar E. Iglesias #include "qapi/qapi-commands-migration.h"
100e14c9ebSEdgar E. Iglesias #include "hw/boards.h"
110e14c9ebSEdgar E. Iglesias #include "sysemu/sysemu.h"
120e14c9ebSEdgar E. Iglesias #include "hw/xen/xen-pvh-common.h"
130e14c9ebSEdgar E. Iglesias #include "hw/xen/arch_hvm.h"
140e14c9ebSEdgar E. Iglesias 
150e14c9ebSEdgar E. Iglesias #define TYPE_XEN_ARM  MACHINE_TYPE_NAME("xenpvh")
160e14c9ebSEdgar E. Iglesias 
170e14c9ebSEdgar E. Iglesias /*
180e14c9ebSEdgar E. Iglesias  * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen
190e14c9ebSEdgar E. Iglesias  * repository.
200e14c9ebSEdgar E. Iglesias  *
210e14c9ebSEdgar E. Iglesias  * Origin: git://xenbits.xen.org/xen.git 2128143c114c
220e14c9ebSEdgar E. Iglesias  */
230e14c9ebSEdgar E. Iglesias #define VIRTIO_MMIO_DEV_SIZE   0x200
240e14c9ebSEdgar E. Iglesias 
250e14c9ebSEdgar E. Iglesias #define NR_VIRTIO_MMIO_DEVICES   \
260e14c9ebSEdgar E. Iglesias    (GUEST_VIRTIO_MMIO_SPI_LAST - GUEST_VIRTIO_MMIO_SPI_FIRST)
270e14c9ebSEdgar E. Iglesias 
xen_arm_instance_init(Object * obj)280e14c9ebSEdgar E. Iglesias static void xen_arm_instance_init(Object *obj)
290e14c9ebSEdgar E. Iglesias {
300e14c9ebSEdgar E. Iglesias     XenPVHMachineState *s = XEN_PVH_MACHINE(obj);
310e14c9ebSEdgar E. Iglesias 
320e14c9ebSEdgar E. Iglesias     /* Default values.  */
330e14c9ebSEdgar E. Iglesias     s->cfg.ram_low = (MemMapEntry) { GUEST_RAM0_BASE, GUEST_RAM0_SIZE };
340e14c9ebSEdgar E. Iglesias     s->cfg.ram_high = (MemMapEntry) { GUEST_RAM1_BASE, GUEST_RAM1_SIZE };
350e14c9ebSEdgar E. Iglesias 
360e14c9ebSEdgar E. Iglesias     s->cfg.virtio_mmio_num = NR_VIRTIO_MMIO_DEVICES;
370e14c9ebSEdgar E. Iglesias     s->cfg.virtio_mmio_irq_base = GUEST_VIRTIO_MMIO_SPI_FIRST;
380e14c9ebSEdgar E. Iglesias     s->cfg.virtio_mmio = (MemMapEntry) { GUEST_VIRTIO_MMIO_BASE,
390e14c9ebSEdgar E. Iglesias                                          VIRTIO_MMIO_DEV_SIZE };
400e14c9ebSEdgar E. Iglesias }
410e14c9ebSEdgar E. Iglesias 
xen_pvh_set_pci_intx_irq(void * opaque,int intx_irq,int level)42*ca9275a4SEdgar E. Iglesias static void xen_pvh_set_pci_intx_irq(void *opaque, int intx_irq, int level)
43*ca9275a4SEdgar E. Iglesias {
44*ca9275a4SEdgar E. Iglesias     XenPVHMachineState *s = XEN_PVH_MACHINE(opaque);
45*ca9275a4SEdgar E. Iglesias     int irq = s->cfg.pci_intx_irq_base + intx_irq;
46*ca9275a4SEdgar E. Iglesias 
47*ca9275a4SEdgar E. Iglesias     if (xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level)) {
48*ca9275a4SEdgar E. Iglesias         error_report("xendevicemodel_set_pci_intx_level failed");
49*ca9275a4SEdgar E. Iglesias     }
50*ca9275a4SEdgar E. Iglesias }
51*ca9275a4SEdgar E. Iglesias 
xen_arm_machine_class_init(ObjectClass * oc,void * data)520e14c9ebSEdgar E. Iglesias static void xen_arm_machine_class_init(ObjectClass *oc, void *data)
530e14c9ebSEdgar E. Iglesias {
540e14c9ebSEdgar E. Iglesias     XenPVHMachineClass *xpc = XEN_PVH_MACHINE_CLASS(oc);
550e14c9ebSEdgar E. Iglesias     MachineClass *mc = MACHINE_CLASS(oc);
560e14c9ebSEdgar E. Iglesias 
570e14c9ebSEdgar E. Iglesias     mc->desc = "Xen PVH ARM machine";
580e14c9ebSEdgar E. Iglesias 
590e14c9ebSEdgar E. Iglesias     /*
600e14c9ebSEdgar E. Iglesias      * mc->max_cpus holds the MAX value allowed in the -smp command-line opts.
610e14c9ebSEdgar E. Iglesias      *
620e14c9ebSEdgar E. Iglesias      * 1. If users don't pass any -smp option:
630e14c9ebSEdgar E. Iglesias      *   ms->smp.cpus will default to 1.
640e14c9ebSEdgar E. Iglesias      *   ms->smp.max_cpus will default to 1.
650e14c9ebSEdgar E. Iglesias      *
660e14c9ebSEdgar E. Iglesias      * 2. If users pass -smp X:
670e14c9ebSEdgar E. Iglesias      *   ms->smp.cpus will be set to X.
680e14c9ebSEdgar E. Iglesias      *   ms->smp.max_cpus will also be set to X.
690e14c9ebSEdgar E. Iglesias      *
700e14c9ebSEdgar E. Iglesias      * 3. If users pass -smp X,maxcpus=Y:
710e14c9ebSEdgar E. Iglesias      *   ms->smp.cpus will be set to X.
720e14c9ebSEdgar E. Iglesias      *   ms->smp.max_cpus will be set to Y.
730e14c9ebSEdgar E. Iglesias      *
740e14c9ebSEdgar E. Iglesias      * In scenarios 2 and 3, if X or Y are set to something larger than
750e14c9ebSEdgar E. Iglesias      * mc->max_cpus, QEMU will bail out with an error message.
760e14c9ebSEdgar E. Iglesias      */
770e14c9ebSEdgar E. Iglesias     mc->max_cpus = GUEST_MAX_VCPUS;
780e14c9ebSEdgar E. Iglesias 
79cb988a10SEdgar E. Iglesias     /* Xen/ARM does not use buffered IOREQs.  */
80cb988a10SEdgar E. Iglesias     xpc->handle_bufioreq = HVM_IOREQSRV_BUFIOREQ_OFF;
81cb988a10SEdgar E. Iglesias 
82*ca9275a4SEdgar E. Iglesias     /* PCI INTX delivery.  */
83*ca9275a4SEdgar E. Iglesias     xpc->set_pci_intx_irq = xen_pvh_set_pci_intx_irq;
84*ca9275a4SEdgar E. Iglesias 
850e14c9ebSEdgar E. Iglesias     /* List of supported features known to work on PVH ARM.  */
86*ca9275a4SEdgar E. Iglesias     xpc->has_pci = true;
870e14c9ebSEdgar E. Iglesias     xpc->has_tpm = true;
880e14c9ebSEdgar E. Iglesias     xpc->has_virtio_mmio = true;
890e14c9ebSEdgar E. Iglesias 
900e14c9ebSEdgar E. Iglesias     xen_pvh_class_setup_common_props(xpc);
910e14c9ebSEdgar E. Iglesias }
920e14c9ebSEdgar E. Iglesias 
930e14c9ebSEdgar E. Iglesias static const TypeInfo xen_arm_machine_type = {
940e14c9ebSEdgar E. Iglesias     .name = TYPE_XEN_ARM,
950e14c9ebSEdgar E. Iglesias     .parent = TYPE_XEN_PVH_MACHINE,
960e14c9ebSEdgar E. Iglesias     .class_init = xen_arm_machine_class_init,
970e14c9ebSEdgar E. Iglesias     .instance_size = sizeof(XenPVHMachineState),
980e14c9ebSEdgar E. Iglesias     .instance_init = xen_arm_instance_init,
990e14c9ebSEdgar E. Iglesias };
1000e14c9ebSEdgar E. Iglesias 
xen_arm_machine_register_types(void)1010e14c9ebSEdgar E. Iglesias static void xen_arm_machine_register_types(void)
1020e14c9ebSEdgar E. Iglesias {
1030e14c9ebSEdgar E. Iglesias     type_register_static(&xen_arm_machine_type);
1040e14c9ebSEdgar E. Iglesias }
1050e14c9ebSEdgar E. Iglesias 
1060e14c9ebSEdgar E. Iglesias type_init(xen_arm_machine_register_types)
107