VirtualBox

source: vbox/trunk/include/VBox/pdm.h@ 3700

Last change on this file since 3700 was 3644, checked in by vboxsync, 18 years ago

Added PDMIHOSTDEVICEPORT and PDMINTERFACE_HOST_DEVICE_CONNECTOR, and a Parallel class. Contributed by: Alexander Eichner

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 265.2 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * If you received this file as part of a commercial VirtualBox
17 * distribution, then only the terms of your commercial VirtualBox
18 * license agreement apply instead of the previous paragraph.
19 */
20
21#ifndef ___VBox_pdm_h
22#define ___VBox_pdm_h
23
24#include <VBox/cdefs.h>
25#include <VBox/types.h>
26#include <VBox/iom.h>
27#include <VBox/ssm.h>
28#include <VBox/cfgm.h>
29#include <VBox/dbgf.h>
30#include <VBox/err.h>
31#include <VBox/pci.h>
32
33#include <iprt/critsect.h>
34#include <iprt/stdarg.h>
35
36
37__BEGIN_DECLS
38
39/** @defgroup grp_pdm The Pluggable Device Manager API
40 * @{
41 */
42
43/** Source position.
44 * @deprecated Use RT_SRC_POS */
45#define PDM_SRC_POS RT_SRC_POS
46
47/** Source position declaration.
48 * @deprecated Use RT_SRC_POS_DECL */
49#define PDM_SRC_POS_DECL RT_SRC_POS_DECL
50
51/** Source position arguments.
52 * @deprecated Use RT_SRC_POS_ARGS */
53#define PDM_SRC_POS_ARGS RT_SRC_POS_ARGS
54
55
56/** @defgroup grp_pdm_queue The PDM Queue
57 * @ingroup grp_pdm
58 * @{
59 */
60
61/** Pointer to a PDM queue. Also called PDM queue handle. */
62typedef struct PDMQUEUE *PPDMQUEUE;
63
64/** Pointer to a PDM queue item core. */
65typedef struct PDMQUEUEITEMCORE *PPDMQUEUEITEMCORE;
66
67/**
68 * PDM queue item core.
69 */
70typedef struct PDMQUEUEITEMCORE
71{
72 /** Pointer to the next item in the pending list - HC Pointer. */
73 HCPTRTYPE(PPDMQUEUEITEMCORE) pNextHC;
74 /** Pointer to the next item in the pending list - GC Pointer. */
75 GCPTRTYPE(PPDMQUEUEITEMCORE) pNextGC;
76#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
77 uint32_t Alignment0;
78#endif
79} PDMQUEUEITEMCORE;
80
81
82/**
83 * Queue consumer callback for devices.
84 *
85 * @returns Success indicator.
86 * If false the item will not be removed and the flushing will stop.
87 * @param pDevIns The device instance.
88 * @param pItem The item to consume. Upon return this item will be freed.
89 */
90typedef DECLCALLBACK(bool) FNPDMQUEUEDEV(PPDMDEVINS pDevIns, PPDMQUEUEITEMCORE pItem);
91/** Pointer to a FNPDMQUEUEDEV(). */
92typedef FNPDMQUEUEDEV *PFNPDMQUEUEDEV;
93
94/**
95 * Queue consumer callback for drivers.
96 *
97 * @returns Success indicator.
98 * If false the item will not be removed and the flushing will stop.
99 * @param pDrvIns The driver instance.
100 * @param pItem The item to consume. Upon return this item will be freed.
101 */
102typedef DECLCALLBACK(bool) FNPDMQUEUEDRV(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItem);
103/** Pointer to a FNPDMQUEUEDRV(). */
104typedef FNPDMQUEUEDRV *PFNPDMQUEUEDRV;
105
106/**
107 * Queue consumer callback for internal component.
108 *
109 * @returns Success indicator.
110 * If false the item will not be removed and the flushing will stop.
111 * @param pVM The VM handle.
112 * @param pItem The item to consume. Upon return this item will be freed.
113 */
114typedef DECLCALLBACK(bool) FNPDMQUEUEINT(PVM pVM, PPDMQUEUEITEMCORE pItem);
115/** Pointer to a FNPDMQUEUEINT(). */
116typedef FNPDMQUEUEINT *PFNPDMQUEUEINT;
117
118/**
119 * Queue consumer callback for external component.
120 *
121 * @returns Success indicator.
122 * If false the item will not be removed and the flushing will stop.
123 * @param pvUser User argument.
124 * @param pItem The item to consume. Upon return this item will be freed.
125 */
126typedef DECLCALLBACK(bool) FNPDMQUEUEEXT(void *pvUser, PPDMQUEUEITEMCORE pItem);
127/** Pointer to a FNPDMQUEUEEXT(). */
128typedef FNPDMQUEUEEXT *PFNPDMQUEUEEXT;
129
130/**
131 * Create a queue with a device owner.
132 *
133 * @returns VBox status code.
134 * @param pVM VM handle.
135 * @param pDevIns Device instance.
136 * @param cbItem Size a queue item.
137 * @param cItems Number of items in the queue.
138 * @param cMilliesInterval Number of milliseconds between polling the queue.
139 * If 0 then the emulation thread will be notified whenever an item arrives.
140 * @param pfnCallback The consumer function.
141 * @param fGCEnabled Set if the queue must be usable from GC.
142 * @param ppQueue Where to store the queue handle on success.
143 * @thread Emulation thread only.
144 */
145PDMR3DECL(int) PDMR3QueueCreateDevice(PVM pVM, PPDMDEVINS pDevIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
146 PFNPDMQUEUEDEV pfnCallback, bool fGCEnabled, PPDMQUEUE *ppQueue);
147
148/**
149 * Create a queue with a driver owner.
150 *
151 * @returns VBox status code.
152 * @param pVM VM handle.
153 * @param pDrvIns Driver instance.
154 * @param cbItem Size a queue item.
155 * @param cItems Number of items in the queue.
156 * @param cMilliesInterval Number of milliseconds between polling the queue.
157 * If 0 then the emulation thread will be notified whenever an item arrives.
158 * @param pfnCallback The consumer function.
159 * @param ppQueue Where to store the queue handle on success.
160 * @thread The emulation thread.
161 */
162PDMR3DECL(int) PDMR3QueueCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
163 PFNPDMQUEUEDRV pfnCallback, PPDMQUEUE *ppQueue);
164
165/**
166 * Create a queue with an internal owner.
167 *
168 * @returns VBox status code.
169 * @param pVM VM handle.
170 * @param cbItem Size a queue item.
171 * @param cItems Number of items in the queue.
172 * @param cMilliesInterval Number of milliseconds between polling the queue.
173 * If 0 then the emulation thread will be notified whenever an item arrives.
174 * @param pfnCallback The consumer function.
175 * @param fGCEnabled Set if the queue must be usable from GC.
176 * @param ppQueue Where to store the queue handle on success.
177 * @thread Emulation thread only.
178 */
179PDMR3DECL(int) PDMR3QueueCreateInternal(PVM pVM, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
180 PFNPDMQUEUEINT pfnCallback, bool fGCEnabled, PPDMQUEUE *ppQueue);
181
182/**
183 * Create a queue with an external owner.
184 *
185 * @returns VBox status code.
186 * @param pVM VM handle.
187 * @param cbItem Size a queue item.
188 * @param cItems Number of items in the queue.
189 * @param cMilliesInterval Number of milliseconds between polling the queue.
190 * If 0 then the emulation thread will be notified whenever an item arrives.
191 * @param pfnCallback The consumer function.
192 * @param pvUser The user argument to the consumer function.
193 * @param ppQueue Where to store the queue handle on success.
194 * @thread The emulation thread.
195 */
196PDMR3DECL(int) PDMR3QueueCreateExternal(PVM pVM, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
197 PFNPDMQUEUEEXT pfnCallback, void *pvUser, PPDMQUEUE *ppQueue);
198
199/**
200 * Destroy a queue.
201 *
202 * @returns VBox status code.
203 * @param pQueue Queue to destroy.
204 * @thread The emulation thread.
205 */
206PDMR3DECL(int) PDMR3QueueDestroy(PPDMQUEUE pQueue);
207
208/**
209 * Destroy a all queues owned by the specified device.
210 *
211 * @returns VBox status code.
212 * @param pVM VM handle.
213 * @param pDevIns Device instance.
214 * @thread Emulation thread only.
215 */
216PDMR3DECL(int) PDMR3QueueDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
217
218/**
219 * Destroy a all queues owned by the specified driver.
220 *
221 * @returns VBox status code.
222 * @param pVM VM handle.
223 * @param pDrvIns Driver instance.
224 * @thread Emulation thread only.
225 */
226PDMR3DECL(int) PDMR3QueueDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
227
228/**
229 * Flushes pending queues.
230 * This is a forced action callback.
231 *
232 * @param pVM VM handle.
233 * @thread The emulation thread.
234 */
235PDMR3DECL(void) PDMR3QueueFlushAll(PVM pVM);
236
237/**
238 * This is a worker function used by PDMQueueFlush to perform the
239 * flush in ring-3.
240 *
241 * The queue which should be flushed is pointed to by either pQueueFlushGC,
242 * pQueueFlushHC, or pQueueue. This function will flush that queue and
243 * recalc the queue FF.
244 *
245 * @param pVM The VM handle.
246 * @param pQueue The queue to flush. Only used in Ring-3.
247 */
248PDMR3DECL(void) PDMR3QueueFlushWorker(PVM pVM, PPDMQUEUE pQueue);
249
250/**
251 * Flushes a PDM queue.
252 *
253 * @param pQueue The queue handle.
254 */
255PDMDECL(void) PDMQueueFlush(PPDMQUEUE pQueue);
256
257/**
258 * Allocate an item from a queue.
259 * The allocated item must be handed on to PDMQueueInsert() after the
260 * data has been filled in.
261 *
262 * @returns Pointer to allocated queue item.
263 * @returns NULL on failure. The queue is exhausted.
264 * @param pQueue The queue handle.
265 * @thread Any thread.
266 */
267PDMDECL(PPDMQUEUEITEMCORE) PDMQueueAlloc(PPDMQUEUE pQueue);
268
269/**
270 * Queue an item.
271 * The item must have been obtained using PDMQueueAlloc(). Once the item
272 * has been passed to this function it must not be touched!
273 *
274 * @param pQueue The queue handle.
275 * @param pItem The item to insert.
276 * @thread Any thread.
277 */
278PDMDECL(void) PDMQueueInsert(PPDMQUEUE pQueue, PPDMQUEUEITEMCORE pItem);
279
280/**
281 * Queue an item.
282 * The item must have been obtained using PDMQueueAlloc(). Once the item
283 * have been passed to this function it must not be touched!
284 *
285 * @param pQueue The queue handle.
286 * @param pItem The item to insert.
287 * @param NanoMaxDelay The maximum delay before processing the queue, in nanoseconds.
288 * This applies only to GC.
289 * @thread Any thread.
290 */
291PDMDECL(void) PDMQueueInsertEx(PPDMQUEUE pQueue, PPDMQUEUEITEMCORE pItem, uint64_t NanoMaxDelay);
292
293
294/**
295 * Gets the GC pointer for the specified queue.
296 *
297 * @returns The GC address of the queue.
298 * @returns NULL if pQueue is invalid.
299 * @param pQueue The queue handle.
300 */
301PDMDECL(GCPTRTYPE(PPDMQUEUE)) PDMQueueGCPtr(PPDMQUEUE pQueue);
302
303/** @} */
304
305
306
307/** @defgroup grp_pdm_critsect The PDM Critical Section
308 * @ingroup grp_pdm
309 * @{
310 */
311
312/**
313 * A PDM critical section.
314 * Initialize using PDMDRVHLP::pfnCritSectInit().
315 */
316typedef union PDMCRITSECT
317{
318 /** Padding. */
319 uint8_t padding[HC_ARCH_BITS == 64 ? 0xb8 : 0x80];
320#ifdef PDMCRITSECTINT_DECLARED
321 /** The internal structure (not normally visible). */
322 struct PDMCRITSECTINT s;
323#endif
324} PDMCRITSECT;
325/** Pointer to a PDM critical section. */
326typedef PDMCRITSECT *PPDMCRITSECT;
327/** Pointer to a const PDM critical section. */
328typedef const PDMCRITSECT *PCPDMCRITSECT;
329
330/**
331 * Initializes a PDM critical section for internal use.
332 *
333 * The PDM critical sections are derived from the IPRT critical sections, but
334 * works in GC as well.
335 *
336 * @returns VBox status code.
337 * @param pVM The VM handle.
338 * @param pDevIns Device instance.
339 * @param pCritSect Pointer to the critical section.
340 * @param pszName The name of the critical section (for statistics).
341 */
342PDMR3DECL(int) PDMR3CritSectInit(PVM pVM, PPDMCRITSECT pCritSect, const char *pszName);
343
344/**
345 * Leaves a critical section entered with PDMCritSectEnter().
346 *
347 * @returns VINF_SUCCESS if entered successfully.
348 * @returns rcBusy when encountering a busy critical section in GC/R0.
349 * @returns VERR_SEM_DESTROYED if the critical section is dead.
350 *
351 * @param pCritSect The PDM critical section to enter.
352 * @param rcBusy The status code to return when we're in GC or R0
353 * and the section is busy.
354 */
355PDMDECL(int) PDMCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy);
356
357/**
358 * Leaves a critical section entered with PDMCritSectEnter().
359 *
360 * @param pCritSect The PDM critical section to leave.
361 */
362PDMDECL(void) PDMCritSectLeave(PPDMCRITSECT pCritSect);
363
364/**
365 * Checks the caller is the owner of the critical section.
366 *
367 * @returns true if owner.
368 * @returns false if not owner.
369 * @param pCritSect The critical section.
370 */
371PDMDECL(bool) PDMCritSectIsOwner(PCPDMCRITSECT pCritSect);
372
373/**
374 * Try enter a critical section.
375 *
376 * @returns VINF_SUCCESS on success.
377 * @returns VERR_SEM_BUSY if the critsect was owned.
378 * @returns VERR_SEM_NESTED if nested enter on a no nesting section. (Asserted.)
379 * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
380 * @param pCritSect The critical section.
381 */
382PDMR3DECL(int) PDMR3CritSectTryEnter(PPDMCRITSECT pCritSect);
383
384/**
385 * Schedule a event semaphore for signalling upon critsect exit.
386 *
387 * @returns VINF_SUCCESS on success.
388 * @returns VERR_TOO_MANY_SEMAPHORES if an event was already scheduled.
389 * @returns VERR_NOT_OWNER if we're not the critsect owner.
390 * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
391 * @param pCritSect The critical section.
392 * @param EventToSignal The semapore that should be signalled.
393 */
394PDMR3DECL(int) PDMR3CritSectScheduleExitEvent(PPDMCRITSECT pCritSect, RTSEMEVENT EventToSignal);
395
396/**
397 * Deletes the critical section.
398 *
399 * @returns VBox status code.
400 * @param pCritSect The PDM critical section to destroy.
401 */
402PDMR3DECL(int) PDMR3CritSectDelete(PPDMCRITSECT pCritSect);
403
404/**
405 * Deletes all remaining critical sections.
406 *
407 * This is called at the end of the termination process.
408 *
409 * @returns VBox status.
410 * First error code, rest is lost.
411 * @param pVM The VM handle.
412 * @remark Don't confuse this with PDMR3CritSectDelete.
413 */
414PDMDECL(int) PDMR3CritSectTerm(PVM pVM);
415
416/**
417 * Process the critical sections queued for ring-3 'leave'.
418 *
419 * @param pVM The VM handle.
420 */
421PDMR3DECL(void) PDMR3CritSectFF(PVM pVM);
422
423/** @} */
424
425
426/** @group grp_pdm_thread
427 * @{
428 */
429
430/**
431 * The thread state
432 */
433typedef enum PDMTHREADSTATE
434{
435 /** The usual invalid 0 entry. */
436 PDMTHREADSTATE_INVALID = 0,
437 /** The thread is initializing.
438 * Prev state: none
439 * Next state: suspended, terminating (error) */
440 PDMTHREADSTATE_INITIALIZING,
441 /** The thread has been asked to suspend.
442 * Prev state: running
443 * Next state: suspended */
444 PDMTHREADSTATE_SUSPENDING,
445 /** The thread is supended.
446 * Prev state: suspending, initializing
447 * Next state: resuming, terminated. */
448 PDMTHREADSTATE_SUSPENDED,
449 /** The thread is active.
450 * Prev state: suspended
451 * Next state: running, terminating. */
452 PDMTHREADSTATE_RESUMING,
453 /** The thread is active.
454 * Prev state: resuming
455 * Next state: suspending, terminating. */
456 PDMTHREADSTATE_RUNNING,
457 /** The thread has been asked to terminate.
458 * Prev state: initializing, suspended, resuming, running
459 * Next state: terminated. */
460 PDMTHREADSTATE_TERMINATING,
461 /** The thread is terminating / has terminated.
462 * Prev state: terminating
463 * Next state: none */
464 PDMTHREADSTATE_TERMINATED,
465 /** The usual 32-bit hack. */
466 PDMTHREADSTATE_32BIT_HACK = 0x7fffffff
467} PDMTHREADSTATE;
468
469/** A pointer to a PDM thread. */
470typedef R3PTRTYPE(struct PDMTHREAD *) PPDMTHREAD;
471/** A pointer to a pointer to a PDM thread. */
472typedef PPDMTHREAD *PPPDMTHREAD;
473
474/**
475 * PDM thread, device variation.
476 *
477 * @returns VBox status code.
478 * @param pDevIns The device instance.
479 * @param pThread The PDM thread data.
480 */
481typedef int FNPDMTHREADDEV(PPDMDEVINS pDevIns, PPDMTHREAD pThread);
482/** Pointer to a FNPDMTHREADDEV(). */
483typedef FNPDMTHREADDEV *PFNPDMTHREADDEV;
484
485/**
486 * PDM thread, driver variation.
487 *
488 * @returns VBox status code.
489 * @param pDrvIns The driver instance.
490 * @param pThread The PDM thread data.
491 */
492typedef int FNPDMTHREADDRV(PPDMDRVINS pDrvIns, PPDMTHREAD pThread);
493/** Pointer to a FNPDMTHREADDRV(). */
494typedef FNPDMTHREADDRV *PFNPDMTHREADDRV;
495
496/**
497 * PDM thread, driver variation.
498 *
499 * @returns VBox status code.
500 * @param pVM The VM handle.
501 * @param pThread The PDM thread data.
502 */
503typedef int FNPDMTHREADINT(PVM pVM, PPDMTHREAD pThread);
504/** Pointer to a FNPDMTHREADINT(). */
505typedef FNPDMTHREADINT *PFNPDMTHREADINT;
506
507/**
508 * PDM thread, driver variation.
509 *
510 * @returns VBox status code.
511 * @param pThread The PDM thread data.
512 */
513typedef int FNPDMTHREADEXT(PPDMTHREAD pThread);
514/** Pointer to a FNPDMTHREADEXT(). */
515typedef FNPDMTHREADEXT *PFNPDMTHREADEXT;
516
517
518
519/**
520 * PDM thread wakup call, device variation.
521 *
522 * @returns VBox status code.
523 * @param pDevIns The device instance.
524 * @param pThread The PDM thread data.
525 */
526typedef int FNPDMTHREADWAKEUPDEV(PPDMDEVINS pDevIns, PPDMTHREAD pThread);
527/** Pointer to a FNPDMTHREADDEV(). */
528typedef FNPDMTHREADWAKEUPDEV *PFNPDMTHREADWAKEUPDEV;
529
530/**
531 * PDM thread wakup call, driver variation.
532 *
533 * @returns VBox status code.
534 * @param pDrvIns The driver instance.
535 * @param pThread The PDM thread data.
536 */
537typedef int FNPDMTHREADWAKEUPDRV(PPDMDRVINS pDrvIns, PPDMTHREAD pThread);
538/** Pointer to a FNPDMTHREADDRV(). */
539typedef FNPDMTHREADWAKEUPDRV *PFNPDMTHREADWAKEUPDRV;
540
541/**
542 * PDM thread wakup call, internal variation.
543 *
544 * @returns VBox status code.
545 * @param pVM The VM handle.
546 * @param pThread The PDM thread data.
547 */
548typedef int FNPDMTHREADWAKEUPINT(PVM pVM, PPDMTHREAD pThread);
549/** Pointer to a FNPDMTHREADWAKEUPINT(). */
550typedef FNPDMTHREADWAKEUPINT *PFNPDMTHREADWAKEUPINT;
551
552/**
553 * PDM thread wakup call, external variation.
554 *
555 * @returns VBox status code.
556 * @param pThread The PDM thread data.
557 */
558typedef int FNPDMTHREADWAKEUPEXT(PPDMTHREAD pThread);
559/** Pointer to a FNPDMTHREADEXT(). */
560typedef FNPDMTHREADWAKEUPEXT *PFNPDMTHREADWAKEUPEXT;
561
562
563/**
564 * PDM Thread instance data.
565 */
566typedef struct PDMTHREAD
567{
568 /** PDMTHREAD_VERSION. */
569 uint32_t u32Version;
570 /** The thread state. */
571 PDMTHREADSTATE volatile enmState;
572 /** The thread handle. */
573 RTTHREAD Thread;
574 /** The user parameter. */
575 R3PTRTYPE(void *) pvUser;
576 /** Data specific to the kind of thread.
577 * This should really be in PDMTHREADINT, but is placed here because of the
578 * function pointer typedefs. So, don't touch these, please.
579 */
580 union
581 {
582 /** PDMTHREADTYPE_DEVICE data. */
583 struct
584 {
585 /** The device instance. */
586 PPDMDEVINSR3 pDevIns;
587 /** The thread function. */
588 R3PTRTYPE(PFNPDMTHREADDEV) pfnThread;
589 /** Thread. */
590 R3PTRTYPE(PFNPDMTHREADWAKEUPDEV) pfnWakeup;
591 } Dev;
592
593 /** PDMTHREADTYPE_DRIVER data. */
594 struct
595 {
596 /** The driver instance. */
597 R3PTRTYPE(PPDMDRVINS) pDrvIns;
598 /** The thread function. */
599 R3PTRTYPE(PFNPDMTHREADDRV) pfnThread;
600 /** Thread. */
601 R3PTRTYPE(PFNPDMTHREADWAKEUPDRV) pfnWakeup;
602 } Drv;
603
604 /** PDMTHREADTYPE_INTERNAL data. */
605 struct
606 {
607 /** The thread function. */
608 R3PTRTYPE(PFNPDMTHREADINT) pfnThread;
609 /** Thread. */
610 R3PTRTYPE(PFNPDMTHREADWAKEUPINT) pfnWakeup;
611 } Int;
612
613 /** PDMTHREADTYPE_EXTERNAL data. */
614 struct
615 {
616 /** The thread function. */
617 R3PTRTYPE(PFNPDMTHREADEXT) pfnThread;
618 /** Thread. */
619 R3PTRTYPE(PFNPDMTHREADWAKEUPEXT) pfnWakeup;
620 } Ext;
621 } u;
622
623 /** Internal data. */
624 union
625 {
626#ifdef PDMTHREADINT_DECLARED
627 PDMTHREADINT s;
628#endif
629 uint8_t padding[64];
630 } Internal;
631} PDMTHREAD;
632
633/** PDMTHREAD::u32Version value. */
634#define PDMTHREAD_VERSION 0xef010000
635
636
637/** @} */
638
639
640
641/** @defgroup grp_pdm_interfaces Interfaces
642 * @ingroup grp_pdm
643 * @{
644 */
645
646/**
647 * Driver interface identficators.
648 */
649typedef enum PDMINTERFACE
650{
651 /** PDMIBASE - The interface everyone supports. */
652 PDMINTERFACE_BASE = 1,
653 /** PDMIMOUSEPORT - The mouse port interface. (Down) Coupled with PDMINTERFACE_MOUSE_CONNECTOR. */
654 PDMINTERFACE_MOUSE_PORT,
655 /** PDMIMOUSECONNECTOR - The mouse connector interface. (Up) Coupled with PDMINTERFACE_MOUSE_PORT. */
656 PDMINTERFACE_MOUSE_CONNECTOR,
657 /** PDMIKEYBOARDPORT - The keyboard port interface. (Down) Coupled with PDMINTERFACE_KEYBOARD_CONNECTOR. */
658 PDMINTERFACE_KEYBOARD_PORT,
659 /** PDMIKEYBOARDCONNECTOR - The keyboard connector interface. (Up) Coupled with PDMINTERFACE_KEYBOARD_PORT. */
660 PDMINTERFACE_KEYBOARD_CONNECTOR,
661 /** PDMIDISPLAYPORT - The display port interface. (Down) Coupled with PDMINTERFACE_DISPLAY_CONNECTOR. */
662 PDMINTERFACE_DISPLAY_PORT,
663 /** PDMIDISPLAYCONNECTOR - The display connector interface. (Up) Coupled with PDMINTERFACE_DISPLAY_PORT. */
664 PDMINTERFACE_DISPLAY_CONNECTOR,
665 /** PDMICHARPORT - The char notify interface. (Down) Coupled with PDMINTERFACE_CHAR. */
666 PDMINTERFACE_CHAR_PORT,
667 /** PDMICHAR - The char driver interface. (Up) Coupled with PDMINTERFACE_CHAR_PORT. */
668 PDMINTERFACE_CHAR,
669 /** PDMISTREAM - The stream driver interface (Up) No coupling.
670 * Used by a char driver to implement PDMINTERFACE_CHAR. */
671 PDMINTERFACE_STREAM,
672 /** PDMIBLOCKPORT - The block notify interface (Down) Coupled with PDMINTERFACE_BLOCK. */
673 PDMINTERFACE_BLOCK_PORT,
674 /** PDMIBLOCK - The block driver interface (Up) Coupled with PDMINTERFACE_BLOCK_PORT. */
675 PDMINTERFACE_BLOCK,
676 /** PDMIBLOCKBIOS - The block bios interface. (External) */
677 PDMINTERFACE_BLOCK_BIOS,
678 /** PDMIMOUNTNOTIFY - The mountable notification interface. (Down) Coupled with PDMINTERFACE_MOUNT. */
679 PDMINTERFACE_MOUNT_NOTIFY,
680 /** PDMIMOUNT - The mountable interface. (Up) Coupled with PDMINTERFACE_MOUNT_NOTIFY. */
681 PDMINTERFACE_MOUNT,
682 /** PDMIMEDIA - The media interface. (Up) No coupling.
683 * Used by a block unit driver to implement PDMINTERFACE_BLOCK and PDMINTERFACE_BLOCK_BIOS. */
684 PDMINTERFACE_MEDIA,
685 /** PDMIISCSITRANSPORT - The iSCSI transport interface (Up) No coupling.
686 * used by the iSCSI media driver. */
687 PDMINTERFACE_ISCSITRANSPORT,
688
689 /** PDMINETWORKPORT - The network port interface. (Down) Coupled with PDMINTERFACE_NETWORK_CONNECTOR. */
690 PDMINTERFACE_NETWORK_PORT,
691 /** PDMINETWORKPORT - The network connector interface. (Up) Coupled with PDMINTERFACE_NETWORK_PORT. */
692 PDMINTERFACE_NETWORK_CONNECTOR,
693 /** PDMINETWORKCONFIG - The network configuartion interface. (Main) Used by the managment api. */
694 PDMINTERFACE_NETWORK_CONFIG,
695
696 /** PDMIAUDIOCONNECTOR - The audio driver interface. (Up) No coupling. */
697 PDMINTERFACE_AUDIO_CONNECTOR,
698
699 /** PDMIAUDIOSNIFFERPORT - The Audio Sniffer Device port interface. */
700 PDMINTERFACE_AUDIO_SNIFFER_PORT,
701 /** PDMIAUDIOSNIFFERCONNECTOR - The Audio Sniffer Driver connector interface. */
702 PDMINTERFACE_AUDIO_SNIFFER_CONNECTOR,
703
704 /** PDMIVMMDEVPORT - The VMM Device port interface. */
705 PDMINTERFACE_VMMDEV_PORT,
706 /** PDMIVMMDEVCONNECTOR - The VMM Device connector interface. */
707 PDMINTERFACE_VMMDEV_CONNECTOR,
708
709 /** PDMILEDPORTS - The generic LED port interface. (Down) Coupled with PDMINTERFACE_LED_CONNECTORS. */
710 PDMINTERFACE_LED_PORTS,
711 /** PDMILEDCONNECTORS - The generic LED connector interface. (Up) Coupled with PDMINTERFACE_LED_PORTS. */
712 PDMINTERFACE_LED_CONNECTORS,
713
714 /** PDMIACPIPORT - ACPI port interface. (Down) Coupled with PDMINTERFACE_ACPI_CONNECTOR. */
715 PDMINTERFACE_ACPI_PORT,
716 /** PDMIACPICONNECTOR - ACPI connector interface. (Up) Coupled with PDMINTERFACE_ACPI_PORT. */
717 PDMINTERFACE_ACPI_CONNECTOR,
718
719 /** PDMIHGCMPORT - The Host-Guest communication manager port interface. Normally implemented by VMMDev. */
720 PDMINTERFACE_HGCM_PORT,
721 /** PDMIHGCMCONNECTOR - The Host-Guest communication manager connector interface. Normally implemented by Main::VMMDevInterface. */
722 PDMINTERFACE_HGCM_CONNECTOR,
723
724 /** VUSBIROOTHUBPORT - VUSB RootHub port interface. (Down) Coupled with PDMINTERFACE_USB_RH_CONNECTOR. */
725 PDMINTERFACE_VUSB_RH_PORT,
726 /** VUSBIROOTHUBCONNECTOR - VUSB RootHub connector interface. (Up) Coupled with PDMINTERFACE_USB_RH_PORT. */
727 PDMINTERFACE_VUSB_RH_CONNECTOR,
728 /** VUSBIROOTHUBCONNECTOR - VUSB RootHub configuration interface. (Main) Used by the managment api. */
729 PDMINTERFACE_VUSB_RH_CONFIG,
730
731 /** VUSBROOTHUBCONNECTOR - VUSB Device interface. (Up) No coupling. */
732 PDMINTERFACE_VUSB_DEVICE,
733
734 /** PDMIHOSTDEVICEPORT - The Host Device port interface. (Down) Coupled with PDMINTERFACE_HOST_DEVICE_CONNECTOR. */
735 PDMINTERFACE_HOST_DEVICE_PORT,
736 /** PDMIHOSTDEVICECONNECTOR - The Host device connector interface (Up) Coupled with PDMINTERFACE_HOST_DEVICE_PORT. */
737 PDMINTERFACE_HOST_DEVICE_CONNECTOR,
738
739 /** Maximum interface number. */
740 PDMINTERFACE_MAX
741} PDMINTERFACE;
742
743
744/**
745 * PDM Driver Base Interface.
746 */
747typedef struct PDMIBASE
748{
749 /**
750 * Queries an interface to the driver.
751 *
752 * @returns Pointer to interface.
753 * @returns NULL if the interface was not supported by the driver.
754 * @param pInterface Pointer to this interface structure.
755 * @param enmInterface The requested interface identification.
756 * @thread Any thread.
757 */
758 DECLR3CALLBACKMEMBER(void *, pfnQueryInterface,(struct PDMIBASE *pInterface, PDMINTERFACE enmInterface));
759} PDMIBASE;
760/** Pointer to a PDM Driver Base Interface. */
761typedef PDMIBASE *PPDMIBASE;
762
763
764/**
765 * Dummy interface.
766 *
767 * This is used to typedef other dummy interfaces. The purpose of a dummy
768 * interface is to validate the logical function of a driver/device and
769 * full a natural interface pair.
770 */
771typedef struct PDMIDUMMY
772{
773 RTHCPTR pvDummy;
774} PDMIDUMMY;
775
776
777/** Pointer to a mouse port interface. */
778typedef struct PDMIMOUSEPORT *PPDMIMOUSEPORT;
779/**
780 * Mouse port interface.
781 * Pair with PDMIMOUSECONNECTOR.
782 */
783typedef struct PDMIMOUSEPORT
784{
785 /**
786 * Puts a mouse event.
787 * This is called by the source of mouse events. The event will be passed up until the
788 * topmost driver, which then calls the registered event handler.
789 *
790 * @returns VBox status code.
791 * @param pInterface Pointer to this interface structure.
792 * @param i32DeltaX The X delta.
793 * @param i32DeltaY The Y delta.
794 * @param i32DeltaZ The Z delta.
795 * @param fButtonStates The button states, see the PDMIMOUSEPORT_BUTTON_* \#defines.
796 * @thread The emulation thread.
797 */
798 DECLR3CALLBACKMEMBER(int, pfnPutEvent,(PPDMIMOUSEPORT pInterface, int32_t i32DeltaX, int32_t i32DeltaY, int32_t i32DeltaZ, uint32_t fButtonStates));
799} PDMIMOUSEPORT;
800
801/** Mouse button defines for PDMIMOUSEPORT::pfnPutEvent.
802 * @{ */
803#define PDMIMOUSEPORT_BUTTON_LEFT BIT(0)
804#define PDMIMOUSEPORT_BUTTON_RIGHT BIT(1)
805#define PDMIMOUSEPORT_BUTTON_MIDDLE BIT(2)
806/** @} */
807
808
809/**
810 * Mouse connector interface.
811 * Pair with PDMIMOUSEPORT.
812 */
813typedef PDMIDUMMY PDMIMOUSECONNECTOR;
814 /** Pointer to a mouse connector interface. */
815typedef PDMIMOUSECONNECTOR *PPDMIMOUSECONNECTOR;
816
817
818/** Pointer to a keyboard port interface. */
819typedef struct PDMIKEYBOARDPORT *PPDMIKEYBOARDPORT;
820/**
821 * Keyboard port interface.
822 * Pair with PDMIKEYBOARDCONNECTOR.
823 */
824typedef struct PDMIKEYBOARDPORT
825{
826 /**
827 * Puts a keyboard event.
828 * This is called by the source of keyboard events. The event will be passed up until the
829 * topmost driver, which then calls the registered event handler.
830 *
831 * @returns VBox status code.
832 * @param pInterface Pointer to this interface structure.
833 * @param u8KeyCode The keycode to queue.
834 * @thread The emulation thread.
835 */
836 DECLR3CALLBACKMEMBER(int, pfnPutEvent,(PPDMIKEYBOARDPORT pInterface, uint8_t u8KeyCode));
837} PDMIKEYBOARDPORT;
838
839/**
840 * Keyboard LEDs.
841 */
842typedef enum PDMKEYBLEDS
843{
844 /** No leds. */
845 PDMKEYBLEDS_NONE = 0x0000,
846 /** Num Lock */
847 PDMKEYBLEDS_NUMLOCK = 0x0001,
848 /** Caps Lock */
849 PDMKEYBLEDS_CAPSLOCK = 0x0002,
850 /** Scroll Lock */
851 PDMKEYBLEDS_SCROLLLOCK = 0x0004
852} PDMKEYBLEDS;
853
854/** Pointer to keyboard connector interface. */
855typedef struct PDMIKEYBOARDCONNECTOR *PPDMIKEYBOARDCONNECTOR;
856
857
858/**
859 * Keyboard connector interface.
860 * Pair with PDMIKEYBOARDPORT
861 */
862typedef struct PDMIKEYBOARDCONNECTOR
863{
864 /**
865 * Notifies the the downstream driver about an LED change initiated by the guest.
866 *
867 * @param pInterface Pointer to the this interface.
868 * @param enmLeds The new led mask.
869 */
870 DECLR3CALLBACKMEMBER(void, pfnLedStatusChange,(PPDMIKEYBOARDCONNECTOR pInterface, PDMKEYBLEDS enmLeds));
871
872} PDMIKEYBOARDCONNECTOR;
873
874
875
876/** Pointer to a display port interface. */
877typedef struct PDMIDISPLAYPORT *PPDMIDISPLAYPORT;
878/**
879 * Display port interface.
880 * Pair with PDMIDISPLAYCONNECTOR.
881 */
882typedef struct PDMIDISPLAYPORT
883{
884 /**
885 * Update the display with any changed regions.
886 *
887 * Flushes any display changes to the memory pointed to by the
888 * PDMIDISPLAYCONNECTOR interface and calles PDMIDISPLAYCONNECTOR::pfnUpdateRect()
889 * while doing so.
890 *
891 * @returns VBox status code.
892 * @param pInterface Pointer to this interface.
893 * @thread The emulation thread.
894 */
895 DECLR3CALLBACKMEMBER(int, pfnUpdateDisplay,(PPDMIDISPLAYPORT pInterface));
896
897 /**
898 * Update the entire display.
899 *
900 * Flushes the entire display content to the memory pointed to by the
901 * PDMIDISPLAYCONNECTOR interface and calles PDMIDISPLAYCONNECTOR::pfnUpdateRect().
902 *
903 * @returns VBox status code.
904 * @param pInterface Pointer to this interface.
905 * @thread The emulation thread.
906 */
907 DECLR3CALLBACKMEMBER(int, pfnUpdateDisplayAll,(PPDMIDISPLAYPORT pInterface));
908
909 /**
910 * Return the current guest color depth in bits per pixel (bpp).
911 *
912 * As the graphics card is able to provide display updates with the bpp
913 * requested by the host, this method can be used to query the actual
914 * guest color depth.
915 *
916 * @returns VBox status code.
917 * @param pInterface Pointer to this interface.
918 * @param pcBits Where to store the current guest color depth.
919 * @thread Any thread.
920 */
921 DECLR3CALLBACKMEMBER(int, pfnQueryColorDepth,(PPDMIDISPLAYPORT pInterface, uint32_t *pcBits));
922
923 /**
924 * Sets the refresh rate and restart the timer.
925 * The rate is defined as the minimum interval between the return of
926 * one PDMIDISPLAYPORT::pfnRefresh() call to the next one.
927 *
928 * The interval timer will be restarted by this call. So at VM startup
929 * this function must be called to start the refresh cycle. The refresh
930 * rate is not saved, but have to be when resuming a loaded VM state.
931 *
932 * @returns VBox status code.
933 * @param pInterface Pointer to this interface.
934 * @param cMilliesInterval Number of millies between two refreshes.
935 * @thread Any thread.
936 */
937 DECLR3CALLBACKMEMBER(int, pfnSetRefreshRate,(PPDMIDISPLAYPORT pInterface, uint32_t cMilliesInterval));
938
939 /**
940 * Create a 32-bbp snapshot of the display.
941 *
942 * This will create a 32-bbp bitmap with dword aligned scanline length. Because
943 * of a wish for no locks in the graphics device, this must be called from the
944 * emulation thread.
945 *
946 * @param pInterface Pointer to this interface.
947 * @param pvData Pointer the buffer to copy the bits to.
948 * @param cbData Size of the buffer.
949 * @param pcx Where to store the width of the bitmap. (optional)
950 * @param pcy Where to store the height of the bitmap. (optional)
951 * @param pcbData Where to store the actual size of the bitmap. (optional)
952 * @thread The emulation thread.
953 */
954 DECLR3CALLBACKMEMBER(int, pfnSnapshot,(PPDMIDISPLAYPORT pInterface, void *pvData, size_t cbData, uint32_t *pcx, uint32_t *pcy, size_t *pcbData));
955
956 /**
957 * Copy bitmap to the display.
958 *
959 * This will convert and copy a 32-bbp bitmap (with dword aligned scanline length) to
960 * the memory pointed to by the PDMIDISPLAYCONNECTOR interface.
961 *
962 * @param pInterface Pointer to this interface.
963 * @param pvData Pointer to the bitmap bits.
964 * @param x The upper left corner x coordinate of the destination rectangle.
965 * @param y The upper left corner y coordinate of the destination rectangle.
966 * @param cx The width of the source and destination rectangles.
967 * @param cy The height of the source and destination rectangles.
968 * @thread The emulation thread.
969 * @remark This is just a convenience for using the bitmap conversions of the
970 * graphics device.
971 */
972 DECLR3CALLBACKMEMBER(int, pfnDisplayBlt,(PPDMIDISPLAYPORT pInterface, const void *pvData, uint32_t x, uint32_t y, uint32_t cx, uint32_t cy));
973
974 /**
975 * Render a rectangle from guest VRAM to Framebuffer.
976 *
977 * @param pInterface Pointer to this interface.
978 * @param x The upper left corner x coordinate of the rectangle to be updated.
979 * @param y The upper left corner y coordinate of the rectangle to be updated.
980 * @param cx The width of the rectangle to be updated.
981 * @param cy The height of the rectangle to be updated.
982 * @thread The emulation thread.
983 */
984 DECLR3CALLBACKMEMBER(void, pfnUpdateDisplayRect,(PPDMIDISPLAYPORT pInterface, int32_t x, int32_t y, uint32_t cx, uint32_t cy));
985
986 /**
987 * Inform the VGA device whether the Display is directly using the guest VRAM and there is no need
988 * to render the VRAM to the framebuffer memory.
989 *
990 * @param pInterface Pointer to this interface.
991 * @param fRender Whether the VRAM content must be rendered to the framebuffer.
992 * @thread The emulation thread.
993 */
994 DECLR3CALLBACKMEMBER(void, pfnSetRenderVRAM,(PPDMIDISPLAYPORT pInterface, bool fRender));
995
996} PDMIDISPLAYPORT;
997
998
999/** Pointer to a display connector interface. */
1000typedef struct PDMIDISPLAYCONNECTOR *PPDMIDISPLAYCONNECTOR;
1001/**
1002 * Display connector interface.
1003 * Pair with PDMIDISPLAYPORT.
1004 */
1005typedef struct PDMIDISPLAYCONNECTOR
1006{
1007 /**
1008 * Resize the display.
1009 * This is called when the resolution changes. This usually happens on
1010 * request from the guest os, but may also happen as the result of a reset.
1011 * If the callback returns VINF_VGA_RESIZE_IN_PROGRESS, the caller (VGA device)
1012 * must not access the connector and return.
1013 *
1014 * @returns VINF_SUCCESS if the framebuffer resize was completed,
1015 * VINF_VGA_RESIZE_IN_PROGRESS if resize takes time and not yet finished.
1016 * @param pInterface Pointer to this interface.
1017 * @param cBits Color depth (bits per pixel) of the new video mode.
1018 * @param pvVRAM Address of the guest VRAM.
1019 * @param cbLine Size in bytes of a single scan line.
1020 * @param cx New display width.
1021 * @param cy New display height.
1022 * @thread The emulation thread.
1023 */
1024 DECLR3CALLBACKMEMBER(int, pfnResize,(PPDMIDISPLAYCONNECTOR pInterface, uint32_t cBits, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy));
1025
1026 /**
1027 * Update a rectangle of the display.
1028 * PDMIDISPLAYPORT::pfnUpdateDisplay is the caller.
1029 *
1030 * @param pInterface Pointer to this interface.
1031 * @param x The upper left corner x coordinate of the rectangle.
1032 * @param y The upper left corner y coordinate of the rectangle.
1033 * @param cx The width of the rectangle.
1034 * @param cy The height of the rectangle.
1035 * @thread The emulation thread.
1036 */
1037 DECLR3CALLBACKMEMBER(void, pfnUpdateRect,(PPDMIDISPLAYCONNECTOR pInterface, uint32_t x, uint32_t y, uint32_t cx, uint32_t cy));
1038
1039 /**
1040 * Refresh the display.
1041 *
1042 * The interval between these calls is set by
1043 * PDMIDISPLAYPORT::pfnSetRefreshRate(). The driver should call
1044 * PDMIDISPLAYPORT::pfnUpdateDisplay() if it wishes to refresh the
1045 * display. PDMIDISPLAYPORT::pfnUpdateDisplay calls pfnUpdateRect with
1046 * the changed rectangles.
1047 *
1048 * @param pInterface Pointer to this interface.
1049 * @thread The emulation thread.
1050 */
1051 DECLR3CALLBACKMEMBER(void, pfnRefresh,(PPDMIDISPLAYCONNECTOR pInterface));
1052
1053 /**
1054 * Reset the display.
1055 *
1056 * Notification message when the graphics card has been reset.
1057 *
1058 * @param pInterface Pointer to this interface.
1059 * @thread The emulation thread.
1060 */
1061 DECLR3CALLBACKMEMBER(void, pfnReset,(PPDMIDISPLAYCONNECTOR pInterface));
1062
1063 /**
1064 * LFB video mode enter/exit.
1065 *
1066 * Notification message when LinearFrameBuffer video mode is enabled/disabled.
1067 *
1068 * @param pInterface Pointer to this interface.
1069 * @param fEnabled false - LFB mode was disabled,
1070 * true - an LFB mode was disabled
1071 * @thread The emulation thread.
1072 */
1073 DECLCALLBACKMEMBER(void, pfnLFBModeChange)(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled);
1074
1075 /**
1076 * Process the guest graphics adapter information.
1077 *
1078 * Direct notification from guest to the display connector.
1079 *
1080 * @param pInterface Pointer to this interface.
1081 * @param pvVRAM Address of the guest VRAM.
1082 * @param u32VRAMSize Size of the guest VRAM.
1083 * @thread The emulation thread.
1084 */
1085 DECLCALLBACKMEMBER(void, pfnProcessAdapterData)(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize);
1086
1087 /**
1088 * Process the guest display information.
1089 *
1090 * Direct notification from guest to the display connector.
1091 *
1092 * @param pInterface Pointer to this interface.
1093 * @param pvVRAM Address of the guest VRAM.
1094 * @param uScreenId The index of the guest display to be processed.
1095 * @thread The emulation thread.
1096 */
1097 DECLCALLBACKMEMBER(void, pfnProcessDisplayData)(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId);
1098
1099
1100 /** Read-only attributes.
1101 * For preformance reasons some readonly attributes are kept in the interface.
1102 * We trust the interface users to respect the readonlyness of these.
1103 * @{
1104 */
1105 /** Pointer to the display data buffer. */
1106 uint8_t *pu8Data;
1107 /** Size of a scanline in the data buffer. */
1108 uint32_t cbScanline;
1109 /** The color depth (in bits) the graphics card is supposed to provide. */
1110 uint32_t cBits;
1111 /** The display width. */
1112 uint32_t cx;
1113 /** The display height. */
1114 uint32_t cy;
1115 /** @} */
1116} PDMIDISPLAYCONNECTOR;
1117
1118
1119
1120/**
1121 * Block drive type.
1122 */
1123typedef enum PDMBLOCKTYPE
1124{
1125 /** Error (for the query function). */
1126 PDMBLOCKTYPE_ERROR = 1,
1127 /** 360KB 5 1/4" floppy drive. */
1128 PDMBLOCKTYPE_FLOPPY_360,
1129 /** 720KB 3 1/2" floppy drive. */
1130 PDMBLOCKTYPE_FLOPPY_720,
1131 /** 1.2MB 5 1/4" floppy drive. */
1132 PDMBLOCKTYPE_FLOPPY_1_20,
1133 /** 1.44MB 3 1/2" floppy drive. */
1134 PDMBLOCKTYPE_FLOPPY_1_44,
1135 /** 2.88MB 3 1/2" floppy drive. */
1136 PDMBLOCKTYPE_FLOPPY_2_88,
1137 /** CDROM drive. */
1138 PDMBLOCKTYPE_CDROM,
1139 /** DVD drive. */
1140 PDMBLOCKTYPE_DVD,
1141 /** Hard disk drive. */
1142 PDMBLOCKTYPE_HARD_DISK
1143} PDMBLOCKTYPE;
1144
1145
1146/**
1147 * Block raw command data transfer direction.
1148 */
1149typedef enum PDMBLOCKTXDIR
1150{
1151 PDMBLOCKTXDIR_NONE = 0,
1152 PDMBLOCKTXDIR_FROM_DEVICE,
1153 PDMBLOCKTXDIR_TO_DEVICE
1154} PDMBLOCKTXDIR;
1155
1156/**
1157 * Block notify interface.
1158 * Pair with PDMIBLOCK.
1159 */
1160typedef PDMIDUMMY PDMIBLOCKPORT;
1161/** Pointer to a block notify interface (dummy). */
1162typedef PDMIBLOCKPORT *PPDMIBLOCKPORT;
1163
1164/** Pointer to a block interface. */
1165typedef struct PDMIBLOCK *PPDMIBLOCK;
1166/**
1167 * Block interface.
1168 * Pair with PDMIBLOCKPORT.
1169 */
1170typedef struct PDMIBLOCK
1171{
1172 /**
1173 * Read bits.
1174 *
1175 * @returns VBox status code.
1176 * @param pInterface Pointer to the interface structure containing the called function pointer.
1177 * @param off Offset to start reading from.
1178 * @param pvBuf Where to store the read bits.
1179 * @param cbRead Number of bytes to read.
1180 * @thread Any thread.
1181 */
1182 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMIBLOCK pInterface, uint64_t off, void *pvBuf, size_t cbRead));
1183
1184 /**
1185 * Write bits.
1186 *
1187 * @returns VBox status code.
1188 * @param pInterface Pointer to the interface structure containing the called function pointer.
1189 * @param off Offset to start writing at.
1190 * @param pvBuf Where to store the write bits.
1191 * @param cbWrite Number of bytes to write.
1192 * @thread Any thread.
1193 */
1194 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMIBLOCK pInterface, uint64_t off, const void *pvBuf, size_t cbWrite));
1195
1196 /**
1197 * Make sure that the bits written are actually on the storage medium.
1198 *
1199 * @returns VBox status code.
1200 * @param pInterface Pointer to the interface structure containing the called function pointer.
1201 * @thread Any thread.
1202 */
1203 DECLR3CALLBACKMEMBER(int, pfnFlush,(PPDMIBLOCK pInterface));
1204
1205 /**
1206 * Send a raw command to the underlying device (CDROM).
1207 * This method is optional (i.e. the function pointer may be NULL).
1208 *
1209 * @returns VBox status code.
1210 * @param pInterface Pointer to the interface structure containing the called function pointer.
1211 * @param pbCmd Offset to start reading from.
1212 * @param enmTxDir Direction of transfer.
1213 * @param pvBuf Pointer tp the transfer buffer.
1214 * @param cbBuf Size of the transfer buffer.
1215 * @param pbSenseKey Status of the command (when return value is VERR_DEV_IO_ERROR).
1216 * @param cTimeoutMillies Command timeout in milliseconds.
1217 * @thread Any thread.
1218 */
1219 DECLR3CALLBACKMEMBER(int, pfnSendCmd,(PPDMIBLOCK pInterface, const uint8_t *pbCmd, PDMBLOCKTXDIR enmTxDir, void *pvBuf, size_t *pcbBuf, uint8_t *pbSenseKey, uint32_t cTimeoutMillies));
1220
1221 /**
1222 * Check if the media is readonly or not.
1223 *
1224 * @returns true if readonly.
1225 * @returns false if read/write.
1226 * @param pInterface Pointer to the interface structure containing the called function pointer.
1227 * @thread Any thread.
1228 */
1229 DECLR3CALLBACKMEMBER(bool, pfnIsReadOnly,(PPDMIBLOCK pInterface));
1230
1231 /**
1232 * Gets the media size in bytes.
1233 *
1234 * @returns Media size in bytes.
1235 * @param pInterface Pointer to the interface structure containing the called function pointer.
1236 * @thread Any thread.
1237 */
1238 DECLR3CALLBACKMEMBER(uint64_t, pfnGetSize,(PPDMIBLOCK pInterface));
1239
1240 /**
1241 * Gets the block drive type.
1242 *
1243 * @returns block drive type.
1244 * @param pInterface Pointer to the interface structure containing the called function pointer.
1245 * @thread Any thread.
1246 */
1247 DECLR3CALLBACKMEMBER(PDMBLOCKTYPE, pfnGetType,(PPDMIBLOCK pInterface));
1248
1249 /**
1250 * Gets the UUID of the block drive.
1251 * Don't return the media UUID if it's removable.
1252 *
1253 * @returns VBox status code.
1254 * @param pInterface Pointer to the interface structure containing the called function pointer.
1255 * @param pUuid Where to store the UUID on success.
1256 * @thread Any thread.
1257 */
1258 DECLR3CALLBACKMEMBER(int, pfnGetUuid,(PPDMIBLOCK pInterface, PRTUUID pUuid));
1259} PDMIBLOCK;
1260
1261
1262/** Pointer to a mount interface. */
1263typedef struct PDMIMOUNTNOTIFY *PPDMIMOUNTNOTIFY;
1264/**
1265 * Block interface.
1266 * Pair with PDMIMOUNT.
1267 */
1268typedef struct PDMIMOUNTNOTIFY
1269{
1270 /**
1271 * Called when a media is mounted.
1272 *
1273 * @param pInterface Pointer to the interface structure containing the called function pointer.
1274 * @thread The emulation thread.
1275 */
1276 DECLR3CALLBACKMEMBER(void, pfnMountNotify,(PPDMIMOUNTNOTIFY pInterface));
1277
1278 /**
1279 * Called when a media is unmounted
1280 * @param pInterface Pointer to the interface structure containing the called function pointer.
1281 * @thread The emulation thread.
1282 */
1283 DECLR3CALLBACKMEMBER(void, pfnUnmountNotify,(PPDMIMOUNTNOTIFY pInterface));
1284} PDMIMOUNTNOTIFY;
1285
1286
1287/* Pointer to mount interface. */
1288typedef struct PDMIMOUNT *PPDMIMOUNT;
1289/**
1290 * Mount interface.
1291 * Pair with PDMIMOUNTNOTIFY.
1292 */
1293typedef struct PDMIMOUNT
1294{
1295 /**
1296 * Mount a media.
1297 *
1298 * This will not unmount any currently mounted media!
1299 *
1300 * @returns VBox status code.
1301 * @param pInterface Pointer to the interface structure containing the called function pointer.
1302 * @param pszFilename Pointer to filename. If this is NULL it assumed that the caller have
1303 * constructed a configuration which can be attached to the bottom driver.
1304 * @param pszCoreDriver Core driver name. NULL will cause autodetection. Ignored if pszFilanem is NULL.
1305 * @thread The emulation thread.
1306 */
1307 DECLR3CALLBACKMEMBER(int, pfnMount,(PPDMIMOUNT pInterface, const char *pszFilename, const char *pszCoreDriver));
1308
1309 /**
1310 * Unmount the media.
1311 *
1312 * The driver will validate and pass it on. On the rebounce it will decide whether or not to detach it self.
1313 *
1314 * @returns VBox status code.
1315 * @param pInterface Pointer to the interface structure containing the called function pointer.
1316 * @thread The emulation thread.
1317 * @param fForce Force the unmount, even for locked media.
1318 * @thread The emulation thread.
1319 */
1320 DECLR3CALLBACKMEMBER(int, pfnUnmount,(PPDMIMOUNT pInterface, bool fForce));
1321
1322 /**
1323 * Checks if a media is mounted.
1324 *
1325 * @returns true if mounted.
1326 * @returns false if not mounted.
1327 * @param pInterface Pointer to the interface structure containing the called function pointer.
1328 * @thread Any thread.
1329 */
1330 DECLR3CALLBACKMEMBER(bool, pfnIsMounted,(PPDMIMOUNT pInterface));
1331
1332 /**
1333 * Locks the media, preventing any unmounting of it.
1334 *
1335 * @returns VBox status code.
1336 * @param pInterface Pointer to the interface structure containing the called function pointer.
1337 * @thread The emulation thread.
1338 */
1339 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMIMOUNT pInterface));
1340
1341 /**
1342 * Unlocks the media, canceling previous calls to pfnLock().
1343 *
1344 * @returns VBox status code.
1345 * @param pInterface Pointer to the interface structure containing the called function pointer.
1346 * @thread The emulation thread.
1347 */
1348 DECLR3CALLBACKMEMBER(int, pfnUnlock,(PPDMIMOUNT pInterface));
1349
1350 /**
1351 * Checks if a media is locked.
1352 *
1353 * @returns true if locked.
1354 * @returns false if not locked.
1355 * @param pInterface Pointer to the interface structure containing the called function pointer.
1356 * @thread Any thread.
1357 */
1358 DECLR3CALLBACKMEMBER(bool, pfnIsLocked,(PPDMIMOUNT pInterface));
1359} PDMIBLOCKMOUNT;
1360
1361/**
1362 * BIOS translation mode.
1363 */
1364typedef enum PDMBIOSTRANSLATION
1365{
1366 /** No translation. */
1367 PDMBIOSTRANSLATION_NONE = 1,
1368 /** LBA translation. */
1369 PDMBIOSTRANSLATION_LBA,
1370 /** Automatic select mode. */
1371 PDMBIOSTRANSLATION_AUTO
1372} PDMBIOSTRANSLATION;
1373
1374/** Pointer to BIOS translation mode. */
1375typedef PDMBIOSTRANSLATION *PPDMBIOSTRANSLATION;
1376
1377/** Pointer to a media interface. */
1378typedef struct PDMIMEDIA *PPDMIMEDIA;
1379/**
1380 * Media interface.
1381 * Makes up the fundation for PDMIBLOCK and PDMIBLOCKBIOS.
1382 */
1383typedef struct PDMIMEDIA
1384{
1385 /**
1386 * Read bits.
1387 *
1388 * @returns VBox status code.
1389 * @param pInterface Pointer to the interface structure containing the called function pointer.
1390 * @param off Offset to start reading from.
1391 * @param pvBuf Where to store the read bits.
1392 * @param cbRead Number of bytes to read.
1393 * @thread Any thread.
1394 */
1395 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMIMEDIA pInterface, uint64_t off, void *pvBuf, size_t cbRead));
1396
1397 /**
1398 * Write bits.
1399 *
1400 * @returns VBox status code.
1401 * @param pInterface Pointer to the interface structure containing the called function pointer.
1402 * @param off Offset to start writing at.
1403 * @param pvBuf Where to store the write bits.
1404 * @param cbWrite Number of bytes to write.
1405 * @thread Any thread.
1406 */
1407 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMIMEDIA pInterface, uint64_t off, const void *pvBuf, size_t cbWrite));
1408
1409 /**
1410 * Make sure that the bits written are actually on the storage medium.
1411 *
1412 * @returns VBox status code.
1413 * @param pInterface Pointer to the interface structure containing the called function pointer.
1414 * @thread Any thread.
1415 */
1416 DECLR3CALLBACKMEMBER(int, pfnFlush,(PPDMIMEDIA pInterface));
1417
1418 /**
1419 * Get the media size in bytes.
1420 *
1421 * @returns Media size in bytes.
1422 * @param pInterface Pointer to the interface structure containing the called function pointer.
1423 * @thread Any thread.
1424 */
1425 DECLR3CALLBACKMEMBER(uint64_t, pfnGetSize,(PPDMIMEDIA pInterface));
1426
1427 /**
1428 * Check if the media is readonly or not.
1429 *
1430 * @returns true if readonly.
1431 * @returns false if read/write.
1432 * @param pInterface Pointer to the interface structure containing the called function pointer.
1433 * @thread Any thread.
1434 */
1435 DECLR3CALLBACKMEMBER(bool, pfnIsReadOnly,(PPDMIMEDIA pInterface));
1436
1437 /**
1438 * Get stored media geometry - BIOS property.
1439 * This is an optional feature of a media.
1440 *
1441 * @returns VBox status code.
1442 * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
1443 * @returns VERR_PDM_GEOMETRY_NOT_SET if the geometry hasn't been set using pfnBiosSetGeometry() yet.
1444 * @param pInterface Pointer to the interface structure containing the called function pointer.
1445 * @param pcCylinders Number of cylinders.
1446 * @param pcHeads Number of heads.
1447 * @param pcSectors Number of sectors. This number is 1-based.
1448 * @remark This have no influence on the read/write operations.
1449 * @thread Any thread.
1450 */
1451 DECLR3CALLBACKMEMBER(int, pfnBiosGetGeometry,(PPDMIMEDIA pInterface, uint32_t *pcCylinders, uint32_t *pcHeads, uint32_t *pcSectors));
1452
1453 /**
1454 * Store the media geometry - BIOS property.
1455 * This is an optional feature of a media.
1456 *
1457 * @returns VBox status code.
1458 * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
1459 * @param pInterface Pointer to the interface structure containing the called function pointer.
1460 * @param cCylinders Number of cylinders.
1461 * @param cHeads Number of heads.
1462 * @param cSectors Number of sectors. This number is 1-based.
1463 * @remark This have no influence on the read/write operations.
1464 * @thread The emulation thread.
1465 */
1466 DECLR3CALLBACKMEMBER(int, pfnBiosSetGeometry,(PPDMIMEDIA pInterface, uint32_t cCylinders, uint32_t cHeads, uint32_t cSectors));
1467
1468 /**
1469 * Get stored geometry translation mode - BIOS property.
1470 * This is an optional feature of a media.
1471 *
1472 * @returns VBox status code.
1473 * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry translation mode.
1474 * @returns VERR_PDM_TRANSLATION_NOT_SET if the translation hasn't been set using pfnBiosSetTranslation() yet.
1475 * @param pInterface Pointer to the interface structure containing the called function pointer.
1476 * @param penmTranslation Where to store the translation type.
1477 * @remark This have no influence on the read/write operations.
1478 * @thread Any thread.
1479 */
1480 DECLR3CALLBACKMEMBER(int, pfnBiosGetTranslation,(PPDMIMEDIA pInterface, PPDMBIOSTRANSLATION penmTranslation));
1481
1482 /**
1483 * Store media geometry - BIOS property.
1484 * This is an optional feature of a media.
1485 *
1486 * @returns VBox status code.
1487 * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
1488 * @param pInterface Pointer to the interface structure containing the called function pointer.
1489 * @param enmTranslation The translation type.
1490 * @remark This have no influence on the read/write operations.
1491 * @thread The emulation thread.
1492 */
1493 DECLR3CALLBACKMEMBER(int, pfnBiosSetTranslation,(PPDMIMEDIA pInterface, PDMBIOSTRANSLATION enmTranslation));
1494
1495 /**
1496 * Gets the UUID of the media drive.
1497 *
1498 * @returns VBox status code.
1499 * @param pInterface Pointer to the interface structure containing the called function pointer.
1500 * @param pUuid Where to store the UUID on success.
1501 * @thread Any thread.
1502 */
1503 DECLR3CALLBACKMEMBER(int, pfnGetUuid,(PPDMIMEDIA pInterface, PRTUUID pUuid));
1504
1505} PDMIMEDIA;
1506
1507
1508/** Pointer to a block BIOS interface. */
1509typedef struct PDMIBLOCKBIOS *PPDMIBLOCKBIOS;
1510/**
1511 * Media BIOS interface.
1512 * The interface the getting and setting properties which the BIOS/CMOS care about.
1513 */
1514typedef struct PDMIBLOCKBIOS
1515{
1516 /**
1517 * Get stored media geometry - BIOS property.
1518 * This is an optional feature of a media.
1519 *
1520 * @returns VBox status code.
1521 * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
1522 * @param pInterface Pointer to the interface structure containing the called function pointer.
1523 * @param pcCylinders Number of cylinders.
1524 * @param pcHeads Number of heads.
1525 * @param pcSectors Number of sectors. This number is 1-based.
1526 * @remark This have no influence on the read/write operations.
1527 * @thread Any thread.
1528 */
1529 DECLR3CALLBACKMEMBER(int, pfnGetGeometry,(PPDMIBLOCKBIOS pInterface, uint32_t *pcCylinders, uint32_t *pcHeads, uint32_t *pcSectors));
1530
1531 /**
1532 * Store the media geometry - BIOS property.
1533 * This is an optional feature of a media.
1534 *
1535 * @returns VBox status code.
1536 * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
1537 * @param pInterface Pointer to the interface structure containing the called function pointer.
1538 * @param cCylinders Number of cylinders.
1539 * @param cHeads Number of heads.
1540 * @param cSectors Number of sectors. This number is 1-based.
1541 * @remark This have no influence on the read/write operations.
1542 * @thread The emulation thread.
1543 */
1544 DECLR3CALLBACKMEMBER(int, pfnSetGeometry,(PPDMIBLOCKBIOS pInterface, uint32_t cCylinders, uint32_t cHeads, uint32_t cSectors));
1545
1546 /**
1547 * Get stored geometry translation mode - BIOS property.
1548 * This is an optional feature of a media.
1549 *
1550 * @returns VBox status code.
1551 * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry translation mode.
1552 * @param pInterface Pointer to the interface structure containing the called function pointer.
1553 * @param penmTranslation Where to store the translation type.
1554 * @remark This have no influence on the read/write operations.
1555 * @thread Any thread.
1556 */
1557 DECLR3CALLBACKMEMBER(int, pfnGetTranslation,(PPDMIBLOCKBIOS pInterface, PPDMBIOSTRANSLATION penmTranslation));
1558
1559 /**
1560 * Store media geometry - BIOS property.
1561 * This is an optional feature of a media.
1562 *
1563 * @returns VBox status code.
1564 * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
1565 * @param pInterface Pointer to the interface structure containing the called function pointer.
1566 * @param enmTranslation The translation type.
1567 * @remark This have no influence on the read/write operations.
1568 * @thread The emulation thread.
1569 */
1570 DECLR3CALLBACKMEMBER(int, pfnSetTranslation,(PPDMIBLOCKBIOS pInterface, PDMBIOSTRANSLATION enmTranslation));
1571
1572 /**
1573 * Checks if the device should be visible to the BIOS or not.
1574 *
1575 * @returns true if the device is visible to the BIOS.
1576 * @returns false if the device is not visible to the BIOS.
1577 * @param pInterface Pointer to the interface structure containing the called function pointer.
1578 * @thread Any thread.
1579 */
1580 DECLR3CALLBACKMEMBER(bool, pfnIsVisible,(PPDMIBLOCKBIOS pInterface));
1581
1582 /**
1583 * Gets the block drive type.
1584 *
1585 * @returns block drive type.
1586 * @param pInterface Pointer to the interface structure containing the called function pointer.
1587 * @thread Any thread.
1588 */
1589 DECLR3CALLBACKMEMBER(PDMBLOCKTYPE, pfnGetType,(PPDMIBLOCKBIOS pInterface));
1590
1591} PDMIBLOCKBIOS;
1592
1593
1594/** Pointer to a static block core driver interface. */
1595typedef struct PDMIMEDIASTATIC *PPDMIMEDIASTATIC;
1596/**
1597 * Static block core driver interface.
1598 */
1599typedef struct PDMIMEDIASTATIC
1600{
1601 /**
1602 * Check if the specified file is a format which the core driver can handle.
1603 *
1604 * @returns true / false accordingly.
1605 * @param pInterface Pointer to the interface structure containing the called function pointer.
1606 * @param pszFilename Name of the file to probe.
1607 */
1608 DECLR3CALLBACKMEMBER(bool, pfnCanHandle,(PPDMIMEDIASTATIC pInterface, const char *pszFilename));
1609} PDMIMEDIASTATIC;
1610
1611
1612/** Pointer to an iSCSI Request PDU buffer. */
1613typedef struct ISCSIREQ *PISCSIREQ;
1614/**
1615 * iSCSI Request PDU buffer (gather).
1616 */
1617typedef struct ISCSIREQ
1618{
1619 /** Length of PDU segment in bytes. */
1620 size_t cbSeg;
1621 /** Pointer to PDU segment. */
1622 const void *pcvSeg;
1623} ISCSIREQ;
1624
1625/** Pointer to an iSCSI Response PDU buffer. */
1626typedef struct ISCSIRES *PISCSIRES;
1627/**
1628 * iSCSI Response PDU buffer (scatter).
1629 */
1630typedef struct ISCSIRES
1631{
1632 /** Length of PDU segment. */
1633 size_t cbSeg;
1634 /** Pointer to PDU segment. */
1635 void *pvSeg;
1636} ISCSIRES;
1637
1638/** Pointer to an iSCSI transport driver interface. */
1639typedef struct PDMIISCSITRANSPORT *PPDMIISCSITRANSPORT;
1640/**
1641 * iSCSI transport driver interface.
1642 */
1643typedef struct PDMIISCSITRANSPORT
1644{
1645 /**
1646 * Read bytes from an iSCSI transport stream. If the connection fails, it is automatically
1647 * reopened on the next call after the error is signalled. Error recovery in this case is
1648 * the duty of the caller.
1649 *
1650 * @returns VBox status code.
1651 * @param pTransport Pointer to the interface structure containing the called function pointer.
1652 * @param pvBuf Where to store the read bits.
1653 * @param cbBuf Number of bytes to read.
1654 * @param pcbRead Actual number of bytes read.
1655 * @thread Any thread.
1656 * @todo Correct the docs.
1657 */
1658 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMIISCSITRANSPORT pTransport, PISCSIRES prgResponse, unsigned int cnResponse));
1659
1660 /**
1661 * Write bytes to an iSCSI transport stream. Padding is performed when necessary. If the connection
1662 * fails, it is automatically reopened on the next call after the error is signalled. Error recovery
1663 * in this case is the duty of the caller.
1664 *
1665 * @returns VBox status code.
1666 * @param pTransport Pointer to the interface structure containing the called function pointer.
1667 * @param pvBuf Where the write bits are stored.
1668 * @param cbWrite Number of bytes to write.
1669 * @thread Any thread.
1670 * @todo Correct the docs.
1671 */
1672 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMIISCSITRANSPORT pTransport, PISCSIREQ prgRequest, unsigned int cnRequest));
1673
1674 /**
1675 * Open the iSCSI transport stream.
1676 *
1677 * @returns VBox status code.
1678 * @param pTransport Pointer to the interface structure containing the called function pointer.
1679 * @param pszTargetAddress Pointer to string of the format address:port.
1680 * @thread Any thread.
1681 */
1682 DECLR3CALLBACKMEMBER(int, pfnOpen,(PPDMIISCSITRANSPORT pTransport, const char *pszTargetAddress));
1683
1684 /**
1685 * Close the iSCSI transport stream.
1686 *
1687 * @returns VBox status code.
1688 * @param pTransport Pointer to the interface structure containing the called function pointer.
1689 * @thread Any thread.
1690 */
1691 DECLR3CALLBACKMEMBER(int, pfnClose,(PPDMIISCSITRANSPORT pTransport));
1692} PDMIISCSITRANSPORT;
1693
1694
1695/** Pointer to a char port interface. */
1696typedef struct PDMICHARPORT *PPDMICHARPORT;
1697/**
1698 * Char port interface.
1699 * Pair with PDMICHAR.
1700 */
1701typedef struct PDMICHARPORT
1702{
1703 /**
1704 * Deliver data read to the device/driver.
1705 *
1706 * @returns VBox status code.
1707 * @param pInterface Pointer to the interface structure containing the called function pointer.
1708 * @param pvBuf Where the read bits are stored.
1709 * @param pcbRead Number of bytes available for reading/having been read.
1710 * @thread Any thread.
1711 */
1712 DECLR3CALLBACKMEMBER(int, pfnNotifyRead,(PPDMICHARPORT pInterface, const void *pvBuf, size_t *pcbRead));
1713} PDMICHARPORT;
1714
1715/** Pointer to a char interface. */
1716typedef struct PDMICHAR *PPDMICHAR;
1717/**
1718 * Char interface.
1719 * Pair with PDMICHARPORT.
1720 */
1721typedef struct PDMICHAR
1722{
1723 /**
1724 * Write bits.
1725 *
1726 * @returns VBox status code.
1727 * @param pInterface Pointer to the interface structure containing the called function pointer.
1728 * @param pvBuf Where to store the write bits.
1729 * @param cbWrite Number of bytes to write.
1730 * @thread Any thread.
1731 */
1732 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMICHAR pInterface, const void *pvBuf, size_t cbWrite));
1733} PDMICHAR;
1734
1735
1736/** Pointer to a stream interface. */
1737typedef struct PDMISTREAM *PPDMISTREAM;
1738/**
1739 * Stream interface.
1740 * Makes up the fundation for PDMICHAR.
1741 */
1742typedef struct PDMISTREAM
1743{
1744 /**
1745 * Read bits.
1746 *
1747 * @returns VBox status code.
1748 * @param pInterface Pointer to the interface structure containing the called function pointer.
1749 * @param pvBuf Where to store the read bits.
1750 * @param cbRead Number of bytes to read/bytes actually read.
1751 * @thread Any thread.
1752 */
1753 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMISTREAM pInterface, void *pvBuf, size_t *cbRead));
1754
1755 /**
1756 * Write bits.
1757 *
1758 * @returns VBox status code.
1759 * @param pInterface Pointer to the interface structure containing the called function pointer.
1760 * @param pvBuf Where to store the write bits.
1761 * @param cbWrite Number of bytes to write/bytes actually written.
1762 * @thread Any thread.
1763 */
1764 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMISTREAM pInterface, const void *pvBuf, size_t *cbWrite));
1765} PDMISTREAM;
1766
1767
1768/** Pointer to a host device port interface. */
1769typedef struct PDMIHOSTDEVICEPORT *PPDMIHOSTDEVICEPORT;
1770
1771/**
1772 * Char port interface.
1773 * Pair with PDMIHOSTDEVICECONNECTOR.
1774 */
1775typedef struct PDMIHOSTDEVICEPORT
1776{
1777 /**
1778 * Deliver data read to the device/driver.
1779 *
1780 * @returns VBox status code.
1781 * @param pInterface Pointer to the interface structure containing the called function pointer.
1782 * @param pvBuf Where the read bits are stored.
1783 * @param pcbRead Number of bytes available for reading/having been read.
1784 * @thread Any thread.
1785 */
1786 DECLR3CALLBACKMEMBER(int, pfnNotifyRead,(PPDMIHOSTDEVICEPORT pInterface, const void *pvBuf, size_t *pcbRead));
1787} PDMIHOSTDEVICEPORT;
1788
1789/** Pointer to a Host Device connector interface. */
1790typedef struct PDMIHOSTDEVICECONNECTOR *PPDMIHOSTDEVICECONNECTOR;
1791
1792/**
1793 * Host device connector interface
1794 * Pair with PDMIHOSTDEVICEPORT.
1795 */
1796typedef struct PDMIHOSTDEVICECONNECTOR
1797{
1798 /**
1799 * Write bits.
1800 *
1801 * @returns VBox status code.
1802 * @param pInterface Pointer to the interface structure containing the called function pointer.
1803 * @param pvBuf Where to store the write bits.
1804 * @param pcbWrite Number of bytes to write/bytes actually written.
1805 * @thread Any thread.
1806 */
1807 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMIHOSTDEVICECONNECTOR pInterface, const void *pvBuf, size_t *pcbWrite));
1808
1809 /**
1810 * Read bits.
1811 *
1812 * @returns VBox status code.
1813 * @param pInterface Pointer to the interface structure containing the called function pointer.
1814 * @param pvBuf Where to store the read bits.
1815 * @param pcbRead Number of bytes to read/bytes actually read.
1816 * @thread Any thread.
1817 */
1818 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMIHOSTDEVICECONNECTOR pInterface, void *pvBuf, size_t *pcbRead));
1819
1820 /**
1821 * Perform IO control on the host device.
1822 *
1823 * @returns VBox status code.
1824 * @param pInterface Pointer to the interface structure containing the called function pointer.
1825 * @param uCommand The number of the command to set or get data
1826 * @param pvData Where to store the command data.
1827 * @thread Any thread.
1828 */
1829 DECLR3CALLBACKMEMBER(int, pfnIOCtl,(PPDMIHOSTDEVICECONNECTOR pInterface, RTUINT uCommand, void *pvData));
1830} PDMIHOSTDEVICECONNECTOR;
1831
1832
1833/** ACPI power source identifier */
1834typedef enum PDMACPIPOWERSOURCE
1835{
1836 PDM_ACPI_POWER_SOURCE_UNKNOWN = 0,
1837 PDM_ACPI_POWER_SOURCE_OUTLET,
1838 PDM_ACPI_POWER_SOURCE_BATTERY
1839} PDMACPIPOWERSOURCE;
1840/** Pointer to ACPI battery state. */
1841typedef PDMACPIPOWERSOURCE *PPDMACPIPOWERSOURCE;
1842
1843/** ACPI battey capacity */
1844typedef enum PDMACPIBATCAPACITY
1845{
1846 PDM_ACPI_BAT_CAPACITY_MIN = 0,
1847 PDM_ACPI_BAT_CAPACITY_MAX = 100,
1848 PDM_ACPI_BAT_CAPACITY_UNKNOWN = 255
1849} PDMACPIBATCAPACITY;
1850/** Pointer to ACPI battery capacity. */
1851typedef PDMACPIBATCAPACITY *PPDMACPIBATCAPACITY;
1852
1853/** ACPI battery state. See ACPI 3.0 spec '_BST (Battery Status)' */
1854typedef enum PDMACPIBATSTATE
1855{
1856 PDM_ACPI_BAT_STATE_CHARGED = 0x00,
1857 PDM_ACPI_BAT_STATE_CHARGING = 0x01,
1858 PDM_ACPI_BAT_STATE_DISCHARGING = 0x02,
1859 PDM_ACPI_BAT_STATE_CRITICAL = 0x04
1860} PDMACPIBATSTATE;
1861/** Pointer to ACPI battery state. */
1862typedef PDMACPIBATSTATE *PPDMACPIBATSTATE;
1863
1864/** Pointer to an ACPI port interface. */
1865typedef struct PDMIACPIPORT *PPDMIACPIPORT;
1866/**
1867 * ACPI port interface.
1868 */
1869typedef struct PDMIACPIPORT
1870{
1871 /**
1872 * Send an ACPI power off event.
1873 *
1874 * @returns VBox status code
1875 * @param pInterface Pointer to the interface structure containing the called function pointer.
1876 */
1877 DECLR3CALLBACKMEMBER(int, pfnPowerButtonPress,(PPDMIACPIPORT pInterface));
1878} PDMIACPIPORT;
1879
1880/** Pointer to an ACPI connector interface. */
1881typedef struct PDMIACPICONNECTOR *PPDMIACPICONNECTOR;
1882/**
1883 * ACPI connector interface.
1884 */
1885typedef struct PDMIACPICONNECTOR
1886{
1887 /**
1888 * Get the current power source of the host system.
1889 *
1890 * @returns VBox status code
1891 * @param pInterface Pointer to the interface structure containing the called function pointer.
1892 * @param penmPowerSource Pointer to the power source result variable.
1893 */
1894 DECLR3CALLBACKMEMBER(int, pfnQueryPowerSource,(PPDMIACPICONNECTOR, PPDMACPIPOWERSOURCE penmPowerSource));
1895
1896 /**
1897 * Query the current battery status of the host system.
1898 *
1899 * @returns VBox status code?
1900 * @param pInterface Pointer to the interface structure containing the called function pointer.
1901 * @param pfPresent Is set to true if battery is present, false otherwise.
1902 * @param penmRemainingCapacity Pointer to the battery remaining capacity (0 - 100 or 255 for unknown).
1903 * @param penmBatteryState Pointer to the battery status.
1904 * @param pu32PresentRate Pointer to the present rate (0..1000 of the total capacity).
1905 */
1906 DECLR3CALLBACKMEMBER(int, pfnQueryBatteryStatus,(PPDMIACPICONNECTOR, bool *pfPresent, PPDMACPIBATCAPACITY penmRemainingCapacity,
1907 PPDMACPIBATSTATE penmBatteryState, uint32_t *pu32PresentRate));
1908} PDMIACPICONNECTOR;
1909
1910/** Pointer to a VMMDevice port interface. */
1911typedef struct PDMIVMMDEVPORT *PPDMIVMMDEVPORT;
1912/**
1913 * VMMDevice port interface.
1914 */
1915typedef struct PDMIVMMDEVPORT
1916{
1917 /**
1918 * Return the current absolute mouse position in pixels
1919 *
1920 * @returns VBox status code
1921 * @param pAbsX Pointer of result value, can be NULL
1922 * @param pAbsY Pointer of result value, can be NULL
1923 */
1924 DECLR3CALLBACKMEMBER(int, pfnQueryAbsoluteMouse,(PPDMIVMMDEVPORT pInterface, uint32_t *pAbsX, uint32_t *pAbsY));
1925
1926 /**
1927 * Set the new absolute mouse position in pixels
1928 *
1929 * @returns VBox status code
1930 * @param absX New absolute X position
1931 * @param absY New absolute Y position
1932 */
1933 DECLR3CALLBACKMEMBER(int, pfnSetAbsoluteMouse,(PPDMIVMMDEVPORT pInterface, uint32_t absX, uint32_t absY));
1934
1935 /**
1936 * Return the current mouse capability flags
1937 *
1938 * @returns VBox status code
1939 * @param pCapabilities Pointer of result value
1940 */
1941 DECLR3CALLBACKMEMBER(int, pfnQueryMouseCapabilities,(PPDMIVMMDEVPORT pInterface, uint32_t *pCapabilities));
1942
1943 /**
1944 * Set the current mouse capability flag (host side)
1945 *
1946 * @returns VBox status code
1947 * @param capabilities Capability mask
1948 */
1949 DECLR3CALLBACKMEMBER(int, pfnSetMouseCapabilities,(PPDMIVMMDEVPORT pInterface, uint32_t capabilities));
1950
1951 /**
1952 * Issue a display resolution change request.
1953 *
1954 * Note that there can only one request in the queue and that in case the guest does
1955 * not process it, issuing another request will overwrite the previous.
1956 *
1957 * @returns VBox status code
1958 * @param cx Horizontal pixel resolution (0 = do not change).
1959 * @param cy Vertical pixel resolution (0 = do not change).
1960 * @param cBits Bits per pixel (0 = do not change).
1961 * @param display The display index.
1962 */
1963 DECLR3CALLBACKMEMBER(int, pfnRequestDisplayChange,(PPDMIVMMDEVPORT pInterface, uint32_t cx, uint32_t cy, uint32_t cBits, uint32_t display));
1964
1965 /**
1966 * Pass credentials to guest.
1967 *
1968 * Note that there can only be one set of credentials and the guest may or may not
1969 * query them and may do whatever it wants with them.
1970 *
1971 * @returns VBox status code
1972 * @param pszUsername User name, may be empty (UTF-8)
1973 * @param pszPassword Password, may be empty (UTF-8)
1974 * @param pszDomain Domain name, may be empty (UTF-8)
1975 * @param fFlags Bitflags
1976 */
1977 DECLR3CALLBACKMEMBER(int, pfnSetCredentials,(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
1978 const char *pszPassword, const char *pszDomain,
1979 uint32_t fFlags));
1980
1981 /**
1982 * Notify the driver about a VBVA status change.
1983 *
1984 * @returns Nothing. Because it is informational callback.
1985 * @param fEnabled Current VBVA status.
1986 */
1987 DECLCALLBACKMEMBER(void, pfnVBVAChange)(PPDMIVMMDEVPORT pInterface, bool fEnabled);
1988
1989} PDMIVMMDEVPORT;
1990
1991/** Forward declaration of the video accelerator command memory. */
1992struct _VBVAMEMORY;
1993/** Forward declaration of the guest information structure. */
1994struct VBoxGuestInfo;
1995/** Pointer to video accelerator command memory. */
1996typedef struct _VBVAMEMORY *PVBVAMEMORY;
1997
1998/** Pointer to a VMMDev connector interface. */
1999typedef struct PDMIVMMDEVCONNECTOR *PPDMIVMMDEVCONNECTOR;
2000/**
2001 * VMMDev connector interface.
2002 * Pair with PDMIVMMDEVPORT.
2003 */
2004typedef struct PDMIVMMDEVCONNECTOR
2005{
2006 /**
2007 * Report guest OS version.
2008 * Called whenever the Additions issue a guest version report request.
2009 *
2010 * @param pInterface Pointer to this interface.
2011 * @param pGuestInfo Pointer to guest information structure
2012 * @thread The emulation thread.
2013 */
2014 DECLR3CALLBACKMEMBER(void, pfnUpdateGuestVersion,(PPDMIVMMDEVCONNECTOR pInterface, struct VBoxGuestInfo *pGuestInfo));
2015
2016 /**
2017 * Update the guest additions capabilities.
2018 * This is called when the guest additions capabilities change. The new capabilities
2019 * are given and the connector should update its internal state.
2020 *
2021 * @param pInterface Pointer to this interface.
2022 * @param newCapabilities New capabilities.
2023 * @thread The emulation thread.
2024 */
2025 DECLR3CALLBACKMEMBER(void, pfnUpdateGuestCapabilities,(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities));
2026
2027 /**
2028 * Update the mouse capabilities.
2029 * This is called when the mouse capabilities change. The new capabilities
2030 * are given and the connector should update its internal state.
2031 *
2032 * @param pInterface Pointer to this interface.
2033 * @param newCapabilities New capabilities.
2034 * @thread The emulation thread.
2035 */
2036 DECLR3CALLBACKMEMBER(void, pfnUpdateMouseCapabilities,(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities));
2037
2038 /**
2039 * Update the pointer shape.
2040 * This is called when the mouse pointer shape changes. The new shape
2041 * is passed as a caller allocated buffer that will be freed after returning
2042 *
2043 * @param pInterface Pointer to this interface.
2044 * @param fVisible Visibility indicator (if false, the other parameters are undefined).
2045 * @param fAlpha Flag whether alpha channel is being passed.
2046 * @param xHot Pointer hot spot x coordinate.
2047 * @param yHot Pointer hot spot y coordinate.
2048 * @param x Pointer new x coordinate on screen.
2049 * @param y Pointer new y coordinate on screen.
2050 * @param cx Pointer width in pixels.
2051 * @param cy Pointer height in pixels.
2052 * @param cbScanline Size of one scanline in bytes.
2053 * @param pvShape New shape buffer.
2054 * @thread The emulation thread.
2055 */
2056 DECLR3CALLBACKMEMBER(void, pfnUpdatePointerShape,(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
2057 uint32_t xHot, uint32_t yHot,
2058 uint32_t cx, uint32_t cy,
2059 void *pvShape));
2060
2061 /**
2062 * Enable or disable video acceleration on behalf of guest.
2063 *
2064 * @param pInterface Pointer to this interface.
2065 * @param fEnable Whether to enable acceleration.
2066 * @param pVbvaMemory Video accelerator memory.
2067
2068 * @return VBox rc. VINF_SUCCESS if VBVA was enabled.
2069 * @thread The emulation thread.
2070 */
2071 DECLR3CALLBACKMEMBER(int, pfnVideoAccelEnable,(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, PVBVAMEMORY pVbvaMemory));
2072
2073 /**
2074 * Force video queue processing.
2075 *
2076 * @param pInterface Pointer to this interface.
2077 * @thread The emulation thread.
2078 */
2079 DECLR3CALLBACKMEMBER(void, pfnVideoAccelFlush,(PPDMIVMMDEVCONNECTOR pInterface));
2080
2081 /**
2082 * Return whether the given video mode is supported/wanted by the host.
2083 *
2084 * @returns VBox status code
2085 * @param pInterface Pointer to this interface.
2086 * @param cy Video mode horizontal resolution in pixels.
2087 * @param cx Video mode vertical resolution in pixels.
2088 * @param cBits Video mode bits per pixel.
2089 * @param pfSupported Where to put the indicator for whether this mode is supported. (output)
2090 * @thread The emulation thread.
2091 */
2092 DECLR3CALLBACKMEMBER(int, pfnVideoModeSupported,(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cx, uint32_t cy, uint32_t cBits, bool *pfSupported));
2093
2094 /**
2095 * Queries by how many pixels the height should be reduced when calculating video modes
2096 *
2097 * @returns VBox status code
2098 * @param pInterface Pointer to this interface.
2099 * @param pcyReduction Pointer to the result value.
2100 * @thread The emulation thread.
2101 */
2102 DECLR3CALLBACKMEMBER(int, pfnGetHeightReduction,(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcyReduction));
2103
2104 /**
2105 * Informs about a credentials judgement result from the guest.
2106 *
2107 * @returns VBox status code
2108 * @param pInterface Pointer to this interface.
2109 * @param fFlags Judgement result flags.
2110 * @thread The emulation thread.
2111 */
2112 DECLR3CALLBACKMEMBER(int, pfnSetCredentialsJudgementResult,(PPDMIVMMDEVCONNECTOR pInterface, uint32_t fFlags));
2113
2114 /**
2115 * Set the visible region of the display
2116 *
2117 * @returns VBox status code.
2118 * @param pInterface Pointer to this interface.
2119 * @param cRect Number of rectangles in pRect
2120 * @param pRect Rectangle array
2121 * @thread The emulation thread.
2122 */
2123 DECLR3CALLBACKMEMBER(int, pfnSetVisibleRegion,(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect));
2124
2125 /**
2126 * Query the visible region of the display
2127 *
2128 * @returns VBox status code.
2129 * @param pInterface Pointer to this interface.
2130 * @param pcRect Number of rectangles in pRect
2131 * @param pRect Rectangle array (set to NULL to query the number of rectangles)
2132 * @thread The emulation thread.
2133 */
2134 DECLR3CALLBACKMEMBER(int, pfnQueryVisibleRegion,(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect));
2135
2136} PDMIVMMDEVCONNECTOR;
2137
2138
2139/**
2140 * MAC address.
2141 * (The first 24 bits are the 'company id', where the first bit seems to have a special meaning if set.)
2142 */
2143typedef union PDMMAC
2144{
2145 /** 8-bit view. */
2146 uint8_t au8[6];
2147 /** 16-bit view. */
2148 uint16_t au16[3];
2149} PDMMAC;
2150/** Pointer to a MAC address. */
2151typedef PDMMAC *PPDMMAC;
2152/** Pointer to a const MAC address. */
2153typedef const PDMMAC *PCPDMMAC;
2154
2155
2156/** Pointer to a network port interface */
2157typedef struct PDMINETWORKPORT *PPDMINETWORKPORT;
2158/**
2159 * Network port interface.
2160 */
2161typedef struct PDMINETWORKPORT
2162{
2163 /**
2164 * Check how much data the device/driver can receive data now.
2165 * This must be called before the pfnRecieve() method is called.
2166 *
2167 * @returns Number of bytes the device can receive now.
2168 * @param pInterface Pointer to the interface structure containing the called function pointer.
2169 * @thread EMT
2170 */
2171 DECLR3CALLBACKMEMBER(size_t, pfnCanReceive,(PPDMINETWORKPORT pInterface));
2172
2173 /**
2174 * Receive data from the network.
2175 *
2176 * @returns VBox status code.
2177 * @param pInterface Pointer to the interface structure containing the called function pointer.
2178 * @param pvBuf The available data.
2179 * @param cb Number of bytes available in the buffer.
2180 * @thread EMT
2181 */
2182 DECLR3CALLBACKMEMBER(int, pfnReceive,(PPDMINETWORKPORT pInterface, const void *pvBuf, size_t cb));
2183
2184} PDMINETWORKPORT;
2185
2186
2187/**
2188 * Network link state.
2189 */
2190typedef enum PDMNETWORKLINKSTATE
2191{
2192 /** Invalid state. */
2193 PDMNETWORKLINKSTATE_INVALID = 0,
2194 /** The link is up. */
2195 PDMNETWORKLINKSTATE_UP,
2196 /** The link is down. */
2197 PDMNETWORKLINKSTATE_DOWN,
2198 /** The link is temporarily down while resuming. */
2199 PDMNETWORKLINKSTATE_DOWN_RESUME
2200} PDMNETWORKLINKSTATE;
2201
2202
2203/** Pointer to a network connector interface */
2204typedef struct PDMINETWORKCONNECTOR *PPDMINETWORKCONNECTOR;
2205/**
2206 * Network connector interface.
2207 */
2208typedef struct PDMINETWORKCONNECTOR
2209{
2210 /**
2211 * Send data to the network.
2212 *
2213 * @returns VBox status code.
2214 * @param pInterface Pointer to the interface structure containing the called function pointer.
2215 * @param pvBuf Data to send.
2216 * @param cb Number of bytes to send.
2217 * @thread EMT
2218 */
2219 DECLR3CALLBACKMEMBER(int, pfnSend,(PPDMINETWORKCONNECTOR pInterface, const void *pvBuf, size_t cb));
2220
2221 /**
2222 * Set promiscuous mode.
2223 *
2224 * This is called when the promiscuous mode is set. This means that there doesn't have
2225 * to be a mode change when it's called.
2226 *
2227 * @param pInterface Pointer to the interface structure containing the called function pointer.
2228 * @param fPromiscuous Set if the adaptor is now in promiscuous mode. Clear if it is not.
2229 * @thread EMT
2230 */
2231 DECLR3CALLBACKMEMBER(void, pfnSetPromiscuousMode,(PPDMINETWORKCONNECTOR pInterface, bool fPromiscuous));
2232
2233 /**
2234 * Notification on link status changes.
2235 *
2236 * @param pInterface Pointer to the interface structure containing the called function pointer.
2237 * @param enmLinkState The new link state.
2238 * @thread EMT
2239 */
2240 DECLR3CALLBACKMEMBER(void, pfnNotifyLinkChanged,(PPDMINETWORKCONNECTOR pInterface, PDMNETWORKLINKSTATE enmLinkState));
2241
2242 /**
2243 * More receive buffer has become available.
2244 *
2245 * This is called when the NIC frees up receive buffers.
2246 *
2247 * @param pInterface Pointer to the interface structure containing the called function pointer.
2248 * @thread EMT
2249 */
2250 DECLR3CALLBACKMEMBER(void, pfnNotifyCanReceive,(PPDMINETWORKCONNECTOR pInterface));
2251
2252} PDMINETWORKCONNECTOR;
2253
2254
2255/** Pointer to a network config port interface */
2256typedef struct PDMINETWORKCONFIG *PPDMINETWORKCONFIG;
2257/**
2258 * Network config port interface.
2259 */
2260typedef struct PDMINETWORKCONFIG
2261{
2262 /**
2263 * Gets the current Media Access Control (MAC) address.
2264 *
2265 * @returns VBox status code.
2266 * @param pInterface Pointer to the interface structure containing the called function pointer.
2267 * @param pMac Where to store the MAC address.
2268 * @thread EMT
2269 */
2270 DECLR3CALLBACKMEMBER(int, pfnGetMac,(PPDMINETWORKCONFIG pInterface, PPDMMAC *pMac));
2271
2272 /**
2273 * Gets the new link state.
2274 *
2275 * @returns The current link state.
2276 * @param pInterface Pointer to the interface structure containing the called function pointer.
2277 * @thread EMT
2278 */
2279 DECLR3CALLBACKMEMBER(PDMNETWORKLINKSTATE, pfnGetLinkState,(PPDMINETWORKCONFIG pInterface));
2280
2281 /**
2282 * Sets the new link state.
2283 *
2284 * @returns VBox status code.
2285 * @param pInterface Pointer to the interface structure containing the called function pointer.
2286 * @param enmState The new link state
2287 * @thread EMT
2288 */
2289 DECLR3CALLBACKMEMBER(int, pfnSetLinkState,(PPDMINETWORKCONFIG pInterface, PDMNETWORKLINKSTATE enmState));
2290
2291} PDMINETWORKCONFIG;
2292
2293
2294/** Pointer to a network connector interface */
2295typedef struct PDMIAUDIOCONNECTOR *PPDMIAUDIOCONNECTOR;
2296/**
2297 * Audio connector interface.
2298 */
2299typedef struct PDMIAUDIOCONNECTOR
2300{
2301 DECLR3CALLBACKMEMBER(void, pfnRun,(PPDMIAUDIOCONNECTOR pInterface));
2302
2303/* DECLR3CALLBACKMEMBER(int, pfnSetRecordSource,(PPDMIAUDIOINCONNECTOR pInterface, AUDIORECSOURCE)); */
2304
2305} PDMIAUDIOCONNECTOR;
2306
2307
2308/** @todo r=bird: the two following interfaces are hacks to work around the missing audio driver
2309 * interface. This should be addressed rather than making more temporary hacks. */
2310
2311/** Pointer to a Audio Sniffer Device port interface. */
2312typedef struct PDMIAUDIOSNIFFERPORT *PPDMIAUDIOSNIFFERPORT;
2313
2314/**
2315 * Audio Sniffer port interface.
2316 */
2317typedef struct PDMIAUDIOSNIFFERPORT
2318{
2319 /**
2320 * Enables or disables sniffing. If sniffing is being enabled also sets a flag
2321 * whether the audio must be also left on the host.
2322 *
2323 * @returns VBox status code
2324 * @param pInterface Pointer to this interface.
2325 * @param fEnable 'true' for enable sniffing, 'false' to disable.
2326 * @param fKeepHostAudio Indicates whether host audio should also present
2327 * 'true' means that sound should not be played
2328 * by the audio device.
2329 */
2330 DECLR3CALLBACKMEMBER(int, pfnSetup,(PPDMIAUDIOSNIFFERPORT pInterface, bool fEnable, bool fKeepHostAudio));
2331
2332} PDMIAUDIOSNIFFERPORT;
2333
2334/** Pointer to a Audio Sniffer connector interface. */
2335typedef struct PDMIAUDIOSNIFFERCONNECTOR *PPDMIAUDIOSNIFFERCONNECTOR;
2336
2337/**
2338 * Audio Sniffer connector interface.
2339 * Pair with PDMIAUDIOSNIFFERPORT.
2340 */
2341typedef struct PDMIAUDIOSNIFFERCONNECTOR
2342{
2343 /**
2344 * AudioSniffer device calls this method when audio samples
2345 * are about to be played and sniffing is enabled.
2346 *
2347 * @param pInterface Pointer to this interface.
2348 * @param pvSamples Audio samples buffer.
2349 * @param cSamples How many complete samples are in the buffer.
2350 * @param iSampleHz The sample frequency in Hz.
2351 * @param cChannels Number of channels. 1 for mono, 2 for stereo.
2352 * @param cBits How many bits a sample for a single channel has. Normally 8 or 16.
2353 * @param fUnsigned Whether samples are unsigned values.
2354 * @thread The emulation thread.
2355 */
2356 DECLR3CALLBACKMEMBER(void, pfnAudioSamplesOut,(PPDMIAUDIOSNIFFERCONNECTOR pInterface, void *pvSamples, uint32_t cSamples,
2357 int iSampleHz, int cChannels, int cBits, bool fUnsigned));
2358
2359 /**
2360 * AudioSniffer device calls this method when output volume is changed.
2361 *
2362 * @param pInterface Pointer to this interface.
2363 * @param u16LeftVolume 0..0xFFFF volume level for left channel.
2364 * @param u16RightVolume 0..0xFFFF volume level for right channel.
2365 * @thread The emulation thread.
2366 */
2367 DECLR3CALLBACKMEMBER(void, pfnAudioVolumeOut,(PPDMIAUDIOSNIFFERCONNECTOR pInterface, uint16_t u16LeftVolume, uint16_t u16RightVolume));
2368
2369} PDMIAUDIOSNIFFERCONNECTOR;
2370
2371
2372/**
2373 * Generic status LED core.
2374 * Note that a unit doesn't have to support all the indicators.
2375 */
2376typedef union PDMLEDCORE
2377{
2378 /** 32-bit view. */
2379 uint32_t volatile u32;
2380 /** Bit view. */
2381 struct
2382 {
2383 /** Reading/Receiving indicator. */
2384 uint32_t fReading : 1;
2385 /** Writing/Sending indicator. */
2386 uint32_t fWriting : 1;
2387 /** Busy indicator. */
2388 uint32_t fBusy : 1;
2389 /** Error indicator. */
2390 uint32_t fError : 1;
2391 } s;
2392} PDMLEDCORE;
2393
2394/** LED bit masks for the u32 view.
2395 * @{ */
2396/** Reading/Receiving indicator. */
2397#define PDMLED_READING BIT(0)
2398/** Writing/Sending indicator. */
2399#define PDMLED_WRITING BIT(1)
2400/** Busy indicator. */
2401#define PDMLED_BUSY BIT(2)
2402/** Error indicator. */
2403#define PDMLED_ERROR BIT(3)
2404/** @} */
2405
2406
2407/**
2408 * Generic status LED.
2409 * Note that a unit doesn't have to support all the indicators.
2410 */
2411typedef struct PDMLED
2412{
2413 /** Just a magic for sanity checking. */
2414 uint32_t u32Magic;
2415 uint32_t u32Alignment; /**< structure size alignment. */
2416 /** The actual LED status.
2417 * Only the device is allowed to change this. */
2418 PDMLEDCORE Actual;
2419 /** The asserted LED status which is cleared by the reader.
2420 * The device will assert the bits but never clear them.
2421 * The driver clears them as it sees fit. */
2422 PDMLEDCORE Asserted;
2423} PDMLED;
2424
2425/** Pointer to an LED. */
2426typedef PDMLED *PPDMLED;
2427/** Pointer to a const LED. */
2428typedef const PDMLED *PCPDMLED;
2429
2430#define PDMLED_MAGIC ( 0x11335577 )
2431
2432/** Pointer to an LED ports interface. */
2433typedef struct PDMILEDPORTS *PPDMILEDPORTS;
2434/**
2435 * Interface for exporting LEDs.
2436 */
2437typedef struct PDMILEDPORTS
2438{
2439 /**
2440 * Gets the pointer to the status LED of a unit.
2441 *
2442 * @returns VBox status code.
2443 * @param pInterface Pointer to the interface structure containing the called function pointer.
2444 * @param iLUN The unit which status LED we desire.
2445 * @param ppLed Where to store the LED pointer.
2446 */
2447 DECLR3CALLBACKMEMBER(int, pfnQueryStatusLed,(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed));
2448
2449} PDMILEDPORTS;
2450
2451
2452/** Pointer to an LED connectors interface. */
2453typedef struct PDMILEDCONNECTORS *PPDMILEDCONNECTORS;
2454/**
2455 * Interface for reading LEDs.
2456 */
2457typedef struct PDMILEDCONNECTORS
2458{
2459 /**
2460 * Notification about a unit which have been changed.
2461 *
2462 * The driver must discard any pointers to data owned by
2463 * the unit and requery it.
2464 *
2465 * @param pInterface Pointer to the interface structure containing the called function pointer.
2466 * @param iLUN The unit number.
2467 */
2468 DECLR3CALLBACKMEMBER(void, pfnUnitChanged,(PPDMILEDCONNECTORS pInterface, unsigned iLUN));
2469} PDMILEDCONNECTORS;
2470
2471
2472/** The special status unit number */
2473#define PDM_STATUS_LUN 999
2474
2475
2476#ifdef VBOX_HGCM
2477
2478/** Abstract HGCM command structure. Used only to define a typed pointer. */
2479struct VBOXHGCMCMD;
2480
2481/** Pointer to HGCM command structure. This pointer is unique and identifies
2482 * the command being processed. The pointer is passed to HGCM connector methods,
2483 * and must be passed back to HGCM port when command is completed.
2484 */
2485typedef struct VBOXHGCMCMD *PVBOXHGCMCMD;
2486
2487/** Pointer to a HGCM port interface. */
2488typedef struct PDMIHGCMPORT *PPDMIHGCMPORT;
2489
2490/**
2491 * HGCM port interface. Normally implemented by VMMDev.
2492 */
2493typedef struct PDMIHGCMPORT
2494{
2495 /**
2496 * Notify the guest on a command completion.
2497 *
2498 * @param pInterface Pointer to this interface.
2499 * @param rc The return code (VBox error code).
2500 * @param pCmd A pointer that identifies the completed command.
2501 *
2502 * @returns VBox status code
2503 */
2504 DECLR3CALLBACKMEMBER(void, pfnCompleted,(PPDMIHGCMPORT pInterface, int32_t rc, PVBOXHGCMCMD pCmd));
2505
2506} PDMIHGCMPORT;
2507
2508
2509/** Pointer to a HGCM connector interface. */
2510typedef struct PDMIHGCMCONNECTOR *PPDMIHGCMCONNECTOR;
2511
2512/** Pointer to a HGCM function parameter. */
2513typedef struct VBOXHGCMSVCPARM *PVBOXHGCMSVCPARM;
2514
2515/** Pointer to a HGCM service location structure. */
2516typedef struct HGCMSERVICELOCATION *PHGCMSERVICELOCATION;
2517
2518/**
2519 * HGCM connector interface.
2520 * Pair with PDMIHGCMPORT.
2521 */
2522typedef struct PDMIHGCMCONNECTOR
2523{
2524 /**
2525 * Locate a service and inform it about a client connection.
2526 *
2527 * @param pInterface Pointer to this interface.
2528 * @param pCmd A pointer that identifies the command.
2529 * @param pServiceLocation Pointer to the service location structure.
2530 * @param pu32ClientID Where to store the client id for the connection.
2531 * @return VBox status code.
2532 * @thread The emulation thread.
2533 */
2534 DECLR3CALLBACKMEMBER(int, pfnConnect,(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID));
2535
2536 /**
2537 * Disconnect from service.
2538 *
2539 * @param pInterface Pointer to this interface.
2540 * @param pCmd A pointer that identifies the command.
2541 * @param u32ClientID The client id returned by the pfnConnect call.
2542 * @return VBox status code.
2543 * @thread The emulation thread.
2544 */
2545 DECLR3CALLBACKMEMBER(int, pfnDisconnect,(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID));
2546
2547 /**
2548 * Process a guest issued command.
2549 *
2550 * @param pInterface Pointer to this interface.
2551 * @param pCmd A pointer that identifies the command.
2552 * @param u32ClientID The client id returned by the pfnConnect call.
2553 * @param u32Function Function to be performed by the service.
2554 * @param cParms Number of parameters in the array pointed to by paParams.
2555 * @param paParms Pointer to an array of parameters.
2556 * @return VBox status code.
2557 * @thread The emulation thread.
2558 */
2559 DECLR3CALLBACKMEMBER(int, pfnCall,(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
2560 uint32_t cParms, PVBOXHGCMSVCPARM paParms));
2561
2562} PDMIHGCMCONNECTOR;
2563
2564#endif
2565
2566/** @} */
2567
2568
2569/** @defgroup grp_pdm_driver Drivers
2570 * @ingroup grp_pdm
2571 * @{
2572 */
2573
2574
2575/**
2576 * Construct a driver instance for a VM.
2577 *
2578 * @returns VBox status.
2579 * @param pDrvIns The driver instance data.
2580 * If the registration structure is needed, pDrvIns->pDrvReg points to it.
2581 * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
2582 * of the driver instance. It's also found in pDrvIns->pCfgHandle as it's expected
2583 * to be used frequently in this function.
2584 */
2585typedef DECLCALLBACK(int) FNPDMDRVCONSTRUCT(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle);
2586/** Pointer to a FNPDMDRVCONSTRUCT() function. */
2587typedef FNPDMDRVCONSTRUCT *PFNPDMDRVCONSTRUCT;
2588
2589/**
2590 * Destruct a driver instance.
2591 *
2592 * Most VM resources are freed by the VM. This callback is provided so that
2593 * any non-VM resources can be freed correctly.
2594 *
2595 * @param pDrvIns The driver instance data.
2596 */
2597typedef DECLCALLBACK(void) FNPDMDRVDESTRUCT(PPDMDRVINS pDrvIns);
2598/** Pointer to a FNPDMDRVDESTRUCT() function. */
2599typedef FNPDMDRVDESTRUCT *PFNPDMDRVDESTRUCT;
2600
2601/**
2602 * Driver I/O Control interface.
2603 *
2604 * This is used by external components, such as the COM interface, to
2605 * communicate with a driver using a driver specific interface. Generally,
2606 * the driver interfaces are used for this task.
2607 *
2608 * @returns VBox status code.
2609 * @param pDrvIns Pointer to the driver instance.
2610 * @param uFunction Function to perform.
2611 * @param pvIn Pointer to input data.
2612 * @param cbIn Size of input data.
2613 * @param pvOut Pointer to output data.
2614 * @param cbOut Size of output data.
2615 * @param pcbOut Where to store the actual size of the output data.
2616 */
2617typedef DECLCALLBACK(int) FNPDMDRVIOCTL(PPDMDRVINS pDrvIns, RTUINT uFunction,
2618 void *pvIn, RTUINT cbIn,
2619 void *pvOut, RTUINT cbOut, PRTUINT pcbOut);
2620/** Pointer to a FNPDMDRVIOCTL() function. */
2621typedef FNPDMDRVIOCTL *PFNPDMDRVIOCTL;
2622
2623/**
2624 * Power On notification.
2625 *
2626 * @param pDrvIns The driver instance data.
2627 */
2628typedef DECLCALLBACK(void) FNPDMDRVPOWERON(PPDMDRVINS pDrvIns);
2629/** Pointer to a FNPDMDRVPOWERON() function. */
2630typedef FNPDMDRVPOWERON *PFNPDMDRVPOWERON;
2631
2632/**
2633 * Reset notification.
2634 *
2635 * @returns VBox status.
2636 * @param pDrvIns The driver instance data.
2637 */
2638typedef DECLCALLBACK(void) FNPDMDRVRESET(PPDMDRVINS pDrvIns);
2639/** Pointer to a FNPDMDRVRESET() function. */
2640typedef FNPDMDRVRESET *PFNPDMDRVRESET;
2641
2642/**
2643 * Suspend notification.
2644 *
2645 * @returns VBox status.
2646 * @param pDrvIns The driver instance data.
2647 */
2648typedef DECLCALLBACK(void) FNPDMDRVSUSPEND(PPDMDRVINS pDrvIns);
2649/** Pointer to a FNPDMDRVSUSPEND() function. */
2650typedef FNPDMDRVSUSPEND *PFNPDMDRVSUSPEND;
2651
2652/**
2653 * Resume notification.
2654 *
2655 * @returns VBox status.
2656 * @param pDrvIns The driver instance data.
2657 */
2658typedef DECLCALLBACK(void) FNPDMDRVRESUME(PPDMDRVINS pDrvIns);
2659/** Pointer to a FNPDMDRVRESUME() function. */
2660typedef FNPDMDRVRESUME *PFNPDMDRVRESUME;
2661
2662/**
2663 * Power Off notification.
2664 *
2665 * @param pDrvIns The driver instance data.
2666 */
2667typedef DECLCALLBACK(void) FNPDMDRVPOWEROFF(PPDMDRVINS pDrvIns);
2668/** Pointer to a FNPDMDRVPOWEROFF() function. */
2669typedef FNPDMDRVPOWEROFF *PFNPDMDRVPOWEROFF;
2670
2671/**
2672 * Detach notification.
2673 *
2674 * This is called when a driver below it in the chain is detaching itself
2675 * from it. The driver should adjust it's state to reflect this.
2676 *
2677 * This is like ejecting a cdrom or floppy.
2678 *
2679 * @param pDrvIns The driver instance.
2680 */
2681typedef DECLCALLBACK(void) FNPDMDRVDETACH(PPDMDRVINS pDrvIns);
2682/** Pointer to a FNPDMDRVDETACH() function. */
2683typedef FNPDMDRVDETACH *PFNPDMDRVDETACH;
2684
2685
2686
2687/** PDM Driver Registration Structure,
2688 * This structure is used when registering a driver from
2689 * VBoxInitDrivers() (HC Ring-3). PDM will continue use till
2690 * the VM is terminated.
2691 */
2692typedef struct PDMDRVREG
2693{
2694 /** Structure version. PDM_DRVREG_VERSION defines the current version. */
2695 uint32_t u32Version;
2696 /** Driver name. */
2697 char szDriverName[32];
2698 /** The description of the driver. The UTF-8 string pointed to shall, like this structure,
2699 * remain unchanged from registration till VM destruction. */
2700 const char *pszDescription;
2701
2702 /** Flags, combination of the PDM_DRVREG_FLAGS_* \#defines. */
2703 RTUINT fFlags;
2704 /** Driver class(es), combination of the PDM_DRVREG_CLASS_* \#defines. */
2705 RTUINT fClass;
2706 /** Maximum number of instances (per VM). */
2707 RTUINT cMaxInstances;
2708 /** Size of the instance data. */
2709 RTUINT cbInstance;
2710
2711 /** Construct instance - required. */
2712 PFNPDMDRVCONSTRUCT pfnConstruct;
2713 /** Destruct instance - optional. */
2714 PFNPDMDRVDESTRUCT pfnDestruct;
2715 /** I/O control - optional. */
2716 PFNPDMDRVIOCTL pfnIOCtl;
2717 /** Power on notification - optional. */
2718 PFNPDMDRVPOWERON pfnPowerOn;
2719 /** Reset notification - optional. */
2720 PFNPDMDRVRESET pfnReset;
2721 /** Suspend notification - optional. */
2722 PFNPDMDRVSUSPEND pfnSuspend;
2723 /** Resume notification - optional. */
2724 PFNPDMDRVRESUME pfnResume;
2725 /** Detach notification - optional. */
2726 PFNPDMDRVDETACH pfnDetach;
2727 /** Power off notification - optional. */
2728 PFNPDMDRVPOWEROFF pfnPowerOff;
2729
2730} PDMDRVREG;
2731/** Pointer to a PDM Driver Structure. */
2732typedef PDMDRVREG *PPDMDRVREG;
2733/** Const pointer to a PDM Driver Structure. */
2734typedef PDMDRVREG const *PCPDMDRVREG;
2735
2736/** Current DRVREG version number. */
2737#define PDM_DRVREG_VERSION 0x80010000
2738
2739/** PDM Device Flags.
2740 * @{ */
2741/** @def PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT
2742 * The bit count for the current host. */
2743#if HC_ARCH_BITS == 32
2744# define PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT 0x000000001
2745#elif HC_ARCH_BITS == 64
2746# define PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT 0x000000002
2747#else
2748# error Unsupported HC_ARCH_BITS value.
2749#endif
2750/** The host bit count mask. */
2751#define PDM_DRVREG_FLAGS_HOST_BITS_MASK 0x000000003
2752
2753/** @} */
2754
2755
2756/** PDM Driver Classes.
2757 * @{ */
2758/** Mouse input driver. */
2759#define PDM_DRVREG_CLASS_MOUSE BIT(0)
2760/** Keyboard input driver. */
2761#define PDM_DRVREG_CLASS_KEYBOARD BIT(1)
2762/** Display driver. */
2763#define PDM_DRVREG_CLASS_DISPLAY BIT(2)
2764/** Network transport driver. */
2765#define PDM_DRVREG_CLASS_NETWORK BIT(3)
2766/** Block driver. */
2767#define PDM_DRVREG_CLASS_BLOCK BIT(4)
2768/** Media driver. */
2769#define PDM_DRVREG_CLASS_MEDIA BIT(5)
2770/** Mountable driver. */
2771#define PDM_DRVREG_CLASS_MOUNTABLE BIT(6)
2772/** Audio driver. */
2773#define PDM_DRVREG_CLASS_AUDIO BIT(7)
2774/** VMMDev driver. */
2775#define PDM_DRVREG_CLASS_VMMDEV BIT(8)
2776/** Status driver. */
2777#define PDM_DRVREG_CLASS_STATUS BIT(9)
2778/** ACPI driver. */
2779#define PDM_DRVREG_CLASS_ACPI BIT(10)
2780/** USB related driver. */
2781#define PDM_DRVREG_CLASS_USB BIT(11)
2782/** ISCSI Transport related driver. */
2783#define PDM_DRVREG_CLASS_ISCSITRANSPORT BIT(12)
2784/** Char driver. */
2785#define PDM_DRVREG_CLASS_CHAR BIT(13)
2786/** Stream driver. */
2787#define PDM_DRVREG_CLASS_STREAM BIT(14)
2788/** @} */
2789
2790
2791/**
2792 * Poller callback.
2793 *
2794 * @param pDrvIns The driver instance.
2795 */
2796typedef DECLCALLBACK(void) FNPDMDRVPOLLER(PPDMDRVINS pDrvIns);
2797/** Pointer to a FNPDMDRVPOLLER function. */
2798typedef FNPDMDRVPOLLER *PFNPDMDRVPOLLER;
2799
2800#ifdef IN_RING3
2801/**
2802 * PDM Driver API.
2803 */
2804typedef struct PDMDRVHLP
2805{
2806 /** Structure version. PDM_DRVHLP_VERSION defines the current version. */
2807 uint32_t u32Version;
2808
2809 /**
2810 * Attaches a driver (chain) to the driver.
2811 *
2812 * @returns VBox status code.
2813 * @param pDrvIns Driver instance.
2814 * @param ppBaseInterface Where to store the pointer to the base interface.
2815 */
2816 DECLR3CALLBACKMEMBER(int, pfnAttach,(PPDMDRVINS pDrvIns, PPDMIBASE *ppBaseInterface));
2817
2818 /**
2819 * Detach the driver the drivers below us.
2820 *
2821 * @returns VBox status code.
2822 * @param pDrvIns Driver instance.
2823 */
2824 DECLR3CALLBACKMEMBER(int, pfnDetach,(PPDMDRVINS pDrvIns));
2825
2826 /**
2827 * Detach the driver from the driver above it and destroy this
2828 * driver and all drivers below it.
2829 *
2830 * @returns VBox status code.
2831 * @param pDrvIns Driver instance.
2832 */
2833 DECLR3CALLBACKMEMBER(int, pfnDetachSelf,(PPDMDRVINS pDrvIns));
2834
2835 /**
2836 * Prepare a media mount.
2837 *
2838 * The driver must not have anything attached to itself
2839 * when calling this function as the purpose is to set up the configuration
2840 * of an future attachment.
2841 *
2842 * @returns VBox status code
2843 * @param pDrvIns Driver instance.
2844 * @param pszFilename Pointer to filename. If this is NULL it assumed that the caller have
2845 * constructed a configuration which can be attached to the bottom driver.
2846 * @param pszCoreDriver Core driver name. NULL will cause autodetection. Ignored if pszFilanem is NULL.
2847 */
2848 DECLR3CALLBACKMEMBER(int, pfnMountPrepare,(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver));
2849
2850 /**
2851 * Assert that the current thread is the emulation thread.
2852 *
2853 * @returns True if correct.
2854 * @returns False if wrong.
2855 * @param pDrvIns Driver instance.
2856 * @param pszFile Filename of the assertion location.
2857 * @param iLine Linenumber of the assertion location.
2858 * @param pszFunction Function of the assertion location.
2859 */
2860 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
2861
2862 /**
2863 * Assert that the current thread is NOT the emulation thread.
2864 *
2865 * @returns True if correct.
2866 * @returns False if wrong.
2867 * @param pDrvIns Driver instance.
2868 * @param pszFile Filename of the assertion location.
2869 * @param iLine Linenumber of the assertion location.
2870 * @param pszFunction Function of the assertion location.
2871 */
2872 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
2873
2874 /**
2875 * Set the VM error message
2876 *
2877 * @returns rc.
2878 * @param pDrvIns Driver instance.
2879 * @param rc VBox status code.
2880 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2881 * @param pszFormat Error message format string.
2882 * @param ... Error message arguments.
2883 */
2884 DECLR3CALLBACKMEMBER(int, pfnVMSetError,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
2885
2886 /**
2887 * Set the VM error message
2888 *
2889 * @returns rc.
2890 * @param pDrvIns Driver instance.
2891 * @param rc VBox status code.
2892 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2893 * @param pszFormat Error message format string.
2894 * @param va Error message arguments.
2895 */
2896 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
2897
2898 /**
2899 * Set the VM runtime error message
2900 *
2901 * @returns VBox status code.
2902 * @param pDrvIns Driver instance.
2903 * @param fFatal Whether it is a fatal error or not.
2904 * @param pszErrorID Error ID string.
2905 * @param pszFormat Error message format string.
2906 * @param ... Error message arguments.
2907 */
2908 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...));
2909
2910 /**
2911 * Set the VM runtime error message
2912 *
2913 * @returns VBox status code.
2914 * @param pDrvIns Driver instance.
2915 * @param fFatal Whether it is a fatal error or not.
2916 * @param pszErrorID Error ID string.
2917 * @param pszFormat Error message format string.
2918 * @param va Error message arguments.
2919 */
2920 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
2921
2922 /**
2923 * Create a queue.
2924 *
2925 * @returns VBox status code.
2926 * @param pDrvIns Driver instance.
2927 * @param cbItem Size a queue item.
2928 * @param cItems Number of items in the queue.
2929 * @param cMilliesInterval Number of milliseconds between polling the queue.
2930 * If 0 then the emulation thread will be notified whenever an item arrives.
2931 * @param pfnCallback The consumer function.
2932 * @param ppQueue Where to store the queue handle on success.
2933 * @thread The emulation thread.
2934 */
2935 DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMDRVINS pDrvIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval, PFNPDMQUEUEDRV pfnCallback, PPDMQUEUE *ppQueue));
2936
2937 /**
2938 * Register a poller function.
2939 * TEMPORARY HACK FOR NETWORKING! DON'T USE!
2940 *
2941 * @returns VBox status code.
2942 * @param pDrvIns Driver instance.
2943 * @param pfnPoller The callback function.
2944 */
2945 DECLR3CALLBACKMEMBER(int, pfnPDMPollerRegister,(PPDMDRVINS pDrvIns, PFNPDMDRVPOLLER pfnPoller));
2946
2947 /**
2948 * Query the virtual timer frequency.
2949 *
2950 * @returns Frequency in Hz.
2951 * @param pDrvIns Driver instance.
2952 * @thread Any thread.
2953 */
2954 DECLR3CALLBACKMEMBER(uint64_t, pfnTMGetVirtualFreq,(PPDMDRVINS pDrvIns));
2955
2956 /**
2957 * Query the virtual time.
2958 *
2959 * @returns The current virtual time.
2960 * @param pDrvIns Driver instance.
2961 * @thread Any thread.
2962 */
2963 DECLR3CALLBACKMEMBER(uint64_t, pfnTMGetVirtualTime,(PPDMDRVINS pDrvIns));
2964
2965 /**
2966 * Creates a timer.
2967 *
2968 * @returns VBox status.
2969 * @param pDrvIns Driver instance.
2970 * @param enmClock The clock to use on this timer.
2971 * @param pfnCallback Callback function.
2972 * @param pszDesc Pointer to description string which must stay around
2973 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
2974 * @param ppTimer Where to store the timer on success.
2975 */
2976 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer));
2977
2978 /**
2979 * Register a save state data unit.
2980 *
2981 * @returns VBox status.
2982 * @param pDrvIns Driver instance.
2983 * @param pszName Data unit name.
2984 * @param u32Instance The instance identifier of the data unit.
2985 * This must together with the name be unique.
2986 * @param u32Version Data layout version number.
2987 * @param cbGuess The approximate amount of data in the unit.
2988 * Only for progress indicators.
2989 * @param pfnSavePrep Prepare save callback, optional.
2990 * @param pfnSaveExec Execute save callback, optional.
2991 * @param pfnSaveDone Done save callback, optional.
2992 * @param pfnLoadPrep Prepare load callback, optional.
2993 * @param pfnLoadExec Execute load callback, optional.
2994 * @param pfnLoadDone Done load callback, optional.
2995 */
2996 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
2997 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
2998 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone));
2999
3000 /**
3001 * Deregister a save state data unit.
3002 *
3003 * @returns VBox status.
3004 * @param pDrvIns Driver instance.
3005 * @param pszName Data unit name.
3006 * @param u32Instance The instance identifier of the data unit.
3007 * This must together with the name be unique.
3008 */
3009 DECLR3CALLBACKMEMBER(int, pfnSSMDeregister,(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance));
3010
3011 /**
3012 * Registers a statistics sample if statistics are enabled.
3013 *
3014 * @param pDrvIns Driver instance.
3015 * @param pvSample Pointer to the sample.
3016 * @param enmType Sample type. This indicates what pvSample is pointing at.
3017 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
3018 * Further nesting is possible.
3019 * @param enmUnit Sample unit.
3020 * @param pszDesc Sample description.
3021 */
3022 DECLR3CALLBACKMEMBER(void, pfnSTAMRegister,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName,
3023 STAMUNIT enmUnit, const char *pszDesc));
3024
3025 /**
3026 * Same as pfnSTAMRegister except that the name is specified in a
3027 * RTStrPrintf like fashion.
3028 *
3029 * @returns VBox status.
3030 * @param pDrvIns Driver instance.
3031 * @param pvSample Pointer to the sample.
3032 * @param enmType Sample type. This indicates what pvSample is pointing at.
3033 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
3034 * @param enmUnit Sample unit.
3035 * @param pszDesc Sample description.
3036 * @param pszName The sample name format string.
3037 * @param ... Arguments to the format string.
3038 */
3039 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterF,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
3040 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...));
3041
3042 /**
3043 * Same as pfnSTAMRegister except that the name is specified in a
3044 * RTStrPrintfV like fashion.
3045 *
3046 * @returns VBox status.
3047 * @param pDrvIns Driver instance.
3048 * @param pvSample Pointer to the sample.
3049 * @param enmType Sample type. This indicates what pvSample is pointing at.
3050 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
3051 * @param enmUnit Sample unit.
3052 * @param pszDesc Sample description.
3053 * @param pszName The sample name format string.
3054 * @param args Arguments to the format string.
3055 */
3056 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
3057 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args));
3058
3059 /**
3060 * Calls the HC R0 VMM entry point, in a safer but slower manner than SUPCallVMMR0.
3061 * When entering using this call the R0 components can call into the host kernel
3062 * (i.e. use the SUPR0 and RT APIs).
3063 *
3064 * See VMMR0Entry() for more details.
3065 *
3066 * @returns error code specific to uFunction.
3067 * @param pDrvIns The driver instance.
3068 * @param uOperation Operation to execute.
3069 * This is limited to services.
3070 * @param pvArg Pointer to argument structure or if cbArg is 0 just an value.
3071 * @param cbArg The size of the argument. This is used to copy whatever the argument
3072 * points at into a kernel buffer to avoid problems like the user page
3073 * being invalidated while we're executing the call.
3074 */
3075 DECLR3CALLBACKMEMBER(int, pfnSUPCallVMMR0Ex,(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg));
3076
3077 /** Just a safety precaution. */
3078 uint32_t u32TheEnd;
3079} PDMDRVHLP;
3080/** Pointer PDM Driver API. */
3081typedef PDMDRVHLP *PPDMDRVHLP;
3082/** Pointer const PDM Driver API. */
3083typedef const PDMDRVHLP *PCPDMDRVHLP;
3084
3085/** Current DRVHLP version number. */
3086#define PDM_DRVHLP_VERSION 0x90010000
3087
3088
3089
3090/**
3091 * PDM Driver Instance.
3092 */
3093typedef struct PDMDRVINS
3094{
3095 /** Structure version. PDM_DRVINS_VERSION defines the current version. */
3096 uint32_t u32Version;
3097
3098 /** Internal data. */
3099 union
3100 {
3101#ifdef PDMDRVINSINT_DECLARED
3102 PDMDRVINSINT s;
3103#endif
3104 uint8_t padding[HC_ARCH_BITS == 32 ? 32 : 64];
3105 } Internal;
3106
3107 /** Pointer the PDM Driver API. */
3108 HCPTRTYPE(PCPDMDRVHLP) pDrvHlp;
3109 /** Pointer to driver registration structure. */
3110 HCPTRTYPE(PCPDMDRVREG) pDrvReg;
3111 /** Configuration handle. */
3112 HCPTRTYPE(PCFGMNODE) pCfgHandle;
3113 /** Driver instance number. */
3114 RTUINT iInstance;
3115 /** Pointer to the base interface of the device/driver instance above. */
3116 HCPTRTYPE(PPDMIBASE) pUpBase;
3117 /** Pointer to the base interface of the driver instance below. */
3118 HCPTRTYPE(PPDMIBASE) pDownBase;
3119 /** The base interface of the driver.
3120 * The driver constructor initializes this. */
3121 PDMIBASE IBase;
3122 /* padding to make achInstanceData aligned at 16 byte boundrary. */
3123 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 3 : 1];
3124 /** Pointer to driver instance data. */
3125 HCPTRTYPE(void *) pvInstanceData;
3126 /** Driver instance data. The size of this area is defined
3127 * in the PDMDRVREG::cbInstanceData field. */
3128 char achInstanceData[4];
3129} PDMDRVINS;
3130
3131/** Current DRVREG version number. */
3132#define PDM_DRVINS_VERSION 0xa0010000
3133
3134/** Converts a pointer to the PDMDRVINS::IBase to a pointer to PDMDRVINS. */
3135#define PDMIBASE_2_PDMDRV(pInterface) ( (PPDMDRVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDRVINS, IBase)) )
3136
3137/**
3138 * @copydoc PDMDRVHLP::pfnVMSetError
3139 */
3140DECLINLINE(int) PDMDrvHlpVMSetError(PPDMDRVINS pDrvIns, const int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
3141{
3142 va_list va;
3143 va_start(va, pszFormat);
3144 pDrvIns->pDrvHlp->pfnVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
3145 va_end(va);
3146 return rc;
3147}
3148
3149/** @def PDMDRV_SET_ERROR
3150 * Set the VM error. See PDMDrvHlpVMSetError() for printf like message formatting.
3151 */
3152#define PDMDRV_SET_ERROR(pDrvIns, rc, pszError) \
3153 PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, "%s", pszError)
3154
3155/**
3156 * @copydoc PDMDRVHLP::pfnVMSetRuntimeError
3157 */
3158DECLINLINE(int) PDMDrvHlpVMSetRuntimeError(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...)
3159{
3160 va_list va;
3161 int rc;
3162 va_start(va, pszFormat);
3163 rc = pDrvIns->pDrvHlp->pfnVMSetRuntimeErrorV(pDrvIns, fFatal, pszErrorID, pszFormat, va);
3164 va_end(va);
3165 return rc;
3166}
3167
3168/** @def PDMDRV_SET_RUNTIME_ERROR
3169 * Set the VM runtime error. See PDMDrvHlpVMSetRuntimeError() for printf like message formatting.
3170 */
3171#define PDMDRV_SET_RUNTIME_ERROR(pDrvIns, fFatal, pszErrorID, pszError) \
3172 PDMDrvHlpVMSetError(pDrvIns, fFatal, pszErrorID, "%s", pszError)
3173
3174#endif /* IN_RING3 */
3175
3176
3177/** @def PDMDRV_ASSERT_EMT
3178 * Assert that the current thread is the emulation thread.
3179 */
3180#ifdef VBOX_STRICT
3181# define PDMDRV_ASSERT_EMT(pDrvIns) pDrvIns->pDrvHlp->pfnAssertEMT(pDrvIns, __FILE__, __LINE__, __FUNCTION__)
3182#else
3183# define PDMDRV_ASSERT_EMT(pDrvIns) do { } while (0)
3184#endif
3185
3186/** @def PDMDRV_ASSERT_OTHER
3187 * Assert that the current thread is NOT the emulation thread.
3188 */
3189#ifdef VBOX_STRICT
3190# define PDMDRV_ASSERT_OTHER(pDrvIns) pDrvIns->pDrvHlp->pfnAssertOther(pDrvIns, __FILE__, __LINE__, __FUNCTION__)
3191#else
3192# define PDMDRV_ASSERT_OTHER(pDrvIns) do { } while (0)
3193#endif
3194
3195
3196#ifdef IN_RING3
3197/**
3198 * @copydoc PDMDRVHLP::pfnSTAMRegister
3199 */
3200DECLINLINE(void) PDMDrvHlpSTAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
3201{
3202 pDrvIns->pDrvHlp->pfnSTAMRegister(pDrvIns, pvSample, enmType, pszName, enmUnit, pszDesc);
3203}
3204
3205/**
3206 * @copydoc PDMDRVHLP::pfnSTAMRegisterF
3207 */
3208DECLINLINE(void) PDMDrvHlpSTAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
3209 const char *pszDesc, const char *pszName, ...)
3210{
3211 va_list va;
3212 va_start(va, pszName);
3213 pDrvIns->pDrvHlp->pfnSTAMRegisterV(pDrvIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
3214 va_end(va);
3215}
3216#endif /* IN_RING3 */
3217
3218
3219
3220/** Pointer to callbacks provided to the VBoxDriverRegister() call. */
3221typedef struct PDMDRVREGCB *PPDMDRVREGCB;
3222/** Pointer to const callbacks provided to the VBoxDriverRegister() call. */
3223typedef const struct PDMDRVREGCB *PCPDMDRVREGCB;
3224
3225/**
3226 * Callbacks for VBoxDriverRegister().
3227 */
3228typedef struct PDMDRVREGCB
3229{
3230 /** Interface version.
3231 * This is set to PDM_DRVREG_CB_VERSION. */
3232 uint32_t u32Version;
3233
3234 /**
3235 * Registers a driver with the current VM instance.
3236 *
3237 * @returns VBox status code.
3238 * @param pCallbacks Pointer to the callback table.
3239 * @param pDrvReg Pointer to the driver registration record.
3240 * This data must be permanent and readonly.
3241 */
3242 DECLR3CALLBACKMEMBER(int, pfnRegister,(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pDrvReg));
3243} PDMDRVREGCB;
3244
3245/** Current version of the PDMDRVREGCB structure. */
3246#define PDM_DRVREG_CB_VERSION 0xb0010000
3247
3248
3249/**
3250 * The VBoxDriverRegister callback function.
3251 *
3252 * PDM will invoke this function after loading a driver module and letting
3253 * the module decide which drivers to register and how to handle conflicts.
3254 *
3255 * @returns VBox status code.
3256 * @param pCallbacks Pointer to the callback table.
3257 * @param u32Version VBox version number.
3258 */
3259typedef DECLCALLBACK(int) FNPDMVBOXDRIVERSREGISTER(PCPDMDRVREGCB pCallbacks, uint32_t u32Version);
3260
3261/**
3262 * Register external drivers
3263 *
3264 * @returns VBox status code.
3265 * @param pVM The VM to operate on.
3266 * @param pfnCallback Driver registration callback
3267 */
3268PDMR3DECL(int) PDMR3RegisterDrivers(PVM pVM, FNPDMVBOXDRIVERSREGISTER pfnCallback);
3269
3270/** @} */
3271
3272
3273
3274
3275/** @defgroup grp_pdm_device Devices
3276 * @ingroup grp_pdm
3277 * @{
3278 */
3279
3280
3281/** @def PDMBOTHCBDECL
3282 * Macro for declaring a callback which is static in HC and exported in GC.
3283 */
3284#if defined(IN_GC) || defined(IN_RING0)
3285# define PDMBOTHCBDECL(type) DECLEXPORT(type)
3286#else
3287# define PDMBOTHCBDECL(type) static type
3288#endif
3289
3290
3291/**
3292 * Construct a device instance for a VM.
3293 *
3294 * @returns VBox status.
3295 * @param pDevIns The device instance data.
3296 * If the registration structure is needed, pDevIns->pDevReg points to it.
3297 * @param iInstance Instance number. Use this to figure out which registers and such to use.
3298 * The instance number is also found in pDevIns->iInstance, but since it's
3299 * likely to be freqently used PDM passes it as parameter.
3300 * @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
3301 * of the device instance. It's also found in pDevIns->pCfgHandle, but since it's
3302 * primary usage will in this function it's passed as a parameter.
3303 */
3304typedef DECLCALLBACK(int) FNPDMDEVCONSTRUCT(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfgHandle);
3305/** Pointer to a FNPDMDEVCONSTRUCT() function. */
3306typedef FNPDMDEVCONSTRUCT *PFNPDMDEVCONSTRUCT;
3307
3308/**
3309 * Destruct a device instance.
3310 *
3311 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
3312 * resources can be freed correctly.
3313 *
3314 * @returns VBox status.
3315 * @param pDevIns The device instance data.
3316 */
3317typedef DECLCALLBACK(int) FNPDMDEVDESTRUCT(PPDMDEVINS pDevIns);
3318/** Pointer to a FNPDMDEVDESTRUCT() function. */
3319typedef FNPDMDEVDESTRUCT *PFNPDMDEVDESTRUCT;
3320
3321/**
3322 * Device relocation callback.
3323 *
3324 * When this callback is called the device instance data, and if the
3325 * device have a GC component, is being relocated, or/and the selectors
3326 * have been changed. The device must use the chance to perform the
3327 * necessary pointer relocations and data updates.
3328 *
3329 * Before the GC code is executed the first time, this function will be
3330 * called with a 0 delta so GC pointer calculations can be one in one place.
3331 *
3332 * @param pDevIns Pointer to the device instance.
3333 * @param offDelta The relocation delta relative to the old location.
3334 *
3335 * @remark A relocation CANNOT fail.
3336 */
3337typedef DECLCALLBACK(void) FNPDMDEVRELOCATE(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
3338/** Pointer to a FNPDMDEVRELOCATE() function. */
3339typedef FNPDMDEVRELOCATE *PFNPDMDEVRELOCATE;
3340
3341
3342/**
3343 * Device I/O Control interface.
3344 *
3345 * This is used by external components, such as the COM interface, to
3346 * communicate with devices using a class wide interface or a device
3347 * specific interface.
3348 *
3349 * @returns VBox status code.
3350 * @param pDevIns Pointer to the device instance.
3351 * @param uFunction Function to perform.
3352 * @param pvIn Pointer to input data.
3353 * @param cbIn Size of input data.
3354 * @param pvOut Pointer to output data.
3355 * @param cbOut Size of output data.
3356 * @param pcbOut Where to store the actual size of the output data.
3357 */
3358typedef DECLCALLBACK(int) FNPDMDEVIOCTL(PPDMDEVINS pDevIns, RTUINT uFunction,
3359 void *pvIn, RTUINT cbIn,
3360 void *pvOut, RTUINT cbOut, PRTUINT pcbOut);
3361/** Pointer to a FNPDMDEVIOCTL() function. */
3362typedef FNPDMDEVIOCTL *PFNPDMDEVIOCTL;
3363
3364/**
3365 * Power On notification.
3366 *
3367 * @returns VBox status.
3368 * @param pDevIns The device instance data.
3369 */
3370typedef DECLCALLBACK(void) FNPDMDEVPOWERON(PPDMDEVINS pDevIns);
3371/** Pointer to a FNPDMDEVPOWERON() function. */
3372typedef FNPDMDEVPOWERON *PFNPDMDEVPOWERON;
3373
3374/**
3375 * Reset notification.
3376 *
3377 * @returns VBox status.
3378 * @param pDevIns The device instance data.
3379 */
3380typedef DECLCALLBACK(void) FNPDMDEVRESET(PPDMDEVINS pDevIns);
3381/** Pointer to a FNPDMDEVRESET() function. */
3382typedef FNPDMDEVRESET *PFNPDMDEVRESET;
3383
3384/**
3385 * Suspend notification.
3386 *
3387 * @returns VBox status.
3388 * @param pDevIns The device instance data.
3389 */
3390typedef DECLCALLBACK(void) FNPDMDEVSUSPEND(PPDMDEVINS pDevIns);
3391/** Pointer to a FNPDMDEVSUSPEND() function. */
3392typedef FNPDMDEVSUSPEND *PFNPDMDEVSUSPEND;
3393
3394/**
3395 * Resume notification.
3396 *
3397 * @returns VBox status.
3398 * @param pDevIns The device instance data.
3399 */
3400typedef DECLCALLBACK(void) FNPDMDEVRESUME(PPDMDEVINS pDevIns);
3401/** Pointer to a FNPDMDEVRESUME() function. */
3402typedef FNPDMDEVRESUME *PFNPDMDEVRESUME;
3403
3404/**
3405 * Power Off notification.
3406 *
3407 * @param pDevIns The device instance data.
3408 */
3409typedef DECLCALLBACK(void) FNPDMDEVPOWEROFF(PPDMDEVINS pDevIns);
3410/** Pointer to a FNPDMDEVPOWEROFF() function. */
3411typedef FNPDMDEVPOWEROFF *PFNPDMDEVPOWEROFF;
3412
3413/**
3414 * Attach command.
3415 *
3416 * This is called to let the device attach to a driver for a specified LUN
3417 * during runtime. This is not called during VM construction, the device
3418 * constructor have to attach to all the available drivers.
3419 *
3420 * This is like plugging in the keyboard or mouse after turning on the PC.
3421 *
3422 * @returns VBox status code.
3423 * @param pDevIns The device instance.
3424 * @param iLUN The logical unit which is being detached.
3425 */
3426typedef DECLCALLBACK(int) FNPDMDEVATTACH(PPDMDEVINS pDevIns, unsigned iLUN);
3427/** Pointer to a FNPDMDEVATTACH() function. */
3428typedef FNPDMDEVATTACH *PFNPDMDEVATTACH;
3429
3430/**
3431 * Detach notification.
3432 *
3433 * This is called when a driver is detaching itself from a LUN of the device.
3434 * The device should adjust it's state to reflect this.
3435 *
3436 * This is like unplugging the network cable to use it for the laptop or
3437 * something while the PC is still running.
3438 *
3439 * @param pDevIns The device instance.
3440 * @param iLUN The logical unit which is being detached.
3441 */
3442typedef DECLCALLBACK(void) FNPDMDEVDETACH(PPDMDEVINS pDevIns, unsigned iLUN);
3443/** Pointer to a FNPDMDEVDETACH() function. */
3444typedef FNPDMDEVDETACH *PFNPDMDEVDETACH;
3445
3446/**
3447 * Query the base interface of a logical unit.
3448 *
3449 * @returns VBOX status code.
3450 * @param pDevIns The device instance.
3451 * @param iLUN The logicial unit to query.
3452 * @param ppBase Where to store the pointer to the base interface of the LUN.
3453 */
3454typedef DECLCALLBACK(int) FNPDMDEVQUERYINTERFACE(PPDMDEVINS pDevIns, unsigned iLUN, PPDMIBASE *ppBase);
3455/** Pointer to a FNPDMDEVQUERYINTERFACE() function. */
3456typedef FNPDMDEVQUERYINTERFACE *PFNPDMDEVQUERYINTERFACE;
3457
3458/**
3459 * Init complete notification.
3460 * This can be done to do communication with other devices and other
3461 * initialization which requires everything to be in place.
3462 *
3463 * @returns VBOX status code.
3464 * @param pDevIns The device instance.
3465 */
3466typedef DECLCALLBACK(int) FNPDMDEVINITCOMPLETE(PPDMDEVINS pDevIns);
3467/** Pointer to a FNPDMDEVINITCOMPLETE() function. */
3468typedef FNPDMDEVINITCOMPLETE *PFNPDMDEVINITCOMPLETE;
3469
3470
3471
3472/** PDM Device Registration Structure,
3473 * This structure is used when registering a device from
3474 * VBoxInitDevices() in HC Ring-3. PDM will continue use till
3475 * the VM is terminated.
3476 */
3477typedef struct PDMDEVREG
3478{
3479 /** Structure version. PDM_DEVREG_VERSION defines the current version. */
3480 uint32_t u32Version;
3481 /** Device name. */
3482 char szDeviceName[32];
3483 /** Name of guest context module (no path).
3484 * Only evalutated if PDM_DEVREG_FLAGS_GC is set. */
3485 char szGCMod[32];
3486 /** Name of guest context module (no path).
3487 * Only evalutated if PDM_DEVREG_FLAGS_GC is set. */
3488 char szR0Mod[32];
3489 /** The description of the device. The UTF-8 string pointed to shall, like this structure,
3490 * remain unchanged from registration till VM destruction. */
3491 const char *pszDescription;
3492
3493 /** Flags, combination of the PDM_DEVREG_FLAGS_* \#defines. */
3494 RTUINT fFlags;
3495 /** Device class(es), combination of the PDM_DEVREG_CLASS_* \#defines. */
3496 RTUINT fClass;
3497 /** Maximum number of instances (per VM). */
3498 RTUINT cMaxInstances;
3499 /** Size of the instance data. */
3500 RTUINT cbInstance;
3501
3502 /** Construct instance - required. */
3503 PFNPDMDEVCONSTRUCT pfnConstruct;
3504 /** Destruct instance - optional. */
3505 PFNPDMDEVDESTRUCT pfnDestruct;
3506 /** Relocation command - optional. */
3507 PFNPDMDEVRELOCATE pfnRelocate;
3508 /** I/O Control interface - optional. */
3509 PFNPDMDEVIOCTL pfnIOCtl;
3510 /** Power on notification - optional. */
3511 PFNPDMDEVPOWERON pfnPowerOn;
3512 /** Reset notification - optional. */
3513 PFNPDMDEVRESET pfnReset;
3514 /** Suspend notification - optional. */
3515 PFNPDMDEVSUSPEND pfnSuspend;
3516 /** Resume notification - optional. */
3517 PFNPDMDEVRESUME pfnResume;
3518 /** Attach command - optional. */
3519 PFNPDMDEVATTACH pfnAttach;
3520 /** Detach notification - optional. */
3521 PFNPDMDEVDETACH pfnDetach;
3522 /** Query a LUN base interface - optional. */
3523 PFNPDMDEVQUERYINTERFACE pfnQueryInterface;
3524 /** Init complete notification - optional. */
3525 PFNPDMDEVINITCOMPLETE pfnInitComplete;
3526 /** Power off notification - optional. */
3527 PFNPDMDEVPOWEROFF pfnPowerOff;
3528} PDMDEVREG;
3529/** Pointer to a PDM Device Structure. */
3530typedef PDMDEVREG *PPDMDEVREG;
3531/** Const pointer to a PDM Device Structure. */
3532typedef PDMDEVREG const *PCPDMDEVREG;
3533
3534/** Current DEVREG version number. */
3535#define PDM_DEVREG_VERSION 0xc0010000
3536
3537/** PDM Device Flags.
3538 * @{ */
3539/** This flag is used to indicate that the device has a GC component. */
3540#define PDM_DEVREG_FLAGS_GC 0x00000001
3541/** This flag is used to indicate that the device has a R0 component. */
3542#define PDM_DEVREG_FLAGS_R0 0x00010000
3543
3544/** @def PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT
3545 * The bit count for the current host. */
3546#if HC_ARCH_BITS == 32
3547# define PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT 0x00000002
3548#elif HC_ARCH_BITS == 64
3549# define PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT 0x00000004
3550#else
3551# error Unsupported HC_ARCH_BITS value.
3552#endif
3553/** The host bit count mask. */
3554#define PDM_DEVREG_FLAGS_HOST_BITS_MASK 0x00000006
3555
3556/** The device support only 32-bit guests. */
3557#define PDM_DEVREG_FLAGS_GUEST_BITS_32 0x00000008
3558/** The device support only 64-bit guests. */
3559#define PDM_DEVREG_FLAGS_GUEST_BITS_64 0x00000010
3560/** The device support both 32-bit & 64-bit guests. */
3561#define PDM_DEVREG_FLAGS_GUEST_BITS_32_64 0x00000018
3562/** @def PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT
3563 * The guest bit count for the current compilation. */
3564#if GC_ARCH_BITS == 32
3565# define PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT PDM_DEVREG_FLAGS_GUEST_BITS_32
3566#elif GC_ARCH_BITS == 64
3567# define PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT PDM_DEVREG_FLAGS_GUEST_BITS_64
3568#else
3569# error Unsupported GC_ARCH_BITS value.
3570#endif
3571/** The guest bit count mask. */
3572#define PDM_DEVREG_FLAGS_GUEST_BITS_MASK 0x00000018
3573
3574/** Indicates that the devices support PAE36 on a 32-bit guest. */
3575#define PDM_DEVREG_FLAGS_PAE36 0x00000020
3576/** @} */
3577
3578
3579/** PDM Device Classes.
3580 * The order is important, lower bit earlier instantiation.
3581 * @{ */
3582/** Architecture device. */
3583#define PDM_DEVREG_CLASS_ARCH BIT(0)
3584/** Architecture BIOS device. */
3585#define PDM_DEVREG_CLASS_ARCH_BIOS BIT(1)
3586/** PCI bus brigde. */
3587#define PDM_DEVREG_CLASS_BUS_PCI BIT(2)
3588/** ISA bus brigde. */
3589#define PDM_DEVREG_CLASS_BUS_ISA BIT(3)
3590/** Input device (mouse, keyboard, joystick,..). */
3591#define PDM_DEVREG_CLASS_INPUT BIT(4)
3592/** Interrupt controller (PIC). */
3593#define PDM_DEVREG_CLASS_PIC BIT(5)
3594/** Interval controoler (PIT). */
3595#define PDM_DEVREG_CLASS_PIT BIT(6)
3596/** RTC/CMOS. */
3597#define PDM_DEVREG_CLASS_RTC BIT(7)
3598/** DMA controller. */
3599#define PDM_DEVREG_CLASS_DMA BIT(8)
3600/** VMM Device. */
3601#define PDM_DEVREG_CLASS_VMM_DEV BIT(9)
3602/** Graphics device, like VGA. */
3603#define PDM_DEVREG_CLASS_GRAPHICS BIT(10)
3604/** Storage controller device. */
3605#define PDM_DEVREG_CLASS_STORAGE BIT(11)
3606/** Network interface controller. */
3607#define PDM_DEVREG_CLASS_NETWORK BIT(12)
3608/** Audio. */
3609#define PDM_DEVREG_CLASS_AUDIO BIT(13)
3610/** USB bus? */
3611#define PDM_DEVREG_CLASS_BUS_USB BIT(14) /* ??? */
3612/** ACPI. */
3613#define PDM_DEVREG_CLASS_ACPI BIT(15)
3614/** Serial controller device. */
3615#define PDM_DEVREG_CLASS_SERIAL BIT(16)
3616/** Parallel controller device */
3617#define PDM_DEVREG_CLASS_PARALLEL BIT(17)
3618/** Misc devices (always last). */
3619#define PDM_DEVREG_CLASS_MISC BIT(31)
3620/** @} */
3621
3622
3623/** @name IRQ Level for use with the *SetIrq APIs.
3624 * @{
3625 */
3626/** Assert the IRQ (can assume value 1). */
3627#define PDM_IRQ_LEVEL_HIGH BIT(0)
3628/** Deassert the IRQ (can assume value 0). */
3629#define PDM_IRQ_LEVEL_LOW 0
3630/** flip-flop - assert and then deassert it again immediately. */
3631#define PDM_IRQ_LEVEL_FLIP_FLOP (BIT(1) | PDM_IRQ_LEVEL_HIGH)
3632/** @} */
3633
3634
3635/**
3636 * PCI Bus registaration structure.
3637 * All the callbacks, except the PCIBIOS hack, are working on PCI devices.
3638 */
3639typedef struct PDMPCIBUSREG
3640{
3641 /** Structure version number. PDM_PCIBUSREG_VERSION defines the current version. */
3642 uint32_t u32Version;
3643
3644 /**
3645 * Registers the device with the default PCI bus.
3646 *
3647 * @returns VBox status code.
3648 * @param pDevIns Device instance of the PCI Bus.
3649 * @param pPciDev The PCI device structure.
3650 * Any PCI enabled device must keep this in it's instance data!
3651 * Fill in the PCI data config before registration, please.
3652 * @param pszName Pointer to device name (permanent, readonly). For debugging, not unique.
3653 * @param iDev The device number ((dev << 3) | function) the device should have on the bus.
3654 * If negative, the pci bus device will assign one.
3655 */
3656 DECLR3CALLBACKMEMBER(int, pfnRegisterHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev));
3657
3658 /**
3659 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
3660 *
3661 * @returns VBox status code.
3662 * @param pDevIns Device instance of the PCI Bus.
3663 * @param pPciDev The PCI device structure.
3664 * @param iRegion The region number.
3665 * @param cbRegion Size of the region.
3666 * @param iType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
3667 * @param pfnCallback Callback for doing the mapping.
3668 */
3669 DECLR3CALLBACKMEMBER(int, pfnIORegionRegisterHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
3670
3671 /**
3672 * Register PCI configuration space read/write callbacks.
3673 *
3674 * @param pDevIns Device instance of the PCI Bus.
3675 * @param pPciDev The PCI device structure.
3676 * @param pfnRead Pointer to the user defined PCI config read function.
3677 * @param ppfnReadOld Pointer to function pointer which will receive the old (default)
3678 * PCI config read function. This way, user can decide when (and if)
3679 * to call default PCI config read function. Can be NULL.
3680 * @param pfnWrite Pointer to the user defined PCI config write function.
3681 * @param pfnWriteOld Pointer to function pointer which will receive the old (default)
3682 * PCI config write function. This way, user can decide when (and if)
3683 * to call default PCI config write function. Can be NULL.
3684 * @thread EMT
3685 */
3686 DECLR3CALLBACKMEMBER(void, pfnSetConfigCallbacksHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
3687 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
3688
3689 /**
3690 * Set the IRQ for a PCI device.
3691 *
3692 * @param pDevIns Device instance of the PCI Bus.
3693 * @param pPciDev The PCI device structure.
3694 * @param iIrq IRQ number to set.
3695 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3696 */
3697 DECLR3CALLBACKMEMBER(void, pfnSetIrqHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
3698
3699 /**
3700 * Saves a state of the PCI device.
3701 *
3702 * @returns VBox status code.
3703 * @param pDevIns Device instance of the PCI Bus.
3704 * @param pPciDev Pointer to PCI device.
3705 * @param pSSMHandle The handle to save the state to.
3706 */
3707 DECLR3CALLBACKMEMBER(int, pfnSaveExecHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
3708
3709 /**
3710 * Loads a saved PCI device state.
3711 *
3712 * @returns VBox status code.
3713 * @param pDevIns Device instance of the PCI Bus.
3714 * @param pPciDev Pointer to PCI device.
3715 * @param pSSMHandle The handle to the saved state.
3716 */
3717 DECLR3CALLBACKMEMBER(int, pfnLoadExecHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
3718
3719 /**
3720 * Called to perform the job of the bios.
3721 * This is only called for the first PCI Bus - it is expected to
3722 * service all the PCI buses.
3723 *
3724 * @returns VBox status.
3725 * @param pDevIns Device instance of the first bus.
3726 */
3727 DECLR3CALLBACKMEMBER(int, pfnFakePCIBIOSHC,(PPDMDEVINS pDevIns));
3728
3729 /** The name of the SetIrq GC entry point. */
3730 const char *pszSetIrqGC;
3731
3732 /** The name of the SetIrq R0 entry point. */
3733 const char *pszSetIrqR0;
3734
3735} PDMPCIBUSREG;
3736/** Pointer to a PCI bus registration structure. */
3737typedef PDMPCIBUSREG *PPDMPCIBUSREG;
3738
3739/** Current PDMPCIBUSREG version number. */
3740#define PDM_PCIBUSREG_VERSION 0xd0020000
3741
3742/**
3743 * PCI Bus GC helpers.
3744 */
3745typedef struct PDMPCIHLPGC
3746{
3747 /** Structure version. PDM_PCIHLPGC_VERSION defines the current version. */
3748 uint32_t u32Version;
3749
3750 /**
3751 * Set an ISA IRQ.
3752 *
3753 * @param pDevIns PCI device instance.
3754 * @param iIrq IRQ number to set.
3755 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3756 * @thread EMT only.
3757 */
3758 DECLGCCALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3759
3760 /**
3761 * Set an I/O-APIC IRQ.
3762 *
3763 * @param pDevIns PCI device instance.
3764 * @param iIrq IRQ number to set.
3765 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3766 * @thread EMT only.
3767 */
3768 DECLGCCALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3769
3770#ifdef VBOX_WITH_PDM_LOCK
3771 /**
3772 * Acquires the PDM lock.
3773 *
3774 * @returns VINF_SUCCESS on success.
3775 * @returns rc if we failed to acquire the lock.
3776 * @param pDevIns The PCI device instance.
3777 * @param rc What to return if we fail to acquire the lock.
3778 */
3779 DECLGCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
3780
3781 /**
3782 * Releases the PDM lock.
3783 *
3784 * @param pDevIns The PCI device instance.
3785 */
3786 DECLGCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
3787#endif
3788 /** Just a safety precaution. */
3789 uint32_t u32TheEnd;
3790} PDMPCIHLPGC;
3791/** Pointer to PCI helpers. */
3792typedef GCPTRTYPE(PDMPCIHLPGC *) PPDMPCIHLPGC;
3793/** Pointer to const PCI helpers. */
3794typedef GCPTRTYPE(const PDMPCIHLPGC *) PCPDMPCIHLPGC;
3795
3796/** Current PDMPCIHLPR3 version number. */
3797#define PDM_PCIHLPGC_VERSION 0xe1010000
3798
3799
3800/**
3801 * PCI Bus R0 helpers.
3802 */
3803typedef struct PDMPCIHLPR0
3804{
3805 /** Structure version. PDM_PCIHLPR0_VERSION defines the current version. */
3806 uint32_t u32Version;
3807
3808 /**
3809 * Set an ISA IRQ.
3810 *
3811 * @param pDevIns PCI device instance.
3812 * @param iIrq IRQ number to set.
3813 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3814 * @thread EMT only.
3815 */
3816 DECLR0CALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3817
3818 /**
3819 * Set an I/O-APIC IRQ.
3820 *
3821 * @param pDevIns PCI device instance.
3822 * @param iIrq IRQ number to set.
3823 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3824 * @thread EMT only.
3825 */
3826 DECLR0CALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3827
3828#ifdef VBOX_WITH_PDM_LOCK
3829 /**
3830 * Acquires the PDM lock.
3831 *
3832 * @returns VINF_SUCCESS on success.
3833 * @returns rc if we failed to acquire the lock.
3834 * @param pDevIns The PCI device instance.
3835 * @param rc What to return if we fail to acquire the lock.
3836 */
3837 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
3838
3839 /**
3840 * Releases the PDM lock.
3841 *
3842 * @param pDevIns The PCI device instance.
3843 */
3844 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
3845#endif
3846
3847 /** Just a safety precaution. */
3848 uint32_t u32TheEnd;
3849} PDMPCIHLPR0;
3850/** Pointer to PCI helpers. */
3851typedef R0PTRTYPE(PDMPCIHLPR0 *) PPDMPCIHLPR0;
3852/** Pointer to const PCI helpers. */
3853typedef R0PTRTYPE(const PDMPCIHLPR0 *) PCPDMPCIHLPR0;
3854
3855/** Current PDMPCIHLPR0 version number. */
3856#define PDM_PCIHLPR0_VERSION 0xe1010000
3857
3858/**
3859 * PCI device helpers.
3860 */
3861typedef struct PDMPCIHLPR3
3862{
3863 /** Structure version. PDM_PCIHLPR3_VERSION defines the current version. */
3864 uint32_t u32Version;
3865
3866 /**
3867 * Set an ISA IRQ.
3868 *
3869 * @param pDevIns The PCI device instance.
3870 * @param iIrq IRQ number to set.
3871 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3872 * @thread EMT only.
3873 */
3874 DECLR3CALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3875
3876 /**
3877 * Set an I/O-APIC IRQ.
3878 *
3879 * @param pDevIns The PCI device instance.
3880 * @param iIrq IRQ number to set.
3881 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3882 * @thread EMT only.
3883 */
3884 DECLR3CALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3885
3886#ifdef VBOX_WITH_PDM_LOCK
3887 /**
3888 * Acquires the PDM lock.
3889 *
3890 * @returns VINF_SUCCESS on success.
3891 * @returns Fatal error on failure.
3892 * @param pDevIns The PCI device instance.
3893 * @param rc Dummy for making the interface identical to the GC and R0 versions.
3894 */
3895 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
3896
3897 /**
3898 * Releases the PDM lock.
3899 *
3900 * @param pDevIns The PCI device instance.
3901 */
3902 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
3903#endif
3904
3905 /**
3906 * Gets the address of the GC PCI Bus helpers.
3907 *
3908 * This should be called at both construction and relocation time
3909 * to obtain the correct address of the GC helpers.
3910 *
3911 * @returns GC pointer to the PCI Bus helpers.
3912 * @param pDevIns Device instance of the PCI Bus.
3913 * @thread EMT only.
3914 */
3915 DECLR3CALLBACKMEMBER(PCPDMPCIHLPGC, pfnGetGCHelpers,(PPDMDEVINS pDevIns));
3916
3917 /**
3918 * Gets the address of the R0 PCI Bus helpers.
3919 *
3920 * This should be called at both construction and relocation time
3921 * to obtain the correct address of the GC helpers.
3922 *
3923 * @returns R0 pointer to the PCI Bus helpers.
3924 * @param pDevIns Device instance of the PCI Bus.
3925 * @thread EMT only.
3926 */
3927 DECLR3CALLBACKMEMBER(PCPDMPCIHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
3928
3929 /** Just a safety precaution. */
3930 uint32_t u32TheEnd;
3931} PDMPCIHLPR3;
3932/** Pointer to PCI helpers. */
3933typedef HCPTRTYPE(PDMPCIHLPR3 *) PPDMPCIHLPR3;
3934/** Pointer to const PCI helpers. */
3935typedef HCPTRTYPE(const PDMPCIHLPR3 *) PCPDMPCIHLPR3;
3936
3937/** Current PDMPCIHLPR3 version number. */
3938#define PDM_PCIHLPR3_VERSION 0xf1010000
3939
3940
3941/**
3942 * Programmable Interrupt Controller registration structure.
3943 */
3944typedef struct PDMPICREG
3945{
3946 /** Structure version number. PDM_PICREG_VERSION defines the current version. */
3947 uint32_t u32Version;
3948
3949 /**
3950 * Set the an IRQ.
3951 *
3952 * @param pDevIns Device instance of the PIC.
3953 * @param iIrq IRQ number to set.
3954 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3955 */
3956 DECLR3CALLBACKMEMBER(void, pfnSetIrqHC,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3957
3958 /**
3959 * Get a pending interrupt.
3960 *
3961 * @returns Pending interrupt number.
3962 * @param pDevIns Device instance of the PIC.
3963 */
3964 DECLR3CALLBACKMEMBER(int, pfnGetInterruptHC,(PPDMDEVINS pDevIns));
3965
3966 /** The name of the GC SetIrq entry point. */
3967 const char *pszSetIrqGC;
3968 /** The name of the GC GetInterrupt entry point. */
3969 const char *pszGetInterruptGC;
3970
3971 /** The name of the R0 SetIrq entry point. */
3972 const char *pszSetIrqR0;
3973 /** The name of the R0 GetInterrupt entry point. */
3974 const char *pszGetInterruptR0;
3975} PDMPICREG;
3976/** Pointer to a PIC registration structure. */
3977typedef PDMPICREG *PPDMPICREG;
3978
3979/** Current PDMPICREG version number. */
3980#define PDM_PICREG_VERSION 0xe0020000
3981
3982/**
3983 * PIC GC helpers.
3984 */
3985typedef struct PDMPICHLPGC
3986{
3987 /** Structure version. PDM_PICHLPGC_VERSION defines the current version. */
3988 uint32_t u32Version;
3989
3990 /**
3991 * Set the interrupt force action flag.
3992 *
3993 * @param pDevIns Device instance of the PIC.
3994 */
3995 DECLGCCALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
3996
3997 /**
3998 * Clear the interrupt force action flag.
3999 *
4000 * @param pDevIns Device instance of the PIC.
4001 */
4002 DECLGCCALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
4003
4004#ifdef VBOX_WITH_PDM_LOCK
4005 /**
4006 * Acquires the PDM lock.
4007 *
4008 * @returns VINF_SUCCESS on success.
4009 * @returns rc if we failed to acquire the lock.
4010 * @param pDevIns The PIC device instance.
4011 * @param rc What to return if we fail to acquire the lock.
4012 */
4013 DECLGCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4014
4015 /**
4016 * Releases the PDM lock.
4017 *
4018 * @param pDevIns The PIC device instance.
4019 */
4020 DECLGCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4021#endif
4022 /** Just a safety precaution. */
4023 uint32_t u32TheEnd;
4024} PDMPICHLPGC;
4025
4026/** Pointer to PIC GC helpers. */
4027typedef GCPTRTYPE(PDMPICHLPGC *) PPDMPICHLPGC;
4028/** Pointer to const PIC GC helpers. */
4029typedef GCPTRTYPE(const PDMPICHLPGC *) PCPDMPICHLPGC;
4030
4031/** Current PDMPICHLPGC version number. */
4032#define PDM_PICHLPGC_VERSION 0xfc010000
4033
4034
4035/**
4036 * PIC R0 helpers.
4037 */
4038typedef struct PDMPICHLPR0
4039{
4040 /** Structure version. PDM_PICHLPR0_VERSION defines the current version. */
4041 uint32_t u32Version;
4042
4043 /**
4044 * Set the interrupt force action flag.
4045 *
4046 * @param pDevIns Device instance of the PIC.
4047 */
4048 DECLR0CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
4049
4050 /**
4051 * Clear the interrupt force action flag.
4052 *
4053 * @param pDevIns Device instance of the PIC.
4054 */
4055 DECLR0CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
4056
4057#ifdef VBOX_WITH_PDM_LOCK
4058 /**
4059 * Acquires the PDM lock.
4060 *
4061 * @returns VINF_SUCCESS on success.
4062 * @returns rc if we failed to acquire the lock.
4063 * @param pDevIns The PIC device instance.
4064 * @param rc What to return if we fail to acquire the lock.
4065 */
4066 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4067
4068 /**
4069 * Releases the PDM lock.
4070 *
4071 * @param pDevIns The PCI device instance.
4072 */
4073 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4074#endif
4075
4076 /** Just a safety precaution. */
4077 uint32_t u32TheEnd;
4078} PDMPICHLPR0;
4079
4080/** Pointer to PIC R0 helpers. */
4081typedef R0PTRTYPE(PDMPICHLPR0 *) PPDMPICHLPR0;
4082/** Pointer to const PIC R0 helpers. */
4083typedef R0PTRTYPE(const PDMPICHLPR0 *) PCPDMPICHLPR0;
4084
4085/** Current PDMPICHLPR0 version number. */
4086#define PDM_PICHLPR0_VERSION 0xfc010000
4087
4088/**
4089 * PIC HC helpers.
4090 */
4091typedef struct PDMPICHLPR3
4092{
4093 /** Structure version. PDM_PICHLP_VERSION defines the current version. */
4094 uint32_t u32Version;
4095
4096 /**
4097 * Set the interrupt force action flag.
4098 *
4099 * @param pDevIns Device instance of the PIC.
4100 */
4101 DECLR3CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
4102
4103 /**
4104 * Clear the interrupt force action flag.
4105 *
4106 * @param pDevIns Device instance of the PIC.
4107 */
4108 DECLR3CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
4109
4110#ifdef VBOX_WITH_PDM_LOCK
4111 /**
4112 * Acquires the PDM lock.
4113 *
4114 * @returns VINF_SUCCESS on success.
4115 * @returns Fatal error on failure.
4116 * @param pDevIns The PIC device instance.
4117 * @param rc Dummy for making the interface identical to the GC and R0 versions.
4118 */
4119 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4120
4121 /**
4122 * Releases the PDM lock.
4123 *
4124 * @param pDevIns The PIC device instance.
4125 */
4126 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4127#endif
4128
4129 /**
4130 * Gets the address of the GC PIC helpers.
4131 *
4132 * This should be called at both construction and relocation time
4133 * to obtain the correct address of the GC helpers.
4134 *
4135 * @returns GC pointer to the PIC helpers.
4136 * @param pDevIns Device instance of the PIC.
4137 */
4138 DECLR3CALLBACKMEMBER(PCPDMPICHLPGC, pfnGetGCHelpers,(PPDMDEVINS pDevIns));
4139
4140 /**
4141 * Gets the address of the R0 PIC helpers.
4142 *
4143 * This should be called at both construction and relocation time
4144 * to obtain the correct address of the GC helpers.
4145 *
4146 * @returns R0 pointer to the PIC helpers.
4147 * @param pDevIns Device instance of the PIC.
4148 */
4149 DECLR3CALLBACKMEMBER(PCPDMPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
4150
4151 /** Just a safety precaution. */
4152 uint32_t u32TheEnd;
4153} PDMPICHLPR3;
4154
4155/** Pointer to PIC HC helpers. */
4156typedef HCPTRTYPE(PDMPICHLPR3 *) PPDMPICHLPR3;
4157/** Pointer to const PIC HC helpers. */
4158typedef HCPTRTYPE(const PDMPICHLPR3 *) PCPDMPICHLPR3;
4159
4160/** Current PDMPICHLPR3 version number. */
4161#define PDM_PICHLPR3_VERSION 0xf0010000
4162
4163
4164
4165/**
4166 * Advanced Programmable Interrupt Controller registration structure.
4167 */
4168typedef struct PDMAPICREG
4169{
4170 /** Structure version number. PDM_APICREG_VERSION defines the current version. */
4171 uint32_t u32Version;
4172
4173 /**
4174 * Get a pending interrupt.
4175 *
4176 * @returns Pending interrupt number.
4177 * @param pDevIns Device instance of the APIC.
4178 */
4179 DECLR3CALLBACKMEMBER(int, pfnGetInterruptHC,(PPDMDEVINS pDevIns));
4180
4181 /**
4182 * Set the APIC base.
4183 *
4184 * @param pDevIns Device instance of the APIC.
4185 * @param u64Base The new base.
4186 */
4187 DECLR3CALLBACKMEMBER(void, pfnSetBaseHC,(PPDMDEVINS pDevIns, uint64_t u64Base));
4188
4189 /**
4190 * Get the APIC base.
4191 *
4192 * @returns Current base.
4193 * @param pDevIns Device instance of the APIC.
4194 */
4195 DECLR3CALLBACKMEMBER(uint64_t, pfnGetBaseHC,(PPDMDEVINS pDevIns));
4196
4197 /**
4198 * Set the TPR (task priority register?).
4199 *
4200 * @param pDevIns Device instance of the APIC.
4201 * @param u8TPR The new TPR.
4202 */
4203 DECLR3CALLBACKMEMBER(void, pfnSetTPRHC,(PPDMDEVINS pDevIns, uint8_t u8TPR));
4204
4205 /**
4206 * Get the TPR (task priority register?).
4207 *
4208 * @returns The current TPR.
4209 * @param pDevIns Device instance of the APIC.
4210 */
4211 DECLR3CALLBACKMEMBER(uint8_t, pfnGetTPRHC,(PPDMDEVINS pDevIns));
4212
4213 /**
4214 * Private interface between the IOAPIC and APIC.
4215 *
4216 * This is a low-level, APIC/IOAPIC implementation specific interface
4217 * which is registered with PDM only because it makes life so much
4218 * simpler right now (GC bits). This is a bad bad hack! The correct
4219 * way of doing this would involve some way of querying GC interfaces
4220 * and relocating them. Perhaps doing some kind of device init in GC...
4221 *
4222 * @returns The current TPR.
4223 * @param pDevIns Device instance of the APIC.
4224 * @param u8Dest See APIC implementation.
4225 * @param u8DestMode See APIC implementation.
4226 * @param u8DeliveryMode See APIC implementation.
4227 * @param iVector See APIC implementation.
4228 * @param u8Polarity See APIC implementation.
4229 * @param u8TriggerMode See APIC implementation.
4230 */
4231 DECLR3CALLBACKMEMBER(void, pfnBusDeliverHC,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
4232 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
4233
4234 /** The name of the GC GetInterrupt entry point. */
4235 const char *pszGetInterruptGC;
4236 /** The name of the GC SetBase entry point. */
4237 const char *pszSetBaseGC;
4238 /** The name of the GC GetBase entry point. */
4239 const char *pszGetBaseGC;
4240 /** The name of the GC SetTPR entry point. */
4241 const char *pszSetTPRGC;
4242 /** The name of the GC GetTPR entry point. */
4243 const char *pszGetTPRGC;
4244 /** The name of the GC BusDeliver entry point. */
4245 const char *pszBusDeliverGC;
4246
4247 /** The name of the R0 GetInterrupt entry point. */
4248 const char *pszGetInterruptR0;
4249 /** The name of the R0 SetBase entry point. */
4250 const char *pszSetBaseR0;
4251 /** The name of the R0 GetBase entry point. */
4252 const char *pszGetBaseR0;
4253 /** The name of the R0 SetTPR entry point. */
4254 const char *pszSetTPRR0;
4255 /** The name of the R0 GetTPR entry point. */
4256 const char *pszGetTPRR0;
4257 /** The name of the R0 BusDeliver entry point. */
4258 const char *pszBusDeliverR0;
4259
4260} PDMAPICREG;
4261/** Pointer to an APIC registration structure. */
4262typedef PDMAPICREG *PPDMAPICREG;
4263
4264/** Current PDMAPICREG version number. */
4265#define PDM_APICREG_VERSION 0x70010000
4266
4267
4268/**
4269 * APIC GC helpers.
4270 */
4271typedef struct PDMAPICHLPGC
4272{
4273 /** Structure version. PDM_APICHLPGC_VERSION defines the current version. */
4274 uint32_t u32Version;
4275
4276 /**
4277 * Set the interrupt force action flag.
4278 *
4279 * @param pDevIns Device instance of the APIC.
4280 */
4281 DECLGCCALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
4282
4283 /**
4284 * Clear the interrupt force action flag.
4285 *
4286 * @param pDevIns Device instance of the APIC.
4287 */
4288 DECLGCCALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
4289
4290 /**
4291 * Sets or clears the APIC bit in the CPUID feature masks.
4292 *
4293 * @param pDevIns Device instance of the APIC.
4294 * @param fEnabled If true the bit is set, else cleared.
4295 */
4296 DECLGCCALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, bool fEnabled));
4297
4298#ifdef VBOX_WITH_PDM_LOCK
4299 /**
4300 * Acquires the PDM lock.
4301 *
4302 * @returns VINF_SUCCESS on success.
4303 * @returns rc if we failed to acquire the lock.
4304 * @param pDevIns The APIC device instance.
4305 * @param rc What to return if we fail to acquire the lock.
4306 */
4307 DECLGCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4308
4309 /**
4310 * Releases the PDM lock.
4311 *
4312 * @param pDevIns The APIC device instance.
4313 */
4314 DECLGCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4315#endif
4316 /** Just a safety precaution. */
4317 uint32_t u32TheEnd;
4318} PDMAPICHLPGC;
4319/** Pointer to APIC GC helpers. */
4320typedef GCPTRTYPE(PDMAPICHLPGC *) PPDMAPICHLPGC;
4321/** Pointer to const APIC helpers. */
4322typedef GCPTRTYPE(const PDMAPICHLPGC *) PCPDMAPICHLPGC;
4323
4324/** Current PDMAPICHLPGC version number. */
4325#define PDM_APICHLPGC_VERSION 0x60010000
4326
4327
4328/**
4329 * APIC R0 helpers.
4330 */
4331typedef struct PDMAPICHLPR0
4332{
4333 /** Structure version. PDM_APICHLPR0_VERSION defines the current version. */
4334 uint32_t u32Version;
4335
4336 /**
4337 * Set the interrupt force action flag.
4338 *
4339 * @param pDevIns Device instance of the APIC.
4340 */
4341 DECLR0CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
4342
4343 /**
4344 * Clear the interrupt force action flag.
4345 *
4346 * @param pDevIns Device instance of the APIC.
4347 */
4348 DECLR0CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
4349
4350 /**
4351 * Sets or clears the APIC bit in the CPUID feature masks.
4352 *
4353 * @param pDevIns Device instance of the APIC.
4354 * @param fEnabled If true the bit is set, else cleared.
4355 */
4356 DECLR0CALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, bool fEnabled));
4357
4358#ifdef VBOX_WITH_PDM_LOCK
4359 /**
4360 * Acquires the PDM lock.
4361 *
4362 * @returns VINF_SUCCESS on success.
4363 * @returns rc if we failed to acquire the lock.
4364 * @param pDevIns The APIC device instance.
4365 * @param rc What to return if we fail to acquire the lock.
4366 */
4367 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4368
4369 /**
4370 * Releases the PDM lock.
4371 *
4372 * @param pDevIns The APIC device instance.
4373 */
4374 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4375#endif
4376
4377 /** Just a safety precaution. */
4378 uint32_t u32TheEnd;
4379} PDMAPICHLPR0;
4380/** Pointer to APIC GC helpers. */
4381typedef GCPTRTYPE(PDMAPICHLPR0 *) PPDMAPICHLPR0;
4382/** Pointer to const APIC helpers. */
4383typedef R0PTRTYPE(const PDMAPICHLPR0 *) PCPDMAPICHLPR0;
4384
4385/** Current PDMAPICHLPR0 version number. */
4386#define PDM_APICHLPR0_VERSION 0x60010000
4387
4388/**
4389 * APIC HC helpers.
4390 */
4391typedef struct PDMAPICHLPR3
4392{
4393 /** Structure version. PDM_APICHLPR3_VERSION defines the current version. */
4394 uint32_t u32Version;
4395
4396 /**
4397 * Set the interrupt force action flag.
4398 *
4399 * @param pDevIns Device instance of the APIC.
4400 */
4401 DECLR3CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
4402
4403 /**
4404 * Clear the interrupt force action flag.
4405 *
4406 * @param pDevIns Device instance of the APIC.
4407 */
4408 DECLR3CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
4409
4410 /**
4411 * Sets or clears the APIC bit in the CPUID feature masks.
4412 *
4413 * @param pDevIns Device instance of the APIC.
4414 * @param fEnabled If true the bit is set, else cleared.
4415 */
4416 DECLR3CALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, bool fEnabled));
4417
4418#ifdef VBOX_WITH_PDM_LOCK
4419 /**
4420 * Acquires the PDM lock.
4421 *
4422 * @returns VINF_SUCCESS on success.
4423 * @returns Fatal error on failure.
4424 * @param pDevIns The APIC device instance.
4425 * @param rc Dummy for making the interface identical to the GC and R0 versions.
4426 */
4427 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4428
4429 /**
4430 * Releases the PDM lock.
4431 *
4432 * @param pDevIns The APIC device instance.
4433 */
4434 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4435#endif
4436
4437 /**
4438 * Gets the address of the GC APIC helpers.
4439 *
4440 * This should be called at both construction and relocation time
4441 * to obtain the correct address of the GC helpers.
4442 *
4443 * @returns GC pointer to the APIC helpers.
4444 * @param pDevIns Device instance of the APIC.
4445 */
4446 DECLR3CALLBACKMEMBER(PCPDMAPICHLPGC, pfnGetGCHelpers,(PPDMDEVINS pDevIns));
4447
4448 /**
4449 * Gets the address of the R0 APIC helpers.
4450 *
4451 * This should be called at both construction and relocation time
4452 * to obtain the correct address of the R0 helpers.
4453 *
4454 * @returns R0 pointer to the APIC helpers.
4455 * @param pDevIns Device instance of the APIC.
4456 */
4457 DECLR3CALLBACKMEMBER(PCPDMAPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
4458
4459 /** Just a safety precaution. */
4460 uint32_t u32TheEnd;
4461} PDMAPICHLPR3;
4462/** Pointer to APIC helpers. */
4463typedef HCPTRTYPE(PDMAPICHLPR3 *) PPDMAPICHLPR3;
4464/** Pointer to const APIC helpers. */
4465typedef HCPTRTYPE(const PDMAPICHLPR3 *) PCPDMAPICHLPR3;
4466
4467/** Current PDMAPICHLP version number. */
4468#define PDM_APICHLPR3_VERSION 0xfd010000
4469
4470
4471/**
4472 * I/O APIC registration structure.
4473 */
4474typedef struct PDMIOAPICREG
4475{
4476 /** Struct version+magic number (PDM_IOAPICREG_VERSION). */
4477 uint32_t u32Version;
4478
4479 /**
4480 * Set the an IRQ.
4481 *
4482 * @param pDevIns Device instance of the I/O APIC.
4483 * @param iIrq IRQ number to set.
4484 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
4485 */
4486 DECLR3CALLBACKMEMBER(void, pfnSetIrqHC,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
4487
4488 /** The name of the GC SetIrq entry point. */
4489 const char *pszSetIrqGC;
4490
4491 /** The name of the R0 SetIrq entry point. */
4492 const char *pszSetIrqR0;
4493} PDMIOAPICREG;
4494/** Pointer to an APIC registration structure. */
4495typedef PDMIOAPICREG *PPDMIOAPICREG;
4496
4497/** Current PDMAPICREG version number. */
4498#define PDM_IOAPICREG_VERSION 0x50010000
4499
4500
4501/**
4502 * IOAPIC GC helpers.
4503 */
4504typedef struct PDMIOAPICHLPGC
4505{
4506 /** Structure version. PDM_IOAPICHLPGC_VERSION defines the current version. */
4507 uint32_t u32Version;
4508
4509 /**
4510 * Private interface between the IOAPIC and APIC.
4511 *
4512 * See comments about this hack on PDMAPICREG::pfnBusDeliverHC.
4513 *
4514 * @returns The current TPR.
4515 * @param pDevIns Device instance of the IOAPIC.
4516 * @param u8Dest See APIC implementation.
4517 * @param u8DestMode See APIC implementation.
4518 * @param u8DeliveryMode See APIC implementation.
4519 * @param iVector See APIC implementation.
4520 * @param u8Polarity See APIC implementation.
4521 * @param u8TriggerMode See APIC implementation.
4522 */
4523 DECLGCCALLBACKMEMBER(void, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
4524 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
4525
4526#ifdef VBOX_WITH_PDM_LOCK
4527 /**
4528 * Acquires the PDM lock.
4529 *
4530 * @returns VINF_SUCCESS on success.
4531 * @returns rc if we failed to acquire the lock.
4532 * @param pDevIns The IOAPIC device instance.
4533 * @param rc What to return if we fail to acquire the lock.
4534 */
4535 DECLGCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4536
4537 /**
4538 * Releases the PDM lock.
4539 *
4540 * @param pDevIns The IOAPIC device instance.
4541 */
4542 DECLGCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4543#endif
4544
4545 /** Just a safety precaution. */
4546 uint32_t u32TheEnd;
4547} PDMIOAPICHLPGC;
4548/** Pointer to IOAPIC GC helpers. */
4549typedef GCPTRTYPE(PDMAPICHLPGC *)PPDMIOAPICHLPGC;
4550/** Pointer to const IOAPIC helpers. */
4551typedef GCPTRTYPE(const PDMIOAPICHLPGC *) PCPDMIOAPICHLPGC;
4552
4553/** Current PDMIOAPICHLPGC version number. */
4554#define PDM_IOAPICHLPGC_VERSION 0xfe010000
4555
4556
4557/**
4558 * IOAPIC R0 helpers.
4559 */
4560typedef struct PDMIOAPICHLPR0
4561{
4562 /** Structure version. PDM_IOAPICHLPR0_VERSION defines the current version. */
4563 uint32_t u32Version;
4564
4565 /**
4566 * Private interface between the IOAPIC and APIC.
4567 *
4568 * See comments about this hack on PDMAPICREG::pfnBusDeliverHC.
4569 *
4570 * @returns The current TPR.
4571 * @param pDevIns Device instance of the IOAPIC.
4572 * @param u8Dest See APIC implementation.
4573 * @param u8DestMode See APIC implementation.
4574 * @param u8DeliveryMode See APIC implementation.
4575 * @param iVector See APIC implementation.
4576 * @param u8Polarity See APIC implementation.
4577 * @param u8TriggerMode See APIC implementation.
4578 */
4579 DECLR0CALLBACKMEMBER(void, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
4580 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
4581
4582#ifdef VBOX_WITH_PDM_LOCK
4583 /**
4584 * Acquires the PDM lock.
4585 *
4586 * @returns VINF_SUCCESS on success.
4587 * @returns rc if we failed to acquire the lock.
4588 * @param pDevIns The IOAPIC device instance.
4589 * @param rc What to return if we fail to acquire the lock.
4590 */
4591 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4592
4593 /**
4594 * Releases the PDM lock.
4595 *
4596 * @param pDevIns The IOAPIC device instance.
4597 */
4598 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4599#endif
4600
4601 /** Just a safety precaution. */
4602 uint32_t u32TheEnd;
4603} PDMIOAPICHLPR0;
4604/** Pointer to IOAPIC R0 helpers. */
4605typedef R0PTRTYPE(PDMAPICHLPGC *) PPDMIOAPICHLPR0;
4606/** Pointer to const IOAPIC helpers. */
4607typedef R0PTRTYPE(const PDMIOAPICHLPR0 *) PCPDMIOAPICHLPR0;
4608
4609/** Current PDMIOAPICHLPR0 version number. */
4610#define PDM_IOAPICHLPR0_VERSION 0xfe010000
4611
4612/**
4613 * IOAPIC HC helpers.
4614 */
4615typedef struct PDMIOAPICHLPR3
4616{
4617 /** Structure version. PDM_IOAPICHLPR3_VERSION defines the current version. */
4618 uint32_t u32Version;
4619
4620 /**
4621 * Private interface between the IOAPIC and APIC.
4622 *
4623 * See comments about this hack on PDMAPICREG::pfnBusDeliverHC.
4624 *
4625 * @returns The current TPR.
4626 * @param pDevIns Device instance of the IOAPIC.
4627 * @param u8Dest See APIC implementation.
4628 * @param u8DestMode See APIC implementation.
4629 * @param u8DeliveryMode See APIC implementation.
4630 * @param iVector See APIC implementation.
4631 * @param u8Polarity See APIC implementation.
4632 * @param u8TriggerMode See APIC implementation.
4633 */
4634 DECLR3CALLBACKMEMBER(void, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
4635 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
4636
4637#ifdef VBOX_WITH_PDM_LOCK
4638 /**
4639 * Acquires the PDM lock.
4640 *
4641 * @returns VINF_SUCCESS on success.
4642 * @returns Fatal error on failure.
4643 * @param pDevIns The IOAPIC device instance.
4644 * @param rc Dummy for making the interface identical to the GC and R0 versions.
4645 */
4646 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
4647
4648 /**
4649 * Releases the PDM lock.
4650 *
4651 * @param pDevIns The IOAPIC device instance.
4652 */
4653 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
4654#endif
4655
4656 /**
4657 * Gets the address of the GC IOAPIC helpers.
4658 *
4659 * This should be called at both construction and relocation time
4660 * to obtain the correct address of the GC helpers.
4661 *
4662 * @returns GC pointer to the IOAPIC helpers.
4663 * @param pDevIns Device instance of the IOAPIC.
4664 */
4665 DECLR3CALLBACKMEMBER(PCPDMIOAPICHLPGC, pfnGetGCHelpers,(PPDMDEVINS pDevIns));
4666
4667 /**
4668 * Gets the address of the R0 IOAPIC helpers.
4669 *
4670 * This should be called at both construction and relocation time
4671 * to obtain the correct address of the R0 helpers.
4672 *
4673 * @returns R0 pointer to the IOAPIC helpers.
4674 * @param pDevIns Device instance of the IOAPIC.
4675 */
4676 DECLR3CALLBACKMEMBER(PCPDMIOAPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
4677
4678 /** Just a safety precaution. */
4679 uint32_t u32TheEnd;
4680} PDMIOAPICHLPR3;
4681/** Pointer to IOAPIC HC helpers. */
4682typedef HCPTRTYPE(PDMIOAPICHLPR3 *) PPDMIOAPICHLPR3;
4683/** Pointer to const IOAPIC helpers. */
4684typedef HCPTRTYPE(const PDMIOAPICHLPR3 *) PCPDMIOAPICHLPR3;
4685
4686/** Current PDMIOAPICHLPR3 version number. */
4687#define PDM_IOAPICHLPR3_VERSION 0xff010000
4688
4689
4690
4691#ifdef IN_RING3
4692
4693/**
4694 * DMA Transfer Handler.
4695 *
4696 * @returns Number of bytes transferred.
4697 * @param pDevIns Device instance of the DMA.
4698 * @param pvUser User pointer.
4699 * @param uChannel Channel number.
4700 * @param off DMA position.
4701 * @param cb Block size.
4702 */
4703typedef DECLCALLBACK(uint32_t) FNDMATRANSFERHANDLER(PPDMDEVINS pDevIns, void *pvUser, unsigned uChannel, uint32_t off, uint32_t cb);
4704/** Pointer to a FNDMATRANSFERHANDLER(). */
4705typedef FNDMATRANSFERHANDLER *PFNDMATRANSFERHANDLER;
4706
4707/**
4708 * DMA Controller registration structure.
4709 */
4710typedef struct PDMDMAREG
4711{
4712 /** Structure version number. PDM_DMACREG_VERSION defines the current version. */
4713 uint32_t u32Version;
4714
4715 /**
4716 * Execute pending transfers.
4717 *
4718 * @returns A more work indiciator. I.e. 'true' if there is more to be done, and 'false' if all is done.
4719 * @param pDevIns Device instance of the DMAC.
4720 */
4721 DECLR3CALLBACKMEMBER(bool, pfnRun,(PPDMDEVINS pDevIns));
4722
4723 /**
4724 * Register transfer function for DMA channel.
4725 *
4726 * @param pDevIns Device instance of the DMAC.
4727 * @param uChannel Channel number.
4728 * @param pfnTransferHandler Device specific transfer function.
4729 * @param pvUSer User pointer to be passed to the callback.
4730 */
4731 DECLR3CALLBACKMEMBER(void, pfnRegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
4732
4733 /**
4734 * Read memory
4735 *
4736 * @returns Number of bytes read.
4737 * @param pDevIns Device instance of the DMAC.
4738 * @param pvBuffer Pointer to target buffer.
4739 * @param off DMA position.
4740 * @param cbBlock Block size.
4741 */
4742 DECLR3CALLBACKMEMBER(uint32_t, pfnReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock));
4743
4744 /**
4745 * Write memory
4746 *
4747 * @returns Number of bytes written.
4748 * @param pDevIns Device instance of the DMAC.
4749 * @param pvBuffer Memory to write.
4750 * @param off DMA position.
4751 * @param cbBlock Block size.
4752 */
4753 DECLR3CALLBACKMEMBER(uint32_t, pfnWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock));
4754
4755 /**
4756 * Set the DREQ line.
4757 *
4758 * @param pDevIns Device instance of the DMAC.
4759 * @param uChannel Channel number.
4760 * @param uLevel Level of the line.
4761 */
4762 DECLR3CALLBACKMEMBER(void, pfnSetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
4763
4764 /**
4765 * Get channel mode
4766 *
4767 * @returns Channel mode.
4768 * @param pDevIns Device instance of the DMAC.
4769 * @param uChannel Channel number.
4770 */
4771 DECLR3CALLBACKMEMBER(uint8_t, pfnGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
4772
4773} PDMDMACREG;
4774/** Pointer to a DMAC registration structure. */
4775typedef PDMDMACREG *PPDMDMACREG;
4776
4777/** Current PDMDMACREG version number. */
4778#define PDM_DMACREG_VERSION 0xf5010000
4779
4780
4781/**
4782 * DMA Controller device helpers.
4783 */
4784typedef struct PDMDMACHLP
4785{
4786 /** Structure version. PDM_DMACHLP_VERSION defines the current version. */
4787 uint32_t u32Version;
4788
4789 /* to-be-defined */
4790
4791} PDMDMACHLP;
4792/** Pointer to DMAC helpers. */
4793typedef PDMDMACHLP *PPDMDMACHLP;
4794/** Pointer to const DMAC helpers. */
4795typedef const PDMDMACHLP *PCPDMDMACHLP;
4796
4797/** Current PDMDMACHLP version number. */
4798#define PDM_DMACHLP_VERSION 0xf6010000
4799
4800#endif /* IN_RING3 */
4801
4802
4803
4804/**
4805 * RTC registration structure.
4806 */
4807typedef struct PDMRTCREG
4808{
4809 /** Structure version number. PDM_RTCREG_VERSION defines the current version. */
4810 uint32_t u32Version;
4811 uint32_t u32Alignment; /**< structure size alignment. */
4812
4813 /**
4814 * Write to a CMOS register and update the checksum if necessary.
4815 *
4816 * @returns VBox status code.
4817 * @param pDevIns Device instance of the RTC.
4818 * @param iReg The CMOS register index.
4819 * @param u8Value The CMOS register value.
4820 */
4821 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
4822
4823 /**
4824 * Read a CMOS register.
4825 *
4826 * @returns VBox status code.
4827 * @param pDevIns Device instance of the RTC.
4828 * @param iReg The CMOS register index.
4829 * @param pu8Value Where to store the CMOS register value.
4830 */
4831 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
4832
4833} PDMRTCREG;
4834/** Pointer to a RTC registration structure. */
4835typedef PDMRTCREG *PPDMRTCREG;
4836/** Pointer to a const RTC registration structure. */
4837typedef const PDMRTCREG *PCPDMRTCREG;
4838
4839/** Current PDMRTCREG version number. */
4840#define PDM_RTCREG_VERSION 0xfa010000
4841
4842
4843/**
4844 * RTC device helpers.
4845 */
4846typedef struct PDMRTCHLP
4847{
4848 /** Structure version. PDM_RTCHLP_VERSION defines the current version. */
4849 uint32_t u32Version;
4850
4851 /* to-be-defined */
4852
4853} PDMRTCHLP;
4854/** Pointer to RTC helpers. */
4855typedef PDMRTCHLP *PPDMRTCHLP;
4856/** Pointer to const RTC helpers. */
4857typedef const PDMRTCHLP *PCPDMRTCHLP;
4858
4859/** Current PDMRTCHLP version number. */
4860#define PDM_RTCHLP_VERSION 0xf6010000
4861
4862
4863
4864#ifdef IN_RING3
4865
4866/**
4867 * PDM Device API.
4868 */
4869typedef struct PDMDEVHLP
4870{
4871 /** Structure version. PDM_DEVHLP_VERSION defines the current version. */
4872 uint32_t u32Version;
4873
4874 /**
4875 * Register a number of I/O ports with a device.
4876 *
4877 * These callbacks are of course for the host context (HC).
4878 * Register HC handlers before guest context (GC) handlers! There must be a
4879 * HC handler for every GC handler!
4880 *
4881 * @returns VBox status.
4882 * @param pDevIns The device instance to register the ports with.
4883 * @param Port First port number in the range.
4884 * @param cPorts Number of ports to register.
4885 * @param pvUser User argument.
4886 * @param pfnOut Pointer to function which is gonna handle OUT operations.
4887 * @param pfnIn Pointer to function which is gonna handle IN operations.
4888 * @param pfnOutStr Pointer to function which is gonna handle string OUT operations.
4889 * @param pfnInStr Pointer to function which is gonna handle string IN operations.
4890 * @param pszDesc Pointer to description string. This must not be freed.
4891 */
4892 DECLR3CALLBACKMEMBER(int, pfnIOPortRegister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTHCPTR pvUser,
4893 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
4894 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc));
4895
4896 /**
4897 * Register a number of I/O ports with a device for GC.
4898 *
4899 * These callbacks are for the host context (GC).
4900 * Register host context (HC) handlers before guest context handlers! There must be a
4901 * HC handler for every GC handler!
4902 *
4903 * @returns VBox status.
4904 * @param pDevIns The device instance to register the ports with and which GC module
4905 * to resolve the names against.
4906 * @param Port First port number in the range.
4907 * @param cPorts Number of ports to register.
4908 * @param pvUser User argument.
4909 * @param pszOut Name of the GC function which is gonna handle OUT operations.
4910 * @param pszIn Name of the GC function which is gonna handle IN operations.
4911 * @param pszOutStr Name of the GC function which is gonna handle string OUT operations.
4912 * @param pszInStr Name of the GC function which is gonna handle string IN operations.
4913 * @param pszDesc Pointer to description string. This must not be freed.
4914 */
4915 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterGC,(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTGCPTR pvUser,
4916 const char *pszOut, const char *pszIn,
4917 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
4918
4919 /**
4920 * Register a number of I/O ports with a device.
4921 *
4922 * These callbacks are of course for the ring-0 host context (R0).
4923 * Register R3 (HC) handlers before R0 (R0) handlers! There must be a R3 (HC) handler for every R0 handler!
4924 *
4925 * @returns VBox status.
4926 * @param pDevIns The device instance to register the ports with.
4927 * @param Port First port number in the range.
4928 * @param cPorts Number of ports to register.
4929 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
4930 * @param pszOut Name of the R0 function which is gonna handle OUT operations.
4931 * @param pszIn Name of the R0 function which is gonna handle IN operations.
4932 * @param pszOutStr Name of the R0 function which is gonna handle string OUT operations.
4933 * @param pszInStr Name of the R0 function which is gonna handle string IN operations.
4934 * @param pszDesc Pointer to description string. This must not be freed.
4935 */
4936 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterR0,(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTR0PTR pvUser,
4937 const char *pszOut, const char *pszIn,
4938 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
4939
4940 /**
4941 * Deregister I/O ports.
4942 *
4943 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
4944 *
4945 * @returns VBox status.
4946 * @param pDevIns The device instance owning the ports.
4947 * @param Port First port number in the range.
4948 * @param cPorts Number of ports to deregister.
4949 */
4950 DECLR3CALLBACKMEMBER(int, pfnIOPortDeregister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts));
4951
4952
4953 /**
4954 * Register a Memory Mapped I/O (MMIO) region.
4955 *
4956 * These callbacks are of course for the host context (HC).
4957 * Register HC handlers before guest context (GC) handlers! There must be a
4958 * HC handler for every GC handler!
4959 *
4960 * @returns VBox status.
4961 * @param pDevIns The device instance to register the MMIO with.
4962 * @param GCPhysStart First physical address in the range.
4963 * @param cbRange The size of the range (in bytes).
4964 * @param pvUser User argument.
4965 * @param pfnWrite Pointer to function which is gonna handle Write operations.
4966 * @param pfnRead Pointer to function which is gonna handle Read operations.
4967 * @param pfnFill Pointer to function which is gonna handle Fill/memset operations. (optional)
4968 * @param pszDesc Pointer to description string. This must not be freed.
4969 */
4970 DECLR3CALLBACKMEMBER(int, pfnMMIORegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
4971 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
4972 const char *pszDesc));
4973
4974 /**
4975 * Register a Memory Mapped I/O (MMIO) region for GC.
4976 *
4977 * These callbacks are for the guest context (GC).
4978 * Register host context (HC) handlers before guest context handlers! There must be a
4979 * HC handler for every GC handler!
4980 *
4981 * @returns VBox status.
4982 * @param pDevIns The device instance to register the MMIO with.
4983 * @param GCPhysStart First physical address in the range.
4984 * @param cbRange The size of the range (in bytes).
4985 * @param pvUser User argument.
4986 * @param pszWrite Name of the GC function which is gonna handle Write operations.
4987 * @param pszRead Name of the GC function which is gonna handle Read operations.
4988 * @param pszFill Name of the GC function which is gonna handle Fill/memset operations. (optional)
4989 * @param pszDesc Pointer to description string. This must not be freed.
4990 */
4991 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterGC,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
4992 const char *pszWrite, const char *pszRead, const char *pszFill,
4993 const char *pszDesc));
4994
4995 /**
4996 * Register a Memory Mapped I/O (MMIO) region for R0.
4997 *
4998 * These callbacks are for the ring-0 host context (R0).
4999 * Register R3 (HC) handlers before R0 handlers! There must be a R3 handler for every R0 handler!
5000 *
5001 * @returns VBox status.
5002 * @param pDevIns The device instance to register the MMIO with.
5003 * @param GCPhysStart First physical address in the range.
5004 * @param cbRange The size of the range (in bytes).
5005 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
5006 * @param pszWrite Name of the GC function which is gonna handle Write operations.
5007 * @param pszRead Name of the GC function which is gonna handle Read operations.
5008 * @param pszFill Name of the GC function which is gonna handle Fill/memset operations. (optional)
5009 * @param pszDesc Pointer to description string. This must not be freed.
5010 */
5011 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterR0,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTR0PTR pvUser,
5012 const char *pszWrite, const char *pszRead, const char *pszFill,
5013 const char *pszDesc));
5014
5015 /**
5016 * Deregister a Memory Mapped I/O (MMIO) region.
5017 *
5018 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
5019 *
5020 * @returns VBox status.
5021 * @param pDevIns The device instance owning the MMIO region(s).
5022 * @param GCPhysStart First physical address in the range.
5023 * @param cbRange The size of the range (in bytes).
5024 */
5025 DECLR3CALLBACKMEMBER(int, pfnMMIODeregister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange));
5026
5027 /**
5028 * Register a ROM (BIOS) region.
5029 *
5030 * It goes without saying that this is read-only memory. The memory region must be
5031 * in unassigned memory. I.e. from the top of the address space or on the PC in
5032 * the 0xa0000-0xfffff range.
5033 *
5034 * @returns VBox status.
5035 * @param pDevIns The device instance owning the ROM region.
5036 * @param GCPhysStart First physical address in the range.
5037 * Must be page aligned!
5038 * @param cbRange The size of the range (in bytes).
5039 * Must be page aligned!
5040 * @param pvBinary Pointer to the binary data backing the ROM image.
5041 * This must be cbRange bytes big.
5042 * It will be copied and doesn't have to stick around.
5043 * @param pszDesc Pointer to description string. This must not be freed.
5044 * @remark There is no way to remove the rom, automatically on device cleanup or
5045 * manually from the device yet. At present I doubt we need such features...
5046 */
5047 DECLR3CALLBACKMEMBER(int, pfnROMRegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, const void *pvBinary, const char *pszDesc));
5048
5049 /**
5050 * Register a save state data unit.
5051 *
5052 * @returns VBox status.
5053 * @param pDevIns Device instance.
5054 * @param pszName Data unit name.
5055 * @param u32Instance The instance identifier of the data unit.
5056 * This must together with the name be unique.
5057 * @param u32Version Data layout version number.
5058 * @param cbGuess The approximate amount of data in the unit.
5059 * Only for progress indicators.
5060 * @param pfnSavePrep Prepare save callback, optional.
5061 * @param pfnSaveExec Execute save callback, optional.
5062 * @param pfnSaveDone Done save callback, optional.
5063 * @param pfnLoadPrep Prepare load callback, optional.
5064 * @param pfnLoadExec Execute load callback, optional.
5065 * @param pfnLoadDone Done load callback, optional.
5066 */
5067 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMDEVINS pDevIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
5068 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
5069 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone));
5070
5071 /**
5072 * Creates a timer.
5073 *
5074 * @returns VBox status.
5075 * @param pDevIns Device instance.
5076 * @param enmClock The clock to use on this timer.
5077 * @param pfnCallback Callback function.
5078 * @param pszDesc Pointer to description string which must stay around
5079 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
5080 * @param ppTimer Where to store the timer on success.
5081 */
5082 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer));
5083
5084 /**
5085 * Creates an external timer.
5086 *
5087 * @returns timer pointer
5088 * @param pDevIns Device instance.
5089 * @param enmClock The clock to use on this timer.
5090 * @param pfnCallback Callback function.
5091 * @param pvUser User pointer
5092 * @param pszDesc Pointer to description string which must stay around
5093 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
5094 */
5095 DECLR3CALLBACKMEMBER(PTMTIMERHC, pfnTMTimerCreateExternal,(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc));
5096
5097 /**
5098 * Registers the device with the default PCI bus.
5099 *
5100 * @returns VBox status code.
5101 * @param pDevIns Device instance.
5102 * @param pPciDev The PCI device structure.
5103 * Any PCI enabled device must keep this in it's instance data!
5104 * Fill in the PCI data config before registration, please.
5105 * @remark This is the simple interface, a Ex interface will be created if
5106 * more features are needed later.
5107 */
5108 DECLR3CALLBACKMEMBER(int, pfnPCIRegister,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev));
5109
5110 /**
5111 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
5112 *
5113 * @returns VBox status code.
5114 * @param pDevIns Device instance.
5115 * @param iRegion The region number.
5116 * @param cbRegion Size of the region.
5117 * @param enmType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
5118 * @param pfnCallback Callback for doing the mapping.
5119 */
5120 DECLR3CALLBACKMEMBER(int, pfnPCIIORegionRegister,(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
5121
5122 /**
5123 * Register PCI configuration space read/write callbacks.
5124 *
5125 * @param pDevIns Device instance.
5126 * @param pPciDev The PCI device structure.
5127 * If NULL the default PCI device for this device instance is used.
5128 * @param pfnRead Pointer to the user defined PCI config read function.
5129 * @param ppfnReadOld Pointer to function pointer which will receive the old (default)
5130 * PCI config read function. This way, user can decide when (and if)
5131 * to call default PCI config read function. Can be NULL.
5132 * @param pfnWrite Pointer to the user defined PCI config write function.
5133 * @param pfnWriteOld Pointer to function pointer which will receive the old (default)
5134 * PCI config write function. This way, user can decide when (and if)
5135 * to call default PCI config write function. Can be NULL.
5136 * @thread EMT
5137 */
5138 DECLR3CALLBACKMEMBER(void, pfnPCISetConfigCallbacks,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
5139 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
5140
5141 /**
5142 * Set the IRQ for a PCI device.
5143 *
5144 * @param pDevIns Device instance.
5145 * @param iIrq IRQ number to set.
5146 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
5147 * @thread Any thread, but will involve the emulation thread.
5148 */
5149 DECLR3CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
5150
5151 /**
5152 * Set the IRQ for a PCI device, but don't wait for EMT to process
5153 * the request when not called from EMT.
5154 *
5155 * @param pDevIns Device instance.
5156 * @param iIrq IRQ number to set.
5157 * @param iLevel IRQ level.
5158 * @thread Any thread, but will involve the emulation thread.
5159 */
5160 DECLR3CALLBACKMEMBER(void, pfnPCISetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
5161
5162 /**
5163 * Set ISA IRQ for a device.
5164 *
5165 * @param pDevIns Device instance.
5166 * @param iIrq IRQ number to set.
5167 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
5168 * @thread Any thread, but will involve the emulation thread.
5169 */
5170 DECLR3CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
5171
5172 /**
5173 * Set the ISA IRQ for a device, but don't wait for EMT to process
5174 * the request when not called from EMT.
5175 *
5176 * @param pDevIns Device instance.
5177 * @param iIrq IRQ number to set.
5178 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
5179 * @thread Any thread, but will involve the emulation thread.
5180 */
5181 DECLR3CALLBACKMEMBER(void, pfnISASetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
5182
5183 /**
5184 * Attaches a driver (chain) to the device.
5185 *
5186 * The first call for a LUN this will serve as a registartion of the LUN. The pBaseInterface and
5187 * the pszDesc string will be registered with that LUN and kept around for PDMR3QueryDeviceLun().
5188 *
5189 * @returns VBox status code.
5190 * @param pDevIns Device instance.
5191 * @param iLun The logical unit to attach.
5192 * @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
5193 * @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
5194 * @param pszDesc Pointer to a string describing the LUN. This string must remain valid
5195 * for the live of the device instance.
5196 */
5197 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMDEVINS pDevIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc));
5198
5199#if 0
5200 /* USB... */
5201
5202#endif
5203
5204 /**
5205 * Allocate memory which is associated with current VM instance
5206 * and automatically freed on it's destruction.
5207 *
5208 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
5209 * @param pDevIns Device instance.
5210 * @param cb Number of bytes to allocate.
5211 */
5212 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMDEVINS pDevIns, size_t cb));
5213
5214 /**
5215 * Allocate memory which is associated with current VM instance
5216 * and automatically freed on it's destruction. The memory is ZEROed.
5217 *
5218 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
5219 * @param pDevIns Device instance.
5220 * @param cb Number of bytes to allocate.
5221 */
5222 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMDEVINS pDevIns, size_t cb));
5223
5224 /**
5225 * Free memory allocated with pfnMMHeapAlloc() and pfnMMHeapAllocZ().
5226 *
5227 * @param pDevIns Device instance.
5228 * @param pv Pointer to the memory to free.
5229 */
5230 DECLR3CALLBACKMEMBER(void, pfnMMHeapFree,(PPDMDEVINS pDevIns, void *pv));
5231
5232 /**
5233 * Set the VM error message
5234 *
5235 * @returns rc.
5236 * @param pDevIns Device instance.
5237 * @param rc VBox status code.
5238 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
5239 * @param pszFormat Error message format string.
5240 * @param ... Error message arguments.
5241 */
5242 DECLR3CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
5243
5244 /**
5245 * Set the VM error message
5246 *
5247 * @returns rc.
5248 * @param pDevIns Device instance.
5249 * @param rc VBox status code.
5250 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
5251 * @param pszFormat Error message format string.
5252 * @param va Error message arguments.
5253 */
5254 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
5255
5256 /**
5257 * Set the VM runtime error message
5258 *
5259 * @returns VBox status code.
5260 * @param pDevIns Device instance.
5261 * @param fFatal Whether it is a fatal error or not.
5262 * @param pszErrorID Error ID string.
5263 * @param pszFormat Error message format string.
5264 * @param ... Error message arguments.
5265 */
5266 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...));
5267
5268 /**
5269 * Set the VM runtime error message
5270 *
5271 * @returns VBox status code.
5272 * @param pDevIns Device instance.
5273 * @param fFatal Whether it is a fatal error or not.
5274 * @param pszErrorID Error ID string.
5275 * @param pszFormat Error message format string.
5276 * @param va Error message arguments.
5277 */
5278 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
5279
5280 /**
5281 * Assert that the current thread is the emulation thread.
5282 *
5283 * @returns True if correct.
5284 * @returns False if wrong.
5285 * @param pDevIns Device instance.
5286 * @param pszFile Filename of the assertion location.
5287 * @param iLine The linenumber of the assertion location.
5288 * @param pszFunction Function of the assertion location.
5289 */
5290 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
5291
5292 /**
5293 * Assert that the current thread is NOT the emulation thread.
5294 *
5295 * @returns True if correct.
5296 * @returns False if wrong.
5297 * @param pDevIns Device instance.
5298 * @param pszFile Filename of the assertion location.
5299 * @param iLine The linenumber of the assertion location.
5300 * @param pszFunction Function of the assertion location.
5301 */
5302 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
5303
5304 /**
5305 * Stops the VM and enters the debugger to look at the guest state.
5306 *
5307 * Use the PDMDeviceDBGFStop() inline function with the RT_SRC_POS macro instead of
5308 * invoking this function directly.
5309 *
5310 * @returns VBox status code which must be passed up to the VMM.
5311 * @param pDevIns Device instance.
5312 * @param pszFile Filename of the assertion location.
5313 * @param iLine The linenumber of the assertion location.
5314 * @param pszFunction Function of the assertion location.
5315 * @param pszFormat Message. (optional)
5316 * @param args Message parameters.
5317 */
5318 DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list args));
5319
5320 /**
5321 * Register a info handler with DBGF,
5322 *
5323 * @returns VBox status code.
5324 * @param pDevIns Device instance.
5325 * @param pszName The identifier of the info.
5326 * @param pszDesc The description of the info and any arguments the handler may take.
5327 * @param pfnHandler The handler function to be called to display the info.
5328 */
5329 DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegister,(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler));
5330
5331 /**
5332 * Registers a statistics sample if statistics are enabled.
5333 *
5334 * @param pDevIns Device instance of the DMA.
5335 * @param pvSample Pointer to the sample.
5336 * @param enmType Sample type. This indicates what pvSample is pointing at.
5337 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
5338 * Further nesting is possible.
5339 * @param enmUnit Sample unit.
5340 * @param pszDesc Sample description.
5341 */
5342 DECLR3CALLBACKMEMBER(void, pfnSTAMRegister,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc));
5343
5344 /**
5345 * Same as pfnSTAMRegister except that the name is specified in a
5346 * RTStrPrintf like fashion.
5347 *
5348 * @returns VBox status.
5349 * @param pDevIns Device instance of the DMA.
5350 * @param pvSample Pointer to the sample.
5351 * @param enmType Sample type. This indicates what pvSample is pointing at.
5352 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
5353 * @param enmUnit Sample unit.
5354 * @param pszDesc Sample description.
5355 * @param pszName The sample name format string.
5356 * @param ... Arguments to the format string.
5357 */
5358 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterF,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
5359 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...));
5360
5361 /**
5362 * Same as pfnSTAMRegister except that the name is specified in a
5363 * RTStrPrintfV like fashion.
5364 *
5365 * @returns VBox status.
5366 * @param pDevIns Device instance of the DMA.
5367 * @param pvSample Pointer to the sample.
5368 * @param enmType Sample type. This indicates what pvSample is pointing at.
5369 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
5370 * @param enmUnit Sample unit.
5371 * @param pszDesc Sample description.
5372 * @param pszName The sample name format string.
5373 * @param args Arguments to the format string.
5374 */
5375 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
5376 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args));
5377
5378 /**
5379 * Register the RTC device.
5380 *
5381 * @returns VBox status code.
5382 * @param pDevIns Device instance.
5383 * @param pRtcReg Pointer to a RTC registration structure.
5384 * @param ppRtcHlp Where to store the pointer to the helper functions.
5385 */
5386 DECLR3CALLBACKMEMBER(int, pfnRTCRegister,(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp));
5387
5388 /**
5389 * Create a queue.
5390 *
5391 * @returns VBox status code.
5392 * @param pDevIns The device instance.
5393 * @param cbItem The size of a queue item.
5394 * @param cItems The number of items in the queue.
5395 * @param cMilliesInterval The number of milliseconds between polling the queue.
5396 * If 0 then the emulation thread will be notified whenever an item arrives.
5397 * @param pfnCallback The consumer function.
5398 * @param fGCEnabled Set if the queue should work in GC too.
5399 * @param ppQueue Where to store the queue handle on success.
5400 * @thread The emulation thread.
5401 */
5402 DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMDEVINS pDevIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
5403 PFNPDMQUEUEDEV pfnCallback, bool fGCEnabled, PPDMQUEUE *ppQueue));
5404
5405 /**
5406 * Initializes a PDM critical section.
5407 *
5408 * The PDM critical sections are derived from the IPRT critical sections, but
5409 * works in GC as well.
5410 *
5411 * @returns VBox status code.
5412 * @param pDevIns Device instance.
5413 * @param pCritSect Pointer to the critical section.
5414 * @param pszName The name of the critical section (for statistics).
5415 */
5416 DECLR3CALLBACKMEMBER(int, pfnCritSectInit,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, const char *pszName));
5417
5418 /**
5419 * Get the real world UTC time adjusted for VM lag, user offset and warpdrive.
5420 *
5421 * @returns pTime.
5422 * @param pDevIns Device instance.
5423 * @param pTime Where to store the time.
5424 */
5425 DECLR3CALLBACKMEMBER(PRTTIMESPEC, pfnUTCNow,(PPDMDEVINS pDevIns, PRTTIMESPEC pTime));
5426
5427 /** Space reserved for future members.
5428 * @{ */
5429 DECLR3CALLBACKMEMBER(void, pfnReserved1,(void));
5430 DECLR3CALLBACKMEMBER(void, pfnReserved2,(void));
5431 DECLR3CALLBACKMEMBER(void, pfnReserved3,(void));
5432 DECLR3CALLBACKMEMBER(void, pfnReserved4,(void));
5433 DECLR3CALLBACKMEMBER(void, pfnReserved5,(void));
5434 DECLR3CALLBACKMEMBER(void, pfnReserved6,(void));
5435 DECLR3CALLBACKMEMBER(void, pfnReserved7,(void));
5436 DECLR3CALLBACKMEMBER(void, pfnReserved8,(void));
5437 DECLR3CALLBACKMEMBER(void, pfnReserved9,(void));
5438 DECLR3CALLBACKMEMBER(void, pfnReserved10,(void));
5439 /** @} */
5440
5441
5442 /** API available to trusted devices only.
5443 *
5444 * These APIs are providing unrestricted access to the guest and the VM,
5445 * or they are interacting intimately with PDM.
5446 *
5447 * @{
5448 */
5449 /**
5450 * Gets the VM handle. Restricted API.
5451 *
5452 * @returns VM Handle.
5453 * @param pDevIns Device instance.
5454 */
5455 DECLR3CALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
5456
5457 /**
5458 * Register the PCI Bus.
5459 *
5460 * @returns VBox status code.
5461 * @param pDevIns Device instance.
5462 * @param pPciBusReg Pointer to PCI bus registration structure.
5463 * @param ppPciHlpR3 Where to store the pointer to the PCI Bus helpers.
5464 */
5465 DECLR3CALLBACKMEMBER(int, pfnPCIBusRegister,(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3));
5466
5467 /**
5468 * Register the PIC device.
5469 *
5470 * @returns VBox status code.
5471 * @param pDevIns Device instance.
5472 * @param pPicReg Pointer to a PIC registration structure.
5473 * @param ppPicHlpR3 Where to store the pointer to the PIC HC helpers.
5474 */
5475 DECLR3CALLBACKMEMBER(int, pfnPICRegister,(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3));
5476
5477 /**
5478 * Register the APIC device.
5479 *
5480 * @returns VBox status code.
5481 * @param pDevIns Device instance.
5482 * @param pApicReg Pointer to a APIC registration structure.
5483 * @param ppApicHlpR3 Where to store the pointer to the APIC helpers.
5484 */
5485 DECLR3CALLBACKMEMBER(int, pfnAPICRegister,(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3));
5486
5487 /**
5488 * Register the I/O APIC device.
5489 *
5490 * @returns VBox status code.
5491 * @param pDevIns Device instance.
5492 * @param pIoApicReg Pointer to a I/O APIC registration structure.
5493 * @param ppIoApicHlpR3 Where to store the pointer to the IOAPIC helpers.
5494 */
5495 DECLR3CALLBACKMEMBER(int, pfnIOAPICRegister,(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3));
5496
5497 /**
5498 * Register the DMA device.
5499 *
5500 * @returns VBox status code.
5501 * @param pDevIns Device instance.
5502 * @param pDmacReg Pointer to a DMAC registration structure.
5503 * @param ppDmacHlp Where to store the pointer to the DMA helpers.
5504 */
5505 DECLR3CALLBACKMEMBER(int, pfnDMACRegister,(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp));
5506
5507 /**
5508 * Read physical memory.
5509 *
5510 * @param pDevIns Device instance.
5511 * @param GCPhys Physical address start reading from.
5512 * @param pvBuf Where to put the read bits.
5513 * @param cbRead How many bytes to read.
5514 * @thread Any thread, but the call may involve the emulation thread.
5515 */
5516 DECLR3CALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
5517
5518 /**
5519 * Write to physical memory.
5520 *
5521 * @param pDevIns Device instance.
5522 * @param GCPhys Physical address to write to.
5523 * @param pvBuf What to write.
5524 * @param cbWrite How many bytes to write.
5525 * @thread Any thread, but the call may involve the emulation thread.
5526 */
5527 DECLR3CALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
5528
5529 /**
5530 * Read guest physical memory by virtual address.
5531 *
5532 * @param pDevIns Device instance.
5533 * @param pvDst Where to put the read bits.
5534 * @param GCVirtSrc Guest virtual address to start reading from.
5535 * @param cb How many bytes to read.
5536 * @thread The emulation thread.
5537 */
5538 DECLR3CALLBACKMEMBER(int, pfnPhysReadGCVirt,(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb));
5539
5540 /**
5541 * Write to guest physical memory by virtual address.
5542 *
5543 * @param pDevIns Device instance.
5544 * @param GCVirtDst Guest virtual address to write to.
5545 * @param pvSrc What to write.
5546 * @param cb How many bytes to write.
5547 * @thread The emulation thread.
5548 */
5549 DECLR3CALLBACKMEMBER(int, pfnPhysWriteGCVirt,(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb));
5550
5551 /**
5552 * Reserve physical address space for ROM and MMIO ranges.
5553 *
5554 * @returns VBox status code.
5555 * @param pDevIns Device instance.
5556 * @param GCPhys Start physical address.
5557 * @param cbRange The size of the range.
5558 * @param pszDesc Description string.
5559 * @thread The emulation thread.
5560 */
5561 DECLR3CALLBACKMEMBER(int, pfnPhysReserve,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc));
5562
5563 /**
5564 * Convert a guest physical address to a host virtual address.
5565 *
5566 * @returns VBox status code.
5567 * @param pDevIns Device instance.
5568 * @param GCPhys Start physical address.
5569 * @param cbRange The size of the range. Use 0 if you don't care about the range.
5570 * @param ppvHC Where to store the HC pointer corresponding to GCPhys.
5571 * @thread Any thread.
5572 */
5573 DECLR3CALLBACKMEMBER(int, pfnPhys2HCVirt,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR ppvHC));
5574
5575 /**
5576 * Convert a guest virtual address to a host virtual address.
5577 *
5578 * @returns VBox status code.
5579 * @param pDevIns Device instance.
5580 * @param GCPtr Guest virtual address.
5581 * @param pHCPtr Where to store the HC pointer corresponding to GCPtr.
5582 * @thread The emulation thread.
5583 * @remark Careful with page boundraries.
5584 */
5585 DECLR3CALLBACKMEMBER(int, pfnPhysGCPtr2HCPtr,(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTHCPTR pHCPtr));
5586
5587 /**
5588 * Checks if the Gate A20 is enabled or not.
5589 *
5590 * @returns true if A20 is enabled.
5591 * @returns false if A20 is disabled.
5592 * @param pDevIns Device instance.
5593 * @thread The emulation thread.
5594 */
5595 DECLR3CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
5596
5597 /**
5598 * Enables or disables the Gate A20.
5599 *
5600 * @param pDevIns Device instance.
5601 * @param fEnable Set this flag to enable the Gate A20; clear it to disable.
5602 * @thread The emulation thread.
5603 */
5604 DECLR3CALLBACKMEMBER(void, pfnA20Set,(PPDMDEVINS pDevIns, bool fEnable));
5605
5606 /**
5607 * Resets the VM.
5608 *
5609 * @returns The appropriate VBox status code to pass around on reset.
5610 * @param pDevIns Device instance.
5611 * @thread The emulation thread.
5612 */
5613 DECLR3CALLBACKMEMBER(int, pfnVMReset,(PPDMDEVINS pDevIns));
5614
5615 /**
5616 * Suspends the VM.
5617 *
5618 * @returns The appropriate VBox status code to pass around on suspend.
5619 * @param pDevIns Device instance.
5620 * @thread The emulation thread.
5621 */
5622 DECLR3CALLBACKMEMBER(int, pfnVMSuspend,(PPDMDEVINS pDevIns));
5623
5624 /**
5625 * Power off the VM.
5626 *
5627 * @returns The appropriate VBox status code to pass around on power off.
5628 * @param pDevIns Device instance.
5629 * @thread The emulation thread.
5630 */
5631 DECLR3CALLBACKMEMBER(int, pfnVMPowerOff,(PPDMDEVINS pDevIns));
5632
5633 /**
5634 * Acquire global VM lock
5635 *
5636 * @returns VBox status code
5637 * @param pDevIns Device instance.
5638 */
5639 DECLR3CALLBACKMEMBER(int , pfnLockVM,(PPDMDEVINS pDevIns));
5640
5641 /**
5642 * Release global VM lock
5643 *
5644 * @returns VBox status code
5645 * @param pDevIns Device instance.
5646 */
5647 DECLR3CALLBACKMEMBER(int, pfnUnlockVM,(PPDMDEVINS pDevIns));
5648
5649 /**
5650 * Check that the current thread owns the global VM lock.
5651 *
5652 * @returns boolean
5653 * @param pDevIns Device instance.
5654 * @param pszFile Filename of the assertion location.
5655 * @param iLine Linenumber of the assertion location.
5656 * @param pszFunction Function of the assertion location.
5657 */
5658 DECLR3CALLBACKMEMBER(bool, pfnAssertVMLock,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
5659
5660 /**
5661 * Register transfer function for DMA channel.
5662 *
5663 * @returns VBox status code.
5664 * @param pDevIns Device instance.
5665 * @param uChannel Channel number.
5666 * @param pfnTransferHandler Device specific transfer callback function.
5667 * @param pvUser User pointer to pass to the callback.
5668 * @thread EMT
5669 */
5670 DECLR3CALLBACKMEMBER(int, pfnDMARegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
5671
5672 /**
5673 * Read memory.
5674 *
5675 * @returns VBox status code.
5676 * @param pDevIns Device instance.
5677 * @param uChannel Channel number.
5678 * @param pvBuffer Pointer to target buffer.
5679 * @param off DMA position.
5680 * @param cbBlock Block size.
5681 * @param pcbRead Where to store the number of bytes which was read. optional.
5682 * @thread EMT
5683 */
5684 DECLR3CALLBACKMEMBER(int, pfnDMAReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead));
5685
5686 /**
5687 * Write memory.
5688 *
5689 * @returns VBox status code.
5690 * @param pDevIns Device instance.
5691 * @param uChannel Channel number.
5692 * @param pvBuffer Memory to write.
5693 * @param off DMA position.
5694 * @param cbBlock Block size.
5695 * @param pcbWritten Where to store the number of bytes which was written. optional.
5696 * @thread EMT
5697 */
5698 DECLR3CALLBACKMEMBER(int, pfnDMAWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten));
5699
5700 /**
5701 * Set the DREQ line.
5702 *
5703 * @returns VBox status code.
5704 * @param pDevIns Device instance.
5705 * @param uChannel Channel number.
5706 * @param uLevel Level of the line.
5707 * @thread EMT
5708 */
5709 DECLR3CALLBACKMEMBER(int, pfnDMASetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
5710
5711 /**
5712 * Get channel mode.
5713 *
5714 * @returns Channel mode. See specs.
5715 * @param pDevIns Device instance.
5716 * @param uChannel Channel number.
5717 * @thread EMT
5718 */
5719 DECLR3CALLBACKMEMBER(uint8_t, pfnDMAGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
5720
5721 /**
5722 * Schedule DMA execution.
5723 *
5724 * @param pDevIns Device instance.
5725 * @thread Any thread.
5726 */
5727 DECLR3CALLBACKMEMBER(void, pfnDMASchedule,(PPDMDEVINS pDevIns));
5728
5729 /**
5730 * Write CMOS value and update the checksum(s).
5731 *
5732 * @returns VBox status code.
5733 * @param pDevIns Device instance.
5734 * @param iReg The CMOS register index.
5735 * @param u8Value The CMOS register value.
5736 * @thread EMT
5737 */
5738 DECLR3CALLBACKMEMBER(int, pfnCMOSWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
5739
5740 /**
5741 * Read CMOS value.
5742 *
5743 * @returns VBox status code.
5744 * @param pDevIns Device instance.
5745 * @param iReg The CMOS register index.
5746 * @param pu8Value Where to store the CMOS register value.
5747 * @thread EMT
5748 */
5749 DECLR3CALLBACKMEMBER(int, pfnCMOSRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
5750
5751 /**
5752 * Query CPUID.
5753 *
5754 * @param pDevIns Device instance.
5755 * @param iLeaf The CPUID leaf to get.
5756 * @param pEax Where to store the EAX value.
5757 * @param pEbx Where to store the EBX value.
5758 * @param pEcx Where to store the ECX value.
5759 * @param pEdx Where to store the EDX value.
5760 */
5761 DECLR3CALLBACKMEMBER(void, pfnGetCpuId,(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx));
5762
5763 /** @} */
5764
5765 /** Just a safety precaution. (The value is 0.) */
5766 uint32_t u32TheEnd;
5767} PDMDEVHLP;
5768#endif /* !IN_RING3 */
5769/** Pointer PDM Device API. */
5770typedef HCPTRTYPE(struct PDMDEVHLP *) PPDMDEVHLP;
5771/** Pointer PDM Device API. */
5772typedef HCPTRTYPE(const struct PDMDEVHLP *) PCPDMDEVHLP;
5773
5774/** Current PDMDEVHLP version number. */
5775#define PDM_DEVHLP_VERSION 0xf2040000
5776
5777
5778/**
5779 * PDM Device API - GC Variant.
5780 */
5781typedef struct PDMDEVHLPGC
5782{
5783 /** Structure version. PDM_DEVHLPGC_VERSION defines the current version. */
5784 uint32_t u32Version;
5785
5786 /**
5787 * Set the IRQ for a PCI device.
5788 *
5789 * @param pDevIns Device instance.
5790 * @param iIrq IRQ number to set.
5791 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
5792 * @thread Any thread, but will involve the emulation thread.
5793 */
5794 DECLGCCALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
5795
5796 /**
5797 * Set ISA IRQ for a device.
5798 *
5799 * @param pDevIns Device instance.
5800 * @param iIrq IRQ number to set.
5801 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
5802 * @thread Any thread, but will involve the emulation thread.
5803 */
5804 DECLGCCALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
5805
5806 /**
5807 * Read physical memory.
5808 *
5809 * @param pDevIns Device instance.
5810 * @param GCPhys Physical address start reading from.
5811 * @param pvBuf Where to put the read bits.
5812 * @param cbRead How many bytes to read.
5813 */
5814 DECLGCCALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
5815
5816 /**
5817 * Write to physical memory.
5818 *
5819 * @param pDevIns Device instance.
5820 * @param GCPhys Physical address to write to.
5821 * @param pvBuf What to write.
5822 * @param cbWrite How many bytes to write.
5823 */
5824 DECLGCCALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
5825
5826 /**
5827 * Checks if the Gate A20 is enabled or not.
5828 *
5829 * @returns true if A20 is enabled.
5830 * @returns false if A20 is disabled.
5831 * @param pDevIns Device instance.
5832 * @thread The emulation thread.
5833 */
5834 DECLGCCALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
5835
5836 /**
5837 * Set the VM error message
5838 *
5839 * @returns rc.
5840 * @param pDrvIns Driver instance.
5841 * @param rc VBox status code.
5842 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
5843 * @param pszFormat Error message format string.
5844 * @param ... Error message arguments.
5845 */
5846 DECLGCCALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
5847
5848 /**
5849 * Set the VM error message
5850 *
5851 * @returns rc.
5852 * @param pDrvIns Driver instance.
5853 * @param rc VBox status code.
5854 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
5855 * @param pszFormat Error message format string.
5856 * @param va Error message arguments.
5857 */
5858 DECLGCCALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
5859
5860 /**
5861 * Set the VM runtime error message
5862 *
5863 * @returns VBox status code.
5864 * @param pDevIns Device instance.
5865 * @param fFatal Whether it is a fatal error or not.
5866 * @param pszErrorID Error ID string.
5867 * @param pszFormat Error message format string.
5868 * @param ... Error message arguments.
5869 */
5870 DECLGCCALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...));
5871
5872 /**
5873 * Set the VM runtime error message
5874 *
5875 * @returns VBox status code.
5876 * @param pDevIns Device instance.
5877 * @param fFatal Whether it is a fatal error or not.
5878 * @param pszErrorID Error ID string.
5879 * @param pszFormat Error message format string.
5880 * @param va Error message arguments.
5881 */
5882 DECLGCCALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
5883
5884 /**
5885 * Set parameters for pending MMIO patch operation
5886 *
5887 * @returns VBox status code.
5888 * @param pDevIns Device instance.
5889 * @param GCPhys MMIO physical address
5890 * @param pCachedData GC pointer to cached data
5891 */
5892 DECLGCCALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
5893
5894 /** Just a safety precaution. */
5895 uint32_t u32TheEnd;
5896} PDMDEVHLPGC;
5897/** Pointer PDM Device GC API. */
5898typedef GCPTRTYPE(struct PDMDEVHLPGC *) PPDMDEVHLPGC;
5899/** Pointer PDM Device GC API. */
5900typedef GCPTRTYPE(const struct PDMDEVHLPGC *) PCPDMDEVHLPGC;
5901
5902/** Current PDMDEVHLP version number. */
5903#define PDM_DEVHLPGC_VERSION 0xfb010000
5904
5905
5906/**
5907 * PDM Device API - R0 Variant.
5908 */
5909typedef struct PDMDEVHLPR0
5910{
5911 /** Structure version. PDM_DEVHLPR0_VERSION defines the current version. */
5912 uint32_t u32Version;
5913
5914 /**
5915 * Set the IRQ for a PCI device.
5916 *
5917 * @param pDevIns Device instance.
5918 * @param iIrq IRQ number to set.
5919 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
5920 * @thread Any thread, but will involve the emulation thread.
5921 */
5922 DECLR0CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
5923
5924 /**
5925 * Set ISA IRQ for a device.
5926 *
5927 * @param pDevIns Device instance.
5928 * @param iIrq IRQ number to set.
5929 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
5930 * @thread Any thread, but will involve the emulation thread.
5931 */
5932 DECLR0CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
5933
5934 /**
5935 * Read physical memory.
5936 *
5937 * @param pDevIns Device instance.
5938 * @param GCPhys Physical address start reading from.
5939 * @param pvBuf Where to put the read bits.
5940 * @param cbRead How many bytes to read.
5941 */
5942 DECLR0CALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
5943
5944 /**
5945 * Write to physical memory.
5946 *
5947 * @param pDevIns Device instance.
5948 * @param GCPhys Physical address to write to.
5949 * @param pvBuf What to write.
5950 * @param cbWrite How many bytes to write.
5951 */
5952 DECLR0CALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
5953
5954 /**
5955 * Checks if the Gate A20 is enabled or not.
5956 *
5957 * @returns true if A20 is enabled.
5958 * @returns false if A20 is disabled.
5959 * @param pDevIns Device instance.
5960 * @thread The emulation thread.
5961 */
5962 DECLR0CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
5963
5964 /**
5965 * Set the VM error message
5966 *
5967 * @returns rc.
5968 * @param pDrvIns Driver instance.
5969 * @param rc VBox status code.
5970 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
5971 * @param pszFormat Error message format string.
5972 * @param ... Error message arguments.
5973 */
5974 DECLR0CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
5975
5976 /**
5977 * Set the VM error message
5978 *
5979 * @returns rc.
5980 * @param pDrvIns Driver instance.
5981 * @param rc VBox status code.
5982 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
5983 * @param pszFormat Error message format string.
5984 * @param va Error message arguments.
5985 */
5986 DECLR0CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
5987
5988 /**
5989 * Set the VM runtime error message
5990 *
5991 * @returns VBox status code.
5992 * @param pDevIns Device instance.
5993 * @param fFatal Whether it is a fatal error or not.
5994 * @param pszErrorID Error ID string.
5995 * @param pszFormat Error message format string.
5996 * @param ... Error message arguments.
5997 */
5998 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...));
5999
6000 /**
6001 * Set the VM runtime error message
6002 *
6003 * @returns VBox status code.
6004 * @param pDevIns Device instance.
6005 * @param fFatal Whether it is a fatal error or not.
6006 * @param pszErrorID Error ID string.
6007 * @param pszFormat Error message format string.
6008 * @param va Error message arguments.
6009 */
6010 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
6011
6012 /**
6013 * Set parameters for pending MMIO patch operation
6014 *
6015 * @returns rc.
6016 * @param pDevIns Device instance.
6017 * @param GCPhys MMIO physical address
6018 * @param pCachedData GC pointer to cached data
6019 */
6020 DECLR0CALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
6021
6022 /** Just a safety precaution. */
6023 uint32_t u32TheEnd;
6024} PDMDEVHLPR0;
6025/** Pointer PDM Device R0 API. */
6026typedef HCPTRTYPE(struct PDMDEVHLPR0 *) PPDMDEVHLPR0;
6027/** Pointer PDM Device GC API. */
6028typedef HCPTRTYPE(const struct PDMDEVHLPR0 *) PCPDMDEVHLPR0;
6029
6030/** Current PDMDEVHLP version number. */
6031#define PDM_DEVHLPR0_VERSION 0xfb010000
6032
6033
6034
6035/**
6036 * PDM Device Instance.
6037 */
6038typedef struct PDMDEVINS
6039{
6040 /** Structure version. PDM_DEVINS_VERSION defines the current version. */
6041 uint32_t u32Version;
6042 /** Device instance number. */
6043 RTUINT iInstance;
6044 /** The base interface of the device.
6045 * The device constructor initializes this if it has any
6046 * device level interfaces to export. To obtain this interface
6047 * call PDMR3QueryDevice(). */
6048 PDMIBASE IBase;
6049
6050 /** Internal data. */
6051 union
6052 {
6053#ifdef PDMDEVINSINT_DECLARED
6054 PDMDEVINSINT s;
6055#endif
6056 uint8_t padding[HC_ARCH_BITS == 32 ? 48 : 96];
6057 } Internal;
6058
6059 /** Pointer the HC PDM Device API. */
6060 R3PTRTYPE(PCPDMDEVHLP) pDevHlp;
6061 /** Pointer the R0 PDM Device API. */
6062 R0PTRTYPE(PCPDMDEVHLPR0) pDevHlpR0;
6063 /** Pointer to device registration structure. */
6064 R3PTRTYPE(PCPDMDEVREG) pDevReg;
6065 /** Configuration handle. */
6066 R3PTRTYPE(PCFGMNODE) pCfgHandle;
6067 /** Pointer to device instance data. */
6068 R3PTRTYPE(void *) pvInstanceDataR3;
6069 /** Pointer to device instance data. */
6070 R0PTRTYPE(void *) pvInstanceDataR0;
6071 /** Pointer the GC PDM Device API. */
6072 GCPTRTYPE(PCPDMDEVHLPGC) pDevHlpGC;
6073 /** Pointer to device instance data. */
6074 GCPTRTYPE(void *) pvInstanceDataGC;
6075 /* padding to make achInstanceData aligned at 32 byte boundrary. */
6076 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 1 : 6];
6077 /** Device instance data. The size of this area is defined
6078 * in the PDMDEVREG::cbInstanceData field. */
6079 char achInstanceData[8];
6080} PDMDEVINS;
6081
6082/** Current DEVREG version number. */
6083#define PDM_DEVINS_VERSION 0xf3010000
6084
6085/** Converts a pointer to the PDMDEVINS::IBase to a pointer to PDMDEVINS. */
6086#define PDMIBASE_2_PDMDEV(pInterface) ( (PPDMDEVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDEVINS, IBase)) )
6087
6088
6089/** @def PDMDEV_ASSERT_EMT
6090 * Assert that the current thread is the emulation thread.
6091 */
6092#ifdef VBOX_STRICT
6093# define PDMDEV_ASSERT_EMT(pDevIns) pDevIns->pDevHlp->pfnAssertEMT(pDevIns, __FILE__, __LINE__, __FUNCTION__)
6094#else
6095# define PDMDEV_ASSERT_EMT(pDevIns) do { } while (0)
6096#endif
6097
6098/** @def PDMDEV_ASSERT_OTHER
6099 * Assert that the current thread is NOT the emulation thread.
6100 */
6101#ifdef VBOX_STRICT
6102# define PDMDEV_ASSERT_OTHER(pDevIns) pDevIns->pDevHlp->pfnAssertOther(pDevIns, __FILE__, __LINE__, __FUNCTION__)
6103#else
6104# define PDMDEV_ASSERT_OTHER(pDevIns) do { } while (0)
6105#endif
6106
6107/** @def PDMDEV_ASSERT_VMLOCK_OWNER
6108 * Assert that the current thread is owner of the VM lock.
6109 */
6110#ifdef VBOX_STRICT
6111# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) pDevIns->pDevHlp->pfnAssertVMLock(pDevIns, __FILE__, __LINE__, __FUNCTION__)
6112#else
6113# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) do { } while (0)
6114#endif
6115
6116/** @def PDMDEV_SET_ERROR
6117 * Set the VM error. See PDMDevHlpVMSetError() for printf like message formatting.
6118 */
6119#define PDMDEV_SET_ERROR(pDevIns, rc, pszError) \
6120 PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, "%s", pszError)
6121
6122/** @def PDMDEV_SET_RUNTIME_ERROR
6123 * Set the VM runtime error. See PDMDevHlpVMSetRuntimeError() for printf like message formatting.
6124 */
6125#define PDMDEV_SET_RUNTIME_ERROR(pDevIns, fFatal, pszErrorID, pszError) \
6126 PDMDevHlpVMSetRuntimeError(pDevIns, fFatal, pszErrorID, "%s", pszError)
6127
6128/** @def PDMINS2DATA
6129 * Converts a PDM Device or Driver instance pointer to a pointer to the instance data.
6130 */
6131#define PDMINS2DATA(pIns, type) ( (type)(void *)&(pIns)->achInstanceData[0] )
6132
6133/** @def PDMINS2DATA_GCPTR
6134 * Converts a PDM Device or Driver instance pointer to a GC pointer to the instance data.
6135 */
6136#define PDMINS2DATA_GCPTR(pIns) ( (pIns)->pvInstanceDataGC )
6137
6138/** @def PDMINS2DATA_R3PTR
6139 * Converts a PDM Device or Driver instance pointer to a HC pointer to the instance data.
6140 */
6141#define PDMINS2DATA_R3PTR(pIns) ( (pIns)->pvInstanceDataR3 )
6142
6143 /** @def PDMINS2DATA_R0PTR
6144 * Converts a PDM Device or Driver instance pointer to a R0 pointer to the instance data.
6145 */
6146#define PDMINS2DATA_R0PTR(pIns) ( (pIns)->pvInstanceDataR0 )
6147
6148/** @def PDMDEVINS_2_GCPTR
6149 * Converts a PDM Device instance pointer a GC PDM Device instance pointer.
6150 */
6151#define PDMDEVINS_2_GCPTR(pDevIns) ( (GCPTRTYPE(PPDMDEVINS))((RTGCUINTPTR)(pDevIns)->pvInstanceDataGC - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
6152
6153/** @def PDMDEVINS_2_R3PTR
6154 * Converts a PDM Device instance pointer a HC PDM Device instance pointer.
6155 */
6156#define PDMDEVINS_2_R3PTR(pDevIns) ( (HCPTRTYPE(PPDMDEVINS))((RTHCUINTPTR)(pDevIns)->pvInstanceDataR3 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
6157
6158/** @def PDMDEVINS_2_R0PTR
6159 * Converts a PDM Device instance pointer a R0 PDM Device instance pointer.
6160 */
6161#define PDMDEVINS_2_R0PTR(pDevIns) ( (R0PTRTYPE(PPDMDEVINS))((RTR0UINTPTR)(pDevIns)->pvInstanceDataR0 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
6162
6163
6164/**
6165 * VBOX_STRICT wrapper for pDevHlp->pfnDBGFStopV.
6166 *
6167 * @returns VBox status code which must be passed up to the VMM.
6168 * @param pDevIns Device instance.
6169 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
6170 * @param pszFormat Message. (optional)
6171 * @param ... Message parameters.
6172 */
6173DECLINLINE(int) PDMDeviceDBGFStop(PPDMDEVINS pDevIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
6174{
6175#ifdef VBOX_STRICT
6176# ifdef IN_RING3
6177 int rc;
6178 va_list args;
6179 va_start(args, pszFormat);
6180 rc = pDevIns->pDevHlp->pfnDBGFStopV(pDevIns, RT_SRC_POS_ARGS, pszFormat, args);
6181 va_end(args);
6182 return rc;
6183# else
6184 return VINF_EM_DBG_STOP;
6185# endif
6186#else
6187 return VINF_SUCCESS;
6188#endif
6189}
6190
6191
6192#ifdef IN_RING3
6193/**
6194 * @copydoc PDMDEVHLP::pfnIOPortRegister
6195 */
6196DECLINLINE(int) PDMDevHlpIOPortRegister(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTHCPTR pvUser,
6197 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
6198 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc)
6199{
6200 return pDevIns->pDevHlp->pfnIOPortRegister(pDevIns, Port, cPorts, pvUser, pfnOut, pfnIn, pfnOutStr, pfnInStr, pszDesc);
6201}
6202
6203/**
6204 * @copydoc PDMDEVHLP::pfnIOPortRegisterGC
6205 */
6206DECLINLINE(int) PDMDevHlpIOPortRegisterGC(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTGCPTR pvUser,
6207 const char *pszOut, const char *pszIn, const char *pszOutStr,
6208 const char *pszInStr, const char *pszDesc)
6209{
6210 return pDevIns->pDevHlp->pfnIOPortRegisterGC(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
6211}
6212
6213/**
6214 * @copydoc PDMDEVHLP::pfnIOPortRegisterR0
6215 */
6216DECLINLINE(int) PDMDevHlpIOPortRegisterR0(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTR0PTR pvUser,
6217 const char *pszOut, const char *pszIn, const char *pszOutStr,
6218 const char *pszInStr, const char *pszDesc)
6219{
6220 return pDevIns->pDevHlp->pfnIOPortRegisterR0(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
6221}
6222
6223/**
6224 * @copydoc PDMDEVHLP::pfnMMIORegister
6225 */
6226DECLINLINE(int) PDMDevHlpMMIORegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
6227 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
6228 const char *pszDesc)
6229{
6230 return pDevIns->pDevHlp->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, pfnFill, pszDesc);
6231}
6232
6233/**
6234 * @copydoc PDMDEVHLP::pfnMMIORegisterGC
6235 */
6236DECLINLINE(int) PDMDevHlpMMIORegisterGC(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
6237 const char *pszWrite, const char *pszRead, const char *pszFill, const char *pszDesc)
6238{
6239 return pDevIns->pDevHlp->pfnMMIORegisterGC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill, pszDesc);
6240}
6241
6242/**
6243 * @copydoc PDMDEVHLP::pfnMMIORegisterR0
6244 */
6245DECLINLINE(int) PDMDevHlpMMIORegisterR0(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTR0PTR pvUser,
6246 const char *pszWrite, const char *pszRead, const char *pszFill, const char *pszDesc)
6247{
6248 return pDevIns->pDevHlp->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill, pszDesc);
6249}
6250
6251/**
6252 * @copydoc PDMDEVHLP::pfnROMRegister
6253 */
6254DECLINLINE(int) PDMDevHlpROMRegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, const void *pvBinary, const char *pszDesc)
6255{
6256 return pDevIns->pDevHlp->pfnROMRegister(pDevIns, GCPhysStart, cbRange, pvBinary, pszDesc);
6257}
6258
6259/**
6260 * @copydoc PDMDEVHLP::pfnSSMRegister
6261 */
6262DECLINLINE(int) PDMDevHlpSSMRegister(PPDMDEVINS pDevIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
6263 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
6264 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone)
6265{
6266 return pDevIns->pDevHlp->pfnSSMRegister(pDevIns, pszName, u32Instance, u32Version, cbGuess,
6267 pfnSavePrep, pfnSaveExec, pfnSaveDone,
6268 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
6269}
6270
6271/**
6272 * @copydoc PDMDEVHLP::pfnTMTimerCreate
6273 */
6274DECLINLINE(int) PDMDevHlpTMTimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer)
6275{
6276 return pDevIns->pDevHlp->pfnTMTimerCreate(pDevIns, enmClock, pfnCallback, pszDesc, ppTimer);
6277}
6278
6279/**
6280 * @copydoc PDMDEVHLP::pfnPCIRegister
6281 */
6282DECLINLINE(int) PDMDevHlpPCIRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev)
6283{
6284 return pDevIns->pDevHlp->pfnPCIRegister(pDevIns, pPciDev);
6285}
6286
6287/**
6288 * @copydoc PDMDEVHLP::pfnPCIIORegionRegister
6289 */
6290DECLINLINE(int) PDMDevHlpPCIIORegionRegister(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
6291{
6292 return pDevIns->pDevHlp->pfnPCIIORegionRegister(pDevIns, iRegion, cbRegion, enmType, pfnCallback);
6293}
6294
6295/**
6296 * @copydoc PDMDEVHLP::pfnPCISetConfigCallbacks
6297 */
6298DECLINLINE(void) PDMDevHlpPCISetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
6299 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
6300{
6301 pDevIns->pDevHlp->pfnPCISetConfigCallbacks(pDevIns, pPciDev, pfnRead, ppfnReadOld, pfnWrite, ppfnWriteOld);
6302}
6303
6304/**
6305 * @copydoc PDMDEVHLP::pfnDriverAttach
6306 */
6307DECLINLINE(int) PDMDevHlpDriverAttach(PPDMDEVINS pDevIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
6308{
6309 return pDevIns->pDevHlp->pfnDriverAttach(pDevIns, iLun, pBaseInterface, ppBaseInterface, pszDesc);
6310}
6311
6312/**
6313 * @copydoc PDMDEVHLP::pfnMMHeapAlloc
6314 */
6315DECLINLINE(void *) PDMDevHlpMMHeapAlloc(PPDMDEVINS pDevIns, size_t cb)
6316{
6317 return pDevIns->pDevHlp->pfnMMHeapAlloc(pDevIns, cb);
6318}
6319
6320/**
6321 * @copydoc PDMDEVHLP::pfnMMHeapAllocZ
6322 */
6323DECLINLINE(void *) PDMDevHlpMMHeapAllocZ(PPDMDEVINS pDevIns, size_t cb)
6324{
6325 return pDevIns->pDevHlp->pfnMMHeapAllocZ(pDevIns, cb);
6326}
6327
6328/**
6329 * @copydoc PDMDEVHLP::pfnMMHeapFree
6330 */
6331DECLINLINE(void) PDMDevHlpMMHeapFree(PPDMDEVINS pDevIns, void *pv)
6332{
6333 pDevIns->pDevHlp->pfnMMHeapFree(pDevIns, pv);
6334}
6335
6336/**
6337 * @copydoc PDMDEVHLP::pfnDBGFInfoRegister
6338 */
6339DECLINLINE(int) PDMDevHlpDBGFInfoRegister(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler)
6340{
6341 return pDevIns->pDevHlp->pfnDBGFInfoRegister(pDevIns, pszName, pszDesc, pfnHandler);
6342}
6343
6344/**
6345 * @copydoc PDMDEVHLP::pfnSTAMRegister
6346 */
6347DECLINLINE(void) PDMDevHlpSTAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
6348{
6349 pDevIns->pDevHlp->pfnSTAMRegister(pDevIns, pvSample, enmType, pszName, enmUnit, pszDesc);
6350}
6351
6352/**
6353 * @copydoc PDMDEVHLP::pfnSTAMRegisterF
6354 */
6355DECLINLINE(void) PDMDevHlpSTAMRegisterF(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
6356 const char *pszDesc, const char *pszName, ...)
6357{
6358 va_list va;
6359 va_start(va, pszName);
6360 pDevIns->pDevHlp->pfnSTAMRegisterV(pDevIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
6361 va_end(va);
6362}
6363
6364/**
6365 * @copydoc PDMDEVHLP::pfnPDMQueueCreate
6366 */
6367DECLINLINE(int) PDMDevHlpPDMQueueCreate(PPDMDEVINS pDevIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
6368 PFNPDMQUEUEDEV pfnCallback, bool fGCEnabled, PPDMQUEUE *ppQueue)
6369{
6370 return pDevIns->pDevHlp->pfnPDMQueueCreate(pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fGCEnabled, ppQueue);
6371}
6372
6373/**
6374 * @copydoc PDMDEVHLP::pfnCritSectInit
6375 */
6376DECLINLINE(int) PDMDevHlpCritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, const char *pszName)
6377{
6378 return pDevIns->pDevHlp->pfnCritSectInit(pDevIns, pCritSect, pszName);
6379}
6380
6381/**
6382 * @copydoc PDMDEVHLP::pfnUTCNow
6383 */
6384DECLINLINE(PRTTIMESPEC) PDMDevHlpUTCNow(PPDMDEVINS pDevIns, PRTTIMESPEC pTime)
6385{
6386 return pDevIns->pDevHlp->pfnUTCNow(pDevIns, pTime);
6387}
6388
6389/**
6390 * @copydoc PDMDEVHLP::pfnGetVM
6391 */
6392DECLINLINE(PVM) PDMDevHlpGetVM(PPDMDEVINS pDevIns)
6393{
6394 return pDevIns->pDevHlp->pfnGetVM(pDevIns);
6395}
6396
6397/**
6398 * @copydoc PDMDEVHLP::pfnPhysReadGCVirt
6399 */
6400DECLINLINE(int) PDMDevHlpPhysReadGCVirt(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb)
6401{
6402 return pDevIns->pDevHlp->pfnPhysReadGCVirt(pDevIns, pvDst, GCVirtSrc, cb);
6403}
6404
6405/**
6406 * @copydoc PDMDEVHLP::pfnPhysWriteGCVirt
6407 */
6408DECLINLINE(int) PDMDevHlpPhysWriteGCVirt(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb)
6409{
6410 return pDevIns->pDevHlp->pfnPhysWriteGCVirt(pDevIns, GCVirtDst, pvSrc, cb);
6411}
6412
6413/**
6414 * @copydoc PDMDEVHLP::pfnPhysReserve
6415 */
6416DECLINLINE(int) PDMDevHlpPhysReserve(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc)
6417{
6418 return pDevIns->pDevHlp->pfnPhysReserve(pDevIns, GCPhys, cbRange, pszDesc);
6419}
6420
6421/**
6422 * @copydoc PDMDEVHLP::pfnPhys2HCVirt
6423 */
6424DECLINLINE(int) PDMDevHlpPhys2HCVirt(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR ppvHC)
6425{
6426 return pDevIns->pDevHlp->pfnPhys2HCVirt(pDevIns, GCPhys, cbRange, ppvHC);
6427}
6428
6429/**
6430 * @copydoc PDMDEVHLP::pfnPhysGCPtr2HCPtr
6431 */
6432DECLINLINE(int) PDMDevHlpPhysGCPtr2HCPtr(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTHCPTR pHCPtr)
6433{
6434 return pDevIns->pDevHlp->pfnPhysGCPtr2HCPtr(pDevIns, GCPtr, pHCPtr);
6435}
6436
6437/**
6438 * @copydoc PDMDEVHLP::pfnA20Set
6439 */
6440DECLINLINE(void) PDMDevHlpA20Set(PPDMDEVINS pDevIns, bool fEnable)
6441{
6442 pDevIns->pDevHlp->pfnA20Set(pDevIns, fEnable);
6443}
6444
6445/**
6446 * @copydoc PDMDEVHLP::pfnVMReset
6447 */
6448DECLINLINE(int) PDMDevHlpVMReset(PPDMDEVINS pDevIns)
6449{
6450 return pDevIns->pDevHlp->pfnVMReset(pDevIns);
6451}
6452
6453/**
6454 * @copydoc PDMDEVHLP::pfnVMSuspend
6455 */
6456DECLINLINE(int) PDMDevHlpVMSuspend(PPDMDEVINS pDevIns)
6457{
6458 return pDevIns->pDevHlp->pfnVMSuspend(pDevIns);
6459}
6460
6461/**
6462 * @copydoc PDMDEVHLP::pfnVMPowerOff
6463 */
6464DECLINLINE(int) PDMDevHlpVMPowerOff(PPDMDEVINS pDevIns)
6465{
6466 return pDevIns->pDevHlp->pfnVMPowerOff(pDevIns);
6467}
6468
6469/**
6470 * @copydoc PDMDEVHLP::pfnDMARegister
6471 */
6472DECLINLINE(int) PDMDevHlpDMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
6473{
6474 return pDevIns->pDevHlp->pfnDMARegister(pDevIns, uChannel, pfnTransferHandler, pvUser);
6475}
6476
6477/**
6478 * @copydoc PDMDEVHLP::pfnDMAReadMemory
6479 */
6480DECLINLINE(int) PDMDevHlpDMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
6481{
6482 return pDevIns->pDevHlp->pfnDMAReadMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbRead);
6483}
6484
6485/**
6486 * @copydoc PDMDEVHLP::pfnDMAWriteMemory
6487 */
6488DECLINLINE(int) PDMDevHlpDMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
6489{
6490 return pDevIns->pDevHlp->pfnDMAWriteMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbWritten);
6491}
6492
6493/**
6494 * @copydoc PDMDEVHLP::pfnDMASetDREQ
6495 */
6496DECLINLINE(int) PDMDevHlpDMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
6497{
6498 return pDevIns->pDevHlp->pfnDMASetDREQ(pDevIns, uChannel, uLevel);
6499}
6500
6501/**
6502 * @copydoc PDMDEVHLP::pfnDMAGetChannelMode
6503 */
6504DECLINLINE(uint8_t) PDMDevHlpDMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
6505{
6506 return pDevIns->pDevHlp->pfnDMAGetChannelMode(pDevIns, uChannel);
6507}
6508
6509/**
6510 * @copydoc PDMDEVHLP::pfnDMASchedule
6511 */
6512DECLINLINE(void) PDMDevHlpDMASchedule(PPDMDEVINS pDevIns)
6513{
6514 pDevIns->pDevHlp->pfnDMASchedule(pDevIns);
6515}
6516
6517/**
6518 * @copydoc PDMDEVHLP::pfnCMOSWrite
6519 */
6520DECLINLINE(int) PDMDevHlpCMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
6521{
6522 return pDevIns->pDevHlp->pfnCMOSWrite(pDevIns, iReg, u8Value);
6523}
6524
6525/**
6526 * @copydoc PDMDEVHLP::pfnCMOSRead
6527 */
6528DECLINLINE(int) PDMDevHlpCMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
6529{
6530 return pDevIns->pDevHlp->pfnCMOSRead(pDevIns, iReg, pu8Value);
6531}
6532
6533/**
6534 * @copydoc PDMDEVHLP::pfnGetCpuId
6535 */
6536DECLINLINE(void) PDMDevHlpGetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
6537{
6538 pDevIns->pDevHlp->pfnGetCpuId(pDevIns, iLeaf, pEax, pEbx, pEcx, pEdx);
6539}
6540#endif /* IN_RING3 */
6541
6542
6543/**
6544 * @copydoc PDMDEVHLP::pfnPCISetIrq
6545 */
6546DECLINLINE(void) PDMDevHlpPCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
6547{
6548#ifdef IN_GC
6549 pDevIns->pDevHlpGC->pfnPCISetIrq(pDevIns, iIrq, iLevel);
6550#elif defined(IN_RING0)
6551 pDevIns->pDevHlpR0->pfnPCISetIrq(pDevIns, iIrq, iLevel);
6552#else
6553 pDevIns->pDevHlp->pfnPCISetIrq(pDevIns, iIrq, iLevel);
6554#endif
6555}
6556
6557/**
6558 * @copydoc PDMDEVHLP::pfnPCISetIrqNoWait
6559 */
6560DECLINLINE(void) PDMDevHlpPCISetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
6561{
6562#ifdef IN_GC
6563 pDevIns->pDevHlpGC->pfnPCISetIrq(pDevIns, iIrq, iLevel);
6564#elif defined(IN_RING0)
6565 pDevIns->pDevHlpR0->pfnPCISetIrq(pDevIns, iIrq, iLevel);
6566#else
6567 pDevIns->pDevHlp->pfnPCISetIrqNoWait(pDevIns, iIrq, iLevel);
6568#endif
6569}
6570
6571/**
6572 * @copydoc PDMDEVHLP::pfnISASetIrq
6573 */
6574DECLINLINE(void) PDMDevHlpISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
6575{
6576#ifdef IN_GC
6577 pDevIns->pDevHlpGC->pfnISASetIrq(pDevIns, iIrq, iLevel);
6578#elif defined(IN_RING0)
6579 pDevIns->pDevHlpR0->pfnISASetIrq(pDevIns, iIrq, iLevel);
6580#else
6581 pDevIns->pDevHlp->pfnISASetIrq(pDevIns, iIrq, iLevel);
6582#endif
6583}
6584
6585/**
6586 * @copydoc PDMDEVHLP::pfnISASetIrqNoWait
6587 */
6588DECLINLINE(void) PDMDevHlpISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
6589{
6590#ifdef IN_GC
6591 pDevIns->pDevHlpGC->pfnISASetIrq(pDevIns, iIrq, iLevel);
6592#elif defined(IN_RING0)
6593 pDevIns->pDevHlpR0->pfnISASetIrq(pDevIns, iIrq, iLevel);
6594#else
6595 pDevIns->pDevHlp->pfnISASetIrqNoWait(pDevIns, iIrq, iLevel);
6596#endif
6597}
6598
6599/**
6600 * @copydoc PDMDEVHLP::pfnPhysRead
6601 */
6602DECLINLINE(void) PDMDevHlpPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
6603{
6604#ifdef IN_GC
6605 pDevIns->pDevHlpGC->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
6606#elif defined(IN_RING0)
6607 pDevIns->pDevHlpR0->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
6608#else
6609 pDevIns->pDevHlp->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
6610#endif
6611}
6612
6613/**
6614 * @copydoc PDMDEVHLP::pfnPhysWrite
6615 */
6616DECLINLINE(void) PDMDevHlpPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
6617{
6618#ifdef IN_GC
6619 pDevIns->pDevHlpGC->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
6620#elif defined(IN_RING0)
6621 pDevIns->pDevHlpR0->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
6622#else
6623 pDevIns->pDevHlp->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
6624#endif
6625}
6626
6627/**
6628 * @copydoc PDMDEVHLP::pfnA20IsEnabled
6629 */
6630DECLINLINE(bool) PDMDevHlpA20IsEnabled(PPDMDEVINS pDevIns)
6631{
6632#ifdef IN_GC
6633 return pDevIns->pDevHlpGC->pfnA20IsEnabled(pDevIns);
6634#elif defined(IN_RING0)
6635 return pDevIns->pDevHlpR0->pfnA20IsEnabled(pDevIns);
6636#else
6637 return pDevIns->pDevHlp->pfnA20IsEnabled(pDevIns);
6638#endif
6639}
6640
6641/**
6642 * @copydoc PDMDEVHLP::pfnVMSetError
6643 */
6644DECLINLINE(int) PDMDevHlpVMSetError(PPDMDEVINS pDevIns, const int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
6645{
6646 va_list va;
6647 va_start(va, pszFormat);
6648#ifdef IN_GC
6649 pDevIns->pDevHlpGC->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
6650#elif defined(IN_RING0)
6651 pDevIns->pDevHlpR0->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
6652#else
6653 pDevIns->pDevHlp->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
6654#endif
6655 va_end(va);
6656 return rc;
6657}
6658
6659/**
6660 * @copydoc PDMDEVHLP::pfnVMSetRuntimeError
6661 */
6662DECLINLINE(int) PDMDevHlpVMSetRuntimeError(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...)
6663{
6664 va_list va;
6665 int rc;
6666 va_start(va, pszFormat);
6667#ifdef IN_GC
6668 rc = pDevIns->pDevHlpGC->pfnVMSetRuntimeErrorV(pDevIns, fFatal, pszErrorID, pszFormat, va);
6669#elif defined(IN_RING0)
6670 rc = pDevIns->pDevHlpR0->pfnVMSetRuntimeErrorV(pDevIns, fFatal, pszErrorID, pszFormat, va);
6671#else
6672 rc = pDevIns->pDevHlp->pfnVMSetRuntimeErrorV(pDevIns, fFatal, pszErrorID, pszFormat, va);
6673#endif
6674 va_end(va);
6675 return rc;
6676}
6677
6678
6679
6680/** Pointer to callbacks provided to the VBoxDeviceRegister() call. */
6681typedef struct PDMDEVREGCB *PPDMDEVREGCB;
6682
6683/**
6684 * Callbacks for VBoxDeviceRegister().
6685 */
6686typedef struct PDMDEVREGCB
6687{
6688 /** Interface version.
6689 * This is set to PDM_DEVREG_CB_VERSION. */
6690 uint32_t u32Version;
6691
6692 /**
6693 * Registers a device with the current VM instance.
6694 *
6695 * @returns VBox status code.
6696 * @param pCallbacks Pointer to the callback table.
6697 * @param pDevReg Pointer to the device registration record.
6698 * This data must be permanent and readonly.
6699 */
6700 DECLR3CALLBACKMEMBER(int, pfnRegister,(PPDMDEVREGCB pCallbacks, PCPDMDEVREG pDevReg));
6701
6702 /**
6703 * Allocate memory which is associated with current VM instance
6704 * and automatically freed on it's destruction.
6705 *
6706 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
6707 * @param pCallbacks Pointer to the callback table.
6708 * @param cb Number of bytes to allocate.
6709 */
6710 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMDEVREGCB pCallbacks, size_t cb));
6711} PDMDEVREGCB;
6712
6713/** Current version of the PDMDEVREGCB structure. */
6714#define PDM_DEVREG_CB_VERSION 0xf4010000
6715
6716
6717/**
6718 * The VBoxDevicesRegister callback function.
6719 *
6720 * PDM will invoke this function after loading a device module and letting
6721 * the module decide which devices to register and how to handle conflicts.
6722 *
6723 * @returns VBox status code.
6724 * @param pCallbacks Pointer to the callback table.
6725 * @param u32Version VBox version number.
6726 */
6727typedef DECLCALLBACK(int) FNPDMVBOXDEVICESREGISTER(PPDMDEVREGCB pCallbacks, uint32_t u32Version);
6728
6729/** @} */
6730
6731
6732
6733
6734/** @defgroup grp_pdm_services Services
6735 * @ingroup grp_pdm
6736 * @{ */
6737
6738
6739/**
6740 * Construct a service instance for a VM.
6741 *
6742 * @returns VBox status.
6743 * @param pSrvIns The service instance data.
6744 * If the registration structure is needed, pSrvIns->pReg points to it.
6745 * @param pCfg Configuration node handle for the service. Use this to obtain the configuration
6746 * of the driver instance. It's also found in pSrvIns->pCfg, but since it's primary
6747 * usage is expected in this function it is passed as a parameter.
6748 */
6749typedef DECLCALLBACK(int) FNPDMSRVCONSTRUCT(PPDMSRVINS pSrvIns, PCFGMNODE pCfg);
6750/** Pointer to a FNPDMSRVCONSTRUCT() function. */
6751typedef FNPDMSRVCONSTRUCT *PFNPDMSRVCONSTRUCT;
6752
6753/**
6754 * Destruct a driver instance.
6755 *
6756 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
6757 * resources can be freed correctly.
6758 *
6759 * @param pSrvIns The service instance data.
6760 */
6761typedef DECLCALLBACK(void) FNPDMSRVDESTRUCT(PPDMSRVINS pSrvIns);
6762/** Pointer to a FNPDMSRVDESTRUCT() function. */
6763typedef FNPDMSRVDESTRUCT *PFNPDMSRVDESTRUCT;
6764
6765/**
6766 * Power On notification.
6767 *
6768 * @param pSrvIns The service instance data.
6769 */
6770typedef DECLCALLBACK(void) FNPDMSRVPOWERON(PPDMSRVINS pSrvIns);
6771/** Pointer to a FNPDMSRVPOWERON() function. */
6772typedef FNPDMSRVPOWERON *PFNPDMSRVPOWERON;
6773
6774/**
6775 * Reset notification.
6776 *
6777 * @returns VBox status.
6778 * @param pSrvIns The service instance data.
6779 */
6780typedef DECLCALLBACK(void) FNPDMSRVRESET(PPDMSRVINS pSrvIns);
6781/** Pointer to a FNPDMSRVRESET() function. */
6782typedef FNPDMSRVRESET *PFNPDMSRVRESET;
6783
6784/**
6785 * Suspend notification.
6786 *
6787 * @returns VBox status.
6788 * @param pSrvIns The service instance data.
6789 */
6790typedef DECLCALLBACK(void) FNPDMSRVSUSPEND(PPDMSRVINS pSrvIns);
6791/** Pointer to a FNPDMSRVSUSPEND() function. */
6792typedef FNPDMSRVSUSPEND *PFNPDMSRVSUSPEND;
6793
6794/**
6795 * Resume notification.
6796 *
6797 * @returns VBox status.
6798 * @param pSrvIns The service instance data.
6799 */
6800typedef DECLCALLBACK(void) FNPDMSRVRESUME(PPDMSRVINS pSrvIns);
6801/** Pointer to a FNPDMSRVRESUME() function. */
6802typedef FNPDMSRVRESUME *PFNPDMSRVRESUME;
6803
6804/**
6805 * Power Off notification.
6806 *
6807 * @param pSrvIns The service instance data.
6808 */
6809typedef DECLCALLBACK(void) FNPDMSRVPOWEROFF(PPDMSRVINS pSrvIns);
6810/** Pointer to a FNPDMSRVPOWEROFF() function. */
6811typedef FNPDMSRVPOWEROFF *PFNPDMSRVPOWEROFF;
6812
6813/**
6814 * Detach notification.
6815 *
6816 * This is called when a driver or device is detached from the service
6817 *
6818 * @param pSrvIns The service instance data.
6819 */
6820typedef DECLCALLBACK(void) FNPDMSRVDETACH(PPDMSRVINS pSrvIns, PPDMDEVINS pDevIns, PPDMDRVINS pDrvIns);
6821/** Pointer to a FNPDMSRVDETACH() function. */
6822typedef FNPDMSRVDETACH *PFNPDMSRVDETACH;
6823
6824
6825
6826/** PDM Service Registration Structure,
6827 * This structure is used when registering a driver from
6828 * VBoxServicesRegister() (HC Ring-3). PDM will continue use till
6829 * the VM is terminated.
6830 */
6831typedef struct PDMSRVREG
6832{
6833 /** Structure version. PDM_SRVREG_VERSION defines the current version. */
6834 uint32_t u32Version;
6835 /** Driver name. */
6836 char szServiceName[32];
6837 /** The description of the driver. The UTF-8 string pointed to shall, like this structure,
6838 * remain unchanged from registration till VM destruction. */
6839 const char *pszDescription;
6840
6841 /** Flags, combination of the PDM_SRVREG_FLAGS_* \#defines. */
6842 RTUINT fFlags;
6843 /** Size of the instance data. */
6844 RTUINT cbInstance;
6845
6846 /** Construct instance - required. */
6847 PFNPDMSRVCONSTRUCT pfnConstruct;
6848 /** Destruct instance - optional. */
6849 PFNPDMSRVDESTRUCT pfnDestruct;
6850 /** Power on notification - optional. */
6851 PFNPDMSRVPOWERON pfnPowerOn;
6852 /** Reset notification - optional. */
6853 PFNPDMSRVRESET pfnReset;
6854 /** Suspend notification - optional. */
6855 PFNPDMSRVSUSPEND pfnSuspend;
6856 /** Resume notification - optional. */
6857 PFNPDMSRVRESUME pfnResume;
6858 /** Detach notification - optional. */
6859 PFNPDMSRVDETACH pfnDetach;
6860 /** Power off notification - optional. */
6861 PFNPDMSRVPOWEROFF pfnPowerOff;
6862
6863} PDMSRVREG;
6864/** Pointer to a PDM Driver Structure. */
6865typedef PDMSRVREG *PPDMSRVREG;
6866/** Const pointer to a PDM Driver Structure. */
6867typedef PDMSRVREG const *PCPDMSRVREG;
6868
6869
6870
6871/**
6872 * PDM Service API.
6873 */
6874typedef struct PDMSRVHLP
6875{
6876 /** Structure version. PDM_SRVHLP_VERSION defines the current version. */
6877 uint32_t u32Version;
6878
6879 /**
6880 * Assert that the current thread is the emulation thread.
6881 *
6882 * @returns True if correct.
6883 * @returns False if wrong.
6884 * @param pSrvIns Service instance.
6885 * @param pszFile Filename of the assertion location.
6886 * @param iLine Linenumber of the assertion location.
6887 * @param pszFunction Function of the assertion location.
6888 */
6889 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMSRVINS pSrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
6890
6891 /**
6892 * Assert that the current thread is NOT the emulation thread.
6893 *
6894 * @returns True if correct.
6895 * @returns False if wrong.
6896 * @param pSrvIns Service instance.
6897 * @param pszFile Filename of the assertion location.
6898 * @param iLine Linenumber of the assertion location.
6899 * @param pszFunction Function of the assertion location.
6900 */
6901 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMSRVINS pSrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
6902
6903 /**
6904 * Creates a timer.
6905 *
6906 * @returns VBox status.
6907 * @param pVM The VM to create the timer in.
6908 * @param pSrvIns Service instance.
6909 * @param enmClock The clock to use on this timer.
6910 * @param pfnCallback Callback function.
6911 * @param pszDesc Pointer to description string which must stay around
6912 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
6913 * @param ppTimer Where to store the timer on success.
6914 */
6915 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMSRVINS pSrvIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer));
6916
6917 /**
6918 * Query the virtual timer frequency.
6919 *
6920 * @returns Frequency in Hz.
6921 * @param pSrvIns Service instance.
6922 * @thread Any thread.
6923 */
6924 DECLR3CALLBACKMEMBER(uint64_t, pfnTMGetVirtualFreq,(PPDMSRVINS pSrvIns));
6925
6926 /**
6927 * Query the virtual time.
6928 *
6929 * @returns The current virtual time.
6930 * @param pSrvIns Service instance.
6931 * @thread Any thread.
6932 */
6933 DECLR3CALLBACKMEMBER(uint64_t, pfnTMGetVirtualTime,(PPDMSRVINS pSrvIns));
6934
6935} PDMSRVHLP;
6936/** Pointer PDM Service API. */
6937typedef PDMSRVHLP *PPDMSRVHLP;
6938/** Pointer const PDM Service API. */
6939typedef const PDMSRVHLP *PCPDMSRVHLP;
6940
6941/** Current SRVHLP version number. */
6942#define PDM_SRVHLP_VERSION 0xf9010000
6943
6944
6945/**
6946 * PDM Service Instance.
6947 */
6948typedef struct PDMSRVINS
6949{
6950 /** Structure version. PDM_SRVINS_VERSION defines the current version. */
6951 uint32_t u32Version;
6952
6953 /** Internal data. */
6954 union
6955 {
6956#ifdef PDMSRVINSINT_DECLARED
6957 PDMSRVINSINT s;
6958#endif
6959 uint8_t padding[HC_ARCH_BITS == 32 ? 32 : 32];
6960 } Internal;
6961
6962 /** Pointer the PDM Service API. */
6963 HCPTRTYPE(PCPDMSRVHLP) pHlp;
6964 /** Pointer to driver registration structure. */
6965 HCPTRTYPE(PCPDMSRVREG) pReg;
6966 /** Configuration handle. */
6967 HCPTRTYPE(PCFGMNODE) pCfg;
6968 /** The base interface of the service.
6969 * The service constructor initializes this. */
6970 PDMIBASE IBase;
6971 /* padding to make achInstanceData aligned at 16 byte boundrary. */
6972 uint32_t au32Padding[2];
6973 /** Pointer to driver instance data. */
6974 HCPTRTYPE(void *) pvInstanceData;
6975 /** Driver instance data. The size of this area is defined
6976 * in the PDMSRVREG::cbInstanceData field. */
6977 char achInstanceData[4];
6978} PDMSRVINS;
6979
6980/** Current PDMSRVREG version number. */
6981#define PDM_SRVINS_VERSION 0xf7010000
6982
6983/** Converts a pointer to the PDMSRVINS::IBase to a pointer to PDMSRVINS. */
6984#define PDMIBASE_2_PDMSRV(pInterface) ( (PPDMSRVINS)((char *)(pInterface) - RT_OFFSETOF(PDMSRVINS, IBase)) )
6985
6986
6987
6988/** Pointer to callbacks provided to the VBoxServiceRegister() call. */
6989typedef struct PDMSRVREGCB *PPDMSRVREGCB;
6990
6991/**
6992 * Callbacks for VBoxServiceRegister().
6993 */
6994typedef struct PDMSRVREGCB
6995{
6996 /** Interface version.
6997 * This is set to PDM_SRVREG_CB_VERSION. */
6998 uint32_t u32Version;
6999
7000 /**
7001 * Registers a service with the current VM instance.
7002 *
7003 * @returns VBox status code.
7004 * @param pCallbacks Pointer to the callback table.
7005 * @param pSrvReg Pointer to the device registration record.
7006 * This data must be permanent and readonly.
7007 */
7008 DECLR3CALLBACKMEMBER(int, pfnRegister,(PPDMSRVREGCB pCallbacks, PCPDMSRVREG pSrvReg));
7009} PDMSRVREGCB;
7010
7011/** Current version of the PDMSRVREGCB structure. */
7012#define PDM_SRVREG_CB_VERSION 0xf8010000
7013
7014
7015/**
7016 * The VBoxServicesRegister callback function.
7017 *
7018 * PDM will invoke this function after loading a device module and letting
7019 * the module decide which devices to register and how to handle conflicts.
7020 *
7021 * @returns VBox status code.
7022 * @param pCallbacks Pointer to the callback table.
7023 * @param u32Version VBox version number.
7024 */
7025typedef DECLCALLBACK(int) FNPDMVBOXSERVICESREGISTER(PPDMSRVREGCB pCallbacks, uint32_t u32Version);
7026
7027
7028/** @} */
7029
7030/**
7031 * Gets the pending interrupt.
7032 *
7033 * @returns VBox status code.
7034 * @param pVM VM handle.
7035 * @param pu8Interrupt Where to store the interrupt on success.
7036 */
7037PDMDECL(int) PDMGetInterrupt(PVM pVM, uint8_t *pu8Interrupt);
7038
7039/**
7040 * Sets the pending ISA interrupt.
7041 *
7042 * @returns VBox status code.
7043 * @param pVM VM handle.
7044 * @param u8Irq The IRQ line.
7045 * @param u8Level The new level. See the PDM_IRQ_LEVEL_* \#defines.
7046 */
7047PDMDECL(int) PDMIsaSetIrq(PVM pVM, uint8_t u8Irq, uint8_t u8Level);
7048
7049/**
7050 * Sets the pending I/O APIC interrupt.
7051 *
7052 * @returns VBox status code.
7053 * @param pVM VM handle.
7054 * @param u8Irq The IRQ line.
7055 * @param u8Level The new level. See the PDM_IRQ_LEVEL_* \#defines.
7056 */
7057PDMDECL(int) PDMIoApicSetIrq(PVM pVM, uint8_t u8Irq, uint8_t u8Level);
7058
7059/**
7060 * Set the APIC base.
7061 *
7062 * @returns VBox status code.
7063 * @param pVM VM handle.
7064 * @param u64Base The new base.
7065 */
7066PDMDECL(int) PDMApicSetBase(PVM pVM, uint64_t u64Base);
7067
7068/**
7069 * Get the APIC base.
7070 *
7071 * @returns VBox status code.
7072 * @param pVM VM handle.
7073 * @param pu64Base Where to store the APIC base.
7074 */
7075PDMDECL(int) PDMApicGetBase(PVM pVM, uint64_t *pu64Base);
7076
7077/**
7078 * Set the TPR (task priority register?).
7079 *
7080 * @returns VBox status code.
7081 * @param pVM VM handle.
7082 * @param u8TPR The new TPR.
7083 */
7084PDMDECL(int) PDMApicSetTPR(PVM pVM, uint8_t u8TPR);
7085
7086/**
7087 * Get the TPR (task priority register?).
7088 *
7089 * @returns The current TPR.
7090 * @param pVM VM handle.
7091 * @param pu8TPR Where to store the TRP.
7092 */
7093PDMDECL(int) PDMApicGetTPR(PVM pVM, uint8_t *pu8TPR);
7094
7095
7096#ifdef IN_RING3
7097/** @defgroup grp_pdm_r3 The PDM Host Context Ring-3 API
7098 * @ingroup grp_pdm
7099 * @{
7100 */
7101
7102/**
7103 * Initializes the PDM.
7104 *
7105 * @returns VBox status code.
7106 * @param pVM The VM to operate on.
7107 */
7108PDMR3DECL(int) PDMR3Init(PVM pVM);
7109
7110/**
7111 * This function will notify all the devices and their
7112 * attached drivers about the VM now being powered on.
7113 *
7114 * @param pVM VM Handle.
7115 */
7116PDMR3DECL(void) PDMR3PowerOn(PVM pVM);
7117
7118/**
7119 * This function will notify all the devices and their
7120 * attached drivers about the VM now being reset.
7121 *
7122 * @param pVM VM Handle.
7123 */
7124PDMR3DECL(void) PDMR3Reset(PVM pVM);
7125
7126/**
7127 * This function will notify all the devices and their
7128 * attached drivers about the VM now being suspended.
7129 *
7130 * @param pVM VM Handle.
7131 */
7132PDMR3DECL(void) PDMR3Suspend(PVM pVM);
7133
7134/**
7135 * This function will notify all the devices and their
7136 * attached drivers about the VM now being resumed.
7137 *
7138 * @param pVM VM Handle.
7139 */
7140PDMR3DECL(void) PDMR3Resume(PVM pVM);
7141
7142/**
7143 * This function will notify all the devices and their
7144 * attached drivers about the VM being powered off.
7145 *
7146 * @param pVM VM Handle.
7147 */
7148PDMR3DECL(void) PDMR3PowerOff(PVM pVM);
7149
7150
7151/**
7152 * Applies relocations to GC modules.
7153 *
7154 * This must be done very early in the relocation
7155 * process so that components can resolve GC symbols during relocation.
7156 *
7157 * @param pVM VM handle.
7158 * @param offDelta Relocation delta relative to old location.
7159 */
7160PDMR3DECL(void) PDMR3LdrRelocate(PVM pVM, RTGCINTPTR offDelta);
7161
7162/**
7163 * Applies relocations to data and code managed by this
7164 * component. This function will be called at init and
7165 * whenever the VMM need to relocate it self inside the GC.
7166 *
7167 * @param pVM VM handle.
7168 * @param offDelta Relocation delta relative to old location.
7169 */
7170PDMR3DECL(void) PDMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
7171
7172/**
7173 * Terminates the PDM.
7174 *
7175 * Termination means cleaning up and freeing all resources,
7176 * the VM it self is at this point powered off or suspended.
7177 *
7178 * @returns VBox status code.
7179 * @param pVM The VM to operate on.
7180 */
7181PDMR3DECL(int) PDMR3Term(PVM pVM);
7182
7183
7184/**
7185 * Get the address of a symbol in a given HC ring-3 module.
7186 *
7187 * @returns VBox status code.
7188 * @param pVM VM handle.
7189 * @param pszModule Module name.
7190 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
7191 * ordinal value rather than a string pointer.
7192 * @param ppvValue Where to store the symbol value.
7193 */
7194PDMR3DECL(int) PDMR3GetSymbolR3(PVM pVM, const char *pszModule, const char *pszSymbol, void **ppvValue);
7195
7196/**
7197 * Get the address of a symbol in a given HC ring-0 module.
7198 *
7199 * @returns VBox status code.
7200 * @param pVM VM handle.
7201 * @param pszModule Module name. If NULL the main R0 module (VMMR0.r0) is assumed.
7202 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
7203 * ordinal value rather than a string pointer.
7204 * @param ppvValue Where to store the symbol value.
7205 */
7206PDMR3DECL(int) PDMR3GetSymbolR0(PVM pVM, const char *pszModule, const char *pszSymbol, PRTR0PTR ppvValue);
7207
7208/**
7209 * Same as PDMR3GetSymbolR0 except that the module will be attempted loaded if not found.
7210 *
7211 * @returns VBox status code.
7212 * @param pVM VM handle.
7213 * @param pszModule Module name. If NULL the main R0 module (VMMR0.r0) is assumed.
7214 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
7215 * ordinal value rather than a string pointer.
7216 * @param ppvValue Where to store the symbol value.
7217 */
7218PDMR3DECL(int) PDMR3GetSymbolR0Lazy(PVM pVM, const char *pszModule, const char *pszSymbol, PRTR0PTR ppvValue);
7219
7220/**
7221 * Loads a module into the guest context (i.e. into the Hypervisor memory region).
7222 *
7223 * The external (to PDM) use of this interface is to load VMMGC.gc.
7224 *
7225 * @returns VBox status code.
7226 * @param pVM The VM to load it into.
7227 * @param pszFilename Filename of the module binary.
7228 * @param pszName Module name. Case sensitive and the length is limited!
7229 */
7230PDMR3DECL(int) PDMR3LoadGC(PVM pVM, const char *pszFilename, const char *pszName);
7231
7232/**
7233 * Get the address of a symbol in a given GC module.
7234 *
7235 * @returns VBox status code.
7236 * @param pVM VM handle.
7237 * @param pszModule Module name. If NULL the main GC module (VMMGC.gc) is assumed.
7238 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
7239 * ordinal value rather than a string pointer.
7240 * @param pGCPtrValue Where to store the symbol value.
7241 */
7242PDMR3DECL(int) PDMR3GetSymbolGC(PVM pVM, const char *pszModule, const char *pszSymbol, PRTGCPTR pGCPtrValue);
7243
7244/**
7245 * Same as PDMR3GetSymbolGC except that the module will be attempted loaded if not found.
7246 *
7247 * @returns VBox status code.
7248 * @param pVM VM handle.
7249 * @param pszModule Module name. If NULL the main GC module (VMMGC.gc) is assumed.
7250 * @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
7251 * ordinal value rather than a string pointer.
7252 * @param pGCPtrValue Where to store the symbol value.
7253 */
7254PDMR3DECL(int) PDMR3GetSymbolGCLazy(PVM pVM, const char *pszModule, const char *pszSymbol, PRTGCPTR pGCPtrValue);
7255
7256/**
7257 * Queries module information from an EIP.
7258 *
7259 * This is typically used to locate a crash address.
7260 *
7261 * @returns VBox status code.
7262 * @param pVM VM handle
7263 * @param uEIP EIP to locate.
7264 * @param pszModName Where to store the module name.
7265 * @param cchModName Size of the module name buffer.
7266 * @param pMod Base address of the module.
7267 * @param pszNearSym1 Name of the closes symbol from below.
7268 * @param cchNearSym1 Size of the buffer pointed to by pszNearSym1.
7269 * @param pNearSym1 The address of pszNearSym1.
7270 * @param pszNearSym2 Name of the closes symbol from below.
7271 * @param cchNearSym2 Size of the buffer pointed to by pszNearSym2.
7272 * @param pNearSym2 The address of pszNearSym2.
7273 */
7274PDMR3DECL(int) PDMR3QueryModFromEIP(PVM pVM, uint32_t uEIP,
7275 char *pszModName, unsigned cchModName, RTGCPTR *pMod,
7276 char *pszNearSym1, unsigned cchNearSym1, RTGCPTR *pNearSym1,
7277 char *pszNearSym2, unsigned cchNearSym2, RTGCPTR *pNearSym2);
7278
7279
7280/**
7281 * Module enumeration callback function.
7282 *
7283 * @returns VBox status.
7284 * Failure will stop the search and return the return code.
7285 * Warnings will be ignored and not returned.
7286 * @param pVM VM Handle.
7287 * @param pszFilename Module filename.
7288 * @param pszName Module name. (short and unique)
7289 * @param ImageBase Address where to executable image is loaded.
7290 * @param cbImage Size of the executable image.
7291 * @param fGC Set if guest context, clear if host context.
7292 * @param pvArg User argument.
7293 */
7294typedef DECLCALLBACK(int) FNPDMR3ENUM(PVM pVM, const char *pszFilename, const char *pszName, RTUINTPTR ImageBase, size_t cbImage, bool fGC);
7295/** Pointer to a FNPDMR3ENUM() function. */
7296typedef FNPDMR3ENUM *PFNPDMR3ENUM;
7297
7298
7299/**
7300 * Enumerate all PDM modules.
7301 *
7302 * @returns VBox status.
7303 * @param pVM VM Handle.
7304 * @param pfnCallback Function to call back for each of the modules.
7305 * @param pvArg User argument.
7306 */
7307PDMR3DECL(int) PDMR3EnumModules(PVM pVM, PFNPDMR3ENUM pfnCallback, void *pvArg);
7308
7309
7310/**
7311 * Queries the base interace of a device instance.
7312 *
7313 * The caller can use this to query other interfaces the device implements
7314 * and use them to talk to the device.
7315 *
7316 * @returns VBox status code.
7317 * @param pVM VM handle.
7318 * @param pszDevice Device name.
7319 * @param iInstance Device instance.
7320 * @param ppBase Where to store the pointer to the base device interface on success.
7321 * @remark We're doing any locking ATM, so don't try call this at times when the
7322 * device chain is known to be updated.
7323 */
7324PDMR3DECL(int) PDMR3QueryDevice(PVM pVM, const char *pszDevice, unsigned iInstance, PPDMIBASE *ppBase);
7325
7326/**
7327 * Queries the base interface of a device LUN.
7328 *
7329 * This differs from PDMR3QueryLun by that it returns the interface on the
7330 * device and not the top level driver.
7331 *
7332 * @returns VBox status code.
7333 * @param pVM VM Handle.
7334 * @param pszDevice Device name.
7335 * @param iInstance Device instance.
7336 * @param iLun The Logical Unit to obtain the interface of.
7337 * @param ppBase Where to store the base interface pointer.
7338 * @remark We're doing any locking ATM, so don't try call this at times when the
7339 * device chain is known to be updated.
7340 */
7341PDMR3DECL(int) PDMR3QueryDeviceLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase);
7342
7343/**
7344 * Query the interface of the top level driver on a LUN.
7345 *
7346 * @returns VBox status code.
7347 * @param pVM VM Handle.
7348 * @param pszDevice Device name.
7349 * @param iInstance Device instance.
7350 * @param iLun The Logical Unit to obtain the interface of.
7351 * @param ppBase Where to store the base interface pointer.
7352 * @remark We're doing any locking ATM, so don't try call this at times when the
7353 * device chain is known to be updated.
7354 */
7355PDMR3DECL(int) PDMR3QueryLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase);
7356
7357/**
7358 * Attaches a preconfigured driver to an existing device instance.
7359 *
7360 * This is used to change drivers and suchlike at runtime.
7361 *
7362 * @returns VBox status code.
7363 * @param pVM VM Handle.
7364 * @param pszDevice Device name.
7365 * @param iInstance Device instance.
7366 * @param iLun The Logical Unit to obtain the interface of.
7367 * @param ppBase Where to store the base interface pointer. Optional.
7368 * @thread EMT
7369 */
7370PDMR3DECL(int) PDMR3DeviceAttach(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase);
7371
7372/**
7373 * Detaches a driver from an existing device instance.
7374 *
7375 * This is used to change drivers and suchlike at runtime.
7376 *
7377 * @returns VBox status code.
7378 * @param pVM VM Handle.
7379 * @param pszDevice Device name.
7380 * @param iInstance Device instance.
7381 * @param iLun The Logical Unit to obtain the interface of.
7382 * @thread EMT
7383 */
7384PDMR3DECL(int) PDMR3DeviceDetach(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun);
7385
7386/**
7387 * Executes pending DMA transfers.
7388 * Forced Action handler.
7389 *
7390 * @param pVM VM handle.
7391 */
7392PDMR3DECL(void) PDMR3DmaRun(PVM pVM);
7393
7394/**
7395 * Call polling function.
7396 *
7397 * @param pVM VM handle.
7398 */
7399PDMR3DECL(void) PDMR3Poll(PVM pVM);
7400
7401/**
7402 * Service a VMMCALLHOST_PDM_LOCK call.
7403 *
7404 * @returns VBox status code.
7405 * @param pVM The VM handle.
7406 */
7407PDMR3DECL(int) PDMR3LockCall(PVM pVM);
7408
7409/** @} */
7410#endif
7411
7412
7413#ifdef IN_GC
7414/** @defgroup grp_pdm_gc The PDM Guest Context API
7415 * @ingroup grp_pdm
7416 * @{
7417 */
7418/** @} */
7419#endif
7420
7421__END_DECLS
7422
7423/** @} */
7424
7425#endif
7426
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette