Annotation of qemu/vl.h, revision 1.1.1.2

1.1       root        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: /* 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>
                     33: #include <limits.h>
                     34: #include <time.h>
                     35: #include <ctype.h>
                     36: #include <errno.h>
                     37: #include <unistd.h>
                     38: #include <fcntl.h>
                     39: #include <sys/stat.h>
                     40: #include "audio/audio.h"
                     41: 
                     42: #ifndef O_LARGEFILE
                     43: #define O_LARGEFILE 0
                     44: #endif
                     45: #ifndef O_BINARY
                     46: #define O_BINARY 0
                     47: #endif
                     48: 
                     49: #ifdef _WIN32
                     50: #define lseek _lseeki64
                     51: #define ENOTSUP 4096
                     52: /* XXX: find 64 bit version */
                     53: #define ftruncate chsize
                     54: 
                     55: static inline char *realpath(const char *path, char *resolved_path)
                     56: {
                     57:     _fullpath(resolved_path, path, _MAX_PATH);
                     58:     return resolved_path;
                     59: }
                     60: #endif
                     61: 
                     62: #ifdef QEMU_TOOL
                     63: 
                     64: /* we use QEMU_TOOL in the command line tools which do not depend on
                     65:    the target CPU type */
                     66: #include "config-host.h"
                     67: #include <setjmp.h>
                     68: #include "osdep.h"
                     69: #include "bswap.h"
                     70: 
                     71: #else
                     72: 
                     73: #include "cpu.h"
                     74: #include "gdbstub.h"
                     75: 
                     76: #endif /* !defined(QEMU_TOOL) */
                     77: 
                     78: #ifndef glue
                     79: #define xglue(x, y) x ## y
                     80: #define glue(x, y) xglue(x, y)
                     81: #define stringify(s)   tostring(s)
                     82: #define tostring(s)    #s
                     83: #endif
                     84: 
                     85: /* vl.c */
                     86: uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
                     87: 
                     88: void hw_error(const char *fmt, ...);
                     89: 
                     90: int get_image_size(const char *filename);
                     91: int load_image(const char *filename, uint8_t *addr);
                     92: extern const char *bios_dir;
                     93: 
                     94: void pstrcpy(char *buf, int buf_size, const char *str);
                     95: char *pstrcat(char *buf, int buf_size, const char *s);
                     96: int strstart(const char *str, const char *val, const char **ptr);
                     97: 
                     98: extern int vm_running;
                     99: 
1.1.1.2 ! root      100: typedef struct vm_change_state_entry VMChangeStateEntry;
        !           101: typedef void VMChangeStateHandler(void *opaque, int running);
1.1       root      102: typedef void VMStopHandler(void *opaque, int reason);
                    103: 
1.1.1.2 ! root      104: VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
        !           105:                                                      void *opaque);
        !           106: void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
        !           107: 
1.1       root      108: int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
                    109: void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
                    110: 
                    111: void vm_start(void);
                    112: void vm_stop(int reason);
                    113: 
                    114: typedef void QEMUResetHandler(void *opaque);
                    115: 
                    116: void qemu_register_reset(QEMUResetHandler *func, void *opaque);
                    117: void qemu_system_reset_request(void);
                    118: void qemu_system_shutdown_request(void);
                    119: void qemu_system_powerdown_request(void);
                    120: #if !defined(TARGET_SPARC)
                    121: // Please implement a power failure function to signal the OS
                    122: #define qemu_system_powerdown() do{}while(0)
                    123: #else
                    124: void qemu_system_powerdown(void);
                    125: #endif
                    126: 
                    127: void main_loop_wait(int timeout);
                    128: 
                    129: extern int ram_size;
                    130: extern int bios_size;
                    131: extern int rtc_utc;
                    132: extern int cirrus_vga_enabled;
                    133: extern int graphic_width;
                    134: extern int graphic_height;
                    135: extern int graphic_depth;
                    136: extern const char *keyboard_layout;
                    137: extern int kqemu_allowed;
                    138: extern int win2k_install_hack;
1.1.1.2 ! root      139: extern int usb_enabled;
        !           140: extern int smp_cpus;
