Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20150316' into staging
[qemu/qmp-unstable.git] / hw / core / machine.c
blobe3a3e2ab73701ff045bb3e24fef0b8ce8ca8d6c1
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 "hw/boards.h"
14 #include "qapi/visitor.h"
15 #include "hw/sysbus.h"
16 #include "sysemu/sysemu.h"
17 #include "qemu/error-report.h"
19 static char *machine_get_accel(Object *obj, Error **errp)
21 MachineState *ms = MACHINE(obj);
23 return g_strdup(ms->accel);
26 static void machine_set_accel(Object *obj, const char *value, Error **errp)
28 MachineState *ms = MACHINE(obj);
30 g_free(ms->accel);
31 ms->accel = g_strdup(value);
34 static void machine_set_kernel_irqchip(Object *obj, bool value, Error **errp)
36 MachineState *ms = MACHINE(obj);
38 ms->kernel_irqchip_allowed = value;
39 ms->kernel_irqchip_required = value;
42 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
43 void *opaque, const char *name,
44 Error **errp)
46 MachineState *ms = MACHINE(obj);
47 int64_t value = ms->kvm_shadow_mem;
49 visit_type_int(v, &value, name, errp);
52 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
53 void *opaque, const char *name,
54 Error **errp)
56 MachineState *ms = MACHINE(obj);
57 Error *error = NULL;
58 int64_t value;
60 visit_type_int(v, &value, name, &error);
61 if (error) {
62 error_propagate(errp, error);
63 return;
66 ms->kvm_shadow_mem = value;
69 static char *machine_get_kernel(Object *obj, Error **errp)
71 MachineState *ms = MACHINE(obj);
73 return g_strdup(ms->kernel_filename);
76 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
78 MachineState *ms = MACHINE(obj);
80 g_free(ms->kernel_filename);
81 ms->kernel_filename = g_strdup(value);
84 static char *machine_get_initrd(Object *obj, Error **errp)
86 MachineState *ms = MACHINE(obj);
88 return g_strdup(ms->initrd_filename);
91 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
93 MachineState *ms = MACHINE(obj);
95 g_free(ms->initrd_filename);
96 ms->initrd_filename = g_strdup(value);
99 static char *machine_get_append(Object *obj, Error **errp)
101 MachineState *ms = MACHINE(obj);
103 return g_strdup(ms->kernel_cmdline);
106 static void machine_set_append(Object *obj, const char *value, Error **errp)
108 MachineState *ms = MACHINE(obj);
110 g_free(ms->kernel_cmdline);
111 ms->kernel_cmdline = g_strdup(value);
114 static char *machine_get_dtb(Object *obj, Error **errp)
116 MachineState *ms = MACHINE(obj);
118 return g_strdup(ms->dtb);
121 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
123 MachineState *ms = MACHINE(obj);
125 g_free(ms->dtb);
126 ms->dtb = g_strdup(value);
129 static char *machine_get_dumpdtb(Object *obj, Error **errp)
131 MachineState *ms = MACHINE(obj);
133 return g_strdup(ms->dumpdtb);
136 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
138 MachineState *ms = MACHINE(obj);
140 g_free(ms->dumpdtb);
141 ms->dumpdtb = g_strdup(value);
144 static void machine_get_phandle_start(Object *obj, Visitor *v,
145 void *opaque, const char *name,
146 Error **errp)
148 MachineState *ms = MACHINE(obj);
149 int64_t value = ms->phandle_start;
151 visit_type_int(v, &value, name, errp);
154 static void machine_set_phandle_start(Object *obj, Visitor *v,
155 void *opaque, const char *name,
156 Error **errp)
158 MachineState *ms = MACHINE(obj);
159 Error *error = NULL;
160 int64_t value;
162 visit_type_int(v, &value, name, &error);
163 if (error) {
164 error_propagate(errp, error);
165 return;
168 ms->phandle_start = value;
171 static char *machine_get_dt_compatible(Object *obj, Error **errp)
173 MachineState *ms = MACHINE(obj);
175 return g_strdup(ms->dt_compatible);
178 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
180 MachineState *ms = MACHINE(obj);
182 g_free(ms->dt_compatible);
183 ms->dt_compatible = g_strdup(value);
186 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
188 MachineState *ms = MACHINE(obj);
190 return ms->dump_guest_core;
193 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
195 MachineState *ms = MACHINE(obj);
197 ms->dump_guest_core = value;
200 static bool machine_get_mem_merge(Object *obj, Error **errp)
202 MachineState *ms = MACHINE(obj);
204 return ms->mem_merge;
207 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
209 MachineState *ms = MACHINE(obj);
211 ms->mem_merge = value;
214 static bool machine_get_usb(Object *obj, Error **errp)
216 MachineState *ms = MACHINE(obj);
218 return ms->usb;
221 static void machine_set_usb(Object *obj, bool value, Error **errp)
223 MachineState *ms = MACHINE(obj);
225 ms->usb = value;
228 static char *machine_get_firmware(Object *obj, Error **errp)
230 MachineState *ms = MACHINE(obj);
232 return g_strdup(ms->firmware);
235 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
237 MachineState *ms = MACHINE(obj);
239 g_free(ms->firmware);
240 ms->firmware = g_strdup(value);
243 static bool machine_get_iommu(Object *obj, Error **errp)
245 MachineState *ms = MACHINE(obj);
247 return ms->iommu;
250 static void machine_set_iommu(Object *obj, bool value, Error **errp)
252 MachineState *ms = MACHINE(obj);
254 ms->iommu = value;
257 static int error_on_sysbus_device(SysBusDevice *sbdev, void *opaque)
259 error_report("Option '-device %s' cannot be handled by this machine",
260 object_class_get_name(object_get_class(OBJECT(sbdev))));
261 exit(1);
264 static void machine_init_notify(Notifier *notifier, void *data)
266 Object *machine = qdev_get_machine();
267 ObjectClass *oc = object_get_class(machine);
268 MachineClass *mc = MACHINE_CLASS(oc);
270 if (mc->has_dynamic_sysbus) {
271 /* Our machine can handle dynamic sysbus devices, we're all good */
272 return;
276 * Loop through all dynamically created devices and check whether there
277 * are sysbus devices among them. If there are, error out.
279 foreach_dynamic_sysbus_device(error_on_sysbus_device, NULL);
282 static void machine_initfn(Object *obj)
284 MachineState *ms = MACHINE(obj);
286 ms->kernel_irqchip_allowed = true;
287 ms->kvm_shadow_mem = -1;
288 ms->dump_guest_core = true;
289 ms->mem_merge = true;
291 object_property_add_str(obj, "accel",
292 machine_get_accel, machine_set_accel, NULL);
293 object_property_set_description(obj, "accel",
294 "Accelerator list",
295 NULL);
296 object_property_add_bool(obj, "kernel-irqchip",
297 NULL,
298 machine_set_kernel_irqchip,
299 NULL);
300 object_property_set_description(obj, "kernel-irqchip",
301 "Use KVM in-kernel irqchip",
302 NULL);
303 object_property_add(obj, "kvm-shadow-mem", "int",
304 machine_get_kvm_shadow_mem,
305 machine_set_kvm_shadow_mem,
306 NULL, NULL, NULL);
307 object_property_set_description(obj, "kvm-shadow-mem",
308 "KVM shadow MMU size",
309 NULL);
310 object_property_add_str(obj, "kernel",
311 machine_get_kernel, machine_set_kernel, NULL);
312 object_property_set_description(obj, "kernel",
313 "Linux kernel image file",
314 NULL);
315 object_property_add_str(obj, "initrd",
316 machine_get_initrd, machine_set_initrd, NULL);
317 object_property_set_description(obj, "initrd",
318 "Linux initial ramdisk file",
319 NULL);
320 object_property_add_str(obj, "append",
321 machine_get_append, machine_set_append, NULL);
322 object_property_set_description(obj, "append",
323 "Linux kernel command line",
324 NULL);
325 object_property_add_str(obj, "dtb",
326 machine_get_dtb, machine_set_dtb, NULL);
327 object_property_set_description(obj, "dtb",
328 "Linux kernel device tree file",
329 NULL);
330 object_property_add_str(obj, "dumpdtb",
331 machine_get_dumpdtb, machine_set_dumpdtb, NULL);
332 object_property_set_description(obj, "dumpdtb",
333 "Dump current dtb to a file and quit",
334 NULL);
335 object_property_add(obj, "phandle-start", "int",
336 machine_get_phandle_start,
337 machine_set_phandle_start,
338 NULL, NULL, NULL);
339 object_property_set_description(obj, "phandle-start",
340 "The first phandle ID we may generate dynamically",
341 NULL);
342 object_property_add_str(obj, "dt-compatible",
343 machine_get_dt_compatible,
344 machine_set_dt_compatible,
345 NULL);
346 object_property_set_description(obj, "dt-compatible",
347 "Overrides the \"compatible\" property of the dt root node",
348 NULL);
349 object_property_add_bool(obj, "dump-guest-core",
350 machine_get_dump_guest_core,
351 machine_set_dump_guest_core,
352 NULL);
353 object_property_set_description(obj, "dump-guest-core",
354 "Include guest memory in a core dump",
355 NULL);
356 object_property_add_bool(obj, "mem-merge",
357 machine_get_mem_merge,
358 machine_set_mem_merge, NULL);
359 object_property_set_description(obj, "mem-merge",
360 "Enable/disable memory merge support",
361 NULL);
362 object_property_add_bool(obj, "usb",
363 machine_get_usb,
364 machine_set_usb, NULL);
365 object_property_set_description(obj, "usb",
366 "Set on/off to enable/disable usb",
367 NULL);
368 object_property_add_str(obj, "firmware",
369 machine_get_firmware,
370 machine_set_firmware, NULL);
371 object_property_set_description(obj, "firmware",
372 "Firmware image",
373 NULL);
374 object_property_add_bool(obj, "iommu",
375 machine_get_iommu,
376 machine_set_iommu, NULL);
377 object_property_set_description(obj, "iommu",
378 "Set on/off to enable/disable Intel IOMMU (VT-d)",
379 NULL);
381 /* Register notifier when init is done for sysbus sanity checks */
382 ms->sysbus_notifier.notify = machine_init_notify;
383 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
386 static void machine_finalize(Object *obj)
388 MachineState *ms = MACHINE(obj);
390 g_free(ms->accel);
391 g_free(ms->kernel_filename);
392 g_free(ms->initrd_filename);
393 g_free(ms->kernel_cmdline);
394 g_free(ms->dtb);
395 g_free(ms->dumpdtb);
396 g_free(ms->dt_compatible);
397 g_free(ms->firmware);
400 bool machine_usb(MachineState *machine)
402 return machine->usb;
405 bool machine_iommu(MachineState *machine)
407 return machine->iommu;
410 bool machine_kernel_irqchip_allowed(MachineState *machine)
412 return machine->kernel_irqchip_allowed;
415 bool machine_kernel_irqchip_required(MachineState *machine)
417 return machine->kernel_irqchip_required;
420 int machine_kvm_shadow_mem(MachineState *machine)
422 return machine->kvm_shadow_mem;
425 int machine_phandle_start(MachineState *machine)
427 return machine->phandle_start;
430 bool machine_dump_guest_core(MachineState *machine)
432 return machine->dump_guest_core;
435 bool machine_mem_merge(MachineState *machine)
437 return machine->mem_merge;
440 static const TypeInfo machine_info = {
441 .name = TYPE_MACHINE,
442 .parent = TYPE_OBJECT,
443 .abstract = true,
444 .class_size = sizeof(MachineClass),
445 .instance_size = sizeof(MachineState),
446 .instance_init = machine_initfn,
447 .instance_finalize = machine_finalize,
450 static void machine_register_types(void)
452 type_register_static(&machine_info);
455 type_init(machine_register_types)