1 /* 2 * QEMU Machine 3 * 4 * Copyright (C) 2014 Red Hat Inc 5 * 6 * Authors: 7 * Marcel Apfelbaum <marcel.a@redhat.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 */ 12 13 #include "hw/boards.h" 14 #include "qapi/visitor.h" 15 16 static char *machine_get_accel(Object *obj, Error **errp) 17 { 18 MachineState *ms = MACHINE(obj); 19 20 return g_strdup(ms->accel); 21 } 22 23 static void machine_set_accel(Object *obj, const char *value, Error **errp) 24 { 25 MachineState *ms = MACHINE(obj); 26 27 ms->accel = g_strdup(value); 28 } 29 30 static bool machine_get_kernel_irqchip(Object *obj, Error **errp) 31 { 32 MachineState *ms = MACHINE(obj); 33 34 return ms->kernel_irqchip; 35 } 36 37 static void machine_set_kernel_irqchip(Object *obj, bool value, Error **errp) 38 { 39 MachineState *ms = MACHINE(obj); 40 41 ms->kernel_irqchip = value; 42 } 43 44 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v, 45 void *opaque, const char *name, 46 Error **errp) 47 { 48 MachineState *ms = MACHINE(obj); 49 int64_t value = ms->kvm_shadow_mem; 50 51 visit_type_int(v, &value, name, errp); 52 } 53 54 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v, 55 void *opaque, const char *name, 56 Error **errp) 57 { 58 MachineState *ms = MACHINE(obj); 59 Error *error = NULL; 60 int64_t value; 61 62 visit_type_int(v, &value, name, &error); 63 if (error) { 64 error_propagate(errp, error); 65 return; 66 } 67 68 ms->kvm_shadow_mem = value; 69 } 70 71 static char *machine_get_kernel(Object *obj, Error **errp) 72 { 73 MachineState *ms = MACHINE(obj); 74 75 return g_strdup(ms->kernel_filename); 76 } 77 78 static void machine_set_kernel(Object *obj, const char *value, Error **errp) 79 { 80 MachineState *ms = MACHINE(obj); 81 82 ms->kernel_filename = g_strdup(value); 83 } 84 85 static char *machine_get_initrd(Object *obj, Error **errp) 86 { 87 MachineState *ms = MACHINE(obj); 88 89 return g_strdup(ms->initrd_filename); 90 } 91 92 static void machine_set_initrd(Object *obj, const char *value, Error **errp) 93 { 94 MachineState *ms = MACHINE(obj); 95 96 ms->initrd_filename = g_strdup(value); 97 } 98 99 static char *machine_get_append(Object *obj, Error **errp) 100 { 101 MachineState *ms = MACHINE(obj); 102 103 return g_strdup(ms->kernel_cmdline); 104 } 105 106 static void machine_set_append(Object *obj, const char *value, Error **errp) 107 { 108 MachineState *ms = MACHINE(obj); 109 110 ms->kernel_cmdline = g_strdup(value); 111 } 112 113 static char *machine_get_dtb(Object *obj, Error **errp) 114 { 115 MachineState *ms = MACHINE(obj); 116 117 return g_strdup(ms->dtb); 118 } 119 120 static void machine_set_dtb(Object *obj, const char *value, Error **errp) 121 { 122 MachineState *ms = MACHINE(obj); 123 124 ms->dtb = g_strdup(value); 125 } 126 127 static char *machine_get_dumpdtb(Object *obj, Error **errp) 128 { 129 MachineState *ms = MACHINE(obj); 130 131 return g_strdup(ms->dumpdtb); 132 } 133 134 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp) 135 { 136 MachineState *ms = MACHINE(obj); 137 138 ms->dumpdtb = g_strdup(value); 139 } 140 141 static void machine_get_phandle_start(Object *obj, Visitor *v, 142 void *opaque, const char *name, 143 Error **errp) 144 { 145 MachineState *ms = MACHINE(obj); 146 int64_t value = ms->phandle_start; 147 148 visit_type_int(v, &value, name, errp); 149 } 150 151 static void machine_set_phandle_start(Object *obj, Visitor *v, 152 void *opaque, const char *name, 153 Error **errp) 154 { 155 MachineState *ms = MACHINE(obj); 156 Error *error = NULL; 157 int64_t value; 158 159 visit_type_int(v, &value, name, &error); 160 if (error) { 161 error_propagate(errp, error); 162 return; 163 } 164 165 ms->phandle_start = value; 166 } 167 168 static char *machine_get_dt_compatible(Object *obj, Error **errp) 169 { 170 MachineState *ms = MACHINE(obj); 171 172 return g_strdup(ms->dt_compatible); 173 } 174 175 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp) 176 { 177 MachineState *ms = MACHINE(obj); 178 179 ms->dt_compatible = g_strdup(value); 180 } 181 182 static bool machine_get_dump_guest_core(Object *obj, Error **errp) 183 { 184 MachineState *ms = MACHINE(obj); 185 186 return ms->dump_guest_core; 187 } 188 189 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp) 190 { 191 MachineState *ms = MACHINE(obj); 192 193 ms->dump_guest_core = value; 194 } 195 196 static bool machine_get_mem_merge(Object *obj, Error **errp) 197 { 198 MachineState *ms = MACHINE(obj); 199 200 return ms->mem_merge; 201 } 202 203 static void machine_set_mem_merge(Object *obj, bool value, Error **errp) 204 { 205 MachineState *ms = MACHINE(obj); 206 207 ms->mem_merge = value; 208 } 209 210 static bool machine_get_usb(Object *obj, Error **errp) 211 { 212 MachineState *ms = MACHINE(obj); 213 214 return ms->usb; 215 } 216 217 static void machine_set_usb(Object *obj, bool value, Error **errp) 218 { 219 MachineState *ms = MACHINE(obj); 220 221 ms->usb = value; 222 } 223 224 static char *machine_get_firmware(Object *obj, Error **errp) 225 { 226 MachineState *ms = MACHINE(obj); 227 228 return g_strdup(ms->firmware); 229 } 230 231 static void machine_set_firmware(Object *obj, const char *value, Error **errp) 232 { 233 MachineState *ms = MACHINE(obj); 234 235 ms->firmware = g_strdup(value); 236 } 237 238 static void machine_initfn(Object *obj) 239 { 240 object_property_add_str(obj, "accel", 241 machine_get_accel, machine_set_accel, NULL); 242 object_property_add_bool(obj, "kernel-irqchip", 243 machine_get_kernel_irqchip, 244 machine_set_kernel_irqchip, 245 NULL); 246 object_property_add(obj, "kvm-shadow-mem", "int", 247 machine_get_kvm_shadow_mem, 248 machine_set_kvm_shadow_mem, 249 NULL, NULL, NULL); 250 object_property_add_str(obj, "kernel", 251 machine_get_kernel, machine_set_kernel, NULL); 252 object_property_add_str(obj, "initrd", 253 machine_get_initrd, machine_set_initrd, NULL); 254 object_property_add_str(obj, "append", 255 machine_get_append, machine_set_append, NULL); 256 object_property_add_str(obj, "dtb", 257 machine_get_dtb, machine_set_dtb, NULL); 258 object_property_add_str(obj, "dumpdtb", 259 machine_get_dumpdtb, machine_set_dumpdtb, NULL); 260 object_property_add(obj, "phandle-start", "int", 261 machine_get_phandle_start, 262 machine_set_phandle_start, 263 NULL, NULL, NULL); 264 object_property_add_str(obj, "dt-compatible", 265 machine_get_dt_compatible, 266 machine_set_dt_compatible, 267 NULL); 268 object_property_add_bool(obj, "dump-guest-core", 269 machine_get_dump_guest_core, 270 machine_set_dump_guest_core, 271 NULL); 272 object_property_add_bool(obj, "mem-merge", 273 machine_get_mem_merge, machine_set_mem_merge, NULL); 274 object_property_add_bool(obj, "usb", machine_get_usb, machine_set_usb, NULL); 275 object_property_add_str(obj, "firmware", 276 machine_get_firmware, machine_set_firmware, NULL); 277 } 278 279 static void machine_finalize(Object *obj) 280 { 281 MachineState *ms = MACHINE(obj); 282 283 g_free(ms->accel); 284 g_free(ms->kernel_filename); 285 g_free(ms->initrd_filename); 286 g_free(ms->kernel_cmdline); 287 g_free(ms->dtb); 288 g_free(ms->dumpdtb); 289 g_free(ms->dt_compatible); 290 g_free(ms->firmware); 291 } 292 293 static const TypeInfo machine_info = { 294 .name = TYPE_MACHINE, 295 .parent = TYPE_OBJECT, 296 .abstract = true, 297 .class_size = sizeof(MachineClass), 298 .instance_size = sizeof(MachineState), 299 .instance_init = machine_initfn, 300 .instance_finalize = machine_finalize, 301 }; 302 303 static void machine_register_types(void) 304 { 305 type_register_static(&machine_info); 306 } 307 308 type_init(machine_register_types) 309