Statistics
| Branch: | Revision:

root / vl.h @ 95219897

History | View | Annotate | Download (31 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
#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

    
100
typedef struct vm_change_state_entry VMChangeStateEntry;
101
typedef void VMChangeStateHandler(void *opaque, int running);
102
typedef void VMStopHandler(void *opaque, int reason);
103

    
104
VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
105
                                                     void *opaque);
106
void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
107

    
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;
139
extern int usb_enabled;
140
extern int smp_cpus;
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);
195
typedef void IOHandler(void *opaque);
196

    
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);
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

    
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

    
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);
237
    int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
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);
250
int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
251

    
252
/* consoles */
253

    
254
typedef struct DisplayState DisplayState;
255
typedef struct TextConsole TextConsole;
256

    
257
typedef void (*vga_hw_update_ptr)(void *);
258
typedef void (*vga_hw_invalidate_ptr)(void *);
259
typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
260

    
261
TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
262
                                  vga_hw_invalidate_ptr invalidate,
263
                                  vga_hw_screen_dump_ptr screen_dump,
264
                                  void *opaque);
265
void vga_hw_update(void);
266
void vga_hw_invalidate(void);
267
void vga_hw_screen_dump(const char *filename);
268

    
269
int is_graphic_console(void);
270
CharDriverState *text_console_init(DisplayState *ds);
271
void console_select(unsigned int index);
272

    
273
/* serial ports */
274

    
275
#define MAX_SERIAL_PORTS 4
276

    
277
extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
278

    
279
/* parallel ports */
280

    
281
#define MAX_PARALLEL_PORTS 3
282

    
283
extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
284

    
285
/* VLANs support */
286

    
287
typedef struct VLANClientState VLANClientState;
288

    
289
struct VLANClientState {
290
    IOReadHandler *fd_read;
291
    /* Packets may still be sent if this returns zero.  It's used to
292
       rate-limit the slirp code.  */
293
    IOCanRWHandler *fd_can_read;
294
    void *opaque;
295
    struct VLANClientState *next;
296
    struct VLANState *vlan;
297
    char info_str[256];
298
};
299

    
300
typedef struct VLANState {
301
    int id;
302
    VLANClientState *first_client;
303
    struct VLANState *next;
304
} VLANState;
305

    
306
VLANState *qemu_find_vlan(int id);
307
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
308
                                      IOReadHandler *fd_read,
309
                                      IOCanRWHandler *fd_can_read,
310
                                      void *opaque);
311
int qemu_can_send_packet(VLANClientState *vc);
312
void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
313
void qemu_handler_true(void *opaque);
314

    
315
void do_info_network(void);
316

    
317
/* TAP win32 */
318
int tap_win32_init(VLANState *vlan, const char *ifname);
319
void tap_win32_poll(void);
320

    
321
/* NIC info */
322

    
323
#define MAX_NICS 8
324

    
325
typedef struct NICInfo {
326
    uint8_t macaddr[6];
327
    const char *model;
328
    VLANState *vlan;
329
} NICInfo;
330

    
331
extern int nb_nics;
332
extern NICInfo nd_table[MAX_NICS];
333

    
334
/* timers */
335

    
336
typedef struct QEMUClock QEMUClock;
337
typedef struct QEMUTimer QEMUTimer;
338
typedef void QEMUTimerCB(void *opaque);
339

    
340
/* The real time clock should be used only for stuff which does not
341
   change the virtual machine state, as it is run even if the virtual
342
   machine is stopped. The real time clock has a frequency of 1000
343
   Hz. */
344
extern QEMUClock *rt_clock;
345

    
346
/* The virtual clock is only run during the emulation. It is stopped
347
   when the virtual machine is stopped. Virtual timers use a high
348
   precision clock, usually cpu cycles (use ticks_per_sec). */
349
extern QEMUClock *vm_clock;
350

    
351
int64_t qemu_get_clock(QEMUClock *clock);
352

    
353
QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
354
void qemu_free_timer(QEMUTimer *ts);
355
void qemu_del_timer(QEMUTimer *ts);
356
void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
357
int qemu_timer_pending(QEMUTimer *ts);
358

    
359
extern int64_t ticks_per_sec;
360
extern int pit_min_timer_count;
361

    
362
void cpu_enable_ticks(void);
363
void cpu_disable_ticks(void);
364

    
365
/* VM Load/Save */
366

    
367
typedef FILE QEMUFile;
368

    
369
void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
370
void qemu_put_byte(QEMUFile *f, int v);
371
void qemu_put_be16(QEMUFile *f, unsigned int v);
372
void qemu_put_be32(QEMUFile *f, unsigned int v);
373
void qemu_put_be64(QEMUFile *f, uint64_t v);
374
int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
375
int qemu_get_byte(QEMUFile *f);
376
unsigned int qemu_get_be16(QEMUFile *f);
377
unsigned int qemu_get_be32(QEMUFile *f);
378
uint64_t qemu_get_be64(QEMUFile *f);
379

    
380
static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
381
{
382
    qemu_put_be64(f, *pv);
383
}
384

    
385
static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
386
{
387
    qemu_put_be32(f, *pv);
388
}
389

    
390
static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
391
{
392
    qemu_put_be16(f, *pv);
393
}
394

    
395
static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
396
{
397
    qemu_put_byte(f, *pv);
398
}
399

    
400
static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
401
{
402
    *pv = qemu_get_be64(f);
403
}
404

    
405
static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
406
{
407
    *pv = qemu_get_be32(f);
408
}
409

    
410
static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
411
{
412
    *pv = qemu_get_be16(f);
413
}
414

    
415
static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
416
{
417
    *pv = qemu_get_byte(f);
418
}
419

    
420
#if TARGET_LONG_BITS == 64
421
#define qemu_put_betl qemu_put_be64
422
#define qemu_get_betl qemu_get_be64
423
#define qemu_put_betls qemu_put_be64s
424
#define qemu_get_betls qemu_get_be64s
425
#else
426
#define qemu_put_betl qemu_put_be32
427
#define qemu_get_betl qemu_get_be32
428
#define qemu_put_betls qemu_put_be32s
429
#define qemu_get_betls qemu_get_be32s
430
#endif
431

    
432
int64_t qemu_ftell(QEMUFile *f);
433
int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
434

    
435
typedef void SaveStateHandler(QEMUFile *f, void *opaque);
436
typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
437

    
438
int qemu_loadvm(const char *filename);
439
int qemu_savevm(const char *filename);
440
int register_savevm(const char *idstr, 
441
                    int instance_id, 
442
                    int version_id,
443
                    SaveStateHandler *save_state,
444
                    LoadStateHandler *load_state,
445
                    void *opaque);
446
void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
447
void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
448

    
449
void cpu_save(QEMUFile *f, void *opaque);
450
int cpu_load(QEMUFile *f, void *opaque, int version_id);
451

    
452
/* block.c */
453
typedef struct BlockDriverState BlockDriverState;
454
typedef struct BlockDriver BlockDriver;
455

    
456
extern BlockDriver bdrv_raw;
457
extern BlockDriver bdrv_cow;
458
extern BlockDriver bdrv_qcow;
459
extern BlockDriver bdrv_vmdk;
460
extern BlockDriver bdrv_cloop;
461
extern BlockDriver bdrv_dmg;
462
extern BlockDriver bdrv_bochs;
463
extern BlockDriver bdrv_vpc;
464
extern BlockDriver bdrv_vvfat;
465

    
466
void bdrv_init(void);
467
BlockDriver *bdrv_find_format(const char *format_name);
468
int bdrv_create(BlockDriver *drv, 
469
                const char *filename, int64_t size_in_sectors,
470
                const char *backing_file, int flags);
471
BlockDriverState *bdrv_new(const char *device_name);
472
void bdrv_delete(BlockDriverState *bs);
473
int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
474
int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
475
               BlockDriver *drv);
476
void bdrv_close(BlockDriverState *bs);
477
int bdrv_read(BlockDriverState *bs, int64_t sector_num, 
478
              uint8_t *buf, int nb_sectors);
