1 | /* $Id: VBoxGuestInternal.h 27967 2010-04-02 20:05:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuest - Guest Additions Driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ___VBoxGuestInternal_h
|
---|
23 | #define ___VBoxGuestInternal_h
|
---|
24 |
|
---|
25 | #include <iprt/types.h>
|
---|
26 | #include <iprt/semaphore.h>
|
---|
27 | #include <iprt/spinlock.h>
|
---|
28 | #include <VBox/VMMDev.h>
|
---|
29 | #include <VBox/VBoxGuest.h>
|
---|
30 | #include <VBox/VBoxGuestLib.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | /** Pointer to the VBoxGuest per session data. */
|
---|
34 | typedef struct VBOXGUESTSESSION *PVBOXGUESTSESSION;
|
---|
35 |
|
---|
36 | /** Pointer to a wait-for-event entry. */
|
---|
37 | typedef struct VBOXGUESTWAIT *PVBOXGUESTWAIT;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * VBox guest wait for event entry.
|
---|
41 | *
|
---|
42 | * Each waiting thread allocates one of these items and adds
|
---|
43 | * it to the wait list before going to sleep on the event sem.
|
---|
44 | */
|
---|
45 | typedef struct VBOXGUESTWAIT
|
---|
46 | {
|
---|
47 | /** The next entry in the list. */
|
---|
48 | PVBOXGUESTWAIT volatile pNext;
|
---|
49 | /** The previous entry in the list. */
|
---|
50 | PVBOXGUESTWAIT volatile pPrev;
|
---|
51 | /** The event semaphore. */
|
---|
52 | RTSEMEVENTMULTI Event;
|
---|
53 | /** The events we are waiting on. */
|
---|
54 | uint32_t fReqEvents;
|
---|
55 | /** The events we received. */
|
---|
56 | uint32_t volatile fResEvents;
|
---|
57 | /** The session that's waiting. */
|
---|
58 | PVBOXGUESTSESSION pSession;
|
---|
59 | #ifdef VBOX_WITH_HGCM
|
---|
60 | /** The HGCM request we're waiting for to complete. */
|
---|
61 | VMMDevHGCMRequestHeader volatile *pHGCMReq;
|
---|
62 | #endif
|
---|
63 | } VBOXGUESTWAIT;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * VBox guest wait for event list.
|
---|
67 | */
|
---|
68 | typedef struct VBOXGUESTWAITLIST
|
---|
69 | {
|
---|
70 | /** The head. */
|
---|
71 | PVBOXGUESTWAIT volatile pHead;
|
---|
72 | /** The tail. */
|
---|
73 | PVBOXGUESTWAIT volatile pTail;
|
---|
74 | } VBOXGUESTWAITLIST;
|
---|
75 | /** Pointer to a wait list. */
|
---|
76 | typedef VBOXGUESTWAITLIST *PVBOXGUESTWAITLIST;
|
---|
77 |
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * VBox guest memory balloon.
|
---|
81 | */
|
---|
82 | typedef struct VBOXGUESTMEMBALLOON
|
---|
83 | {
|
---|
84 | /** Mutext protecting the members below from concurrent access.. */
|
---|
85 | RTSEMFASTMUTEX hMtx;
|
---|
86 | /** The current number of chunks in the balloon. */
|
---|
87 | uint32_t cChunks;
|
---|
88 | /** The maximum number of chunks in the balloon (typically the amount of guest
|
---|
89 | * memory / chunksize). */
|
---|
90 | uint32_t cMaxChunks;
|
---|
91 | /** This is true if we are using RTR0MemObjAllocPhysNC() / RTR0MemObjGetPagePhysAddr()
|
---|
92 | * and false otherwise. */
|
---|
93 | bool fUseKernelAPI;
|
---|
94 | /** The current owner of the balloon.
|
---|
95 | * This is automatically assigned to the first session using the ballooning
|
---|
96 | * API and first released when the session closes. */
|
---|
97 | PVBOXGUESTSESSION pOwner;
|
---|
98 | /** The pointer to the array of memory objects holding the chunks of the
|
---|
99 | * balloon. This array is cMaxChunks in size when present. */
|
---|
100 | PRTR0MEMOBJ paMemObj;
|
---|
101 | } VBOXGUESTMEMBALLOON;
|
---|
102 | /** Pointer to a memory balloon. */
|
---|
103 | typedef VBOXGUESTMEMBALLOON *PVBOXGUESTMEMBALLOON;
|
---|
104 |
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * VBox guest device (data) extension.
|
---|
108 | */
|
---|
109 | typedef struct VBOXGUESTDEVEXT
|
---|
110 | {
|
---|
111 | /** The base of the adapter I/O ports. */
|
---|
112 | RTIOPORT IOPortBase;
|
---|
113 | /** Pointer to the mapping of the VMMDev adapter memory. */
|
---|
114 | VMMDevMemory volatile *pVMMDevMemory;
|
---|
115 | /** Events we won't permit anyone to filter out. */
|
---|
116 | uint32_t fFixedEvents;
|
---|
117 | /** The memory object reserving space for the guest mappings. */
|
---|
118 | RTR0MEMOBJ hGuestMappings;
|
---|
119 |
|
---|
120 | /** Spinlock protecting the signaling and resetting of the wait-for-event
|
---|
121 | * semaphores as well as the event acking in the ISR. */
|
---|
122 | RTSPINLOCK EventSpinlock;
|
---|
123 | /** Preallocated VMMDevEvents for the IRQ handler. */
|
---|
124 | VMMDevEvents *pIrqAckEvents;
|
---|
125 | /** The physical address of pIrqAckEvents. */
|
---|
126 | RTCCPHYS PhysIrqAckEvents;
|
---|
127 | /** Wait-for-event list for threads waiting for multiple events. */
|
---|
128 | VBOXGUESTWAITLIST WaitList;
|
---|
129 | #ifdef VBOX_WITH_HGCM
|
---|
130 | /** Wait-for-event list for threads waiting on HGCM async completion.
|
---|
131 | * The entire list is evaluated upon the arrival of an HGCM event, unlike
|
---|
132 | * the other lists which are only evaluated till the first thread has been woken up. */
|
---|
133 | VBOXGUESTWAITLIST HGCMWaitList;
|
---|
134 | #endif
|
---|
135 | /** List of free wait-for-event entries. */
|
---|
136 | VBOXGUESTWAITLIST FreeList;
|
---|
137 | /** Mask of pending events. */
|
---|
138 | uint32_t volatile f32PendingEvents;
|
---|
139 | /** Current VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
|
---|
140 | * Used to implement polling. */
|
---|
141 | uint32_t volatile u32MousePosChangedSeq;
|
---|
142 |
|
---|
143 | /** Spinlock various items in the VBOXGUESTSESSION. */
|
---|
144 | RTSPINLOCK SessionSpinlock;
|
---|
145 |
|
---|
146 | /** The current clipboard client ID, 0 if no client.
|
---|
147 | * For implementing the VBOXGUEST_IOCTL_CLIPBOARD_CONNECT interface. */
|
---|
148 | uint32_t u32ClipboardClientId;
|
---|
149 |
|
---|
150 | /** Memory balloon information for RTR0MemObjAllocPhysNC(). */
|
---|
151 | VBOXGUESTMEMBALLOON MemBalloon;
|
---|
152 |
|
---|
153 | } VBOXGUESTDEVEXT;
|
---|
154 | /** Pointer to the VBoxGuest driver data. */
|
---|
155 | typedef VBOXGUESTDEVEXT *PVBOXGUESTDEVEXT;
|
---|
156 |
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * The VBoxGuest per session data.
|
---|
160 | *
|
---|
161 | * @remark Not quite sure whether this will be useful or not, but since
|
---|
162 | * its already there let's keep it for now in case it might come
|
---|
163 | * in handy later.
|
---|
164 | */
|
---|
165 | typedef struct VBOXGUESTSESSION
|
---|
166 | {
|
---|
167 | #if defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
|
---|
168 | /** Pointer to the next session with the same hash. */
|
---|
169 | PVBOXGUESTSESSION pNextHash;
|
---|
170 | #endif
|
---|
171 | #if defined(RT_OS_OS2)
|
---|
172 | /** The system file number of this session. */
|
---|
173 | uint16_t sfn;
|
---|
174 | uint16_t Alignment; /**< Alignment */
|
---|
175 | #endif
|
---|
176 | /** The process (id) of the session.
|
---|
177 | * This is NIL if it's a kernel session. */
|
---|
178 | RTPROCESS Process;
|
---|
179 | /** Which process this session is associated with.
|
---|
180 | * This is NIL if it's a kernel session. */
|
---|
181 | RTR0PROCESS R0Process;
|
---|
182 | /** Pointer to the device extension. */
|
---|
183 | PVBOXGUESTDEVEXT pDevExt;
|
---|
184 |
|
---|
185 | #ifdef VBOX_WITH_HGCM
|
---|
186 | /** Array containing HGCM client IDs associated with this session.
|
---|
187 | * This will be automatically disconnected when the session is closed. */
|
---|
188 | uint32_t volatile aHGCMClientIds[8];
|
---|
189 | #endif
|
---|
190 | /** The last consumed VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
|
---|
191 | * Used to implement polling. */
|
---|
192 | uint32_t volatile u32MousePosChangedSeq;
|
---|
193 |
|
---|
194 | } VBOXGUESTSESSION;
|
---|
195 |
|
---|
196 | RT_C_DECLS_BEGIN
|
---|
197 |
|
---|
198 | int VBoxGuestInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase, void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fEvents);
|
---|
199 | void VBoxGuestDeleteDevExt(PVBOXGUESTDEVEXT pDevExt);
|
---|
200 | bool VBoxGuestCommonISR(PVBOXGUESTDEVEXT pDevExt);
|
---|
201 | int VBoxGuestSetGuestCapabilities(uint32_t fOr, uint32_t fNot);
|
---|
202 |
|
---|
203 | int VBoxGuestCreateUserSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
|
---|
204 | int VBoxGuestCreateKernelSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
|
---|
205 | void VBoxGuestCloseSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
|
---|
206 |
|
---|
207 | int VBoxGuestCommonIOCtlFast(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
|
---|
208 | int VBoxGuestCommonIOCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession,
|
---|
209 | void *pvData, size_t cbData, size_t *pcbDataReturned);
|
---|
210 |
|
---|
211 | #if defined(RT_OS_SOLARIS) \
|
---|
212 | || defined(RT_OS_FREEBSD) \
|
---|
213 | || defined(RT_OS_LINUX)
|
---|
214 | DECLVBGL(void *) VBoxGuestNativeServiceOpen(uint32_t *pu32Version);
|
---|
215 | DECLVBGL(void) VBoxGuestNativeServiceClose(void *pvOpaque);
|
---|
216 | DECLVBGL(int) VBoxGuestNativeServiceCall(void *pvOpaque, unsigned int iCmd, void *pvData, size_t cbSize, size_t *pcbReturn);
|
---|
217 | #endif
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * ISR callback for notifying threads polling for mouse events.
|
---|
221 | *
|
---|
222 | * This is called at the end of the ISR, after leaving the event spinlock, if
|
---|
223 | * VMMDEV_EVENT_MOUSE_POSITION_CHANGED was raised by the host.
|
---|
224 | *
|
---|
225 | * @param pDevExt The device extension.
|
---|
226 | */
|
---|
227 | void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt);
|
---|
228 |
|
---|
229 | RT_C_DECLS_END
|
---|
230 |
|
---|
231 | #endif
|
---|
232 |
|
---|