Teach usermode emulation how to lie about uname -r.
[qemu/mini2440.git] / vl.h
blobbdfcfb1d8f51931bc78286290295602df41aca1b
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
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"
42 #ifndef O_LARGEFILE
43 #define O_LARGEFILE 0
44 #endif
45 #ifndef O_BINARY
46 #define O_BINARY 0
47 #endif
49 #ifdef _WIN32
50 #define lseek _lseeki64
51 #define ENOTSUP 4096
52 /* XXX: find 64 bit version */
53 #define ftruncate chsize
55 static inline char *realpath(const char *path, char *resolved_path)
57 _fullpath(resolved_path, path, _MAX_PATH);
58 return resolved_path;
60 #endif
62 #ifdef QEMU_TOOL
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"
71 #else
73 #include "cpu.h"
74 #include "gdbstub.h"
76 #endif /* !defined(QEMU_TOOL) */
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
85 #ifndef MIN
86 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
87 #endif
88 #ifndef MAX
89 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
90 #endif
92 /* vl.c */
93 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
95 void hw_error(const char *fmt, ...);
97 extern const char *bios_dir;
99 void pstrcpy(char *buf, int buf_size, const char *str);
100 char *pstrcat(char *buf, int buf_size, const char *s);
101 int strstart(const char *str, const char *val, const char **ptr);
103 extern int vm_running;
105 typedef struct vm_change_state_entry VMChangeStateEntry;
106 typedef void VMChangeStateHandler(void *opaque, int running);
107 typedef void VMStopHandler(void *opaque, int reason);
109 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
110 void *opaque);
111 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
113 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
114 void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
116 void vm_start(void);
117 void vm_stop(int reason);
119 typedef void QEMUResetHandler(void *opaque);
121 void qemu_register_reset(QEMUResetHandler *func, void *opaque);
122 void qemu_system_reset_request(void);
123 void qemu_system_shutdown_request(void);
124 void qemu_system_powerdown_request(void);
125 #if !defined(TARGET_SPARC)
126 // Please implement a power failure function to signal the OS
127 #define qemu_system_powerdown() do{}while(0)
128 #else
129 void qemu_system_powerdown(void);
130 #endif
132 void main_loop_wait(int timeout);
134 extern int ram_size;
135 extern int bios_size;
136 extern int rtc_utc;
137 extern int cirrus_vga_enabled;
138 extern int graphic_width;
139 extern int graphic_height;
140 extern int graphic_depth;
141 extern const char *keyboard_layout;
142 extern int kqemu_allowed;
143 extern int win2k_install_hack;
144 extern int usb_enabled;
145 extern int smp_cpus;
147 /* XXX: make it dynamic */
148 #if defined (TARGET_PPC)
149 #define BIOS_SIZE ((512 + 32) * 1024)
150 #elif defined(TARGET_MIPS)
151 #define BIOS_SIZE (128 * 1024)
152 #else
153 #define BIOS_SIZE ((256 + 64) * 1024)
154 #endif
156 /* keyboard/mouse support */
158 #define MOUSE_EVENT_LBUTTON 0x01
159 #define MOUSE_EVENT_RBUTTON 0x02
160 #define MOUSE_EVENT_MBUTTON 0x04
162 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
163 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
165 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
166 void qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque, int absolute);
168 void kbd_put_keycode(int keycode);
169 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
170 int kbd_mouse_is_absolute(void);
172 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
173 constants) */
174 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
175 #define QEMU_KEY_BACKSPACE 0x007f
176 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
177 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
178 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
179 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
180 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
181 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
182 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
183 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
184 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
186 #define QEMU_KEY_CTRL_UP 0xe400
187 #define QEMU_KEY_CTRL_DOWN 0xe401
188 #define QEMU_KEY_CTRL_LEFT 0xe402
189 #define QEMU_KEY_CTRL_RIGHT 0xe403
190 #define QEMU_KEY_CTRL_HOME 0xe404
191 #define QEMU_KEY_CTRL_END 0xe405
192 #define QEMU_KEY_CTRL_PAGEUP 0xe406
193 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
195 void kbd_put_keysym(int keysym);
197 /* async I/O support */
199 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
200 typedef int IOCanRWHandler(void *opaque);
201 typedef void IOHandler(void *opaque);
203 int qemu_set_fd_handler2(int fd,
204 IOCanRWHandler *fd_read_poll,
205 IOHandler *fd_read,
206 IOHandler *fd_write,
207 void *opaque);
208 int qemu_set_fd_handler(int fd,
209 IOHandler *fd_read,
210 IOHandler *fd_write,
211 void *opaque);
213 /* Polling handling */
215 /* return TRUE if no sleep should be done afterwards */
216 typedef int PollingFunc(void *opaque);
218 int qemu_add_polling_cb(PollingFunc *func, void *opaque);
219 void qemu_del_polling_cb(PollingFunc *func, void *opaque);
221 /* character device */
223 #define CHR_EVENT_BREAK 0 /* serial break char */
224 #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
228 #define CHR_IOCTL_SERIAL_SET_PARAMS 1
229 typedef struct {
230 int speed;
231 int parity;
232 int data_bits;
233 int stop_bits;
234 } QEMUSerialSetParams;
236 #define CHR_IOCTL_SERIAL_SET_BREAK 2
238 #define CHR_IOCTL_PP_READ_DATA 3
239 #define CHR_IOCTL_PP_WRITE_DATA 4
240 #define CHR_IOCTL_PP_READ_CONTROL 5
241 #define CHR_IOCTL_PP_WRITE_CONTROL 6
242 #define CHR_IOCTL_PP_READ_STATUS 7
244 typedef void IOEventHandler(void *opaque, int event);
246 typedef struct CharDriverState {
247 int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
248 void (*chr_add_read_handler)(struct CharDriverState *s,
249 IOCanRWHandler *fd_can_read,
250 IOReadHandler *fd_read, void *opaque);
251 int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
252 IOEventHandler *chr_event;
253 void (*chr_send_event)(struct CharDriverState *chr, int event);
254 void (*chr_close)(struct CharDriverState *chr);
255 void *opaque;
256 } CharDriverState;
258 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
259 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
260 void qemu_chr_send_event(CharDriverState *s, int event);
261 void qemu_chr_add_read_handler(CharDriverState *s,
262 IOCanRWHandler *fd_can_read,
263 IOReadHandler *fd_read, void *opaque);
264 void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event);
265 int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
267 /* consoles */
269 typedef struct DisplayState DisplayState;
270 typedef struct TextConsole TextConsole;
272 typedef void (*vga_hw_update_ptr)(void *);
273 typedef void (*vga_hw_invalidate_ptr)(void *);
274 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
276 TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
277 vga_hw_invalidate_ptr invalidate,
278 vga_hw_screen_dump_ptr screen_dump,
279 void *opaque);
280 void vga_hw_update(void);
281 void vga_hw_invalidate(void);
282 void vga_hw_screen_dump(const char *filename);
284 int is_graphic_console(void);
285 CharDriverState *text_console_init(DisplayState *ds);
286 void console_select(unsigned int index);
288 /* serial ports */
290 #define MAX_SERIAL_PORTS 4
292 extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
294 /* parallel ports */
296 #define MAX_PARALLEL_PORTS 3
298 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
300 /* VLANs support */
302 typedef struct VLANClientState VLANClientState;
304 struct VLANClientState {
305 IOReadHandler *fd_read;
306 /* Packets may still be sent if this returns zero. It's used to
307 rate-limit the slirp code. */
308 IOCanRWHandler *fd_can_read;
309 void *opaque;
310 struct VLANClientState *next;
311 struct VLANState *vlan;
312 char info_str[256];
315 typedef struct VLANState {
316 int id;
317 VLANClientState *first_client;
318 struct VLANState *next;
319 } VLANState;
321 VLANState *qemu_find_vlan(int id);
322 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
323 IOReadHandler *fd_read,
324 IOCanRWHandler *fd_can_read,
325 void *opaque);
326 int qemu_can_send_packet(VLANClientState *vc);
327 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
328 void qemu_handler_true(void *opaque);
330 void do_info_network(void);
332 /* TAP win32 */
333 int tap_win32_init(VLANState *vlan, const char *ifname);
334 void tap_win32_poll(void);
336 /* NIC info */
338 #define MAX_NICS 8
340 typedef struct NICInfo {
341 uint8_t macaddr[6];
342 const char *model;
343 VLANState *vlan;
344 } NICInfo;
346 extern int nb_nics;
347 extern NICInfo nd_table[MAX_NICS];
349 /* timers */
351 typedef struct QEMUClock QEMUClock;
352 typedef struct QEMUTimer QEMUTimer;
353 typedef void QEMUTimerCB(void *opaque);
355 /* The real time clock should be used only for stuff which does not
356 change the virtual machine state, as it is run even if the virtual
357 machine is stopped. The real time clock has a frequency of 1000
358 Hz. */
359 extern QEMUClock *rt_clock;
361 /* The virtual clock is only run during the emulation. It is stopped
362 when the virtual machine is stopped. Virtual timers use a high
363 precision clock, usually cpu cycles (use ticks_per_sec). */
364 extern QEMUClock *vm_clock;
366 int64_t qemu_get_clock(QEMUClock *clock);
368 QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque);
369 void qemu_free_timer(QEMUTimer *ts);
370 void qemu_del_timer(QEMUTimer *ts);
371 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
372 int qemu_timer_pending(QEMUTimer *ts);
374 extern int64_t ticks_per_sec;
375 extern int pit_min_timer_count;
377 void cpu_enable_ticks(void);
378 void cpu_disable_ticks(void);
380 /* VM Load/Save */
382 typedef FILE QEMUFile;
384 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
385 void qemu_put_byte(QEMUFile *f, int v);
386 void qemu_put_be16(QEMUFile *f, unsigned int v);
387 void qemu_put_be32(QEMUFile *f, unsigned int v);
388 void qemu_put_be64(QEMUFile *f, uint64_t v);
389 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
390 int qemu_get_byte(QEMUFile *f);
391 unsigned int qemu_get_be16(QEMUFile *f);
392 unsigned int qemu_get_be32(QEMUFile *f);
393 uint64_t qemu_get_be64(QEMUFile *f);
395 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
397 qemu_put_be64(f, *pv);
400 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
402 qemu_put_be32(f, *pv);
405 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
407 qemu_put_be16(f, *pv);
410 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
412 qemu_put_byte(f, *pv);
415 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
417 *pv = qemu_get_be64(f);
420 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
422 *pv = qemu_get_be32(f);
425 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
427 *pv = qemu_get_be16(f);
430 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
432 *pv = qemu_get_byte(f);
435 #if TARGET_LONG_BITS == 64
436 #define qemu_put_betl qemu_put_be64
437 #define qemu_get_betl qemu_get_be64
438 #define qemu_put_betls qemu_put_be64s
439 #define qemu_get_betls qemu_get_be64s
440 #else
441 #define qemu_put_betl qemu_put_be32
442 #define qemu_get_betl qemu_get_be32
443 #define qemu_put_betls qemu_put_be32s
444 #define qemu_get_betls qemu_get_be32s
445 #endif
447 int64_t qemu_ftell(QEMUFile *f);
448 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
450 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
451 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
453 int qemu_loadvm(const char *filename);
454 int qemu_savevm(const char *filename);
455 int register_savevm(const char *idstr,
456 int instance_id,
457 int version_id,
458 SaveStateHandler *save_state,
459 LoadStateHandler *load_state,
460 void *opaque);
461 void qemu_get_timer(QEMUFile *f, QEMUTimer *ts);
462 void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
464 void cpu_save(QEMUFile *f, void *opaque);
465 int cpu_load(QEMUFile *f, void *opaque, int version_id);
467 /* block.c */
468 typedef struct BlockDriverState BlockDriverState;
469 typedef struct BlockDriver BlockDriver;
471 extern BlockDriver bdrv_raw;
472 extern BlockDriver bdrv_cow;
473 extern BlockDriver bdrv_qcow;
474 extern BlockDriver bdrv_vmdk;
475 extern BlockDriver bdrv_cloop;
476 extern BlockDriver bdrv_dmg;
477 extern BlockDriver bdrv_bochs;
478 extern BlockDriver bdrv_vpc;
479 extern BlockDriver bdrv_vvfat;
481 void bdrv_init(void);
482 BlockDriver *bdrv_find_format(const char *format_name);
483 int bdrv_create(BlockDriver *drv,
484 const char *filename, int64_t size_in_sectors,
485 const char *backing_file, int flags);
486 BlockDriverState *bdrv_new(const char *device_name);
487 void bdrv_delete(BlockDriverState *bs);
488 int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot);
489 int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
490 BlockDriver *drv);
491 void bdrv_close(BlockDriverState *bs);
492 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
493 uint8_t *buf, int nb_sectors);
494 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
495 const uint8_t *buf, int nb_sectors);
496 void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr);
497 int bdrv_commit(BlockDriverState *bs);
498 void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size);
500 #define BDRV_TYPE_HD 0
501 #define BDRV_TYPE_CDROM 1
502 #define BDRV_TYPE_FLOPPY 2
503 #define BIOS_ATA_TRANSLATION_AUTO 0
504 #define BIOS_ATA_TRANSLATION_NONE 1
505 #define BIOS_ATA_TRANSLATION_LBA 2
507 void bdrv_set_geometry_hint(BlockDriverState *bs,
508 int cyls, int heads, int secs);
509 void bdrv_set_type_hint(BlockDriverState *bs, int type);
510 void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
511 void bdrv_get_geometry_hint(BlockDriverState *bs,
512 int *pcyls, int *pheads, int *psecs);
513 int bdrv_get_type_hint(BlockDriverState *bs);
514 int bdrv_get_translation_hint(BlockDriverState *bs);
515 int bdrv_is_removable(BlockDriverState *bs);
516 int bdrv_is_read_only(BlockDriverState *bs);
517 int bdrv_is_inserted(BlockDriverState *bs);
518 int bdrv_is_locked(BlockDriverState *bs);
519 void bdrv_set_locked(BlockDriverState *bs, int locked);
520 void bdrv_set_change_cb(BlockDriverState *bs,
521 void (*change_cb)(void *opaque), void *opaque);
522 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
523 void bdrv_info(void);
524 BlockDriverState *bdrv_find(const char *name);
525 void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
526 int bdrv_is_encrypted(BlockDriverState *bs);
527 int bdrv_set_key(BlockDriverState *bs, const char *key);
528 void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
529 void *opaque);
530 const char *bdrv_get_device_name(BlockDriverState *bs);
532 int qcow_get_cluster_size(BlockDriverState *bs);
533 int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num,
534 const uint8_t *buf);
536 #ifndef QEMU_TOOL
538 typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size,
539 int boot_device,
540 DisplayState *ds, const char **fd_filename, int snapshot,
541 const char *kernel_filename, const char *kernel_cmdline,
542 const char *initrd_filename);
544 typedef struct QEMUMachine {
545 const char *name;
546 const char *desc;
547 QEMUMachineInitFunc *init;
548 struct QEMUMachine *next;
549 } QEMUMachine;
551 int qemu_register_machine(QEMUMachine *m);
553 typedef void SetIRQFunc(void *opaque, int irq_num, int level);
554 typedef void IRQRequestFunc(void *opaque, int level);
556 /* ISA bus */
558 extern target_phys_addr_t isa_mem_base;
560 typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data);
561 typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address);
563 int register_ioport_read(int start, int length, int size,
564 IOPortReadFunc *func, void *opaque);
565 int register_ioport_write(int start, int length, int size,
566 IOPortWriteFunc *func, void *opaque);
567 void isa_unassign_ioport(int start, int length);
569 /* PCI bus */
571 extern target_phys_addr_t pci_mem_base;
573 typedef struct PCIBus PCIBus;
574 typedef struct PCIDevice PCIDevice;
576 typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
577 uint32_t address, uint32_t data, int len);
578 typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
579 uint32_t address, int len);
580 typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num,
581 uint32_t addr, uint32_t size, int type);
583 #define PCI_ADDRESS_SPACE_MEM 0x00
584 #define PCI_ADDRESS_SPACE_IO 0x01
585 #define PCI_ADDRESS_SPACE_MEM_PREFETCH 0x08
587 typedef struct PCIIORegion {
588 uint32_t addr; /* current PCI mapping address. -1 means not mapped */
589 uint32_t size;
590 uint8_t type;
591 PCIMapIORegionFunc *map_func;
592 } PCIIORegion;
594 #define PCI_ROM_SLOT 6
595 #define PCI_NUM_REGIONS 7
597 #define PCI_DEVICES_MAX 64
599 #define PCI_VENDOR_ID 0x00 /* 16 bits */
600 #define PCI_DEVICE_ID 0x02 /* 16 bits */
601 #define PCI_COMMAND 0x04 /* 16 bits */
602 #define PCI_COMMAND_IO 0x1 /* Enable response in I/O space */
603 #define PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */
604 #define PCI_CLASS_DEVICE 0x0a /* Device class */
605 #define PCI_INTERRUPT_LINE 0x3c /* 8 bits */
606 #define PCI_INTERRUPT_PIN 0x3d /* 8 bits */
607 #define PCI_MIN_GNT 0x3e /* 8 bits */
608 #define PCI_MAX_LAT 0x3f /* 8 bits */
610 struct PCIDevice {
611 /* PCI config space */
612 uint8_t config[256];
614 /* the following fields are read only */
615 PCIBus *bus;
616 int devfn;
617 char name[64];
618 PCIIORegion io_regions[PCI_NUM_REGIONS];
620 /* do not access the following fields */
621 PCIConfigReadFunc *config_read;
622 PCIConfigWriteFunc *config_write;
623 /* ??? This is a PC-specific hack, and should be removed. */
624 int irq_index;
627 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
628 int instance_size, int devfn,
629 PCIConfigReadFunc *config_read,
630 PCIConfigWriteFunc *config_write);
632 void pci_register_io_region(PCIDevice *pci_dev, int region_num,
633 uint32_t size, int type,
634 PCIMapIORegionFunc *map_func);
636 void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level);
638 uint32_t pci_default_read_config(PCIDevice *d,
639 uint32_t address, int len);
640 void pci_default_write_config(PCIDevice *d,
641 uint32_t address, uint32_t val, int len);
642 void generic_pci_save(QEMUFile* f, void *opaque);
643 int generic_pci_load(QEMUFile* f, void *opaque, int version_id);
645 typedef void (*pci_set_irq_fn)(PCIDevice *pci_dev, void *pic,
646 int irq_num, int level);
647 PCIBus *pci_register_bus(pci_set_irq_fn set_irq, void *pic, int devfn_min);
649 void pci_nic_init(PCIBus *bus, NICInfo *nd);
650 void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
651 uint32_t pci_data_read(void *opaque, uint32_t addr, int len);
652 int pci_bus_num(PCIBus *s);
653 void pci_for_each_device(void (*fn)(PCIDevice *d));
655 void pci_info(void);
657 /* prep_pci.c */
658 PCIBus *pci_prep_init(void);
660 /* grackle_pci.c */
661 PCIBus *pci_grackle_init(uint32_t base, void *pic);
663 /* unin_pci.c */
664 PCIBus *pci_pmac_init(void *pic);
666 /* apb_pci.c */
667 PCIBus *pci_apb_init(target_ulong special_base, target_ulong mem_base,
668 void *pic);
670 PCIBus *pci_vpb_init(void *pic);
672 /* piix_pci.c */
673 PCIBus *i440fx_init(void);
674 int piix3_init(PCIBus *bus);
675 void pci_bios_init(void);
677 /* openpic.c */
678 typedef struct openpic_t openpic_t;
679 void openpic_set_irq(void *opaque, int n_IRQ, int level);
680 openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,
681 CPUState **envp);
683 /* heathrow_pic.c */
684 typedef struct HeathrowPICS HeathrowPICS;
685 void heathrow_pic_set_irq(void *opaque, int num, int level);
686 HeathrowPICS *heathrow_pic_init(int *pmem_index);
688 #ifdef HAS_AUDIO
689 struct soundhw {
690 const char *name;
691 const char *descr;
692 int enabled;
693 int isa;
694 union {
695 int (*init_isa) (AudioState *s);
696 int (*init_pci) (PCIBus *bus, AudioState *s);
697 } init;
700 extern struct soundhw soundhw[];
701 #endif
703 /* vga.c */
705 #define VGA_RAM_SIZE (4096 * 1024)
707 struct DisplayState {
708 uint8_t *data;
709 int linesize;
710 int depth;
711 int bgr; /* BGR color order instead of RGB. Only valid for depth == 32 */
712 int width;
713 int height;
714 void *opaque;
716 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
717 void (*dpy_resize)(struct DisplayState *s, int w, int h);
718 void (*dpy_refresh)(struct DisplayState *s);
719 void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
722 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
724 s->dpy_update(s, x, y, w, h);
727 static inline void dpy_resize(DisplayState *s, int w, int h)
729 s->dpy_resize(s, w, h);
732 int vga_initialize(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
733 unsigned long vga_ram_offset, int vga_ram_size,
734 unsigned long vga_bios_offset, int vga_bios_size);
736 /* cirrus_vga.c */
737 void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
738 unsigned long vga_ram_offset, int vga_ram_size);
739 void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
740 unsigned long vga_ram_offset, int vga_ram_size);
742 /* sdl.c */
743 void sdl_display_init(DisplayState *ds, int full_screen);
745 /* cocoa.m */
746 void cocoa_display_init(DisplayState *ds, int full_screen);
748 /* vnc.c */
749 void vnc_display_init(DisplayState *ds, int display);
751 /* ide.c */
752 #define MAX_DISKS 4
754 extern BlockDriverState *bs_table[MAX_DISKS];
756 void isa_ide_init(int iobase, int iobase2, int irq,
757 BlockDriverState *hd0, BlockDriverState *hd1);
758 void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
759 int secondary_ide_enabled);
760 void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn);
761 int pmac_ide_init (BlockDriverState **hd_table,
762 SetIRQFunc *set_irq, void *irq_opaque, int irq);
764 /* es1370.c */
765 int es1370_init (PCIBus *bus, AudioState *s);
767 /* sb16.c */
768 int SB16_init (AudioState *s);
770 /* adlib.c */
771 int Adlib_init (AudioState *s);
773 /* gus.c */
774 int GUS_init (AudioState *s);
776 /* dma.c */
777 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
778 int DMA_get_channel_mode (int nchan);
779 int DMA_read_memory (int nchan, void *buf, int pos, int size);
780 int DMA_write_memory (int nchan, void *buf, int pos, int size);
781 void DMA_hold_DREQ (int nchan);
782 void DMA_release_DREQ (int nchan);
783 void DMA_schedule(int nchan);
784 void DMA_run (void);
785 void DMA_init (int high_page_enable);
786 void DMA_register_channel (int nchan,
787 DMA_transfer_handler transfer_handler,
788 void *opaque);
789 /* fdc.c */
790 #define MAX_FD 2
791 extern BlockDriverState *fd_table[MAX_FD];
793 typedef struct fdctrl_t fdctrl_t;
795 fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped,
796 uint32_t io_base,
797 BlockDriverState **fds);
798 int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num);
800 /* ne2000.c */
802 void isa_ne2000_init(int base, int irq, NICInfo *nd);
803 void pci_ne2000_init(PCIBus *bus, NICInfo *nd);
805 /* rtl8139.c */
807 void pci_rtl8139_init(PCIBus *bus, NICInfo *nd);
809 /* pckbd.c */
811 void kbd_init(void);
813 /* mc146818rtc.c */
815 typedef struct RTCState RTCState;
817 RTCState *rtc_init(int base, int irq);
818 void rtc_set_memory(RTCState *s, int addr, int val);
819 void rtc_set_date(RTCState *s, const struct tm *tm);
821 /* serial.c */
823 typedef struct SerialState SerialState;
824 SerialState *serial_init(SetIRQFunc *set_irq, void *opaque,
825 int base, int irq, CharDriverState *chr);
826 SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque,
827 target_ulong base, int it_shift,
828 int irq, CharDriverState *chr);
830 /* parallel.c */
832 typedef struct ParallelState ParallelState;
833 ParallelState *parallel_init(int base, int irq, CharDriverState *chr);
835 /* i8259.c */
837 typedef struct PicState2 PicState2;
838 extern PicState2 *isa_pic;
839 void pic_set_irq(int irq, int level);
840 void pic_set_irq_new(void *opaque, int irq, int level);
841 PicState2 *pic_init(IRQRequestFunc *irq_request, void *irq_request_opaque);
842 void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func,
843 void *alt_irq_opaque);
844 int pic_read_irq(PicState2 *s);
845 void pic_update_irq(PicState2 *s);
846 uint32_t pic_intack_read(PicState2 *s);
847 void pic_info(void);
848 void irq_info(void);
850 /* APIC */
851 typedef struct IOAPICState IOAPICState;
853 int apic_init(CPUState *env);
854 int apic_get_interrupt(CPUState *env);
855 IOAPICState *ioapic_init(void);
856 void ioapic_set_irq(void *opaque, int vector, int level);
858 /* i8254.c */
860 #define PIT_FREQ 1193182
862 typedef struct PITState PITState;
864 PITState *pit_init(int base, int irq);
865 void pit_set_gate(PITState *pit, int channel, int val);
866 int pit_get_gate(PITState *pit, int channel);
867 int pit_get_initial_count(PITState *pit, int channel);
868 int pit_get_mode(PITState *pit, int channel);
869 int pit_get_out(PITState *pit, int channel, int64_t current_time);
871 /* pcspk.c */
872 void pcspk_init(PITState *);
873 int pcspk_audio_init(AudioState *);
875 /* acpi.c */
876 extern int acpi_enabled;
877 void piix4_pm_init(PCIBus *bus, int devfn);
878 void acpi_bios_init(void);
880 /* pc.c */
881 extern QEMUMachine pc_machine;
882 extern QEMUMachine isapc_machine;
884 void ioport_set_a20(int enable);
885 int ioport_get_a20(void);
887 /* ppc.c */
888 extern QEMUMachine prep_machine;
889 extern QEMUMachine core99_machine;
890 extern QEMUMachine heathrow_machine;
892 /* mips_r4k.c */
893 extern QEMUMachine mips_machine;
895 /* shix.c */
896 extern QEMUMachine shix_machine;
898 #ifdef TARGET_PPC
899 ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq);
900 #endif
901 void PREP_debug_write (void *opaque, uint32_t addr, uint32_t val);
903 extern CPUWriteMemoryFunc *PPC_io_write[];
904 extern CPUReadMemoryFunc *PPC_io_read[];
905 void PPC_debug_write (void *opaque, uint32_t addr, uint32_t val);
907 /* sun4m.c */
908 extern QEMUMachine sun4m_machine;
909 uint32_t iommu_translate(uint32_t addr);
910 void pic_set_irq_cpu(int irq, int level, unsigned int cpu);
912 /* iommu.c */
913 void *iommu_init(uint32_t addr);
914 uint32_t iommu_translate_local(void *opaque, uint32_t addr);
916 /* lance.c */
917 void lance_init(NICInfo *nd, int irq, uint32_t leaddr, uint32_t ledaddr);
919 /* tcx.c */
920 void tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
921 unsigned long vram_offset, int vram_size, int width, int height);
923 /* slavio_intctl.c */
924 void *slavio_intctl_init();
925 void slavio_intctl_set_cpu(void *opaque, unsigned int cpu, CPUState *env);
926 void slavio_pic_info(void *opaque);
927 void slavio_irq_info(void *opaque);
928 void slavio_pic_set_irq(void *opaque, int irq, int level);
929 void slavio_pic_set_irq_cpu(void *opaque, int irq, int level, unsigned int cpu);
931 /* loader.c */
932 int get_image_size(const char *filename);
933 int load_image(const char *filename, uint8_t *addr);
934 int load_elf(const char *filename, int64_t virt_to_phys_addend, uint64_t *pentry);
935 int load_aout(const char *filename, uint8_t *addr);
937 /* slavio_timer.c */
938 void slavio_timer_init(uint32_t addr, int irq, int mode, unsigned int cpu);
940 /* slavio_serial.c */
941 SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDriverState *chr2);
942 void slavio_serial_ms_kbd_init(int base, int irq);
944 /* slavio_misc.c */
945 void *slavio_misc_init(uint32_t base, int irq);
946 void slavio_set_power_fail(void *opaque, int power_failing);
948 /* esp.c */
949 void esp_init(BlockDriverState **bd, int irq, uint32_t espaddr, uint32_t espdaddr);
951 /* sun4u.c */
952 extern QEMUMachine sun4u_machine;
954 /* NVRAM helpers */
955 #include "hw/m48t59.h"
957 void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value);
958 uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr);
959 void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value);
960 uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr);
961 void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr, uint32_t value);
962 uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr);
963 void NVRAM_set_string (m48t59_t *nvram, uint32_t addr,
964 const unsigned char *str, uint32_t max);
965 int NVRAM_get_string (m48t59_t *nvram, uint8_t *dst, uint16_t addr, int max);
966 void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr,
967 uint32_t start, uint32_t count);
968 int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
969 const unsigned char *arch,
970 uint32_t RAM_size, int boot_device,
971 uint32_t kernel_image, uint32_t kernel_size,
972 const char *cmdline,
973 uint32_t initrd_image, uint32_t initrd_size,
974 uint32_t NVRAM_image,
975 int width, int height, int depth);
977 /* adb.c */
979 #define MAX_ADB_DEVICES 16
981 #define ADB_MAX_OUT_LEN 16
983 typedef struct ADBDevice ADBDevice;
985 /* buf = NULL means polling */
986 typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
987 const uint8_t *buf, int len);
988 typedef int ADBDeviceReset(ADBDevice *d);
990 struct ADBDevice {
991 struct ADBBusState *bus;
992 int devaddr;
993 int handler;
994 ADBDeviceRequest *devreq;
995 ADBDeviceReset *devreset;
996 void *opaque;
999 typedef struct ADBBusState {
1000 ADBDevice devices[MAX_ADB_DEVICES];
1001 int nb_devices;
1002 int poll_index;
1003 } ADBBusState;
1005 int adb_request(ADBBusState *s, uint8_t *buf_out,
1006 const uint8_t *buf, int len);
1007 int adb_poll(ADBBusState *s, uint8_t *buf_out);
1009 ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
1010 ADBDeviceRequest *devreq,
1011 ADBDeviceReset *devreset,
1012 void *opaque);
1013 void adb_kbd_init(ADBBusState *bus);
1014 void adb_mouse_init(ADBBusState *bus);
1016 /* cuda.c */
1018 extern ADBBusState adb_bus;
1019 int cuda_init(SetIRQFunc *set_irq, void *irq_opaque, int irq);
1021 #include "hw/usb.h"
1023 /* usb ports of the VM */
1025 #define MAX_VM_USB_PORTS 8
1027 extern USBPort *vm_usb_ports[MAX_VM_USB_PORTS];
1028 extern USBDevice *vm_usb_hub;
1030 void do_usb_add(const char *devname);
1031 void do_usb_del(const char *devname);
1032 void usb_info(void);
1034 /* integratorcp.c */
1035 extern QEMUMachine integratorcp926_machine;
1036 extern QEMUMachine integratorcp1026_machine;
1038 /* versatilepb.c */
1039 extern QEMUMachine versatilepb_machine;
1040 extern QEMUMachine versatileab_machine;
1042 /* ps2.c */
1043 void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg);
1044 void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg);
1045 void ps2_write_mouse(void *, int val);
1046 void ps2_write_keyboard(void *, int val);
1047 uint32_t ps2_read_data(void *);
1048 void ps2_queue(void *, int b);
1049 void ps2_keyboard_set_translation(void *opaque, int mode);
1051 /* smc91c111.c */
1052 void smc91c111_init(NICInfo *, uint32_t, void *, int);
1054 /* pl110.c */
1055 void *pl110_init(DisplayState *ds, uint32_t base, void *pic, int irq, int);
1057 /* pl011.c */
1058 void pl011_init(uint32_t base, void *pic, int irq, CharDriverState *chr);
1060 /* pl050.c */
1061 void pl050_init(uint32_t base, void *pic, int irq, int is_mouse);
1063 /* pl080.c */
1064 void *pl080_init(uint32_t base, void *pic, int irq);
1066 /* pl190.c */
1067 void *pl190_init(uint32_t base, void *parent, int irq, int fiq);
1069 /* arm-timer.c */
1070 void sp804_init(uint32_t base, void *pic, int irq);
1071 void icp_pit_init(uint32_t base, void *pic, int irq);
1073 /* arm_boot.c */
1075 void arm_load_kernel(int ram_size, const char *kernel_filename,
1076 const char *kernel_cmdline, const char *initrd_filename,
1077 int board_id);
1079 /* sh7750.c */
1080 struct SH7750State;
1082 struct SH7750State *sh7750_init(CPUState * cpu);
1084 typedef struct {
1085 /* The callback will be triggered if any of the designated lines change */
1086 uint16_t portamask_trigger;
1087 uint16_t portbmask_trigger;
1088 /* Return 0 if no action was taken */
1089 int (*port_change_cb) (uint16_t porta, uint16_t portb,
1090 uint16_t * periph_pdtra,
1091 uint16_t * periph_portdira,
1092 uint16_t * periph_pdtrb,
1093 uint16_t * periph_portdirb);
1094 } sh7750_io_device;
1096 int sh7750_register_io_device(struct SH7750State *s,
1097 sh7750_io_device * device);
1098 /* tc58128.c */
1099 int tc58128_init(struct SH7750State *s, char *zone1, char *zone2);
1101 #endif /* defined(QEMU_TOOL) */
1103 /* monitor.c */
1104 void monitor_init(CharDriverState *hd, int show_banner);
1105 void term_puts(const char *str);
1106 void term_vprintf(const char *fmt, va_list ap);
1107 void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
1108 void term_flush(void);
1109 void term_print_help(void);
1110 void monitor_readline(const char *prompt, int is_password,
1111 char *buf, int buf_size);
1113 /* readline.c */
1114 typedef void ReadLineFunc(void *opaque, const char *str);
1116 extern int completion_index;
1117 void add_completion(const char *str);
1118 void readline_handle_byte(int ch);
1119 void readline_find_completion(const char *cmdline);
1120 const char *readline_get_history(unsigned int index);
1121 void readline_start(const char *prompt, int is_password,
1122 ReadLineFunc *readline_func, void *opaque);
1124 void kqemu_record_dump(void);
1126 #endif /* VL_H */