479
int bdrv_write(BlockDriverState *bs, int64_t sector_num, 
480
               const uint8_t *buf, int nb_sectors);
481
void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
482
int bdrv_commit(BlockDriverState *bs);
483
void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
484

    
485
#define BDRV_TYPE_HD     0
486
#define BDRV_TYPE_CDROM  1
487
#define BDRV_TYPE_FLOPPY 2
488
#define BIOS_ATA_TRANSLATION_AUTO 0
489
#define BIOS_ATA_TRANSLATION_NONE 1
490
#define BIOS_ATA_TRANSLATION_LBA  2
491

    
492
void bdrv_set_geometry_hint(BlockDriverState *bs, 
493
                            int cyls, int heads, int secs);
494
void bdrv_set_type_hint(BlockDriverState *bs, int type);
495
void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
496
void bdrv_get_geometry_hint(BlockDriverState *bs, 
497
                            int *pcyls, int *pheads, int *psecs);
498
int bdrv_get_type_hint(BlockDriverState *bs);
499
int bdrv_get_translation_hint(BlockDriverState *bs);
500
int bdrv_is_removable(BlockDriverState *bs);
501
int bdrv_is_read_only(BlockDriverState *bs);
502
int bdrv_is_inserted(BlockDriverState *bs);
503
int bdrv_is_locked(BlockDriverState *bs);
504
void bdrv_set_locked(BlockDriverState *bs, int locked);
505
void bdrv_set_change_cb(BlockDriverState *bs, 
506
                        void (*change_cb)(void *opaque), void *opaque);
507
void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
508
void bdrv_info(void);
509
BlockDriverState *bdrv_find(const char *name);
510
void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
511
int bdrv_is_encrypted(BlockDriverState *bs);
512
int bdrv_set_key(BlockDriverState *bs, const char *key);
513
void bdrv_iterate_format(void (*it)(void *opaque, const char *name), 
514
                         void *opaque);
515
const char *bdrv_get_device_name(BlockDriverState *bs);
516

    
517
int qcow_get_cluster_size(BlockDriverState *bs);
518
int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num,
519
                          const uint8_t *buf);
520

    
521
#ifndef QEMU_TOOL
522

    
523
typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size, 
524
                                 int boot_device,
525
             DisplayState *ds, const char **fd_filename, int snapshot,
526
             const char *kernel_filename, const char *kernel_cmdline,
527
             const char *initrd_filename);
528

    
529
typedef struct QEMUMachine {
530
    const char *name;
531
    const char *desc;
532
    QEMUMachineInitFunc *init;
533
    struct QEMUMachine *next;
534
} QEMUMachine;
535

    
536
int qemu_register_machine(QEMUMachine *m);
537

    
538
typedef void SetIRQFunc(void *opaque, int irq_num, int level);
539
typedef void IRQRequestFunc(void *opaque, int level);
540

    
541
/* ISA bus */
542

    
543
extern target_phys_addr_t isa_mem_base;
544

    
545
typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
546
typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
547

    
548
int register_ioport_read(int start, int length, int size, 
549
                         IOPortReadFunc *func, void *opaque);
550
int register_ioport_write(int start, int length, int size, 
551
                          IOPortWriteFunc *func, void *opaque);
552
void isa_unassign_ioport(int start, int length);
553

    
554
/* PCI bus */
555

    
556
extern target_phys_addr_t pci_mem_base;
557

    
558
typedef struct PCIBus PCIBus;
559
typedef struct PCIDevice PCIDevice;
560

    
561
typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, 
562
                                uint32_t address, uint32_t data, int len);
563
typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, 
564
                                   uint32_t address, int len);
565
typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, 
566
                                uint32_t addr, uint32_t size, int type);
