Statistics
| Branch: | Revision:

root / vl.h @ e5b0bc44

History | View | Annotate | Download (44.3 kB)

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

    
41
#ifndef O_LARGEFILE
42
#define O_LARGEFILE 0
43
#endif
44
#ifndef O_BINARY
45
#define O_BINARY 0
46
#endif
47

    
48
#ifndef ENOMEDIUM
49
#define ENOMEDIUM ENODEV
50
#endif
51

    
52
#ifdef _WIN32
53
#include <windows.h>
54
#define fsync _commit
55
#define lseek _lseeki64
56
#define ENOTSUP 4096
57
#define ENOMEDIUM 4097
58
extern int qemu_ftruncate64(int, int64_t);
59
#define ftruncate qemu_ftruncate64
60

    
61

    
62
static inline char *realpath(const char *path, char *resolved_path)
63
{
64
    _fullpath(resolved_path, path, _MAX_PATH);
65
    return resolved_path;
66
}
67

    
68
#define PRId64 "I64d"
69
#define PRIx64 "I64x"
70
#define PRIu64 "I64u"
71
#define PRIo64 "I64o"
72
#endif
73

    
74
#ifdef QEMU_TOOL
75

    
76
/* we use QEMU_TOOL in the command line tools which do not depend on
77
   the target CPU type */
78
#include "config-host.h"
79
#include <setjmp.h>
80
#include "osdep.h"
81
#include "bswap.h"
82

    
83
#else
84

    
85
#include "audio/audio.h"
86
#include "cpu.h"
87
#include "gdbstub.h"
88

    
89
#endif /* !defined(QEMU_TOOL) */
90

    
91
#ifndef glue
92
#define xglue(x, y) x ## y
93
#define glue(x, y) xglue(x, y)
94
#define stringify(s)        tostring(s)
95
#define tostring(s)        #s
96
#endif
97

    
98
#ifndef MIN
99
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
100
#endif
101
#ifndef MAX
102
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
103
#endif
104

    
105
/* cutils.c */
106
void pstrcpy(char *buf, int buf_size, const char *str);
107
char *pstrcat(char *buf, int buf_size, const char *s);
108
int strstart(const char *str, const char *val, const char **ptr);
109
int stristart(const char *str, const char *val, const char **ptr);
110

    
111
/* vl.c */
112
uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
113

    
114
void hw_error(const char *fmt, ...);
115

    
116
extern const char *bios_dir;
117

    
118
extern int vm_running;
119

    
120
typedef struct vm_change_state_entry VMChangeStateEntry;
121
typedef void VMChangeStateHandler(void *opaque, int running);
122
typedef void VMStopHandler(void *opaque, int reason);
123

    
124
VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
125
                                                     void *opaque);
126
void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
127

    
128
int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
129
void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
130

    
131
void vm_start(void);
132
void vm_stop(int reason);
133

    
134
typedef void QEMUResetHandler(void *opaque);
135

    
136
void qemu_register_reset(QEMUResetHandler *func, void *opaque);
137
void qemu_system_reset_request(void);
138
void qemu_system_shutdown_request(void);
139
void qemu_system_powerdown_request(void);
140
#if !defined(TARGET_SPARC)
141
// Please implement a power failure function to signal the OS
142
#define qemu_system_powerdown() do{}while(0)
143
#else
144
void qemu_system_powerdown(void);
145
#endif
146

    
147
void main_loop_wait(int timeout);
148

    
149
extern int ram_size;
150
extern int bios_size;
151
extern int rtc_utc;
152
extern int cirrus_vga_enabled;
153
extern int graphic_width;
154
extern int graphic_height;
155
extern int graphic_depth;
156
extern const char *keyboard_layout;
157
extern int kqemu_allowed;
158
extern int win2k_install_hack;
159
extern int usb_enabled;
160
extern int smp_cpus;
161
extern int no_quit;
162
extern int semihosting_enabled;
163
extern int autostart;
164

    
165
#define MAX_OPTION_ROMS 16
166
extern const char *option_rom[MAX_OPTION_ROMS];
167
extern int nb_option_roms;
168

    
169
/* XXX: make it dynamic */
170
#if defined (TARGET_PPC) || defined (TARGET_SPARC64)
171
#define BIOS_SIZE ((512 + 32) * 1024)
172
#elif defined(TARGET_MIPS)
173
#define BIOS_SIZE (4 * 1024 * 1024)
174
#else
175
#define BIOS_SIZE ((256 + 64) * 1024)
176
#endif
177

    
178
/* keyboard/mouse support */
179

    
180
#define MOUSE_EVENT_LBUTTON 0x01
181
#define MOUSE_EVENT_RBUTTON 0x02
182
#define MOUSE_EVENT_MBUTTON 0x04
183

    
184
typedef void QEMUPutKBDEvent(void *opaque, int keycode);
185
typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
186

    
187
typedef struct QEMUPutMouseEntry {
188
    QEMUPutMouseEvent *qemu_put_mouse_event;
189
    void *qemu_put_mouse_event_opaque;
190
    int qemu_put_mouse_event_absolute;
191
    char *qemu_put_mouse_event_name;
192

    
193
    /* used internally by qemu for handling mice */
194
    struct QEMUPutMouseEntry *next;
195
} QEMUPutMouseEntry;
196

    
197
void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
198
QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
199
                                                void *opaque, int absolute,
200
                                                const char *name);
201
void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
202

    
203
void kbd_put_keycode(int keycode);
204
void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
205
int kbd_mouse_is_absolute(void);
206

    
207
void do_info_mice(void);
208
void do_mouse_set(int index);
209

    
210
/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
211
   constants) */
212
#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
213
#define QEMU_KEY_BACKSPACE  0x007f
214
#define QEMU_KEY_UP         QEMU_KEY_ESC1('A')
215
#define QEMU_KEY_DOWN       QEMU_KEY_ESC1('B')
216
#define QEMU_KEY_RIGHT      QEMU_KEY_ESC1('C')
217
#define QEMU_KEY_LEFT       QEMU_KEY_ESC1('D')
218
#define QEMU_KEY_HOME       QEMU_KEY_ESC1(1)
219
#define QEMU_KEY_END        QEMU_KEY_ESC1(4)
220
#define QEMU_KEY_PAGEUP     QEMU_KEY_ESC1(5)
221
#define QEMU_KEY_PAGEDOWN   QEMU_KEY_ESC1(6)
222
#define QEMU_KEY_DELETE     QEMU_KEY_ESC1(3)
223

    
224
#define QEMU_KEY_CTRL_UP         0xe400
225
#define QEMU_KEY_CTRL_DOWN       0xe401
226
#define QEMU_KEY_CTRL_LEFT       0xe402
227
#define QEMU_KEY_CTRL_RIGHT      0xe403
228
#define QEMU_KEY_CTRL_HOME       0xe404
229
#define QEMU_KEY_CTRL_END        0xe405
230
#define QEMU_KEY_CTRL_PAGEUP     0xe406
231
#define QEMU_KEY_CTRL_PAGEDOWN   0xe407
232

    
233
void kbd_put_keysym(int keysym);
234

    
235
/* async I/O support */
236

    
237
typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
238
typedef int IOCanRWHandler(void *opaque);
239
typedef void IOHandler(void *opaque);
240

    
241
int qemu_set_fd_handler2(int fd, 
242
                         IOCanRWHandler *fd_read_poll, 
243
                         IOHandler *fd_read, 
244
                         IOHandler *fd_write, 
245
                         void *opaque);
246
int qemu_set_fd_handler(int fd,
247
                        IOHandler *fd_read, 
248
                        IOHandler *fd_write,
249
                        void *opaque);
250

    
251
/* Polling handling */
252

    
253
/* return TRUE if no sleep should be done afterwards */
254
typedef int PollingFunc(void *opaque);
255

    
256
int qemu_add_polling_cb(PollingFunc *func, void *opaque);
257
void qemu_del_polling_cb(PollingFunc *func, void *opaque);
258

    
259
#ifdef _WIN32
260
/* Wait objects handling */
261
typedef void WaitObjectFunc(void *opaque);
262

    
263
int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
264
void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
265
#endif
266

    
267
typedef struct QEMUBH QEMUBH;
268

    
269
/* character device */
270

    
271
#define CHR_EVENT_BREAK 0 /* serial break char */
272
#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
273
#define CHR_EVENT_RESET 2 /* new connection established */
274

    
275

    
276
#define CHR_IOCTL_SERIAL_SET_PARAMS   1
277
typedef struct {
278
    int speed;
279
    int parity;
280
    int data_bits;
281
    int stop_bits;
282
} QEMUSerialSetParams;
283

    
284
#define CHR_IOCTL_SERIAL_SET_BREAK    2
285

    
286
#define CHR_IOCTL_PP_READ_DATA        3
287
#define CHR_IOCTL_PP_WRITE_DATA       4
288
#define CHR_IOCTL_PP_READ_CONTROL     5
289
#define CHR_IOCTL_PP_WRITE_CONTROL    6
290
#define CHR_IOCTL_PP_READ_STATUS      7
291

    
292
typedef void IOEventHandler(void *opaque, int event);
293

    
294
typedef struct CharDriverState {
295
    int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
296
    void (*chr_update_read_handler)(struct CharDriverState *s);
297
    int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
298
    IOEventHandler *chr_event;
299
    IOCanRWHandler *chr_can_read;
300
    IOReadHandler *chr_read;
301
    void *handler_opaque;
302
    void (*chr_send_event)(struct CharDriverState *chr, int event);
303
    void (*chr_close)(struct CharDriverState *chr);
304
    void *opaque;
305
    QEMUBH *bh;
306
} CharDriverState;
307

    
308
CharDriverState *qemu_chr_open(const char *filename);
309
void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
310
int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
311
void qemu_chr_send_event(CharDriverState *s, int event);
312
void qemu_chr_add_handlers(CharDriverState *s, 
313
                           IOCanRWHandler *fd_can_read, 
314
                           IOReadHandler *fd_read,
315
                           IOEventHandler *fd_event,
316
                           void *opaque);
317
int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
318
void qemu_chr_reset(CharDriverState *s);
319
int qemu_chr_can_read(CharDriverState *s);
320
void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
321

    
322
/* consoles */
323

    
324
typedef struct DisplayState DisplayState;
325
typedef struct TextConsole TextConsole;
326

    
327
typedef void (*vga_hw_update_ptr)(void *);
328
typedef void (*vga_hw_invalidate_ptr)(void *);
329
typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
330

    
331
TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
332
                                  vga_hw_invalidate_ptr invalidate,
333
                                  vga_hw_screen_dump_ptr screen_dump,
334
                                  void *opaque);
335
void vga_hw_update(void);
336
void vga_hw_invalidate(void);
337
void vga_hw_screen_dump(const char *filename);
338

    
339
int is_graphic_console(void);
340
CharDriverState *text_console_init(DisplayState *ds);
341
void console_select(unsigned int index);
342

    
343
/* serial ports */
344

    
345
#define MAX_SERIAL_PORTS 4
346

    
347
extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
348

    
349
/* parallel ports */
350

    
351
#define MAX_PARALLEL_PORTS 3
352

    
353
extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
354

    
355
/* VLANs support */
356

    
357
typedef struct VLANClientState VLANClientState;
358

    
359
struct VLANClientState {
360
    IOReadHandler *fd_read;
361
    /* Packets may still be sent if this returns zero.  It's used to
362
       rate-limit the slirp code.  */
363
    IOCanRWHandler *fd_can_read;
364
    void *opaque;
365
    struct VLANClientState *next;
366
    struct VLANState *vlan;
367
    char info_str[256];
368
};
369

    
370
typedef struct VLANState {
371
    int id;
372
    VLANClientState *first_client;
373
    struct VLANState *next;
374
} VLANState;
375

    
376
VLANState *qemu_find_vlan(int id);
377
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
378
                                      IOReadHandler *fd_read,
379
                                      IOCanRWHandler *fd_can_read,
380
                                      void *opaque);
381
int qemu_can_send_packet(VLANClientState *vc);
382
void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
383
void qemu_handler_true(void *opaque);
384

    
385
void do_info_network(void);
386

    
387
/* TAP win32 */
388
int tap_win32_init(VLANState *vlan, const char *ifname);
389

    
390
/* NIC info */
391

    
392
#define MAX_NICS 8
393

    
394
typedef struct NICInfo {
395
    uint8_t macaddr[6];
396
    const char *model;
397
    VLANState *vlan;
398
} NICInfo;
399

    
400
extern int nb_nics;
401
extern NICInfo nd_table[MAX_NICS];
402

    
403
/* timers */
404

    
405
typedef struct QEMUClock QEMUClock;
406
typedef struct QEMUTimer QEMUTimer;
407
typedef void QEMUTimerCB(void *opaque);
408

    
409
/* The real time clock should be used only for stuff which does not
410
   change the virtual machine state, as it is run even if the virtual
411
   machine is stopped. The real time clock has a frequency of 1000
412
   Hz. */
413
extern QEMUClock *rt_clock;
414

    
415
/* The virtual clock is only run during the emulation. It is stopped
416
   when the virtual machine is stopped. Virtual timers use a high
417
   precision clock, usually cpu cycles (use ticks_per_sec). */
418
extern QEMUClock *vm_clock;
419

    
420
int64_t qemu_get_clock(QEMUClock *clock);
421

    
422
QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
423
void qemu_free_timer(QEMUTimer *ts);
424
void qemu_del_timer(QEMUTimer *ts);
425
void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
426
int qemu_timer_pending(QEMUTimer *ts);
427

    
428
extern int64_t ticks_per_sec;
429
extern int pit_min_timer_count;
430

    
431
int64_t cpu_get_ticks(void);
432
void cpu_enable_ticks(void);
433
void cpu_disable_ticks(void);
434

    
435
/* VM Load/Save */
436

    
437
typedef struct QEMUFile QEMUFile;
438

    
439
QEMUFile *qemu_fopen(const char *filename, const char *mode);
440
void qemu_fflush(QEMUFile *f);
441
void qemu_fclose(QEMUFile *f);
442
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
443
void qemu_put_byte(QEMUFile *f, int v);
444
void qemu_put_be16(QEMUFile *f, unsigned int v);
445
void qemu_put_be32(QEMUFile *f, unsigned int v);
446
void qemu_put_be64(QEMUFile *f, uint64_t v);
447
int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
448
int qemu_get_byte(QEMUFile *f);
449
unsigned int qemu_get_be16(QEMUFile *f);
450
unsigned int qemu_get_be32(QEMUFile *f);
451
uint64_t qemu_get_be64(QEMUFile *f);
452

    
453
static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
454
{
455
    qemu_put_be64(f, *pv);
456
}
457

    
458
static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
459
{
460
    qemu_put_be32(f, *pv);
461
}
462

    
463
static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
464
{
465
    qemu_put_be16(f, *pv);
466
}
467

    
468
static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
469
{
470
    qemu_put_byte(f, *pv);
471
}
472

    
473
static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
474
{
475
    *pv = qemu_get_be64(f);
476
}
477

    
478
static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
479
{
480
    *pv = qemu_get_be32(f);
481
}
482

    
483
static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
484
{
485
    *pv = qemu_get_be16(f);
486
}
487

    
488
static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
489
{
490
    *pv = qemu_get_byte(f);
491
}
492

    
493
#if TARGET_LONG_BITS == 64
494
#define qemu_put_betl qemu_put_be64
495
#define qemu_get_betl qemu_get_be64
496
#define qemu_put_betls qemu_put_be64s
497
#define qemu_get_betls qemu_get_be64s
498
#else
499
#define qemu_put_betl qemu_put_be32
500
#define qemu_get_betl qemu_get_be32
501
#define qemu_put_betls qemu_put_be32s
502
#define qemu_get_betls qemu_get_be32s
503
#endif
504

    
505
int64_t qemu_ftell(QEMUFile *f);
506
int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
507

    
508
typedef void SaveStateHandler(QEMUFile *f, void *opaque);
509
typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
510

    
511
int register_savevm(const char *idstr, 
512
                    int instance_id, 
513
                    int version_id,
514
                    SaveStateHandler *save_state,
515
                    LoadStateHandler *load_state,
516
                    void *opaque);
517
void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
518
void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
519

    
520
void cpu_save(QEMUFile *f, void *opaque);
521
int cpu_load(QEMUFile *f, void *opaque, int version_id);
522

    
523
void do_savevm(const char *name);
524
void do_loadvm(const char *name);
525
void do_delvm(const char *name);
526
void do_info_snapshots(void);
527

    
528
/* bottom halves */
529
typedef void QEMUBHFunc(void *opaque);
530

    
531
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
532
void qemu_bh_schedule(QEMUBH *bh);
533
void qemu_bh_cancel(QEMUBH *bh);
534
void qemu_bh_delete(QEMUBH *bh);
535
int qemu_bh_poll(void);
536

    
537
/* block.c */
538
typedef struct BlockDriverState BlockDriverState;
539
typedef struct BlockDriver BlockDriver;
540

    
541
extern BlockDriver bdrv_raw;
542
extern BlockDriver bdrv_host_device;
543
extern BlockDriver bdrv_cow;
544
extern BlockDriver bdrv_qcow;
545
extern BlockDriver bdrv_vmdk;
546
extern BlockDriver bdrv_cloop;
547
extern BlockDriver bdrv_dmg;
548
extern BlockDriver bdrv_bochs;
549
extern BlockDriver bdrv_vpc;
550
extern BlockDriver bdrv_vvfat;
551
extern BlockDriver bdrv_qcow2;
552

    
553
typedef struct BlockDriverInfo {
554
    /* in bytes, 0 if irrelevant */
555
    int cluster_size; 
556
    /* offset at which the VM state can be saved (0 if not possible) */
557
    int64_t vm_state_offset; 
558
} BlockDriverInfo;
559

    
560
typedef struct QEMUSnapshotInfo {
561
    char id_str[128]; /* unique snapshot id */
562
    /* the following fields are informative. They are not needed for
563
       the consistency of the snapshot */
564
    char name[256]; /* user choosen name */
565
    uint32_t vm_state_size; /* VM state info size */
566
    uint32_t date_sec; /* UTC date of the snapshot */
567
    uint32_t date_nsec;
568
    uint64_t vm_clock_nsec; /* VM clock relative to boot */
569
} QEMUSnapshotInfo;
570

    
571
#define BDRV_O_RDONLY      0x0000
572
#define BDRV_O_RDWR        0x0002
573
#define BDRV_O_ACCESS      0x0003
574
#define BDRV_O_CREAT       0x0004 /* create an empty file */
575
#define BDRV_O_SNAPSHOT    0x0008 /* open the file read only and save writes in a snapshot */
576
#define BDRV_O_FILE        0x0010 /* open as a raw file (do not try to
577
                                     use a disk image format on top of
578
                                     it (default for
579
                                     bdrv_file_open()) */
580

    
581
void bdrv_init(void);
582
BlockDriver *bdrv_find_format(const char *format_name);
583
int bdrv_create(BlockDriver *drv, 
584
                const char *filename, int64_t size_in_sectors,
585
                const char *backing_file, int flags);
586
BlockDriverState *bdrv_new(const char *device_name);
587
void bdrv_delete(BlockDriverState *bs);
588
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
589
int bdrv_open(BlockDriverState *bs, const char *filename, int flags);
590
int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
591
               BlockDriver *drv);
