ia64/xen-unstable

view tools/ioemu/vl.h @ 10949:4c2fab8f8c34

[qemu] Use xenstore to configure ioemu block devices.
- read ioemu block device config from xenstore
- don't require the ioemu: prefix on block devices any longer
- allow change of media associated with cdrom drives
- replace cdrom= option by :cdrom suffix on regular block device config:
'file:/root/mytest.iso,hdc:cdrom,r'
- don't create default cdrom drive anymore - to create default empty
cdrom drive use: ',hdc:cdrom,r'

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Thu Aug 03 18:28:29 2006 +0100 (2006-08-03)
parents 060025203f54
children 155385a02d0b
line source
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
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 #include "xenctrl.h"
42 #include "xs.h"
44 #ifndef O_LARGEFILE
45 #define O_LARGEFILE 0
46 #endif
47 #ifndef O_BINARY
48 #define O_BINARY 0
49 #endif
51 #ifdef _WIN32
52 #define lseek _lseeki64
53 #define ENOTSUP 4096
54 /* XXX: find 64 bit version */
55 #define ftruncate chsize
57 static inline char *realpath(const char *path, char *resolved_path)
58 {
59 _fullpath(resolved_path, path, _MAX_PATH);
60 return resolved_path;
61 }
62 #endif
64 #ifdef QEMU_TOOL
66 /* we use QEMU_TOOL in the command line tools which do not depend on
67 the target CPU type */
68 #include "config-host.h"
69 #include <setjmp.h>
70 #include "osdep.h"
71 #include "bswap.h"
73 #else
75 #include "cpu.h"
76 #include "gdbstub.h"
78 #endif /* !defined(QEMU_TOOL) */
80 #ifndef glue
81 #define xglue(x, y) x ## y
82 #define glue(x, y) xglue(x, y)
83 #define stringify(s) tostring(s)
84 #define tostring(s) #s
85 #endif
87 #ifndef MIN
88 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
89 #endif
90 #ifndef MAX
91 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
92 #endif
94 /* vl.c */
95 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
97 void hw_error(const char *fmt, ...);
99 extern const char *bios_dir;
101 void pstrcpy(char *buf, int buf_size, const char *str);
102 char *pstrcat(char *buf, int buf_size, const char *s);
103 int strstart(const char *str, const char *val, const char **ptr);
105 extern int vm_running;
107 typedef struct vm_change_state_entry VMChangeStateEntry;
108 typedef void VMChangeStateHandler(void *opaque, int running);
109 typedef void VMStopHandler(void *opaque, int reason);
111 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
112 void *opaque);
113 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
115 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
116 void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
118 void vm_start(void);
119 void vm_stop(int reason);
121 typedef void QEMUResetHandler(void *opaque);
123 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
124 void qemu_system_reset_request(void);
125 void qemu_system_reset(void);
126 void qemu_system_shutdown_request(void);
127 void qemu_system_powerdown_request(void);
128 #if !defined(TARGET_SPARC)
129 // Please implement a power failure function to signal the OS
130 #define qemu_system_powerdown() do{}while(0)
131 #else
132 void qemu_system_powerdown(void);
133 #endif
135 extern int reset_requested;
137 void main_loop_wait(int timeout);
139 int unset_mm_mapping(int xc_handle, uint32_t domid, unsigned long nr_pages,
140 unsigned int address_bits, unsigned long *extent_start);
141 int set_mm_mapping(int xc_handle, uint32_t domid, unsigned long nr_pages,
142 unsigned int address_bits, unsigned long *extent_start);
144 extern void *shared_vram;
146 extern FILE *logfile;
148 extern int xc_handle;
149 extern int domid;
151 extern uint64_t ram_size;
152 extern int bios_size;
153 extern int rtc_utc;
154 extern int cirrus_vga_enabled;
155 extern int graphic_width;
156 extern int graphic_height;
157 extern int graphic_depth;
158 extern const char *keyboard_layout;
159 extern int kqemu_allowed;
160 extern int win2k_install_hack;
161 extern int usb_enabled;
162 extern int smp_cpus;
164 /* XXX: make it dynamic */
165 #if defined (TARGET_PPC)
166 #define BIOS_SIZE ((512 + 32) * 1024)
167 #elif defined(TARGET_MIPS)
168 #define BIOS_SIZE (128 * 1024)
169 #else
170 #define BIOS_SIZE ((256 + 64) * 1024)
171 #endif
173 /* keyboard/mouse support */
175 #define MOUSE_EVENT_LBUTTON 0x01
176 #define MOUSE_EVENT_RBUTTON 0x02
177 #define MOUSE_EVENT_MBUTTON 0x04
179 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
180 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
182 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
183 void qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque, int absolute);
185 void kbd_put_keycode(int keycode);
186 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
187 int kbd_mouse_is_absolute(void);
189 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
190 constants) */
191 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
192 #define QEMU_KEY_BACKSPACE 0x007f
193 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
194 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
195 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
196 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
197 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
198 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
199 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
200 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
201 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
203 #define QEMU_KEY_CTRL_UP 0xe400
204 #define QEMU_KEY_CTRL_DOWN 0xe401
205 #define QEMU_KEY_CTRL_LEFT 0xe402
206 #define QEMU_KEY_CTRL_RIGHT 0xe403
207 #define QEMU_KEY_CTRL_HOME 0xe404
208 #define QEMU_KEY_CTRL_END 0xe405
209 #define QEMU_KEY_CTRL_PAGEUP 0xe406
210 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
212 void kbd_put_keysym(int keysym);
214 /* async I/O support */
216 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
217 typedef int IOCanRWHandler(void *opaque);
218 typedef void IOHandler(void *opaque);
220 int qemu_set_fd_handler2(int fd,
221 IOCanRWHandler *fd_read_poll,
222 IOHandler *fd_read,
223 IOHandler *fd_write,
224 void *opaque);
225 int qemu_set_fd_handler(int fd,
226 IOHandler *fd_read,
227 IOHandler *fd_write,
228 void *opaque);
230 /* Polling handling */
232 /* return TRUE if no sleep should be done afterwards */
233 typedef int PollingFunc(void *opaque);
235 int qemu_add_polling_cb(PollingFunc *func, void *opaque);
236 void qemu_del_polling_cb(PollingFunc *func, void *opaque);
238 /* character device */
240 #define CHR_EVENT_BREAK 0 /* serial break char */
241 #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
245 #define CHR_IOCTL_SERIAL_SET_PARAMS 1
246 typedef struct {
247 int speed;
248 int parity;
249 int data_bits;
250 int stop_bits;
251 } QEMUSerialSetParams;
253 #define CHR_IOCTL_SERIAL_SET_BREAK 2
255 #define CHR_IOCTL_PP_READ_DATA 3
256 #define CHR_IOCTL_PP_WRITE_DATA 4
257 #define CHR_IOCTL_PP_READ_CONTROL 5
258 #define CHR_IOCTL_PP_WRITE_CONTROL 6
259 #define CHR_IOCTL_PP_READ_STATUS 7
261 typedef void IOEventHandler(void *opaque, int event);
263 typedef struct CharDriverState {
264 int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
265 void (*chr_add_read_handler)(struct CharDriverState *s,
266 IOCanRWHandler *fd_can_read,
267 IOReadHandler *fd_read, void *opaque);
268 int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
269 IOEventHandler *chr_event;
270 void (*chr_send_event)(struct CharDriverState *chr, int event);
271 void (*chr_close)(struct CharDriverState *chr);
272 void *opaque;
273 } CharDriverState;
275 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
276 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
277 void qemu_chr_send_event(CharDriverState *s, int event);
278 void qemu_chr_add_read_handler(CharDriverState *s,
279 IOCanRWHandler *fd_can_read,
280 IOReadHandler *fd_read, void *opaque);
281 void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event);
282 int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
284 /* consoles */
286 typedef struct DisplayState DisplayState;
287 typedef struct TextConsole TextConsole;
289 typedef void (*vga_hw_update_ptr)(void *);
290 typedef void (*vga_hw_invalidate_ptr)(void *);
291 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
293 TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
294 vga_hw_invalidate_ptr invalidate,
295 vga_hw_screen_dump_ptr screen_dump,
296 void *opaque);
297 void vga_hw_update(void);
298 void vga_hw_invalidate(void);
299 void vga_hw_screen_dump(const char *filename);
301 int is_graphic_console(void);
302 CharDriverState *text_console_init(DisplayState *ds);
303 void console_select(unsigned int index);
304 void set_color_table(DisplayState *ds);
306 /* serial ports */
308 #define MAX_SERIAL_PORTS 4
310 extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
312 /* parallel ports */
314 #define MAX_PARALLEL_PORTS 3
316 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
318 /* VLANs support */
320 typedef struct VLANClientState VLANClientState;
322 struct VLANClientState {
323 IOReadHandler *fd_read;
324 /* Packets may still be sent if this returns zero. It's used to
325 rate-limit the slirp code. */
326 IOCanRWHandler *fd_can_read;
327 void *opaque;
328 struct VLANClientState *next;
329 struct VLANState *vlan;
330 char info_str[256];
331 };
333 typedef struct VLANState {
334 int id;
335 VLANClientState *first_client;
336 struct VLANState *next;
337 } VLANState;
339 VLANState *qemu_find_vlan(int id);
340 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
341 IOReadHandler *fd_read,
342 IOCanRWHandler *fd_can_read,
343 void *opaque);
344 int qemu_can_send_packet(VLANClientState *vc);
345 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
346 void qemu_handler_true(void *opaque);
348 void do_info_network(void);
350 /* TAP win32 */
351 int tap_win32_init(VLANState *vlan, const char *ifname);
352 void tap_win32_poll(void);
354 /* NIC info */
356 #define MAX_NICS 8
358 typedef struct NICInfo {
359 uint8_t macaddr[6];
360 const char *model;
361 VLANState *vlan;
362 } NICInfo;
364 extern int nb_nics;
365 extern NICInfo nd_table[MAX_NICS];
367 /* timers */
369 typedef struct QEMUClock QEMUClock;
370 typedef struct QEMUTimer QEMUTimer;
371 typedef void QEMUTimerCB(void *opaque);
373 /* The real time clock should be used only for stuff which does not
374 change the virtual machine state, as it is run even if the virtual
375 machine is stopped. The real time clock has a frequency of 1000
376 Hz. */
377 extern QEMUClock *rt_clock;
379 /* The virtual clock is only run during the emulation. It is stopped
380 when the virtual machine is stopped. Virtual timers use a high
381 precision clock, usually cpu cycles (use ticks_per_sec). */
382 extern QEMUClock *vm_clock;
384 int64_t qemu_get_clock(QEMUClock *clock);
386 QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
387 void qemu_free_timer(QEMUTimer *ts);
388 void qemu_del_timer(QEMUTimer *ts);
389 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
390 int qemu_timer_pending(QEMUTimer *ts);
392 extern int64_t ticks_per_sec;
393 extern int pit_min_timer_count;
395 void cpu_enable_ticks(void);
396 void cpu_disable_ticks(void);
398 /* VM Load/Save */
400 typedef FILE QEMUFile;
402 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
403 void qemu_put_byte(QEMUFile *f, int v);
404 void qemu_put_be16(QEMUFile *f, unsigned int v);
405 void qemu_put_be32(QEMUFile *f, unsigned int v);
406 void qemu_put_be64(QEMUFile *f, uint64_t v);
407 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
408 int qemu_get_byte(QEMUFile *f);
409 unsigned int qemu_get_be16(QEMUFile *f);
410 unsigned int qemu_get_be32(QEMUFile *f);
411 uint64_t qemu_get_be64(QEMUFile *f);
413 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
414 {
415 qemu_put_be64(f, *pv);
416 }
418 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
419 {
420 qemu_put_be32(f, *pv);
421 }
423 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
424 {
425 qemu_put_be16(f, *pv);
426 }
428 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
429 {
430 qemu_put_byte(f, *pv);
431 }
433 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
434 {
435 *pv = qemu_get_be64(f);
436 }
438 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
439 {
440 *pv = qemu_get_be32(f);
441 }
443 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
444 {
445 *pv = qemu_get_be16(f);
446 }
448 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
449 {
450 *pv = qemu_get_byte(f);
451 }
453 #if TARGET_LONG_BITS == 64
454 #define qemu_put_betl qemu_put_be64
455 #define qemu_get_betl qemu_get_be64
456 #define qemu_put_betls qemu_put_be64s
457 #define qemu_get_betls qemu_get_be64s
458 #else
459 #define qemu_put_betl qemu_put_be32
460 #define qemu_get_betl qemu_get_be32
461 #define qemu_put_betls qemu_put_be32s
462 #define qemu_get_betls qemu_get_be32s
463 #endif
465 int64_t qemu_ftell(QEMUFile *f);
466 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
468 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
469 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
471 int qemu_loadvm(const char *filename);
472 int qemu_savevm(const char *filename);
473 int register_savevm(const char *idstr,
474 int instance_id,
475 int version_id,
476 SaveStateHandler *save_state,
477 LoadStateHandler *load_state,
478 void *opaque);
479 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
480 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
482 void cpu_save(QEMUFile *f, void *opaque);
483 int cpu_load(QEMUFile *f, void *opaque, int version_id);
485 /* block.c */
486 typedef struct BlockDriverState BlockDriverState;
487 typedef struct BlockDriver BlockDriver;
489 extern BlockDriver bdrv_raw;
490 extern BlockDriver bdrv_cow;
491 extern BlockDriver bdrv_qcow;
492 extern BlockDriver bdrv_vmdk;
493 extern BlockDriver bdrv_cloop;
494 extern BlockDriver bdrv_dmg;
495 extern BlockDriver bdrv_bochs;
496 extern BlockDriver bdrv_vpc;
497 extern BlockDriver bdrv_vvfat;
499 void bdrv_init(void);
500 BlockDriver *bdrv_find_format(const char *format_name);
501 int bdrv_create(BlockDriver *drv,
502 const char *filename, int64_t size_in_sectors,
503 const char *backing_file, int flags);
504 BlockDriverState *bdrv_new(const char *device_name);
505 void bdrv_delete(BlockDriverState *bs);
506 int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
507 int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
508 BlockDriver *drv);
509 void bdrv_close(BlockDriverState *bs);
510 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
511 uint8_t *buf, int nb_sectors);
512 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
513 const uint8_t *buf, int nb_sectors);
514 void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
515 int bdrv_commit(BlockDriverState *bs);
516 void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
518 #define BDRV_TYPE_HD 0
519 #define BDRV_TYPE_CDROM 1
520 #define BDRV_TYPE_FLOPPY 2
521 #define BIOS_ATA_TRANSLATION_AUTO 0
522 #define BIOS_ATA_TRANSLATION_NONE 1
523 #define BIOS_ATA_TRANSLATION_LBA 2
525 void bdrv_set_geometry_hint(BlockDriverState *bs,
526 int cyls, int heads, int secs);
527 void bdrv_set_type_hint(BlockDriverState *bs, int type);
528 void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
529 void bdrv_get_geometry_hint(BlockDriverState *bs,
530 int *pcyls, int *pheads, int *psecs);
531 int bdrv_get_type_hint(BlockDriverState *bs);
532 int bdrv_get_translation_hint(BlockDriverState *bs);
533 int bdrv_is_removable(BlockDriverState *bs);
534 int bdrv_is_read_only(BlockDriverState *bs);
535 int bdrv_is_inserted(BlockDriverState *bs);
536 int bdrv_is_locked(BlockDriverState *bs);
537 void bdrv_set_locked(BlockDriverState *bs, int locked);
538 void bdrv_set_change_cb(BlockDriverState *bs,
539 void (*change_cb)(void *opaque), void *opaque);
540 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
541 void bdrv_info(void);
542 BlockDriverState *bdrv_find(const char *name);
543 void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
544 int bdrv_is_encrypted(BlockDriverState *bs);
545 int bdrv_set_key(BlockDriverState *bs, const char *key);
546 void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
547 void *opaque);
548 const char *bdrv_get_device_name(BlockDriverState *bs);
550 int qcow_get_cluster_size(BlockDriverState *bs);
551 int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num,
552 const uint8_t *buf);
554 #ifndef QEMU_TOOL
556 typedef void QEMUMachineInitFunc(uint64_t ram_size, int vga_ram_size,
557 int boot_device,
558 DisplayState *ds, const char **fd_filename, int snapshot,
559 const char *kernel_filename, const char *kernel_cmdline,
560 const char *initrd_filename, time_t timeoffset);
562 typedef struct QEMUMachine {
563 const char *name;
564 const char *desc;
565 QEMUMachineInitFunc *init;
566 struct QEMUMachine *next;
567 } QEMUMachine;
569 int qemu_register_machine(QEMUMachine *m);
571 typedef void SetIRQFunc(void *opaque, int irq_num, int level);
572 typedef void IRQRequestFunc(void *opaque, int level);
574 /* ISA bus */
576 extern target_phys_addr_t isa_mem_base;
578 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
579 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
581 int register_ioport_read(int start, int length, int size,
582 IOPortReadFunc *func, void *opaque);
583 int register_ioport_write(int start, int length, int size,
584 IOPortWriteFunc *func, void *opaque);
585 void isa_unassign_ioport(int start, int length);
587 /* PCI bus */
589 extern target_phys_addr_t pci_mem_base;
591 typedef struct PCIBus PCIBus;
592 typedef struct PCIDevice PCIDevice;
594 typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
595 uint32_t address, uint32_t data, int len);
596 typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
597 uint32_t address, int len);
598 typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num,
599 uint32_t addr, uint32_t size, int type);
601 #define PCI_ADDRESS_SPACE_MEM 0x00
602 #define PCI_ADDRESS_SPACE_IO 0x01
603 #define PCI_ADDRESS_SPACE_MEM_PREFETCH 0x08
605 typedef struct PCIIORegion {
606 uint32_t addr; /* current PCI mapping address. -1 means not mapped */
607 uint32_t size;
608 uint8_t type;
609 PCIMapIORegionFunc *map_func;
610 } PCIIORegion;
612 #define PCI_ROM_SLOT 6
613 #define PCI_NUM_REGIONS 7
614 struct PCIDevice {
615 /* PCI config space */
616 uint8_t config[256];
618 /* the following fields are read only */
619 PCIBus *bus;
620 int devfn;
621 char name[64];
622 PCIIORegion io_regions[PCI_NUM_REGIONS];
624 /* do not access the following fields */
625 PCIConfigReadFunc *config_read;
626 PCIConfigWriteFunc *config_write;
627 int irq_index;
628 };
630 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
631 int instance_size, int devfn,
632 PCIConfigReadFunc *config_read,
633 PCIConfigWriteFunc *config_write);
635 void pci_register_io_region(PCIDevice *pci_dev, int region_num,
636 uint32_t size, int type,
637 PCIMapIORegionFunc *map_func);
639 void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level);
641 uint32_t pci_default_read_config(PCIDevice *d,
642 uint32_t address, int len);
643 void pci_default_write_config(PCIDevice *d,
644 uint32_t address, uint32_t val, int len);
645 void generic_pci_save(QEMUFile* f, void *opaque);
646 int generic_pci_load(QEMUFile* f, void *opaque, int version_id);
648 extern struct PIIX3State *piix3_state;
650 PCIBus *i440fx_init(void);
651 void piix3_init(PCIBus *bus);
652 void pci_bios_init(void);
653 void pci_info(void);
655 /* temporary: will be moved in platform specific file */
656 void pci_set_pic(PCIBus *bus, SetIRQFunc *set_irq, void *irq_opaque);
657 PCIBus *pci_prep_init(void);
658 PCIBus *pci_grackle_init(uint32_t base);
659 PCIBus *pci_pmac_init(void);
660 PCIBus *pci_apb_init(target_ulong special_base, target_ulong mem_base);
662 void pci_nic_init(PCIBus *bus, NICInfo *nd);
664 /* openpic.c */
665 typedef struct openpic_t openpic_t;
666 void openpic_set_irq(void *opaque, int n_IRQ, int level);
667 openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,
668 CPUState **envp);
670 /* heathrow_pic.c */
671 typedef struct HeathrowPICS HeathrowPICS;
672 void heathrow_pic_set_irq(void *opaque, int num, int level);
673 HeathrowPICS *heathrow_pic_init(int *pmem_index);
675 #ifdef HAS_AUDIO
676 struct soundhw {
677 const char *name;
678 const char *descr;
679 int enabled;
680 int isa;
681 union {
682 int (*init_isa) (AudioState *s);
683 int (*init_pci) (PCIBus *bus, AudioState *s);
684 } init;
685 };
687 extern struct soundhw soundhw[];
688 #endif
690 /* vga.c */
692 #define VGA_RAM_SIZE (4096 * 1024)
694 struct DisplayState {
695 uint8_t *data;
696 int linesize;
697 int depth;
698 int width;
699 int height;
700 void *opaque;
702 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
703 void (*dpy_resize)(struct DisplayState *s, int w, int h);
704 void (*dpy_refresh)(struct DisplayState *s);
705 void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
706 };
708 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
709 {
710 s->dpy_update(s, x, y, w, h);
711 }
713 static inline void dpy_resize(DisplayState *s, int w, int h)
714 {
715 s->dpy_resize(s, w, h);
716 }
718 int vga_initialize(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
719 unsigned long vga_ram_offset, int vga_ram_size,
720 unsigned long vga_bios_offset, int vga_bios_size);
722 /* cirrus_vga.c */
723 void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
724 unsigned long vga_ram_offset, int vga_ram_size);
725 void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
726 unsigned long vga_ram_offset, int vga_ram_size);
728 /* sdl.c */
729 void sdl_display_init(DisplayState *ds, int full_screen);
731 /* cocoa.m */
732 void cocoa_display_init(DisplayState *ds, int full_screen);
734 /* vnc.c */
735 void vnc_display_init(DisplayState *ds, int display);
736 int vnc_start_viewer(int port);
738 /* ide.c */
739 #define MAX_DISKS 4
741 extern BlockDriverState *bs_table[MAX_DISKS];
743 void isa_ide_init(int iobase, int iobase2, int irq,
744 BlockDriverState *hd0, BlockDriverState *hd1);
745 void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
746 int secondary_ide_enabled);
747 void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table);
748 int pmac_ide_init (BlockDriverState **hd_table,
749 SetIRQFunc *set_irq, void *irq_opaque, int irq);
751 /* es1370.c */
752 int es1370_init (PCIBus *bus, AudioState *s);
754 /* sb16.c */
755 int SB16_init (AudioState *s);
757 /* adlib.c */
758 int Adlib_init (AudioState *s);
760 /* gus.c */
761 int GUS_init (AudioState *s);
763 /* dma.c */
764 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
765 int DMA_get_channel_mode (int nchan);
766 int DMA_read_memory (int nchan, void *buf, int pos, int size);
767 int DMA_write_memory (int nchan, void *buf, int pos, int size);
768 void DMA_hold_DREQ (int nchan);
769 void DMA_release_DREQ (int nchan);
770 void DMA_schedule(int nchan);
771 void DMA_run (void);
772 void DMA_init (int high_page_enable);
773 void DMA_register_channel (int nchan,
774 DMA_transfer_handler transfer_handler,
775 void *opaque);
776 /* fdc.c */
777 #define MAX_FD 2
778 extern BlockDriverState *fd_table[MAX_FD];
780 typedef struct fdctrl_t fdctrl_t;
782 fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped,
783 uint32_t io_base,
784 BlockDriverState **fds);
785 int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
787 /* ne2000.c */
789 void isa_ne2000_init(int base, int irq, NICInfo *nd);
790 void pci_ne2000_init(PCIBus *bus, NICInfo *nd);
792 /* rtl8139.c */
794 void pci_rtl8139_init(PCIBus *bus, NICInfo *nd);
796 /* pckbd.c */
798 void kbd_init(void);
800 /* mc146818rtc.c */
802 typedef struct RTCState RTCState;
804 RTCState *rtc_init(int base, int irq);
805 void rtc_set_memory(RTCState *s, int addr, int val);
806 void rtc_set_date(RTCState *s, const struct tm *tm);
808 /* serial.c */
810 typedef struct SerialState SerialState;
811 SerialState *serial_init(SetIRQFunc *set_irq, void *opaque,
812 int base, int irq, CharDriverState *chr);
813 SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque,
814 target_ulong base, int it_shift,
815 int irq, CharDriverState *chr);
817 /* parallel.c */
819 typedef struct ParallelState ParallelState;
820 ParallelState *parallel_init(int base, int irq, CharDriverState *chr);
822 /* i8259.c */
824 typedef struct PicState2 PicState2;
825 extern PicState2 *isa_pic;
826 void pic_set_irq(int irq, int level);
827 void pic_set_irq_new(void *opaque, int irq, int level);
828 PicState2 *pic_init(IRQRequestFunc *irq_request, void *irq_request_opaque);
829 void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func,
830 void *alt_irq_opaque);
831 int pic_read_irq(PicState2 *s);
832 void pic_update_irq(PicState2 *s);
833 uint32_t pic_intack_read(PicState2 *s);
834 void pic_info(void);
835 void irq_info(void);
836 void sp_info(void);
838 /* APIC */
839 typedef struct IOAPICState IOAPICState;
841 int apic_init(CPUState *env);
842 int apic_get_interrupt(CPUState *env);
843 IOAPICState *ioapic_init(void);
844 void ioapic_set_irq(void *opaque, int vector, int level);
846 /* i8254.c */
848 #define PIT_FREQ 1193182
850 typedef struct PITState PITState;
852 PITState *pit_init(int base, int irq);
853 void pit_set_gate(PITState *pit, int channel, int val);
854 int pit_get_gate(PITState *pit, int channel);
855 int pit_get_initial_count(PITState *pit, int channel);
856 int pit_get_mode(PITState *pit, int channel);
857 int pit_get_out(PITState *pit, int channel, int64_t current_time);
859 /* pcspk.c */
860 void pcspk_init(PITState *);
861 int pcspk_audio_init(AudioState *);
863 /* pc.c */
864 extern QEMUMachine pc_machine;
865 extern QEMUMachine isapc_machine;
867 void ioport_set_a20(int enable);
868 int ioport_get_a20(void);
870 /* ppc.c */
871 extern QEMUMachine prep_machine;
872 extern QEMUMachine core99_machine;
873 extern QEMUMachine heathrow_machine;
875 /* mips_r4k.c */
876 extern QEMUMachine mips_machine;
878 /* shix.c */
879 extern QEMUMachine shix_machine;
881 #ifdef TARGET_PPC
882 ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq);
883 #endif
884 void PREP_debug_write (void *opaque, uint32_t addr, uint32_t val);
886 extern CPUWriteMemoryFunc *PPC_io_write[];
887 extern CPUReadMemoryFunc *PPC_io_read[];
888 void PPC_debug_write (void *opaque, uint32_t addr, uint32_t val);
890 /* sun4m.c */
891 extern QEMUMachine sun4m_machine;
892 uint32_t iommu_translate(uint32_t addr);
893 void pic_set_irq_cpu(int irq, int level, unsigned int cpu);
895 /* iommu.c */
896 void *iommu_init(uint32_t addr);
897 uint32_t iommu_translate_local(void *opaque, uint32_t addr);
899 /* lance.c */
900 void lance_init(NICInfo *nd, int irq, uint32_t leaddr, uint32_t ledaddr);
902 /* tcx.c */
903 void tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
904 unsigned long vram_offset, int vram_size, int width, int height);
906 /* slavio_intctl.c */
907 void *slavio_intctl_init(void);
908 void slavio_intctl_set_cpu(void *opaque, unsigned int cpu, CPUState *env);
909 void slavio_pic_info(void *opaque);
910 void slavio_irq_info(void *opaque);
911 void slavio_pic_set_irq(void *opaque, int irq, int level);
912 void slavio_pic_set_irq_cpu(void *opaque, int irq, int level, unsigned int cpu);
914 /* loader.c */
915 int get_image_size(const char *filename);
916 int load_image(const char *filename, uint8_t *addr);
917 int load_elf(const char *filename, int64_t virt_to_phys_addend, uint64_t *pentry);
918 int load_aout(const char *filename, uint8_t *addr);
920 /* slavio_timer.c */
921 void slavio_timer_init(uint32_t addr, int irq, int mode, unsigned int cpu);
923 /* slavio_serial.c */
924 SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDriverState *chr2);
925 void slavio_serial_ms_kbd_init(int base, int irq);
927 /* slavio_misc.c */
928 void *slavio_misc_init(uint32_t base, int irq);
929 void slavio_set_power_fail(void *opaque, int power_failing);
931 /* esp.c */
932 void esp_init(BlockDriverState **bd, int irq, uint32_t espaddr, uint32_t espdaddr);
934 /* sun4u.c */
935 extern QEMUMachine sun4u_machine;
937 /* NVRAM helpers */
938 #include "hw/m48t59.h"
940 void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value);
941 uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr);
942 void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value);
943 uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr);
944 void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr, uint32_t value);
945 uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr);
946 void NVRAM_set_string (m48t59_t *nvram, uint32_t addr,
947 const unsigned char *str, uint32_t max);
948 int NVRAM_get_string (m48t59_t *nvram, uint8_t *dst, uint16_t addr, int max);
949 void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr,
950 uint32_t start, uint32_t count);
951 int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
952 const unsigned char *arch,
953 uint32_t RAM_size, int boot_device,
954 uint32_t kernel_image, uint32_t kernel_size,
955 const char *cmdline,
956 uint32_t initrd_image, uint32_t initrd_size,
957 uint32_t NVRAM_image,
958 int width, int height, int depth);
960 /* adb.c */
962 #define MAX_ADB_DEVICES 16
964 #define ADB_MAX_OUT_LEN 16
966 typedef struct ADBDevice ADBDevice;
968 /* buf = NULL means polling */
969 typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
970 const uint8_t *buf, int len);
971 typedef int ADBDeviceReset(ADBDevice *d);
973 struct ADBDevice {
974 struct ADBBusState *bus;
975 int devaddr;
976 int handler;
977 ADBDeviceRequest *devreq;
978 ADBDeviceReset *devreset;
979 void *opaque;
980 };
982 typedef struct ADBBusState {
983 ADBDevice devices[MAX_ADB_DEVICES];
984 int nb_devices;
985 int poll_index;
986 } ADBBusState;
988 int adb_request(ADBBusState *s, uint8_t *buf_out,
989 const uint8_t *buf, int len);
990 int adb_poll(ADBBusState *s, uint8_t *buf_out);
992 ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
993 ADBDeviceRequest *devreq,
994 ADBDeviceReset *devreset,
995 void *opaque);
996 void adb_kbd_init(ADBBusState *bus);
997 void adb_mouse_init(ADBBusState *bus);
999 /* cuda.c */
1001 extern ADBBusState adb_bus;
1002 int cuda_init(SetIRQFunc *set_irq, void *irq_opaque, int irq);
1004 #include "hw/usb.h"
1006 /* usb ports of the VM */
1008 #define MAX_VM_USB_PORTS 8
1010 extern USBPort *vm_usb_ports[MAX_VM_USB_PORTS];
1011 extern USBDevice *vm_usb_hub;
1013 void do_usb_add(const char *devname);
1014 void do_usb_del(const char *devname);
1015 void usb_info(void);
1017 /* integratorcp.c */
1018 extern QEMUMachine integratorcp926_machine;
1019 extern QEMUMachine integratorcp1026_machine;
1021 /* versatilepb.c */
1022 extern QEMUMachine versatilepb_machine;
1023 extern QEMUMachine versatileab_machine;
1025 /* ps2.c */
1026 void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg);
1027 void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg);
1028 void ps2_write_mouse(void *, int val);
1029 void ps2_write_keyboard(void *, int val);
1030 uint32_t ps2_read_data(void *);
1031 void ps2_queue(void *, int b);
1032 void ps2_keyboard_set_translation(void *opaque, int mode);
1034 /* smc91c111.c */
1035 void smc91c111_init(NICInfo *, uint32_t, void *, int);
1037 /* pl110.c */
1038 void *pl110_init(DisplayState *ds, uint32_t base, void *pic, int irq, int);
1040 /* pl011.c */
1041 void pl011_init(uint32_t base, void *pic, int irq, CharDriverState *chr);
1043 /* pl050.c */
1044 void pl050_init(uint32_t base, void *pic, int irq, int is_mouse);
1046 /* pl080.c */
1047 void *pl080_init(uint32_t base, void *pic, int irq);
1049 /* pl190.c */
1050 void *pl190_init(uint32_t base, void *parent, int irq, int fiq);
1052 /* arm-timer.c */
1053 void sp804_init(uint32_t base, void *pic, int irq);
1054 void icp_pit_init(uint32_t base, void *pic, int irq);
1056 /* arm_boot.c */
1058 void arm_load_kernel(int ram_size, const char *kernel_filename,
1059 const char *kernel_cmdline, const char *initrd_filename,
1060 int board_id);
1062 /* sh7750.c */
1063 struct SH7750State;
1065 struct SH7750State *sh7750_init(CPUState * cpu);
1067 typedef struct {
1068 /* The callback will be triggered if any of the designated lines change */
1069 uint16_t portamask_trigger;
1070 uint16_t portbmask_trigger;
1071 /* Return 0 if no action was taken */
1072 int (*port_change_cb) (uint16_t porta, uint16_t portb,
1073 uint16_t * periph_pdtra,
1074 uint16_t * periph_portdira,
1075 uint16_t * periph_pdtrb,
1076 uint16_t * periph_portdirb);
1077 } sh7750_io_device;
1079 int sh7750_register_io_device(struct SH7750State *s,
1080 sh7750_io_device * device);
1081 /* tc58128.c */
1082 int tc58128_init(struct SH7750State *s, char *zone1, char *zone2);
1084 #endif /* defined(QEMU_TOOL) */
1086 /* monitor.c */
1087 void monitor_init(CharDriverState *hd, int show_banner);
1088 void term_puts(const char *str);
1089 void term_vprintf(const char *fmt, va_list ap);
1090 void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
1091 void term_flush(void);
1092 void term_print_help(void);
1093 void monitor_readline(const char *prompt, int is_password,
1094 char *buf, int buf_size);
1095 void do_eject(int force, const char *filename);
1096 void do_change(const char *device, const char *filename);
1098 /* readline.c */
1099 typedef void ReadLineFunc(void *opaque, const char *str);
1101 extern int completion_index;
1102 void add_completion(const char *str);
1103 void readline_handle_byte(int ch);
1104 void readline_find_completion(const char *cmdline);
1105 const char *readline_get_history(unsigned int index);
1106 void readline_start(const char *prompt, int is_password,
1107 ReadLineFunc *readline_func, void *opaque);
1109 /* xenstore.c */
1110 void xenstore_parse_domain_config(int domid);
1111 int xenstore_fd(void);
1112 void xenstore_process_event(void *opaque);
1113 void xenstore_check_new_media_present(int timeout);
1116 void kqemu_record_dump(void);
1118 extern char domain_name[];
1120 void destroy_hvm_domain(void);
1122 #endif /* VL_H */