DM: register pm ops to monitor

Then, acrnctl could send command to monitor module of DM and call
functions defined in pm ops. One example is: acrnctl resume UOS
after UOS enter S3.

Also add general pm.c and move pm related function to this file.

Signed-off-by: Yan Like <like.yan@intel.com>
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Yin Fengwei 2018-07-06 13:24:45 +08:00 committed by lijinxia
parent f576f97ea8
commit a2241d983d
5 changed files with 77 additions and 0 deletions

View File

@ -104,6 +104,7 @@ SRCS += core/sw_load_vsbl.c
SRCS += core/smbiostbl.c
SRCS += core/mevent.c
SRCS += core/gc.c
SRCS += core/pm.c
SRCS += core/console.c
SRCS += core/inout.c
SRCS += core/mem.c

View File

@ -33,6 +33,7 @@
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <pthread.h>
#include "vmmapi.h"
#include "acpi.h"

View File

@ -19,6 +19,7 @@
#include "dm.h"
#include "monitor.h"
#include "acrn_mngr.h"
#include "pm.h"
/* helpers */
/* Check if @path is a directory, and create if not exist */
@ -205,6 +206,15 @@ static void handle_query(struct mngr_msg *msg, int client_fd, void *param)
mngr_send_msg(client_fd, &ack, NULL, ACK_TIMEOUT);
}
static struct monitor_vm_ops pmc_ops = {
.stop = NULL,
.resume = vm_monitor_resume,
.suspend = NULL,
.pause = NULL,
.unpause = NULL,
.query = vm_monitor_query,
};
int monitor_init(struct vmctx *ctx)
{
int ret;
@ -243,6 +253,8 @@ int monitor_init(struct vmctx *ctx)
goto handlers_err;
}
monitor_register_vm_ops(&pmc_ops, ctx, "PMC_VM_OPs");
return 0;
handlers_err:

50
devicemodel/core/pm.c Normal file
View File

@ -0,0 +1,50 @@
/*
* Copyright (C) <2018> Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <stdbool.h>
#include <pthread.h>
#include "vmmapi.h"
static pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t suspend_mutex = PTHREAD_MUTEX_INITIALIZER;
int
wait_for_resume(struct vmctx *ctx)
{
pthread_mutex_lock(&suspend_mutex);
while (vm_get_suspend_mode() == VM_SUSPEND_SUSPEND) {
pthread_cond_wait(&suspend_cond, &suspend_mutex);
}
pthread_mutex_unlock(&suspend_mutex);
return 0;
}
int
vm_resume(struct vmctx *ctx)
{
pthread_mutex_lock(&suspend_mutex);
vm_set_suspend_mode(VM_SUSPEND_NONE);
pthread_cond_signal(&suspend_cond);
pthread_mutex_unlock(&suspend_mutex);
return 0;
}
int
vm_monitor_resume(void *arg)
{
struct vmctx *ctx = (struct vmctx *)arg;
vm_resume(ctx);
return 0;
}
int
vm_monitor_query(void *arg)
{
return vm_get_suspend_mode();
}

13
devicemodel/include/pm.h Normal file
View File

@ -0,0 +1,13 @@
/*
* Copyright (C) <2018> Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _DM_INCLUDE_PM_
#define _DM_INCLUDE_PM_
int wait_for_resume(struct vmctx *ctx);
int vm_resume(struct vmctx *ctx);
int vm_monitor_resume(void *arg);
int vm_monitor_query(void *arg);
#endif