xref: /openbmc/qemu/hw/vfio/cpr.c (revision a7365e98)
1 /*
2  * Copyright (c) 2021-2024 Oracle and/or its affiliates.
3  *
4  * This work is licensed under the terms of the GNU GPL, version 2 or later.
5  * See the COPYING file in the top-level directory.
6  */
7 
8 #include "qemu/osdep.h"
9 #include "hw/vfio/vfio-common.h"
10 #include "migration/misc.h"
11 #include "qapi/error.h"
12 #include "sysemu/runstate.h"
13 
14 static int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier,
15                                     MigrationEvent *e, Error **errp)
16 {
17     if (e->type == MIG_EVENT_PRECOPY_SETUP &&
18         !runstate_check(RUN_STATE_SUSPENDED) && !vm_get_suspended()) {
19 
20         error_setg(errp,
21             "VFIO device only supports cpr-reboot for runstate suspended");
22 
23         return -1;
24     }
25     return 0;
26 }
27 
28 bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp)
29 {
30     migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier,
31                                 vfio_cpr_reboot_notifier,
32                                 MIG_MODE_CPR_REBOOT);
33     return true;
34 }
35 
36 void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer)
37 {
38     migration_remove_notifier(&bcontainer->cpr_reboot_notifier);
39 }
40