1.1       root      141: 
                    142: /* XXX: make it dynamic */
                    143: #if defined (TARGET_PPC)
                    144: #define BIOS_SIZE ((512 + 32) * 1024)
                    145: #elif defined(TARGET_MIPS)
                    146: #define BIOS_SIZE (128 * 1024)
                    147: #else
                    148: #define BIOS_SIZE ((256 + 64) * 1024)
                    149: #endif
                    150: 
                    151: /* keyboard/mouse support */
                    152: 
                    153: #define MOUSE_EVENT_LBUTTON 0x01
                    154: #define MOUSE_EVENT_RBUTTON 0x02
                    155: #define MOUSE_EVENT_MBUTTON 0x04
                    156: 
                    157: typedef void QEMUPutKBDEvent(void *opaque, int keycode);
                    158: typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
                    159: 
                    160: void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
                    161: void qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque);
                    162: 
                    163: void kbd_put_keycode(int keycode);
                    164: void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
                    165: 
                    166: /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
                    167:    constants) */
                    168: #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
                    169: #define QEMU_KEY_BACKSPACE  0x007f
                    170: #define QEMU_KEY_UP         QEMU_KEY_ESC1('A')
                    171: #define QEMU_KEY_DOWN       QEMU_KEY_ESC1('B')
                    172: #define QEMU_KEY_RIGHT      QEMU_KEY_ESC1('C')
                    173: #define QEMU_KEY_LEFT       QEMU_KEY_ESC1('D')
                    174: #define QEMU_KEY_HOME       QEMU_KEY_ESC1(1)
                    175: #define QEMU_KEY_END        QEMU_KEY_ESC1(4)
                    176: #define QEMU_KEY_PAGEUP     QEMU_KEY_ESC1(5)
                    177: #define QEMU_KEY_PAGEDOWN   QEMU_KEY_ESC1(6)
                    178: #define QEMU_KEY_DELETE     QEMU_KEY_ESC1(3)
                    179: 
                    180: #define QEMU_KEY_CTRL_UP         0xe400
                    181: #define QEMU_KEY_CTRL_DOWN       0xe401
                    182: #define QEMU_KEY_CTRL_LEFT       0xe402
                    183: #define QEMU_KEY_CTRL_RIGHT      0xe403
                    184: #define QEMU_KEY_CTRL_HOME       0xe404
                    185: #define QEMU_KEY_CTRL_END        0xe405
                    186: #define QEMU_KEY_CTRL_PAGEUP     0xe406
                    187: #define QEMU_KEY_CTRL_PAGEDOWN   0xe407
                    188: 
                    189: void kbd_put_keysym(int keysym);
                    190: 
                    191: /* async I/O support */
                    192: 
                    193: typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
                    194: typedef int IOCanRWHandler(void *opaque);
1.1.1.2 ! root      195: typedef void IOHandler(void *opaque);
1.1       root      196: 
1.1.1.2 ! root      197: int qemu_set_fd_handler2(int fd, 
        !           198:                          IOCanRWHandler *fd_read_poll, 
        !           199:                          IOHandler *fd_read, 
        !           200:                          IOHandler *fd_write, 
        !           201:                          void *opaque);
        !           202: int qemu_set_fd_handler(int fd,
        !           203:                         IOHandler *fd_read, 
        !           204:                         IOHandler *fd_write,
        !           205:                         void *opaque);
1.1       root      206: 
                    207: /* character device */
                    208: 
                    209: #define CHR_EVENT_BREAK 0 /* serial break char */
                    210: #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
                    211: 
1.1.1.2 ! root      212: 
        !           213: 
        !           214: #define CHR_IOCTL_SERIAL_SET_PARAMS   1
        !           215: typedef struct {
        !           216:     int speed;
        !           217:     int parity;
        !           218:     int data_bits;
        !           219:     int stop_bits;
        !           220: } QEMUSerialSetParams;
        !           221: 
        !           222: #define CHR_IOCTL_SERIAL_SET_BREAK    2
        !           223: 
        !           224: #define CHR_IOCTL_PP_READ_DATA        3
        !           225: #define CHR_IOCTL_PP_WRITE_DATA       4
        !           226: #define CHR_IOCTL_PP_READ_CONTROL     5
        !           227: #define CHR_IOCTL_PP_WRITE_CONTROL    6
        !           228: #define CHR_IOCTL_PP_READ_STATUS      7
        !           229: 
1.1       root      230: typedef void IOEventHandler(void *opaque, int event);
                    231: 
                    232: typedef struct CharDriverState {
                    233:     int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
                    234:     void (*chr_add_read_handler)(struct CharDriverState *s, 
                    235:                                  IOCanRWHandler *fd_can_read, 
                    236:                                  IOReadHandler *fd_read, void *opaque);
1.1.1.2 ! root      237:     int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
1.1       root      238:     IOEventHandler *chr_event;
                    239:     void (*chr_send_event)(struct CharDriverState *chr, int event);
                    240:     void *opaque;
                    241: } CharDriverState;
                    242: 
                    243: void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
                    244: int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
                    245: void qemu_chr_send_event(CharDriverState *s, int event);
                    246: void qemu_chr_add_read_handler(CharDriverState *s, 
                    247:                                IOCanRWHandler *fd_can_read, 
                    248:                                IOReadHandler *fd_read, void *opaque);
                    249: void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event);
1.1.1.2 ! root      250: int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
        !           251: 
1.1       root      252: /* consoles */
                    253: 
                    254: typedef struct DisplayState DisplayState;
                    255: typedef struct TextConsole TextConsole;
                    256: 
                    257: extern TextConsole *vga_console;
                    258: 
                    259: TextConsole *graphic_console_init(DisplayState *ds);
                    260: int is_active_console(TextConsole *s);
                    261: CharDriverState *text_console_init(DisplayState *ds);
                    262: void console_select(unsigned int index);
                    263: 
                    264: /* serial ports */
                    265: 
                    266: #define MAX_SERIAL_PORTS 4
                    267: 
                    268: extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
                    269: 
                    270: /* parallel ports */
                    271: 
                    272: #define MAX_PARALLEL_PORTS 3
                    273: 
                    274: extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
                    275: 
