1 | /* $Id: HGSMIBase.cpp 68848 2017-09-24 16:58:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Video driver, common code - HGSMI guest-to-host communication.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
10 | * copy of this software and associated documentation files (the "Software"),
|
---|
11 | * to deal in the Software without restriction, including without limitation
|
---|
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
13 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
14 | * Software is furnished to do so, subject to the following conditions:
|
---|
15 | *
|
---|
16 | * The above copyright notice and this permission notice shall be included in
|
---|
17 | * all copies or substantial portions of the Software.
|
---|
18 | *
|
---|
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
22 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
---|
23 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
---|
24 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
25 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
26 | */
|
---|
27 |
|
---|
28 | #include <HGSMIBase.h>
|
---|
29 | #include <VBoxVideoIPRT.h>
|
---|
30 | #include <VBoxVideoGuest.h>
|
---|
31 | #include <VBoxVideoVBE.h>
|
---|
32 | #include <HGSMIChannels.h>
|
---|
33 | #include <HGSMIChSetup.h>
|
---|
34 |
|
---|
35 | /** Detect whether HGSMI is supported by the host. */
|
---|
36 | DECLHIDDEN(bool) VBoxHGSMIIsSupported(void)
|
---|
37 | {
|
---|
38 | uint16_t DispiId;
|
---|
39 |
|
---|
40 | VBVO_PORT_WRITE_U16(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ID);
|
---|
41 | VBVO_PORT_WRITE_U16(VBE_DISPI_IOPORT_DATA, VBE_DISPI_ID_HGSMI);
|
---|
42 |
|
---|
43 | DispiId = VBVO_PORT_READ_U16(VBE_DISPI_IOPORT_DATA);
|
---|
44 |
|
---|
45 | return (DispiId == VBE_DISPI_ID_HGSMI);
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Inform the host of the location of the host flags in VRAM via an HGSMI command.
|
---|
51 | * @returns IPRT status value.
|
---|
52 | * @returns VERR_NOT_IMPLEMENTED if the host does not support the command.
|
---|
53 | * @returns VERR_NO_MEMORY if a heap allocation fails.
|
---|
54 | * @param pCtx the context of the guest heap to use.
|
---|
55 | * @param offLocation the offset chosen for the flags withing guest VRAM.
|
---|
56 | */
|
---|
57 | DECLHIDDEN(int) VBoxHGSMIReportFlagsLocation(PHGSMIGUESTCOMMANDCONTEXT pCtx, HGSMIOFFSET offLocation)
|
---|
58 | {
|
---|
59 | HGSMIBUFFERLOCATION *p;
|
---|
60 |
|
---|
61 | /* Allocate the IO buffer. */
|
---|
62 | p = (HGSMIBUFFERLOCATION *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p), HGSMI_CH_HGSMI,
|
---|
63 | HGSMI_CC_HOST_FLAGS_LOCATION);
|
---|
64 | if (!p)
|
---|
65 | return VERR_NO_MEMORY;
|
---|
66 |
|
---|
67 | /* Prepare data to be sent to the host. */
|
---|
68 | p->offLocation = offLocation;
|
---|
69 | p->cbLocation = sizeof(HGSMIHOSTFLAGS);
|
---|
70 | /* No need to check that the buffer is valid as we have just allocated it. */
|
---|
71 | VBoxHGSMIBufferSubmit(pCtx, p);
|
---|
72 | /* Free the IO buffer. */
|
---|
73 | VBoxHGSMIBufferFree(pCtx, p);
|
---|
74 |
|
---|
75 | return VINF_SUCCESS;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Notify the host of HGSMI-related guest capabilities via an HGSMI command.
|
---|
81 | * @returns IPRT status value.
|
---|
82 | * @returns VERR_NOT_IMPLEMENTED if the host does not support the command.
|
---|
83 | * @returns VERR_NO_MEMORY if a heap allocation fails.
|
---|
84 | * @param pCtx the context of the guest heap to use.
|
---|
85 | * @param fCaps the capabilities to report, see VBVACAPS.
|
---|
86 | */
|
---|
87 | DECLHIDDEN(int) VBoxHGSMISendCapsInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx, uint32_t fCaps)
|
---|
88 | {
|
---|
89 | VBVACAPS *p;
|
---|
90 |
|
---|
91 | /* Allocate the IO buffer. */
|
---|
92 | p = (VBVACAPS *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p), HGSMI_CH_VBVA, VBVA_INFO_CAPS);
|
---|
93 |
|
---|
94 | if (!p)
|
---|
95 | return VERR_NO_MEMORY;
|
---|
96 |
|
---|
97 | /* Prepare data to be sent to the host. */
|
---|
98 | p->rc = VERR_NOT_IMPLEMENTED;
|
---|
99 | p->fCaps = fCaps;
|
---|
100 | /* No need to check that the buffer is valid as we have just allocated it. */
|
---|
101 | VBoxHGSMIBufferSubmit(pCtx, p);
|
---|
102 |
|
---|
103 | AssertRC(p->rc);
|
---|
104 | /* Free the IO buffer. */
|
---|
105 | VBoxHGSMIBufferFree(pCtx, p);
|
---|
106 | return p->rc;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Get the information needed to map the basic communication structures in
|
---|
112 | * device memory into our address space. All pointer parameters are optional.
|
---|
113 | *
|
---|
114 | * @param cbVRAM how much video RAM is allocated to the device
|
---|
115 | * @param poffVRAMBaseMapping where to save the offset from the start of the
|
---|
116 | * device VRAM of the whole area to map
|
---|
117 | * @param pcbMapping where to save the mapping size
|
---|
118 | * @param poffGuestHeapMemory where to save the offset into the mapped area
|
---|
119 | * of the guest heap backing memory
|
---|
120 | * @param pcbGuestHeapMemory where to save the size of the guest heap
|
---|
121 | * backing memory
|
---|
122 | * @param poffHostFlags where to save the offset into the mapped area
|
---|
123 | * of the host flags
|
---|
124 | */
|
---|
125 | DECLHIDDEN(void) VBoxHGSMIGetBaseMappingInfo(uint32_t cbVRAM,
|
---|
126 | uint32_t *poffVRAMBaseMapping,
|
---|
127 | uint32_t *pcbMapping,
|
---|
128 | uint32_t *poffGuestHeapMemory,
|
---|
129 | uint32_t *pcbGuestHeapMemory,
|
---|
130 | uint32_t *poffHostFlags)
|
---|
131 | {
|
---|
132 | AssertPtrNullReturnVoid(poffVRAMBaseMapping);
|
---|
133 | AssertPtrNullReturnVoid(pcbMapping);
|
---|
134 | AssertPtrNullReturnVoid(poffGuestHeapMemory);
|
---|
135 | AssertPtrNullReturnVoid(pcbGuestHeapMemory);
|
---|
136 | AssertPtrNullReturnVoid(poffHostFlags);
|
---|
137 | if (poffVRAMBaseMapping)
|
---|
138 | *poffVRAMBaseMapping = cbVRAM - VBVA_ADAPTER_INFORMATION_SIZE;
|
---|
139 | if (pcbMapping)
|
---|
140 | *pcbMapping = VBVA_ADAPTER_INFORMATION_SIZE;
|
---|
141 | if (poffGuestHeapMemory)
|
---|
142 | *poffGuestHeapMemory = 0;
|
---|
143 | if (pcbGuestHeapMemory)
|
---|
144 | *pcbGuestHeapMemory = VBVA_ADAPTER_INFORMATION_SIZE
|
---|
145 | - sizeof(HGSMIHOSTFLAGS);
|
---|
146 | if (poffHostFlags)
|
---|
147 | *poffHostFlags = VBVA_ADAPTER_INFORMATION_SIZE
|
---|
148 | - sizeof(HGSMIHOSTFLAGS);
|
---|
149 | }
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Query the host for an HGSMI configuration parameter via an HGSMI command.
|
---|
153 | * @returns iprt status value
|
---|
154 | * @param pCtx the context containing the heap used
|
---|
155 | * @param u32Index the index of the parameter to query,
|
---|
156 | * @see VBVACONF32::u32Index
|
---|
157 | * @param pulValue where to store the value of the parameter on success
|
---|
158 | */
|
---|
159 | DECLHIDDEN(int) VBoxQueryConfHGSMI(PHGSMIGUESTCOMMANDCONTEXT pCtx, uint32_t u32Index, uint32_t *pulValue)
|
---|
160 | {
|
---|
161 | VBVACONF32 *p;
|
---|
162 |
|
---|
163 | /* Allocate the IO buffer. */
|
---|
164 | p = (VBVACONF32 *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p), HGSMI_CH_VBVA,
|
---|
165 | VBVA_QUERY_CONF32);
|
---|
166 | if (!p)
|
---|
167 | return VERR_NO_MEMORY;
|
---|
168 |
|
---|
169 | /* Prepare data to be sent to the host. */
|
---|
170 | p->u32Index = u32Index;
|
---|
171 | p->u32Value = UINT32_MAX;
|
---|
172 | /* No need to check that the buffer is valid as we have just allocated it. */
|
---|
173 | VBoxHGSMIBufferSubmit(pCtx, p);
|
---|
174 | *pulValue = p->u32Value;
|
---|
175 | /* Free the IO buffer. */
|
---|
176 | VBoxHGSMIBufferFree(pCtx, p);
|
---|
177 | return VINF_SUCCESS;
|
---|
178 | }
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Pass the host a new mouse pointer shape via an HGSMI command.
|
---|
182 | *
|
---|
183 | * @returns success or failure
|
---|
184 | * @param pCtx the context containing the heap to be used
|
---|
185 | * @param fFlags cursor flags, @see VMMDevReqMousePointer::fFlags
|
---|
186 | * @param cHotX horizontal position of the hot spot
|
---|
187 | * @param cHotY vertical position of the hot spot
|
---|
188 | * @param cWidth width in pixels of the cursor
|
---|
189 | * @param cHeight height in pixels of the cursor
|
---|
190 | * @param pPixels pixel data, @see VMMDevReqMousePointer for the format
|
---|
191 | * @param cbLength size in bytes of the pixel data
|
---|
192 | */
|
---|
193 | DECLHIDDEN(int) VBoxHGSMIUpdatePointerShape(PHGSMIGUESTCOMMANDCONTEXT pCtx, uint32_t fFlags,
|
---|
194 | uint32_t cHotX, uint32_t cHotY, uint32_t cWidth, uint32_t cHeight,
|
---|
195 | uint8_t *pPixels, uint32_t cbLength)
|
---|
196 | {
|
---|
197 | VBVAMOUSEPOINTERSHAPE *p;
|
---|
198 | uint32_t cbPixels = 0;
|
---|
199 | int rc;
|
---|
200 |
|
---|
201 | if (fFlags & VBOX_MOUSE_POINTER_SHAPE)
|
---|
202 | {
|
---|
203 | /*
|
---|
204 | * Size of the pointer data:
|
---|
205 | * sizeof (AND mask) + sizeof (XOR_MASK)
|
---|
206 | */
|
---|
207 | cbPixels = ((((cWidth + 7) / 8) * cHeight + 3) & ~3)
|
---|
208 | + cWidth * 4 * cHeight;
|
---|
209 | if (cbPixels > cbLength)
|
---|
210 | return VERR_INVALID_PARAMETER;
|
---|
211 | /*
|
---|
212 | * If shape is supplied, then always create the pointer visible.
|
---|
213 | * See comments in 'vboxUpdatePointerShape'
|
---|
214 | */
|
---|
215 | fFlags |= VBOX_MOUSE_POINTER_VISIBLE;
|
---|
216 | }
|
---|
217 | /* Allocate the IO buffer. */
|
---|
218 | p = (VBVAMOUSEPOINTERSHAPE *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p) + cbPixels, HGSMI_CH_VBVA,
|
---|
219 | VBVA_MOUSE_POINTER_SHAPE);
|
---|
220 | if (!p)
|
---|
221 | return VERR_NO_MEMORY;
|
---|
222 | /* Prepare data to be sent to the host. */
|
---|
223 | /* Will be updated by the host. */
|
---|
224 | p->i32Result = VINF_SUCCESS;
|
---|
225 | /* We have our custom flags in the field */
|
---|
226 | p->fu32Flags = fFlags;
|
---|
227 | p->u32HotX = cHotX;
|
---|
228 | p->u32HotY = cHotY;
|
---|
229 | p->u32Width = cWidth;
|
---|
230 | p->u32Height = cHeight;
|
---|
231 | if (cbPixels)
|
---|
232 | /* Copy the actual pointer data. */
|
---|
233 | memcpy (p->au8Data, pPixels, cbPixels);
|
---|
234 | /* No need to check that the buffer is valid as we have just allocated it. */
|
---|
235 | VBoxHGSMIBufferSubmit(pCtx, p);
|
---|
236 | rc = p->i32Result;
|
---|
237 | /* Free the IO buffer. */
|
---|
238 | VBoxHGSMIBufferFree(pCtx, p);
|
---|
239 | return rc;
|
---|
240 | }
|
---|
241 |
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Report the guest cursor position. The host may wish to use this information
|
---|
245 | * to re-position its own cursor (though this is currently unlikely). The
|
---|
246 | * current host cursor position is returned.
|
---|
247 | * @param pCtx The context containing the heap used.
|
---|
248 | * @param fReportPosition Are we reporting a position?
|
---|
249 | * @param x Guest cursor X position.
|
---|
250 | * @param y Guest cursor Y position.
|
---|
251 | * @param pxHost Host cursor X position is stored here. Optional.
|
---|
252 | * @param pyHost Host cursor Y position is stored here. Optional.
|
---|
253 | * @returns iprt status code.
|
---|
254 | * @returns VERR_NO_MEMORY HGSMI heap allocation failed.
|
---|
255 | */
|
---|
256 | DECLHIDDEN(int) VBoxHGSMICursorPosition(PHGSMIGUESTCOMMANDCONTEXT pCtx, bool fReportPosition,
|
---|
257 | uint32_t x, uint32_t y, uint32_t *pxHost, uint32_t *pyHost)
|
---|
258 | {
|
---|
259 | VBVACURSORPOSITION *p;
|
---|
260 |
|
---|
261 | /* Allocate the IO buffer. */
|
---|
262 | p = (VBVACURSORPOSITION *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p), HGSMI_CH_VBVA,
|
---|
263 | VBVA_CURSOR_POSITION);
|
---|
264 | if (!p)
|
---|
265 | return VERR_NO_MEMORY;
|
---|
266 | /* Prepare data to be sent to the host. */
|
---|
267 | p->fReportPosition = fReportPosition;
|
---|
268 | p->x = x;
|
---|
269 | p->y = y;
|
---|
270 | /* No need to check that the buffer is valid as we have just allocated it. */
|
---|
271 | VBoxHGSMIBufferSubmit(pCtx, p);
|
---|
272 | if (pxHost)
|
---|
273 | *pxHost = p->x;
|
---|
274 | if (pyHost)
|
---|
275 | *pyHost = p->y;
|
---|
276 | /* Free the IO buffer. */
|
---|
277 | VBoxHGSMIBufferFree(pCtx, p);
|
---|
278 | return VINF_SUCCESS;
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * @todo Mouse pointer position to be read from VMMDev memory, address of the
|
---|
284 | * memory region can be queried from VMMDev via an IOCTL. This VMMDev memory
|
---|
285 | * region will contain host information which is needed by the guest.
|
---|
286 | *
|
---|
287 | * Reading will not cause a switch to the host.
|
---|
288 | *
|
---|
289 | * Have to take into account:
|
---|
290 | * * synchronization: host must write to the memory only from EMT,
|
---|
291 | * large structures must be read under flag, which tells the host
|
---|
292 | * that the guest is currently reading the memory (OWNER flag?).
|
---|
293 | * * guest writes: may be allocate a page for the host info and make
|
---|
294 | * the page readonly for the guest.
|
---|
295 | * * the information should be available only for additions drivers.
|
---|
296 | * * VMMDev additions driver will inform the host which version of the info
|
---|
297 | * it expects, host must support all versions.
|
---|
298 | */
|
---|