]> git.proxmox.com Git - mirror_qemu.git/blame - vl.h
dummy VGA PCI support - VGA font selection fix (Daniel Serpell)
[mirror_qemu.git] / vl.h
CommitLineData
fc01f7e7
FB
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
67b915a5
FB
27/* we put basic includes here to avoid repeating them in device drivers */
28#include <stdlib.h>
29#include <stdio.h>
30#include <stdarg.h>
31#include <string.h>
32#include <inttypes.h>
8a7ddc38 33#include <time.h>
67b915a5
FB
34#include <ctype.h>
35#include <errno.h>
36#include <unistd.h>
37#include <fcntl.h>
7d3505c5 38#include <sys/stat.h>
67b915a5
FB
39
40#ifndef O_LARGEFILE
41#define O_LARGEFILE 0
42#endif
40c3bac3
FB
43#ifndef O_BINARY
44#define O_BINARY 0
45#endif
67b915a5
FB
46
47#ifdef _WIN32
bfbc9133 48#define lseek64 _lseeki64
67b915a5 49#endif
8a7ddc38 50
16f62432
FB
51#include "cpu.h"
52
7d3505c5
FB
53#ifdef _BSD
54#define lseek64 lseek
55#define ftruncate64 ftruncate
56#define mkstemp64 mkstemp
57#define MAP_ANONYMOUS MAP_ANON
58#endif
59
67b915a5
FB
60#ifndef glue
61#define xglue(x, y) x ## y
62#define glue(x, y) xglue(x, y)
63#define stringify(s) tostring(s)
64#define tostring(s) #s
65#endif
66
67#if defined(WORDS_BIGENDIAN)
68static inline uint32_t be32_to_cpu(uint32_t v)
69{
70 return v;
71}
72
73static inline uint16_t be16_to_cpu(uint16_t v)
74{
75 return v;
76}
77
165c6fc8
FB
78static inline uint32_t cpu_to_be32(uint32_t v)
79{
80 return v;
81}
82
83static inline uint16_t cpu_to_be16(uint16_t v)
84{
85 return v;
86}
87
67b915a5
FB
88static inline uint32_t le32_to_cpu(uint32_t v)
89{
90 return bswap32(v);
91}
92
93static inline uint16_t le16_to_cpu(uint16_t v)
94{
95 return bswap16(v);
96}
97
165c6fc8
FB
98static inline uint32_t cpu_to_le32(uint32_t v)
99{
100 return bswap32(v);
101}
102
103static inline uint16_t cpu_to_le16(uint16_t v)
104{
105 return bswap16(v);
106}
107
67b915a5 108#else
165c6fc8 109
67b915a5
FB
110static inline uint32_t be32_to_cpu(uint32_t v)
111{
112 return bswap32(v);
113}
114
115static inline uint16_t be16_to_cpu(uint16_t v)
116{
117 return bswap16(v);
118}
119
165c6fc8
FB
120static inline uint32_t cpu_to_be32(uint32_t v)
121{
122 return bswap32(v);
123}
124
125static inline uint16_t cpu_to_be16(uint16_t v)
126{
127 return bswap16(v);
128}
129
67b915a5
FB
130static inline uint32_t le32_to_cpu(uint32_t v)
131{
132 return v;
133}
134
135static inline uint16_t le16_to_cpu(uint16_t v)
136{
137 return v;
138}
165c6fc8
FB
139
140static inline uint32_t cpu_to_le32(uint32_t v)
141{
142 return v;
143}
144
145static inline uint16_t cpu_to_le16(uint16_t v)
146{
147 return v;
148}
67b915a5
FB
149#endif
150
151
33e3963e 152/* vl.c */
313aa567
FB
153extern int reset_requested;
154
80cabfad 155uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
313aa567 156
80cabfad
FB
157void hw_error(const char *fmt, ...);
158
159int load_image(const char *filename, uint8_t *addr);
160extern const char *bios_dir;
161
162void pstrcpy(char *buf, int buf_size, const char *str);
163char *pstrcat(char *buf, int buf_size, const char *s);
33e3963e 164
c4b1fcc0
FB
165int serial_open_device(void);
166
8a7ddc38
FB
167extern int vm_running;
168
169typedef void VMStopHandler(void *opaque, int reason);
170
171int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
172void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
173
174void vm_start(void);
175void vm_stop(int reason);
176
aaaa7df6
FB
177extern int audio_enabled;
178
c20709aa
FB
179/* async I/O support */
180
181typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
182typedef int IOCanRWHandler(void *opaque);
183
184int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read,
185 IOReadHandler *fd_read, void *opaque);
186void qemu_del_fd_read_handler(int fd);
187
c4b1fcc0
FB
188/* network redirectors support */
189
190#define MAX_NICS 8
191
192typedef struct NetDriverState {
c20709aa 193 int index; /* index number in QEMU */
c4b1fcc0
FB
194 uint8_t macaddr[6];
195 char ifname[16];
c20709aa
FB
196 void (*send_packet)(struct NetDriverState *nd,
197 const uint8_t *buf, int size);
198 void (*add_read_packet)(struct NetDriverState *nd,
199 IOCanRWHandler *fd_can_read,
200 IOReadHandler *fd_read, void *opaque);
201 /* tun specific data */
202 int fd;
203 /* slirp specific data */
c4b1fcc0
FB
204} NetDriverState;
205
206extern int nb_nics;
207extern NetDriverState nd_table[MAX_NICS];
208
c20709aa
FB
209void qemu_send_packet(NetDriverState *nd, const uint8_t *buf, int size);
210void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read,
211 IOReadHandler *fd_read, void *opaque);
8a7ddc38
FB
212
213/* timers */
214
215typedef struct QEMUClock QEMUClock;
216typedef struct QEMUTimer QEMUTimer;
217typedef void QEMUTimerCB(void *opaque);
218
219/* The real time clock should be used only for stuff which does not
220 change the virtual machine state, as it is run even if the virtual
69b91039 221 machine is stopped. The real time clock has a frequency of 1000
8a7ddc38
FB
222 Hz. */
223extern QEMUClock *rt_clock;
224
225/* Rge virtual clock is only run during the emulation. It is stopped
226 when the virtual machine is stopped. Virtual timers use a high
227 precision clock, usually cpu cycles (use ticks_per_sec). */
228extern QEMUClock *vm_clock;
229
230int64_t qemu_get_clock(QEMUClock *clock);
231
232QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
233void qemu_free_timer(QEMUTimer *ts);
234void qemu_del_timer(QEMUTimer *ts);
235void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
236int qemu_timer_pending(QEMUTimer *ts);
237
238extern int64_t ticks_per_sec;
239extern int pit_min_timer_count;
240
241void cpu_enable_ticks(void);
242void cpu_disable_ticks(void);
243
244/* VM Load/Save */
245
246typedef FILE QEMUFile;
247
248void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
249void qemu_put_byte(QEMUFile *f, int v);
250void qemu_put_be16(QEMUFile *f, unsigned int v);
251void qemu_put_be32(QEMUFile *f, unsigned int v);
252void qemu_put_be64(QEMUFile *f, uint64_t v);
253int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
254int qemu_get_byte(QEMUFile *f);
255unsigned int qemu_get_be16(QEMUFile *f);
256unsigned int qemu_get_be32(QEMUFile *f);
257uint64_t qemu_get_be64(QEMUFile *f);
258
259static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
260{
261 qemu_put_be64(f, *pv);
262}
263
264static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
265{
266 qemu_put_be32(f, *pv);
267}
268
269static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
270{
271 qemu_put_be16(f, *pv);
272}
273
274static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
275{
276 qemu_put_byte(f, *pv);
277}
278
279static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
280{
281 *pv = qemu_get_be64(f);
282}
283
284static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
285{
286 *pv = qemu_get_be32(f);
287}
288
289static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
290{
291 *pv = qemu_get_be16(f);
292}
293
294static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
295{
296 *pv = qemu_get_byte(f);
297}
298
299int64_t qemu_ftell(QEMUFile *f);
300int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
301
302typedef void SaveStateHandler(QEMUFile *f, void *opaque);
303typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
304
305int qemu_loadvm(const char *filename);
306int qemu_savevm(const char *filename);
307int register_savevm(const char *idstr,
308 int instance_id,
309 int version_id,
310 SaveStateHandler *save_state,
311 LoadStateHandler *load_state,
312 void *opaque);
313void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
314void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
c4b1fcc0 315
fc01f7e7
FB
316/* block.c */
317typedef struct BlockDriverState BlockDriverState;
318
c4b1fcc0
FB
319BlockDriverState *bdrv_new(const char *device_name);
320void bdrv_delete(BlockDriverState *bs);
321int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
fc01f7e7
FB
322void bdrv_close(BlockDriverState *bs);
323int bdrv_read(BlockDriverState *bs, int64_t sector_num,
324 uint8_t *buf, int nb_sectors);
325int bdrv_write(BlockDriverState *bs, int64_t sector_num,
326 const uint8_t *buf, int nb_sectors);
327void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
33e3963e 328int bdrv_commit(BlockDriverState *bs);
77fef8c1 329void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
33e3963e 330
c4b1fcc0
FB
331#define BDRV_TYPE_HD 0
332#define BDRV_TYPE_CDROM 1
333#define BDRV_TYPE_FLOPPY 2
334
335void bdrv_set_geometry_hint(BlockDriverState *bs,
336 int cyls, int heads, int secs);
337void bdrv_set_type_hint(BlockDriverState *bs, int type);
338void bdrv_get_geometry_hint(BlockDriverState *bs,
339 int *pcyls, int *pheads, int *psecs);
340int bdrv_get_type_hint(BlockDriverState *bs);
341int bdrv_is_removable(BlockDriverState *bs);
342int bdrv_is_read_only(BlockDriverState *bs);
343int bdrv_is_inserted(BlockDriverState *bs);
344int bdrv_is_locked(BlockDriverState *bs);
345void bdrv_set_locked(BlockDriverState *bs, int locked);
346void bdrv_set_change_cb(BlockDriverState *bs,
347 void (*change_cb)(void *opaque), void *opaque);
348
349void bdrv_info(void);
350BlockDriverState *bdrv_find(const char *name);
351
26aa7d72
FB
352/* ISA bus */
353
354extern target_phys_addr_t isa_mem_base;
355
356typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
357typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
358
359int register_ioport_read(int start, int length, int size,
360 IOPortReadFunc *func, void *opaque);
361int register_ioport_write(int start, int length, int size,
362 IOPortWriteFunc *func, void *opaque);
69b91039
FB
363void isa_unassign_ioport(int start, int length);
364
365/* PCI bus */
366
367extern int pci_enabled;
368
369extern target_phys_addr_t pci_mem_base;
370
371typedef struct PCIDevice PCIDevice;
372
373typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
374 uint32_t address, uint32_t data, int len);
375typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
376 uint32_t address, int len);
377typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num,
378 uint32_t addr, uint32_t size, int type);
379
380#define PCI_ADDRESS_SPACE_MEM 0x00
381#define PCI_ADDRESS_SPACE_IO 0x01
382#define PCI_ADDRESS_SPACE_MEM_PREFETCH 0x08
383
384typedef struct PCIIORegion {
385 uint32_t addr;
386 uint32_t size;
387 uint8_t type;
388 PCIMapIORegionFunc *map_func;
389} PCIIORegion;
390
391struct PCIDevice {
392 /* PCI config space */
393 uint8_t config[256];
394
395 /* the following fields are read only */
396 int bus_num;
397 int devfn;
398 char name[64];
399 PCIIORegion io_regions[6];
400
401 /* do not access the following fields */
402 PCIConfigReadFunc *config_read;
403 PCIConfigWriteFunc *config_write;
404};
405
406PCIDevice *pci_register_device(const char *name, int instance_size,
407 int bus_num, int devfn,
408 PCIConfigReadFunc *config_read,
409 PCIConfigWriteFunc *config_write);
410
411void pci_register_io_region(PCIDevice *pci_dev, int region_num,
412 uint32_t size, int type,
413 PCIMapIORegionFunc *map_func);
414
415void i440fx_init(void);
416void piix3_init(void);
417void pci_bios_init(void);
26aa7d72 418
313aa567
FB
419/* vga.c */
420
4fa0f5d2 421#define VGA_RAM_SIZE (4096 * 1024)
313aa567
FB
422
423typedef struct DisplayState {
424 uint8_t *data;
425 int linesize;
426 int depth;
427 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
428 void (*dpy_resize)(struct DisplayState *s, int w, int h);
429 void (*dpy_refresh)(struct DisplayState *s);
430} DisplayState;
431
432static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
433{
434 s->dpy_update(s, x, y, w, h);
435}
436
437static inline void dpy_resize(DisplayState *s, int w, int h)
438{
439 s->dpy_resize(s, w, h);
440}
441
7138fcfb
FB
442int vga_initialize(DisplayState *ds, uint8_t *vga_ram_base,
443 unsigned long vga_ram_offset, int vga_ram_size);
313aa567 444void vga_update_display(void);
59a983b9 445void vga_screen_dump(const char *filename);
313aa567
FB
446
447/* sdl.c */
448void sdl_display_init(DisplayState *ds);
449
5391d806
FB
450/* ide.c */
451#define MAX_DISKS 4
452
453extern BlockDriverState *bs_table[MAX_DISKS];
454
69b91039
FB
455void isa_ide_init(int iobase, int iobase2, int irq,
456 BlockDriverState *hd0, BlockDriverState *hd1);
457void pci_ide_init(BlockDriverState **hd_table);
5391d806 458
27503323
FB
459/* oss.c */
460typedef enum {
461 AUD_FMT_U8,
462 AUD_FMT_S8,
463 AUD_FMT_U16,
464 AUD_FMT_S16
465} audfmt_e;
466
467void AUD_open (int rfreq, int rnchannels, audfmt_e rfmt);
468void AUD_reset (int rfreq, int rnchannels, audfmt_e rfmt);
469int AUD_write (void *in_buf, int size);
470void AUD_run (void);
471void AUD_adjust_estimate (int _leftover);
472int AUD_get_free (void);
473int AUD_get_live (void);
474int AUD_get_buffer_size (void);
475void AUD_init (void);
476
477/* dma.c */
16f62432 478typedef int (*DMA_transfer_handler) (void *opaque, target_ulong addr, int size);
27503323
FB
479int DMA_get_channel_mode (int nchan);
480void DMA_hold_DREQ (int nchan);
481void DMA_release_DREQ (int nchan);
16f62432 482void DMA_schedule(int nchan);
27503323
FB
483void DMA_run (void);
484void DMA_init (void);
485void DMA_register_channel (int nchan,
16f62432 486 DMA_transfer_handler transfer_handler, void *opaque);
27503323
FB
487
488/* sb16.c */
489void SB16_run (void);
490void SB16_init (void);
491
7138fcfb
FB
492/* fdc.c */
493#define MAX_FD 2
494extern BlockDriverState *fd_table[MAX_FD];
495
baca51fa
FB
496typedef struct fdctrl_t fdctrl_t;
497
498fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped,
499 uint32_t io_base,
500 BlockDriverState **fds);
501int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
7138fcfb 502
80cabfad
FB
503/* ne2000.c */
504
69b91039
FB
505void isa_ne2000_init(int base, int irq, NetDriverState *nd);
506void pci_ne2000_init(NetDriverState *nd);
80cabfad
FB
507
508/* pckbd.c */
509
510void kbd_put_keycode(int keycode);
511
512#define MOUSE_EVENT_LBUTTON 0x01
513#define MOUSE_EVENT_RBUTTON 0x02
514#define MOUSE_EVENT_MBUTTON 0x04
515void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
516
517void kbd_init(void);
518
519/* mc146818rtc.c */
520
8a7ddc38 521typedef struct RTCState RTCState;
80cabfad 522
8a7ddc38
FB
523RTCState *rtc_init(int base, int irq);
524void rtc_set_memory(RTCState *s, int addr, int val);
525void rtc_set_date(RTCState *s, const struct tm *tm);
80cabfad
FB
526
527/* serial.c */
528
c4b1fcc0
FB
529typedef struct SerialState SerialState;
530
531extern SerialState *serial_console;
532
533SerialState *serial_init(int base, int irq, int fd);
534int serial_can_receive(SerialState *s);
535void serial_receive_byte(SerialState *s, int ch);
536void serial_receive_break(SerialState *s);
80cabfad
FB
537
538/* i8259.c */
539
540void pic_set_irq(int irq, int level);
541void pic_init(void);
c5df018e 542uint32_t pic_intack_read(CPUState *env);
c20709aa 543void pic_info(void);
80cabfad
FB
544
545/* i8254.c */
546
547#define PIT_FREQ 1193182
548
ec844b96
FB
549typedef struct PITState PITState;
550
551PITState *pit_init(int base, int irq);
552void pit_set_gate(PITState *pit, int channel, int val);
553int pit_get_gate(PITState *pit, int channel);
554int pit_get_out(PITState *pit, int channel, int64_t current_time);
80cabfad
FB
555
556/* pc.c */
557void pc_init(int ram_size, int vga_ram_size, int boot_device,
558 DisplayState *ds, const char **fd_filename, int snapshot,
559 const char *kernel_filename, const char *kernel_cmdline,
560 const char *initrd_filename);
561
26aa7d72
FB
562/* ppc.c */
563void ppc_init (int ram_size, int vga_ram_size, int boot_device,
564 DisplayState *ds, const char **fd_filename, int snapshot,
565 const char *kernel_filename, const char *kernel_cmdline,
566 const char *initrd_filename);
567
c4b1fcc0
FB
568/* monitor.c */
569void monitor_init(void);
40c3bac3 570void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
c4b1fcc0
FB
571void term_flush(void);
572void term_print_help(void);
573
8a7ddc38
FB
574/* gdbstub.c */
575
576#define DEFAULT_GDBSTUB_PORT 1234
577
578int gdbserver_start(int port);
579
fc01f7e7 580#endif /* VL_H */