Skip to content

Commit

Permalink
dm: vm_event: send poweroff event on pm port write
Browse files Browse the repository at this point in the history
When the virtual PM port is written, we can infer that guest has just
initiated a poweroff action. So we send a poweroff event upon this port
write. The DM event handler will try to emit it (to Libvirt).
Developers can write app/script to decide what to do with this event.

Tracked-On: projectacrn#8547
Signed-off-by: Wu Zhou <wu.zhou@intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
  • Loading branch information
izhouwu committed Jan 19, 2024
1 parent 7c837eb commit f480f98
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions devicemodel/arch/x86/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "lpc.h"
#include "monitor.h"
#include "log.h"
#include "vm_event.h"

static pthread_mutex_t pm_lock = PTHREAD_MUTEX_INITIALIZER;
static struct mevent *power_button;
Expand Down Expand Up @@ -242,6 +243,14 @@ power_button_handler(int signal, enum ev_type type, void *arg)
inject_power_button_event(arg);
}

static void
send_poweroff_event(void)
{
struct vm_event event;
event.type = VM_EVENT_POWEROFF;
dm_send_vm_event(&event);
}

static int
pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
uint32_t *eax, void *arg)
Expand All @@ -265,6 +274,7 @@ pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
*/
if (*eax & VIRTUAL_PM1A_SLP_EN) {
if ((pm1_control & VIRTUAL_PM1A_SLP_TYP) >> 10 == 5) {
send_poweroff_event();
vm_suspend(ctx, VM_SUSPEND_POWEROFF);
}

Expand Down

0 comments on commit f480f98

Please sign in to comment.