567

    
568
#define PCI_ADDRESS_SPACE_MEM                0x00
569
#define PCI_ADDRESS_SPACE_IO                0x01
570
#define PCI_ADDRESS_SPACE_MEM_PREFETCH        0x08
571

    
572
typedef struct PCIIORegion {
573
    uint32_t addr; /* current PCI mapping address. -1 means not mapped */
574
    uint32_t size;
575
    uint8_t type;
576
    PCIMapIORegionFunc *map_func;
577
} PCIIORegion;
578

    
579
#define PCI_ROM_SLOT 6
580
#define PCI_NUM_REGIONS 7
581
struct PCIDevice {
582
    /* PCI config space */
583
    uint8_t config[256];
584

    
585
    /* the following fields are read only */
586
    PCIBus *bus;
587
    int devfn;
588
    char name[64];
589
    PCIIORegion io_regions[PCI_NUM_REGIONS];
590
    
591
    /* do not access the following fields */
592
    PCIConfigReadFunc *config_read;
593
    PCIConfigWriteFunc *config_write;
594
    int irq_index;
595
};
596

    
597
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
598
                               int instance_size, int devfn,
599
                               PCIConfigReadFunc *config_read, 
600
                               PCIConfigWriteFunc *config_write);
601

    
602
void pci_register_io_region(PCIDevice *pci_dev, int region_num, 
603
                            uint32_t size, int type, 
604
                            PCIMapIORegionFunc *map_func);
605

    
606
void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level);
607

    
608
uint32_t pci_default_read_config(PCIDevice *d, 
609
                                 uint32_t address, int len);
610
void pci_default_write_config(PCIDevice *d, 
611
                              uint32_t address, uint32_t val, int len);
612
void generic_pci_save(QEMUFile* f, void *opaque);
613
int generic_pci_load(QEMUFile* f, void *opaque, int version_id);
614

    
615
extern struct PIIX3State *piix3_state;
616

    
617
PCIBus *i440fx_init(void);
618
void piix3_init(PCIBus *bus);
619
void pci_bios_init(void);
620
void pci_info(void);
621

    
622
/* temporary: will be moved in platform specific file */
623
void pci_set_pic(PCIBus *bus, SetIRQFunc *set_irq, void *irq_opaque);
624
PCIBus *pci_prep_init(void);
625
PCIBus *pci_grackle_init(uint32_t base);
626
PCIBus *pci_pmac_init(void);
627
PCIBus *pci_apb_init(target_ulong special_base, target_ulong mem_base);
628

    
629
void pci_nic_init(PCIBus *bus, NICInfo *nd);
630

    
631
/* openpic.c */
632
typedef struct openpic_t openpic_t;
633
void openpic_set_irq(void *opaque, int n_IRQ, int level);
634
openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,
635
                         CPUState **envp);
636

    
637
/* heathrow_pic.c */
638
typedef struct HeathrowPICS HeathrowPICS;
639
void heathrow_pic_set_irq(void *opaque, int num, int level);
640
HeathrowPICS *heathrow_pic_init(int *pmem_index);
641

    
642
#ifdef HAS_AUDIO
643
struct soundhw {
644
    const char *name;
645
    const char *descr;
646
    int enabled;
647
    int isa;
648
    union {
649
        int (*init_isa) (AudioState *s);
650
        int (*init_pci) (PCIBus *bus, AudioState *s);
651
    } init;
652
};
653

    
654
extern struct soundhw soundhw[];
655
#endif
656

    
657
/* vga.c */
658

    
659
#define VGA_RAM_SIZE (4096 * 1024)
660

    
661
struct DisplayState {
662
    uint8_t *data;
663
    int linesize;
664
    int depth;
665
    int width;
666
    int height;
667
    void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
668
    void (*dpy_resize)(struct DisplayState *s, int w, int h);
669
    void (*dpy_refresh)(struct DisplayState *s);
670
};
671

    
672
static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
673
{
674
    s->dpy_update(s, x, y, w, h);
675
}
676

    
677
static inline void dpy_resize(DisplayState *s, int w, int h)
678
{
679
    s->dpy_resize(s, w, h);
680
}
681

    
682
int vga_initialize(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
683
                   unsigned long vga_ram_offset, int vga_ram_size,
684
                   unsigned long vga_bios_offset, int vga_bios_size);
685

    
686
/* cirrus_vga.c */
687
void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
688
                         unsigned long vga_ram_offset, int vga_ram_size);
