Tested-by: Jim Shu <jim.shu@sifive.com>
On Thu, May 19, 2022 at 11:36 PM Damien Hedde <damien.hedde@greensocs.com>
wrote:
> phase_until() now supports the following transitions:
> + accel-created -> machine-initialized
> + machine-initialized -> machine-ready
>
> As a consequence we can now support the use of qmp_exit_preconfig()
> from phases _accel-created_ and _machine-initialized_.
>
> This commit is a preparation to support cold plugging a device
> using qapi (which will be introduced in a following commit). For this
> we need fine grain control of the phase.
>
> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>
> v5: update due to refactor of previous commit
> ---
> softmmu/vl.c | 26 +++++++++++++++++++++-----
> 1 file changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 7f8d15b5b8..ea15e37973 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -2698,8 +2698,9 @@ static void qemu_machine_creation_done(void)
>
> void qmp_x_exit_preconfig(Error **errp)
> {
> - if (phase_check(PHASE_MACHINE_INITIALIZED)) {
> - error_setg(errp, "The command is permitted only before machine
> initialization");
> + if (phase_check(PHASE_MACHINE_READY)) {
> + error_setg(errp, "The command is permitted only before"
> + " machine is ready");
> return;
> }
> phase_until(PHASE_MACHINE_READY, errp);
> @@ -2707,9 +2708,6 @@ void qmp_x_exit_preconfig(Error **errp)
>
> static void qemu_phase_ready(Error **errp)
> {
> - qemu_init_board();
> - /* phase is now PHASE_MACHINE_INITIALIZED. */
> - qemu_create_cli_devices();
> cxl_fixed_memory_window_link_targets(errp);
> qemu_machine_creation_done();
> /* Phase is now PHASE_MACHINE_READY. */
> @@ -2749,6 +2747,24 @@ bool phase_until(MachineInitPhase phase, Error
> **errp)
>
> switch (cur_phase) {
> case PHASE_ACCEL_CREATED:
> + qemu_init_board();
> + /* Phase is now PHASE_MACHINE_INITIALIZED. */
> + /*
> + * Handle CLI devices now in order leave this case in a state
> + * where we can cold plug devices with QMP. The following call
> + * handles the CLI options:
> + * + -fw_cfg (has side effects on device cold plug)
> + * + -device
> + */
> + qemu_create_cli_devices();
> + /*
> + * At this point all CLI options are handled apart:
> + * + -S (autostart)
> + * + -incoming
> + */
> + break;
> +
> + case PHASE_MACHINE_INITIALIZED:
> qemu_phase_ready(errp);
> break;
>
> --
> 2.36.1
>
>
>