VirtualBox

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

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

New device helper PCISetConfigCallbacks. (patch from R. Zeljko)

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