689
void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base, 
690
                         unsigned long vga_ram_offset, int vga_ram_size);
691

    
692
/* sdl.c */
693
void sdl_display_init(DisplayState *ds, int full_screen);
694

    
695
/* cocoa.m */
696
void cocoa_display_init(DisplayState *ds, int full_screen);
697

    
698
/* ide.c */
699
#define MAX_DISKS 4
700

    
701
extern BlockDriverState *bs_table[MAX_DISKS];
702

    
703
void isa_ide_init(int iobase, int iobase2, int irq,
704
                  BlockDriverState *hd0, BlockDriverState *hd1);
705
void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
706
                         int secondary_ide_enabled);
707
void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table);
708
int pmac_ide_init (BlockDriverState **hd_table,
709
                   SetIRQFunc *set_irq, void *irq_opaque, int irq);
710

    
711
/* es1370.c */
712
int es1370_init (PCIBus *bus, AudioState *s);
713

    
714
/* sb16.c */
715
int SB16_init (AudioState *s);
716

    
717
/* adlib.c */
718
int Adlib_init (AudioState *s);
719

    
720
/* gus.c */
721
int GUS_init (AudioState *s);
722

    
723
/* dma.c */
724
typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
725
int DMA_get_channel_mode (int nchan);
726
int DMA_read_memory (int nchan, void *buf, int pos, int size);
727
int DMA_write_memory (int nchan, void *buf, int pos, int size);
728
void DMA_hold_DREQ (int nchan);
729
void DMA_release_DREQ (int nchan);
730
void DMA_schedule(int nchan);
731
void DMA_run (void);
732
void DMA_init (int high_page_enable);
733
void DMA_register_channel (int nchan,
734
                           DMA_transfer_handler transfer_handler,
735
                           void *opaque);
736
/* fdc.c */
737
#define MAX_FD 2
738
extern BlockDriverState *fd_table[MAX_FD];
739

    
740
typedef struct fdctrl_t fdctrl_t;
741

    
742
fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, 
743
                       uint32_t io_base,
744
                       BlockDriverState **fds);
745
int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
746

    
747
/* ne2000.c */
748

    
749
void isa_ne2000_init(int base, int irq, NICInfo *nd);
750
void pci_ne2000_init(PCIBus *bus, NICInfo *nd);
751

    
752
/* rtl8139.c */
753

    
754
void pci_rtl8139_init(PCIBus *bus, NICInfo *nd);
755

    
756
/* pckbd.c */
757

    
758
void kbd_init(void);
759

    
760
/* mc146818rtc.c */
761

    
762
typedef struct RTCState RTCState;
763

    
764
RTCState *rtc_init(int base, int irq);
765
void rtc_set_memory(RTCState *s, int addr, int val);
766
void rtc_set_date(RTCState *s, const struct tm *tm);
767

    
768
/* serial.c */
769

    
770
typedef struct SerialState SerialState;
771
SerialState *serial_init(SetIRQFunc *set_irq, void *opaque,
772
                         int base, int irq, CharDriverState *chr);
773
SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque,
774
                             target_ulong base, int it_shift,
775
                             int irq, CharDriverState *chr);
776

    
777
/* parallel.c */
778

    
779
typedef struct ParallelState ParallelState;
780
ParallelState *parallel_init(int base, int irq, CharDriverState *chr);
781

    
782
/* i8259.c */
783

    
784
typedef struct PicState2 PicState2;
785
extern PicState2 *isa_pic;
786
void pic_set_irq(int irq, int level);
787
void pic_set_irq_new(void *opaque, int irq, int level);
788
PicState2 *pic_init(IRQRequestFunc *irq_request, void *irq_request_opaque);
789
void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func,
790
                          void *alt_irq_opaque);