592
void bdrv_close(BlockDriverState *bs);
593
int bdrv_read(BlockDriverState *bs, int64_t sector_num, 
594
              uint8_t *buf, int nb_sectors);
595
int bdrv_write(BlockDriverState *bs, int64_t sector_num, 
596
               const uint8_t *buf, int nb_sectors);
597
int bdrv_pread(BlockDriverState *bs, int64_t offset, 
598
               void *buf, int count);
599
int bdrv_pwrite(BlockDriverState *bs, int64_t offset, 
600
                const void *buf, int count);
601
int bdrv_truncate(BlockDriverState *bs, int64_t offset);
602
int64_t bdrv_getlength(BlockDriverState *bs);
603
void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
604
int bdrv_commit(BlockDriverState *bs);
605
void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
606
/* async block I/O */
607
typedef struct BlockDriverAIOCB BlockDriverAIOCB;
608
typedef void BlockDriverCompletionFunc(void *opaque, int ret);
609

    
610
BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,
611
                                uint8_t *buf, int nb_sectors,
612
                                BlockDriverCompletionFunc *cb, void *opaque);
613
BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
614
                                 const uint8_t *buf, int nb_sectors,
615
                                 BlockDriverCompletionFunc *cb, void *opaque);
616
void bdrv_aio_cancel(BlockDriverAIOCB *acb);
617

    
618
void qemu_aio_init(void);
619
void qemu_aio_poll(void);
620
void qemu_aio_flush(void);
621
void qemu_aio_wait_start(void);
622
void qemu_aio_wait(void);
623
void qemu_aio_wait_end(void);
624

    
625
/* Ensure contents are flushed to disk.  */
626
void bdrv_flush(BlockDriverState *bs);
627

    
628
#define BDRV_TYPE_HD     0
629
#define BDRV_TYPE_CDROM  1
630
#define BDRV_TYPE_FLOPPY 2
631
#define BIOS_ATA_TRANSLATION_AUTO   0
632
#define BIOS_ATA_TRANSLATION_NONE   1
633
#define BIOS_ATA_TRANSLATION_LBA    2
634
#define BIOS_ATA_TRANSLATION_LARGE  3
635
#define BIOS_ATA_TRANSLATION_RECHS  4
636

    
637
void bdrv_set_geometry_hint(BlockDriverState *bs, 
638
                            int cyls, int heads, int secs);
639
void bdrv_set_type_hint(BlockDriverState *bs, int type);
640
void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
641
void bdrv_get_geometry_hint(BlockDriverState *bs, 
642
                            int *pcyls, int *pheads, int *psecs);
643
int bdrv_get_type_hint(BlockDriverState *bs);
644
int bdrv_get_translation_hint(BlockDriverState *bs);
645
int bdrv_is_removable(BlockDriverState *bs);
646
int bdrv_is_read_only(BlockDriverState *bs);
647
int bdrv_is_inserted(BlockDriverState *bs);
648
int bdrv_media_changed(BlockDriverState *bs);
649
int bdrv_is_locked(BlockDriverState *bs);
650
void bdrv_set_locked(BlockDriverState *bs, int locked);
651
void bdrv_eject(BlockDriverState *bs, int eject_flag);
652
void bdrv_set_change_cb(BlockDriverState *bs, 
653
                        void (*change_cb)(void *opaque), void *opaque);
654
void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
655
void bdrv_info(void);
656
BlockDriverState *bdrv_find(const char *name);
657
void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
658
int bdrv_is_encrypted(BlockDriverState *bs);
659
int bdrv_set_key(BlockDriverState *bs, const char *key);
660
void bdrv_iterate_format(void (*it)(void *opaque, const char *name), 
661
                         void *opaque);
662
const char *bdrv_get_device_name(BlockDriverState *bs);
663
int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num, 
664
                          const uint8_t *buf, int nb_sectors);
665
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
666

    
667
void bdrv_get_backing_filename(BlockDriverState *bs, 
668
                               char *filename, int filename_size);
669
int bdrv_snapshot_create(BlockDriverState *bs, 
670
                         QEMUSnapshotInfo *sn_info);
671
int bdrv_snapshot_goto(BlockDriverState *bs, 
672
                       const char *snapshot_id);
673
int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
674
int bdrv_snapshot_list(BlockDriverState *bs, 
675
                       QEMUSnapshotInfo **psn_info);
676
char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
677

    
678
char *get_human_readable_size(char *buf, int buf_size, int64_t size);
679
int path_is_absolute(const char *path);
680
void path_combine(char *dest, int dest_size,
681
                  const char *base_path,
682
                  const char *filename);
683

    
684
#ifndef QEMU_TOOL
685

    
686
typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size, 
687
                                 int boot_device,
688
             DisplayState *ds, const char **fd_filename, int snapshot,
689
             const char *kernel_filename, const char *kernel_cmdline,
690
             const char *initrd_filename);
691

    
692
typedef struct QEMUMachine {
693
    const char *name;
694
    const char *desc;
695
    QEMUMachineInitFunc *init;
696
    struct QEMUMachine *next;
697
} QEMUMachine;
698

    
699
int qemu_register_machine(QEMUMachine *m);
700

    
701
typedef void SetIRQFunc(void *opaque, int irq_num, int level);
702
typedef void IRQRequestFunc(void *opaque, int level);
703

    
704
/* ISA bus */
705

    
706
extern target_phys_addr_t isa_mem_base;
707

    
708
typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
709
typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
710

    
711
int register_ioport_read(int start, int length, int size, 
712
                         IOPortReadFunc *func, void *opaque);
713
int register_ioport_write(int start, int length, int size, 
714
                          IOPortWriteFunc *func, void *opaque);
715
void isa_unassign_ioport(int start, int length);
716

    
717
void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size);
718

    
719
/* PCI bus */
720

    
721
extern target_phys_addr_t pci_mem_base;
722

    
723
typedef struct PCIBus PCIBus;
724
typedef struct PCIDevice PCIDevice;
725

    
726
typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, 
727
                                uint32_t address, uint32_t data, int len);
728
typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, 
729
                                   uint32_t address, int len);
730
typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, 
731
                                uint32_t addr, uint32_t size, int type);