1.1.1.2 ! root      276: /* VLANs support */
        !           277: 
        !           278: typedef struct VLANClientState VLANClientState;
        !           279: 
        !           280: struct VLANClientState {
        !           281:     IOReadHandler *fd_read;
        !           282:     void *opaque;
        !           283:     struct VLANClientState *next;
        !           284:     struct VLANState *vlan;
        !           285:     char info_str[256];
        !           286: };
        !           287: 
        !           288: typedef struct VLANState {
        !           289:     int id;
        !           290:     VLANClientState *first_client;
        !           291:     struct VLANState *next;
        !           292: } VLANState;
        !           293: 
        !           294: VLANState *qemu_find_vlan(int id);
        !           295: VLANClientState *qemu_new_vlan_client(VLANState *vlan,
        !           296:                                       IOReadHandler *fd_read, void *opaque);
        !           297: void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
        !           298: 
        !           299: void do_info_network(void);
        !           300: 
        !           301: /* NIC info */
1.1       root      302: 
                    303: #define MAX_NICS 8
                    304: 
1.1.1.2 ! root      305: typedef struct NICInfo {
1.1       root      306:     uint8_t macaddr[6];
1.1.1.2 ! root      307:     VLANState *vlan;
        !           308: } NICInfo;
1.1       root      309: 
                    310: extern int nb_nics;
1.1.1.2 ! root      311: extern NICInfo nd_table[MAX_NICS];
1.1       root      312: 
                    313: /* timers */
                    314: 
                    315: typedef struct QEMUClock QEMUClock;
                    316: typedef struct QEMUTimer QEMUTimer;
                    317: typedef void QEMUTimerCB(void *opaque);
                    318: 
                    319: /* The real time clock should be used only for stuff which does not
                    320:    change the virtual machine state, as it is run even if the virtual
                    321:    machine is stopped. The real time clock has a frequency of 1000
                    322:    Hz. */
                    323: extern QEMUClock *rt_clock;
                    324: 
                    325: /* The virtual clock is only run during the emulation. It is stopped
                    326:    when the virtual machine is stopped. Virtual timers use a high
                    327:    precision clock, usually cpu cycles (use ticks_per_sec). */
                    328: extern QEMUClock *vm_clock;
                    329: 
                    330: int64_t qemu_get_clock(QEMUClock *clock);
                    331: 
                    332: QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
                    333: void qemu_free_timer(QEMUTimer *ts);
                    334: void qemu_del_timer(QEMUTimer *ts);
                    335: void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
                    336: int qemu_timer_pending(QEMUTimer *ts);
                    337: 
                    338: extern int64_t ticks_per_sec;
                    339: extern int pit_min_timer_count;
                    340: 
                    341: void cpu_enable_ticks(void);
                    342: void cpu_disable_ticks(void);
                    343: 
                    344: /* VM Load/Save */
                    345: 
                    346: typedef FILE QEMUFile;
                    347: 
                    348: void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
                    349: void qemu_put_byte(QEMUFile *f, int v);
                    350: void qemu_put_be16(QEMUFile *f, unsigned int v);
                    351: void qemu_put_be32(QEMUFile *f, unsigned int v);
                    352: void qemu_put_be64(QEMUFile *f, uint64_t v);
                    353: int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
                    354: int qemu_get_byte(QEMUFile *f);
                    355: unsigned int qemu_get_be16(QEMUFile *f);
                    356: unsigned int qemu_get_be32(QEMUFile *f);
                    357: uint64_t qemu_get_be64(QEMUFile *f);
                    358: 
                    359: static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
                    360: {
                    361:     qemu_put_be64(f, *pv);
                    362: }
                    363: 
                    364: static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
                    365: {
                    366:     qemu_put_be32(f, *pv);
                    367: }
                    368: 
                    369: static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
                    370: {
                    371:     qemu_put_be16(f, *pv);
                    372: }
                    373: 
                    374: static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
                    375: {
                    376:     qemu_put_byte(f, *pv);
                    377: }
                    378: 
                    379: static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
                    380: {
                    381:     *pv = qemu_get_be64(f);
                    382: }
                    383: 
                    384: static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
                    385: {
                    386:     *pv = qemu_get_be32(f);
                    387: }
                    388: 
                    389: static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
                    390: {
                    391:     *pv = qemu_get_be16(f);
                    392: }
                    393: 
                    394: static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
                    395: {
                    396:     *pv = qemu_get_byte(f);
                    397: }
                    398: 
                    399: #if TARGET_LONG_BITS == 64
                    400: #define qemu_put_betl qemu_put_be64
                    401: #define qemu_get_betl qemu_get_be64
                    402: #define qemu_put_betls qemu_put_be64s
                    403: #define qemu_get_betls qemu_get_be64s
                    404: #else
                    405: #define qemu_put_betl qemu_put_be32
                    406: #define qemu_get_betl qemu_get_be32
                    407: #define qemu_put_betls qemu_put_be32s
                    408: #define qemu_get_betls qemu_get_be32s
                    409: #endif
                    410: 
                    411: int64_t qemu_ftell(QEMUFile *f);
                    412: int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
                    413: 
                    414: typedef void SaveStateHandler(QEMUFile *f, void *opaque);
                    415: typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
                    416: 
                    417: int qemu_loadvm(const char *filename);
                    418: int qemu_savevm(const char *filename);
                    419: int register_savevm(const char *idstr, 
                    420:                     int instance_id, 
                    421:                     int version_id,
                    422:                     SaveStateHandler *save_state,
                    423:                     LoadStateHandler *load_state,
                    424:                     void *opaque);
                    425: void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
                    426: void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
                    427: 
