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