include/qemu/osdep.h: Don't include qapi/error.h
[qemu/ar7.git] / hw / core / machine.c
blob136bf275bcc3732199f9cb4ca87633595fc97237
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/error.h"
16 #include "qapi-visit.h"
17 #include "qapi/visitor.h"
18 #include "hw/sysbus.h"
19 #include "sysemu/sysemu.h"
20 #include "qemu/error-report.h"
22 static char *machine_get_accel(Object *obj, Error **errp)
24 MachineState *ms = MACHINE(obj);
26 return g_strdup(ms->accel);
29 static void machine_set_accel(Object *obj, const char *value, Error **errp)
31 MachineState *ms = MACHINE(obj);
33 g_free(ms->accel);
34 ms->accel = g_strdup(value);
37 static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
38 const char *name, void *opaque,
39 Error **errp)
41 Error *err = NULL;
42 MachineState *ms = MACHINE(obj);
43 OnOffSplit mode;
45 visit_type_OnOffSplit(v, name, &mode, &err);
46 if (err) {
47 error_propagate(errp, err);
48 return;
49 } else {
50 switch (mode) {
51 case ON_OFF_SPLIT_ON:
52 ms->kernel_irqchip_allowed = true;
53 ms->kernel_irqchip_required = true;
54 ms->kernel_irqchip_split = false;
55 break;
56 case ON_OFF_SPLIT_OFF:
57 ms->kernel_irqchip_allowed = false;
58 ms->kernel_irqchip_required = false;
59 ms->kernel_irqchip_split = false;
60 break;
61 case ON_OFF_SPLIT_SPLIT:
62 ms->kernel_irqchip_allowed = true;
63 ms->kernel_irqchip_required = true;
64 ms->kernel_irqchip_split = true;
65 break;
66 default:
67 abort();
72 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
73 const char *name, void *opaque,
74 Error **errp)
76 MachineState *ms = MACHINE(obj);
77 int64_t value = ms->kvm_shadow_mem;
79 visit_type_int(v, name, &value, errp);
82 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
83 const char *name, void *opaque,
84 Error **errp)
86 MachineState *ms = MACHINE(obj);
87 Error *error = NULL;
88 int64_t value;
90 visit_type_int(v, name, &value, &error);
91 if (error) {
92 error_propagate(errp, error);
93 return;
96 ms->kvm_shadow_mem = value;
99 static char *machine_get_kernel(Object *obj, Error **errp)
101 MachineState *ms = MACHINE(obj);
103 return g_strdup(ms->kernel_filename);
106 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
108 MachineState *ms = MACHINE(obj);
110 g_free(ms->kernel_filename);
111 ms->kernel_filename = g_strdup(value);
114 static char *machine_get_initrd(Object *obj, Error **errp)
116 MachineState *ms = MACHINE(obj);
118 return g_strdup(ms->initrd_filename);
121 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
123 MachineState *ms = MACHINE(obj);
125 g_free(ms->initrd_filename);
126 ms->initrd_filename = g_strdup(value);
129 static char *machine_get_append(Object *obj, Error **errp)
131 MachineState *ms = MACHINE(obj);
133 return g_strdup(ms->kernel_cmdline);
136 static void machine_set_append(Object *obj, const char *value, Error **errp)
138 MachineState *ms = MACHINE(obj);
140 g_free(ms->kernel_cmdline);
141 ms->kernel_cmdline = g_strdup(value);
144 static char *machine_get_dtb(Object *obj, Error **errp)
146 MachineState *ms = MACHINE(obj);
148 return g_strdup(ms->dtb);
151 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
153 MachineState *ms = MACHINE(obj);
155 g_free(ms->dtb);
156 ms->dtb = g_strdup(value);
159 static char *machine_get_dumpdtb(Object *obj, Error **errp)
161 MachineState *ms = MACHINE(obj);
163 return g_strdup(ms->dumpdtb);
166 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
168 MachineState *ms = MACHINE(obj);
170 g_free(ms->dumpdtb);
171 ms->dumpdtb = g_strdup(value);
174 static void machine_get_phandle_start(Object *obj, Visitor *v,
175 const char *name, void *opaque,
176 Error **errp)
178 MachineState *ms = MACHINE(obj);
179 int64_t value = ms->phandle_start;
181 visit_type_int(v, name, &value, errp);
184 static void machine_set_phandle_start(Object *obj, Visitor *v,
185 const char *name, void *opaque,
186 Error **errp)
188 MachineState *ms = MACHINE(obj);
189 Error *error = NULL;
190 int64_t value;
192 visit_type_int(v, name, &value, &error);
193 if (error) {
194 error_propagate(errp, error);
195 return;
198 ms->phandle_start = value;
201 static char *machine_get_dt_compatible(Object *obj, Error **errp)
203 MachineState *ms = MACHINE(obj);
205 return g_strdup(ms->dt_compatible);
208 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
210 MachineState *ms = MACHINE(obj);
212 g_free(ms->dt_compatible);
213 ms->dt_compatible = g_strdup(value);
216 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
218 MachineState *ms = MACHINE(obj);
220 return ms->dump_guest_core;
223 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
225 MachineState *ms = MACHINE(obj);
227 ms->dump_guest_core = value;
230 static bool machine_get_mem_merge(Object *obj, Error **errp)
232 MachineState *ms = MACHINE(obj);
234 return ms->mem_merge;
237 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
239 MachineState *ms = MACHINE(obj);
241 ms->mem_merge = value;
244 static bool machine_get_usb(Object *obj, Error **errp)
246 MachineState *ms = MACHINE(obj);
248 return ms->usb;
251 static void machine_set_usb(Object *obj, bool value, Error **errp)
253 MachineState *ms = MACHINE(obj);
255 ms->usb = value;
256 ms->usb_disabled = !value;
259 static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp)
261 MachineState *ms = MACHINE(obj);
263 return ms->igd_gfx_passthru;
266 static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp)
268 MachineState *ms = MACHINE(obj);
270 ms->igd_gfx_passthru = value;
273 static char *machine_get_firmware(Object *obj, Error **errp)
275 MachineState *ms = MACHINE(obj);
277 return g_strdup(ms->firmware);
280 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
282 MachineState *ms = MACHINE(obj);
284 g_free(ms->firmware);
285 ms->firmware = g_strdup(value);
288 static bool machine_get_iommu(Object *obj, Error **errp)
290 MachineState *ms = MACHINE(obj);
292 return ms->iommu;
295 static void machine_set_iommu(Object *obj, bool value, Error **errp)
297 MachineState *ms = MACHINE(obj);
299 ms->iommu = value;
302 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
304 MachineState *ms = MACHINE(obj);
306 ms->suppress_vmdesc = value;
309 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
311 MachineState *ms = MACHINE(obj);
313 return ms->suppress_vmdesc;
316 static void machine_set_enforce_config_section(Object *obj, bool value,
317 Error **errp)
319 MachineState *ms = MACHINE(obj);
321 ms->enforce_config_section = value;
324 static bool machine_get_enforce_config_section(Object *obj, Error **errp)
326 MachineState *ms = MACHINE(obj);
328 return ms->enforce_config_section;
331 static int error_on_sysbus_device(SysBusDevice *sbdev, void *opaque)
333 error_report("Option '-device %s' cannot be handled by this machine",
334 object_class_get_name(object_get_class(OBJECT(sbdev))));
335 exit(1);
338 static void machine_init_notify(Notifier *notifier, void *data)
340 Object *machine = qdev_get_machine();
341 ObjectClass *oc = object_get_class(machine);
342 MachineClass *mc = MACHINE_CLASS(oc);
344 if (mc->has_dynamic_sysbus) {
345 /* Our machine can handle dynamic sysbus devices, we're all good */
346 return;
350 * Loop through all dynamically created devices and check whether there
351 * are sysbus devices among them. If there are, error out.
353 foreach_dynamic_sysbus_device(error_on_sysbus_device, NULL);
356 static void machine_class_init(ObjectClass *oc, void *data)
358 MachineClass *mc = MACHINE_CLASS(oc);
360 /* Default 128 MB as guest ram size */
361 mc->default_ram_size = 128 * M_BYTE;
362 mc->rom_file_has_mr = true;
365 static void machine_class_base_init(ObjectClass *oc, void *data)
367 if (!object_class_is_abstract(oc)) {
368 MachineClass *mc = MACHINE_CLASS(oc);
369 const char *cname = object_class_get_name(oc);
370 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
371 mc->name = g_strndup(cname,
372 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
376 static void machine_initfn(Object *obj)
378 MachineState *ms = MACHINE(obj);
380 ms->kernel_irqchip_allowed = true;
381 ms->kvm_shadow_mem = -1;
382 ms->dump_guest_core = true;
383 ms->mem_merge = true;
385 object_property_add_str(obj, "accel",
386 machine_get_accel, machine_set_accel, NULL);
387 object_property_set_description(obj, "accel",
388 "Accelerator list",
389 NULL);
390 object_property_add(obj, "kernel-irqchip", "OnOffSplit",
391 NULL,
392 machine_set_kernel_irqchip,
393 NULL, NULL, NULL);
394 object_property_set_description(obj, "kernel-irqchip",
395 "Configure KVM in-kernel irqchip",
396 NULL);
397 object_property_add(obj, "kvm-shadow-mem", "int",
398 machine_get_kvm_shadow_mem,
399 machine_set_kvm_shadow_mem,
400 NULL, NULL, NULL);
401 object_property_set_description(obj, "kvm-shadow-mem",
402 "KVM shadow MMU size",
403 NULL);
404 object_property_add_str(obj, "kernel",
405 machine_get_kernel, machine_set_kernel, NULL);
406 object_property_set_description(obj, "kernel",
407 "Linux kernel image file",
408 NULL);
409 object_property_add_str(obj, "initrd",
410 machine_get_initrd, machine_set_initrd, NULL);
411 object_property_set_description(obj, "initrd",
412 "Linux initial ramdisk file",
413 NULL);
414 object_property_add_str(obj, "append",
415 machine_get_append, machine_set_append, NULL);
416 object_property_set_description(obj, "append",
417 "Linux kernel command line",
418 NULL);
419 object_property_add_str(obj, "dtb",
420 machine_get_dtb, machine_set_dtb, NULL);
421 object_property_set_description(obj, "dtb",
422 "Linux kernel device tree file",
423 NULL);
424 object_property_add_str(obj, "dumpdtb",
425 machine_get_dumpdtb, machine_set_dumpdtb, NULL);
426 object_property_set_description(obj, "dumpdtb",
427 "Dump current dtb to a file and quit",
428 NULL);
429 object_property_add(obj, "phandle-start", "int",
430 machine_get_phandle_start,
431 machine_set_phandle_start,
432 NULL, NULL, NULL);
433 object_property_set_description(obj, "phandle-start",
434 "The first phandle ID we may generate dynamically",
435 NULL);
436 object_property_add_str(obj, "dt-compatible",
437 machine_get_dt_compatible,
438 machine_set_dt_compatible,
439 NULL);
440 object_property_set_description(obj, "dt-compatible",
441 "Overrides the \"compatible\" property of the dt root node",
442 NULL);
443 object_property_add_bool(obj, "dump-guest-core",
444 machine_get_dump_guest_core,
445 machine_set_dump_guest_core,
446 NULL);
447 object_property_set_description(obj, "dump-guest-core",
448 "Include guest memory in a core dump",
449 NULL);
450 object_property_add_bool(obj, "mem-merge",
451 machine_get_mem_merge,
452 machine_set_mem_merge, NULL);
453 object_property_set_description(obj, "mem-merge",
454 "Enable/disable memory merge support",
455 NULL);
456 object_property_add_bool(obj, "usb",
457 machine_get_usb,
458 machine_set_usb, NULL);
459 object_property_set_description(obj, "usb",
460 "Set on/off to enable/disable usb",
461 NULL);
462 object_property_add_bool(obj, "igd-passthru",
463 machine_get_igd_gfx_passthru,
464 machine_set_igd_gfx_passthru, NULL);
465 object_property_set_description(obj, "igd-passthru",
466 "Set on/off to enable/disable igd passthrou",
467 NULL);
468 object_property_add_str(obj, "firmware",
469 machine_get_firmware,
470 machine_set_firmware, NULL);
471 object_property_set_description(obj, "firmware",
472 "Firmware image",
473 NULL);
474 object_property_add_bool(obj, "iommu",
475 machine_get_iommu,
476 machine_set_iommu, NULL);
477 object_property_set_description(obj, "iommu",
478 "Set on/off to enable/disable Intel IOMMU (VT-d)",
479 NULL);
480 object_property_add_bool(obj, "suppress-vmdesc",
481 machine_get_suppress_vmdesc,
482 machine_set_suppress_vmdesc, NULL);
483 object_property_set_description(obj, "suppress-vmdesc",
484 "Set on to disable self-describing migration",
485 NULL);
486 object_property_add_bool(obj, "enforce-config-section",
487 machine_get_enforce_config_section,
488 machine_set_enforce_config_section, NULL);
489 object_property_set_description(obj, "enforce-config-section",
490 "Set on to enforce configuration section migration",
491 NULL);
493 /* Register notifier when init is done for sysbus sanity checks */
494 ms->sysbus_notifier.notify = machine_init_notify;
495 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
498 static void machine_finalize(Object *obj)
500 MachineState *ms = MACHINE(obj);
502 g_free(ms->accel);
503 g_free(ms->kernel_filename);
504 g_free(ms->initrd_filename);
505 g_free(ms->kernel_cmdline);
506 g_free(ms->dtb);
507 g_free(ms->dumpdtb);
508 g_free(ms->dt_compatible);
509 g_free(ms->firmware);
512 bool machine_usb(MachineState *machine)
514 return machine->usb;
517 bool machine_kernel_irqchip_allowed(MachineState *machine)
519 return machine->kernel_irqchip_allowed;
522 bool machine_kernel_irqchip_required(MachineState *machine)
524 return machine->kernel_irqchip_required;
527 bool machine_kernel_irqchip_split(MachineState *machine)
529 return machine->kernel_irqchip_split;
532 int machine_kvm_shadow_mem(MachineState *machine)
534 return machine->kvm_shadow_mem;
537 int machine_phandle_start(MachineState *machine)
539 return machine->phandle_start;
542 bool machine_dump_guest_core(MachineState *machine)
544 return machine->dump_guest_core;
547 bool machine_mem_merge(MachineState *machine)
549 return machine->mem_merge;
552 static const TypeInfo machine_info = {
553 .name = TYPE_MACHINE,
554 .parent = TYPE_OBJECT,
555 .abstract = true,
556 .class_size = sizeof(MachineClass),
557 .class_init = machine_class_init,
558 .class_base_init = machine_class_base_init,
559 .instance_size = sizeof(MachineState),
560 .instance_init = machine_initfn,
561 .instance_finalize = machine_finalize,
564 static void machine_register_types(void)
566 type_register_static(&machine_info);
569 type_init(machine_register_types)