1.1.1.2 ! root      428: void cpu_save(QEMUFile *f, void *opaque);
        !           429: int cpu_load(QEMUFile *f, void *opaque, int version_id);
        !           430: 
1.1       root      431: /* block.c */
                    432: typedef struct BlockDriverState BlockDriverState;
                    433: typedef struct BlockDriver BlockDriver;
                    434: 
                    435: extern BlockDriver bdrv_raw;
                    436: extern BlockDriver bdrv_cow;
                    437: extern BlockDriver bdrv_qcow;
                    438: extern BlockDriver bdrv_vmdk;
                    439: extern BlockDriver bdrv_cloop;
                    440: extern BlockDriver bdrv_dmg;
                    441: extern BlockDriver bdrv_bochs;
                    442: extern BlockDriver bdrv_vpc;
                    443: extern BlockDriver bdrv_vvfat;
                    444: 
                    445: void bdrv_init(void);
                    446: BlockDriver *bdrv_find_format(const char *format_name);
                    447: int bdrv_create(BlockDriver *drv, 
                    448:                 const char *filename, int64_t size_in_sectors,
                    449:                 const char *backing_file, int flags);
                    450: BlockDriverState *bdrv_new(const char *device_name);
                    451: void bdrv_delete(BlockDriverState *bs);
                    452: int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
                    453: int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
                    454:                BlockDriver *drv);
                    455: void bdrv_close(BlockDriverState *bs);
                    456: int bdrv_read(BlockDriverState *bs, int64_t sector_num, 
                    457:               uint8_t *buf, int nb_sectors);
                    458: int bdrv_write(BlockDriverState *bs, int64_t sector_num, 
                    459:                const uint8_t *buf, int nb_sectors);
                    460: void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
                    461: int bdrv_commit(BlockDriverState *bs);
                    462: void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
                    463: 
                    464: #define BDRV_TYPE_HD     0
                    465: #define BDRV_TYPE_CDROM  1
                    466: #define BDRV_TYPE_FLOPPY 2
                    467: #define BIOS_ATA_TRANSLATION_AUTO 0
                    468: #define BIOS_ATA_TRANSLATION_NONE 1
                    469: #define BIOS_ATA_TRANSLATION_LBA  2
                    470: 
                    471: void bdrv_set_geometry_hint(BlockDriverState *bs, 
                    472:                             int cyls, int heads, int secs);
                    473: void bdrv_set_type_hint(BlockDriverState *bs, int type);
                    474: void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
                    475: void bdrv_get_geometry_hint(BlockDriverState *bs, 
                    476:                             int *pcyls, int *pheads, int *psecs);
                    477: int bdrv_get_type_hint(BlockDriverState *bs);
                    478: int bdrv_get_translation_hint(BlockDriverState *bs);
                    479: int bdrv_is_removable(BlockDriverState *bs);
                    480: int bdrv_is_read_only(BlockDriverState *bs);
                    481: int bdrv_is_inserted(BlockDriverState *bs);
                    482: int bdrv_is_locked(BlockDriverState *bs);
                    483: void bdrv_set_locked(BlockDriverState *bs, int locked);
                    484: void bdrv_set_change_cb(BlockDriverState *bs, 
                    485:                         void (*change_cb)(void *opaque), void *opaque);
                    486: void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
                    487: void bdrv_info(void);
                    488: BlockDriverState *bdrv_find(const char *name);
                    489: void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
                    490: int bdrv_is_encrypted(BlockDriverState *bs);
                    491: int bdrv_set_key(BlockDriverState *bs, const char *key);
                    492: void bdrv_iterate_format(void (*it)(void *opaque, const char *name), 
                    493:                          void *opaque);
                    494: const char *bdrv_get_device_name(BlockDriverState *bs);
                    495: 
                    496: int qcow_get_cluster_size(BlockDriverState *bs);
                    497: int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num,
                    498:                           const uint8_t *buf);
                    499: 
                    500: #ifndef QEMU_TOOL
                    501: 
                    502: typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size, 
                    503:                                  int boot_device,
                    504:              DisplayState *ds, const char **fd_filename, int snapshot,
                    505:              const char *kernel_filename, const char *kernel_cmdline,
                    506:              const char *initrd_filename);
                    507: 
                    508: typedef struct QEMUMachine {
                    509:     const char *name;
                    510:     const char *desc;
                    511:     QEMUMachineInitFunc *init;
                    512:     struct QEMUMachine *next;
                    513: } QEMUMachine;
                    514: 
                    515: int qemu_register_machine(QEMUMachine *m);
                    516: 
                    517: typedef void SetIRQFunc(void *opaque, int irq_num, int level);
                    518: typedef void IRQRequestFunc(void *opaque, int level);
                    519: 
                    520: /* ISA bus */
                    521: 
                    522: extern target_phys_addr_t isa_mem_base;
                    523: 
                    524: typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
                    525: typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
                    526: 
                    527: int register_ioport_read(int start, int length, int size, 
                    528:                          IOPortReadFunc *func, void *opaque);
                    529: int register_ioport_write(int start, int length, int size, 
                    530:                           IOPortWriteFunc *func, void *opaque);
                    531: void isa_unassign_ioport(int start, int length);
                    532: 
                    533: /* PCI bus */
                    534: 
                    535: extern target_phys_addr_t pci_mem_base;
                    536: 
                    537: typedef struct PCIBus PCIBus;
                    538: typedef struct PCIDevice PCIDevice;
                    539: 
                    540: typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, 
                    541:                                 uint32_t address, uint32_t data, int len);
                    542: typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, 
                    543:                                    uint32_t address, int len);
                    544: typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, 
                    545:                                 uint32_t addr, uint32_t size, int type);
                    546: 
                    547: #define PCI_ADDRESS_SPACE_MEM          0x00
                    548: #define PCI_ADDRESS_SPACE_IO           0x01
                    549: #define PCI_ADDRESS_SPACE_MEM_PREFETCH 0x08
                    550: 
                    551: typedef struct PCIIORegion {
                    552:     uint32_t addr; /* current PCI mapping address. -1 means not mapped */
                    553:     uint32_t size;
                    554:     uint8_t type;
                    555:     PCIMapIORegionFunc *map_func;
                    556: } PCIIORegion;
                    557: 
                    558: #define PCI_ROM_SLOT 6
                    559: #define PCI_NUM_REGIONS 7
                    560: struct PCIDevice {
                    561:     /* PCI config space */
                    562:     uint8_t config[256];
                    563: 
                    564:     /* the following fields are read only */
                    565:     PCIBus *bus;
                    566:     int devfn;
                    567:     char name[64];
                    568:     PCIIORegion io_regions[PCI_NUM_REGIONS];
                    569:     
                    570:     /* do not access the following fields */
                    571:     PCIConfigReadFunc *config_read;
                    572:     PCIConfigWriteFunc *config_write;
                    573:     int irq_index;
                    574: };
                    575: 
                    576: PCIDevice *pci_register_device(PCIBus *bus, const char *name,
                    577:                                int instance_size, int devfn,
                    578:                                PCIConfigReadFunc *config_read, 
                    579:                                PCIConfigWriteFunc *config_write);
                    580: 
                    581: void pci_register_io_region(PCIDevice *pci_dev, int region_num, 
                    582:                             uint32_t size, int type, 
                    583:                             PCIMapIORegionFunc *map_func);
                    584: 
                    585: void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level);
                    586: 
                    587: uint32_t pci_default_read_config(PCIDevice *d, 
                    588:                                  uint32_t address, int len);
                    589: void pci_default_write_config(PCIDevice *d, 
                    590:                               uint32_t address, uint32_t val, int len);
                    591: void generic_pci_save(QEMUFile* f, void *opaque);
                    592: int generic_pci_load(QEMUFile* f, void *opaque, int version_id);
                    593: 
                    594: extern struct PIIX3State *piix3_state;
                    595: 
                    596: PCIBus *i440fx_init(void);
                    597: void piix3_init(PCIBus *bus);
                    598: void pci_bios_init(void);
                    599: void pci_info(void);
                    600: 
                    601: /* temporary: will be moved in platform specific file */
                    602: void pci_set_pic(PCIBus *bus, SetIRQFunc *set_irq, void *irq_opaque);
                    603: PCIBus *pci_prep_init(void);
                    604: PCIBus *pci_grackle_init(uint32_t base);
                    605: PCIBus *pci_pmac_init(void);
                    606: PCIBus *pci_apb_init(target_ulong special_base, target_ulong mem_base);
                    607: 
                    608: /* openpic.c */
                    609: typedef struct openpic_t openpic_t;
                    610: void openpic_set_irq(void *opaque, int n_IRQ, int level);
