From 61bc064d7afaa49fc15b6924e0e78be4f365c8d3 Mon Sep 17 00:00:00 2001 From: Jinhyung Choi Date: Tue, 3 Dec 2013 16:01:37 +0900 Subject: [PATCH] suspend/resume: setting suspend lock state - qemu option "ignore-suspend-lock" is created, that skips suspend lock as default. - qemu manages suspend state. - sdb server can request suspend lock and unlock state. - emulator daemon request to qumu the suspend state, and it sets default suspend state through power manager Change-Id: I4d6e4898b41fca419501ce098eb8d1e67e843cb5 Signed-off-by: Jinhyung Choi --- qemu-options.hx | 7 +++++++ tizen/src/ecs/ecs.c | 12 ++++++++++++ tizen/src/ecs/ecs.h | 8 +++++++- tizen/src/ecs/ecs_msg.c | 35 ++++++++++++++++++++++++++++++++++- tizen/src/guest_server.c | 16 +++++++++++++--- vl.c | 6 ++++++ 6 files changed, 79 insertions(+), 5 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index cf891b2cc0..8f43232042 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3125,6 +3125,13 @@ STEXI @findex -disable-skin ETEXI +DEF("ignore-suspend-lock", 0, QEMU_OPTION_ignore_suspend_lock, "", QEMU_ARCH_ALL) +STEXI +@item -ignore-suspend-lock +@findex -ignore-suspend-lock +Disable suspend lock statement in order to reach suspend power state +ETEXI + HXCOMM Internal use DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL) DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL) diff --git a/tizen/src/ecs/ecs.c b/tizen/src/ecs/ecs.c index f44b8f348b..7bbd271be8 100644 --- a/tizen/src/ecs/ecs.c +++ b/tizen/src/ecs/ecs.c @@ -75,6 +75,18 @@ static int g_client_id = 1; static pthread_mutex_t mutex_clilist = PTHREAD_MUTEX_INITIALIZER; +static int suspend_state = 1; + +void ecs_set_suspend_state(int state) +{ + suspend_state = state; +} + +int ecs_get_suspend_state(void) +{ + return suspend_state; +} + static char* get_emulator_ecs_log_path(void) { gchar *emulator_ecs_log_path = NULL; diff --git a/tizen/src/ecs/ecs.h b/tizen/src/ecs/ecs.h index 05e9c5e612..a2b366c077 100644 --- a/tizen/src/ecs/ecs.h +++ b/tizen/src/ecs/ecs.h @@ -125,7 +125,6 @@ struct Monitor { int suspend_cnt; uint8_t outbuf[OUT_BUF_SIZE]; int outbuf_index; - CPUArchState *mon_cpu; void *password_opaque; QError *error; QLIST_HEAD(,mon_fd_t) fds; @@ -218,6 +217,13 @@ bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg); /* version check */ //void send_ecs_version_check(ECS_Client* ccli); +/* Suspend/resume */ +#define SUSPEND_LOCK 1 +#define SUSPEND_UNLOCK 0 +int ecs_get_suspend_state(void); +void ecs_set_suspend_state(int state); +void ecs_suspend_lock_state(int state); + /* request */ int accel_min_max(double value); void req_set_sensor_accel(int x, int y, int z); diff --git a/tizen/src/ecs/ecs_msg.c b/tizen/src/ecs/ecs_msg.c index 5ef0f6b48e..9942eef2bd 100644 --- a/tizen/src/ecs/ecs_msg.c +++ b/tizen/src/ecs/ecs_msg.c @@ -142,6 +142,9 @@ static bool send_to_single_client(ECS__Master* master, ECS_Client *ccli) #endif static void msgproc_injector_ans(ECS_Client* ccli, const char* category, bool succeed) { + if (ccli == NULL) { + return; + } int catlen = 0; ECS__Master master = ECS__MASTER__INIT; ECS__InjectorAns ans = ECS__INJECTOR_ANS__INIT; @@ -223,6 +226,24 @@ injector_req_fail: msgproc_injector_ans(ccli, cmd, ret); return false; } + +void ecs_suspend_lock_state(int state) +{ + int catlen; + + ECS__InjectorReq msg = ECS__INJECTOR_REQ__INIT; + const char* category = "suspend"; + + catlen = strlen(category); + msg.category = (char*) g_malloc0(catlen + 1); + memcpy(msg.category, category, catlen); + + msg.group = 5; + msg.action = state; + + msgproc_injector_req(NULL, &msg); +} + #if 0 void msgproc_checkversion_req(ECS_Client* ccli, ECS__CheckVersionReq* msg) { @@ -438,6 +459,16 @@ bool ntf_to_injector(const char* data, const int len) { return true; } +static bool injector_req_handle(const char* cat) +{ + if (!strncmp(cat, "suspend", 7)) { + ecs_suspend_lock_state(ecs_get_suspend_state()); + return true; + } + + return false; +} + bool send_injector_ntf(const char* data, const int len) { type_length length = 0; @@ -453,6 +484,9 @@ bool send_injector_ntf(const char* data, const int len) read_val_char(data + catsize + 2, &group); read_val_char(data + catsize + 2 + 1, &action); + if (injector_req_handle(cat)) { + return true; + } const char* ijdata = (data + catsize + 2 + 1 + 1); @@ -464,7 +498,6 @@ bool send_injector_ntf(const char* data, const int len) ntf.category = (char*) g_malloc(catsize + 1); strncpy(ntf.category, cat, 10); - ntf.length = length; ntf.group = group; ntf.action = action; diff --git a/tizen/src/guest_server.c b/tizen/src/guest_server.c index 51a0d3f9cc..4394f88304 100644 --- a/tizen/src/guest_server.c +++ b/tizen/src/guest_server.c @@ -54,6 +54,7 @@ #include "maru_common.h" #include "hw/maru_virtio_hwkey.h" #include "hw/maru_pm.h" +#include "ecs/ecs.h" MULTI_DEBUG_CHANNEL(qemu, guest_server); @@ -92,7 +93,7 @@ static void remove_sdb_client(GS_Client* client) pthread_mutex_unlock(&mutex_clilist); } -static void send_to_client(GS_Client* client, int state) +static void send_to_sdb_client(GS_Client* client, int state) { struct sockaddr_in sock_addr; int s, slen = sizeof(sock_addr); @@ -143,7 +144,7 @@ void notify_all_sdb_clients(int state) QTAILQ_FOREACH(client, &clients, next) { - send_to_client(client, state); + send_to_sdb_client(client, state); } pthread_mutex_unlock(&mutex_clilist); @@ -191,7 +192,7 @@ static void add_sdb_client(struct sockaddr_in* addr, int port, const char* seria INFO("Added new sdb client. ip: %s, port: %d, serial: %s\n", inet_ntoa((client->addr).sin_addr), client->port, client->serial); - send_to_client(client, runstate_check(RUN_STATE_SUSPENDED)); + send_to_sdb_client(client, runstate_check(RUN_STATE_SUSPENDED)); } static int parse_val(char* buff, unsigned char data, char* parsbuf) @@ -461,6 +462,11 @@ static void wakeup_guest(void) maru_hwkey_event(RELEASE, POWER_KEY); } +static void suspend_lock_state(int state) +{ + ecs_suspend_lock_state(state); +} + static void command_handler(char* readbuf, struct sockaddr_in* client_addr) { char command[RECV_BUF_SIZE]; @@ -481,6 +487,10 @@ static void command_handler(char* readbuf, struct sockaddr_in* client_addr) register_sdb_server(readbuf, client_addr); } else if (strcmp(command, "6\n") == 0) { wakeup_guest(); + } else if (strcmp(command, "7\n") == 0) { + suspend_lock_state(SUSPEND_LOCK); + } else if (strcmp(command, "8\n") == 0) { + suspend_lock_state(SUSPEND_UNLOCK); } else { INFO("!!! unknown command : %s\n", command); } diff --git a/vl.c b/vl.c index f8f648b694..fbdde1babc 100644 --- a/vl.c +++ b/vl.c @@ -189,6 +189,7 @@ int qemu_main(int argc, char **argv, char **envp); #include "tizen/src/emul_state.h" #include "tizen/src/maru_display.h" #include "tizen/src/skin/maruskin_operation.h" +#include "tizen/src/ecs/ecs.h" #endif //#define DEBUG_NET @@ -3996,6 +3997,11 @@ int main(int argc, char **argv, char **envp) exit(1); #endif break; +#ifdef CONFIG_MARU + case QEMU_OPTION_ignore_suspend_lock: + ecs_set_suspend_state(SUSPEND_UNLOCK); + break; +#endif case QEMU_OPTION_object: opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); if (!opts) { -- 2.34.1