hw/core: Clean up includes
[qemu/ar7.git] / hw / core / machine.c
blob1261368add36eccc40016f382b887c104877766e
1 /*
2 * QEMU Machine
4 * Copyright (C) 2014 Red Hat Inc
6 * Authors:
7 * Marcel Apfelbaum <marcel.a@redhat.com>
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.
13 #include "qemu/osdep.h"
14 #include "hw/boards.h"
15 #include "qapi-visit.h"
16 #include "qapi/visitor.h"
17 #include "hw/sysbus.h"
18 #include "sysemu/sysemu.h"
19 #include "qemu/error-report.h"
21 static char *machine_get_accel(Object *obj, Error **errp)
23 MachineState *ms = MACHINE(obj);
25 return g_strdup(ms->accel);
28 static void machine_set_accel(Object *obj, const char *value, Error **errp)
30 MachineState *ms = MACHINE(obj);
32 g_free(ms->accel);
33 ms->accel = g_strdup(value);
36 static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
37 void *opaque, const char *name,
38 Error **errp)
40 Error *err = NULL;
41 MachineState *ms = MACHINE(obj);
42 OnOffSplit mode;
44 visit_type_OnOffSplit(v, &mode, name, &err);
45 if (err) {
46 error_propagate(errp, err);
47 return;
48 } else {
49 switch (mode) {
50 case ON_OFF_SPLIT_ON:
51 ms->kernel_irqchip_allowed = true;
52 ms->kernel_irqchip_required = true;
53 ms->kernel_irqchip_split = false;
54 break;
55 case ON_OFF_SPLIT_OFF:
56 ms->kernel_irqchip_allowed = false;
57 ms->kernel_irqchip_required = false;
58 ms->kernel_irqchip_split = false;
59 break;
60 case ON_OFF_SPLIT_SPLIT:
61 ms->kernel_irqchip_allowed = true;
62 ms->kernel_irqchip_required = true;
63 ms->kernel_irqchip_split = true;
64 break;
65 default:
66 abort();
71 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
72 void *opaque, const char *name,
73 Error **errp)
75 MachineState *ms = MACHINE(obj);
76 int64_t value = ms->kvm_shadow_mem;
78 visit_type_int(v, &value, name, errp);
81 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
82 void *opaque, const char *name,
83 Error **errp)
85 MachineState *ms = MACHINE(obj);
86 Error *error = NULL;
87 int64_t value;
89 visit_type_int(v, &value, name, &error);
90 if (error) {
91 error_propagate(errp, error);
92 return;
95 ms->kvm_shadow_mem = value;
98 static char *machine_get_kernel(Object *obj, Error **errp)
100 MachineState *ms = MACHINE(obj);
102 return g_strdup(ms->kernel_filename);
105 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
107 MachineState *ms = MACHINE(obj);
109 g_free(ms->kernel_filename);
110 ms->kernel_filename = g_strdup(value);
113 static char *machine_get_initrd(Object *obj, Error **errp)
115 MachineState *ms = MACHINE(obj);
117 return g_strdup(ms->initrd_filename);
120 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
122 MachineState *ms = MACHINE(obj);
124 g_free(ms->initrd_filename);
125 ms->initrd_filename = g_strdup(value);
128 static char *machine_get_append(Object *obj, Error **errp)
130 MachineState *ms = MACHINE(obj);
132 return g_strdup(ms->kernel_cmdline);
135 static void machine_set_append(Object *obj, const char *value, Error **errp)
137 MachineState *ms = MACHINE(obj);
139 g_free(ms->kernel_cmdline);
140 ms->kernel_cmdline = g_strdup(value);
143 static char *machine_get_dtb(Object *obj, Error **errp)
145 MachineState *ms = MACHINE(obj);
147 return g_strdup(ms->dtb);
150 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
152 MachineState *ms = MACHINE(obj);
154 g_free(ms->dtb);
155 ms->dtb = g_strdup(value);
158 static char *machine_get_dumpdtb(Object *obj, Error **errp)
160 MachineState *ms = MACHINE(obj);
162 return g_strdup(ms->dumpdtb);
165 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
167 MachineState *ms = MACHINE(obj);
169 g_free(ms->dumpdtb);
170 ms->dumpdtb = g_strdup(value);
173 static void machine_get_phandle_start(Object *obj, Visitor *v,
174 void *opaque, const char *name,
175 Error **errp)
177 MachineState *ms = MACHINE(obj);
178 int64_t value = ms->phandle_start;
180 visit_type_int(v, &value, name, errp);
183 static void machine_set_phandle_start(Object *obj, Visitor *v,
184 void *opaque, const char *name,
185 Error **errp)
187 MachineState *ms = MACHINE(obj);
188 Error *error = NULL;
189 int64_t value;
191 visit_type_int(v, &value, name, &error);
192 if (error) {
193 error_propagate(errp, error);
194 return;
197 ms->phandle_start = value;
200 static char *machine_get_dt_compatible(Object *obj, Error **errp)
202 MachineState *ms = MACHINE(obj);
204 return g_strdup(ms->dt_compatible);
207 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
209 MachineState *ms = MACHINE(obj);
211 g_free(ms->dt_compatible);
212 ms->dt_compatible = g_strdup(value);
215 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
217 MachineState *ms = MACHINE(obj);
219 return ms->dump_guest_core;
222 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
224 MachineState *ms = MACHINE(obj);
226 ms->dump_guest_core = value;
229 static bool machine_get_mem_merge(Object *obj, Error **errp)
231 MachineState *ms = MACHINE(obj);
233 return ms->mem_merge;
236 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
238 MachineState *ms = MACHINE(obj);
240 ms->mem_merge = value;
243 static bool machine_get_usb(Object *obj, Error **errp)
245 MachineState *ms = MACHINE(obj);
247 return ms->usb;
250 static void machine_set_usb(Object *obj, bool value, Error **errp)
252 MachineState *ms = MACHINE(obj);
254 ms->usb = value;
255 ms->usb_disabled = !value;
258 static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp)
260 MachineState *ms = MACHINE(obj);
262 return ms->igd_gfx_passthru;
265 static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp)
267 MachineState *ms = MACHINE(obj);
269 ms->igd_gfx_passthru = value;
272 static char *machine_get_firmware(Object *obj, Error **errp)
274 MachineState *ms = MACHINE(obj);
276 return g_strdup(ms->firmware);
279 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
281 MachineState *ms = MACHINE(obj);
283 g_free(ms->firmware);
284 ms->firmware = g_strdup(value);
287 static bool machine_get_iommu(Object *obj, Error **errp)
289 MachineState *ms = MACHINE(obj);
291 return ms->iommu;
294 static void machine_set_iommu(Object *obj, bool value, Error **errp)
296 MachineState *ms = MACHINE(obj);
298 ms->iommu = value;
301 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
303 MachineState *ms = MACHINE(obj);
305 ms->suppress_vmdesc = value;
308 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
310 MachineState *ms = MACHINE(obj);
312 return ms->suppress_vmdesc;
315 static int error_on_sysbus_device(SysBusDevice *sbdev, void *opaque)
317 error_report("Option '-device %s' cannot be handled by this machine",
318 object_class_get_name(object_get_class(OBJECT(sbdev))));
319 exit(1);
322 static void machine_init_notify(Notifier *notifier, void *data)
324 Object *machine = qdev_get_machine();
325 ObjectClass *oc = object_get_class(machine);
326 MachineClass *mc = MACHINE_CLASS(oc);
328 if (mc->has_dynamic_sysbus) {
329 /* Our machine can handle dynamic sysbus devices, we're all good */
330 return;
334 * Loop through all dynamically created devices and check whether there
335 * are sysbus devices among them. If there are, error out.
337 foreach_dynamic_sysbus_device(error_on_sysbus_device, NULL);
340 static void machine_class_init(ObjectClass *oc, void *data)
342 MachineClass *mc = MACHINE_CLASS(oc);
344 /* Default 128 MB as guest ram size */
345 mc->default_ram_size = 128 * M_BYTE;
346 mc->rom_file_has_mr = true;
349 static void machine_class_base_init(ObjectClass *oc, void *data)
351 if (!object_class_is_abstract(oc)) {
352 MachineClass *mc = MACHINE_CLASS(oc);
353 const char *cname = object_class_get_name(oc);
354 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
355 mc->name = g_strndup(cname,
356 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
360 static void machine_initfn(Object *obj)
362 MachineState *ms = MACHINE(obj);
364 ms->kernel_irqchip_allowed = true;
365 ms->kvm_shadow_mem = -1;
366 ms->dump_guest_core = true;
367 ms->mem_merge = true;
369 object_property_add_str(obj, "accel",
370 machine_get_accel, machine_set_accel, NULL);
371 object_property_set_description(obj, "accel",
372 "Accelerator list",
373 NULL);
374 object_property_add(obj, "kernel-irqchip", "OnOffSplit",
375 NULL,
376 machine_set_kernel_irqchip,
377 NULL, NULL, NULL);
378 object_property_set_description(obj, "kernel-irqchip",
379 "Configure KVM in-kernel irqchip",
380 NULL);
381 object_property_add(obj, "kvm-shadow-mem", "int",
382 machine_get_kvm_shadow_mem,
383 machine_set_kvm_shadow_mem,
384 NULL, NULL, NULL);
385 object_property_set_description(obj, "kvm-shadow-mem",
386 "KVM shadow MMU size",
387 NULL);
388 object_property_add_str(obj, "kernel",
389 machine_get_kernel, machine_set_kernel, NULL);
390 object_property_set_description(obj, "kernel",
391 "Linux kernel image file",
392 NULL);
393 object_property_add_str(obj, "initrd",
394 machine_get_initrd, machine_set_initrd, NULL);
395 object_property_set_description(obj, "initrd",
396 "Linux initial ramdisk file",
397 NULL);
398 object_property_add_str(obj, "append",
399 machine_get_append, machine_set_append, NULL);
400 object_property_set_description(obj, "append",
401 "Linux kernel command line",
402 NULL);
403 object_property_add_str(obj, "dtb",
404 machine_get_dtb, machine_set_dtb, NULL);
405 object_property_set_description(obj, "dtb",
406 "Linux kernel device tree file",
407 NULL);
408 object_property_add_str(obj, "dumpdtb",
409 machine_get_dumpdtb, machine_set_dumpdtb, NULL);
410 object_property_set_description(obj, "dumpdtb",
411 "Dump current dtb to a file and quit",
412 NULL);
413 object_property_add(obj, "phandle-start", "int",
414 machine_get_phandle_start,
415 machine_set_phandle_start,
416 NULL, NULL, NULL);
417 object_property_set_description(obj, "phandle-start",
418 "The first phandle ID we may generate dynamically",
419 NULL);
420 object_property_add_str(obj, "dt-compatible",
421 machine_get_dt_compatible,
422 machine_set_dt_compatible,
423 NULL);
424 object_property_set_description(obj, "dt-compatible",
425 "Overrides the \"compatible\" property of the dt root node",
426 NULL);
427 object_property_add_bool(obj, "dump-guest-core",
428 machine_get_dump_guest_core,
429 machine_set_dump_guest_core,
430 NULL);
431 object_property_set_description(obj, "dump-guest-core",
432 "Include guest memory in a core dump",
433 NULL);
434 object_property_add_bool(obj, "mem-merge",
435 machine_get_mem_merge,
436 machine_set_mem_merge, NULL);
437 object_property_set_description(obj, "mem-merge",
438 "Enable/disable memory merge support",
439 NULL);
440 object_property_add_bool(obj, "usb",
441 machine_get_usb,
442 machine_set_usb, NULL);
443 object_property_set_description(obj, "usb",
444 "Set on/off to enable/disable usb",
445 NULL);
446 object_property_add_bool(obj, "igd-passthru",
447 machine_get_igd_gfx_passthru,
448 machine_set_igd_gfx_passthru, NULL);
449 object_property_set_description(obj, "igd-passthru",
450 "Set on/off to enable/disable igd passthrou",
451 NULL);
452 object_property_add_str(obj, "firmware",
453 machine_get_firmware,
454 machine_set_firmware, NULL);
455 object_property_set_description(obj, "firmware",
456 "Firmware image",
457 NULL);
458 object_property_add_bool(obj, "iommu",
459 machine_get_iommu,
460 machine_set_iommu, NULL);
461 object_property_set_description(obj, "iommu",
462 "Set on/off to enable/disable Intel IOMMU (VT-d)",
463 NULL);
464 object_property_add_bool(obj, "suppress-vmdesc",
465 machine_get_suppress_vmdesc,
466 machine_set_suppress_vmdesc, NULL);
467 object_property_set_description(obj, "suppress-vmdesc",
468 "Set on to disable self-describing migration",
469 NULL);
471 /* Register notifier when init is done for sysbus sanity checks */
472 ms->sysbus_notifier.notify = machine_init_notify;
473 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
476 static void machine_finalize(Object *obj)
478 MachineState *ms = MACHINE(obj);
480 g_free(ms->accel);
481 g_free(ms->kernel_filename);
482 g_free(ms->initrd_filename);
483 g_free(ms->kernel_cmdline);
484 g_free(ms->dtb);
485 g_free(ms->dumpdtb);
486 g_free(ms->dt_compatible);
487 g_free(ms->firmware);
490 bool machine_usb(MachineState *machine)
492 return machine->usb;
495 bool machine_kernel_irqchip_allowed(MachineState *machine)
497 return machine->kernel_irqchip_allowed;
500 bool machine_kernel_irqchip_required(MachineState *machine)
502 return machine->kernel_irqchip_required;
505 bool machine_kernel_irqchip_split(MachineState *machine)
507 return machine->kernel_irqchip_split;
510 int machine_kvm_shadow_mem(MachineState *machine)
512 return machine->kvm_shadow_mem;
515 int machine_phandle_start(MachineState *machine)
517 return machine->phandle_start;
520 bool machine_dump_guest_core(MachineState *machine)
522 return machine->dump_guest_core;
525 bool machine_mem_merge(MachineState *machine)
527 return machine->mem_merge;
530 static const TypeInfo machine_info = {
531 .name = TYPE_MACHINE,
532 .parent = TYPE_OBJECT,
533 .abstract = true,
534 .class_size = sizeof(MachineClass),
535 .class_init = machine_class_init,
536 .class_base_init = machine_class_base_init,
537 .instance_size = sizeof(MachineState),
538 .instance_init = machine_initfn,
539 .instance_finalize = machine_finalize,
542 static void machine_register_types(void)
544 type_register_static(&machine_info);
547 type_init(machine_register_types)