1.1.1.2 ! root      611: openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,
        !           612:                          CPUState **envp);
1.1       root      613: 
                    614: /* heathrow_pic.c */
                    615: typedef struct HeathrowPICS HeathrowPICS;
                    616: void heathrow_pic_set_irq(void *opaque, int num, int level);
                    617: HeathrowPICS *heathrow_pic_init(int *pmem_index);
                    618: 
1.1.1.2 ! root      619: #ifdef HAS_AUDIO
        !           620: struct soundhw {
        !           621:     const char *name;
        !           622:     const char *descr;
        !           623:     int enabled;
        !           624:     int isa;
        !           625:     union {
        !           626:         int (*init_isa) (AudioState *s);
        !           627:         int (*init_pci) (PCIBus *bus, AudioState *s);
        !           628:     } init;
        !           629: };
        !           630: 
        !           631: extern struct soundhw soundhw[];
        !           632: #endif
        !           633: 
1.1       root      634: /* vga.c */
                    635: 
                    636: #define VGA_RAM_SIZE (4096 * 1024)
                    637: 
                    638: struct DisplayState {
                    639:     uint8_t *data;
                    640:     int linesize;
                    641:     int depth;
                    642:     int width;
                    643:     int height;
                    644:     void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
                    645:     void (*dpy_resize)(struct DisplayState *s, int w, int h);
                    646:     void (*dpy_refresh)(struct DisplayState *s);
                    647: };
                    648: 
                    649: static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
                    650: {
                    651:     s->dpy_update(s, x, y, w, h);
                    652: }
                    653: 
                    654: static inline void dpy_resize(DisplayState *s, int w, int h)
                    655: {
                    656:     s->dpy_resize(s, w, h);
                    657: }
                    658: 
                    659: int vga_initialize(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
                    660:                    unsigned long vga_ram_offset, int vga_ram_size,
                    661:                    unsigned long vga_bios_offset, int vga_bios_size);
                    662: void vga_update_display(void);
                    663: void vga_invalidate_display(void);
                    664: void vga_screen_dump(const char *filename);
                    665: 
                    666: /* cirrus_vga.c */
                    667: void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
                    668:                          unsigned long vga_ram_offset, int vga_ram_size);
                    669: void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base, 
                    670:                          unsigned long vga_ram_offset, int vga_ram_size);
                    671: 
                    672: /* sdl.c */
                    673: void sdl_display_init(DisplayState *ds, int full_screen);
                    674: 
                    675: /* cocoa.m */
                    676: void cocoa_display_init(DisplayState *ds, int full_screen);
                    677: 
                    678: /* ide.c */
                    679: #define MAX_DISKS 4
                    680: 
                    681: extern BlockDriverState *bs_table[MAX_DISKS];
                    682: 
                    683: void isa_ide_init(int iobase, int iobase2, int irq,
                    684:                   BlockDriverState *hd0, BlockDriverState *hd1);
                    685: void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
                    686:                          int secondary_ide_enabled);
                    687: void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table);
                    688: int pmac_ide_init (BlockDriverState **hd_table,
                    689:                    SetIRQFunc *set_irq, void *irq_opaque, int irq);
                    690: 
