1 | /* $Id: VBoxGuestInternal.h 44992 2013-03-11 15:41:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuest - Guest Additions Driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2012 Oracle Corporation
|
---|
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 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef ___VBoxGuestInternal_h
|
---|
28 | #define ___VBoxGuestInternal_h
|
---|
29 |
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/list.h>
|
---|
32 | #include <iprt/semaphore.h>
|
---|
33 | #include <iprt/spinlock.h>
|
---|
34 | #include <VBox/VMMDev.h>
|
---|
35 | #include <VBox/VBoxGuest.h>
|
---|
36 | #include <VBox/VBoxGuestLib.h>
|
---|
37 |
|
---|
38 | /** @def VBOXGUEST_USE_WAKE_UP_LIST
|
---|
39 | * Defer wake-up of waiting thread when defined. */
|
---|
40 | #if defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
|
---|
41 | # define VBOXGUEST_USE_DEFERRED_WAKE_UP
|
---|
42 | #endif
|
---|
43 |
|
---|
44 |
|
---|
45 | /** Pointer to the VBoxGuest per session data. */
|
---|
46 | typedef struct VBOXGUESTSESSION *PVBOXGUESTSESSION;
|
---|
47 |
|
---|
48 | /** Pointer to a wait-for-event entry. */
|
---|
49 | typedef struct VBOXGUESTWAIT *PVBOXGUESTWAIT;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * VBox guest wait for event entry.
|
---|
53 | *
|
---|
54 | * Each waiting thread allocates one of these items and adds
|
---|
55 | * it to the wait list before going to sleep on the event sem.
|
---|
56 | */
|
---|
57 | typedef struct VBOXGUESTWAIT
|
---|
58 | {
|
---|
59 | /** The list node. */
|
---|
60 | RTLISTNODE ListNode;
|
---|
61 | /** The events we are waiting on. */
|
---|
62 | uint32_t fReqEvents;
|
---|
63 | /** The events we received. */
|
---|
64 | uint32_t volatile fResEvents;
|
---|
65 | #ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
|
---|
66 | /** Set by VBoxGuestWaitDoWakeUps before leaving the spinlock to call
|
---|
67 | * RTSemEventMultiSignal. */
|
---|
68 | bool volatile fPendingWakeUp;
|
---|
69 | /** Set by the requestor thread if it got the spinlock before the
|
---|
70 | * signaller. Deals with the race in VBoxGuestWaitDoWakeUps. */
|
---|
71 | bool volatile fFreeMe;
|
---|
72 | #endif
|
---|
73 | /** The event semaphore. */
|
---|
74 | RTSEMEVENTMULTI Event;
|
---|
75 | /** The session that's waiting. */
|
---|
76 | PVBOXGUESTSESSION pSession;
|
---|
77 | #ifdef VBOX_WITH_HGCM
|
---|
78 | /** The HGCM request we're waiting for to complete. */
|
---|
79 | VMMDevHGCMRequestHeader volatile *pHGCMReq;
|
---|
80 | #endif
|
---|
81 | } VBOXGUESTWAIT;
|
---|
82 |
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * VBox guest memory balloon.
|
---|
86 | */
|
---|
87 | typedef struct VBOXGUESTMEMBALLOON
|
---|
88 | {
|
---|
89 | /** Mutex protecting the members below from concurrent access.. */
|
---|
90 | RTSEMFASTMUTEX hMtx;
|
---|
91 | /** The current number of chunks in the balloon. */
|
---|
92 | uint32_t cChunks;
|
---|
93 | /** The maximum number of chunks in the balloon (typically the amount of guest
|
---|
94 | * memory / chunksize). */
|
---|
95 | uint32_t cMaxChunks;
|
---|
96 | /** This is true if we are using RTR0MemObjAllocPhysNC() / RTR0MemObjGetPagePhysAddr()
|
---|
97 | * and false otherwise. */
|
---|
98 | bool fUseKernelAPI;
|
---|
99 | /** The current owner of the balloon.
|
---|
100 | * This is automatically assigned to the first session using the ballooning
|
---|
101 | * API and first released when the session closes. */
|
---|
102 | PVBOXGUESTSESSION pOwner;
|
---|
103 | /** The pointer to the array of memory objects holding the chunks of the
|
---|
104 | * balloon. This array is cMaxChunks in size when present. */
|
---|
105 | PRTR0MEMOBJ paMemObj;
|
---|
106 | } VBOXGUESTMEMBALLOON;
|
---|
107 | /** Pointer to a memory balloon. */
|
---|
108 | typedef VBOXGUESTMEMBALLOON *PVBOXGUESTMEMBALLOON;
|
---|
109 |
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * VBox guest device (data) extension.
|
---|
113 | */
|
---|
114 | typedef struct VBOXGUESTDEVEXT
|
---|
115 | {
|
---|
116 | /** The base of the adapter I/O ports. */
|
---|
117 | RTIOPORT IOPortBase;
|
---|
118 | /** Pointer to the mapping of the VMMDev adapter memory. */
|
---|
119 | VMMDevMemory volatile *pVMMDevMemory;
|
---|
120 | /** Events we won't permit anyone to filter out. */
|
---|
121 | uint32_t fFixedEvents;
|
---|
122 | /** The memory object reserving space for the guest mappings. */
|
---|
123 | RTR0MEMOBJ hGuestMappings;
|
---|
124 | /** Spinlock protecting the signaling and resetting of the wait-for-event
|
---|
125 | * semaphores as well as the event acking in the ISR. */
|
---|
126 | RTSPINLOCK EventSpinlock;
|
---|
127 | /** Preallocated VMMDevEvents for the IRQ handler. */
|
---|
128 | VMMDevEvents *pIrqAckEvents;
|
---|
129 | /** The physical address of pIrqAckEvents. */
|
---|
130 | RTCCPHYS PhysIrqAckEvents;
|
---|
131 | /** Wait-for-event list for threads waiting for multiple events
|
---|
132 | * (VBOXGUESTWAIT). */
|
---|
133 | RTLISTANCHOR WaitList;
|
---|
134 | #ifdef VBOX_WITH_HGCM
|
---|
135 | /** Wait-for-event list for threads waiting on HGCM async completion
|
---|
136 | * (VBOXGUESTWAIT).
|
---|
137 | *
|
---|
138 | * The entire list is evaluated upon the arrival of an HGCM event, unlike
|
---|
139 | * the other lists which are only evaluated till the first thread has
|
---|
140 | * been woken up. */
|
---|
141 | RTLISTANCHOR HGCMWaitList;
|
---|
142 | #endif
|
---|
143 | #ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
|
---|
144 | /** List of wait-for-event entries that needs waking up
|
---|
145 | * (VBOXGUESTWAIT). */
|
---|
146 | RTLISTANCHOR WakeUpList;
|
---|
147 | #endif
|
---|
148 | /** List of wait-for-event entries that has been woken up
|
---|
149 | * (VBOXGUESTWAIT). */
|
---|
150 | RTLISTANCHOR WokenUpList;
|
---|
151 | /** List of free wait-for-event entries (VBOXGUESTWAIT). */
|
---|
152 | RTLISTANCHOR FreeList;
|
---|
153 | /** Mask of pending events. */
|
---|
154 | uint32_t volatile f32PendingEvents;
|
---|
155 | /** Current VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
|
---|
156 | * Used to implement polling. */
|
---|
157 | uint32_t volatile u32MousePosChangedSeq;
|
---|
158 |
|
---|
159 | /** Spinlock various items in the VBOXGUESTSESSION. */
|
---|
160 | RTSPINLOCK SessionSpinlock;
|
---|
161 | #ifdef VBOX_WITH_VRDP_SESSION_HANDLING
|
---|
162 | bool fVRDPEnabled;
|
---|
163 | #endif
|
---|
164 | /** Flag indicating whether logging to the release log
|
---|
165 | * is enabled. */
|
---|
166 | bool fLoggingEnabled;
|
---|
167 | /** Memory balloon information for RTR0MemObjAllocPhysNC(). */
|
---|
168 | VBOXGUESTMEMBALLOON MemBalloon;
|
---|
169 | /** For each mouse status feature the number of sessions which have
|
---|
170 | * enabled it. A feature is enabled globally if at least one session has
|
---|
171 | * requested it. */
|
---|
172 | /** @todo can we programmatically determine the size of the array and
|
---|
173 | * still get the following alignment right? */
|
---|
174 | uint32_t volatile acMouseFeatureUsage[32];
|
---|
175 | /** The mouse feature status matching the counts above. These are updated
|
---|
176 | * together inside the session spinlock. */
|
---|
177 | uint32_t volatile fMouseStatus;
|
---|
178 | /** Counter of number of active ISRs. Currently used for safely removing
|
---|
179 | * the mouse handler callback. */
|
---|
180 | uint32_t volatile cISR;
|
---|
181 | /** Callback and user data for a kernel mouse handler. */
|
---|
182 | VBoxGuestMouseSetNotifyCallback MouseNotifyCallback;
|
---|
183 | } VBOXGUESTDEVEXT;
|
---|
184 | /** Pointer to the VBoxGuest driver data. */
|
---|
185 | typedef VBOXGUESTDEVEXT *PVBOXGUESTDEVEXT;
|
---|
186 |
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * The VBoxGuest per session data.
|
---|
190 | *
|
---|
191 | * @remark Not quite sure whether this will be useful or not, but since
|
---|
192 | * its already there let's keep it for now in case it might come
|
---|
193 | * in handy later.
|
---|
194 | */
|
---|
195 | typedef struct VBOXGUESTSESSION
|
---|
196 | {
|
---|
197 | #if defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
|
---|
198 | /** Pointer to the next session with the same hash. */
|
---|
199 | PVBOXGUESTSESSION pNextHash;
|
---|
200 | #endif
|
---|
201 | #if defined(RT_OS_OS2)
|
---|
202 | /** The system file number of this session. */
|
---|
203 | uint16_t sfn;
|
---|
204 | uint16_t Alignment; /**< Alignment */
|
---|
205 | #endif
|
---|
206 | /** The process (id) of the session.
|
---|
207 | * This is NIL if it's a kernel session. */
|
---|
208 | RTPROCESS Process;
|
---|
209 | /** Which process this session is associated with.
|
---|
210 | * This is NIL if it's a kernel session. */
|
---|
211 | RTR0PROCESS R0Process;
|
---|
212 | /** Pointer to the device extension. */
|
---|
213 | PVBOXGUESTDEVEXT pDevExt;
|
---|
214 |
|
---|
215 | #ifdef VBOX_WITH_HGCM
|
---|
216 | /** Array containing HGCM client IDs associated with this session.
|
---|
217 | * This will be automatically disconnected when the session is closed. */
|
---|
218 | uint32_t volatile aHGCMClientIds[64];
|
---|
219 | #endif
|
---|
220 | /** The last consumed VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
|
---|
221 | * Used to implement polling. */
|
---|
222 | uint32_t volatile u32MousePosChangedSeq;
|
---|
223 | /** Mouse features supported. A feature enabled in any guest session will
|
---|
224 | * be enabled for the host. */
|
---|
225 | uint32_t volatile fMouseStatus;
|
---|
226 |
|
---|
227 | } VBOXGUESTSESSION;
|
---|
228 |
|
---|
229 | RT_C_DECLS_BEGIN
|
---|
230 |
|
---|
231 | int VBoxGuestInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase, void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fEvents);
|
---|
232 | bool VBoxGuestCommonISR(PVBOXGUESTDEVEXT pDevExt);
|
---|
233 | void VBoxGuestDeleteDevExt(PVBOXGUESTDEVEXT pDevExt);
|
---|
234 | int VBoxGuestReinitDevExtAfterHibernation(PVBOXGUESTDEVEXT pDevExt, VBOXOSTYPE enmOSType);
|
---|
235 | int VBoxGuestSetGuestCapabilities(uint32_t fOr, uint32_t fNot);
|
---|
236 | #ifdef VBOXGUEST_USE_DEFERRED_WAKE_UP
|
---|
237 | void VBoxGuestWaitDoWakeUps(PVBOXGUESTDEVEXT pDevExt);
|
---|
238 | #endif
|
---|
239 |
|
---|
240 | int VBoxGuestCreateUserSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
|
---|
241 | int VBoxGuestCreateKernelSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession);
|
---|
242 | void VBoxGuestCloseSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
|
---|
243 |
|
---|
244 | int VBoxGuestCommonIOCtlFast(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession);
|
---|
245 | int VBoxGuestCommonIOCtl(unsigned iFunction, PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession,
|
---|
246 | void *pvData, size_t cbData, size_t *pcbDataReturned);
|
---|
247 |
|
---|
248 | #if defined(RT_OS_SOLARIS) \
|
---|
249 | || defined(RT_OS_FREEBSD) \
|
---|
250 | || defined(RT_OS_LINUX)
|
---|
251 | DECLVBGL(void *) VBoxGuestNativeServiceOpen(uint32_t *pu32Version);
|
---|
252 | DECLVBGL(void) VBoxGuestNativeServiceClose(void *pvOpaque);
|
---|
253 | DECLVBGL(int) VBoxGuestNativeServiceCall(void *pvOpaque, unsigned int iCmd, void *pvData, size_t cbSize, size_t *pcbReturn);
|
---|
254 | #endif
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * ISR callback for notifying threads polling for mouse events.
|
---|
258 | *
|
---|
259 | * This is called at the end of the ISR, after leaving the event spinlock, if
|
---|
260 | * VMMDEV_EVENT_MOUSE_POSITION_CHANGED was raised by the host.
|
---|
261 | *
|
---|
262 | * @param pDevExt The device extension.
|
---|
263 | */
|
---|
264 | void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt);
|
---|
265 |
|
---|
266 |
|
---|
267 | #ifdef VBOX_WITH_DPC_LATENCY_CHECKER
|
---|
268 | int VbgdNtIOCtl_DpcLatencyChecker(void);
|
---|
269 | #endif
|
---|
270 |
|
---|
271 | RT_C_DECLS_END
|
---|
272 |
|
---|
273 | #endif
|
---|
274 |
|
---|