Initialize
[sdk/emulator/qemu.git] / target-i386 / helper_gpi.c
1 /*
2  * Virtio general purpose interface
3  *
4  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
5  *
6  * Contact:
7  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
8  * DongKyun Yun <dk77.yun@samsung.com>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23  *
24  * Contributors:
25  * - S-Core Co., Ltd
26  *
27  */
28
29 #define _XOPEN_SOURCE 600
30
31 #include <string.h>
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <stdio.h>
35
36 #include "qemu-common.h"
37 #include "qemu-log.h"
38 #include "helper_gpi.h"
39
40 #include "sdb.h"
41 #include "tizen/src/debug_ch.h"
42 MULTI_DEBUG_CHANNEL(qemu, gpi);
43
44 /**
45  *  Global variables
46  *
47  */
48 static struct object_ops *call_ops = NULL;
49
50 /* do_call_gpi()
51  *
52  */
53 static int sync_sdb_port(char *args_in, int args_len, char *r_buffer, int r_len)
54 {
55         char tmp[32] = {0};
56
57         snprintf(tmp, sizeof(tmp)-1, "%d", get_sdb_base_port());
58
59         if( r_len < strlen(tmp) ){
60                 ERR("short return buffer length [%d < %d(%s)] \n", r_len, strlen(tmp), tmp);
61                 return 0;
62         }
63
64         memcpy(r_buffer, tmp, strlen(tmp));
65         TRACE("sdb-port: => return [%s]\n", r_buffer);
66
67         return 1;
68 }
69
70 static int dummy_function(char *args_in, int args_len, char *r_buffer, int r_len)
71 {
72         ERR("Need the specific operation \n");
73
74         return 1;
75 }
76
77 static void do_call_init(void)
78 {
79         int i;
80
81         call_ops = qemu_mallocz(CAll_HANDLE_MAX*sizeof(object_ops_t) );
82
83         /* set dummy function */
84         for( i = 0; i < CAll_HANDLE_MAX ; i++ ) {
85                 call_ops[i].ftn = &dummy_function;
86         }
87
88         /* init function */
89         call_ops[FTN_SYNC_SDB_PORT].ftn = &sync_sdb_port;
90
91         return;
92 }
93
94
95 int call_gpi(int pid, int ftn_num, char *in_args, int args_len, char *r_buffer, int r_len)
96 {
97         static int init = 0;
98         int ret;
99
100         TRACE("ftn_num(%d) args_len(%d) r_len(%d) \n", ftn_num, args_len, r_len);
101
102         if( init == 0 ){
103                 do_call_init();
104                 init = 1;
105         }
106
107         ret = call_ops[ftn_num].ftn(in_args, args_len, r_buffer, r_len);
108         TRACE("return [%s]\n", r_buffer);
109
110         if(!ret){
111                 /* error */
112         }
113
114         return ret;
115 }