1258b2a40SEdgar E. Iglesias /* 2258b2a40SEdgar E. Iglesias * QEMU Xen PVH machine - common code. 3258b2a40SEdgar E. Iglesias * 4258b2a40SEdgar E. Iglesias * Copyright (c) 2024 Advanced Micro Devices, Inc. 5258b2a40SEdgar E. Iglesias * 6258b2a40SEdgar E. Iglesias * SPDX-License-Identifier: GPL-2.0-or-later 7258b2a40SEdgar E. Iglesias */ 8258b2a40SEdgar E. Iglesias 9258b2a40SEdgar E. Iglesias #include "qemu/osdep.h" 10258b2a40SEdgar E. Iglesias #include "qemu/error-report.h" 11258b2a40SEdgar E. Iglesias #include "qapi/error.h" 12258b2a40SEdgar E. Iglesias #include "qapi/visitor.h" 13258b2a40SEdgar E. Iglesias #include "hw/boards.h" 14258b2a40SEdgar E. Iglesias #include "hw/irq.h" 15258b2a40SEdgar E. Iglesias #include "hw/sysbus.h" 16258b2a40SEdgar E. Iglesias #include "sysemu/sysemu.h" 17258b2a40SEdgar E. Iglesias #include "sysemu/tpm.h" 18258b2a40SEdgar E. Iglesias #include "sysemu/tpm_backend.h" 19258b2a40SEdgar E. Iglesias #include "hw/xen/xen-pvh-common.h" 20258b2a40SEdgar E. Iglesias #include "trace.h" 21258b2a40SEdgar E. Iglesias 22258b2a40SEdgar E. Iglesias static const MemoryListener xen_memory_listener = { 23258b2a40SEdgar E. Iglesias .region_add = xen_region_add, 24258b2a40SEdgar E. Iglesias .region_del = xen_region_del, 25258b2a40SEdgar E. Iglesias .log_start = NULL, 26258b2a40SEdgar E. Iglesias .log_stop = NULL, 27258b2a40SEdgar E. Iglesias .log_sync = NULL, 28258b2a40SEdgar E. Iglesias .log_global_start = NULL, 29258b2a40SEdgar E. Iglesias .log_global_stop = NULL, 30258b2a40SEdgar E. Iglesias .priority = MEMORY_LISTENER_PRIORITY_ACCEL, 31258b2a40SEdgar E. Iglesias }; 32258b2a40SEdgar E. Iglesias 33258b2a40SEdgar E. Iglesias static void xen_pvh_init_ram(XenPVHMachineState *s, 34258b2a40SEdgar E. Iglesias MemoryRegion *sysmem) 35258b2a40SEdgar E. Iglesias { 36258b2a40SEdgar E. Iglesias MachineState *ms = MACHINE(s); 37258b2a40SEdgar E. Iglesias ram_addr_t block_len, ram_size[2]; 38258b2a40SEdgar E. Iglesias 39258b2a40SEdgar E. Iglesias if (ms->ram_size <= s->cfg.ram_low.size) { 40258b2a40SEdgar E. Iglesias ram_size[0] = ms->ram_size; 41258b2a40SEdgar E. Iglesias ram_size[1] = 0; 42258b2a40SEdgar E. Iglesias block_len = s->cfg.ram_low.base + ram_size[0]; 43258b2a40SEdgar E. Iglesias } else { 44258b2a40SEdgar E. Iglesias ram_size[0] = s->cfg.ram_low.size; 45258b2a40SEdgar E. Iglesias ram_size[1] = ms->ram_size - s->cfg.ram_low.size; 46258b2a40SEdgar E. Iglesias block_len = s->cfg.ram_high.base + ram_size[1]; 47258b2a40SEdgar E. Iglesias } 48258b2a40SEdgar E. Iglesias 49258b2a40SEdgar E. Iglesias memory_region_init_ram(&xen_memory, NULL, "xen.ram", block_len, 50258b2a40SEdgar E. Iglesias &error_fatal); 51258b2a40SEdgar E. Iglesias 52258b2a40SEdgar E. Iglesias memory_region_init_alias(&s->ram.low, NULL, "xen.ram.lo", &xen_memory, 53258b2a40SEdgar E. Iglesias s->cfg.ram_low.base, ram_size[0]); 54258b2a40SEdgar E. Iglesias memory_region_add_subregion(sysmem, s->cfg.ram_low.base, &s->ram.low); 55258b2a40SEdgar E. Iglesias if (ram_size[1] > 0) { 56258b2a40SEdgar E. Iglesias memory_region_init_alias(&s->ram.high, NULL, "xen.ram.hi", &xen_memory, 57258b2a40SEdgar E. Iglesias s->cfg.ram_high.base, ram_size[1]); 58258b2a40SEdgar E. Iglesias memory_region_add_subregion(sysmem, s->cfg.ram_high.base, &s->ram.high); 59258b2a40SEdgar E. Iglesias } 60258b2a40SEdgar E. Iglesias 61258b2a40SEdgar E. Iglesias /* Setup support for grants. */ 62258b2a40SEdgar E. Iglesias memory_region_init_ram(&xen_grants, NULL, "xen.grants", block_len, 63258b2a40SEdgar E. Iglesias &error_fatal); 64258b2a40SEdgar E. Iglesias memory_region_add_subregion(sysmem, XEN_GRANT_ADDR_OFF, &xen_grants); 65258b2a40SEdgar E. Iglesias } 66258b2a40SEdgar E. Iglesias 67258b2a40SEdgar E. Iglesias static void xen_set_irq(void *opaque, int irq, int level) 68258b2a40SEdgar E. Iglesias { 69258b2a40SEdgar E. Iglesias if (xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level)) { 70258b2a40SEdgar E. Iglesias error_report("xendevicemodel_set_irq_level failed"); 71258b2a40SEdgar E. Iglesias } 72258b2a40SEdgar E. Iglesias } 73258b2a40SEdgar E. Iglesias 74258b2a40SEdgar E. Iglesias static void xen_create_virtio_mmio_devices(XenPVHMachineState *s) 75258b2a40SEdgar E. Iglesias { 76258b2a40SEdgar E. Iglesias int i; 77258b2a40SEdgar E. Iglesias 78692ec933SEdgar E. Iglesias /* 79692ec933SEdgar E. Iglesias * We create the transports in reverse order. Since qbus_realize() 80692ec933SEdgar E. Iglesias * prepends (not appends) new child buses, the decrementing loop below will 81692ec933SEdgar E. Iglesias * create a list of virtio-mmio buses with increasing base addresses. 82692ec933SEdgar E. Iglesias * 83692ec933SEdgar E. Iglesias * When a -device option is processed from the command line, 84692ec933SEdgar E. Iglesias * qbus_find_recursive() picks the next free virtio-mmio bus in forwards 85692ec933SEdgar E. Iglesias * order. 86692ec933SEdgar E. Iglesias * 87692ec933SEdgar E. Iglesias * This is what the Xen tools expect. 88692ec933SEdgar E. Iglesias */ 89692ec933SEdgar E. Iglesias for (i = s->cfg.virtio_mmio_num - 1; i >= 0; i--) { 90258b2a40SEdgar E. Iglesias hwaddr base = s->cfg.virtio_mmio.base + i * s->cfg.virtio_mmio.size; 91258b2a40SEdgar E. Iglesias qemu_irq irq = qemu_allocate_irq(xen_set_irq, NULL, 92258b2a40SEdgar E. Iglesias s->cfg.virtio_mmio_irq_base + i); 93258b2a40SEdgar E. Iglesias 94258b2a40SEdgar E. Iglesias sysbus_create_simple("virtio-mmio", base, irq); 95258b2a40SEdgar E. Iglesias 96258b2a40SEdgar E. Iglesias trace_xen_create_virtio_mmio_devices(i, 97258b2a40SEdgar E. Iglesias s->cfg.virtio_mmio_irq_base + i, 98258b2a40SEdgar E. Iglesias base); 99258b2a40SEdgar E. Iglesias } 100258b2a40SEdgar E. Iglesias } 101258b2a40SEdgar E. Iglesias 102258b2a40SEdgar E. Iglesias #ifdef CONFIG_TPM 103258b2a40SEdgar E. Iglesias static void xen_enable_tpm(XenPVHMachineState *s) 104258b2a40SEdgar E. Iglesias { 105258b2a40SEdgar E. Iglesias Error *errp = NULL; 106258b2a40SEdgar E. Iglesias DeviceState *dev; 107258b2a40SEdgar E. Iglesias SysBusDevice *busdev; 108258b2a40SEdgar E. Iglesias 109258b2a40SEdgar E. Iglesias TPMBackend *be = qemu_find_tpm_be("tpm0"); 110258b2a40SEdgar E. Iglesias if (be == NULL) { 111258b2a40SEdgar E. Iglesias error_report("Couldn't find tmp0 backend"); 112258b2a40SEdgar E. Iglesias return; 113258b2a40SEdgar E. Iglesias } 114258b2a40SEdgar E. Iglesias dev = qdev_new(TYPE_TPM_TIS_SYSBUS); 115258b2a40SEdgar E. Iglesias object_property_set_link(OBJECT(dev), "tpmdev", OBJECT(be), &errp); 116258b2a40SEdgar E. Iglesias object_property_set_str(OBJECT(dev), "tpmdev", be->id, &errp); 117258b2a40SEdgar E. Iglesias busdev = SYS_BUS_DEVICE(dev); 118258b2a40SEdgar E. Iglesias sysbus_realize_and_unref(busdev, &error_fatal); 119258b2a40SEdgar E. Iglesias sysbus_mmio_map(busdev, 0, s->cfg.tpm.base); 120258b2a40SEdgar E. Iglesias 121258b2a40SEdgar E. Iglesias trace_xen_enable_tpm(s->cfg.tpm.base); 122258b2a40SEdgar E. Iglesias } 123258b2a40SEdgar E. Iglesias #endif 124258b2a40SEdgar E. Iglesias 125*f22e598aSEdgar E. Iglesias /* 126*f22e598aSEdgar E. Iglesias * We use the GPEX PCIe controller with its internal INTX PCI interrupt 127*f22e598aSEdgar E. Iglesias * swizzling. This swizzling is emulated in QEMU and routes all INTX 128*f22e598aSEdgar E. Iglesias * interrupts from endpoints down to only 4 INTX interrupts. 129*f22e598aSEdgar E. Iglesias * See include/hw/pci/pci.h : pci_swizzle() 130*f22e598aSEdgar E. Iglesias */ 131*f22e598aSEdgar E. Iglesias static inline void xenpvh_gpex_init(XenPVHMachineState *s, 132*f22e598aSEdgar E. Iglesias XenPVHMachineClass *xpc, 133*f22e598aSEdgar E. Iglesias MemoryRegion *sysmem) 134*f22e598aSEdgar E. Iglesias { 135*f22e598aSEdgar E. Iglesias MemoryRegion *ecam_reg; 136*f22e598aSEdgar E. Iglesias MemoryRegion *mmio_reg; 137*f22e598aSEdgar E. Iglesias DeviceState *dev; 138*f22e598aSEdgar E. Iglesias int i; 139*f22e598aSEdgar E. Iglesias 140*f22e598aSEdgar E. Iglesias object_initialize_child(OBJECT(s), "gpex", &s->pci.gpex, 141*f22e598aSEdgar E. Iglesias TYPE_GPEX_HOST); 142*f22e598aSEdgar E. Iglesias dev = DEVICE(&s->pci.gpex); 143*f22e598aSEdgar E. Iglesias sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); 144*f22e598aSEdgar E. Iglesias 145*f22e598aSEdgar E. Iglesias ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); 146*f22e598aSEdgar E. Iglesias memory_region_add_subregion(sysmem, s->cfg.pci_ecam.base, ecam_reg); 147*f22e598aSEdgar E. Iglesias 148*f22e598aSEdgar E. Iglesias mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); 149*f22e598aSEdgar E. Iglesias 150*f22e598aSEdgar E. Iglesias if (s->cfg.pci_mmio.size) { 151*f22e598aSEdgar E. Iglesias memory_region_init_alias(&s->pci.mmio_alias, OBJECT(dev), "pcie-mmio", 152*f22e598aSEdgar E. Iglesias mmio_reg, 153*f22e598aSEdgar E. Iglesias s->cfg.pci_mmio.base, s->cfg.pci_mmio.size); 154*f22e598aSEdgar E. Iglesias memory_region_add_subregion(sysmem, s->cfg.pci_mmio.base, 155*f22e598aSEdgar E. Iglesias &s->pci.mmio_alias); 156*f22e598aSEdgar E. Iglesias } 157*f22e598aSEdgar E. Iglesias 158*f22e598aSEdgar E. Iglesias if (s->cfg.pci_mmio_high.size) { 159*f22e598aSEdgar E. Iglesias memory_region_init_alias(&s->pci.mmio_high_alias, OBJECT(dev), 160*f22e598aSEdgar E. Iglesias "pcie-mmio-high", 161*f22e598aSEdgar E. Iglesias mmio_reg, s->cfg.pci_mmio_high.base, s->cfg.pci_mmio_high.size); 162*f22e598aSEdgar E. Iglesias memory_region_add_subregion(sysmem, s->cfg.pci_mmio_high.base, 163*f22e598aSEdgar E. Iglesias &s->pci.mmio_high_alias); 164*f22e598aSEdgar E. Iglesias } 165*f22e598aSEdgar E. Iglesias 166*f22e598aSEdgar E. Iglesias /* 167*f22e598aSEdgar E. Iglesias * PVH implementations with PCI enabled must provide set_pci_intx_irq() 168*f22e598aSEdgar E. Iglesias * and optionally an implementation of set_pci_link_route(). 169*f22e598aSEdgar E. Iglesias */ 170*f22e598aSEdgar E. Iglesias assert(xpc->set_pci_intx_irq); 171*f22e598aSEdgar E. Iglesias 172*f22e598aSEdgar E. Iglesias for (i = 0; i < GPEX_NUM_IRQS; i++) { 173*f22e598aSEdgar E. Iglesias qemu_irq irq = qemu_allocate_irq(xpc->set_pci_intx_irq, s, i); 174*f22e598aSEdgar E. Iglesias 175*f22e598aSEdgar E. Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); 176*f22e598aSEdgar E. Iglesias gpex_set_irq_num(GPEX_HOST(dev), i, s->cfg.pci_intx_irq_base + i); 177*f22e598aSEdgar E. Iglesias if (xpc->set_pci_link_route) { 178*f22e598aSEdgar E. Iglesias xpc->set_pci_link_route(i, s->cfg.pci_intx_irq_base + i); 179*f22e598aSEdgar E. Iglesias } 180*f22e598aSEdgar E. Iglesias } 181*f22e598aSEdgar E. Iglesias } 182*f22e598aSEdgar E. Iglesias 183258b2a40SEdgar E. Iglesias static void xen_pvh_init(MachineState *ms) 184258b2a40SEdgar E. Iglesias { 185258b2a40SEdgar E. Iglesias XenPVHMachineState *s = XEN_PVH_MACHINE(ms); 186258b2a40SEdgar E. Iglesias XenPVHMachineClass *xpc = XEN_PVH_MACHINE_GET_CLASS(s); 187258b2a40SEdgar E. Iglesias MemoryRegion *sysmem = get_system_memory(); 188258b2a40SEdgar E. Iglesias 189258b2a40SEdgar E. Iglesias if (ms->ram_size == 0) { 190258b2a40SEdgar E. Iglesias warn_report("%s: ram size not specified. QEMU machine started" 191258b2a40SEdgar E. Iglesias " without IOREQ (no emulated devices including virtio)", 192258b2a40SEdgar E. Iglesias MACHINE_CLASS(object_get_class(OBJECT(ms)))->desc); 193258b2a40SEdgar E. Iglesias return; 194258b2a40SEdgar E. Iglesias } 195258b2a40SEdgar E. Iglesias 196258b2a40SEdgar E. Iglesias xen_pvh_init_ram(s, sysmem); 197258b2a40SEdgar E. Iglesias xen_register_ioreq(&s->ioreq, ms->smp.max_cpus, &xen_memory_listener); 198258b2a40SEdgar E. Iglesias 199258b2a40SEdgar E. Iglesias if (s->cfg.virtio_mmio_num) { 200258b2a40SEdgar E. Iglesias xen_create_virtio_mmio_devices(s); 201258b2a40SEdgar E. Iglesias } 202258b2a40SEdgar E. Iglesias 203258b2a40SEdgar E. Iglesias #ifdef CONFIG_TPM 204258b2a40SEdgar E. Iglesias if (xpc->has_tpm) { 205258b2a40SEdgar E. Iglesias if (s->cfg.tpm.base) { 206258b2a40SEdgar E. Iglesias xen_enable_tpm(s); 207258b2a40SEdgar E. Iglesias } else { 208258b2a40SEdgar E. Iglesias warn_report("tpm-base-addr is not set. TPM will not be enabled"); 209258b2a40SEdgar E. Iglesias } 210258b2a40SEdgar E. Iglesias } 211258b2a40SEdgar E. Iglesias #endif 212258b2a40SEdgar E. Iglesias 213*f22e598aSEdgar E. Iglesias /* Non-zero pci-ecam-size enables PCI. */ 214*f22e598aSEdgar E. Iglesias if (s->cfg.pci_ecam.size) { 215*f22e598aSEdgar E. Iglesias if (s->cfg.pci_ecam.size != 256 * MiB) { 216*f22e598aSEdgar E. Iglesias error_report("pci-ecam-size only supports values 0 or 0x10000000"); 217*f22e598aSEdgar E. Iglesias exit(EXIT_FAILURE); 218*f22e598aSEdgar E. Iglesias } 219*f22e598aSEdgar E. Iglesias xenpvh_gpex_init(s, xpc, sysmem); 220*f22e598aSEdgar E. Iglesias } 221*f22e598aSEdgar E. Iglesias 222258b2a40SEdgar E. Iglesias /* Call the implementation specific init. */ 223258b2a40SEdgar E. Iglesias if (xpc->init) { 224258b2a40SEdgar E. Iglesias xpc->init(ms); 225258b2a40SEdgar E. Iglesias } 226258b2a40SEdgar E. Iglesias } 227258b2a40SEdgar E. Iglesias 228258b2a40SEdgar E. Iglesias #define XEN_PVH_PROP_MEMMAP_SETTER(n, f) \ 229258b2a40SEdgar E. Iglesias static void xen_pvh_set_ ## n ## _ ## f(Object *obj, Visitor *v, \ 230258b2a40SEdgar E. Iglesias const char *name, void *opaque, \ 231258b2a40SEdgar E. Iglesias Error **errp) \ 232258b2a40SEdgar E. Iglesias { \ 233258b2a40SEdgar E. Iglesias XenPVHMachineState *xp = XEN_PVH_MACHINE(obj); \ 234258b2a40SEdgar E. Iglesias uint64_t value; \ 235258b2a40SEdgar E. Iglesias \ 236258b2a40SEdgar E. Iglesias if (!visit_type_size(v, name, &value, errp)) { \ 237258b2a40SEdgar E. Iglesias return; \ 238258b2a40SEdgar E. Iglesias } \ 239258b2a40SEdgar E. Iglesias xp->cfg.n.f = value; \ 240258b2a40SEdgar E. Iglesias } 241258b2a40SEdgar E. Iglesias 242258b2a40SEdgar E. Iglesias #define XEN_PVH_PROP_MEMMAP_GETTER(n, f) \ 243258b2a40SEdgar E. Iglesias static void xen_pvh_get_ ## n ## _ ## f(Object *obj, Visitor *v, \ 244258b2a40SEdgar E. Iglesias const char *name, void *opaque, \ 245258b2a40SEdgar E. Iglesias Error **errp) \ 246258b2a40SEdgar E. Iglesias { \ 247258b2a40SEdgar E. Iglesias XenPVHMachineState *xp = XEN_PVH_MACHINE(obj); \ 248258b2a40SEdgar E. Iglesias uint64_t value = xp->cfg.n.f; \ 249258b2a40SEdgar E. Iglesias \ 250258b2a40SEdgar E. Iglesias visit_type_uint64(v, name, &value, errp); \ 251258b2a40SEdgar E. Iglesias } 252258b2a40SEdgar E. Iglesias 253258b2a40SEdgar E. Iglesias #define XEN_PVH_PROP_MEMMAP_BASE(n) \ 254258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP_SETTER(n, base) \ 255258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP_GETTER(n, base) \ 256258b2a40SEdgar E. Iglesias 257258b2a40SEdgar E. Iglesias #define XEN_PVH_PROP_MEMMAP_SIZE(n) \ 258258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP_SETTER(n, size) \ 259258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP_GETTER(n, size) 260258b2a40SEdgar E. Iglesias 261258b2a40SEdgar E. Iglesias #define XEN_PVH_PROP_MEMMAP(n) \ 262258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP_BASE(n) \ 263258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP_SIZE(n) 264258b2a40SEdgar E. Iglesias 265258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP(ram_low) 266258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP(ram_high) 267258b2a40SEdgar E. Iglesias /* TPM only has a base-addr option. */ 268258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP_BASE(tpm) 269258b2a40SEdgar E. Iglesias XEN_PVH_PROP_MEMMAP(virtio_mmio) 270*f22e598aSEdgar E. Iglesias XEN_PVH_PROP_MEMMAP(pci_ecam) 271*f22e598aSEdgar E. Iglesias XEN_PVH_PROP_MEMMAP(pci_mmio) 272*f22e598aSEdgar E. Iglesias XEN_PVH_PROP_MEMMAP(pci_mmio_high) 273258b2a40SEdgar E. Iglesias 274258b2a40SEdgar E. Iglesias void xen_pvh_class_setup_common_props(XenPVHMachineClass *xpc) 275258b2a40SEdgar E. Iglesias { 276258b2a40SEdgar E. Iglesias ObjectClass *oc = OBJECT_CLASS(xpc); 277258b2a40SEdgar E. Iglesias MachineClass *mc = MACHINE_CLASS(xpc); 278258b2a40SEdgar E. Iglesias 279258b2a40SEdgar E. Iglesias #define OC_MEMMAP_PROP_BASE(c, prop_name, name) \ 280258b2a40SEdgar E. Iglesias do { \ 281258b2a40SEdgar E. Iglesias object_class_property_add(c, prop_name "-base", "uint64_t", \ 282258b2a40SEdgar E. Iglesias xen_pvh_get_ ## name ## _base, \ 283258b2a40SEdgar E. Iglesias xen_pvh_set_ ## name ## _base, NULL, NULL); \ 284258b2a40SEdgar E. Iglesias object_class_property_set_description(oc, prop_name "-base", \ 285258b2a40SEdgar E. Iglesias "Set base address for " prop_name); \ 286258b2a40SEdgar E. Iglesias } while (0) 287258b2a40SEdgar E. Iglesias 288258b2a40SEdgar E. Iglesias #define OC_MEMMAP_PROP_SIZE(c, prop_name, name) \ 289258b2a40SEdgar E. Iglesias do { \ 290258b2a40SEdgar E. Iglesias object_class_property_add(c, prop_name "-size", "uint64_t", \ 291258b2a40SEdgar E. Iglesias xen_pvh_get_ ## name ## _size, \ 292258b2a40SEdgar E. Iglesias xen_pvh_set_ ## name ## _size, NULL, NULL); \ 293258b2a40SEdgar E. Iglesias object_class_property_set_description(oc, prop_name "-size", \ 294258b2a40SEdgar E. Iglesias "Set memory range size for " prop_name); \ 295258b2a40SEdgar E. Iglesias } while (0) 296258b2a40SEdgar E. Iglesias 297258b2a40SEdgar E. Iglesias #define OC_MEMMAP_PROP(c, prop_name, name) \ 298258b2a40SEdgar E. Iglesias do { \ 299258b2a40SEdgar E. Iglesias OC_MEMMAP_PROP_BASE(c, prop_name, name); \ 300258b2a40SEdgar E. Iglesias OC_MEMMAP_PROP_SIZE(c, prop_name, name); \ 301258b2a40SEdgar E. Iglesias } while (0) 302258b2a40SEdgar E. Iglesias 303258b2a40SEdgar E. Iglesias /* 304258b2a40SEdgar E. Iglesias * We provide memmap properties to allow Xen to move things to other 305258b2a40SEdgar E. Iglesias * addresses for example when users need to accomodate the memory-map 306258b2a40SEdgar E. Iglesias * for 1:1 mapped devices/memory. 307258b2a40SEdgar E. Iglesias */ 308258b2a40SEdgar E. Iglesias OC_MEMMAP_PROP(oc, "ram-low", ram_low); 309258b2a40SEdgar E. Iglesias OC_MEMMAP_PROP(oc, "ram-high", ram_high); 310258b2a40SEdgar E. Iglesias 311258b2a40SEdgar E. Iglesias if (xpc->has_virtio_mmio) { 312258b2a40SEdgar E. Iglesias OC_MEMMAP_PROP(oc, "virtio-mmio", virtio_mmio); 313258b2a40SEdgar E. Iglesias } 314258b2a40SEdgar E. Iglesias 315*f22e598aSEdgar E. Iglesias if (xpc->has_pci) { 316*f22e598aSEdgar E. Iglesias OC_MEMMAP_PROP(oc, "pci-ecam", pci_ecam); 317*f22e598aSEdgar E. Iglesias OC_MEMMAP_PROP(oc, "pci-mmio", pci_mmio); 318*f22e598aSEdgar E. Iglesias OC_MEMMAP_PROP(oc, "pci-mmio-high", pci_mmio_high); 319*f22e598aSEdgar E. Iglesias } 320*f22e598aSEdgar E. Iglesias 321258b2a40SEdgar E. Iglesias #ifdef CONFIG_TPM 322258b2a40SEdgar E. Iglesias if (xpc->has_tpm) { 323258b2a40SEdgar E. Iglesias object_class_property_add(oc, "tpm-base-addr", "uint64_t", 324258b2a40SEdgar E. Iglesias xen_pvh_get_tpm_base, 325258b2a40SEdgar E. Iglesias xen_pvh_set_tpm_base, 326258b2a40SEdgar E. Iglesias NULL, NULL); 327258b2a40SEdgar E. Iglesias object_class_property_set_description(oc, "tpm-base-addr", 328258b2a40SEdgar E. Iglesias "Set Base address for TPM device."); 329258b2a40SEdgar E. Iglesias 330258b2a40SEdgar E. Iglesias machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); 331258b2a40SEdgar E. Iglesias } 332258b2a40SEdgar E. Iglesias #endif 333258b2a40SEdgar E. Iglesias } 334258b2a40SEdgar E. Iglesias 335258b2a40SEdgar E. Iglesias static void xen_pvh_class_init(ObjectClass *oc, void *data) 336258b2a40SEdgar E. Iglesias { 337258b2a40SEdgar E. Iglesias MachineClass *mc = MACHINE_CLASS(oc); 338258b2a40SEdgar E. Iglesias 339258b2a40SEdgar E. Iglesias mc->init = xen_pvh_init; 340258b2a40SEdgar E. Iglesias 341258b2a40SEdgar E. Iglesias mc->desc = "Xen PVH machine"; 342258b2a40SEdgar E. Iglesias mc->max_cpus = 1; 343258b2a40SEdgar E. Iglesias mc->default_machine_opts = "accel=xen"; 344258b2a40SEdgar E. Iglesias /* Set to zero to make sure that the real ram size is passed. */ 345258b2a40SEdgar E. Iglesias mc->default_ram_size = 0; 346258b2a40SEdgar E. Iglesias } 347258b2a40SEdgar E. Iglesias 348258b2a40SEdgar E. Iglesias static const TypeInfo xen_pvh_info = { 349258b2a40SEdgar E. Iglesias .name = TYPE_XEN_PVH_MACHINE, 350258b2a40SEdgar E. Iglesias .parent = TYPE_MACHINE, 351258b2a40SEdgar E. Iglesias .abstract = true, 352258b2a40SEdgar E. Iglesias .instance_size = sizeof(XenPVHMachineState), 353258b2a40SEdgar E. Iglesias .class_size = sizeof(XenPVHMachineClass), 354258b2a40SEdgar E. Iglesias .class_init = xen_pvh_class_init, 355258b2a40SEdgar E. Iglesias }; 356258b2a40SEdgar E. Iglesias 357258b2a40SEdgar E. Iglesias static void xen_pvh_register_types(void) 358258b2a40SEdgar E. Iglesias { 359258b2a40SEdgar E. Iglesias type_register_static(&xen_pvh_info); 360258b2a40SEdgar E. Iglesias } 361258b2a40SEdgar E. Iglesias 362258b2a40SEdgar E. Iglesias type_init(xen_pvh_register_types); 363