-
Notifications
You must be signed in to change notification settings - Fork 2
/
qemu.h
112 lines (100 loc) · 3.38 KB
/
qemu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _libs_hardware_qemu_h
#define _libs_hardware_qemu_h
#ifdef __cplusplus
extern "C" {
#endif
#ifdef QEMU_HARDWARE
/* returns 1 iff we're running in the emulator */
extern int qemu_check(void);
/* a structure used to hold enough state to connect to a given
* QEMU communication channel, either through a qemud socket or
* a serial port.
*
* initialize the structure by zero-ing it out
*/
typedef struct {
char is_inited;
char is_available;
char is_qemud;
char is_qemud_old;
char is_tty;
int fd;
char device[32];
} QemuChannel;
/* try to open a qemu communication channel.
* returns a file descriptor on success, or -1 in case of
* error.
*
* 'channel' must be a QemuChannel structure that is empty
* on the first call. You can call this function several
* time to re-open the channel using the same 'channel'
* object to speed things a bit.
*/
extern int qemu_channel_open( QemuChannel* channel,
const char* name,
int mode );
/* create a command made of a 4-hexchar prefix followed
* by the content. the prefix contains the content's length
* in hexadecimal coding.
*
* 'buffer' must be at last 6 bytes
* returns -1 in case of overflow, or the command's total length
* otherwise (i.e. content length + 4)
*/
extern int qemu_command_format( char* buffer,
int buffer_size,
const char* format,
... );
/* directly sends a command through the 'hw-control' channel.
* this will open the channel, send the formatted command, then
* close the channel automatically.
* returns 0 on success, or -1 on error.
*/
extern int qemu_control_command( const char* fmt, ... );
/* sends a question to the hw-control channel, then receive an answer in
* a user-allocated buffer. returns the length of the answer, or -1
* in case of error.
*
* 'question' *must* have been formatted through qemu_command_format
*/
extern int qemu_control_query( const char* question, int questionlen,
char* answer, int answersize );
#endif /* QEMU_HARDWARE */
/* use QEMU_FALLBACK(call) to call a QEMU-specific callback */
/* use QEMU_FALLBACK_VOID(call) if the function returns void */
#ifdef QEMU_HARDWARE
# define QEMU_FALLBACK(x) \
do { \
if (qemu_check()) \
return qemu_ ## x ; \
} while (0)
# define QEMU_FALLBACK_VOID(x) \
do { \
if (qemu_check()) { \
qemu_ ## x ; \
return; \
} \
} while (0)
#else
# define QEMU_FALLBACK(x) ((void)0)
# define QEMU_FALLBACK_VOID(x) ((void)0)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _libs_hardware_qemu_h */