VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp@ 58154

Last change on this file since 58154 was 56378, checked in by vboxsync, 10 years ago

Windows guest additions, VBVA: host mouse cursor capability.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.0 KB
Line 
1/* $Id: HGSMIBase.cpp 56378 2015-06-12 06:10:56Z vboxsync $ */
2/** @file
3 * VirtualBox Video driver, common code - HGSMI initialisation and helper
4 * functions.
5 */
6
7/*
8 * Copyright (C) 2006-2015 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include <VBox/VBoxVideoGuest.h>
20#include <VBox/VBoxVideo.h>
21#include <VBox/VBoxGuest.h>
22#include <VBox/Hardware/VBoxVideoVBE.h>
23#include <VBox/VMMDev.h>
24
25#include <iprt/asm.h>
26#include <iprt/log.h>
27#include <iprt/string.h>
28
29/** Send completion notification to the host for the command located at offset
30 * @a offt into the host command buffer. */
31static void HGSMINotifyHostCmdComplete(PHGSMIHOSTCOMMANDCONTEXT pCtx, HGSMIOFFSET offt)
32{
33 VBoxVideoCmnPortWriteUlong(pCtx->port, offt);
34}
35
36
37/**
38 * Inform the host that a command has been handled.
39 *
40 * @param pCtx the context containing the heap to be used
41 * @param pvMem pointer into the heap as mapped in @a pCtx to the command to
42 * be completed
43 */
44RTDECL(void) VBoxHGSMIHostCmdComplete(PHGSMIHOSTCOMMANDCONTEXT pCtx,
45 void *pvMem)
46{
47 HGSMIBUFFERHEADER *pHdr = HGSMIBufferHeaderFromData(pvMem);
48 HGSMIOFFSET offMem = HGSMIPointerToOffset(&pCtx->areaCtx, pHdr);
49 Assert(offMem != HGSMIOFFSET_VOID);
50 if(offMem != HGSMIOFFSET_VOID)
51 {
52 HGSMINotifyHostCmdComplete(pCtx, offMem);
53 }
54}
55
56
57/** Submit an incoming host command to the appropriate handler. */
58static void hgsmiHostCmdProcess(PHGSMIHOSTCOMMANDCONTEXT pCtx,
59 HGSMIOFFSET offBuffer)
60{
61 int rc = HGSMIBufferProcess(&pCtx->areaCtx, &pCtx->channels, offBuffer);
62 Assert(!RT_FAILURE(rc));
63 if(RT_FAILURE(rc))
64 {
65 /* failure means the command was not submitted to the handler for some reason
66 * it's our responsibility to notify its completion in this case */
67 HGSMINotifyHostCmdComplete(pCtx, offBuffer);
68 }
69 /* if the cmd succeeded it's responsibility of the callback to complete it */
70}
71
72/** Get the next command from the host. */
73static HGSMIOFFSET hgsmiGetHostBuffer(PHGSMIHOSTCOMMANDCONTEXT pCtx)
74{
75 return VBoxVideoCmnPortReadUlong(pCtx->port);
76}
77
78
79/** Get and handle the next command from the host. */
80static void hgsmiHostCommandQueryProcess(PHGSMIHOSTCOMMANDCONTEXT pCtx)
81{
82 HGSMIOFFSET offset = hgsmiGetHostBuffer(pCtx);
83 AssertReturnVoid(offset != HGSMIOFFSET_VOID);
84 hgsmiHostCmdProcess(pCtx, offset);
85}
86
87
88/** Drain the host command queue. */
89RTDECL(void) VBoxHGSMIProcessHostQueue(PHGSMIHOSTCOMMANDCONTEXT pCtx)
90{
91 while (pCtx->pfHostFlags->u32HostFlags & HGSMIHOSTFLAGS_COMMANDS_PENDING)
92 {
93 if (!ASMAtomicCmpXchgBool(&pCtx->fHostCmdProcessing, true, false))
94 return;
95 hgsmiHostCommandQueryProcess(pCtx);
96 ASMAtomicWriteBool(&pCtx->fHostCmdProcessing, false);
97 }
98}
99
100
101/** Detect whether HGSMI is supported by the host. */
102RTDECL(bool) VBoxHGSMIIsSupported(void)
103{
104 uint16_t DispiId;
105
106 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ID);
107 VBoxVideoCmnPortWriteUshort(VBE_DISPI_IOPORT_DATA, VBE_DISPI_ID_HGSMI);
108
109 DispiId = VBoxVideoCmnPortReadUshort(VBE_DISPI_IOPORT_DATA);
110
111 return (DispiId == VBE_DISPI_ID_HGSMI);
112}
113
114
115/**
116 * Allocate and initialise a command descriptor in the guest heap for a
117 * guest-to-host command.
118 *
119 * @returns pointer to the descriptor's command data buffer
120 * @param pCtx the context containing the heap to be used
121 * @param cbData the size of the command data to go into the descriptor
122 * @param u8Ch the HGSMI channel to be used, set to the descriptor
123 * @param u16Op the HGSMI command to be sent, set to the descriptor
124 */
125RTDECL(void *) VBoxHGSMIBufferAlloc(PHGSMIGUESTCOMMANDCONTEXT pCtx,
126 HGSMISIZE cbData,
127 uint8_t u8Ch,
128 uint16_t u16Op)
129{
130#ifdef VBOX_WDDM_MINIPORT
131 return VBoxSHGSMIHeapAlloc (&pCtx->heapCtx, cbData, u8Ch, u16Op);
132#else
133 return HGSMIHeapAlloc (&pCtx->heapCtx, cbData, u8Ch, u16Op);
134#endif
135}
136
137
138/**
139 * Free a descriptor allocated by @a VBoxHGSMIBufferAlloc.
140 *
141 * @param pCtx the context containing the heap used
142 * @param pvBuffer the pointer returned by @a VBoxHGSMIBufferAlloc
143 */
144RTDECL(void) VBoxHGSMIBufferFree(PHGSMIGUESTCOMMANDCONTEXT pCtx,
145 void *pvBuffer)
146{
147#ifdef VBOX_WDDM_MINIPORT
148 VBoxSHGSMIHeapFree (&pCtx->heapCtx, pvBuffer);
149#else
150 HGSMIHeapFree (&pCtx->heapCtx, pvBuffer);
151#endif
152}
153
154
155/**
156 * Submit a command descriptor allocated by @a VBoxHGSMIBufferAlloc.
157 *
158 * @param pCtx the context containing the heap used
159 * @param pvBuffer the pointer returned by @a VBoxHGSMIBufferAlloc
160 */
161RTDECL(int) VBoxHGSMIBufferSubmit(PHGSMIGUESTCOMMANDCONTEXT pCtx,
162 void *pvBuffer)
163{
164 /* Initialize the buffer and get the offset for port IO. */
165 HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (HGSMIGUESTCMDHEAP_GET(&pCtx->heapCtx), pvBuffer);
166
167 Assert(offBuffer != HGSMIOFFSET_VOID);
168 if (offBuffer != HGSMIOFFSET_VOID)
169 {
170 /* Submit the buffer to the host. */
171 VBoxVideoCmnPortWriteUlong(pCtx->port, offBuffer);
172 return VINF_SUCCESS;
173 }
174
175 return VERR_INVALID_PARAMETER;
176}
177
178
179/** Inform the host of the location of the host flags in VRAM via an HGSMI
180 * command. */
181static int vboxHGSMIReportFlagsLocation(PHGSMIGUESTCOMMANDCONTEXT pCtx,
182 HGSMIOFFSET offLocation)
183{
184 HGSMIBUFFERLOCATION *p;
185 int rc = VINF_SUCCESS;
186
187 /* Allocate the IO buffer. */
188 p = (HGSMIBUFFERLOCATION *)VBoxHGSMIBufferAlloc(pCtx,
189 sizeof(HGSMIBUFFERLOCATION),
190 HGSMI_CH_HGSMI,
191 HGSMI_CC_HOST_FLAGS_LOCATION);
192 if (p)
193 {
194 /* Prepare data to be sent to the host. */
195 p->offLocation = offLocation;
196 p->cbLocation = sizeof(HGSMIHOSTFLAGS);
197 rc = VBoxHGSMIBufferSubmit(pCtx, p);
198 /* Free the IO buffer. */
199 VBoxHGSMIBufferFree(pCtx, p);
200 }
201 else
202 rc = VERR_NO_MEMORY;
203 return rc;
204}
205
206
207/** Notify the host of HGSMI-related guest capabilities via an HGSMI command.
208 */
209static int vboxHGSMISendCapsInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
210 uint32_t fCaps)
211{
212 VBVACAPS *pCaps;
213 int rc = VINF_SUCCESS;
214
215 /* Allocate the IO buffer. */
216 pCaps = (VBVACAPS *)VBoxHGSMIBufferAlloc(pCtx,
217 sizeof(VBVACAPS), HGSMI_CH_VBVA,
218 VBVA_INFO_CAPS);
219
220 if (pCaps)
221 {
222 /* Prepare data to be sent to the host. */
223 pCaps->rc = VERR_NOT_IMPLEMENTED;
224 pCaps->fCaps = fCaps;
225 rc = VBoxHGSMIBufferSubmit(pCtx, pCaps);
226 if (RT_SUCCESS(rc))
227 {
228 AssertRC(pCaps->rc);
229 rc = pCaps->rc;
230 }
231 /* Free the IO buffer. */
232 VBoxHGSMIBufferFree(pCtx, pCaps);
233 }
234 else
235 rc = VERR_NO_MEMORY;
236 return rc;
237}
238
239
240/**
241 * Notify the host of HGSMI-related guest capabilities via an HGSMI command.
242 * @returns IPRT status value.
243 * @returns VERR_NOT_IMPLEMENTED if the host does not support the command.
244 * @returns VERR_NO_MEMORY if a heap allocation fails.
245 * @param pCtx the context of the guest heap to use.
246 * @param fCaps the capabilities to report, see VBVACAPS.
247 */
248RTDECL(int) VBoxHGSMISendCapsInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
249 uint32_t fCaps)
250{
251 return vboxHGSMISendCapsInfo(pCtx, fCaps);
252}
253
254
255/** Tell the host about the location of the area of VRAM set aside for the host
256 * heap. */
257static int vboxHGSMIReportHostArea(PHGSMIGUESTCOMMANDCONTEXT pCtx,
258 uint32_t u32AreaOffset, uint32_t u32AreaSize)
259{
260 VBVAINFOHEAP *p;
261 int rc = VINF_SUCCESS;
262
263 /* Allocate the IO buffer. */
264 p = (VBVAINFOHEAP *)VBoxHGSMIBufferAlloc(pCtx,
265 sizeof (VBVAINFOHEAP), HGSMI_CH_VBVA,
266 VBVA_INFO_HEAP);
267 if (p)
268 {
269 /* Prepare data to be sent to the host. */
270 p->u32HeapOffset = u32AreaOffset;
271 p->u32HeapSize = u32AreaSize;
272 rc = VBoxHGSMIBufferSubmit(pCtx, p);
273 /* Free the IO buffer. */
274 VBoxHGSMIBufferFree(pCtx, p);
275 }
276 else
277 rc = VERR_NO_MEMORY;
278 return rc;
279}
280
281
282/**
283 * Get the information needed to map the basic communication structures in
284 * device memory into our address space. All pointer parameters are optional.
285 *
286 * @param cbVRAM how much video RAM is allocated to the device
287 * @param poffVRAMBaseMapping where to save the offset from the start of the
288 * device VRAM of the whole area to map
289 * @param pcbMapping where to save the mapping size
290 * @param poffGuestHeapMemory where to save the offset into the mapped area
291 * of the guest heap backing memory
292 * @param pcbGuestHeapMemory where to save the size of the guest heap
293 * backing memory
294 * @param poffHostFlags where to save the offset into the mapped area
295 * of the host flags
296 */
297RTDECL(void) VBoxHGSMIGetBaseMappingInfo(uint32_t cbVRAM,
298 uint32_t *poffVRAMBaseMapping,
299 uint32_t *pcbMapping,
300 uint32_t *poffGuestHeapMemory,
301 uint32_t *pcbGuestHeapMemory,
302 uint32_t *poffHostFlags)
303{
304 AssertPtrNullReturnVoid(poffVRAMBaseMapping);
305 AssertPtrNullReturnVoid(pcbMapping);
306 AssertPtrNullReturnVoid(poffGuestHeapMemory);
307 AssertPtrNullReturnVoid(pcbGuestHeapMemory);
308 AssertPtrNullReturnVoid(poffHostFlags);
309 if (poffVRAMBaseMapping)
310 *poffVRAMBaseMapping = cbVRAM - VBVA_ADAPTER_INFORMATION_SIZE;
311 if (pcbMapping)
312 *pcbMapping = VBVA_ADAPTER_INFORMATION_SIZE;
313 if (poffGuestHeapMemory)
314 *poffGuestHeapMemory = 0;
315 if (pcbGuestHeapMemory)
316 *pcbGuestHeapMemory = VBVA_ADAPTER_INFORMATION_SIZE
317 - sizeof(HGSMIHOSTFLAGS);
318 if (poffHostFlags)
319 *poffHostFlags = VBVA_ADAPTER_INFORMATION_SIZE
320 - sizeof(HGSMIHOSTFLAGS);
321}
322
323
324/**
325 * Set up the HGSMI guest-to-host command context.
326 * @returns iprt status value
327 * @param pCtx the context to set up
328 * @param pvGuestHeapMemory a pointer to the mapped backing memory for
329 * the guest heap
330 * @param cbGuestHeapMemory the size of the backing memory area
331 * @param offVRAMGuestHeapMemory the offset of the memory pointed to by
332 * @a pvGuestHeapMemory within the video RAM
333 */
334RTDECL(int) VBoxHGSMISetupGuestContext(PHGSMIGUESTCOMMANDCONTEXT pCtx,
335 void *pvGuestHeapMemory,
336 uint32_t cbGuestHeapMemory,
337 uint32_t offVRAMGuestHeapMemory,
338 const HGSMIENV *pEnv)
339{
340 /** @todo should we be using a fixed ISA port value here? */
341 pCtx->port = (RTIOPORT)VGA_PORT_HGSMI_GUEST;
342#ifdef VBOX_WDDM_MINIPORT
343 return VBoxSHGSMIInit(&pCtx->heapCtx, pvGuestHeapMemory,
344 cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
345#else
346 return HGSMIHeapSetup(&pCtx->heapCtx, pvGuestHeapMemory,
347 cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
348#endif
349}
350
351
352/**
353 * Get the information needed to map the area used by the host to send back
354 * requests.
355 *
356 * @param pCtx the context containing the heap to use
357 * @param cbVRAM how much video RAM is allocated to the device
358 * @param offVRAMBaseMapping the offset of the basic communication structures
359 * into the guest's VRAM
360 * @param poffVRAMHostArea where to store the offset into VRAM of the host
361 * heap area
362 * @param pcbHostArea where to store the size of the host heap area
363 */
364RTDECL(void) VBoxHGSMIGetHostAreaMapping(PHGSMIGUESTCOMMANDCONTEXT pCtx,
365 uint32_t cbVRAM,
366 uint32_t offVRAMBaseMapping,
367 uint32_t *poffVRAMHostArea,
368 uint32_t *pcbHostArea)
369{
370 uint32_t offVRAMHostArea = offVRAMBaseMapping, cbHostArea = 0;
371
372 AssertPtrReturnVoid(poffVRAMHostArea);
373 AssertPtrReturnVoid(pcbHostArea);
374 VBoxQueryConfHGSMI(pCtx, VBOX_VBVA_CONF32_HOST_HEAP_SIZE, &cbHostArea);
375 if (cbHostArea != 0)
376 {
377 uint32_t cbHostAreaMaxSize = cbVRAM / 4;
378 /** @todo what is the idea of this? */
379 if (cbHostAreaMaxSize >= VBVA_ADAPTER_INFORMATION_SIZE)
380 {
381 cbHostAreaMaxSize -= VBVA_ADAPTER_INFORMATION_SIZE;
382 }
383 if (cbHostArea > cbHostAreaMaxSize)
384 {
385 cbHostArea = cbHostAreaMaxSize;
386 }
387 /* Round up to 4096 bytes. */
388 cbHostArea = (cbHostArea + 0xFFF) & ~0xFFF;
389 offVRAMHostArea = offVRAMBaseMapping - cbHostArea;
390 }
391
392 *pcbHostArea = cbHostArea;
393 *poffVRAMHostArea = offVRAMHostArea;
394 LogFunc(("offVRAMHostArea = 0x%08X, cbHostArea = 0x%08X\n",
395 offVRAMHostArea, cbHostArea));
396}
397
398
399/**
400 * Initialise the host context structure.
401 *
402 * @param pCtx the context structure to initialise
403 * @param pvBaseMapping where the basic HGSMI structures are mapped at
404 * @param offHostFlags the offset of the host flags into the basic HGSMI
405 * structures
406 * @param pvHostAreaMapping where the area for the host heap is mapped at
407 * @param offVRAMHostArea offset of the host heap area into VRAM
408 * @param cbHostArea size in bytes of the host heap area
409 */
410RTDECL(void) VBoxHGSMISetupHostContext(PHGSMIHOSTCOMMANDCONTEXT pCtx,
411 void *pvBaseMapping,
412 uint32_t offHostFlags,
413 void *pvHostAreaMapping,
414 uint32_t offVRAMHostArea,
415 uint32_t cbHostArea)
416{
417 uint8_t *pu8HostFlags = ((uint8_t *)pvBaseMapping) + offHostFlags;
418 pCtx->pfHostFlags = (HGSMIHOSTFLAGS *)pu8HostFlags;
419 /** @todo should we really be using a fixed ISA port value here? */
420 pCtx->port = (RTIOPORT)VGA_PORT_HGSMI_HOST;
421 HGSMIAreaInitialize(&pCtx->areaCtx, pvHostAreaMapping, cbHostArea,
422 offVRAMHostArea);
423}
424
425
426/**
427 * Tell the host about the ways it can use to communicate back to us via an
428 * HGSMI command
429 *
430 * @returns iprt status value
431 * @param pCtx the context containing the heap to use
432 * @param offVRAMFlagsLocation where we wish the host to place its flags
433 * relative to the start of the VRAM
434 * @param fCaps additions HGSMI capabilities the guest
435 * supports
436 * @param offVRAMHostArea offset into VRAM of the host heap area
437 * @param cbHostArea size in bytes of the host heap area
438 */
439RTDECL(int) VBoxHGSMISendHostCtxInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
440 HGSMIOFFSET offVRAMFlagsLocation,
441 uint32_t fCaps,
442 uint32_t offVRAMHostArea,
443 uint32_t cbHostArea)
444{
445 Log(("VBoxVideo::vboxSetupAdapterInfo\n"));
446
447 /* setup the flags first to ensure they are initialized by the time the
448 * host heap is ready */
449 int rc = vboxHGSMIReportFlagsLocation(pCtx, offVRAMFlagsLocation);
450 AssertRC(rc);
451 if (RT_SUCCESS(rc) && fCaps)
452 {
453 /* Inform about caps */
454 rc = vboxHGSMISendCapsInfo(pCtx, fCaps);
455 AssertRC(rc);
456 }
457 if (RT_SUCCESS (rc))
458 {
459 /* Report the host heap location. */
460 rc = vboxHGSMIReportHostArea(pCtx, offVRAMHostArea, cbHostArea);
461 AssertRC(rc);
462 }
463 Log(("VBoxVideo::vboxSetupAdapterInfo finished rc = %d\n", rc));
464 return rc;
465}
466
467
468/** Sanity test on first call. We do not worry about concurrency issues. */
469static int testQueryConf(PHGSMIGUESTCOMMANDCONTEXT pCtx)
470{
471 static bool cOnce = false;
472 uint32_t ulValue = 0;
473 int rc;
474
475 if (cOnce)
476 return VINF_SUCCESS;
477 cOnce = true;
478 rc = VBoxQueryConfHGSMI(pCtx, UINT32_MAX, &ulValue);
479 if (RT_SUCCESS(rc) && ulValue == UINT32_MAX)
480 return VINF_SUCCESS;
481 cOnce = false;
482 if (RT_FAILURE(rc))
483 return rc;
484 return VERR_INTERNAL_ERROR;
485}
486
487
488/**
489 * Query the host for an HGSMI configuration parameter via an HGSMI command.
490 * @returns iprt status value
491 * @param pCtx the context containing the heap used
492 * @param u32Index the index of the parameter to query,
493 * @see VBVACONF32::u32Index
494 * @param u32DefValue defaut value
495 * @param pulValue where to store the value of the parameter on success
496 */
497RTDECL(int) VBoxQueryConfHGSMIDef(PHGSMIGUESTCOMMANDCONTEXT pCtx,
498 uint32_t u32Index, uint32_t u32DefValue, uint32_t *pulValue)
499{
500 int rc = VINF_SUCCESS;
501 VBVACONF32 *p;
502 LogFunc(("u32Index = %d\n", u32Index));
503
504 rc = testQueryConf(pCtx);
505 if (RT_FAILURE(rc))
506 return rc;
507 /* Allocate the IO buffer. */
508 p = (VBVACONF32 *)VBoxHGSMIBufferAlloc(pCtx,
509 sizeof(VBVACONF32), HGSMI_CH_VBVA,
510 VBVA_QUERY_CONF32);
511 if (p)
512 {
513 /* Prepare data to be sent to the host. */
514 p->u32Index = u32Index;
515 p->u32Value = u32DefValue;
516 rc = VBoxHGSMIBufferSubmit(pCtx, p);
517 if (RT_SUCCESS(rc))
518 {
519 *pulValue = p->u32Value;
520 LogFunc(("u32Value = %d\n", p->u32Value));
521 }
522 /* Free the IO buffer. */
523 VBoxHGSMIBufferFree(pCtx, p);
524 }
525 else
526 rc = VERR_NO_MEMORY;
527 LogFunc(("rc = %d\n", rc));
528 return rc;
529}
530
531RTDECL(int) VBoxQueryConfHGSMI(PHGSMIGUESTCOMMANDCONTEXT pCtx,
532 uint32_t u32Index, uint32_t *pulValue)
533{
534 return VBoxQueryConfHGSMIDef(pCtx, u32Index, UINT32_MAX, pulValue);
535}
536
537/**
538 * Pass the host a new mouse pointer shape via an HGSMI command.
539 *
540 * @returns success or failure
541 * @param fFlags cursor flags, @see VMMDevReqMousePointer::fFlags
542 * @param cHotX horizontal position of the hot spot
543 * @param cHotY vertical position of the hot spot
544 * @param cWidth width in pixels of the cursor
545 * @param cHeight height in pixels of the cursor
546 * @param pPixels pixel data, @see VMMDevReqMousePointer for the format
547 * @param cbLength size in bytes of the pixel data
548 */
549RTDECL(int) VBoxHGSMIUpdatePointerShape(PHGSMIGUESTCOMMANDCONTEXT pCtx,
550 uint32_t fFlags,
551 uint32_t cHotX,
552 uint32_t cHotY,
553 uint32_t cWidth,
554 uint32_t cHeight,
555 uint8_t *pPixels,
556 uint32_t cbLength)
557{
558 VBVAMOUSEPOINTERSHAPE *p;
559 uint32_t cbData = 0;
560 int rc = VINF_SUCCESS;
561
562 if (fFlags & VBOX_MOUSE_POINTER_SHAPE)
563 {
564 /* Size of the pointer data: sizeof (AND mask) + sizeof (XOR_MASK) */
565 cbData = ((((cWidth + 7) / 8) * cHeight + 3) & ~3)
566 + cWidth * 4 * cHeight;
567 /* If shape is supplied, then always create the pointer visible.
568 * See comments in 'vboxUpdatePointerShape'
569 */
570 fFlags |= VBOX_MOUSE_POINTER_VISIBLE;
571 }
572 LogFlowFunc(("cbData %d, %dx%d\n", cbData, cWidth, cHeight));
573 if (cbData > cbLength)
574 {
575 LogFunc(("calculated pointer data size is too big (%d bytes, limit %d)\n",
576 cbData, cbLength));
577 return VERR_INVALID_PARAMETER;
578 }
579 /* Allocate the IO buffer. */
580 p = (VBVAMOUSEPOINTERSHAPE *)VBoxHGSMIBufferAlloc(pCtx,
581 sizeof(VBVAMOUSEPOINTERSHAPE)
582 + cbData,
583 HGSMI_CH_VBVA,
584 VBVA_MOUSE_POINTER_SHAPE);
585 if (p)
586 {
587 /* Prepare data to be sent to the host. */
588 /* Will be updated by the host. */
589 p->i32Result = VINF_SUCCESS;
590 /* We have our custom flags in the field */
591 p->fu32Flags = fFlags;
592 p->u32HotX = cHotX;
593 p->u32HotY = cHotY;
594 p->u32Width = cWidth;
595 p->u32Height = cHeight;
596 if (p->fu32Flags & VBOX_MOUSE_POINTER_SHAPE)
597 /* Copy the actual pointer data. */
598 memcpy (p->au8Data, pPixels, cbData);
599 rc = VBoxHGSMIBufferSubmit(pCtx, p);
600 if (RT_SUCCESS(rc))
601 rc = p->i32Result;
602 /* Free the IO buffer. */
603 VBoxHGSMIBufferFree(pCtx, p);
604 }
605 else
606 rc = VERR_NO_MEMORY;
607 LogFlowFunc(("rc %d\n", rc));
608 return rc;
609}
610
611
612/**
613 * Report the guest cursor position. The host may wish to use this information
614 * to re-position its own cursor (though this is currently unlikely). The
615 * current host cursor position is returned.
616 * @param pCtx The context containing the heap used.
617 * @param fReportPosition Are we reporting a position?
618 * @param x Guest cursor X position.
619 * @param y Guest cursor Y position.
620 * @param pxHost Host cursor X position is stored here. Optional.
621 * @param pyHost Host cursor Y position is stored here. Optional.
622 * @returns iprt status code.
623 * @returns VERR_NO_MEMORY HGSMI heap allocation failed.
624 */
625RTDECL(int) VBoxHGSMICursorPosition(PHGSMIGUESTCOMMANDCONTEXT pCtx, bool fReportPosition, uint32_t x, uint32_t y,
626 uint32_t *pxHost, uint32_t *pyHost)
627{
628 int rc = VINF_SUCCESS;
629 VBVACURSORPOSITION *p;
630 Log(("%s: x=%u, y=%u\n", __PRETTY_FUNCTION__, (unsigned)x, (unsigned)y));
631
632 /* Allocate the IO buffer. */
633 p = (VBVACURSORPOSITION *)VBoxHGSMIBufferAlloc(pCtx, sizeof(VBVACURSORPOSITION), HGSMI_CH_VBVA, VBVA_CURSOR_POSITION);
634 if (p)
635 {
636 /* Prepare data to be sent to the host. */
637 p->fReportPosition = fReportPosition ? 1 : 0;
638 p->x = x;
639 p->y = y;
640 rc = VBoxHGSMIBufferSubmit(pCtx, p);
641 if (RT_SUCCESS(rc))
642 {
643 if (pxHost)
644 *pxHost = p->x;
645 if (pyHost)
646 *pyHost = p->y;
647 Log(("%s: return: x=%u, y=%u\n", __PRETTY_FUNCTION__, (unsigned)x, (unsigned)y));
648 }
649 /* Free the IO buffer. */
650 VBoxHGSMIBufferFree(pCtx, p);
651 }
652 else
653 rc = VERR_NO_MEMORY;
654 LogFunc(("rc = %d\n", rc));
655 return rc;
656}
657
658
659/** @todo Mouse pointer position to be read from VMMDev memory, address of the memory region
660 * can be queried from VMMDev via an IOCTL. This VMMDev memory region will contain
661 * host information which is needed by the guest.
662 *
663 * Reading will not cause a switch to the host.
664 *
665 * Have to take into account:
666 * * synchronization: host must write to the memory only from EMT,
667 * large structures must be read under flag, which tells the host
668 * that the guest is currently reading the memory (OWNER flag?).
669 * * guest writes: may be allocate a page for the host info and make
670 * the page readonly for the guest.
671 * * the information should be available only for additions drivers.
672 * * VMMDev additions driver will inform the host which version of the info it expects,
673 * host must support all versions.
674 *
675 */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette