4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "hw/qdev-properties.h"
31 #include "qapi/compat-policy.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qapi/qmp/qjson.h"
35 #include "qemu-version.h"
36 #include "qemu/cutils.h"
37 #include "qemu/help_option.h"
38 #include "qemu/uuid.h"
39 #include "sysemu/reset.h"
40 #include "sysemu/runstate.h"
41 #include "sysemu/runstate-action.h"
42 #include "sysemu/seccomp.h"
43 #include "sysemu/tcg.h"
44 #include "sysemu/xen.h"
46 #include "qemu/error-report.h"
47 #include "qemu/sockets.h"
48 #include "qemu/accel.h"
50 #include "hw/isa/isa.h"
51 #include "hw/scsi/scsi.h"
52 #include "hw/display/vga.h"
53 #include "sysemu/watchdog.h"
54 #include "hw/firmware/smbios.h"
55 #include "hw/acpi/acpi.h"
56 #include "hw/xen/xen.h"
57 #include "hw/loader.h"
58 #include "monitor/qdev.h"
60 #include "net/slirp.h"
61 #include "monitor/monitor.h"
62 #include "ui/console.h"
64 #include "sysemu/sysemu.h"
65 #include "sysemu/numa.h"
66 #include "sysemu/hostmem.h"
67 #include "exec/gdbstub.h"
68 #include "qemu/timer.h"
69 #include "chardev/char.h"
70 #include "qemu/bitmap.h"
72 #include "sysemu/blockdev.h"
73 #include "hw/block/block.h"
74 #include "hw/i386/x86.h"
75 #include "hw/i386/pc.h"
76 #include "migration/misc.h"
77 #include "migration/snapshot.h"
78 #include "sysemu/tpm.h"
79 #include "sysemu/dma.h"
80 #include "hw/audio/soundhw.h"
81 #include "audio/audio.h"
82 #include "sysemu/cpus.h"
83 #include "sysemu/cpu-timers.h"
84 #include "migration/colo.h"
85 #include "migration/postcopy-ram.h"
86 #include "sysemu/kvm.h"
87 #include "sysemu/hax.h"
88 #include "qapi/qobject-input-visitor.h"
89 #include "qemu/option.h"
90 #include "qemu/config-file.h"
91 #include "qemu/qemu-options.h"
92 #include "qemu/main-loop.h"
94 #include "fsdev/qemu-fsdev.h"
96 #include "sysemu/qtest.h"
98 #include "disas/disas.h"
101 #include "trace/control.h"
102 #include "qemu/plugin.h"
103 #include "qemu/queue.h"
104 #include "sysemu/arch_init.h"
105 #include "exec/confidential-guest-support.h"
107 #include "ui/qemu-spice.h"
108 #include "qapi/string-input-visitor.h"
109 #include "qapi/opts-visitor.h"
110 #include "qapi/clone-visitor.h"
111 #include "qom/object_interfaces.h"
112 #include "semihosting/semihost.h"
113 #include "crypto/init.h"
114 #include "sysemu/replay.h"
115 #include "qapi/qapi-events-run-state.h"
116 #include "qapi/qapi-visit-block-core.h"
117 #include "qapi/qapi-visit-compat.h"
118 #include "qapi/qapi-visit-ui.h"
119 #include "qapi/qapi-commands-block-core.h"
120 #include "qapi/qapi-commands-migration.h"
121 #include "qapi/qapi-commands-misc.h"
122 #include "qapi/qapi-visit-qom.h"
123 #include "qapi/qapi-commands-ui.h"
124 #include "qapi/qmp/qerror.h"
125 #include "sysemu/iothread.h"
126 #include "qemu/guest-random.h"
128 #define MAX_VIRTIO_CONSOLES 1
130 typedef struct BlockdevOptionsQueueEntry
{
131 BlockdevOptions
*bdo
;
133 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry
) entry
;
134 } BlockdevOptionsQueueEntry
;
136 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry
) BlockdevOptionsQueue
;
138 typedef struct ObjectOption
{
140 QTAILQ_ENTRY(ObjectOption
) next
;
143 static const char *cpu_option
;
144 static const char *mem_path
;
145 static const char *incoming
;
146 static const char *loadvm
;
147 static QTAILQ_HEAD(, ObjectOption
) object_opts
= QTAILQ_HEAD_INITIALIZER(object_opts
);
148 static ram_addr_t maxram_size
;
149 static uint64_t ram_slots
;
150 static int display_remote
;
152 static bool preconfig_requested
;
153 static QemuPluginList plugin_list
= QTAILQ_HEAD_INITIALIZER(plugin_list
);
154 static BlockdevOptionsQueue bdo_queue
= QSIMPLEQ_HEAD_INITIALIZER(bdo_queue
);
155 static bool nographic
= false;
156 static int mem_prealloc
; /* force preallocation of physical target memory */
157 static ram_addr_t ram_size
;
158 static const char *vga_model
= NULL
;
159 static DisplayOptions dpy
;
160 static int num_serial_hds
;
161 static Chardev
**serial_hds
;
162 static const char *log_mask
;
163 static const char *log_file
;
164 static bool list_data_dirs
;
165 static const char *watchdog
;
166 static const char *qtest_chrdev
;
167 static const char *qtest_log
;
169 static int has_defaults
= 1;
170 static int default_serial
= 1;
171 static int default_parallel
= 1;
172 static int default_monitor
= 1;
173 static int default_floppy
= 1;
174 static int default_cdrom
= 1;
175 static int default_sdcard
= 1;
176 static int default_vga
= 1;
177 static int default_net
= 1;
183 { .driver
= "isa-serial", .flag
= &default_serial
},
184 { .driver
= "isa-parallel", .flag
= &default_parallel
},
185 { .driver
= "isa-fdc", .flag
= &default_floppy
},
186 { .driver
= "floppy", .flag
= &default_floppy
},
187 { .driver
= "ide-cd", .flag
= &default_cdrom
},
188 { .driver
= "ide-hd", .flag
= &default_cdrom
},
189 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
190 { .driver
= "scsi-hd", .flag
= &default_cdrom
},
191 { .driver
= "VGA", .flag
= &default_vga
},
192 { .driver
= "isa-vga", .flag
= &default_vga
},
193 { .driver
= "cirrus-vga", .flag
= &default_vga
},
194 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
195 { .driver
= "vmware-svga", .flag
= &default_vga
},
196 { .driver
= "qxl-vga", .flag
= &default_vga
},
197 { .driver
= "virtio-vga", .flag
= &default_vga
},
198 { .driver
= "ati-vga", .flag
= &default_vga
},
199 { .driver
= "vhost-user-vga", .flag
= &default_vga
},
202 static QemuOptsList qemu_rtc_opts
= {
204 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
209 .type
= QEMU_OPT_STRING
,
212 .type
= QEMU_OPT_STRING
,
215 .type
= QEMU_OPT_STRING
,
217 { /* end of list */ }
221 static QemuOptsList qemu_option_rom_opts
= {
222 .name
= "option-rom",
223 .implied_opt_name
= "romfile",
224 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
228 .type
= QEMU_OPT_NUMBER
,
231 .type
= QEMU_OPT_STRING
,
233 { /* end of list */ }
237 static QemuOptsList qemu_machine_opts
= {
239 .implied_opt_name
= "type",
241 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
244 * no elements => accept any
245 * sanity checking will happen later
246 * when setting machine properties
252 static QemuOptsList qemu_accel_opts
= {
254 .implied_opt_name
= "accel",
255 .head
= QTAILQ_HEAD_INITIALIZER(qemu_accel_opts
.head
),
258 * no elements => accept any
259 * sanity checking will happen later
260 * when setting accelerator properties
266 static QemuOptsList qemu_boot_opts
= {
268 .implied_opt_name
= "order",
270 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
274 .type
= QEMU_OPT_STRING
,
277 .type
= QEMU_OPT_STRING
,
280 .type
= QEMU_OPT_BOOL
,
283 .type
= QEMU_OPT_STRING
,
285 .name
= "splash-time",
286 .type
= QEMU_OPT_NUMBER
,
288 .name
= "reboot-timeout",
289 .type
= QEMU_OPT_NUMBER
,
292 .type
= QEMU_OPT_BOOL
,
298 static QemuOptsList qemu_add_fd_opts
= {
300 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
304 .type
= QEMU_OPT_NUMBER
,
305 .help
= "file descriptor of which a duplicate is added to fd set",
308 .type
= QEMU_OPT_NUMBER
,
309 .help
= "ID of the fd set to add fd to",
312 .type
= QEMU_OPT_STRING
,
313 .help
= "free-form string used to describe fd",
315 { /* end of list */ }
319 static QemuOptsList qemu_object_opts
= {
321 .implied_opt_name
= "qom-type",
322 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
328 static QemuOptsList qemu_tpmdev_opts
= {
330 .implied_opt_name
= "type",
331 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
333 /* options are defined in the TPM backends */
334 { /* end of list */ }
338 static QemuOptsList qemu_overcommit_opts
= {
339 .name
= "overcommit",
340 .head
= QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts
.head
),
344 .type
= QEMU_OPT_BOOL
,
348 .type
= QEMU_OPT_BOOL
,
350 { /* end of list */ }
354 static QemuOptsList qemu_msg_opts
= {
356 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
360 .type
= QEMU_OPT_BOOL
,
363 .name
= "guest-name",
364 .type
= QEMU_OPT_BOOL
,
365 .help
= "Prepends guest name for error messages but only if "
366 "-name guest is set otherwise option is ignored\n",
368 { /* end of list */ }
372 static QemuOptsList qemu_name_opts
= {
374 .implied_opt_name
= "guest",
376 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
380 .type
= QEMU_OPT_STRING
,
381 .help
= "Sets the name of the guest.\n"
382 "This name will be displayed in the SDL window caption.\n"
383 "The name will also be used for the VNC server",
386 .type
= QEMU_OPT_STRING
,
387 .help
= "Sets the name of the QEMU process, as shown in top etc",
389 .name
= "debug-threads",
390 .type
= QEMU_OPT_BOOL
,
391 .help
= "When enabled, name the individual threads; defaults off.\n"
392 "NOTE: The thread names are for debugging and not a\n"
395 { /* End of list */ }
399 static QemuOptsList qemu_mem_opts
= {
401 .implied_opt_name
= "size",
402 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
407 .type
= QEMU_OPT_SIZE
,
411 .type
= QEMU_OPT_NUMBER
,
415 .type
= QEMU_OPT_SIZE
,
417 { /* end of list */ }
421 static QemuOptsList qemu_icount_opts
= {
423 .implied_opt_name
= "shift",
425 .head
= QTAILQ_HEAD_INITIALIZER(qemu_icount_opts
.head
),
429 .type
= QEMU_OPT_STRING
,
432 .type
= QEMU_OPT_BOOL
,
435 .type
= QEMU_OPT_BOOL
,
438 .type
= QEMU_OPT_STRING
,
441 .type
= QEMU_OPT_STRING
,
443 .name
= "rrsnapshot",
444 .type
= QEMU_OPT_STRING
,
446 { /* end of list */ }
450 static QemuOptsList qemu_fw_cfg_opts
= {
452 .implied_opt_name
= "name",
453 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts
.head
),
457 .type
= QEMU_OPT_STRING
,
458 .help
= "Sets the fw_cfg name of the blob to be inserted",
461 .type
= QEMU_OPT_STRING
,
462 .help
= "Sets the name of the file from which "
463 "the fw_cfg blob will be loaded",
466 .type
= QEMU_OPT_STRING
,
467 .help
= "Sets content of the blob to be inserted from a string",
470 .type
= QEMU_OPT_STRING
,
471 .help
= "Sets id of the object generating the fw_cfg blob "
474 { /* end of list */ }
478 static QemuOptsList qemu_action_opts
= {
481 .head
= QTAILQ_HEAD_INITIALIZER(qemu_action_opts
.head
),
485 .type
= QEMU_OPT_STRING
,
488 .type
= QEMU_OPT_STRING
,
491 .type
= QEMU_OPT_STRING
,
494 .type
= QEMU_OPT_STRING
,
496 { /* end of list */ }
501 * Get machine options
503 * Returns: machine options (never null).
505 static QemuOpts
*qemu_get_machine_opts(void)
507 return qemu_find_opts_singleton("machine");
510 const char *qemu_get_vm_name(void)
515 static int default_driver_check(void *opaque
, QemuOpts
*opts
, Error
**errp
)
517 const char *driver
= qemu_opt_get(opts
, "driver");
522 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
523 if (strcmp(default_list
[i
].driver
, driver
) != 0)
525 *(default_list
[i
].flag
) = 0;
530 static int parse_name(void *opaque
, QemuOpts
*opts
, Error
**errp
)
532 const char *proc_name
;
534 if (qemu_opt_get(opts
, "debug-threads")) {
535 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
537 qemu_name
= qemu_opt_get(opts
, "guest");
539 proc_name
= qemu_opt_get(opts
, "process");
541 os_set_proc_name(proc_name
);
547 bool defaults_enabled(void)
553 static int parse_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
555 int fd
, dupfd
, flags
;
557 const char *fd_opaque
= NULL
;
560 fd
= qemu_opt_get_number(opts
, "fd", -1);
561 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
562 fd_opaque
= qemu_opt_get(opts
, "opaque");
565 error_setg(errp
, "fd option is required and must be non-negative");
569 if (fd
<= STDERR_FILENO
) {
570 error_setg(errp
, "fd cannot be a standard I/O stream");
575 * All fds inherited across exec() necessarily have FD_CLOEXEC
576 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
578 flags
= fcntl(fd
, F_GETFD
);
579 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
580 error_setg(errp
, "fd is not valid or already in use");
585 error_setg(errp
, "set option is required and must be non-negative");
589 #ifdef F_DUPFD_CLOEXEC
590 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
594 qemu_set_cloexec(dupfd
);
598 error_setg(errp
, "error duplicating fd: %s", strerror(errno
));
602 /* add the duplicate fd, and optionally the opaque string, to the fd set */
603 fdinfo
= monitor_fdset_add_fd(dupfd
, true, fdset_id
, !!fd_opaque
, fd_opaque
,
610 static int cleanup_add_fd(void *opaque
, QemuOpts
*opts
, Error
**errp
)
614 fd
= qemu_opt_get_number(opts
, "fd", -1);
621 /***********************************************************/
622 /* QEMU Block devices */
624 #define HD_OPTS "media=disk"
625 #define CDROM_OPTS "media=cdrom"
627 #define PFLASH_OPTS ""
631 static int drive_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
633 BlockInterfaceType
*block_default_type
= opaque
;
635 return drive_new(opts
, *block_default_type
, errp
) == NULL
;
638 static int drive_enable_snapshot(void *opaque
, QemuOpts
*opts
, Error
**errp
)
640 if (qemu_opt_get(opts
, "snapshot") == NULL
) {
641 qemu_opt_set(opts
, "snapshot", "on", &error_abort
);
646 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
647 int index
, const char *optstr
)
652 if (!enable
|| drive_get_by_index(type
, index
)) {
656 opts
= drive_add(type
, index
, NULL
, optstr
);
658 drive_enable_snapshot(NULL
, opts
, NULL
);
661 dinfo
= drive_new(opts
, type
, &error_abort
);
662 dinfo
->is_default
= true;
666 static void configure_blockdev(BlockdevOptionsQueue
*bdo_queue
,
667 MachineClass
*machine_class
, int snapshot
)
670 * If the currently selected machine wishes to override the
671 * units-per-bus property of its default HBA interface type, do so
674 if (machine_class
->units_per_default_bus
) {
675 override_max_devs(machine_class
->block_default_type
,
676 machine_class
->units_per_default_bus
);
679 /* open the virtual block devices */
680 while (!QSIMPLEQ_EMPTY(bdo_queue
)) {
681 BlockdevOptionsQueueEntry
*bdo
= QSIMPLEQ_FIRST(bdo_queue
);
683 QSIMPLEQ_REMOVE_HEAD(bdo_queue
, entry
);
684 loc_push_restore(&bdo
->loc
);
685 qmp_blockdev_add(bdo
->bdo
, &error_fatal
);
687 qapi_free_BlockdevOptions(bdo
->bdo
);
691 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
,
694 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
695 &machine_class
->block_default_type
, &error_fatal
)) {
696 /* We printed help */
700 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
702 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
703 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
707 static QemuOptsList qemu_smp_opts
= {
709 .implied_opt_name
= "cpus",
711 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
715 .type
= QEMU_OPT_NUMBER
,
718 .type
= QEMU_OPT_NUMBER
,
721 .type
= QEMU_OPT_NUMBER
,
724 .type
= QEMU_OPT_NUMBER
,
727 .type
= QEMU_OPT_NUMBER
,
730 .type
= QEMU_OPT_NUMBER
,
736 static void realtime_init(void)
739 if (os_mlock() < 0) {
740 error_report("locking memory failed");
747 static void configure_msg(QemuOpts
*opts
)
749 message_with_timestamp
= qemu_opt_get_bool(opts
, "timestamp", false);
750 error_with_guestname
= qemu_opt_get_bool(opts
, "guest-name", false);
754 /***********************************************************/
757 static int usb_device_add(const char *devname
)
759 USBDevice
*dev
= NULL
;
761 if (!machine_usb(current_machine
)) {
765 dev
= usbdevice_create(devname
);
772 static int usb_parse(const char *cmdline
)
775 r
= usb_device_add(cmdline
);
777 error_report("could not add USB device '%s'", cmdline
);
782 /***********************************************************/
783 /* machine registration */
785 static MachineClass
*find_machine(const char *name
, GSList
*machines
)
789 for (el
= machines
; el
; el
= el
->next
) {
790 MachineClass
*mc
= el
->data
;
792 if (!strcmp(mc
->name
, name
) || !g_strcmp0(mc
->alias
, name
)) {
800 static MachineClass
*find_default_machine(GSList
*machines
)
803 MachineClass
*default_machineclass
= NULL
;
805 for (el
= machines
; el
; el
= el
->next
) {
806 MachineClass
*mc
= el
->data
;
808 if (mc
->is_default
) {
809 assert(default_machineclass
== NULL
&& "Multiple default machines");
810 default_machineclass
= mc
;
814 return default_machineclass
;
817 static int machine_help_func(QemuOpts
*opts
, MachineState
*machine
)
819 ObjectProperty
*prop
;
820 ObjectPropertyIterator iter
;
822 if (!qemu_opt_has_help_opt(opts
)) {
826 object_property_iter_init(&iter
, OBJECT(machine
));
827 while ((prop
= object_property_iter_next(&iter
))) {
832 printf("%s.%s=%s", MACHINE_GET_CLASS(machine
)->name
,
833 prop
->name
, prop
->type
);
834 if (prop
->description
) {
835 printf(" (%s)\n", prop
->description
);
844 static void version(void)
846 printf("QEMU emulator version " QEMU_FULL_VERSION
"\n"
847 QEMU_COPYRIGHT
"\n");
850 static void help(int exitcode
)
853 printf("usage: %s [options] [disk_image]\n\n"
854 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
855 error_get_progname());
857 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
858 if ((arch_mask) & arch_type) \
859 fputs(opt_help, stdout);
861 #define ARCHHEADING(text, arch_mask) \
862 if ((arch_mask) & arch_type) \
863 puts(stringify(text));
865 #define DEFHEADING(text) ARCHHEADING(text, QEMU_ARCH_ALL)
867 #include "qemu-options.def"
869 printf("\nDuring emulation, the following keys are useful:\n"
870 "ctrl-alt-f toggle full screen\n"
871 "ctrl-alt-n switch to virtual console 'n'\n"
872 "ctrl-alt toggle mouse and keyboard grab\n"
874 "When using -nographic, press 'ctrl-a h' to get some help.\n"
876 QEMU_HELP_BOTTOM
"\n");
881 #define HAS_ARG 0x0001
883 typedef struct QEMUOption
{
890 static const QEMUOption qemu_options
[] = {
891 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
893 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
894 { option, opt_arg, opt_enum, arch_mask },
895 #define DEFHEADING(text)
896 #define ARCHHEADING(text, arch_mask)
898 #include "qemu-options.def"
902 typedef struct VGAInterfaceInfo
{
903 const char *opt_name
; /* option name */
904 const char *name
; /* human-readable name */
905 /* Class names indicating that support is available.
906 * If no class is specified, the interface is always available */
907 const char *class_names
[2];
910 static const VGAInterfaceInfo vga_interfaces
[VGA_TYPE_MAX
] = {
913 .name
= "no graphic card",
917 .name
= "standard VGA",
918 .class_names
= { "VGA", "isa-vga" },
921 .opt_name
= "cirrus",
922 .name
= "Cirrus VGA",
923 .class_names
= { "cirrus-vga", "isa-cirrus-vga" },
926 .opt_name
= "vmware",
927 .name
= "VMWare SVGA",
928 .class_names
= { "vmware-svga" },
931 .opt_name
= "virtio",
932 .name
= "Virtio VGA",
933 .class_names
= { "virtio-vga" },
938 .class_names
= { "qxl-vga" },
942 .name
= "TCX framebuffer",
943 .class_names
= { "sun-tcx" },
947 .name
= "CG3 framebuffer",
948 .class_names
= { "cgthree" },
952 .name
= "Xen paravirtualized framebuffer",
956 static bool vga_interface_available(VGAInterfaceType t
)
958 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
960 assert(t
< VGA_TYPE_MAX
);
961 return !ti
->class_names
[0] ||
962 module_object_class_by_name(ti
->class_names
[0]) ||
963 module_object_class_by_name(ti
->class_names
[1]);
967 get_default_vga_model(const MachineClass
*machine_class
)
969 if (machine_class
->default_display
) {
970 return machine_class
->default_display
;
971 } else if (vga_interface_available(VGA_CIRRUS
)) {
973 } else if (vga_interface_available(VGA_STD
)) {
980 static void select_vgahw(const MachineClass
*machine_class
, const char *p
)
985 if (g_str_equal(p
, "help")) {
986 const char *def
= get_default_vga_model(machine_class
);
988 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
989 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
991 if (vga_interface_available(t
) && ti
->opt_name
) {
992 printf("%-20s %s%s\n", ti
->opt_name
, ti
->name
?: "",
993 g_str_equal(ti
->opt_name
, def
) ? " (default)" : "");
999 assert(vga_interface_type
== VGA_NONE
);
1000 for (t
= 0; t
< VGA_TYPE_MAX
; t
++) {
1001 const VGAInterfaceInfo
*ti
= &vga_interfaces
[t
];
1002 if (ti
->opt_name
&& strstart(p
, ti
->opt_name
, &opts
)) {
1003 if (!vga_interface_available(t
)) {
1004 error_report("%s not available", ti
->name
);
1007 vga_interface_type
= t
;
1011 if (t
== VGA_TYPE_MAX
) {
1013 error_report("unknown vga type: %s", p
);
1017 const char *nextopt
;
1019 if (strstart(opts
, ",retrace=", &nextopt
)) {
1021 if (strstart(opts
, "dumb", &nextopt
))
1022 vga_retrace_method
= VGA_RETRACE_DUMB
;
1023 else if (strstart(opts
, "precise", &nextopt
))
1024 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1025 else goto invalid_vga
;
1026 } else goto invalid_vga
;
1031 static void parse_display_qapi(const char *optarg
)
1033 DisplayOptions
*opts
;
1036 v
= qobject_input_visitor_new_str(optarg
, "type", &error_fatal
);
1038 visit_type_DisplayOptions(v
, NULL
, &opts
, &error_fatal
);
1039 QAPI_CLONE_MEMBERS(DisplayOptions
, &dpy
, opts
);
1041 qapi_free_DisplayOptions(opts
);
1045 DisplayOptions
*qmp_query_display_options(Error
**errp
)
1047 return QAPI_CLONE(DisplayOptions
, &dpy
);
1050 static void parse_display(const char *p
)
1054 if (is_help_option(p
)) {
1055 qemu_display_help();
1059 if (strstart(p
, "sdl", &opts
)) {
1061 * sdl DisplayType needs hand-crafted parser instead of
1062 * parse_display_qapi() due to some options not in
1063 * DisplayOptions, specifically:
1065 * Already deprecated.
1066 * - ctrl_grab + alt_grab
1067 * Not clear yet what happens to them long-term. Should
1068 * replaced by something better or deprecated and dropped.
1070 dpy
.type
= DISPLAY_TYPE_SDL
;
1072 const char *nextopt
;
1074 if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1076 if (strstart(opts
, "on", &nextopt
)) {
1078 } else if (strstart(opts
, "off", &nextopt
)) {
1081 goto invalid_sdl_args
;
1083 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1085 if (strstart(opts
, "on", &nextopt
)) {
1087 } else if (strstart(opts
, "off", &nextopt
)) {
1090 goto invalid_sdl_args
;
1092 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1094 dpy
.has_window_close
= true;
1095 if (strstart(opts
, "on", &nextopt
)) {
1096 dpy
.window_close
= true;
1097 } else if (strstart(opts
, "off", &nextopt
)) {
1098 dpy
.window_close
= false;
1100 goto invalid_sdl_args
;
1102 } else if (strstart(opts
, ",show-cursor=", &nextopt
)) {
1104 dpy
.has_show_cursor
= true;
1105 if (strstart(opts
, "on", &nextopt
)) {
1106 dpy
.show_cursor
= true;
1107 } else if (strstart(opts
, "off", &nextopt
)) {
1108 dpy
.show_cursor
= false;
1110 goto invalid_sdl_args
;
1112 } else if (strstart(opts
, ",gl=", &nextopt
)) {
1115 if (strstart(opts
, "on", &nextopt
)) {
1116 dpy
.gl
= DISPLAYGL_MODE_ON
;
1117 } else if (strstart(opts
, "core", &nextopt
)) {
1118 dpy
.gl
= DISPLAYGL_MODE_CORE
;
1119 } else if (strstart(opts
, "es", &nextopt
)) {
1120 dpy
.gl
= DISPLAYGL_MODE_ES
;
1121 } else if (strstart(opts
, "off", &nextopt
)) {
1122 dpy
.gl
= DISPLAYGL_MODE_OFF
;
1124 goto invalid_sdl_args
;
1128 error_report("invalid SDL option string");
1133 } else if (strstart(p
, "vnc", &opts
)) {
1135 * vnc isn't a (local) DisplayType but a protocol for remote
1139 vnc_parse(opts
+ 1);
1141 error_report("VNC requires a display argument vnc=<display>");
1145 parse_display_qapi(p
);
1149 static inline bool nonempty_str(const char *str
)
1154 static int parse_fw_cfg(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1158 const char *name
, *file
, *str
, *gen_id
;
1159 FWCfgState
*fw_cfg
= (FWCfgState
*) opaque
;
1161 if (fw_cfg
== NULL
) {
1162 error_setg(errp
, "fw_cfg device not available");
1165 name
= qemu_opt_get(opts
, "name");
1166 file
= qemu_opt_get(opts
, "file");
1167 str
= qemu_opt_get(opts
, "string");
1168 gen_id
= qemu_opt_get(opts
, "gen_id");
1170 /* we need the name, and exactly one of: file, content string, gen_id */
1171 if (!nonempty_str(name
) ||
1172 nonempty_str(file
) + nonempty_str(str
) + nonempty_str(gen_id
) != 1) {
1173 error_setg(errp
, "name, plus exactly one of file,"
1174 " string and gen_id, are needed");
1177 if (strlen(name
) > FW_CFG_MAX_FILE_PATH
- 1) {
1178 error_setg(errp
, "name too long (max. %d char)",
1179 FW_CFG_MAX_FILE_PATH
- 1);
1182 if (nonempty_str(gen_id
)) {
1184 * In this particular case where the content is populated
1185 * internally, the "etc/" namespace protection is relaxed,
1186 * so do not emit a warning.
1188 } else if (strncmp(name
, "opt/", 4) != 0) {
1189 warn_report("externally provided fw_cfg item names "
1190 "should be prefixed with \"opt/\"");
1192 if (nonempty_str(str
)) {
1193 size
= strlen(str
); /* NUL terminator NOT included in fw_cfg blob */
1194 buf
= g_memdup(str
, size
);
1195 } else if (nonempty_str(gen_id
)) {
1196 if (!fw_cfg_add_from_generator(fw_cfg
, name
, gen_id
, errp
)) {
1202 if (!g_file_get_contents(file
, &buf
, &size
, &err
)) {
1203 error_setg(errp
, "can't load %s: %s", file
, err
->message
);
1208 /* For legacy, keep user files in a specific global order. */
1209 fw_cfg_set_order_override(fw_cfg
, FW_CFG_ORDER_OVERRIDE_USER
);
1210 fw_cfg_add_file(fw_cfg
, name
, buf
, size
);
1211 fw_cfg_reset_order_override(fw_cfg
);
1215 static int device_help_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1217 return qdev_device_help(opts
);
1220 static int device_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1224 dev
= qdev_device_add(opts
, errp
);
1225 if (!dev
&& *errp
) {
1226 error_report_err(*errp
);
1229 object_unref(OBJECT(dev
));
1234 static int chardev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1236 Error
*local_err
= NULL
;
1238 if (!qemu_chr_new_from_opts(opts
, NULL
, &local_err
)) {
1240 error_propagate(errp
, local_err
);
1248 #ifdef CONFIG_VIRTFS
1249 static int fsdev_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1251 return qemu_fsdev_add(opts
, errp
);
1255 static int mon_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
1257 return monitor_init_opts(opts
, errp
);
1260 static void monitor_parse(const char *optarg
, const char *mode
, bool pretty
)
1262 static int monitor_device_index
= 0;
1267 if (strstart(optarg
, "chardev:", &p
)) {
1268 snprintf(label
, sizeof(label
), "%s", p
);
1270 snprintf(label
, sizeof(label
), "compat_monitor%d",
1271 monitor_device_index
);
1272 opts
= qemu_chr_parse_compat(label
, optarg
, true);
1274 error_report("parse error: %s", optarg
);
1279 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, &error_fatal
);
1280 qemu_opt_set(opts
, "mode", mode
, &error_abort
);
1281 qemu_opt_set(opts
, "chardev", label
, &error_abort
);
1282 if (!strcmp(mode
, "control")) {
1283 qemu_opt_set_bool(opts
, "pretty", pretty
, &error_abort
);
1285 assert(pretty
== false);
1287 monitor_device_index
++;
1290 struct device_config
{
1292 DEV_USB
, /* -usbdevice */
1293 DEV_SERIAL
, /* -serial */
1294 DEV_PARALLEL
, /* -parallel */
1295 DEV_DEBUGCON
, /* -debugcon */
1296 DEV_GDB
, /* -gdb, -s */
1297 DEV_SCLP
, /* s390 sclp */
1299 const char *cmdline
;
1301 QTAILQ_ENTRY(device_config
) next
;
1304 static QTAILQ_HEAD(, device_config
) device_configs
=
1305 QTAILQ_HEAD_INITIALIZER(device_configs
);
1307 static void add_device_config(int type
, const char *cmdline
)
1309 struct device_config
*conf
;
1311 conf
= g_malloc0(sizeof(*conf
));
1313 conf
->cmdline
= cmdline
;
1314 loc_save(&conf
->loc
);
1315 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1318 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1320 struct device_config
*conf
;
1323 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1324 if (conf
->type
!= type
)
1326 loc_push_restore(&conf
->loc
);
1327 rc
= func(conf
->cmdline
);
1328 loc_pop(&conf
->loc
);
1336 static void qemu_disable_default_devices(void)
1338 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1340 qemu_opts_foreach(qemu_find_opts("device"),
1341 default_driver_check
, NULL
, NULL
);
1342 qemu_opts_foreach(qemu_find_opts("global"),
1343 default_driver_check
, NULL
, NULL
);
1345 if (!vga_model
&& !default_vga
) {
1346 vga_interface_type
= VGA_DEVICE
;
1348 if (!has_defaults
|| machine_class
->no_serial
) {
1351 if (!has_defaults
|| machine_class
->no_parallel
) {
1352 default_parallel
= 0;
1354 if (!has_defaults
|| machine_class
->no_floppy
) {
1357 if (!has_defaults
|| machine_class
->no_cdrom
) {
1360 if (!has_defaults
|| machine_class
->no_sdcard
) {
1363 if (!has_defaults
) {
1364 default_monitor
= 0;
1370 static void qemu_create_default_devices(void)
1372 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1374 if (is_daemonized()) {
1375 /* According to documentation and historically, -nographic redirects
1376 * serial port, parallel port and monitor to stdio, which does not work
1377 * with -daemonize. We can redirect these to null instead, but since
1378 * -nographic is legacy, let's just error out.
1379 * We disallow -nographic only if all other ports are not redirected
1380 * explicitly, to not break existing legacy setups which uses
1381 * -nographic _and_ redirects all ports explicitly - this is valid
1382 * usage, -nographic is just a no-op in this case.
1385 && (default_parallel
|| default_serial
|| default_monitor
)) {
1386 error_report("-nographic cannot be used with -daemonize");
1392 if (default_parallel
)
1393 add_device_config(DEV_PARALLEL
, "null");
1394 if (default_serial
&& default_monitor
) {
1395 add_device_config(DEV_SERIAL
, "mon:stdio");
1398 add_device_config(DEV_SERIAL
, "stdio");
1399 if (default_monitor
)
1400 monitor_parse("stdio", "readline", false);
1404 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
1405 if (default_parallel
)
1406 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
1407 if (default_monitor
)
1408 monitor_parse("vc:80Cx24C", "readline", false);
1412 QemuOptsList
*net
= qemu_find_opts("net");
1413 qemu_opts_parse(net
, "nic", true, &error_abort
);
1415 qemu_opts_parse(net
, "user", true, &error_abort
);
1419 #if defined(CONFIG_VNC)
1420 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head
))) {
1424 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
&& !display_remote
) {
1425 if (!qemu_display_find_default(&dpy
)) {
1426 dpy
.type
= DISPLAY_TYPE_NONE
;
1427 #if defined(CONFIG_VNC)
1428 vnc_parse("localhost:0,to=99,id=default");
1432 if (dpy
.type
== DISPLAY_TYPE_DEFAULT
) {
1433 dpy
.type
= DISPLAY_TYPE_NONE
;
1436 /* If no default VGA is requested, the default is "none". */
1438 vga_model
= get_default_vga_model(machine_class
);
1441 select_vgahw(machine_class
, vga_model
);
1445 static int serial_parse(const char *devname
)
1447 int index
= num_serial_hds
;
1450 if (strcmp(devname
, "none") == 0)
1452 snprintf(label
, sizeof(label
), "serial%d", index
);
1453 serial_hds
= g_renew(Chardev
*, serial_hds
, index
+ 1);
1455 serial_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1456 if (!serial_hds
[index
]) {
1457 error_report("could not connect serial device"
1458 " to character backend '%s'", devname
);
1465 Chardev
*serial_hd(int i
)
1468 if (i
< num_serial_hds
) {
1469 return serial_hds
[i
];
1474 static int parallel_parse(const char *devname
)
1476 static int index
= 0;
1479 if (strcmp(devname
, "none") == 0)
1481 if (index
== MAX_PARALLEL_PORTS
) {
1482 error_report("too many parallel ports");
1485 snprintf(label
, sizeof(label
), "parallel%d", index
);
1486 parallel_hds
[index
] = qemu_chr_new_mux_mon(label
, devname
, NULL
);
1487 if (!parallel_hds
[index
]) {
1488 error_report("could not connect parallel device"
1489 " to character backend '%s'", devname
);
1496 static int debugcon_parse(const char *devname
)
1500 if (!qemu_chr_new_mux_mon("debugcon", devname
, NULL
)) {
1501 error_report("invalid character backend '%s'", devname
);
1504 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
1506 error_report("already have a debugcon device");
1509 qemu_opt_set(opts
, "driver", "isa-debugcon", &error_abort
);
1510 qemu_opt_set(opts
, "chardev", "debugcon", &error_abort
);
1514 static gint
machine_class_cmp(gconstpointer a
, gconstpointer b
)
1516 const MachineClass
*mc1
= a
, *mc2
= b
;
1519 if (mc1
->family
== NULL
) {
1520 if (mc2
->family
== NULL
) {
1521 /* Compare standalone machine types against each other; they sort
1522 * in increasing order.
1524 return strcmp(object_class_get_name(OBJECT_CLASS(mc1
)),
1525 object_class_get_name(OBJECT_CLASS(mc2
)));
1528 /* Standalone machine types sort after families. */
1532 if (mc2
->family
== NULL
) {
1533 /* Families sort before standalone machine types. */
1537 /* Families sort between each other alphabetically increasingly. */
1538 res
= strcmp(mc1
->family
, mc2
->family
);
1543 /* Within the same family, machine types sort in decreasing order. */
1544 return strcmp(object_class_get_name(OBJECT_CLASS(mc2
)),
1545 object_class_get_name(OBJECT_CLASS(mc1
)));
1548 static MachineClass
*machine_parse(const char *name
, GSList
*machines
)
1553 if (is_help_option(name
)) {
1554 printf("Supported machines are:\n");
1555 machines
= g_slist_sort(machines
, machine_class_cmp
);
1556 for (el
= machines
; el
; el
= el
->next
) {
1557 MachineClass
*mc
= el
->data
;
1559 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
1561 printf("%-20s %s%s%s\n", mc
->name
, mc
->desc
,
1562 mc
->is_default
? " (default)" : "",
1563 mc
->deprecation_reason
? " (deprecated)" : "");
1568 mc
= find_machine(name
, machines
);
1570 error_report("unsupported machine type");
1571 error_printf("Use -machine help to list supported machines\n");
1577 static const char *pid_file
;
1578 static Notifier qemu_unlink_pidfile_notifier
;
1580 static void qemu_unlink_pidfile(Notifier
*n
, void *data
)
1587 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1588 const char **poptarg
, int *poptind
)
1590 const QEMUOption
*popt
;
1591 int optind
= *poptind
;
1592 char *r
= argv
[optind
];
1595 loc_set_cmdline(argv
, optind
, 1);
1597 /* Treat --foo the same as -foo. */
1600 popt
= qemu_options
;
1603 error_report("invalid option");
1606 if (!strcmp(popt
->name
, r
+ 1))
1610 if (popt
->flags
& HAS_ARG
) {
1611 if (optind
>= argc
) {
1612 error_report("requires an argument");
1615 optarg
= argv
[optind
++];
1616 loc_set_cmdline(argv
, optind
- 2, 2);
1627 static MachineClass
*select_machine(void)
1629 GSList
*machines
= object_class_get_list(TYPE_MACHINE
, false);
1630 MachineClass
*machine_class
= find_default_machine(machines
);
1635 loc_push_none(&loc
);
1637 opts
= qemu_get_machine_opts();
1638 qemu_opts_loc_restore(opts
);
1640 optarg
= qemu_opt_get(opts
, "type");
1642 machine_class
= machine_parse(optarg
, machines
);
1645 if (!machine_class
) {
1646 error_report("No machine specified, and there is no default");
1647 error_printf("Use -machine help to list supported machines\n");
1652 g_slist_free(machines
);
1653 return machine_class
;
1656 static int object_parse_property_opt(Object
*obj
,
1657 const char *name
, const char *value
,
1658 const char *skip
, Error
**errp
)
1660 if (g_str_equal(name
, skip
)) {
1664 if (!object_property_parse(obj
, name
, value
, errp
)) {
1671 static int machine_set_property(void *opaque
,
1672 const char *name
, const char *value
,
1675 g_autofree
char *qom_name
= g_strdup(name
);
1678 for (p
= qom_name
; *p
; p
++) {
1684 /* Legacy options do not correspond to MachineState properties. */
1685 if (g_str_equal(qom_name
, "accel")) {
1688 if (g_str_equal(qom_name
, "igd-passthru")) {
1689 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name
, value
,
1693 if (g_str_equal(qom_name
, "kvm-shadow-mem")) {
1694 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
,
1698 if (g_str_equal(qom_name
, "kernel-irqchip")) {
1699 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name
, value
,
1701 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name
, value
,
1706 return object_parse_property_opt(opaque
, name
, value
, "type", errp
);
1709 static void object_option_foreach_add(bool (*type_opt_predicate
)(const char *))
1711 ObjectOption
*opt
, *next
;
1713 QTAILQ_FOREACH_SAFE(opt
, &object_opts
, next
, next
) {
1714 const char *type
= ObjectType_str(opt
->opts
->qom_type
);
1715 if (type_opt_predicate(type
)) {
1716 user_creatable_add_qapi(opt
->opts
, &error_fatal
);
1717 qapi_free_ObjectOptions(opt
->opts
);
1718 QTAILQ_REMOVE(&object_opts
, opt
, next
);
1724 static void object_option_parse(const char *optarg
)
1731 if (optarg
[0] == '{') {
1732 QObject
*obj
= qobject_from_json(optarg
, &error_fatal
);
1734 v
= qobject_input_visitor_new(obj
);
1737 opts
= qemu_opts_parse_noisily(qemu_find_opts("object"),
1743 type
= qemu_opt_get(opts
, "qom-type");
1745 error_setg(&error_fatal
, QERR_MISSING_PARAMETER
, "qom-type");
1747 if (user_creatable_print_help(type
, opts
)) {
1751 v
= opts_visitor_new(opts
);
1754 opt
= g_new0(ObjectOption
, 1);
1755 visit_type_ObjectOptions(v
, NULL
, &opt
->opts
, &error_fatal
);
1758 QTAILQ_INSERT_TAIL(&object_opts
, opt
, next
);
1762 * Initial object creation happens before all other
1763 * QEMU data types are created. The majority of objects
1764 * can be created at this point. The rng-egd object
1765 * cannot be created here, as it depends on the chardev
1768 static bool object_create_early(const char *type
)
1771 * Objects should not be made "delayed" without a reason. If you
1772 * add one, state the reason in a comment!
1775 /* Reason: property "chardev" */
1776 if (g_str_equal(type
, "rng-egd") ||
1777 g_str_equal(type
, "qtest")) {
1781 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1782 /* Reason: cryptodev-vhost-user property "chardev" */
1783 if (g_str_equal(type
, "cryptodev-vhost-user")) {
1788 /* Reason: vhost-user-blk-server property "node-name" */
1789 if (g_str_equal(type
, "vhost-user-blk-server")) {
1793 * Reason: filter-* property "netdev" etc.
1795 if (g_str_equal(type
, "filter-buffer") ||
1796 g_str_equal(type
, "filter-dump") ||
1797 g_str_equal(type
, "filter-mirror") ||
1798 g_str_equal(type
, "filter-redirector") ||
1799 g_str_equal(type
, "colo-compare") ||
1800 g_str_equal(type
, "filter-rewriter") ||
1801 g_str_equal(type
, "filter-replay")) {
1806 * Allocation of large amounts of memory may delay
1807 * chardev initialization for too long, and trigger timeouts
1808 * on software that waits for a monitor socket to be created
1811 if (g_str_has_prefix(type
, "memory-backend-")) {
1818 static void qemu_apply_machine_options(void)
1820 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1821 QemuOpts
*machine_opts
= qemu_get_machine_opts();
1822 const char *boot_order
= NULL
;
1823 const char *boot_once
= NULL
;
1826 qemu_opt_foreach(machine_opts
, machine_set_property
, current_machine
,
1828 current_machine
->ram_size
= ram_size
;
1829 current_machine
->maxram_size
= maxram_size
;
1830 current_machine
->ram_slots
= ram_slots
;
1832 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
1834 boot_order
= qemu_opt_get(opts
, "order");
1836 validate_bootdevices(boot_order
, &error_fatal
);
1839 boot_once
= qemu_opt_get(opts
, "once");
1841 validate_bootdevices(boot_once
, &error_fatal
);
1844 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
1845 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
1849 boot_order
= machine_class
->default_boot_order
;
1852 current_machine
->boot_order
= boot_order
;
1853 current_machine
->boot_once
= boot_once
;
1855 if (semihosting_enabled() && !semihosting_get_argc()) {
1856 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
1857 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append") ?: "";
1858 /* fall back to the -kernel/-append */
1859 semihosting_arg_fallback(kernel_filename
, kernel_cmdline
);
1863 static void qemu_create_early_backends(void)
1865 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
1867 if ((alt_grab
|| ctrl_grab
) && dpy
.type
!= DISPLAY_TYPE_SDL
) {
1868 error_report("-alt-grab and -ctrl-grab are only valid "
1869 "for SDL, ignoring option");
1871 if (dpy
.has_window_close
&&
1872 (dpy
.type
!= DISPLAY_TYPE_GTK
&& dpy
.type
!= DISPLAY_TYPE_SDL
)) {
1873 error_report("-no-quit is only valid for GTK and SDL, "
1877 qemu_display_early_init(&dpy
);
1878 qemu_console_early_init();
1880 if (dpy
.has_gl
&& dpy
.gl
!= DISPLAYGL_MODE_OFF
&& display_opengl
== 0) {
1881 #if defined(CONFIG_OPENGL)
1882 error_report("OpenGL is not supported by the display");
1884 error_report("OpenGL support is disabled");
1889 object_option_foreach_add(object_create_early
);
1891 /* spice needs the timers to be initialized by this point */
1892 /* spice must initialize before audio as it changes the default auiodev */
1893 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1896 qemu_opts_foreach(qemu_find_opts("chardev"),
1897 chardev_init_func
, NULL
, &error_fatal
);
1899 #ifdef CONFIG_VIRTFS
1900 qemu_opts_foreach(qemu_find_opts("fsdev"),
1901 fsdev_init_func
, NULL
, &error_fatal
);
1905 * Note: we need to create audio and block backends before
1906 * machine_set_property(), so machine properties can refer to
1909 configure_blockdev(&bdo_queue
, machine_class
, snapshot
);
1910 audio_init_audiodevs();
1915 * The remainder of object creation happens after the
1916 * creation of chardev, fsdev, net clients and device data types.
1918 static bool object_create_late(const char *type
)
1920 return !object_create_early(type
);
1923 static void qemu_create_late_backends(void)
1926 qtest_server_init(qtest_chrdev
, qtest_log
, &error_fatal
);
1929 net_init_clients(&error_fatal
);
1931 object_option_foreach_add(object_create_late
);
1933 if (tpm_init() < 0) {
1937 qemu_opts_foreach(qemu_find_opts("mon"),
1938 mon_init_func
, NULL
, &error_fatal
);
1940 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
1942 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
1944 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
1947 /* now chardevs have been created we may have semihosting to connect */
1948 qemu_semihosting_connect_chardevs();
1949 qemu_semihosting_console_init();
1952 static bool have_custom_ram_size(void)
1954 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
1955 return !!qemu_opt_get_size(opts
, "size", 0);
1958 static void qemu_resolve_machine_memdev(void)
1960 if (current_machine
->ram_memdev_id
) {
1962 ram_addr_t backend_size
;
1964 backend
= object_resolve_path_type(current_machine
->ram_memdev_id
,
1965 TYPE_MEMORY_BACKEND
, NULL
);
1967 error_report("Memory backend '%s' not found",
1968 current_machine
->ram_memdev_id
);
1971 backend_size
= object_property_get_uint(backend
, "size", &error_abort
);
1972 if (have_custom_ram_size() && backend_size
!= ram_size
) {
1973 error_report("Size specified by -m option must match size of "
1974 "explicitly specified 'memory-backend' property");
1978 error_report("'-mem-path' can't be used together with"
1979 "'-machine memory-backend'");
1982 ram_size
= backend_size
;
1985 if (!xen_enabled()) {
1986 /* On 32-bit hosts, QEMU is limited by virtual address space */
1987 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
1988 error_report("at most 2047 MB RAM can be simulated");
1994 static void set_memory_options(MachineClass
*mc
)
1997 const char *mem_str
;
1998 const ram_addr_t default_ram_size
= mc
->default_ram_size
;
1999 QemuOpts
*opts
= qemu_find_opts_singleton("memory");
2002 loc_push_none(&loc
);
2003 qemu_opts_loc_restore(opts
);
2006 mem_str
= qemu_opt_get(opts
, "size");
2009 error_report("missing 'size' option value");
2013 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
2015 /* Fix up legacy suffix-less format */
2016 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
2017 uint64_t overflow_check
= sz
;
2020 if (sz
/ MiB
!= overflow_check
) {
2021 error_report("too large 'size' option value");
2027 /* backward compatibility behaviour for case "-m 0" */
2029 sz
= default_ram_size
;
2032 sz
= QEMU_ALIGN_UP(sz
, 8192);
2033 if (mc
->fixup_ram_size
) {
2034 sz
= mc
->fixup_ram_size(sz
);
2037 if (ram_size
!= sz
) {
2038 error_report("ram size too large");
2042 maxram_size
= ram_size
;
2044 if (qemu_opt_get(opts
, "maxmem")) {
2047 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
2048 slots
= qemu_opt_get_number(opts
, "slots", 0);
2049 if (sz
< ram_size
) {
2050 error_report("invalid value of -m option maxmem: "
2051 "maximum memory size (0x%" PRIx64
") must be at least "
2052 "the initial memory size (0x" RAM_ADDR_FMT
")",
2055 } else if (slots
&& sz
== ram_size
) {
2056 error_report("invalid value of -m option maxmem: "
2057 "memory slots were specified but maximum memory size "
2058 "(0x%" PRIx64
") is equal to the initial memory size "
2059 "(0x" RAM_ADDR_FMT
")", sz
, ram_size
);
2065 } else if (qemu_opt_get(opts
, "slots")) {
2066 error_report("invalid -m option value: missing 'maxmem' option");
2073 static void qemu_create_machine(MachineClass
*machine_class
)
2075 object_set_machine_compat_props(machine_class
->compat_props
);
2077 set_memory_options(machine_class
);
2079 current_machine
= MACHINE(object_new_with_class(OBJECT_CLASS(machine_class
)));
2080 if (machine_help_func(qemu_get_machine_opts(), current_machine
)) {
2083 object_property_add_child(object_get_root(), "machine",
2084 OBJECT(current_machine
));
2085 object_property_add_child(container_get(OBJECT(current_machine
),
2087 "sysbus", OBJECT(sysbus_get_default()));
2089 if (machine_class
->minimum_page_bits
) {
2090 if (!set_preferred_target_page_bits(machine_class
->minimum_page_bits
)) {
2091 /* This would be a board error: specifying a minimum smaller than
2092 * a target's compile-time fixed setting.
2094 g_assert_not_reached();
2098 cpu_exec_init_all();
2101 if (machine_class
->hw_version
) {
2102 qemu_set_hw_version(machine_class
->hw_version
);
2105 machine_smp_parse(current_machine
,
2106 qemu_opts_find(qemu_find_opts("smp-opts"), NULL
), &error_fatal
);
2109 * Get the default machine options from the machine if it is not already
2110 * specified either by the configuration file or by the command line.
2112 if (machine_class
->default_machine_opts
) {
2113 qemu_opts_set_defaults(qemu_find_opts("machine"),
2114 machine_class
->default_machine_opts
, 0);
2118 static int global_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2122 g
= g_malloc0(sizeof(*g
));
2123 g
->driver
= qemu_opt_get(opts
, "driver");
2124 g
->property
= qemu_opt_get(opts
, "property");
2125 g
->value
= qemu_opt_get(opts
, "value");
2126 qdev_prop_register_global(g
);
2130 static void qemu_read_default_config_file(Error
**errp
)
2134 g_autofree
char *file
= get_relocated_path(CONFIG_QEMU_CONFDIR
"/qemu.conf");
2136 ret
= qemu_read_config_file(file
, errp
);
2138 if (ret
== -ENOENT
) {
2145 static int qemu_set_option(const char *str
)
2147 Error
*local_err
= NULL
;
2148 char group
[64], id
[64], arg
[64];
2153 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
2154 if (rc
< 3 || str
[offset
] != '=') {
2155 error_report("can't parse: \"%s\"", str
);
2159 list
= qemu_find_opts(group
);
2164 opts
= qemu_opts_find(list
, id
);
2166 error_report("there is no %s \"%s\" defined",
2171 if (!qemu_opt_set(opts
, arg
, str
+ offset
+ 1, &local_err
)) {
2172 error_report_err(local_err
);
2178 static void user_register_global_props(void)
2180 qemu_opts_foreach(qemu_find_opts("global"),
2181 global_init_func
, NULL
, NULL
);
2184 static int do_configure_icount(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2186 icount_configure(opts
, errp
);
2190 static int accelerator_set_property(void *opaque
,
2191 const char *name
, const char *value
,
2194 return object_parse_property_opt(opaque
, name
, value
, "accel", errp
);
2197 static int do_configure_accelerator(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2199 bool *p_init_failed
= opaque
;
2200 const char *acc
= qemu_opt_get(opts
, "accel");
2201 AccelClass
*ac
= accel_find(acc
);
2204 bool qtest_with_kvm
;
2206 qtest_with_kvm
= g_str_equal(acc
, "kvm") && qtest_chrdev
!= NULL
;
2209 *p_init_failed
= true;
2210 if (!qtest_with_kvm
) {
2211 error_report("invalid accelerator %s", acc
);
2215 accel
= ACCEL(object_new_with_class(OBJECT_CLASS(ac
)));
2216 object_apply_compat_props(OBJECT(accel
));
2217 qemu_opt_foreach(opts
, accelerator_set_property
,
2221 ret
= accel_init_machine(accel
, current_machine
);
2223 *p_init_failed
= true;
2224 if (!qtest_with_kvm
|| ret
!= -ENOENT
) {
2225 error_report("failed to initialize %s: %s", acc
, strerror(-ret
));
2233 static void configure_accelerators(const char *progname
)
2235 const char *accelerators
;
2236 bool init_failed
= false;
2238 qemu_opts_foreach(qemu_find_opts("icount"),
2239 do_configure_icount
, NULL
, &error_fatal
);
2241 accelerators
= qemu_opt_get(qemu_get_machine_opts(), "accel");
2242 if (QTAILQ_EMPTY(&qemu_accel_opts
.head
)) {
2243 char **accel_list
, **tmp
;
2245 if (accelerators
== NULL
) {
2246 /* Select the default accelerator */
2247 bool have_tcg
= accel_find("tcg");
2248 bool have_kvm
= accel_find("kvm");
2250 if (have_tcg
&& have_kvm
) {
2251 if (g_str_has_suffix(progname
, "kvm")) {
2252 /* If the program name ends with "kvm", we prefer KVM */
2253 accelerators
= "kvm:tcg";
2255 accelerators
= "tcg:kvm";
2257 } else if (have_kvm
) {
2258 accelerators
= "kvm";
2259 } else if (have_tcg
) {
2260 accelerators
= "tcg";
2262 error_report("No accelerator selected and"
2263 " no default accelerator available");
2267 accel_list
= g_strsplit(accelerators
, ":", 0);
2269 for (tmp
= accel_list
; *tmp
; tmp
++) {
2271 * Filter invalid accelerators here, to prevent obscenities
2272 * such as "-machine accel=tcg,,thread=single".
2274 if (accel_find(*tmp
)) {
2275 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp
, true);
2278 error_report("invalid accelerator %s", *tmp
);
2281 g_strfreev(accel_list
);
2283 if (accelerators
!= NULL
) {
2284 error_report("The -accel and \"-machine accel=\" options are incompatible");
2289 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2290 do_configure_accelerator
, &init_failed
, &error_fatal
)) {
2292 error_report("no accelerator found");
2297 if (init_failed
&& !qtest_chrdev
) {
2298 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
2299 error_report("falling back to %s", ac
->name
);
2302 if (icount_enabled() && !tcg_enabled()) {
2303 error_report("-icount is not allowed with hardware virtualization");
2308 static void create_default_memdev(MachineState
*ms
, const char *path
)
2311 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
2313 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
2315 object_property_set_str(obj
, "mem-path", path
, &error_fatal
);
2317 object_property_set_int(obj
, "size", ms
->ram_size
, &error_fatal
);
2318 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
2320 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2321 object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
2322 false, &error_fatal
);
2323 user_creatable_complete(USER_CREATABLE(obj
), &error_fatal
);
2325 object_property_set_str(OBJECT(ms
), "memory-backend", mc
->default_ram_id
,
2329 static void qemu_validate_options(void)
2331 QemuOpts
*machine_opts
= qemu_get_machine_opts();
2332 const char *kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
2333 const char *initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
2334 const char *kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
2336 if (kernel_filename
== NULL
) {
2337 if (kernel_cmdline
!= NULL
) {
2338 error_report("-append only allowed with -kernel option");
2342 if (initrd_filename
!= NULL
) {
2343 error_report("-initrd only allowed with -kernel option");
2348 if (loadvm
&& preconfig_requested
) {
2349 error_report("'preconfig' and 'loadvm' options are "
2350 "mutually exclusive");
2353 if (incoming
&& preconfig_requested
&& strcmp(incoming
, "defer") != 0) {
2354 error_report("'preconfig' supports '-incoming defer' only");
2358 #ifdef CONFIG_CURSES
2359 if (is_daemonized() && dpy
.type
== DISPLAY_TYPE_CURSES
) {
2360 error_report("curses display cannot be used with -daemonize");
2366 static void qemu_process_sugar_options(void)
2371 val
= g_strdup_printf("%d",
2372 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2373 object_register_sugar_prop("memory-backend", "prealloc-threads", val
,
2376 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2380 int i
= select_watchdog(watchdog
);
2382 exit (i
== 1 ? 1 : 0);
2386 /* -action processing */
2389 * Process all the -action parameters parsed from cmdline.
2391 static int process_runstate_actions(void *opaque
, QemuOpts
*opts
, Error
**errp
)
2393 Error
*local_err
= NULL
;
2394 QDict
*qdict
= qemu_opts_to_qdict(opts
, NULL
);
2395 QObject
*ret
= NULL
;
2396 qmp_marshal_set_action(qdict
, &ret
, &local_err
);
2398 qobject_unref(qdict
);
2400 error_propagate(errp
, local_err
);
2406 static void qemu_process_early_options(void)
2408 #ifdef CONFIG_SECCOMP
2409 QemuOptsList
*olist
= qemu_find_opts_err("sandbox", NULL
);
2411 qemu_opts_foreach(olist
, parse_sandbox
, NULL
, &error_fatal
);
2415 qemu_opts_foreach(qemu_find_opts("name"),
2416 parse_name
, NULL
, &error_fatal
);
2418 if (qemu_opts_foreach(qemu_find_opts("action"),
2419 process_runstate_actions
, NULL
, &error_fatal
)) {
2424 qemu_opts_foreach(qemu_find_opts("add-fd"),
2425 parse_add_fd
, NULL
, &error_fatal
);
2427 qemu_opts_foreach(qemu_find_opts("add-fd"),
2428 cleanup_add_fd
, NULL
, &error_fatal
);
2431 /* Open the logfile at this point and set the log mask if necessary. */
2433 qemu_set_log_filename(log_file
, &error_fatal
);
2437 mask
= qemu_str_to_log_mask(log_mask
);
2439 qemu_print_log_usage(stdout
);
2447 qemu_add_default_firmwarepath();
2450 static void qemu_process_help_options(void)
2453 * Check for -cpu help and -device help before we call select_machine(),
2454 * which will return an error if the architecture has no default machine
2455 * type and the user did not specify one, so that the user doesn't need
2456 * to say '-cpu help -machine something'.
2458 if (cpu_option
&& is_help_option(cpu_option
)) {
2459 list_cpus(cpu_option
);
2463 if (qemu_opts_foreach(qemu_find_opts("device"),
2464 device_help_func
, NULL
, NULL
)) {
2468 /* -L help lists the data directories and exits. */
2469 if (list_data_dirs
) {
2470 qemu_list_data_dirs();
2475 static void qemu_maybe_daemonize(const char *pid_file
)
2480 rcu_disable_atfork();
2482 if (pid_file
&& !qemu_write_pidfile(pid_file
, &err
)) {
2483 error_reportf_err(err
, "cannot create PID file: ");
2487 qemu_unlink_pidfile_notifier
.notify
= qemu_unlink_pidfile
;
2488 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier
);
2491 static void qemu_init_displays(void)
2495 /* init local displays */
2496 ds
= init_displaystate();
2497 qemu_display_init(ds
, &dpy
);
2499 /* must be after terminal init, SDL library changes signal handlers */
2500 os_setup_signal_handling();
2502 /* init remote displays */
2504 qemu_opts_foreach(qemu_find_opts("vnc"),
2505 vnc_init_func
, NULL
, &error_fatal
);
2509 qemu_spice
.display_init();
2513 static void qemu_init_board(void)
2515 MachineClass
*machine_class
= MACHINE_GET_CLASS(current_machine
);
2517 if (machine_class
->default_ram_id
&& current_machine
->ram_size
&&
2518 numa_uses_legacy_mem() && !current_machine
->ram_memdev_id
) {
2519 create_default_memdev(current_machine
, mem_path
);
2522 /* process plugin before CPUs are created, but once -smp has been parsed */
2523 qemu_plugin_load_list(&plugin_list
, &error_fatal
);
2525 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2526 machine_run_board_init(current_machine
);
2528 drive_check_orphaned();
2532 if (hax_enabled()) {
2533 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2538 static void qemu_create_cli_devices(void)
2542 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2543 parse_fw_cfg
, fw_cfg_find(), &error_fatal
);
2545 /* init USB devices */
2546 if (machine_usb(current_machine
)) {
2547 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2551 /* init generic devices */
2552 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE
);
2553 qemu_opts_foreach(qemu_find_opts("device"),
2554 device_init_func
, NULL
, &error_fatal
);
2555 rom_reset_order_override();
2558 static void qemu_machine_creation_done(void)
2560 MachineState
*machine
= MACHINE(qdev_get_machine());
2562 /* Did we create any drives that we failed to create a device for? */
2563 drive_check_orphaned();
2565 /* Don't warn about the default network setup that you get if
2566 * no command line -net or -netdev options are specified. There
2567 * are two cases that we would otherwise complain about:
2568 * (1) board doesn't support a NIC but the implicit "-net nic"
2570 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2571 * sets up a nic that isn't connected to anything.
2573 if (!default_net
&& (!qtest_enabled() || has_defaults
)) {
2574 net_check_clients();
2577 qdev_prop_check_globals();
2579 qdev_machine_creation_done();
2583 * Verify that Confidential Guest Support has actually been initialized
2585 assert(machine
->cgs
->ready
);
2588 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
2593 void qmp_x_exit_preconfig(Error
**errp
)
2595 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
2596 error_setg(errp
, "The command is permitted only before machine initialization");
2601 qemu_create_cli_devices();
2602 qemu_machine_creation_done();
2605 Error
*local_err
= NULL
;
2606 if (!load_snapshot(loadvm
, NULL
, false, NULL
, &local_err
)) {
2607 error_report_err(local_err
);
2612 if (replay_mode
!= REPLAY_MODE_NONE
) {
2613 replay_vmstate_init();
2617 Error
*local_err
= NULL
;
2618 if (strcmp(incoming
, "defer") != 0) {
2619 qmp_migrate_incoming(incoming
, &local_err
);
2621 error_reportf_err(local_err
, "-incoming %s: ", incoming
);
2625 } else if (autostart
) {
2630 void qemu_init(int argc
, char **argv
, char **envp
)
2633 QemuOpts
*icount_opts
= NULL
, *accel_opts
= NULL
;
2634 QemuOptsList
*olist
;
2637 MachineClass
*machine_class
;
2638 bool userconfig
= true;
2639 FILE *vmstate_dump_file
= NULL
;
2641 qemu_add_opts(&qemu_drive_opts
);
2642 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
2643 qemu_add_drive_opts(&qemu_common_drive_opts
);
2644 qemu_add_drive_opts(&qemu_drive_opts
);
2645 qemu_add_drive_opts(&bdrv_runtime_opts
);
2646 qemu_add_opts(&qemu_chardev_opts
);
2647 qemu_add_opts(&qemu_device_opts
);
2648 qemu_add_opts(&qemu_netdev_opts
);
2649 qemu_add_opts(&qemu_nic_opts
);
2650 qemu_add_opts(&qemu_net_opts
);
2651 qemu_add_opts(&qemu_rtc_opts
);
2652 qemu_add_opts(&qemu_global_opts
);
2653 qemu_add_opts(&qemu_mon_opts
);
2654 qemu_add_opts(&qemu_trace_opts
);
2655 qemu_plugin_add_opts();
2656 qemu_add_opts(&qemu_option_rom_opts
);
2657 qemu_add_opts(&qemu_machine_opts
);
2658 qemu_add_opts(&qemu_accel_opts
);
2659 qemu_add_opts(&qemu_mem_opts
);
2660 qemu_add_opts(&qemu_smp_opts
);
2661 qemu_add_opts(&qemu_boot_opts
);
2662 qemu_add_opts(&qemu_add_fd_opts
);
2663 qemu_add_opts(&qemu_object_opts
);
2664 qemu_add_opts(&qemu_tpmdev_opts
);
2665 qemu_add_opts(&qemu_overcommit_opts
);
2666 qemu_add_opts(&qemu_msg_opts
);
2667 qemu_add_opts(&qemu_name_opts
);
2668 qemu_add_opts(&qemu_numa_opts
);
2669 qemu_add_opts(&qemu_icount_opts
);
2670 qemu_add_opts(&qemu_semihosting_config_opts
);
2671 qemu_add_opts(&qemu_fw_cfg_opts
);
2672 qemu_add_opts(&qemu_action_opts
);
2673 module_call_init(MODULE_INIT_OPTS
);
2675 error_init(argv
[0]);
2676 qemu_init_exec_dir(argv
[0]);
2678 qemu_init_subsystems();
2680 /* first pass of option parsing */
2682 while (optind
< argc
) {
2683 if (argv
[optind
][0] != '-') {
2687 const QEMUOption
*popt
;
2689 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2690 switch (popt
->index
) {
2691 case QEMU_OPTION_nouserconfig
:
2699 qemu_read_default_config_file(&error_fatal
);
2702 /* second pass of option parsing */
2707 if (argv
[optind
][0] != '-') {
2708 loc_set_cmdline(argv
, optind
, 1);
2709 drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2711 const QEMUOption
*popt
;
2713 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2714 if (!(popt
->arch_mask
& arch_type
)) {
2715 error_report("Option not supported for this target");
2718 switch(popt
->index
) {
2719 case QEMU_OPTION_cpu
:
2720 /* hw initialization will check this */
2721 cpu_option
= optarg
;
2723 case QEMU_OPTION_hda
:
2724 case QEMU_OPTION_hdb
:
2725 case QEMU_OPTION_hdc
:
2726 case QEMU_OPTION_hdd
:
2727 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2730 case QEMU_OPTION_blockdev
:
2733 BlockdevOptionsQueueEntry
*bdo
;
2735 v
= qobject_input_visitor_new_str(optarg
, "driver",
2738 bdo
= g_new(BlockdevOptionsQueueEntry
, 1);
2739 visit_type_BlockdevOptions(v
, NULL
, &bdo
->bdo
,
2742 loc_save(&bdo
->loc
);
2743 QSIMPLEQ_INSERT_TAIL(&bdo_queue
, bdo
, entry
);
2746 case QEMU_OPTION_drive
:
2747 if (drive_def(optarg
) == NULL
) {
2751 case QEMU_OPTION_set
:
2752 if (qemu_set_option(optarg
) != 0)
2755 case QEMU_OPTION_global
:
2756 if (qemu_global_option(optarg
) != 0)
2759 case QEMU_OPTION_mtdblock
:
2760 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2762 case QEMU_OPTION_sd
:
2763 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
2765 case QEMU_OPTION_pflash
:
2766 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2768 case QEMU_OPTION_snapshot
:
2770 Error
*blocker
= NULL
;
2772 error_setg(&blocker
, QERR_REPLAY_NOT_SUPPORTED
,
2774 replay_add_blocker(blocker
);
2777 case QEMU_OPTION_numa
:
2778 opts
= qemu_opts_parse_noisily(qemu_find_opts("numa"),
2784 case QEMU_OPTION_display
:
2785 parse_display(optarg
);
2787 case QEMU_OPTION_nographic
:
2788 olist
= qemu_find_opts("machine");
2789 qemu_opts_parse_noisily(olist
, "graphics=off", false);
2791 dpy
.type
= DISPLAY_TYPE_NONE
;
2793 case QEMU_OPTION_curses
:
2794 #ifdef CONFIG_CURSES
2795 dpy
.type
= DISPLAY_TYPE_CURSES
;
2797 error_report("curses or iconv support is disabled");
2801 case QEMU_OPTION_portrait
:
2802 graphic_rotate
= 90;
2804 case QEMU_OPTION_rotate
:
2805 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2806 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2807 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2808 error_report("only 90, 180, 270 deg rotation is available");
2812 case QEMU_OPTION_kernel
:
2813 qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg
, &error_abort
);
2815 case QEMU_OPTION_initrd
:
2816 qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg
, &error_abort
);
2818 case QEMU_OPTION_append
:
2819 qemu_opts_set(qemu_find_opts("machine"), "append", optarg
, &error_abort
);
2821 case QEMU_OPTION_dtb
:
2822 qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg
, &error_abort
);
2824 case QEMU_OPTION_cdrom
:
2825 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2827 case QEMU_OPTION_boot
:
2828 opts
= qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2834 case QEMU_OPTION_fda
:
2835 case QEMU_OPTION_fdb
:
2836 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2839 case QEMU_OPTION_no_fd_bootchk
:
2842 case QEMU_OPTION_netdev
:
2844 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2848 case QEMU_OPTION_nic
:
2850 if (net_client_parse(qemu_find_opts("nic"), optarg
) == -1) {
2854 case QEMU_OPTION_net
:
2856 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2860 #ifdef CONFIG_LIBISCSI
2861 case QEMU_OPTION_iscsi
:
2862 opts
= qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2869 case QEMU_OPTION_audio_help
:
2870 audio_legacy_help();
2873 case QEMU_OPTION_audiodev
:
2874 audio_parse_option(optarg
);
2876 case QEMU_OPTION_soundhw
:
2877 select_soundhw (optarg
);
2882 case QEMU_OPTION_version
:
2887 opts
= qemu_opts_parse_noisily(qemu_find_opts("memory"),
2894 case QEMU_OPTION_tpmdev
:
2895 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
2900 case QEMU_OPTION_mempath
:
2903 case QEMU_OPTION_mem_prealloc
:
2912 case QEMU_OPTION_DFILTER
:
2913 qemu_set_dfilter_ranges(optarg
, &error_fatal
);
2915 case QEMU_OPTION_seed
:
2916 qemu_guest_random_seed_main(optarg
, &error_fatal
);
2919 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2921 case QEMU_OPTION_gdb
:
2922 add_device_config(DEV_GDB
, optarg
);
2925 if (is_help_option(optarg
)) {
2926 list_data_dirs
= true;
2928 qemu_add_data_dir(g_strdup(optarg
));
2931 case QEMU_OPTION_bios
:
2932 qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg
, &error_abort
);
2934 case QEMU_OPTION_singlestep
:
2941 keyboard_layout
= optarg
;
2943 case QEMU_OPTION_vga
:
2952 w
= strtol(p
, (char **)&p
, 10);
2955 error_report("invalid resolution or depth");
2961 h
= strtol(p
, (char **)&p
, 10);
2966 depth
= strtol(p
, (char **)&p
, 10);
2967 if (depth
!= 1 && depth
!= 2 && depth
!= 4 &&
2968 depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2969 depth
!= 24 && depth
!= 32)
2971 } else if (*p
== '\0') {
2972 depth
= graphic_depth
;
2979 graphic_depth
= depth
;
2982 case QEMU_OPTION_echr
:
2985 term_escape_char
= strtol(optarg
, &r
, 0);
2987 printf("Bad argument to echr\n");
2990 case QEMU_OPTION_monitor
:
2991 default_monitor
= 0;
2992 if (strncmp(optarg
, "none", 4)) {
2993 monitor_parse(optarg
, "readline", false);
2996 case QEMU_OPTION_qmp
:
2997 monitor_parse(optarg
, "control", false);
2998 default_monitor
= 0;
3000 case QEMU_OPTION_qmp_pretty
:
3001 monitor_parse(optarg
, "control", true);
3002 default_monitor
= 0;
3004 case QEMU_OPTION_mon
:
3005 opts
= qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg
,
3010 default_monitor
= 0;
3012 case QEMU_OPTION_chardev
:
3013 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3019 case QEMU_OPTION_fsdev
:
3020 olist
= qemu_find_opts("fsdev");
3022 error_report("fsdev support is disabled");
3025 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3030 case QEMU_OPTION_virtfs
: {
3033 const char *writeout
, *sock_fd
, *socket
, *path
, *security_model
,
3036 olist
= qemu_find_opts("virtfs");
3038 error_report("virtfs support is disabled");
3041 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3046 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3047 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3048 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3051 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3052 qemu_opts_id(opts
) ?:
3053 qemu_opt_get(opts
, "mount_tag"),
3056 error_report("duplicate or invalid fsdev id: %s",
3057 qemu_opt_get(opts
, "mount_tag"));
3061 writeout
= qemu_opt_get(opts
, "writeout");
3063 #ifdef CONFIG_SYNC_FILE_RANGE
3064 qemu_opt_set(fsdev
, "writeout", writeout
, &error_abort
);
3066 error_report("writeout=immediate not supported "
3067 "on this platform");
3071 qemu_opt_set(fsdev
, "fsdriver",
3072 qemu_opt_get(opts
, "fsdriver"), &error_abort
);
3073 path
= qemu_opt_get(opts
, "path");
3075 qemu_opt_set(fsdev
, "path", path
, &error_abort
);
3077 security_model
= qemu_opt_get(opts
, "security_model");
3078 if (security_model
) {
3079 qemu_opt_set(fsdev
, "security_model", security_model
,
3082 socket
= qemu_opt_get(opts
, "socket");
3084 qemu_opt_set(fsdev
, "socket", socket
, &error_abort
);
3086 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3088 qemu_opt_set(fsdev
, "sock_fd", sock_fd
, &error_abort
);
3091 qemu_opt_set_bool(fsdev
, "readonly",
3092 qemu_opt_get_bool(opts
, "readonly", 0),
3094 multidevs
= qemu_opt_get(opts
, "multidevs");
3096 qemu_opt_set(fsdev
, "multidevs", multidevs
, &error_abort
);
3098 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3100 qemu_opt_set(device
, "driver", "virtio-9p-pci", &error_abort
);
3101 qemu_opt_set(device
, "fsdev",
3102 qemu_opts_id(fsdev
), &error_abort
);
3103 qemu_opt_set(device
, "mount_tag",
3104 qemu_opt_get(opts
, "mount_tag"), &error_abort
);
3107 case QEMU_OPTION_serial
:
3108 add_device_config(DEV_SERIAL
, optarg
);
3110 if (strncmp(optarg
, "mon:", 4) == 0) {
3111 default_monitor
= 0;
3114 case QEMU_OPTION_watchdog
:
3116 error_report("only one watchdog option may be given");
3121 case QEMU_OPTION_action
:
3122 olist
= qemu_find_opts("action");
3123 if (!qemu_opts_parse_noisily(olist
, optarg
, false)) {
3127 case QEMU_OPTION_watchdog_action
:
3128 if (select_watchdog_action(optarg
) == -1) {
3129 error_report("unknown -watchdog-action parameter");
3133 case QEMU_OPTION_parallel
:
3134 add_device_config(DEV_PARALLEL
, optarg
);
3135 default_parallel
= 0;
3136 if (strncmp(optarg
, "mon:", 4) == 0) {
3137 default_monitor
= 0;
3140 case QEMU_OPTION_debugcon
:
3141 add_device_config(DEV_DEBUGCON
, optarg
);
3143 case QEMU_OPTION_loadvm
:
3146 case QEMU_OPTION_full_screen
:
3147 dpy
.has_full_screen
= true;
3148 dpy
.full_screen
= true;
3150 case QEMU_OPTION_alt_grab
:
3153 case QEMU_OPTION_ctrl_grab
:
3156 case QEMU_OPTION_no_quit
:
3157 dpy
.has_window_close
= true;
3158 dpy
.window_close
= false;
3160 case QEMU_OPTION_sdl
:
3162 dpy
.type
= DISPLAY_TYPE_SDL
;
3165 error_report("SDL support is disabled");
3168 case QEMU_OPTION_pidfile
:
3171 case QEMU_OPTION_win2k_hack
:
3172 win2k_install_hack
= 1;
3174 case QEMU_OPTION_acpitable
:
3175 opts
= qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3180 acpi_table_add(opts
, &error_fatal
);
3182 case QEMU_OPTION_smbios
:
3183 opts
= qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3188 smbios_entry_add(opts
, &error_fatal
);
3190 case QEMU_OPTION_fwcfg
:
3191 opts
= qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3197 case QEMU_OPTION_preconfig
:
3198 preconfig_requested
= true;
3200 case QEMU_OPTION_enable_kvm
:
3201 olist
= qemu_find_opts("machine");
3202 qemu_opts_parse_noisily(olist
, "accel=kvm", false);
3205 case QEMU_OPTION_machine
:
3206 olist
= qemu_find_opts("machine");
3207 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3212 case QEMU_OPTION_accel
:
3213 accel_opts
= qemu_opts_parse_noisily(qemu_find_opts("accel"),
3215 optarg
= qemu_opt_get(accel_opts
, "accel");
3216 if (!optarg
|| is_help_option(optarg
)) {
3217 printf("Accelerators supported in QEMU binary:\n");
3218 GSList
*el
, *accel_list
= object_class_get_list(TYPE_ACCEL
,
3220 for (el
= accel_list
; el
; el
= el
->next
) {
3221 gchar
*typename
= g_strdup(object_class_get_name(
3222 OBJECT_CLASS(el
->data
)));
3223 /* omit qtest which is used for tests only */
3224 if (g_strcmp0(typename
, ACCEL_CLASS_NAME("qtest")) &&
3225 g_str_has_suffix(typename
, ACCEL_CLASS_SUFFIX
)) {
3226 gchar
**optname
= g_strsplit(typename
,
3227 ACCEL_CLASS_SUFFIX
, 0);
3228 printf("%s\n", optname
[0]);
3229 g_strfreev(optname
);
3233 g_slist_free(accel_list
);
3237 case QEMU_OPTION_usb
:
3238 olist
= qemu_find_opts("machine");
3239 qemu_opts_parse_noisily(olist
, "usb=on", false);
3241 case QEMU_OPTION_usbdevice
:
3242 olist
= qemu_find_opts("machine");
3243 qemu_opts_parse_noisily(olist
, "usb=on", false);
3244 add_device_config(DEV_USB
, optarg
);
3246 case QEMU_OPTION_device
:
3247 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3252 case QEMU_OPTION_smp
:
3253 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3258 case QEMU_OPTION_vnc
:
3261 case QEMU_OPTION_no_acpi
:
3262 olist
= qemu_find_opts("machine");
3263 qemu_opts_parse_noisily(olist
, "acpi=off", false);
3265 case QEMU_OPTION_no_hpet
:
3266 olist
= qemu_find_opts("machine");
3267 qemu_opts_parse_noisily(olist
, "hpet=off", false);
3269 case QEMU_OPTION_no_reboot
:
3270 olist
= qemu_find_opts("action");
3271 qemu_opts_parse_noisily(olist
, "reboot=shutdown", false);
3273 case QEMU_OPTION_no_shutdown
:
3274 olist
= qemu_find_opts("action");
3275 qemu_opts_parse_noisily(olist
, "shutdown=pause", false);
3277 case QEMU_OPTION_uuid
:
3278 if (qemu_uuid_parse(optarg
, &qemu_uuid
) < 0) {
3279 error_report("failed to parse UUID string: wrong format");
3282 qemu_uuid_set
= true;
3284 case QEMU_OPTION_option_rom
:
3285 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3286 error_report("too many option ROMs");
3289 opts
= qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3294 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3295 option_rom
[nb_option_roms
].bootindex
=
3296 qemu_opt_get_number(opts
, "bootindex", -1);
3297 if (!option_rom
[nb_option_roms
].name
) {
3298 error_report("Option ROM file is not specified");
3303 case QEMU_OPTION_semihosting
:
3304 qemu_semihosting_enable();
3306 case QEMU_OPTION_semihosting_config
:
3307 if (qemu_semihosting_config_options(optarg
) != 0) {
3311 case QEMU_OPTION_name
:
3312 opts
= qemu_opts_parse_noisily(qemu_find_opts("name"),
3317 /* Capture guest name if -msg guest-name is used later */
3318 error_guest_name
= qemu_opt_get(opts
, "guest");
3320 case QEMU_OPTION_prom_env
:
3321 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3322 error_report("too many prom variables");
3325 prom_envs
[nb_prom_envs
] = optarg
;
3328 case QEMU_OPTION_old_param
:
3331 case QEMU_OPTION_rtc
:
3332 opts
= qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg
,
3338 case QEMU_OPTION_icount
:
3339 icount_opts
= qemu_opts_parse_noisily(qemu_find_opts("icount"),
3345 case QEMU_OPTION_incoming
:
3347 runstate_set(RUN_STATE_INMIGRATE
);
3351 case QEMU_OPTION_only_migratable
:
3352 only_migratable
= 1;
3354 case QEMU_OPTION_nodefaults
:
3357 case QEMU_OPTION_xen_domid
:
3358 if (!(xen_available())) {
3359 error_report("Option not supported for this target");
3362 xen_domid
= atoi(optarg
);
3364 case QEMU_OPTION_xen_attach
:
3365 if (!(xen_available())) {
3366 error_report("Option not supported for this target");
3369 xen_mode
= XEN_ATTACH
;
3371 case QEMU_OPTION_xen_domid_restrict
:
3372 if (!(xen_available())) {
3373 error_report("Option not supported for this target");
3376 xen_domid_restrict
= true;
3378 case QEMU_OPTION_trace
:
3379 trace_opt_parse(optarg
);
3381 case QEMU_OPTION_plugin
:
3382 qemu_plugin_opt_parse(optarg
, &plugin_list
);
3384 case QEMU_OPTION_readconfig
:
3385 qemu_read_config_file(optarg
, &error_fatal
);
3387 case QEMU_OPTION_spice
:
3388 olist
= qemu_find_opts_err("spice", NULL
);
3390 ui_module_load_one("spice-core");
3391 olist
= qemu_find_opts("spice");
3394 error_report("spice support is disabled");
3397 opts
= qemu_opts_parse_noisily(olist
, optarg
, false);
3403 case QEMU_OPTION_writeconfig
:
3406 warn_report("-writeconfig is deprecated and will go away without a replacement");
3407 if (strcmp(optarg
, "-") == 0) {
3410 fp
= fopen(optarg
, "w");
3412 error_report("open %s: %s", optarg
,
3417 qemu_config_write(fp
);
3423 case QEMU_OPTION_qtest
:
3424 qtest_chrdev
= optarg
;
3426 case QEMU_OPTION_qtest_log
:
3429 case QEMU_OPTION_sandbox
:
3430 olist
= qemu_find_opts("sandbox");
3432 #ifndef CONFIG_SECCOMP
3433 error_report("-sandbox support is not enabled "
3434 "in this QEMU binary");
3439 opts
= qemu_opts_parse_noisily(olist
, optarg
, true);
3444 case QEMU_OPTION_add_fd
:
3446 opts
= qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3452 error_report("File descriptor passing is disabled on this "
3457 case QEMU_OPTION_object
:
3458 object_option_parse(optarg
);
3460 case QEMU_OPTION_overcommit
:
3461 opts
= qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3466 enable_mlock
= qemu_opt_get_bool(opts
, "mem-lock", false);
3467 enable_cpu_pm
= qemu_opt_get_bool(opts
, "cpu-pm", false);
3469 case QEMU_OPTION_compat
:
3474 v
= qobject_input_visitor_new_str(optarg
, NULL
,
3477 visit_type_CompatPolicy(v
, NULL
, &opts
, &error_fatal
);
3478 QAPI_CLONE_MEMBERS(CompatPolicy
, &compat_policy
, opts
);
3480 qapi_free_CompatPolicy(opts
);
3484 case QEMU_OPTION_msg
:
3485 opts
= qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg
,
3490 configure_msg(opts
);
3492 case QEMU_OPTION_dump_vmstate
:
3493 if (vmstate_dump_file
) {
3494 error_report("only one '-dump-vmstate' "
3495 "option may be given");
3498 vmstate_dump_file
= fopen(optarg
, "w");
3499 if (vmstate_dump_file
== NULL
) {
3500 error_report("open %s: %s", optarg
, strerror(errno
));
3504 case QEMU_OPTION_enable_sync_profile
:
3507 case QEMU_OPTION_nouserconfig
:
3508 /* Nothing to be parsed here. Especially, do not error out below. */
3511 if (os_parse_cmd_args(popt
->index
, optarg
)) {
3512 error_report("Option not supported in this build");
3519 * Clear error location left behind by the loop.
3520 * Best done right after the loop. Do not insert code here!
3524 qemu_validate_options();
3525 qemu_process_sugar_options();
3528 * These options affect everything else and should be processed
3529 * before daemonizing.
3531 qemu_process_early_options();
3533 qemu_process_help_options();
3534 qemu_maybe_daemonize(pid_file
);
3537 * The trace backend must be initialized after daemonizing.
3538 * trace_init_backends() will call st_init(), which will create the
3539 * trace thread in the parent, and also register st_flush_trace_buffer()
3540 * in atexit(). This function will force the parent to wait for the
3541 * writeout thread to finish, which will not occur, and the parent
3542 * process will be left in the host.
3544 if (!trace_init_backends()) {
3549 qemu_init_main_loop(&error_fatal
);
3552 user_register_global_props();
3553 replay_configure(icount_opts
);
3555 configure_rtc(qemu_find_opts_singleton("rtc"));
3557 qemu_create_machine(select_machine());
3561 qemu_disable_default_devices();
3562 qemu_create_default_devices();
3563 qemu_create_early_backends();
3565 qemu_apply_machine_options();
3566 phase_advance(PHASE_MACHINE_CREATED
);
3569 * Note: uses machine properties such as kernel-irqchip, must run
3570 * after machine_set_property().
3572 configure_accelerators(argv
[0]);
3573 phase_advance(PHASE_ACCEL_CREATED
);
3576 * Beware, QOM objects created before this point miss global and
3577 * compat properties.
3579 * Global properties get set up by qdev_prop_register_global(),
3580 * called from user_register_global_props(), and certain option
3581 * desugaring. Also in CPU feature desugaring (buried in
3582 * parse_cpu_option()), which happens below this point, but may
3583 * only target the CPU type, which can only be created after
3584 * parse_cpu_option() returned the type.
3586 * Machine compat properties: object_set_machine_compat_props().
3587 * Accelerator compat props: object_set_accelerator_compat_props(),
3588 * called from do_configure_accelerator().
3591 machine_class
= MACHINE_GET_CLASS(current_machine
);
3592 if (!qtest_enabled() && machine_class
->deprecation_reason
) {
3593 error_report("Machine type '%s' is deprecated: %s",
3594 machine_class
->name
, machine_class
->deprecation_reason
);
3598 * Note: creates a QOM object, must run only after global and
3599 * compat properties have been set up.
3601 migration_object_init();
3603 qemu_create_late_backends();
3605 /* parse features once if machine provides default cpu_type */
3606 current_machine
->cpu_type
= machine_class
->default_cpu_type
;
3608 current_machine
->cpu_type
= parse_cpu_option(cpu_option
);
3610 /* NB: for machine none cpu_type could STILL be NULL here! */
3612 qemu_resolve_machine_memdev();
3613 parse_numa_opts(current_machine
);
3615 if (vmstate_dump_file
) {
3617 dump_vmstate_json_to_file(vmstate_dump_file
);
3621 if (!preconfig_requested
) {
3622 qmp_x_exit_preconfig(&error_fatal
);
3624 qemu_init_displays();
3625 accel_setup_post(current_machine
);