791
int pic_read_irq(PicState2 *s);
792
void pic_update_irq(PicState2 *s);
793
uint32_t pic_intack_read(PicState2 *s);
794
void pic_info(void);
795
void irq_info(void);
796

    
797
/* APIC */
798
typedef struct IOAPICState IOAPICState;
799

    
800
int apic_init(CPUState *env);
801
int apic_get_interrupt(CPUState *env);
802
IOAPICState *ioapic_init(void);
803
void ioapic_set_irq(void *opaque, int vector, int level);
804

    
805
/* i8254.c */
806

    
807
#define PIT_FREQ 1193182
808

    
809
typedef struct PITState PITState;
810

    
811
PITState *pit_init(int base, int irq);
812
void pit_set_gate(PITState *pit, int channel, int val);
813
int pit_get_gate(PITState *pit, int channel);
814
int pit_get_out(PITState *pit, int channel, int64_t current_time);
815

    
816
/* pc.c */
817
extern QEMUMachine pc_machine;
818
extern QEMUMachine isapc_machine;
819

    
820
void ioport_set_a20(int enable);
821
int ioport_get_a20(void);
822

    
823
/* ppc.c */
824
extern QEMUMachine prep_machine;
825
extern QEMUMachine core99_machine;
826
extern QEMUMachine heathrow_machine;
827

    
828
/* mips_r4k.c */
829
extern QEMUMachine mips_machine;
830

    
831
#ifdef TARGET_PPC
832
ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq);
833
#endif
834
void PREP_debug_write (void *opaque, uint32_t addr, uint32_t val);
835

    
836
extern CPUWriteMemoryFunc *PPC_io_write[];
837
extern CPUReadMemoryFunc *PPC_io_read[];
838
void PPC_debug_write (void *opaque, uint32_t addr, uint32_t val);
839

    
840
/* sun4m.c */
841
extern QEMUMachine sun4m_machine;
842
uint32_t iommu_translate(uint32_t addr);
843
void pic_set_irq_cpu(int irq, int level, unsigned int cpu);
844

    
845
/* iommu.c */
846
void *iommu_init(uint32_t addr);
847
uint32_t iommu_translate_local(void *opaque, uint32_t addr);
848

    
849
/* lance.c */
850
void lance_init(NICInfo *nd, int irq, uint32_t leaddr, uint32_t ledaddr);
851

    
852
/* tcx.c */
853
void tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
854
               unsigned long vram_offset, int vram_size, int width, int height);
855

    
856
/* slavio_intctl.c */
857
void *slavio_intctl_init();
858
void slavio_intctl_set_cpu(void *opaque, unsigned int cpu, CPUState *env);
859
void slavio_pic_info(void *opaque);
860
void slavio_irq_info(void *opaque);
861
void slavio_pic_set_irq(void *opaque, int irq, int level);
862
void slavio_pic_set_irq_cpu(void *opaque, int irq, int level, unsigned int cpu);
863

    
864
/* magic-load.c */
865
int load_elf(const char *filename, uint8_t *addr);
866
int load_aout(const char *filename, uint8_t *addr);
867

    
868
/* slavio_timer.c */
869
void slavio_timer_init(uint32_t addr, int irq, int mode, unsigned int cpu);
870

    
871
/* slavio_serial.c */
872
SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDriverState *chr2);
873
void slavio_serial_ms_kbd_init(int base, int irq);
874

    
875
/* slavio_misc.c */
876
void *slavio_misc_init(uint32_t base, int irq);
877
void slavio_set_power_fail(void *opaque, int power_failing);
878

    
879
/* esp.c */
880
void esp_init(BlockDriverState **bd, int irq, uint32_t espaddr, uint32_t espdaddr);
881

    
882
/* sun4u.c */
883
extern QEMUMachine sun4u_machine;
884

    
885
/* NVRAM helpers */
886
#include "hw/m48t59.h"
887

    
888
void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value);
889
uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr);
890
void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value);
891
uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr);
892
void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr, uint32_t value);
893
uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr);
894
void NVRAM_set_string (m48t59_t *nvram, uint32_t addr,
895
                       const unsigned char *str, uint32_t max);
896
int NVRAM_get_string (m48t59_t *nvram, uint8_t *dst, uint16_t addr, int max);
897
void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr,
898
                    uint32_t start, uint32_t count);