732

    
733
#define PCI_ADDRESS_SPACE_MEM                0x00
734
#define PCI_ADDRESS_SPACE_IO                0x01
735
#define PCI_ADDRESS_SPACE_MEM_PREFETCH        0x08
736

    
737
typedef struct PCIIORegion {
738
    uint32_t addr; /* current PCI mapping address. -1 means not mapped */
739
    uint32_t size;
740
    uint8_t type;
741
    PCIMapIORegionFunc *map_func;
742
} PCIIORegion;
743

    
744
#define PCI_ROM_SLOT 6
745
#define PCI_NUM_REGIONS 7
746

    
747
#define PCI_DEVICES_MAX 64
748

    
749
#define PCI_VENDOR_ID                0x00        /* 16 bits */
750
#define PCI_DEVICE_ID                0x02        /* 16 bits */
751
#define PCI_COMMAND                0x04        /* 16 bits */
752
#define  PCI_COMMAND_IO                0x1        /* Enable response in I/O space */
753
#define  PCI_COMMAND_MEMORY        0x2        /* Enable response in Memory space */
754
#define PCI_CLASS_DEVICE        0x0a    /* Device class */
755
#define PCI_INTERRUPT_LINE        0x3c        /* 8 bits */
756
#define PCI_INTERRUPT_PIN        0x3d        /* 8 bits */
757
#define PCI_MIN_GNT                0x3e        /* 8 bits */
758
#define PCI_MAX_LAT                0x3f        /* 8 bits */
759

    
760
struct PCIDevice {
761
    /* PCI config space */
762
    uint8_t config[256];
763

    
764
    /* the following fields are read only */
765
    PCIBus *bus;
766
    int devfn;
767
    char name[64];
768
    PCIIORegion io_regions[PCI_NUM_REGIONS];
769
    
770
    /* do not access the following fields */
771
    PCIConfigReadFunc *config_read;
772
    PCIConfigWriteFunc *config_write;
773
    /* ??? This is a PC-specific hack, and should be removed.  */
774
    int irq_index;
775

    
776
    /* Current IRQ levels.  Used internally by the generic PCI code.  */
777
    int irq_state[4];
778
};
779

    
780
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
781
                               int instance_size, int devfn,
782
                               PCIConfigReadFunc *config_read, 
783
                               PCIConfigWriteFunc *config_write);
784

    
785
void pci_register_io_region(PCIDevice *pci_dev, int region_num, 
786
                            uint32_t size, int type, 
787
                            PCIMapIORegionFunc *map_func);
788

    
789
void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level);
790

    
791
uint32_t pci_default_read_config(PCIDevice *d, 
792
                                 uint32_t address, int len);
793
void pci_default_write_config(PCIDevice *d, 
794
                              uint32_t address, uint32_t val, int len);
795
void pci_device_save(PCIDevice *s, QEMUFile *f);
796
int pci_device_load(PCIDevice *s, QEMUFile *f);
797

    
798
typedef void (*pci_set_irq_fn)(void *pic, int irq_num, int level);
799
typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
800
PCIBus *pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
801
                         void *pic, int devfn_min, int nirq);
802

    
803
void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn);
804
void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
805
uint32_t pci_data_read(void *opaque, uint32_t addr, int len);
806
int pci_bus_num(PCIBus *s);
807
void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d));
808

    
809
void pci_info(void);
810
PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint32_t id,
811
                        pci_map_irq_fn map_irq, const char *name);
812

    
813
/* prep_pci.c */
814
PCIBus *pci_prep_init(void);
815

    
816
/* grackle_pci.c */
817
PCIBus *pci_grackle_init(uint32_t base, void *pic);
818

    
819
/* unin_pci.c */
820
PCIBus *pci_pmac_init(void *pic);
821

    
822
/* apb_pci.c */
823
PCIBus *pci_apb_init(target_ulong special_base, target_ulong mem_base,
824
                     void *pic);
825

    
826
PCIBus *pci_vpb_init(void *pic, int irq, int realview);
827

    
828
/* piix_pci.c */
829
PCIBus *i440fx_init(PCIDevice **pi440fx_state);
830
void i440fx_set_smm(PCIDevice *d, int val);
831
int piix3_init(PCIBus *bus, int devfn);
832
void i440fx_init_memory_mappings(PCIDevice *d);
833

    
834
int piix4_init(PCIBus *bus, int devfn);
835

    
836
/* openpic.c */
837
typedef struct openpic_t openpic_t;
838
void openpic_set_irq(void *opaque, int n_IRQ, int level);
839
openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,
840
                         CPUState **envp);
841

    
842
/* heathrow_pic.c */
843
typedef struct HeathrowPICS HeathrowPICS;
844
void heathrow_pic_set_irq(void *opaque, int num, int level);
845
HeathrowPICS *heathrow_pic_init(int *pmem_index);
846

    
847
/* gt64xxx.c */
848
PCIBus *pci_gt64120_init(void *pic);
849

    
850
#ifdef HAS_AUDIO
851
struct soundhw {
852
    const char *name;
853
    const char *descr;
854
    int enabled;
855
    int isa;
856
    union {
857
        int (*init_isa) (AudioState *s);
858
        int (*init_pci) (PCIBus *bus, AudioState *s);
859
    } init;
860
};
861

    
862
extern struct soundhw soundhw[];
863
#endif
864

    
865
/* vga.c */
866

    
867
#define VGA_RAM_SIZE (8192 * 1024)
868

    
869
struct DisplayState {
870
    uint8_t *data;
871
    int linesize;
872
    int depth;
873
    int bgr; /* BGR color order instead of RGB. Only valid for depth == 32 */
874
    int width;
875
    int height;
876
    void *opaque;
877

    
878
    void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
879
    void (*dpy_resize)(struct DisplayState *s, int w, int h);
880
    void (*dpy_refresh)(struct DisplayState *s);
881
    void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
882
};
883

    
884
static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
885
{
886
    s->dpy_update(s, x, y, w, h);
887
}
888

    
889
static inline void dpy_resize(DisplayState *s, int w, int h)
890
{
891
    s->dpy_resize(s, w, h);
892
}
893

    
894
int isa_vga_init(DisplayState *ds, uint8_t *vga_ram_base, 
895
                 unsigned long vga_ram_offset, int vga_ram_size);
896
int pci_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
897
                 unsigned long vga_ram_offset, int vga_ram_size,
898
                 unsigned long vga_bios_offset, int vga_bios_size);
899

    
900
/* cirrus_vga.c */
901
void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
902
                         unsigned long vga_ram_offset, int vga_ram_size);
903
void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base, 
904
                         unsigned long vga_ram_offset, int vga_ram_size);