1.1.1.2 ! root      691: /* es1370.c */
        !           692: int es1370_init (PCIBus *bus, AudioState *s);
        !           693: 
1.1       root      694: /* sb16.c */
1.1.1.2 ! root      695: int SB16_init (AudioState *s);
1.1       root      696: 
                    697: /* adlib.c */
1.1.1.2 ! root      698: int Adlib_init (AudioState *s);
1.1       root      699: 
                    700: /* gus.c */
1.1.1.2 ! root      701: int GUS_init (AudioState *s);
1.1       root      702: 
                    703: /* dma.c */
                    704: typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
                    705: int DMA_get_channel_mode (int nchan);
                    706: int DMA_read_memory (int nchan, void *buf, int pos, int size);
                    707: int DMA_write_memory (int nchan, void *buf, int pos, int size);
                    708: void DMA_hold_DREQ (int nchan);
                    709: void DMA_release_DREQ (int nchan);
                    710: void DMA_schedule(int nchan);
                    711: void DMA_run (void);
                    712: void DMA_init (int high_page_enable);
                    713: void DMA_register_channel (int nchan,
                    714:                            DMA_transfer_handler transfer_handler,
                    715:                            void *opaque);
                    716: /* fdc.c */
                    717: #define MAX_FD 2
                    718: extern BlockDriverState *fd_table[MAX_FD];
                    719: 
                    720: typedef struct fdctrl_t fdctrl_t;
                    721: 
                    722: fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, 
                    723:                        uint32_t io_base,
                    724:                        BlockDriverState **fds);
                    725: int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
                    726: 
                    727: /* ne2000.c */
                    728: 
1.1.1.2 ! root      729: void isa_ne2000_init(int base, int irq, NICInfo *nd);
        !           730: void pci_ne2000_init(PCIBus *bus, NICInfo *nd);
1.1       root      731: 
                    732: /* pckbd.c */
                    733: 
                    734: void kbd_init(void);
                    735: 
                    736: /* mc146818rtc.c */
                    737: 
                    738: typedef struct RTCState RTCState;
                    739: 
                    740: RTCState *rtc_init(int base, int irq);
                    741: void rtc_set_memory(RTCState *s, int addr, int val);
                    742: void rtc_set_date(RTCState *s, const struct tm *tm);
                    743: 
                    744: /* serial.c */
                    745: 
                    746: typedef struct SerialState SerialState;
1.1.1.2 ! root      747: SerialState *serial_init(SetIRQFunc *set_irq, void *opaque,
        !           748:                          int base, int irq, CharDriverState *chr);
        !           749: SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque,
        !           750:                              target_ulong base, int it_shift,
        !           751:                              int irq, CharDriverState *chr);