899
int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
900
                          const unsigned char *arch,
901
                          uint32_t RAM_size, int boot_device,
902
                          uint32_t kernel_image, uint32_t kernel_size,
903
                          const char *cmdline,
904
                          uint32_t initrd_image, uint32_t initrd_size,
905
                          uint32_t NVRAM_image,
906
                          int width, int height, int depth);
907

    
908
/* adb.c */
909

    
910
#define MAX_ADB_DEVICES 16
911

    
912
#define ADB_MAX_OUT_LEN 16
913

    
914
typedef struct ADBDevice ADBDevice;
915

    
916
/* buf = NULL means polling */
917
typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
918
                              const uint8_t *buf, int len);
919
typedef int ADBDeviceReset(ADBDevice *d);
920

    
921
struct ADBDevice {
922
    struct ADBBusState *bus;
923
    int devaddr;
924
    int handler;
925
    ADBDeviceRequest *devreq;
926
    ADBDeviceReset *devreset;
927
    void *opaque;
928
};
929

    
930
typedef struct ADBBusState {
931
    ADBDevice devices[MAX_ADB_DEVICES];
932
    int nb_devices;
933
    int poll_index;
934
} ADBBusState;
935

    
936
int adb_request(ADBBusState *s, uint8_t *buf_out,
937
                const uint8_t *buf, int len);
938
int adb_poll(ADBBusState *s, uint8_t *buf_out);
939

    
940
ADBDevice *adb_register_device(ADBBusState *s, int devaddr, 
941
                               ADBDeviceRequest *devreq, 
942
                               ADBDeviceReset *devreset, 
943
                               void *opaque);
944
void adb_kbd_init(ADBBusState *bus);
945
void adb_mouse_init(ADBBusState *bus);
946

    
947
/* cuda.c */
948

    
949
extern ADBBusState adb_bus;
950
int cuda_init(SetIRQFunc *set_irq, void *irq_opaque, int irq);
951

    
952
#include "hw/usb.h"
953

    
954
/* usb ports of the VM */
955

    
956
#define MAX_VM_USB_PORTS 8
957

    
958
extern USBPort *vm_usb_ports[MAX_VM_USB_PORTS];
959
extern USBDevice *vm_usb_hub;
960

    
961
void do_usb_add(const char *devname);
962
void do_usb_del(const char *devname);
963
void usb_info(void);
964

    
965
/* integratorcp.c */
966
extern QEMUMachine integratorcp926_machine;
967
extern QEMUMachine integratorcp1026_machine;
968

    
969
/* ps2.c */
970
void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg);
971
void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg);
972
void ps2_write_mouse(void *, int val);
973
void ps2_write_keyboard(void *, int val);
974
uint32_t ps2_read_data(void *);
975
void ps2_queue(void *, int b);
976
void ps2_keyboard_set_translation(void *opaque, int mode);
977

    
978
/* smc91c111.c */
979
void smc91c111_init(NICInfo *, uint32_t, void *, int);
980

    
981
/* pl110.c */
982
void *pl110_init(DisplayState *ds, uint32_t base, void *pic, int irq, int);
983

    
984
#endif /* defined(QEMU_TOOL) */
985

    
986
/* monitor.c */
987
void monitor_init(CharDriverState *hd, int show_banner);
988
void term_puts(const char *str);
989
void term_vprintf(const char *fmt, va_list ap);
990
void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
991
void term_flush(void);
992
void term_print_help(void);
993
void monitor_readline(const char *prompt, int is_password,
994
                      char *buf, int buf_size);
995

    
996
/* readline.c */
997
typedef void ReadLineFunc(void *opaque, const char *str);
998

    
999
extern int completion_index;
1000
void add_completion(const char *str);
1001
void readline_handle_byte(int ch);
1002
void readline_find_completion(const char *cmdline);
1003
const char *readline_get_history(unsigned int index);
1004
void readline_start(const char *prompt, int is_password,
1005
                    ReadLineFunc *readline_func, void *opaque);
1006

    
1007
void kqemu_record_dump(void);
1008

    
1009
#endif /* VL_H */