905

    
906
/* sdl.c */
907
void sdl_display_init(DisplayState *ds, int full_screen);
908

    
909
/* cocoa.m */
910
void cocoa_display_init(DisplayState *ds, int full_screen);
911

    
912
/* vnc.c */
913
void vnc_display_init(DisplayState *ds, const char *display);
914

    
915
/* x_keymap.c */
916
extern uint8_t _translate_keycode(const int key);
917

    
918
/* ide.c */
919
#define MAX_DISKS 4
920

    
921
extern BlockDriverState *bs_table[MAX_DISKS + 1];
922

    
923
void isa_ide_init(int iobase, int iobase2, int irq,
924
                  BlockDriverState *hd0, BlockDriverState *hd1);
925
void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
926
                         int secondary_ide_enabled);
927
void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn);
928
int pmac_ide_init (BlockDriverState **hd_table,
929
                   SetIRQFunc *set_irq, void *irq_opaque, int irq);
930

    
931
/* cdrom.c */
932
int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
933
int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
934

    
935
/* es1370.c */
936
int es1370_init (PCIBus *bus, AudioState *s);
937

    
938
/* sb16.c */
939
int SB16_init (AudioState *s);
940

    
941
/* adlib.c */
942
int Adlib_init (AudioState *s);
943

    
944
/* gus.c */
945
int GUS_init (AudioState *s);
946

    
947
/* dma.c */
948
typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
949
int DMA_get_channel_mode (int nchan);
950
int DMA_read_memory (int nchan, void *buf, int pos, int size);
951
int DMA_write_memory (int nchan, void *buf, int pos, int size);
952
void DMA_hold_DREQ (int nchan);
953
void DMA_release_DREQ (int nchan);
954
void DMA_schedule(int nchan);
955
void DMA_run (void);
956
void DMA_init (int high_page_enable);
957
void DMA_register_channel (int nchan,
958
                           DMA_transfer_handler transfer_handler,
959
                           void *opaque);
960
/* fdc.c */
961
#define MAX_FD 2
962
extern BlockDriverState *fd_table[MAX_FD];
963

    
964
typedef struct fdctrl_t fdctrl_t;
965

    
966
fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, 
967
                       uint32_t io_base,
968
                       BlockDriverState **fds);
969
int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
970

    
971
/* ne2000.c */
972

    
973
void isa_ne2000_init(int base, int irq, NICInfo *nd);
974
void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn);
975

    
976
/* rtl8139.c */
977

    
978
void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn);
979

    
980
/* pcnet.c */
981

    
982
void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn);
983
void pcnet_h_reset(void *opaque);
984
void *lance_init(NICInfo *nd, uint32_t leaddr, void *dma_opaque);
985

    
986

    
987
/* pckbd.c */
988

    
989
void kbd_init(void);
990

    
991
/* mc146818rtc.c */
992

    
993
typedef struct RTCState RTCState;
994

    
995
RTCState *rtc_init(int base, int irq);
996
void rtc_set_memory(RTCState *s, int addr, int val);
997
void rtc_set_date(RTCState *s, const struct tm *tm);
998

    
999
/* serial.c */
1000

    
1001
typedef struct SerialState SerialState;
1002
SerialState *serial_init(SetIRQFunc *set_irq, void *opaque,
1003
                         int base, int irq, CharDriverState *chr);
1004
SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque,
1005
                             target_ulong base, int it_shift,
1006
                             int irq, CharDriverState *chr);
1007

    
1008
/* parallel.c */
1009

    
1010
typedef struct ParallelState ParallelState;
1011
ParallelState *parallel_init(int base, int irq, CharDriverState *chr);
1012

    
1013
/* i8259.c */
1014

    
1015
typedef struct PicState2 PicState2;
1016
extern PicState2 *isa_pic;
1017
void pic_set_irq(int irq, int level);
1018
void pic_set_irq_new(void *opaque, int irq, int level);
1019
PicState2 *pic_init(IRQRequestFunc *irq_request, void *irq_request_opaque);
1020
void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func,
1021
                          void *alt_irq_opaque);
1022
int pic_read_irq(PicState2 *s);
1023
void pic_update_irq(PicState2 *s);
1024
uint32_t pic_intack_read(PicState2 *s);
1025
void pic_info(void);
1026
void irq_info(void);
1027

    
1028
/* APIC */
1029
typedef struct IOAPICState IOAPICState;
1030

    
1031
int apic_init(CPUState *env);
1032
int apic_get_interrupt(CPUState *env);
1033
IOAPICState *ioapic_init(void);
1034
void ioapic_set_irq(void *opaque, int vector, int level);
1035

    
1036
/* i8254.c */
1037

    
1038
#define PIT_FREQ 1193182
1039

    
1040
typedef struct PITState PITState;
1041

    
1042
PITState *pit_init(int base, int irq);
1043
void pit_set_gate(PITState *pit, int channel, int val);
1044
int pit_get_gate(PITState *pit, int channel);
1045
int pit_get_initial_count(PITState *pit, int channel);
1046
int pit_get_mode(PITState *pit, int channel);
1047
int pit_get_out(PITState *pit, int channel, int64_t current_time);
1048

    
1049
/* pcspk.c */
1050
void pcspk_init(PITState *);
1051
int pcspk_audio_init(AudioState *);
1052

    
1053
/* acpi.c */
1054
extern int acpi_enabled;
1055
void piix4_pm_init(PCIBus *bus, int devfn);
1056
void acpi_bios_init(void);
1057

    
1058
/* pc.c */
1059
extern QEMUMachine pc_machine;
1060
extern QEMUMachine isapc_machine;
1061
extern int fd_bootchk;
1062

    
1063
void ioport_set_a20(int enable);
1064
int ioport_get_a20(void);
1065

    
1066
/* ppc.c */
1067
extern QEMUMachine prep_machine;
1068
extern QEMUMachine core99_machine;
1069
extern QEMUMachine heathrow_machine;
1070

    
1071
/* mips_r4k.c */
1072
extern QEMUMachine mips_machine;
1073

    
1074
/* mips_malta.c */
1075
extern QEMUMachine mips_malta_machine;
1076

    
1077
/* mips_int */
1078
extern void cpu_mips_irq_request(void *opaque, int irq, int level);
1079

    
1080
/* mips_timer.c */
1081
extern void cpu_mips_clock_init(CPUState *);
1082
extern void cpu_mips_irqctrl_init (void);
1083

    
1084
/* shix.c */
1085
extern QEMUMachine shix_machine;
1086

    
1087
#ifdef TARGET_PPC
1088
ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq);
1089
#endif
1090
void PREP_debug_write (void *opaque, uint32_t addr, uint32_t val);
1091

    
1092
extern CPUWriteMemoryFunc *PPC_io_write[];
1093
extern CPUReadMemoryFunc *PPC_io_read[];
1094
void PPC_debug_write (void *opaque, uint32_t addr, uint32_t val);
1095

    
1096
/* sun4m.c */
1097
extern QEMUMachine sun4m_machine;
1098
void pic_set_irq_cpu(int irq, int level, unsigned int cpu);
1099

    
1100
/* iommu.c */
1101
void *iommu_init(uint32_t addr);
1102
void sparc_iommu_memory_rw(void *opaque, target_phys_addr_t addr,
1103
                                 uint8_t *buf, int len, int is_write);