1.1       root      752: 
                    753: /* parallel.c */
                    754: 
                    755: typedef struct ParallelState ParallelState;
                    756: ParallelState *parallel_init(int base, int irq, CharDriverState *chr);
                    757: 
                    758: /* i8259.c */
                    759: 
                    760: typedef struct PicState2 PicState2;
                    761: extern PicState2 *isa_pic;
                    762: void pic_set_irq(int irq, int level);
                    763: void pic_set_irq_new(void *opaque, int irq, int level);
                    764: PicState2 *pic_init(IRQRequestFunc *irq_request, void *irq_request_opaque);
                    765: void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func,
                    766:                           void *alt_irq_opaque);
                    767: int pic_read_irq(PicState2 *s);
                    768: void pic_update_irq(PicState2 *s);
                    769: uint32_t pic_intack_read(PicState2 *s);
                    770: void pic_info(void);
                    771: void irq_info(void);
                    772: 
                    773: /* APIC */
                    774: typedef struct IOAPICState IOAPICState;
                    775: 
                    776: int apic_init(CPUState *env);
                    777: int apic_get_interrupt(CPUState *env);
                    778: IOAPICState *ioapic_init(void);
                    779: void ioapic_set_irq(void *opaque, int vector, int level);
                    780: 
                    781: /* i8254.c */
                    782: 
                    783: #define PIT_FREQ 1193182
                    784: 
                    785: typedef struct PITState PITState;
                    786: 
                    787: PITState *pit_init(int base, int irq);
                    788: void pit_set_gate(PITState *pit, int channel, int val);
                    789: int pit_get_gate(PITState *pit, int channel);
                    790: int pit_get_out(PITState *pit, int channel, int64_t current_time);
                    791: 
                    792: /* pc.c */
                    793: extern QEMUMachine pc_machine;
1.1.1.2 ! root      794: extern QEMUMachine isapc_machine;
        !           795: 
        !           796: void ioport_set_a20(int enable);
        !           797: int ioport_get_a20(void);
1.1       root      798: 
                    799: /* ppc.c */
                    800: extern QEMUMachine prep_machine;
                    801: extern QEMUMachine core99_machine;
                    802: extern QEMUMachine heathrow_machine;
                    803: 
                    804: /* mips_r4k.c */
                    805: extern QEMUMachine mips_machine;
                    806: 
                    807: #ifdef TARGET_PPC
                    808: ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq);
                    809: #endif
                    810: void PREP_debug_write (void *opaque, uint32_t addr, uint32_t val);
                    811: 
                    812: extern CPUWriteMemoryFunc *PPC_io_write[];
                    813: extern CPUReadMemoryFunc *PPC_io_read[];
                    814: void PPC_debug_write (void *opaque, uint32_t addr, uint32_t val);
                    815: 
                    816: /* sun4m.c */
                    817: extern QEMUMachine sun4m_machine;
                    818: uint32_t iommu_translate(uint32_t addr);
1.1.1.2 ! root      819: void pic_set_irq_cpu(int irq, int level, unsigned int cpu);
1.1       root      820: 
                    821: /* iommu.c */
                    822: void *iommu_init(uint32_t addr);
                    823: uint32_t iommu_translate_local(void *opaque, uint32_t addr);
                    824: 
                    825: /* lance.c */
1.1.1.2 ! root      826: void lance_init(NICInfo *nd, int irq, uint32_t leaddr, uint32_t ledaddr);
1.1       root      827: 
                    828: /* tcx.c */
                    829: void *tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
                    830:               unsigned long vram_offset, int vram_size, int width, int height);
                    831: void tcx_update_display(void *opaque);
                    832: void tcx_invalidate_display(void *opaque);
                    833: void tcx_screen_dump(void *opaque, const char *filename);
                    834: 
                    835: /* slavio_intctl.c */
                    836: void *slavio_intctl_init();
1.1.1.2 ! root      837: void slavio_intctl_set_cpu(void *opaque, unsigned int cpu, CPUState *env);
1.1       root      838: void slavio_pic_info(void *opaque);
                    839: void slavio_irq_info(void *opaque);
                    840: void slavio_pic_set_irq(void *opaque, int irq, int level);
1.1.1.2 ! root      841: void slavio_pic_set_irq_cpu(void *opaque, int irq, int level, unsigned int cpu);
1.1       root      842: 
                    843: /* magic-load.c */
                    844: int load_elf(const char *filename, uint8_t *addr);
                    845: int load_aout(const char *filename, uint8_t *addr);
                    846: 
                    847: /* slavio_timer.c */
