Merge branch 'qemu-cvs'
[qemu-kvm/fedora.git] / hw / hw.h
blobe228804156f96d31928e2a38f3900ceab64777f7
1 /* Declarations for use by hardware emulation. */
2 #ifndef QEMU_HW_H
3 #define QEMU_HW_H
5 #include "qemu-common.h"
6 #include "irq.h"
8 /* VM Load/Save */
10 typedef void (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf, int64_t pos, int size);
11 typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, int64_t pos, int size);
12 typedef void (QEMUFileCloseFunc)(void *opaque);
14 QEMUFile *qemu_fopen(void *opaque, QEMUFilePutBufferFunc *put_buffer,
15 QEMUFileGetBufferFunc *get_buffer, QEMUFileCloseFunc *close);
16 QEMUFile *qemu_fopen_file(const char *filename, const char *mode);
17 QEMUFile *qemu_fopen_fd(int fd);
18 void qemu_fflush(QEMUFile *f);
19 void qemu_fclose(QEMUFile *f);
20 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size);
21 void qemu_put_byte(QEMUFile *f, int8_t v);
23 static inline void qemu_put_ubyte(QEMUFile *f, uint8_t v)
25 qemu_put_byte(f, (int8_t)v);
28 #define qemu_put_sbyte qemu_put_byte
30 void qemu_put_be16(QEMUFile *f, uint16_t v);
31 void qemu_put_be32(QEMUFile *f, uint32_t v);
32 void qemu_put_be64(QEMUFile *f, uint64_t v);
33 size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size);
34 int8_t qemu_get_byte(QEMUFile *f);
36 static inline uint8_t qemu_get_ubyte(QEMUFile *f)
38 return (uint8_t)qemu_get_byte(f);
41 #define qemu_get_sbyte qemu_get_byte
43 uint16_t qemu_get_be16(QEMUFile *f);
44 uint32_t qemu_get_be32(QEMUFile *f);
45 uint64_t qemu_get_be64(QEMUFile *f);
47 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
49 qemu_put_be64(f, *pv);
52 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
54 qemu_put_be32(f, *pv);
57 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
59 qemu_put_be16(f, *pv);
62 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
64 qemu_put_byte(f, *pv);
67 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
69 *pv = qemu_get_be64(f);
72 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
74 *pv = qemu_get_be32(f);
77 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
79 *pv = qemu_get_be16(f);
82 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
84 *pv = qemu_get_byte(f);
87 // Signed versions for type safety
88 static inline void qemu_put_sbuffer(QEMUFile *f, const int8_t *buf, size_t size)
90 qemu_put_buffer(f, (const uint8_t *)buf, size);
93 static inline void qemu_put_sbe16(QEMUFile *f, int16_t v)
95 qemu_put_be16(f, (uint16_t)v);
98 static inline void qemu_put_sbe32(QEMUFile *f, int32_t v)
100 qemu_put_be32(f, (uint32_t)v);
103 static inline void qemu_put_sbe64(QEMUFile *f, int64_t v)
105 qemu_put_be64(f, (uint64_t)v);
108 static inline size_t qemu_get_sbuffer(QEMUFile *f, int8_t *buf, size_t size)
110 return qemu_get_buffer(f, (uint8_t *)buf, size);
113 static inline int16_t qemu_get_sbe16(QEMUFile *f)
115 return (int16_t)qemu_get_be16(f);
118 static inline int32_t qemu_get_sbe32(QEMUFile *f)
120 return (int32_t)qemu_get_be32(f);
123 static inline int64_t qemu_get_sbe64(QEMUFile *f)
125 return (int64_t)qemu_get_be64(f);
128 static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv)
130 qemu_put_8s(f, (const uint8_t *)pv);
133 static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv)
135 qemu_put_be16s(f, (const uint16_t *)pv);
138 static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv)
140 qemu_put_be32s(f, (const uint32_t *)pv);
143 static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv)
145 qemu_put_be64s(f, (const uint64_t *)pv);
148 static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv)
150 qemu_get_8s(f, (uint8_t *)pv);
153 static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv)
155 qemu_get_be16s(f, (uint16_t *)pv);
158 static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv)
160 qemu_get_be32s(f, (uint32_t *)pv);
163 static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
165 qemu_get_be64s(f, (uint64_t *)pv);
168 #ifdef NEED_CPU_H
169 #if TARGET_LONG_BITS == 64
170 #define qemu_put_betl qemu_put_be64
171 #define qemu_get_betl qemu_get_be64
172 #define qemu_put_betls qemu_put_be64s
173 #define qemu_get_betls qemu_get_be64s
174 #define qemu_put_sbetl qemu_put_sbe64
175 #define qemu_get_sbetl qemu_get_sbe64
176 #define qemu_put_sbetls qemu_put_sbe64s
177 #define qemu_get_sbetls qemu_get_sbe64s
178 #else
179 #define qemu_put_betl qemu_put_be32
180 #define qemu_get_betl qemu_get_be32
181 #define qemu_put_betls qemu_put_be32s
182 #define qemu_get_betls qemu_get_be32s
183 #define qemu_put_sbetl qemu_put_sbe32
184 #define qemu_get_sbetl qemu_get_sbe32
185 #define qemu_put_sbetls qemu_put_sbe32s
186 #define qemu_get_sbetls qemu_get_sbe32s
187 #endif
188 #endif
190 int64_t qemu_ftell(QEMUFile *f);
191 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
193 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
194 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
196 int register_savevm(const char *idstr,
197 int instance_id,
198 int version_id,
199 SaveStateHandler *save_state,
200 LoadStateHandler *load_state,
201 void *opaque);
203 typedef void QEMUResetHandler(void *opaque);
205 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
207 /* handler to set the boot_device for a specific type of QEMUMachine */
208 /* return 0 if success */
209 typedef int QEMUBootSetHandler(void *opaque, const char *boot_device);
210 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
212 /* These should really be in isa.h, but are here to make pc.h happy. */
213 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
214 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
216 #endif