1104
static inline void sparc_iommu_memory_read(void *opaque,
1105
                                           target_phys_addr_t addr,
1106
                                           uint8_t *buf, int len)
1107
{
1108
    sparc_iommu_memory_rw(opaque, addr, buf, len, 0);
1109
}
1110

    
1111
static inline void sparc_iommu_memory_write(void *opaque,
1112
                                            target_phys_addr_t addr,
1113
                                            uint8_t *buf, int len)
1114
{
1115
    sparc_iommu_memory_rw(opaque, addr, buf, len, 1);
1116
}
1117

    
1118
/* tcx.c */
1119
void tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
1120
               unsigned long vram_offset, int vram_size, int width, int height);
1121

    
1122
/* slavio_intctl.c */
1123
void *slavio_intctl_init();
1124
void slavio_intctl_set_cpu(void *opaque, unsigned int cpu, CPUState *env);
1125
void slavio_pic_info(void *opaque);
1126
void slavio_irq_info(void *opaque);
1127
void slavio_pic_set_irq(void *opaque, int irq, int level);
1128
void slavio_pic_set_irq_cpu(void *opaque, int irq, int level, unsigned int cpu);
1129

    
1130
/* loader.c */
1131
int get_image_size(const char *filename);
1132
int load_image(const char *filename, uint8_t *addr);
1133
int load_elf(const char *filename, int64_t virt_to_phys_addend, uint64_t *pentry);
1134
int load_aout(const char *filename, uint8_t *addr);
1135

    
1136
/* slavio_timer.c */
1137
void slavio_timer_init(uint32_t addr, int irq, int mode, unsigned int cpu);
1138

    
1139
/* slavio_serial.c */
1140
SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDriverState *chr2);
1141
void slavio_serial_ms_kbd_init(int base, int irq);
1142

    
1143
/* slavio_misc.c */
1144
void *slavio_misc_init(uint32_t base, int irq);
1145
void slavio_set_power_fail(void *opaque, int power_failing);
1146

    
1147
/* esp.c */
1148
void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id);
1149
void *esp_init(BlockDriverState **bd, uint32_t espaddr, void *dma_opaque);
1150
void esp_reset(void *opaque);
1151

    
1152
/* sparc32_dma.c */
1153
void *sparc32_dma_init(uint32_t daddr, int espirq, int leirq, void *iommu,
1154
                       void *intctl);
1155
void ledma_set_irq(void *opaque, int isr);
1156
void ledma_memory_read(void *opaque, target_phys_addr_t addr, 
1157
                       uint8_t *buf, int len, int do_bswap);
1158
void ledma_memory_write(void *opaque, target_phys_addr_t addr, 
1159
                        uint8_t *buf, int len, int do_bswap);
1160
void espdma_raise_irq(void *opaque);
1161
void espdma_clear_irq(void *opaque);
1162
void espdma_memory_read(void *opaque, uint8_t *buf, int len);
1163
void espdma_memory_write(void *opaque, uint8_t *buf, int len);
1164
void sparc32_dma_set_reset_data(void *opaque, void *esp_opaque,
1165
                                void *lance_opaque);
1166

    
1167
/* cs4231.c */
1168
void cs_init(target_phys_addr_t base, int irq, void *intctl);
1169

    
1170
/* sun4u.c */
1171
extern QEMUMachine sun4u_machine;
1172

    
1173
/* NVRAM helpers */
1174
#include "hw/m48t59.h"
1175

    
1176
void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value);
1177
uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr);
1178
void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value);
1179
uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr);
1180
void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr, uint32_t value);
1181
uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr);
1182
void NVRAM_set_string (m48t59_t *nvram, uint32_t addr,
1183
                       const unsigned char *str, uint32_t max);
1184
int NVRAM_get_string (m48t59_t *nvram, uint8_t *dst, uint16_t addr, int max);
1185
void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr,
1186
                    uint32_t start, uint32_t count);
1187
int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
1188
                          const unsigned char *arch,
1189
                          uint32_t RAM_size, int boot_device,
1190
                          uint32_t kernel_image, uint32_t kernel_size,
1191
                          const char *cmdline,
1192
                          uint32_t initrd_image, uint32_t initrd_size,
1193
                          uint32_t NVRAM_image,
1194
                          int width, int height, int depth);
1195

    
1196
/* adb.c */
1197

    
1198
#define MAX_ADB_DEVICES 16
1199

    
1200
#define ADB_MAX_OUT_LEN 16
1201

    
1202
typedef struct ADBDevice ADBDevice;
1203

    
1204
/* buf = NULL means polling */
1205
typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
1206
                              const uint8_t *buf, int len);
1207
typedef int ADBDeviceReset(ADBDevice *d);
1208

    
1209
struct ADBDevice {
1210
    struct ADBBusState *bus;
1211
    int devaddr;
1212
    int handler;
1213
    ADBDeviceRequest *devreq;
1214
    ADBDeviceReset *devreset;
1215
    void *opaque;
1216
};
1217

    
1218
typedef struct ADBBusState {
1219
    ADBDevice devices[MAX_ADB_DEVICES];
1220
    int nb_devices;
1221
    int poll_index;
1222
} ADBBusState;
1223

    
1224
int adb_request(ADBBusState *s, uint8_t *buf_out,
1225
                const uint8_t *buf, int len);
1226
int adb_poll(ADBBusState *s, uint8_t *buf_out);
1227

    
1228
ADBDevice *adb_register_device(ADBBusState *s, int devaddr, 
1229
                               ADBDeviceRequest *devreq, 
1230
                               ADBDeviceReset *devreset, 
1231
                               void *opaque);
1232
void adb_kbd_init(ADBBusState *bus);
1233
void adb_mouse_init(ADBBusState *bus);
1234

    
1235
/* cuda.c */
1236

    
1237
extern ADBBusState adb_bus;
1238
int cuda_init(SetIRQFunc *set_irq, void *irq_opaque, int irq);
1239

    
1240
#include "hw/usb.h"
1241

    
1242
/* usb ports of the VM */
1243

    
1244
void qemu_register_usb_port(USBPort *port, void *opaque, int index,
1245
                            usb_attachfn attach);
