45cc0b546142405f6177f9e3045c4caa829755d5
[qemu] / hw / hw.h
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
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  */
14 typedef void (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf,
15                                      int64_t pos, int size);
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);
36 QEMUFile *qemu_fopen(const char *filename, const char *mode);
37 QEMUFile *qemu_fopen_fd(int fd);
38 void qemu_fflush(QEMUFile *f);
39 int qemu_fclose(QEMUFile *f);
40 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
41 void qemu_put_byte(QEMUFile *f, int v);
42 void qemu_put_be16(QEMUFile *f, unsigned int v);
43 void qemu_put_be32(QEMUFile *f, unsigned int v);
44 void qemu_put_be64(QEMUFile *f, uint64_t v);
45 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
46 int qemu_get_byte(QEMUFile *f);
47 unsigned int qemu_get_be16(QEMUFile *f);
48 unsigned int qemu_get_be32(QEMUFile *f);
49 uint64_t qemu_get_be64(QEMUFile *f);
50 int qemu_file_rate_limit(QEMUFile *f);
51
52 /* Try to send any outstanding data.  This function is useful when output is
53  * halted due to rate limiting or EAGAIN errors occur as it can be used to
54  * resume output. */
55 void qemu_file_put_notify(QEMUFile *f);
56
57 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
58 {
59     qemu_put_be64(f, *pv);
60 }
61
62 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
63 {
64     qemu_put_be32(f, *pv);
65 }
66
67 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
68 {
69     qemu_put_be16(f, *pv);
70 }
71
72 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
73 {
74     qemu_put_byte(f, *pv);
75 }
76
77 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
78 {
79     *pv = qemu_get_be64(f);
80 }
81
82 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
83 {
84     *pv = qemu_get_be32(f);
85 }
86
87 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
88 {
89     *pv = qemu_get_be16(f);
90 }
91
92 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
93 {
94     *pv = qemu_get_byte(f);
95 }
96
97 #ifdef NEED_CPU_H
98 #if TARGET_LONG_BITS == 64
99 #define qemu_put_betl qemu_put_be64
100 #define qemu_get_betl qemu_get_be64
101 #define qemu_put_betls qemu_put_be64s
102 #define qemu_get_betls qemu_get_be64s
103 #else
104 #define qemu_put_betl qemu_put_be32
105 #define qemu_get_betl qemu_get_be32
106 #define qemu_put_betls qemu_put_be32s
107 #define qemu_get_betls qemu_get_be32s
108 #endif
109 #endif
110
111 int64_t qemu_ftell(QEMUFile *f);
112 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
113
114 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
115 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
116
117 int register_savevm(const char *idstr,
118                     int instance_id,
119                     int version_id,
120                     SaveStateHandler *save_state,
121                     LoadStateHandler *load_state,
122                     void *opaque);
123
124 typedef void QEMUResetHandler(void *opaque);
125
126 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
127
128 /* handler to set the boot_device for a specific type of QEMUMachine */
129 /* return 0 if success */
130 typedef int QEMUBootSetHandler(void *opaque, const char *boot_device);
131 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
132
133 /* These should really be in isa.h, but are here to make pc.h happy.  */
134 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
135 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
136
137 #endif