]> git.proxmox.com Git - qemu.git/blob - vl.h
added I/O API - io port API change - added multiple network interface support - redir...
[qemu.git] / vl.h
1 /*
2 * QEMU System Emulator header
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 #ifndef VL_H
25 #define VL_H
26
27 #include "cpu.h"
28
29 /* vl.c */
30 extern int reset_requested;
31 extern int64_t ticks_per_sec;
32 extern int pit_min_timer_count;
33
34 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
35 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
36
37 int register_ioport_read(int start, int length, int size,
38 IOPortReadFunc *func, void *opaque);
39 int register_ioport_write(int start, int length, int size,
40 IOPortWriteFunc *func, void *opaque);
41 int64_t cpu_get_ticks(void);
42 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
43
44 void hw_error(const char *fmt, ...);
45
46 int load_image(const char *filename, uint8_t *addr);
47 extern const char *bios_dir;
48
49 void pstrcpy(char *buf, int buf_size, const char *str);
50 char *pstrcat(char *buf, int buf_size, const char *s);
51
52 int serial_open_device(void);
53
54 /* network redirectors support */
55
56 #define MAX_NICS 8
57
58 typedef struct NetDriverState {
59 int fd;
60 uint8_t macaddr[6];
61 char ifname[16];
62 } NetDriverState;
63
64 extern int nb_nics;
65 extern NetDriverState nd_table[MAX_NICS];
66
67 void net_send_packet(NetDriverState *nd, const uint8_t *buf, int size);
68
69 /* async I/O support */
70
71 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
72 typedef int IOCanRWHandler(void *opaque);
73
74 int add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read,
75 IOReadHandler *fd_read, void *opaque);
76
77 /* block.c */
78 typedef struct BlockDriverState BlockDriverState;
79
80 BlockDriverState *bdrv_new(const char *device_name);
81 void bdrv_delete(BlockDriverState *bs);
82 int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
83 void bdrv_close(BlockDriverState *bs);
84 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
85 uint8_t *buf, int nb_sectors);
86 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
87 const uint8_t *buf, int nb_sectors);
88 void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
89 int bdrv_commit(BlockDriverState *bs);
90 void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
91
92 #define BDRV_TYPE_HD 0
93 #define BDRV_TYPE_CDROM 1
94 #define BDRV_TYPE_FLOPPY 2
95
96 void bdrv_set_geometry_hint(BlockDriverState *bs,
97 int cyls, int heads, int secs);
98 void bdrv_set_type_hint(BlockDriverState *bs, int type);
99 void bdrv_get_geometry_hint(BlockDriverState *bs,
100 int *pcyls, int *pheads, int *psecs);
101 int bdrv_get_type_hint(BlockDriverState *bs);
102 int bdrv_is_removable(BlockDriverState *bs);
103 int bdrv_is_read_only(BlockDriverState *bs);
104 int bdrv_is_inserted(BlockDriverState *bs);
105 int bdrv_is_locked(BlockDriverState *bs);
106 void bdrv_set_locked(BlockDriverState *bs, int locked);
107 void bdrv_set_change_cb(BlockDriverState *bs,
108 void (*change_cb)(void *opaque), void *opaque);
109
110 void bdrv_info(void);
111 BlockDriverState *bdrv_find(const char *name);
112
113 /* vga.c */
114
115 #define VGA_RAM_SIZE (4096 * 1024)
116
117 typedef struct DisplayState {
118 uint8_t *data;
119 int linesize;
120 int depth;
121 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
122 void (*dpy_resize)(struct DisplayState *s, int w, int h);
123 void (*dpy_refresh)(struct DisplayState *s);
124 } DisplayState;
125
126 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
127 {
128 s->dpy_update(s, x, y, w, h);
129 }
130
131 static inline void dpy_resize(DisplayState *s, int w, int h)
132 {
133 s->dpy_resize(s, w, h);
134 }
135
136 int vga_initialize(DisplayState *ds, uint8_t *vga_ram_base,
137 unsigned long vga_ram_offset, int vga_ram_size);
138 void vga_update_display(void);
139
140 /* sdl.c */
141 void sdl_display_init(DisplayState *ds);
142
143 /* ide.c */
144 #define MAX_DISKS 4
145
146 extern BlockDriverState *bs_table[MAX_DISKS];
147
148 void ide_init(int iobase, int iobase2, int irq,
149 BlockDriverState *hd0, BlockDriverState *hd1);
150
151 /* oss.c */
152 typedef enum {
153 AUD_FMT_U8,
154 AUD_FMT_S8,
155 AUD_FMT_U16,
156 AUD_FMT_S16
157 } audfmt_e;
158
159 void AUD_open (int rfreq, int rnchannels, audfmt_e rfmt);
160 void AUD_reset (int rfreq, int rnchannels, audfmt_e rfmt);
161 int AUD_write (void *in_buf, int size);
162 void AUD_run (void);
163 void AUD_adjust_estimate (int _leftover);
164 int AUD_get_free (void);
165 int AUD_get_live (void);
166 int AUD_get_buffer_size (void);
167 void AUD_init (void);
168
169 /* dma.c */
170 typedef int (*DMA_transfer_handler) (void *opaque, target_ulong addr, int size);
171 int DMA_get_channel_mode (int nchan);
172 void DMA_hold_DREQ (int nchan);
173 void DMA_release_DREQ (int nchan);
174 void DMA_schedule(int nchan);
175 void DMA_run (void);
176 void DMA_init (void);
177 void DMA_register_channel (int nchan,
178 DMA_transfer_handler transfer_handler, void *opaque);
179
180 /* sb16.c */
181 void SB16_run (void);
182 void SB16_init (void);
183
184 /* fdc.c */
185 #define MAX_FD 2
186 extern BlockDriverState *fd_table[MAX_FD];
187
188 void fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, uint32_t base,
189 BlockDriverState **fds);
190 int fdctrl_get_drive_type(int drive_num);
191
192 /* ne2000.c */
193
194 void ne2000_init(int base, int irq, NetDriverState *nd);
195
196 /* pckbd.c */
197
198 void kbd_put_keycode(int keycode);
199
200 #define MOUSE_EVENT_LBUTTON 0x01
201 #define MOUSE_EVENT_RBUTTON 0x02
202 #define MOUSE_EVENT_MBUTTON 0x04
203 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
204
205 void kbd_init(void);
206
207 /* mc146818rtc.c */
208
209 typedef struct RTCState {
210 uint8_t cmos_data[128];
211 uint8_t cmos_index;
212 int irq;
213 } RTCState;
214
215 extern RTCState rtc_state;
216
217 void rtc_init(int base, int irq);
218 void rtc_timer(void);
219
220 /* serial.c */
221
222 typedef struct SerialState SerialState;
223
224 extern SerialState *serial_console;
225
226 SerialState *serial_init(int base, int irq, int fd);
227 int serial_can_receive(SerialState *s);
228 void serial_receive_byte(SerialState *s, int ch);
229 void serial_receive_break(SerialState *s);
230
231 /* i8259.c */
232
233 void pic_set_irq(int irq, int level);
234 void pic_init(void);
235
236 /* i8254.c */
237
238 #define PIT_FREQ 1193182
239
240 typedef struct PITChannelState {
241 int count; /* can be 65536 */
242 uint16_t latched_count;
243 uint8_t rw_state;
244 uint8_t mode;
245 uint8_t bcd; /* not supported */
246 uint8_t gate; /* timer start */
247 int64_t count_load_time;
248 int64_t count_last_edge_check_time;
249 } PITChannelState;
250
251 extern PITChannelState pit_channels[3];
252
253 void pit_init(int base);
254 void pit_set_gate(PITChannelState *s, int val);
255 int pit_get_out(PITChannelState *s);
256 int pit_get_out_edges(PITChannelState *s);
257
258 /* pc.c */
259 void pc_init(int ram_size, int vga_ram_size, int boot_device,
260 DisplayState *ds, const char **fd_filename, int snapshot,
261 const char *kernel_filename, const char *kernel_cmdline,
262 const char *initrd_filename);
263
264 /* monitor.c */
265 void monitor_init(void);
266 void term_printf(const char *fmt, ...);
267 void term_flush(void);
268 void term_print_help(void);
269
270 #endif /* VL_H */