1246

    
1247
#define VM_USB_HUB_SIZE 8
1248

    
1249
void do_usb_add(const char *devname);
1250
void do_usb_del(const char *devname);
1251
void usb_info(void);
1252

    
1253
/* scsi-disk.c */
1254
enum scsi_reason {
1255
    SCSI_REASON_DONE, /* Command complete.  */
1256
    SCSI_REASON_DATA  /* Transfer complete, more data required.  */
1257
};
1258

    
1259
typedef struct SCSIDevice SCSIDevice;
1260
typedef void (*scsi_completionfn)(void *opaque, int reason, uint32_t tag,
1261
                                  uint32_t arg);
1262

    
1263
SCSIDevice *scsi_disk_init(BlockDriverState *bdrv,
1264
                           int tcq,
1265
                           scsi_completionfn completion,
1266
                           void *opaque);
1267
void scsi_disk_destroy(SCSIDevice *s);
1268

    
1269
int32_t scsi_send_command(SCSIDevice *s, uint32_t tag, uint8_t *buf, int lun);
1270
/* SCSI data transfers are asynchrnonous.  However, unlike the block IO
1271
   layer the completion routine may be called directly by
1272
   scsi_{read,write}_data.  */
1273
void scsi_read_data(SCSIDevice *s, uint32_t tag);
1274
int scsi_write_data(SCSIDevice *s, uint32_t tag);
1275
void scsi_cancel_io(SCSIDevice *s, uint32_t tag);
1276
uint8_t *scsi_get_buf(SCSIDevice *s, uint32_t tag);
1277

    
1278
/* lsi53c895a.c */
1279
void lsi_scsi_attach(void *opaque, BlockDriverState *bd, int id);
1280
void *lsi_scsi_init(PCIBus *bus, int devfn);
1281

    
1282
/* integratorcp.c */
1283
extern QEMUMachine integratorcp926_machine;
1284
extern QEMUMachine integratorcp1026_machine;
1285

    
1286
/* versatilepb.c */
1287
extern QEMUMachine versatilepb_machine;
1288
extern QEMUMachine versatileab_machine;
1289

    
1290
/* realview.c */
1291
extern QEMUMachine realview_machine;
1292

    
1293
/* ps2.c */
1294
void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg);
1295
void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg);
1296
void ps2_write_mouse(void *, int val);
1297
void ps2_write_keyboard(void *, int val);
1298
uint32_t ps2_read_data(void *);
1299
void ps2_queue(void *, int b);
1300
void ps2_keyboard_set_translation(void *opaque, int mode);
1301

    
1302
/* smc91c111.c */
1303
void smc91c111_init(NICInfo *, uint32_t, void *, int);
1304

    
1305
/* pl110.c */
1306
void *pl110_init(DisplayState *ds, uint32_t base, void *pic, int irq, int);
1307

    
1308
/* pl011.c */
1309
void pl011_init(uint32_t base, void *pic, int irq, CharDriverState *chr);
1310

    
1311
/* pl050.c */
1312
void pl050_init(uint32_t base, void *pic, int irq, int is_mouse);
1313

    
1314
/* pl080.c */
1315
void *pl080_init(uint32_t base, void *pic, int irq, int nchannels);
1316

    
1317
/* pl190.c */
1318
void *pl190_init(uint32_t base, void *parent, int irq, int fiq);
1319

    
1320
/* arm-timer.c */
1321
void sp804_init(uint32_t base, void *pic, int irq);
1322
void icp_pit_init(uint32_t base, void *pic, int irq);
1323

    
1324
/* arm_sysctl.c */
1325
void arm_sysctl_init(uint32_t base, uint32_t sys_id);
1326

    
1327
/* arm_gic.c */
1328
void *arm_gic_init(uint32_t base, void *parent, int parent_irq);
1329

    
1330
/* arm_boot.c */
1331

    
1332
void arm_load_kernel(CPUState *env, int ram_size, const char *kernel_filename,
1333
                     const char *kernel_cmdline, const char *initrd_filename,
1334
                     int board_id);
1335

    
1336
/* sh7750.c */
1337
struct SH7750State;
1338

    
1339
struct SH7750State *sh7750_init(CPUState * cpu);
1340

    
1341
typedef struct {
1342
    /* The callback will be triggered if any of the designated lines change */
1343
    uint16_t portamask_trigger;
1344
    uint16_t portbmask_trigger;
1345
    /* Return 0 if no action was taken */
1346
    int (*port_change_cb) (uint16_t porta, uint16_t portb,
1347
                           uint16_t * periph_pdtra,
1348
                           uint16_t * periph_portdira,
1349
                           uint16_t * periph_pdtrb,
1350
                           uint16_t * periph_portdirb);
1351
} sh7750_io_device;
1352

    
1353
int sh7750_register_io_device(struct SH7750State *s,
1354
                              sh7750_io_device * device);
1355
/* tc58128.c */
1356
int tc58128_init(struct SH7750State *s, char *zone1, char *zone2);
1357

    
1358
/* NOR flash devices */
1359
typedef struct pflash_t pflash_t;
1360

    
1361
pflash_t *pflash_register (target_ulong base, ram_addr_t off,
1362
                           BlockDriverState *bs,
1363
                           target_ulong sector_len, int nb_blocs, int width,
1364
                           uint16_t id0, uint16_t id1, 
1365
                           uint16_t id2, uint16_t id3);
1366

    
1367
#endif /* defined(QEMU_TOOL) */
1368

    
1369
/* monitor.c */
1370
void monitor_init(CharDriverState *hd, int show_banner);
1371
void term_puts(const char *str);
1372
void term_vprintf(const char *fmt, va_list ap);
1373
void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
1374
void term_print_filename(const char *filename);
1375
void term_flush(void);
1376
void term_print_help(void);
1377
void monitor_readline(const char *prompt, int is_password,
1378
                      char *buf, int buf_size);
1379

    
1380
/* readline.c */
1381
typedef void ReadLineFunc(void *opaque, const char *str);
1382

    
1383
extern int completion_index;
1384
void add_completion(const char *str);
1385
void readline_handle_byte(int ch);
1386
void readline_find_completion(const char *cmdline);
1387
const char *readline_get_history(unsigned int index);
1388
void readline_start(const char *prompt, int is_password,
1389
                    ReadLineFunc *readline_func, void *opaque);
1390

    
1391
void kqemu_record_dump(void);
1392

    
1393
#endif /* VL_H */