1.1.1.2 ! root      848: void slavio_timer_init(uint32_t addr, int irq, int mode, unsigned int cpu);
1.1       root      849: 
                    850: /* slavio_serial.c */
                    851: SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDriverState *chr2);
                    852: void slavio_serial_ms_kbd_init(int base, int irq);
                    853: 
                    854: /* slavio_misc.c */
                    855: void *slavio_misc_init(uint32_t base, int irq);
                    856: void slavio_set_power_fail(void *opaque, int power_failing);
                    857: 
                    858: /* esp.c */
                    859: void esp_init(BlockDriverState **bd, int irq, uint32_t espaddr, uint32_t espdaddr);
                    860: 
                    861: /* sun4u.c */
                    862: extern QEMUMachine sun4u_machine;
                    863: 
                    864: /* NVRAM helpers */
                    865: #include "hw/m48t59.h"
                    866: 
                    867: void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value);
                    868: uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr);
                    869: void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value);
                    870: uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr);
                    871: void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr, uint32_t value);
                    872: uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr);
                    873: void NVRAM_set_string (m48t59_t *nvram, uint32_t addr,
                    874:                        const unsigned char *str, uint32_t max);
                    875: int NVRAM_get_string (m48t59_t *nvram, uint8_t *dst, uint16_t addr, int max);
                    876: void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr,
                    877:                     uint32_t start, uint32_t count);
                    878: int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
                    879:                           const unsigned char *arch,
                    880:                           uint32_t RAM_size, int boot_device,
                    881:                           uint32_t kernel_image, uint32_t kernel_size,
                    882:                           const char *cmdline,
                    883:                           uint32_t initrd_image, uint32_t initrd_size,
                    884:                           uint32_t NVRAM_image,
                    885:                           int width, int height, int depth);
                    886: 
                    887: /* adb.c */
                    888: 
                    889: #define MAX_ADB_DEVICES 16
                    890: 
                    891: #define ADB_MAX_OUT_LEN 16
                    892: 
                    893: typedef struct ADBDevice ADBDevice;
                    894: 
                    895: /* buf = NULL means polling */
                    896: typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
                    897:                               const uint8_t *buf, int len);
                    898: typedef int ADBDeviceReset(ADBDevice *d);
                    899: 
                    900: struct ADBDevice {
                    901:     struct ADBBusState *bus;
                    902:     int devaddr;
                    903:     int handler;
                    904:     ADBDeviceRequest *devreq;
                    905:     ADBDeviceReset *devreset;
                    906:     void *opaque;
                    907: };
                    908: 
                    909: typedef struct ADBBusState {
                    910:     ADBDevice devices[MAX_ADB_DEVICES];
                    911:     int nb_devices;
                    912:     int poll_index;
                    913: } ADBBusState;
                    914: 
                    915: int adb_request(ADBBusState *s, uint8_t *buf_out,
                    916:                 const uint8_t *buf, int len);
                    917: int adb_poll(ADBBusState *s, uint8_t *buf_out);
                    918: 
                    919: ADBDevice *adb_register_device(ADBBusState *s, int devaddr, 
                    920:                                ADBDeviceRequest *devreq, 
                    921:                                ADBDeviceReset *devreset, 
                    922:                                void *opaque);
                    923: void adb_kbd_init(ADBBusState *bus);
                    924: void adb_mouse_init(ADBBusState *bus);
                    925: 
                    926: /* cuda.c */
                    927: 
                    928: extern ADBBusState adb_bus;
                    929: int cuda_init(SetIRQFunc *set_irq, void *irq_opaque, int irq);
                    930: 
1.1.1.2 ! root      931: #include "hw/usb.h"
        !           932: 
        !           933: /* usb ports of the VM */
        !           934: 
        !           935: #define MAX_VM_USB_PORTS 8
        !           936: 
        !           937: extern USBPort *vm_usb_ports[MAX_VM_USB_PORTS];
        !           938: extern USBDevice *vm_usb_hub;
        !           939: 
        !           940: void do_usb_add(const char *devname);
        !           941: void do_usb_del(const char *devname);
        !           942: void usb_info(void);
        !           943: 
        !           944: /* integratorcp.c */
        !           945: extern QEMUMachine integratorcp_machine;
        !           946: 
        !           947: /* ps2.c */
        !           948: void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg);
        !           949: void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg);
        !           950: void ps2_write_mouse(void *, int val);
        !           951: void ps2_write_keyboard(void *, int val);
        !           952: uint32_t ps2_read_data(void *);
        !           953: void ps2_queue(void *, int b);
        !           954: 
        !           955: /* smc91c111.c */
        !           956: void smc91c111_init(NICInfo *, uint32_t, void *, int);
        !           957: 
1.1       root      958: #endif /* defined(QEMU_TOOL) */
                    959: 
                    960: /* monitor.c */
                    961: void monitor_init(CharDriverState *hd, int show_banner);
                    962: void term_puts(const char *str);
                    963: void term_vprintf(const char *fmt, va_list ap);
                    964: void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
                    965: void term_flush(void);
                    966: void term_print_help(void);
                    967: void monitor_readline(const char *prompt, int is_password,
                    968:                       char *buf, int buf_size);
                    969: 
                    970: /* readline.c */
                    971: typedef void ReadLineFunc(void *opaque, const char *str);
                    972: 
                    973: extern int completion_index;
                    974: void add_completion(const char *str);
                    975: void readline_handle_byte(int ch);
                    976: void readline_find_completion(const char *cmdline);
                    977: const char *readline_get_history(unsigned int index);
                    978: void readline_start(const char *prompt, int is_password,
                    979:                     ReadLineFunc *readline_func, void *opaque);
                    980: 
                    981: void kqemu_record_dump(void);
                    982: 
                    983: #endif /* VL_H */

unix.superglobalmegacorp.com