]>
Commit | Line | Data |
---|---|---|
87ecb68b PB |
1 | /* Declarations for use by hardware emulation. */ |
2 | #ifndef QEMU_HW_H | |
3 | #define QEMU_HW_H | |
4 | ||
5 | #include "qemu-common.h" | |
6 | #include "irq.h" | |
7 | ||
8 | /* VM Load/Save */ | |
9 | ||
5dafc53f AL |
10 | /* This function writes a chunk of data to a file at the given position. |
11 | * The pos argument can be ignored if the file is only being used for | |
12 | * streaming. The handler should try to write all of the data it can. | |
13 | */ | |
871d2f07 AL |
14 | typedef int (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf, |
15 | int64_t pos, int size); | |
5dafc53f AL |
16 | |
17 | /* Read a chunk of data from a file at the given position. The pos argument | |
18 | * can be ignored if the file is only be used for streaming. The number of | |
19 | * bytes actually read should be returned. | |
20 | */ | |
21 | typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, | |
22 | int64_t pos, int size); | |
23 | ||
24 | /* Close a file and return an error code */ | |
25 | typedef int (QEMUFileCloseFunc)(void *opaque); | |
26 | ||
27 | /* Called to determine if the file has exceeded it's bandwidth allocation. The | |
28 | * bandwidth capping is a soft limit, not a hard limit. | |
29 | */ | |
30 | typedef int (QEMUFileRateLimit)(void *opaque); | |
31 | ||
32 | QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, | |
33 | QEMUFileGetBufferFunc *get_buffer, | |
34 | QEMUFileCloseFunc *close, | |
35 | QEMUFileRateLimit *rate_limit); | |
87ecb68b | 36 | QEMUFile *qemu_fopen(const char *filename, const char *mode); |
c1d36665 | 37 | QEMUFile *qemu_fopen_socket(int fd); |
87ecb68b | 38 | void qemu_fflush(QEMUFile *f); |
5dafc53f | 39 | int qemu_fclose(QEMUFile *f); |
2ca83a8d BS |
40 | void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); |
41 | void qemu_put_byte(QEMUFile *f, int v); | |
b6c4f71f BS |
42 | |
43 | static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) | |
44 | { | |
45 | qemu_put_byte(f, (int)v); | |
46 | } | |
47 | ||
48 | #define qemu_put_sbyte qemu_put_byte | |
49 | ||
2ca83a8d BS |
50 | void qemu_put_be16(QEMUFile *f, unsigned int v); |
51 | void qemu_put_be32(QEMUFile *f, unsigned int v); | |
87ecb68b | 52 | void qemu_put_be64(QEMUFile *f, uint64_t v); |
2ca83a8d BS |
53 | int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size); |
54 | int qemu_get_byte(QEMUFile *f); | |
b6c4f71f BS |
55 | |
56 | static inline unsigned int qemu_get_ubyte(QEMUFile *f) | |
57 | { | |
58 | return (unsigned int)qemu_get_byte(f); | |
59 | } | |
60 | ||
61 | #define qemu_get_sbyte qemu_get_byte | |
62 | ||
2ca83a8d BS |
63 | unsigned int qemu_get_be16(QEMUFile *f); |
64 | unsigned int qemu_get_be32(QEMUFile *f); | |
87ecb68b | 65 | uint64_t qemu_get_be64(QEMUFile *f); |
5dafc53f | 66 | int qemu_file_rate_limit(QEMUFile *f); |
871d2f07 | 67 | int qemu_file_has_error(QEMUFile *f); |
5dafc53f AL |
68 | |
69 | /* Try to send any outstanding data. This function is useful when output is | |
70 | * halted due to rate limiting or EAGAIN errors occur as it can be used to | |
71 | * resume output. */ | |
72 | void qemu_file_put_notify(QEMUFile *f); | |
87ecb68b PB |
73 | |
74 | static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) | |
75 | { | |
76 | qemu_put_be64(f, *pv); | |
77 | } | |
78 | ||
79 | static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv) | |
80 | { | |
81 | qemu_put_be32(f, *pv); | |
82 | } | |
83 | ||
84 | static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv) | |
85 | { | |
86 | qemu_put_be16(f, *pv); | |
87 | } | |
88 | ||
89 | static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv) | |
90 | { | |
91 | qemu_put_byte(f, *pv); | |
92 | } | |
93 | ||
94 | static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv) | |
95 | { | |
96 | *pv = qemu_get_be64(f); | |
97 | } | |
98 | ||
99 | static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv) | |
100 | { | |
101 | *pv = qemu_get_be32(f); | |
102 | } | |
103 | ||
104 | static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv) | |
105 | { | |
106 | *pv = qemu_get_be16(f); | |
107 | } | |
108 | ||
109 | static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv) | |
110 | { | |
111 | *pv = qemu_get_byte(f); | |
112 | } | |
113 | ||
b6c4f71f BS |
114 | // Signed versions for type safety |
115 | static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, int size) | |
116 | { | |
117 | qemu_put_buffer(f, (const uint8_t *)buf, size); | |
118 | } | |
119 | ||
120 | static inline void qemu_put_sbe16(QEMUFile *f, int v) | |
121 | { | |
122 | qemu_put_be16(f, (unsigned int)v); | |
123 | } | |
124 | ||
125 | static inline void qemu_put_sbe32(QEMUFile *f, int v) | |
126 | { | |
127 | qemu_put_be32(f, (unsigned int)v); | |
128 | } | |
129 | ||
130 | static inline void qemu_put_sbe64(QEMUFile *f, int64_t v) | |
131 | { | |
132 | qemu_put_be64(f, (uint64_t)v); | |
133 | } | |
134 | ||
135 | static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, int size) | |
136 | { | |
137 | return qemu_get_buffer(f, (uint8_t *)buf, size); | |
138 | } | |
139 | ||
140 | static inline int qemu_get_sbe16(QEMUFile *f) | |
141 | { | |
142 | return (int)qemu_get_be16(f); | |
143 | } | |
144 | ||
145 | static inline int qemu_get_sbe32(QEMUFile *f) | |
146 | { | |
147 | return (int)qemu_get_be32(f); | |
148 | } | |
149 | ||
150 | static inline int64_t qemu_get_sbe64(QEMUFile *f) | |
151 | { | |
152 | return (int64_t)qemu_get_be64(f); | |
153 | } | |
154 | ||
155 | static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv) | |
156 | { | |
157 | qemu_put_8s(f, (const uint8_t *)pv); | |
158 | } | |
159 | ||
160 | static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv) | |
161 | { | |
162 | qemu_put_be16s(f, (const uint16_t *)pv); | |
163 | } | |
164 | ||
165 | static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv) | |
166 | { | |
167 | qemu_put_be32s(f, (const uint32_t *)pv); | |
168 | } | |
169 | ||
170 | static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv) | |
171 | { | |
172 | qemu_put_be64s(f, (const uint64_t *)pv); | |
173 | } | |
174 | ||
175 | static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv) | |
176 | { | |
177 | qemu_get_8s(f, (uint8_t *)pv); | |
178 | } | |
179 | ||
180 | static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv) | |
181 | { | |
182 | qemu_get_be16s(f, (uint16_t *)pv); | |
183 | } | |
184 | ||
185 | static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv) | |
186 | { | |
187 | qemu_get_be32s(f, (uint32_t *)pv); | |
188 | } | |
189 | ||
190 | static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv) | |
191 | { | |
192 | qemu_get_be64s(f, (uint64_t *)pv); | |
193 | } | |
194 | ||
87ecb68b PB |
195 | #ifdef NEED_CPU_H |
196 | #if TARGET_LONG_BITS == 64 | |
197 | #define qemu_put_betl qemu_put_be64 | |
198 | #define qemu_get_betl qemu_get_be64 | |
199 | #define qemu_put_betls qemu_put_be64s | |
200 | #define qemu_get_betls qemu_get_be64s | |
b6c4f71f BS |
201 | #define qemu_put_sbetl qemu_put_sbe64 |
202 | #define qemu_get_sbetl qemu_get_sbe64 | |
203 | #define qemu_put_sbetls qemu_put_sbe64s | |
204 | #define qemu_get_sbetls qemu_get_sbe64s | |
87ecb68b PB |
205 | #else |
206 | #define qemu_put_betl qemu_put_be32 | |
207 | #define qemu_get_betl qemu_get_be32 | |
208 | #define qemu_put_betls qemu_put_be32s | |
209 | #define qemu_get_betls qemu_get_be32s | |
b6c4f71f BS |
210 | #define qemu_put_sbetl qemu_put_sbe32 |
211 | #define qemu_get_sbetl qemu_get_sbe32 | |
212 | #define qemu_put_sbetls qemu_put_sbe32s | |
213 | #define qemu_get_sbetls qemu_get_sbe32s | |
87ecb68b PB |
214 | #endif |
215 | #endif | |
216 | ||
217 | int64_t qemu_ftell(QEMUFile *f); | |
218 | int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence); | |
219 | ||
220 | typedef void SaveStateHandler(QEMUFile *f, void *opaque); | |
9366f418 | 221 | typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque); |
87ecb68b PB |
222 | typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); |
223 | ||
224 | int register_savevm(const char *idstr, | |
225 | int instance_id, | |
226 | int version_id, | |
227 | SaveStateHandler *save_state, | |
228 | LoadStateHandler *load_state, | |
229 | void *opaque); | |
230 | ||
9366f418 AL |
231 | int register_savevm_live(const char *idstr, |
232 | int instance_id, | |
233 | int version_id, | |
234 | SaveLiveStateHandler *save_live_state, | |
235 | SaveStateHandler *save_state, | |
236 | LoadStateHandler *load_state, | |
237 | void *opaque); | |
238 | ||
87ecb68b PB |
239 | typedef void QEMUResetHandler(void *opaque); |
240 | ||
241 | void qemu_register_reset(QEMUResetHandler *func, void *opaque); | |
242 | ||
0ecdffbb AJ |
243 | /* handler to set the boot_device for a specific type of QEMUMachine */ |
244 | /* return 0 if success */ | |
3b4366de BS |
245 | typedef int QEMUBootSetHandler(void *opaque, const char *boot_device); |
246 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque); | |
0ecdffbb | 247 | |
87ecb68b PB |
248 | /* These should really be in isa.h, but are here to make pc.h happy. */ |
249 | typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data); | |
250 | typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address); | |
251 | ||
252 | #endif |