1 /* 2 * QEMU ARM Xen PVH Machine 3 * 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this software and associated documentation files (the "Software"), to deal 7 * in the Software without restriction, including without limitation the rights 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 * copies of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 * THE SOFTWARE. 22 */ 23 24 #include "qemu/osdep.h" 25 #include "qemu/error-report.h" 26 #include "qapi/qapi-commands-migration.h" 27 #include "qapi/visitor.h" 28 #include "hw/boards.h" 29 #include "hw/sysbus.h" 30 #include "sysemu/block-backend.h" 31 #include "sysemu/tpm_backend.h" 32 #include "sysemu/sysemu.h" 33 #include "hw/xen/xen-hvm-common.h" 34 #include "sysemu/tpm.h" 35 #include "hw/xen/arch_hvm.h" 36 37 #define TYPE_XEN_ARM MACHINE_TYPE_NAME("xenpvh") 38 OBJECT_DECLARE_SIMPLE_TYPE(XenArmState, XEN_ARM) 39 40 static MemoryListener xen_memory_listener = { 41 .region_add = xen_region_add, 42 .region_del = xen_region_del, 43 .log_start = NULL, 44 .log_stop = NULL, 45 .log_sync = NULL, 46 .log_global_start = NULL, 47 .log_global_stop = NULL, 48 .priority = 10, 49 }; 50 51 struct XenArmState { 52 /*< private >*/ 53 MachineState parent; 54 55 XenIOState *state; 56 57 struct { 58 uint64_t tpm_base_addr; 59 } cfg; 60 }; 61 62 void arch_handle_ioreq(XenIOState *state, ioreq_t *req) 63 { 64 hw_error("Invalid ioreq type 0x%x\n", req->type); 65 66 return; 67 } 68 69 void arch_xen_set_memory(XenIOState *state, MemoryRegionSection *section, 70 bool add) 71 { 72 } 73 74 void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) 75 { 76 } 77 78 void qmp_xen_set_global_dirty_log(bool enable, Error **errp) 79 { 80 } 81 82 #ifdef CONFIG_TPM 83 static void xen_enable_tpm(XenArmState *xam) 84 { 85 Error *errp = NULL; 86 DeviceState *dev; 87 SysBusDevice *busdev; 88 89 TPMBackend *be = qemu_find_tpm_be("tpm0"); 90 if (be == NULL) { 91 DPRINTF("Couldn't fine the backend for tpm0\n"); 92 return; 93 } 94 dev = qdev_new(TYPE_TPM_TIS_SYSBUS); 95 object_property_set_link(OBJECT(dev), "tpmdev", OBJECT(be), &errp); 96 object_property_set_str(OBJECT(dev), "tpmdev", be->id, &errp); 97 busdev = SYS_BUS_DEVICE(dev); 98 sysbus_realize_and_unref(busdev, &error_fatal); 99 sysbus_mmio_map(busdev, 0, xam->cfg.tpm_base_addr); 100 101 DPRINTF("Connected tpmdev at address 0x%lx\n", xam->cfg.tpm_base_addr); 102 } 103 #endif 104 105 static void xen_arm_init(MachineState *machine) 106 { 107 XenArmState *xam = XEN_ARM(machine); 108 109 xam->state = g_new0(XenIOState, 1); 110 111 xen_register_ioreq(xam->state, machine->smp.cpus, xen_memory_listener); 112 113 #ifdef CONFIG_TPM 114 if (xam->cfg.tpm_base_addr) { 115 xen_enable_tpm(xam); 116 } else { 117 DPRINTF("tpm-base-addr is not provided. TPM will not be enabled\n"); 118 } 119 #endif 120 } 121 122 #ifdef CONFIG_TPM 123 static void xen_arm_get_tpm_base_addr(Object *obj, Visitor *v, 124 const char *name, void *opaque, 125 Error **errp) 126 { 127 XenArmState *xam = XEN_ARM(obj); 128 uint64_t value = xam->cfg.tpm_base_addr; 129 130 visit_type_uint64(v, name, &value, errp); 131 } 132 133 static void xen_arm_set_tpm_base_addr(Object *obj, Visitor *v, 134 const char *name, void *opaque, 135 Error **errp) 136 { 137 XenArmState *xam = XEN_ARM(obj); 138 uint64_t value; 139 140 if (!visit_type_uint64(v, name, &value, errp)) { 141 return; 142 } 143 144 xam->cfg.tpm_base_addr = value; 145 } 146 #endif 147 148 static void xen_arm_machine_class_init(ObjectClass *oc, void *data) 149 { 150 151 MachineClass *mc = MACHINE_CLASS(oc); 152 mc->desc = "Xen Para-virtualized PC"; 153 mc->init = xen_arm_init; 154 mc->max_cpus = 1; 155 mc->default_machine_opts = "accel=xen"; 156 157 #ifdef CONFIG_TPM 158 object_class_property_add(oc, "tpm-base-addr", "uint64_t", 159 xen_arm_get_tpm_base_addr, 160 xen_arm_set_tpm_base_addr, 161 NULL, NULL); 162 object_class_property_set_description(oc, "tpm-base-addr", 163 "Set Base address for TPM device."); 164 165 machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); 166 #endif 167 } 168 169 static const TypeInfo xen_arm_machine_type = { 170 .name = TYPE_XEN_ARM, 171 .parent = TYPE_MACHINE, 172 .class_init = xen_arm_machine_class_init, 173 .instance_size = sizeof(XenArmState), 174 }; 175 176 static void xen_arm_machine_register_types(void) 177 { 178 type_register_static(&xen_arm_machine_type); 179 } 180 181 type_init(xen_arm_machine_register_types) 182