]>
Commit | Line | Data |
---|---|---|
fc01f7e7 FB |
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 | ||
67b915a5 FB |
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> | |
8a7ddc38 | 33 | #include <time.h> |
67b915a5 FB |
34 | #include <ctype.h> |
35 | #include <errno.h> | |
36 | #include <unistd.h> | |
37 | #include <fcntl.h> | |
7d3505c5 | 38 | #include <sys/stat.h> |
67b915a5 FB |
39 | |
40 | #ifndef O_LARGEFILE | |
41 | #define O_LARGEFILE 0 | |
42 | #endif | |
40c3bac3 FB |
43 | #ifndef O_BINARY |
44 | #define O_BINARY 0 | |
45 | #endif | |
67b915a5 FB |
46 | |
47 | #ifdef _WIN32 | |
bfbc9133 | 48 | #define lseek64 _lseeki64 |
67b915a5 | 49 | #endif |
8a7ddc38 | 50 | |
16f62432 FB |
51 | #include "cpu.h" |
52 | ||
67b915a5 FB |
53 | #ifndef glue |
54 | #define xglue(x, y) x ## y | |
55 | #define glue(x, y) xglue(x, y) | |
56 | #define stringify(s) tostring(s) | |
57 | #define tostring(s) #s | |
58 | #endif | |
59 | ||
60 | #if defined(WORDS_BIGENDIAN) | |
61 | static inline uint32_t be32_to_cpu(uint32_t v) | |
62 | { | |
63 | return v; | |
64 | } | |
65 | ||
66 | static inline uint16_t be16_to_cpu(uint16_t v) | |
67 | { | |
68 | return v; | |
69 | } | |
70 | ||
165c6fc8 FB |
71 | static inline uint32_t cpu_to_be32(uint32_t v) |
72 | { | |
73 | return v; | |
74 | } | |
75 | ||
76 | static inline uint16_t cpu_to_be16(uint16_t v) | |
77 | { | |
78 | return v; | |
79 | } | |
80 | ||
67b915a5 FB |
81 | static inline uint32_t le32_to_cpu(uint32_t v) |
82 | { | |
83 | return bswap32(v); | |
84 | } | |
85 | ||
86 | static inline uint16_t le16_to_cpu(uint16_t v) | |
87 | { | |
88 | return bswap16(v); | |
89 | } | |
90 | ||
165c6fc8 FB |
91 | static inline uint32_t cpu_to_le32(uint32_t v) |
92 | { | |
93 | return bswap32(v); | |
94 | } | |
95 | ||
96 | static inline uint16_t cpu_to_le16(uint16_t v) | |
97 | { | |
98 | return bswap16(v); | |
99 | } | |
100 | ||
67b915a5 | 101 | #else |
165c6fc8 | 102 | |
67b915a5 FB |
103 | static inline uint32_t be32_to_cpu(uint32_t v) |
104 | { | |
105 | return bswap32(v); | |
106 | } | |
107 | ||
108 | static inline uint16_t be16_to_cpu(uint16_t v) | |
109 | { | |
110 | return bswap16(v); | |
111 | } | |
112 | ||
165c6fc8 FB |
113 | static inline uint32_t cpu_to_be32(uint32_t v) |
114 | { | |
115 | return bswap32(v); | |
116 | } | |
117 | ||
118 | static inline uint16_t cpu_to_be16(uint16_t v) | |
119 | { | |
120 | return bswap16(v); | |
121 | } | |
122 | ||
67b915a5 FB |
123 | static inline uint32_t le32_to_cpu(uint32_t v) |
124 | { | |
125 | return v; | |
126 | } | |
127 | ||
128 | static inline uint16_t le16_to_cpu(uint16_t v) | |
129 | { | |
130 | return v; | |
131 | } | |
165c6fc8 FB |
132 | |
133 | static inline uint32_t cpu_to_le32(uint32_t v) | |
134 | { | |
135 | return v; | |
136 | } | |
137 | ||
138 | static inline uint16_t cpu_to_le16(uint16_t v) | |
139 | { | |
140 | return v; | |
141 | } | |
67b915a5 FB |
142 | #endif |
143 | ||
eb26db16 FB |
144 | static inline void cpu_to_le16w(uint16_t *p, uint16_t v) |
145 | { | |
146 | *p = cpu_to_le16(v); | |
147 | } | |
148 | ||
149 | static inline void cpu_to_le32w(uint32_t *p, uint32_t v) | |
150 | { | |
151 | *p = cpu_to_le32(v); | |
152 | } | |
153 | ||
154 | static inline uint16_t le16_to_cpup(const uint16_t *p) | |
155 | { | |
156 | return le16_to_cpu(*p); | |
157 | } | |
158 | ||
159 | static inline uint32_t le32_to_cpup(const uint32_t *p) | |
160 | { | |
161 | return le32_to_cpu(*p); | |
162 | } | |
163 | ||
164 | /* unaligned versions (optimized for frequent unaligned accesses)*/ | |
165 | ||
166 | #if defined(__i386__) || defined(__powerpc__) | |
167 | ||
168 | #define cpu_to_le16wu(p, v) cpu_to_le16w(p, v) | |
169 | #define cpu_to_le32wu(p, v) cpu_to_le32w(p, v) | |
170 | #define le16_to_cpupu(p) le16_to_cpup(p) | |
171 | #define le32_to_cpupu(p) le32_to_cpup(p) | |
172 | ||
173 | #else | |
174 | ||
175 | static inline void cpu_to_le16wu(uint16_t *p, uint16_t v) | |
176 | { | |
177 | uint8_t *p1 = (uint8_t *)p; | |
178 | ||
179 | p1[0] = v; | |
180 | p1[1] = v >> 8; | |
181 | } | |
182 | ||
183 | static inline void cpu_to_le32wu(uint32_t *p, uint32_t v) | |
184 | { | |
185 | uint8_t *p1 = (uint8_t *)p; | |
186 | ||
187 | p1[0] = v; | |
188 | p1[1] = v >> 8; | |
189 | p1[2] = v >> 16; | |
190 | p1[3] = v >> 24; | |
191 | } | |
192 | ||
193 | static inline uint16_t le16_to_cpupu(const uint16_t *p) | |
194 | { | |
195 | const uint8_t *p1 = (const uint8_t *)p; | |
196 | return p1[0] | (p1[1] << 8); | |
197 | } | |
198 | ||
199 | static inline uint32_t le32_to_cpupu(const uint32_t *p) | |
200 | { | |
201 | const uint8_t *p1 = (const uint8_t *)p; | |
202 | return p1[0] | (p1[1] << 8) | (p1[2] << 16) | (p1[3] << 24); | |
203 | } | |
204 | ||
205 | #endif | |
67b915a5 | 206 | |
33e3963e | 207 | /* vl.c */ |
80cabfad | 208 | uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c); |
313aa567 | 209 | |
80cabfad FB |
210 | void hw_error(const char *fmt, ...); |
211 | ||
7587cf44 | 212 | int get_image_size(const char *filename); |
80cabfad FB |
213 | int load_image(const char *filename, uint8_t *addr); |
214 | extern const char *bios_dir; | |
215 | ||
216 | void pstrcpy(char *buf, int buf_size, const char *str); | |
217 | char *pstrcat(char *buf, int buf_size, const char *s); | |
33e3963e | 218 | |
c4b1fcc0 FB |
219 | int serial_open_device(void); |
220 | ||
8a7ddc38 FB |
221 | extern int vm_running; |
222 | ||
223 | typedef void VMStopHandler(void *opaque, int reason); | |
224 | ||
225 | int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque); | |
226 | void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque); | |
227 | ||
228 | void vm_start(void); | |
229 | void vm_stop(int reason); | |
230 | ||
bb0c6722 FB |
231 | typedef void QEMUResetHandler(void *opaque); |
232 | ||
233 | void qemu_register_reset(QEMUResetHandler *func, void *opaque); | |
234 | void qemu_system_reset_request(void); | |
235 | void qemu_system_shutdown_request(void); | |
236 | ||
aaaa7df6 | 237 | extern int audio_enabled; |
0ced6589 FB |
238 | extern int ram_size; |
239 | extern int bios_size; | |
ee22c2f7 | 240 | extern int rtc_utc; |
1f04275e | 241 | extern int cirrus_vga_enabled; |
28b9b5af FB |
242 | extern int graphic_width; |
243 | extern int graphic_height; | |
244 | extern int graphic_depth; | |
0ced6589 FB |
245 | |
246 | /* XXX: make it dynamic */ | |
247 | #if defined (TARGET_PPC) | |
248 | #define BIOS_SIZE (512 * 1024) | |
249 | #else | |
7587cf44 | 250 | #define BIOS_SIZE ((256 + 64) * 1024) |
0ced6589 | 251 | #endif |
aaaa7df6 | 252 | |
63066f4f FB |
253 | /* keyboard/mouse support */ |
254 | ||
255 | #define MOUSE_EVENT_LBUTTON 0x01 | |
256 | #define MOUSE_EVENT_RBUTTON 0x02 | |
257 | #define MOUSE_EVENT_MBUTTON 0x04 | |
258 | ||
259 | typedef void QEMUPutKBDEvent(void *opaque, int keycode); | |
260 | typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state); | |
261 | ||
262 | void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque); | |
263 | void qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, void *opaque); | |
264 | ||
265 | void kbd_put_keycode(int keycode); | |
266 | void kbd_mouse_event(int dx, int dy, int dz, int buttons_state); | |
267 | ||
c20709aa FB |
268 | /* async I/O support */ |
269 | ||
270 | typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size); | |
271 | typedef int IOCanRWHandler(void *opaque); | |
272 | ||
273 | int qemu_add_fd_read_handler(int fd, IOCanRWHandler *fd_can_read, | |
274 | IOReadHandler *fd_read, void *opaque); | |
275 | void qemu_del_fd_read_handler(int fd); | |
276 | ||
c4b1fcc0 FB |
277 | /* network redirectors support */ |
278 | ||
279 | #define MAX_NICS 8 | |
280 | ||
281 | typedef struct NetDriverState { | |
c20709aa | 282 | int index; /* index number in QEMU */ |
c4b1fcc0 FB |
283 | uint8_t macaddr[6]; |
284 | char ifname[16]; | |
c20709aa FB |
285 | void (*send_packet)(struct NetDriverState *nd, |
286 | const uint8_t *buf, int size); | |
287 | void (*add_read_packet)(struct NetDriverState *nd, | |
288 | IOCanRWHandler *fd_can_read, | |
289 | IOReadHandler *fd_read, void *opaque); | |
290 | /* tun specific data */ | |
291 | int fd; | |
292 | /* slirp specific data */ | |
c4b1fcc0 FB |
293 | } NetDriverState; |
294 | ||
295 | extern int nb_nics; | |
296 | extern NetDriverState nd_table[MAX_NICS]; | |
297 | ||
c20709aa FB |
298 | void qemu_send_packet(NetDriverState *nd, const uint8_t *buf, int size); |
299 | void qemu_add_read_packet(NetDriverState *nd, IOCanRWHandler *fd_can_read, | |
300 | IOReadHandler *fd_read, void *opaque); | |
8a7ddc38 FB |
301 | |
302 | /* timers */ | |
303 | ||
304 | typedef struct QEMUClock QEMUClock; | |
305 | typedef struct QEMUTimer QEMUTimer; | |
306 | typedef void QEMUTimerCB(void *opaque); | |
307 | ||
308 | /* The real time clock should be used only for stuff which does not | |
309 | change the virtual machine state, as it is run even if the virtual | |
69b91039 | 310 | machine is stopped. The real time clock has a frequency of 1000 |
8a7ddc38 FB |
311 | Hz. */ |
312 | extern QEMUClock *rt_clock; | |
313 | ||
314 | /* Rge virtual clock is only run during the emulation. It is stopped | |
315 | when the virtual machine is stopped. Virtual timers use a high | |
316 | precision clock, usually cpu cycles (use ticks_per_sec). */ | |
317 | extern QEMUClock *vm_clock; | |
318 | ||
319 | int64_t qemu_get_clock(QEMUClock *clock); | |
320 | ||
321 | QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque); | |
322 | void qemu_free_timer(QEMUTimer *ts); | |
323 | void qemu_del_timer(QEMUTimer *ts); | |
324 | void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); | |
325 | int qemu_timer_pending(QEMUTimer *ts); | |
326 | ||
327 | extern int64_t ticks_per_sec; | |
328 | extern int pit_min_timer_count; | |
329 | ||
330 | void cpu_enable_ticks(void); | |
331 | void cpu_disable_ticks(void); | |
332 | ||
333 | /* VM Load/Save */ | |
334 | ||
335 | typedef FILE QEMUFile; | |
336 | ||
337 | void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); | |
338 | void qemu_put_byte(QEMUFile *f, int v); | |
339 | void qemu_put_be16(QEMUFile *f, unsigned int v); | |
340 | void qemu_put_be32(QEMUFile *f, unsigned int v); | |
341 | void qemu_put_be64(QEMUFile *f, uint64_t v); | |
342 | int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size); | |
343 | int qemu_get_byte(QEMUFile *f); | |
344 | unsigned int qemu_get_be16(QEMUFile *f); | |
345 | unsigned int qemu_get_be32(QEMUFile *f); | |
346 | uint64_t qemu_get_be64(QEMUFile *f); | |
347 | ||
348 | static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) | |
349 | { | |
350 | qemu_put_be64(f, *pv); | |
351 | } | |
352 | ||
353 | static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv) | |
354 | { | |
355 | qemu_put_be32(f, *pv); | |
356 | } | |
357 | ||
358 | static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv) | |
359 | { | |
360 | qemu_put_be16(f, *pv); | |
361 | } | |
362 | ||
363 | static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv) | |
364 | { | |
365 | qemu_put_byte(f, *pv); | |
366 | } | |
367 | ||
368 | static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv) | |
369 | { | |
370 | *pv = qemu_get_be64(f); | |
371 | } | |
372 | ||
373 | static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv) | |
374 | { | |
375 | *pv = qemu_get_be32(f); | |
376 | } | |
377 | ||
378 | static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv) | |
379 | { | |
380 | *pv = qemu_get_be16(f); | |
381 | } | |
382 | ||
383 | static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv) | |
384 | { | |
385 | *pv = qemu_get_byte(f); | |
386 | } | |
387 | ||
388 | int64_t qemu_ftell(QEMUFile *f); | |
389 | int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence); | |
390 | ||
391 | typedef void SaveStateHandler(QEMUFile *f, void *opaque); | |
392 | typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); | |
393 | ||
394 | int qemu_loadvm(const char *filename); | |
395 | int qemu_savevm(const char *filename); | |
396 | int register_savevm(const char *idstr, | |
397 | int instance_id, | |
398 | int version_id, | |
399 | SaveStateHandler *save_state, | |
400 | LoadStateHandler *load_state, | |
401 | void *opaque); | |
402 | void qemu_get_timer(QEMUFile *f, QEMUTimer *ts); | |
403 | void qemu_put_timer(QEMUFile *f, QEMUTimer *ts); | |
c4b1fcc0 | 404 | |
fc01f7e7 FB |
405 | /* block.c */ |
406 | typedef struct BlockDriverState BlockDriverState; | |
407 | ||
c4b1fcc0 FB |
408 | BlockDriverState *bdrv_new(const char *device_name); |
409 | void bdrv_delete(BlockDriverState *bs); | |
410 | int bdrv_open(BlockDriverState *bs, const char *filename, int snapshot); | |
fc01f7e7 FB |
411 | void bdrv_close(BlockDriverState *bs); |
412 | int bdrv_read(BlockDriverState *bs, int64_t sector_num, | |
413 | uint8_t *buf, int nb_sectors); | |
414 | int bdrv_write(BlockDriverState *bs, int64_t sector_num, | |
415 | const uint8_t *buf, int nb_sectors); | |
416 | void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr); | |
33e3963e | 417 | int bdrv_commit(BlockDriverState *bs); |
77fef8c1 | 418 | void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size); |
33e3963e | 419 | |
c4b1fcc0 FB |
420 | #define BDRV_TYPE_HD 0 |
421 | #define BDRV_TYPE_CDROM 1 | |
422 | #define BDRV_TYPE_FLOPPY 2 | |
423 | ||
424 | void bdrv_set_geometry_hint(BlockDriverState *bs, | |
425 | int cyls, int heads, int secs); | |
426 | void bdrv_set_type_hint(BlockDriverState *bs, int type); | |
427 | void bdrv_get_geometry_hint(BlockDriverState *bs, | |
428 | int *pcyls, int *pheads, int *psecs); | |
429 | int bdrv_get_type_hint(BlockDriverState *bs); | |
430 | int bdrv_is_removable(BlockDriverState *bs); | |
431 | int bdrv_is_read_only(BlockDriverState *bs); | |
432 | int bdrv_is_inserted(BlockDriverState *bs); | |
433 | int bdrv_is_locked(BlockDriverState *bs); | |
434 | void bdrv_set_locked(BlockDriverState *bs, int locked); | |
435 | void bdrv_set_change_cb(BlockDriverState *bs, | |
436 | void (*change_cb)(void *opaque), void *opaque); | |
437 | ||
438 | void bdrv_info(void); | |
439 | BlockDriverState *bdrv_find(const char *name); | |
440 | ||
26aa7d72 FB |
441 | /* ISA bus */ |
442 | ||
443 | extern target_phys_addr_t isa_mem_base; | |
444 | ||
445 | typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data); | |
446 | typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address); | |
447 | ||
448 | int register_ioport_read(int start, int length, int size, | |
449 | IOPortReadFunc *func, void *opaque); | |
450 | int register_ioport_write(int start, int length, int size, | |
451 | IOPortWriteFunc *func, void *opaque); | |
69b91039 FB |
452 | void isa_unassign_ioport(int start, int length); |
453 | ||
454 | /* PCI bus */ | |
455 | ||
456 | extern int pci_enabled; | |
457 | ||
458 | extern target_phys_addr_t pci_mem_base; | |
459 | ||
46e50e9d | 460 | typedef struct PCIBus PCIBus; |
69b91039 FB |
461 | typedef struct PCIDevice PCIDevice; |
462 | ||
463 | typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, | |
464 | uint32_t address, uint32_t data, int len); | |
465 | typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, | |
466 | uint32_t address, int len); | |
467 | typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, | |
468 | uint32_t addr, uint32_t size, int type); | |
469 | ||
470 | #define PCI_ADDRESS_SPACE_MEM 0x00 | |
471 | #define PCI_ADDRESS_SPACE_IO 0x01 | |
472 | #define PCI_ADDRESS_SPACE_MEM_PREFETCH 0x08 | |
473 | ||
474 | typedef struct PCIIORegion { | |
5768f5ac | 475 | uint32_t addr; /* current PCI mapping address. -1 means not mapped */ |
69b91039 FB |
476 | uint32_t size; |
477 | uint8_t type; | |
478 | PCIMapIORegionFunc *map_func; | |
479 | } PCIIORegion; | |
480 | ||
8a8696a3 FB |
481 | #define PCI_ROM_SLOT 6 |
482 | #define PCI_NUM_REGIONS 7 | |
69b91039 FB |
483 | struct PCIDevice { |
484 | /* PCI config space */ | |
485 | uint8_t config[256]; | |
486 | ||
487 | /* the following fields are read only */ | |
46e50e9d | 488 | PCIBus *bus; |
69b91039 FB |
489 | int devfn; |
490 | char name[64]; | |
8a8696a3 | 491 | PCIIORegion io_regions[PCI_NUM_REGIONS]; |
69b91039 FB |
492 | |
493 | /* do not access the following fields */ | |
494 | PCIConfigReadFunc *config_read; | |
495 | PCIConfigWriteFunc *config_write; | |
5768f5ac | 496 | int irq_index; |
69b91039 FB |
497 | }; |
498 | ||
46e50e9d FB |
499 | PCIDevice *pci_register_device(PCIBus *bus, const char *name, |
500 | int instance_size, int devfn, | |
69b91039 FB |
501 | PCIConfigReadFunc *config_read, |
502 | PCIConfigWriteFunc *config_write); | |
503 | ||
504 | void pci_register_io_region(PCIDevice *pci_dev, int region_num, | |
505 | uint32_t size, int type, | |
506 | PCIMapIORegionFunc *map_func); | |
507 | ||
5768f5ac FB |
508 | void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level); |
509 | ||
510 | uint32_t pci_default_read_config(PCIDevice *d, | |
511 | uint32_t address, int len); | |
512 | void pci_default_write_config(PCIDevice *d, | |
513 | uint32_t address, uint32_t val, int len); | |
514 | ||
9995c51f FB |
515 | extern struct PIIX3State *piix3_state; |
516 | ||
46e50e9d FB |
517 | PCIBus *i440fx_init(void); |
518 | void piix3_init(PCIBus *bus); | |
69b91039 | 519 | void pci_bios_init(void); |
5768f5ac | 520 | void pci_info(void); |
26aa7d72 | 521 | |
77d4bc34 | 522 | /* temporary: will be moved in platform specific file */ |
46e50e9d FB |
523 | PCIBus *pci_prep_init(void); |
524 | struct openpic_t; | |
525 | void pci_pmac_set_openpic(PCIBus *bus, struct openpic_t *openpic); | |
526 | PCIBus *pci_pmac_init(void); | |
77d4bc34 | 527 | |
28b9b5af FB |
528 | /* openpic.c */ |
529 | typedef struct openpic_t openpic_t; | |
530 | void openpic_set_irq (openpic_t *opp, int n_IRQ, int level); | |
e2733d20 | 531 | openpic_t *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus); |
28b9b5af | 532 | |
313aa567 FB |
533 | /* vga.c */ |
534 | ||
4fa0f5d2 | 535 | #define VGA_RAM_SIZE (4096 * 1024) |
313aa567 FB |
536 | |
537 | typedef struct DisplayState { | |
538 | uint8_t *data; | |
539 | int linesize; | |
540 | int depth; | |
541 | void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h); | |
542 | void (*dpy_resize)(struct DisplayState *s, int w, int h); | |
543 | void (*dpy_refresh)(struct DisplayState *s); | |
544 | } DisplayState; | |
545 | ||
546 | static inline void dpy_update(DisplayState *s, int x, int y, int w, int h) | |
547 | { | |
548 | s->dpy_update(s, x, y, w, h); | |
549 | } | |
550 | ||
551 | static inline void dpy_resize(DisplayState *s, int w, int h) | |
552 | { | |
553 | s->dpy_resize(s, w, h); | |
554 | } | |
555 | ||
46e50e9d FB |
556 | int vga_initialize(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, |
557 | unsigned long vga_ram_offset, int vga_ram_size); | |
313aa567 | 558 | void vga_update_display(void); |
ee38b4c8 | 559 | void vga_invalidate_display(void); |
59a983b9 | 560 | void vga_screen_dump(const char *filename); |
313aa567 | 561 | |
d6bfa22f | 562 | /* cirrus_vga.c */ |
46e50e9d | 563 | void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, |
d6bfa22f | 564 | unsigned long vga_ram_offset, int vga_ram_size); |
d6bfa22f FB |
565 | void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base, |
566 | unsigned long vga_ram_offset, int vga_ram_size); | |
567 | ||
313aa567 FB |
568 | /* sdl.c */ |
569 | void sdl_display_init(DisplayState *ds); | |
570 | ||
5391d806 FB |
571 | /* ide.c */ |
572 | #define MAX_DISKS 4 | |
573 | ||
574 | extern BlockDriverState *bs_table[MAX_DISKS]; | |
575 | ||
69b91039 FB |
576 | void isa_ide_init(int iobase, int iobase2, int irq, |
577 | BlockDriverState *hd0, BlockDriverState *hd1); | |
46e50e9d FB |
578 | void pci_ide_init(PCIBus *bus, BlockDriverState **hd_table); |
579 | void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table); | |
28b9b5af FB |
580 | int pmac_ide_init (BlockDriverState **hd_table, |
581 | openpic_t *openpic, int irq); | |
5391d806 | 582 | |
27503323 FB |
583 | /* oss.c */ |
584 | typedef enum { | |
585 | AUD_FMT_U8, | |
586 | AUD_FMT_S8, | |
587 | AUD_FMT_U16, | |
588 | AUD_FMT_S16 | |
589 | } audfmt_e; | |
590 | ||
591 | void AUD_open (int rfreq, int rnchannels, audfmt_e rfmt); | |
592 | void AUD_reset (int rfreq, int rnchannels, audfmt_e rfmt); | |
593 | int AUD_write (void *in_buf, int size); | |
594 | void AUD_run (void); | |
595 | void AUD_adjust_estimate (int _leftover); | |
596 | int AUD_get_free (void); | |
597 | int AUD_get_live (void); | |
598 | int AUD_get_buffer_size (void); | |
599 | void AUD_init (void); | |
600 | ||
601 | /* dma.c */ | |
16f62432 | 602 | typedef int (*DMA_transfer_handler) (void *opaque, target_ulong addr, int size); |
27503323 FB |
603 | int DMA_get_channel_mode (int nchan); |
604 | void DMA_hold_DREQ (int nchan); | |
605 | void DMA_release_DREQ (int nchan); | |
16f62432 | 606 | void DMA_schedule(int nchan); |
27503323 | 607 | void DMA_run (void); |
28b9b5af | 608 | void DMA_init (int high_page_enable); |
27503323 | 609 | void DMA_register_channel (int nchan, |
16f62432 | 610 | DMA_transfer_handler transfer_handler, void *opaque); |
27503323 FB |
611 | |
612 | /* sb16.c */ | |
613 | void SB16_run (void); | |
614 | void SB16_init (void); | |
615 | ||
7138fcfb FB |
616 | /* fdc.c */ |
617 | #define MAX_FD 2 | |
618 | extern BlockDriverState *fd_table[MAX_FD]; | |
619 | ||
baca51fa FB |
620 | typedef struct fdctrl_t fdctrl_t; |
621 | ||
622 | fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, | |
623 | uint32_t io_base, | |
624 | BlockDriverState **fds); | |
625 | int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num); | |
7138fcfb | 626 | |
80cabfad FB |
627 | /* ne2000.c */ |
628 | ||
69b91039 | 629 | void isa_ne2000_init(int base, int irq, NetDriverState *nd); |
46e50e9d | 630 | void pci_ne2000_init(PCIBus *bus, NetDriverState *nd); |
80cabfad FB |
631 | |
632 | /* pckbd.c */ | |
633 | ||
80cabfad FB |
634 | void kbd_init(void); |
635 | ||
636 | /* mc146818rtc.c */ | |
637 | ||
8a7ddc38 | 638 | typedef struct RTCState RTCState; |
80cabfad | 639 | |
8a7ddc38 FB |
640 | RTCState *rtc_init(int base, int irq); |
641 | void rtc_set_memory(RTCState *s, int addr, int val); | |
642 | void rtc_set_date(RTCState *s, const struct tm *tm); | |
80cabfad FB |
643 | |
644 | /* serial.c */ | |
645 | ||
c4b1fcc0 FB |
646 | typedef struct SerialState SerialState; |
647 | ||
648 | extern SerialState *serial_console; | |
649 | ||
650 | SerialState *serial_init(int base, int irq, int fd); | |
651 | int serial_can_receive(SerialState *s); | |
652 | void serial_receive_byte(SerialState *s, int ch); | |
653 | void serial_receive_break(SerialState *s); | |
80cabfad FB |
654 | |
655 | /* i8259.c */ | |
656 | ||
657 | void pic_set_irq(int irq, int level); | |
658 | void pic_init(void); | |
c5df018e | 659 | uint32_t pic_intack_read(CPUState *env); |
c20709aa | 660 | void pic_info(void); |
4a0fb71e | 661 | void irq_info(void); |
80cabfad FB |
662 | |
663 | /* i8254.c */ | |
664 | ||
665 | #define PIT_FREQ 1193182 | |
666 | ||
ec844b96 FB |
667 | typedef struct PITState PITState; |
668 | ||
669 | PITState *pit_init(int base, int irq); | |
670 | void pit_set_gate(PITState *pit, int channel, int val); | |
671 | int pit_get_gate(PITState *pit, int channel); | |
672 | int pit_get_out(PITState *pit, int channel, int64_t current_time); | |
80cabfad FB |
673 | |
674 | /* pc.c */ | |
675 | void pc_init(int ram_size, int vga_ram_size, int boot_device, | |
676 | DisplayState *ds, const char **fd_filename, int snapshot, | |
677 | const char *kernel_filename, const char *kernel_cmdline, | |
678 | const char *initrd_filename); | |
679 | ||
26aa7d72 FB |
680 | /* ppc.c */ |
681 | void ppc_init (int ram_size, int vga_ram_size, int boot_device, | |
682 | DisplayState *ds, const char **fd_filename, int snapshot, | |
683 | const char *kernel_filename, const char *kernel_cmdline, | |
684 | const char *initrd_filename); | |
77d4bc34 FB |
685 | void ppc_prep_init (int ram_size, int vga_ram_size, int boot_device, |
686 | DisplayState *ds, const char **fd_filename, int snapshot, | |
687 | const char *kernel_filename, const char *kernel_cmdline, | |
688 | const char *initrd_filename); | |
689 | void ppc_chrp_init(int ram_size, int vga_ram_size, int boot_device, | |
690 | DisplayState *ds, const char **fd_filename, int snapshot, | |
691 | const char *kernel_filename, const char *kernel_cmdline, | |
692 | const char *initrd_filename); | |
8cc43fef FB |
693 | #ifdef TARGET_PPC |
694 | ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq); | |
695 | #endif | |
64201201 | 696 | void PREP_debug_write (void *opaque, uint32_t addr, uint32_t val); |
77d4bc34 FB |
697 | |
698 | extern CPUWriteMemoryFunc *PPC_io_write[]; | |
699 | extern CPUReadMemoryFunc *PPC_io_read[]; | |
700 | extern int prep_enabled; | |
26aa7d72 | 701 | |
64201201 FB |
702 | /* NVRAM helpers */ |
703 | #include "hw/m48t59.h" | |
704 | ||
705 | void NVRAM_set_byte (m48t59_t *nvram, uint32_t addr, uint8_t value); | |
706 | uint8_t NVRAM_get_byte (m48t59_t *nvram, uint32_t addr); | |
707 | void NVRAM_set_word (m48t59_t *nvram, uint32_t addr, uint16_t value); | |
708 | uint16_t NVRAM_get_word (m48t59_t *nvram, uint32_t addr); | |
709 | void NVRAM_set_lword (m48t59_t *nvram, uint32_t addr, uint32_t value); | |
710 | uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr); | |
711 | void NVRAM_set_string (m48t59_t *nvram, uint32_t addr, | |
712 | const unsigned char *str, uint32_t max); | |
713 | int NVRAM_get_string (m48t59_t *nvram, uint8_t *dst, uint16_t addr, int max); | |
714 | void NVRAM_set_crc (m48t59_t *nvram, uint32_t addr, | |
715 | uint32_t start, uint32_t count); | |
716 | int PPC_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size, | |
717 | const unsigned char *arch, | |
718 | uint32_t RAM_size, int boot_device, | |
719 | uint32_t kernel_image, uint32_t kernel_size, | |
28b9b5af | 720 | const char *cmdline, |
64201201 | 721 | uint32_t initrd_image, uint32_t initrd_size, |
28b9b5af FB |
722 | uint32_t NVRAM_image, |
723 | int width, int height, int depth); | |
64201201 | 724 | |
63066f4f FB |
725 | /* adb.c */ |
726 | ||
727 | #define MAX_ADB_DEVICES 16 | |
728 | ||
e2733d20 | 729 | #define ADB_MAX_OUT_LEN 16 |
63066f4f | 730 | |
e2733d20 | 731 | typedef struct ADBDevice ADBDevice; |
63066f4f | 732 | |
e2733d20 FB |
733 | /* buf = NULL means polling */ |
734 | typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out, | |
735 | const uint8_t *buf, int len); | |
12c28fed FB |
736 | typedef int ADBDeviceReset(ADBDevice *d); |
737 | ||
63066f4f FB |
738 | struct ADBDevice { |
739 | struct ADBBusState *bus; | |
740 | int devaddr; | |
741 | int handler; | |
e2733d20 | 742 | ADBDeviceRequest *devreq; |
12c28fed | 743 | ADBDeviceReset *devreset; |
63066f4f FB |
744 | void *opaque; |
745 | }; | |
746 | ||
747 | typedef struct ADBBusState { | |
748 | ADBDevice devices[MAX_ADB_DEVICES]; | |
749 | int nb_devices; | |
e2733d20 | 750 | int poll_index; |
63066f4f FB |
751 | } ADBBusState; |
752 | ||
e2733d20 FB |
753 | int adb_request(ADBBusState *s, uint8_t *buf_out, |
754 | const uint8_t *buf, int len); | |
755 | int adb_poll(ADBBusState *s, uint8_t *buf_out); | |
63066f4f FB |
756 | |
757 | ADBDevice *adb_register_device(ADBBusState *s, int devaddr, | |
e2733d20 | 758 | ADBDeviceRequest *devreq, |
12c28fed | 759 | ADBDeviceReset *devreset, |
63066f4f FB |
760 | void *opaque); |
761 | void adb_kbd_init(ADBBusState *bus); | |
762 | void adb_mouse_init(ADBBusState *bus); | |
763 | ||
764 | /* cuda.c */ | |
765 | ||
766 | extern ADBBusState adb_bus; | |
28b9b5af | 767 | int cuda_init(openpic_t *openpic, int irq); |
63066f4f | 768 | |
c4b1fcc0 FB |
769 | /* monitor.c */ |
770 | void monitor_init(void); | |
40c3bac3 | 771 | void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2))); |
c4b1fcc0 FB |
772 | void term_flush(void); |
773 | void term_print_help(void); | |
774 | ||
8a7ddc38 FB |
775 | /* gdbstub.c */ |
776 | ||
777 | #define DEFAULT_GDBSTUB_PORT 1234 | |
778 | ||
779 | int gdbserver_start(int port); | |
780 | ||
fc01f7e7 | 781 | #endif /* VL_H */ |