]> git.proxmox.com Git - mirror_qemu.git/blame - hw/core/machine.c
hw: remove SET_MACHINE_COMPAT
[mirror_qemu.git] / hw / core / machine.c
CommitLineData
36d20cb2
MA
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
18c86e2b 13#include "qemu/osdep.h"
fc6b3cf9 14#include "qemu/units.h"
36d20cb2 15#include "hw/boards.h"
da34e65c 16#include "qapi/error.h"
9af23989 17#include "qapi/qapi-visit-common.h"
6b1b1440 18#include "qapi/visitor.h"
33cd52b5
AG
19#include "hw/sysbus.h"
20#include "sysemu/sysemu.h"
3bfe5716 21#include "sysemu/numa.h"
33cd52b5 22#include "qemu/error-report.h"
c6ff347c 23#include "sysemu/qtest.h"
6b1b1440
MA
24
25static char *machine_get_accel(Object *obj, Error **errp)
26{
27 MachineState *ms = MACHINE(obj);
28
29 return g_strdup(ms->accel);
30}
31
32static void machine_set_accel(Object *obj, const char *value, Error **errp)
33{
34 MachineState *ms = MACHINE(obj);
35
556068ee 36 g_free(ms->accel);
6b1b1440
MA
37 ms->accel = g_strdup(value);
38}
39
32c18a2d 40static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
d7bce999 41 const char *name, void *opaque,
32c18a2d 42 Error **errp)
6b1b1440 43{
32c18a2d 44 Error *err = NULL;
6b1b1440 45 MachineState *ms = MACHINE(obj);
32c18a2d 46 OnOffSplit mode;
6b1b1440 47
51e72bc1 48 visit_type_OnOffSplit(v, name, &mode, &err);
32c18a2d
MG
49 if (err) {
50 error_propagate(errp, err);
51 return;
52 } else {
53 switch (mode) {
54 case ON_OFF_SPLIT_ON:
55 ms->kernel_irqchip_allowed = true;
56 ms->kernel_irqchip_required = true;
57 ms->kernel_irqchip_split = false;
58 break;
59 case ON_OFF_SPLIT_OFF:
60 ms->kernel_irqchip_allowed = false;
61 ms->kernel_irqchip_required = false;
62 ms->kernel_irqchip_split = false;
63 break;
64 case ON_OFF_SPLIT_SPLIT:
65 ms->kernel_irqchip_allowed = true;
66 ms->kernel_irqchip_required = true;
67 ms->kernel_irqchip_split = true;
68 break;
69 default:
78a39306
GK
70 /* The value was checked in visit_type_OnOffSplit() above. If
71 * we get here, then something is wrong in QEMU.
72 */
32c18a2d
MG
73 abort();
74 }
75 }
6b1b1440
MA
76}
77
78static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
d7bce999 79 const char *name, void *opaque,
6b1b1440
MA
80 Error **errp)
81{
82 MachineState *ms = MACHINE(obj);
83 int64_t value = ms->kvm_shadow_mem;
84
51e72bc1 85 visit_type_int(v, name, &value, errp);
6b1b1440
MA
86}
87
88static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
d7bce999 89 const char *name, void *opaque,
6b1b1440
MA
90 Error **errp)
91{
92 MachineState *ms = MACHINE(obj);
93 Error *error = NULL;
94 int64_t value;
95
51e72bc1 96 visit_type_int(v, name, &value, &error);
6b1b1440
MA
97 if (error) {
98 error_propagate(errp, error);
99 return;
100 }
101
102 ms->kvm_shadow_mem = value;
103}
104
105static char *machine_get_kernel(Object *obj, Error **errp)
106{
107 MachineState *ms = MACHINE(obj);
108
109 return g_strdup(ms->kernel_filename);
110}
111
112static void machine_set_kernel(Object *obj, const char *value, Error **errp)
113{
114 MachineState *ms = MACHINE(obj);
115
556068ee 116 g_free(ms->kernel_filename);
6b1b1440
MA
117 ms->kernel_filename = g_strdup(value);
118}
119
120static char *machine_get_initrd(Object *obj, Error **errp)
121{
122 MachineState *ms = MACHINE(obj);
123
124 return g_strdup(ms->initrd_filename);
125}
126
127static void machine_set_initrd(Object *obj, const char *value, Error **errp)
128{
129 MachineState *ms = MACHINE(obj);
130
556068ee 131 g_free(ms->initrd_filename);
6b1b1440
MA
132 ms->initrd_filename = g_strdup(value);
133}
134
135static char *machine_get_append(Object *obj, Error **errp)
136{
137 MachineState *ms = MACHINE(obj);
138
139 return g_strdup(ms->kernel_cmdline);
140}
141
142static void machine_set_append(Object *obj, const char *value, Error **errp)
143{
144 MachineState *ms = MACHINE(obj);
145
556068ee 146 g_free(ms->kernel_cmdline);
6b1b1440
MA
147 ms->kernel_cmdline = g_strdup(value);
148}
149
150static char *machine_get_dtb(Object *obj, Error **errp)
151{
152 MachineState *ms = MACHINE(obj);
153
154 return g_strdup(ms->dtb);
155}
156
157static void machine_set_dtb(Object *obj, const char *value, Error **errp)
158{
159 MachineState *ms = MACHINE(obj);
160
556068ee 161 g_free(ms->dtb);
6b1b1440
MA
162 ms->dtb = g_strdup(value);
163}
164
165static char *machine_get_dumpdtb(Object *obj, Error **errp)
166{
167 MachineState *ms = MACHINE(obj);
168
169 return g_strdup(ms->dumpdtb);
170}
171
172static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
173{
174 MachineState *ms = MACHINE(obj);
175
556068ee 176 g_free(ms->dumpdtb);
6b1b1440
MA
177 ms->dumpdtb = g_strdup(value);
178}
179
180static void machine_get_phandle_start(Object *obj, Visitor *v,
d7bce999
EB
181 const char *name, void *opaque,
182 Error **errp)
6b1b1440
MA
183{
184 MachineState *ms = MACHINE(obj);
185 int64_t value = ms->phandle_start;
186
51e72bc1 187 visit_type_int(v, name, &value, errp);
6b1b1440
MA
188}
189
190static void machine_set_phandle_start(Object *obj, Visitor *v,
d7bce999
EB
191 const char *name, void *opaque,
192 Error **errp)
6b1b1440
MA
193{
194 MachineState *ms = MACHINE(obj);
195 Error *error = NULL;
196 int64_t value;
197
51e72bc1 198 visit_type_int(v, name, &value, &error);
6b1b1440
MA
199 if (error) {
200 error_propagate(errp, error);
201 return;
202 }
203
204 ms->phandle_start = value;
205}
206
207static char *machine_get_dt_compatible(Object *obj, Error **errp)
208{
209 MachineState *ms = MACHINE(obj);
210
211 return g_strdup(ms->dt_compatible);
212}
213
214static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
215{
216 MachineState *ms = MACHINE(obj);
217
556068ee 218 g_free(ms->dt_compatible);
6b1b1440
MA
219 ms->dt_compatible = g_strdup(value);
220}
221
222static bool machine_get_dump_guest_core(Object *obj, Error **errp)
223{
224 MachineState *ms = MACHINE(obj);
225
226 return ms->dump_guest_core;
227}
228
229static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
230{
231 MachineState *ms = MACHINE(obj);
232
233 ms->dump_guest_core = value;
234}
235
236static bool machine_get_mem_merge(Object *obj, Error **errp)
237{
238 MachineState *ms = MACHINE(obj);
239
240 return ms->mem_merge;
241}
242
243static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
244{
245 MachineState *ms = MACHINE(obj);
246
247 ms->mem_merge = value;
248}
249
250static bool machine_get_usb(Object *obj, Error **errp)
251{
252 MachineState *ms = MACHINE(obj);
253
254 return ms->usb;
255}
256
257static void machine_set_usb(Object *obj, bool value, Error **errp)
258{
259 MachineState *ms = MACHINE(obj);
260
261 ms->usb = value;
c6e76503 262 ms->usb_disabled = !value;
6b1b1440
MA
263}
264
cfc58cf3
EH
265static bool machine_get_graphics(Object *obj, Error **errp)
266{
267 MachineState *ms = MACHINE(obj);
268
269 return ms->enable_graphics;
270}
271
272static void machine_set_graphics(Object *obj, bool value, Error **errp)
273{
274 MachineState *ms = MACHINE(obj);
275
276 ms->enable_graphics = value;
277}
278
79814179
TC
279static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp)
280{
281 MachineState *ms = MACHINE(obj);
282
283 return ms->igd_gfx_passthru;
284}
285
286static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp)
287{
288 MachineState *ms = MACHINE(obj);
289
290 ms->igd_gfx_passthru = value;
291}
292
6b1b1440
MA
293static char *machine_get_firmware(Object *obj, Error **errp)
294{
295 MachineState *ms = MACHINE(obj);
296
297 return g_strdup(ms->firmware);
298}
299
300static void machine_set_firmware(Object *obj, const char *value, Error **errp)
301{
302 MachineState *ms = MACHINE(obj);
303
556068ee 304 g_free(ms->firmware);
6b1b1440
MA
305 ms->firmware = g_strdup(value);
306}
307
9850c604
AG
308static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
309{
310 MachineState *ms = MACHINE(obj);
311
312 ms->suppress_vmdesc = value;
313}
314
315static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
316{
317 MachineState *ms = MACHINE(obj);
318
319 return ms->suppress_vmdesc;
320}
321
902c053d
GK
322static void machine_set_enforce_config_section(Object *obj, bool value,
323 Error **errp)
324{
325 MachineState *ms = MACHINE(obj);
326
91c082ad
TH
327 warn_report("enforce-config-section is deprecated, please use "
328 "-global migration.send-configuration=on|off instead");
329
902c053d
GK
330 ms->enforce_config_section = value;
331}
332
333static bool machine_get_enforce_config_section(Object *obj, Error **errp)
334{
335 MachineState *ms = MACHINE(obj);
336
337 return ms->enforce_config_section;
338}
339
db588194
BS
340static char *machine_get_memory_encryption(Object *obj, Error **errp)
341{
342 MachineState *ms = MACHINE(obj);
343
344 return g_strdup(ms->memory_encryption);
345}
346
347static void machine_set_memory_encryption(Object *obj, const char *value,
348 Error **errp)
349{
350 MachineState *ms = MACHINE(obj);
351
352 g_free(ms->memory_encryption);
353 ms->memory_encryption = g_strdup(value);
354}
355
0bd1909d 356void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
33cd52b5 357{
0bd1909d
EH
358 strList *item = g_new0(strList, 1);
359
360 item->value = g_strdup(type);
361 item->next = mc->allowed_dynamic_sysbus_devices;
362 mc->allowed_dynamic_sysbus_devices = item;
33cd52b5
AG
363}
364
0bd1909d 365static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
33cd52b5 366{
0bd1909d
EH
367 MachineState *machine = opaque;
368 MachineClass *mc = MACHINE_GET_CLASS(machine);
369 bool allowed = false;
370 strList *wl;
33cd52b5 371
0bd1909d
EH
372 for (wl = mc->allowed_dynamic_sysbus_devices;
373 !allowed && wl;
374 wl = wl->next) {
375 allowed |= !!object_dynamic_cast(OBJECT(sbdev), wl->value);
376 }
377
378 if (!allowed) {
379 error_report("Option '-device %s' cannot be handled by this machine",
380 object_class_get_name(object_get_class(OBJECT(sbdev))));
381 exit(1);
33cd52b5 382 }
0bd1909d
EH
383}
384
385static void machine_init_notify(Notifier *notifier, void *data)
386{
387 MachineState *machine = MACHINE(qdev_get_machine());
33cd52b5
AG
388
389 /*
0bd1909d
EH
390 * Loop through all dynamically created sysbus devices and check if they are
391 * all allowed. If a device is not allowed, error out.
33cd52b5 392 */
0bd1909d 393 foreach_dynamic_sysbus_device(validate_sysbus_device, machine);
33cd52b5
AG
394}
395
f2d672c2
IM
396HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
397{
398 int i;
f2d672c2 399 HotpluggableCPUList *head = NULL;
d342eb76
IM
400 MachineClass *mc = MACHINE_GET_CLASS(machine);
401
402 /* force board to initialize possible_cpus if it hasn't been done yet */
403 mc->possible_cpu_arch_ids(machine);
f2d672c2 404
f2d672c2 405 for (i = 0; i < machine->possible_cpus->len; i++) {
d342eb76 406 Object *cpu;
f2d672c2
IM
407 HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1);
408 HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
409
d342eb76 410 cpu_item->type = g_strdup(machine->possible_cpus->cpus[i].type);
f2d672c2
IM
411 cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count;
412 cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props,
413 sizeof(*cpu_item->props));
414
415 cpu = machine->possible_cpus->cpus[i].cpu;
416 if (cpu) {
417 cpu_item->has_qom_path = true;
418 cpu_item->qom_path = object_get_canonical_path(cpu);
419 }
420 list_item->value = cpu_item;
421 list_item->next = head;
422 head = list_item;
423 }
424 return head;
425}
426
7c88e65d
IM
427/**
428 * machine_set_cpu_numa_node:
429 * @machine: machine object to modify
430 * @props: specifies which cpu objects to assign to
431 * numa node specified by @props.node_id
432 * @errp: if an error occurs, a pointer to an area to store the error
433 *
434 * Associate NUMA node specified by @props.node_id with cpu slots that
435 * match socket/core/thread-ids specified by @props. It's recommended to use
436 * query-hotpluggable-cpus.props values to specify affected cpu slots,
437 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
438 *
439 * However for CLI convenience it's possible to pass in subset of properties,
440 * which would affect all cpu slots that match it.
441 * Ex for pc machine:
442 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
443 * -numa cpu,node-id=0,socket_id=0 \
444 * -numa cpu,node-id=1,socket_id=1
445 * will assign all child cores of socket 0 to node 0 and
446 * of socket 1 to node 1.
447 *
448 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
449 * return error.
450 * Empty subset is disallowed and function will return with error in this case.
451 */
452void machine_set_cpu_numa_node(MachineState *machine,
453 const CpuInstanceProperties *props, Error **errp)
454{
455 MachineClass *mc = MACHINE_GET_CLASS(machine);
456 bool match = false;
457 int i;
458
459 if (!mc->possible_cpu_arch_ids) {
460 error_setg(errp, "mapping of CPUs to NUMA node is not supported");
461 return;
462 }
463
464 /* disabling node mapping is not supported, forbid it */
465 assert(props->has_node_id);
466
467 /* force board to initialize possible_cpus if it hasn't been done yet */
468 mc->possible_cpu_arch_ids(machine);
469
470 for (i = 0; i < machine->possible_cpus->len; i++) {
471 CPUArchId *slot = &machine->possible_cpus->cpus[i];
472
473 /* reject unsupported by board properties */
474 if (props->has_thread_id && !slot->props.has_thread_id) {
475 error_setg(errp, "thread-id is not supported");
476 return;
477 }
478
479 if (props->has_core_id && !slot->props.has_core_id) {
480 error_setg(errp, "core-id is not supported");
481 return;
482 }
483
484 if (props->has_socket_id && !slot->props.has_socket_id) {
485 error_setg(errp, "socket-id is not supported");
486 return;
487 }
488
489 /* skip slots with explicit mismatch */
490 if (props->has_thread_id && props->thread_id != slot->props.thread_id) {
491 continue;
492 }
493
494 if (props->has_core_id && props->core_id != slot->props.core_id) {
495 continue;
496 }
497
498 if (props->has_socket_id && props->socket_id != slot->props.socket_id) {
499 continue;
500 }
501
502 /* reject assignment if slot is already assigned, for compatibility
503 * of legacy cpu_index mapping with SPAPR core based mapping do not
504 * error out if cpu thread and matched core have the same node-id */
505 if (slot->props.has_node_id &&
506 slot->props.node_id != props->node_id) {
507 error_setg(errp, "CPU is already assigned to node-id: %" PRId64,
508 slot->props.node_id);
509 return;
510 }
511
512 /* assign slot to node as it's matched '-numa cpu' key */
513 match = true;
514 slot->props.node_id = props->node_id;
515 slot->props.has_node_id = props->has_node_id;
516 }
517
518 if (!match) {
519 error_setg(errp, "no match found");
520 }
521}
522
076b35b5
ND
523static void machine_class_init(ObjectClass *oc, void *data)
524{
525 MachineClass *mc = MACHINE_CLASS(oc);
526
527 /* Default 128 MB as guest ram size */
d23b6caa 528 mc->default_ram_size = 128 * MiB;
71ae9e94 529 mc->rom_file_has_mr = true;
26b81df4 530
55641213
LV
531 /* numa node memory size aligned on 8MB by default.
532 * On Linux, each node's border has to be 8MB aligned
533 */
534 mc->numa_mem_align_shift = 23;
3bfe5716 535 mc->numa_auto_assign_ram = numa_default_auto_assign_ram;
55641213 536
26b81df4
EH
537 object_class_property_add_str(oc, "accel",
538 machine_get_accel, machine_set_accel, &error_abort);
539 object_class_property_set_description(oc, "accel",
540 "Accelerator list", &error_abort);
541
e80200c5 542 object_class_property_add(oc, "kernel-irqchip", "on|off|split",
26b81df4
EH
543 NULL, machine_set_kernel_irqchip,
544 NULL, NULL, &error_abort);
545 object_class_property_set_description(oc, "kernel-irqchip",
546 "Configure KVM in-kernel irqchip", &error_abort);
547
548 object_class_property_add(oc, "kvm-shadow-mem", "int",
549 machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem,
550 NULL, NULL, &error_abort);
551 object_class_property_set_description(oc, "kvm-shadow-mem",
552 "KVM shadow MMU size", &error_abort);
553
554 object_class_property_add_str(oc, "kernel",
555 machine_get_kernel, machine_set_kernel, &error_abort);
556 object_class_property_set_description(oc, "kernel",
557 "Linux kernel image file", &error_abort);
558
559 object_class_property_add_str(oc, "initrd",
560 machine_get_initrd, machine_set_initrd, &error_abort);
561 object_class_property_set_description(oc, "initrd",
562 "Linux initial ramdisk file", &error_abort);
563
564 object_class_property_add_str(oc, "append",
565 machine_get_append, machine_set_append, &error_abort);
566 object_class_property_set_description(oc, "append",
567 "Linux kernel command line", &error_abort);
568
569 object_class_property_add_str(oc, "dtb",
570 machine_get_dtb, machine_set_dtb, &error_abort);
571 object_class_property_set_description(oc, "dtb",
572 "Linux kernel device tree file", &error_abort);
573
574 object_class_property_add_str(oc, "dumpdtb",
575 machine_get_dumpdtb, machine_set_dumpdtb, &error_abort);
576 object_class_property_set_description(oc, "dumpdtb",
577 "Dump current dtb to a file and quit", &error_abort);
578
579 object_class_property_add(oc, "phandle-start", "int",
580 machine_get_phandle_start, machine_set_phandle_start,
581 NULL, NULL, &error_abort);
582 object_class_property_set_description(oc, "phandle-start",
583 "The first phandle ID we may generate dynamically", &error_abort);
584
585 object_class_property_add_str(oc, "dt-compatible",
586 machine_get_dt_compatible, machine_set_dt_compatible, &error_abort);
587 object_class_property_set_description(oc, "dt-compatible",
588 "Overrides the \"compatible\" property of the dt root node",
589 &error_abort);
590
591 object_class_property_add_bool(oc, "dump-guest-core",
592 machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort);
593 object_class_property_set_description(oc, "dump-guest-core",
594 "Include guest memory in a core dump", &error_abort);
595
596 object_class_property_add_bool(oc, "mem-merge",
597 machine_get_mem_merge, machine_set_mem_merge, &error_abort);
598 object_class_property_set_description(oc, "mem-merge",
599 "Enable/disable memory merge support", &error_abort);
600
601 object_class_property_add_bool(oc, "usb",
602 machine_get_usb, machine_set_usb, &error_abort);
603 object_class_property_set_description(oc, "usb",
604 "Set on/off to enable/disable usb", &error_abort);
605
606 object_class_property_add_bool(oc, "graphics",
607 machine_get_graphics, machine_set_graphics, &error_abort);
608 object_class_property_set_description(oc, "graphics",
609 "Set on/off to enable/disable graphics emulation", &error_abort);
610
611 object_class_property_add_bool(oc, "igd-passthru",
612 machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru,
613 &error_abort);
614 object_class_property_set_description(oc, "igd-passthru",
615 "Set on/off to enable/disable igd passthrou", &error_abort);
616
617 object_class_property_add_str(oc, "firmware",
618 machine_get_firmware, machine_set_firmware,
619 &error_abort);
620 object_class_property_set_description(oc, "firmware",
621 "Firmware image", &error_abort);
622
623 object_class_property_add_bool(oc, "suppress-vmdesc",
624 machine_get_suppress_vmdesc, machine_set_suppress_vmdesc,
625 &error_abort);
626 object_class_property_set_description(oc, "suppress-vmdesc",
627 "Set on to disable self-describing migration", &error_abort);
628
629 object_class_property_add_bool(oc, "enforce-config-section",
630 machine_get_enforce_config_section, machine_set_enforce_config_section,
631 &error_abort);
632 object_class_property_set_description(oc, "enforce-config-section",
633 "Set on to enforce configuration section migration", &error_abort);
db588194
BS
634
635 object_class_property_add_str(oc, "memory-encryption",
636 machine_get_memory_encryption, machine_set_memory_encryption,
637 &error_abort);
638 object_class_property_set_description(oc, "memory-encryption",
bfec23a0 639 "Set memory encryption object to use", &error_abort);
076b35b5
ND
640}
641
dcb3d601
EH
642static void machine_class_base_init(ObjectClass *oc, void *data)
643{
644 if (!object_class_is_abstract(oc)) {
98cec76a 645 MachineClass *mc = MACHINE_CLASS(oc);
dcb3d601
EH
646 const char *cname = object_class_get_name(oc);
647 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
98cec76a
EH
648 mc->name = g_strndup(cname,
649 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
b66bbee3 650 mc->compat_props = g_ptr_array_new();
dcb3d601
EH
651 }
652}
653
6b1b1440
MA
654static void machine_initfn(Object *obj)
655{
33cd52b5 656 MachineState *ms = MACHINE(obj);
b2fc91db 657 MachineClass *mc = MACHINE_GET_CLASS(obj);
33cd52b5 658
d8870d02 659 ms->kernel_irqchip_allowed = true;
b2fc91db 660 ms->kernel_irqchip_split = mc->default_kernel_irqchip_split;
4689b77b 661 ms->kvm_shadow_mem = -1;
47c8ca53 662 ms->dump_guest_core = true;
75cc7f01 663 ms->mem_merge = true;
cfc58cf3 664 ms->enable_graphics = true;
d8870d02 665
33cd52b5
AG
666 /* Register notifier when init is done for sysbus sanity checks */
667 ms->sysbus_notifier.notify = machine_init_notify;
668 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
6b1b1440
MA
669}
670
671static void machine_finalize(Object *obj)
672{
673 MachineState *ms = MACHINE(obj);
674
675 g_free(ms->accel);
676 g_free(ms->kernel_filename);
677 g_free(ms->initrd_filename);
678 g_free(ms->kernel_cmdline);
679 g_free(ms->dtb);
680 g_free(ms->dumpdtb);
681 g_free(ms->dt_compatible);
682 g_free(ms->firmware);
2ff4f67c 683 g_free(ms->device_memory);
6b1b1440 684}
36d20cb2 685
5e97b623
MA
686bool machine_usb(MachineState *machine)
687{
688 return machine->usb;
689}
690
d8870d02
MA
691bool machine_kernel_irqchip_allowed(MachineState *machine)
692{
693 return machine->kernel_irqchip_allowed;
694}
695
696bool machine_kernel_irqchip_required(MachineState *machine)
697{
698 return machine->kernel_irqchip_required;
699}
700
32c18a2d
MG
701bool machine_kernel_irqchip_split(MachineState *machine)
702{
703 return machine->kernel_irqchip_split;
704}
705
4689b77b
MA
706int machine_kvm_shadow_mem(MachineState *machine)
707{
708 return machine->kvm_shadow_mem;
709}
710
6cabe7fa
MA
711int machine_phandle_start(MachineState *machine)
712{
713 return machine->phandle_start;
714}
715
47c8ca53
MA
716bool machine_dump_guest_core(MachineState *machine)
717{
718 return machine->dump_guest_core;
719}
720
75cc7f01
MA
721bool machine_mem_merge(MachineState *machine)
722{
723 return machine->mem_merge;
724}
725
ec78f811
IM
726static char *cpu_slot_to_string(const CPUArchId *cpu)
727{
728 GString *s = g_string_new(NULL);
729 if (cpu->props.has_socket_id) {
730 g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id);
731 }
732 if (cpu->props.has_core_id) {
733 if (s->len) {
734 g_string_append_printf(s, ", ");
735 }
736 g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id);
737 }
738 if (cpu->props.has_thread_id) {
739 if (s->len) {
740 g_string_append_printf(s, ", ");
741 }
742 g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id);
743 }
744 return g_string_free(s, false);
745}
746
7a3099fc 747static void machine_numa_finish_cpu_init(MachineState *machine)
ec78f811
IM
748{
749 int i;
60bed6a3 750 bool default_mapping;
ec78f811
IM
751 GString *s = g_string_new(NULL);
752 MachineClass *mc = MACHINE_GET_CLASS(machine);
753 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine);
754
755 assert(nb_numa_nodes);
60bed6a3
IM
756 for (i = 0; i < possible_cpus->len; i++) {
757 if (possible_cpus->cpus[i].props.has_node_id) {
758 break;
759 }
760 }
761 default_mapping = (i == possible_cpus->len);
762
ec78f811
IM
763 for (i = 0; i < possible_cpus->len; i++) {
764 const CPUArchId *cpu_slot = &possible_cpus->cpus[i];
765
ec78f811 766 if (!cpu_slot->props.has_node_id) {
d41f3e75
IM
767 /* fetch default mapping from board and enable it */
768 CpuInstanceProperties props = cpu_slot->props;
769
79e07936 770 props.node_id = mc->get_default_cpu_node_id(machine, i);
d41f3e75 771 if (!default_mapping) {
60bed6a3
IM
772 /* record slots with not set mapping,
773 * TODO: make it hard error in future */
774 char *cpu_str = cpu_slot_to_string(cpu_slot);
775 g_string_append_printf(s, "%sCPU %d [%s]",
776 s->len ? ", " : "", i, cpu_str);
777 g_free(cpu_str);
d41f3e75
IM
778
779 /* non mapped cpus used to fallback to node 0 */
780 props.node_id = 0;
60bed6a3 781 }
d41f3e75
IM
782
783 props.has_node_id = true;
784 machine_set_cpu_numa_node(machine, &props, &error_fatal);
ec78f811
IM
785 }
786 }
c6ff347c 787 if (s->len && !qtest_enabled()) {
3dc6f869
AF
788 warn_report("CPU(s) not present in any NUMA nodes: %s",
789 s->str);
790 warn_report("All CPU(s) up to maxcpus should be described "
791 "in NUMA config, ability to start up with partial NUMA "
792 "mappings is obsoleted and will be removed in future");
ec78f811
IM
793 }
794 g_string_free(s, true);
795}
796
482dfe9a
IM
797void machine_run_board_init(MachineState *machine)
798{
799 MachineClass *machine_class = MACHINE_GET_CLASS(machine);
ec78f811 800
7747abf1 801 numa_complete_configuration(machine);
3aeaac8f 802 if (nb_numa_nodes) {
7a3099fc 803 machine_numa_finish_cpu_init(machine);
3aeaac8f 804 }
c9cf636d
AF
805
806 /* If the machine supports the valid_cpu_types check and the user
807 * specified a CPU with -cpu check here that the user CPU is supported.
808 */
809 if (machine_class->valid_cpu_types && machine->cpu_type) {
810 ObjectClass *class = object_class_by_name(machine->cpu_type);
811 int i;
812
813 for (i = 0; machine_class->valid_cpu_types[i]; i++) {
814 if (object_class_dynamic_cast(class,
815 machine_class->valid_cpu_types[i])) {
816 /* The user specificed CPU is in the valid field, we are
817 * good to go.
818 */
819 break;
820 }
821 }
822
823 if (!machine_class->valid_cpu_types[i]) {
824 /* The user specified CPU is not valid */
825 error_report("Invalid CPU type: %s", machine->cpu_type);
826 error_printf("The valid types are: %s",
827 machine_class->valid_cpu_types[0]);
828 for (i = 1; machine_class->valid_cpu_types[i]; i++) {
829 error_printf(", %s", machine_class->valid_cpu_types[i]);
830 }
831 error_printf("\n");
832
833 exit(1);
834 }
835 }
836
482dfe9a
IM
837 machine_class->init(machine);
838}
839
36d20cb2
MA
840static const TypeInfo machine_info = {
841 .name = TYPE_MACHINE,
842 .parent = TYPE_OBJECT,
843 .abstract = true,
844 .class_size = sizeof(MachineClass),
076b35b5 845 .class_init = machine_class_init,
dcb3d601 846 .class_base_init = machine_class_base_init,
36d20cb2 847 .instance_size = sizeof(MachineState),
6b1b1440
MA
848 .instance_init = machine_initfn,
849 .instance_finalize = machine_finalize,
36d20cb2
MA
850};
851
852static void machine_register_types(void)
853{
854 type_register_static(&machine_info);
855}
856
857type_init(machine_register_types)