VirtualBox

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

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

Additions/x11: temporary check-in of new X11 Additions resizing code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.8 KB
Line 
1/* $Id: HGSMIBase.cpp 55043 2015-03-31 15:59:35Z vboxsync $ */
2/** @file
3 * VirtualBox Video driver, common code - HGSMI initialisation and helper
4 * functions.
5 */
6
7/*
8 * Copyright (C) 2006-2012 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, HGSMI_HEAP_TYPE_MA, pvGuestHeapMemory,
344 cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
345#else
346 return HGSMIHeapSetup(&pCtx->heapCtx, HGSMI_HEAP_TYPE_MA, 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 pulValue where to store the value of the parameter on success
495 */
496RTDECL(int) VBoxQueryConfHGSMI(PHGSMIGUESTCOMMANDCONTEXT pCtx,
497 uint32_t u32Index, uint32_t *pulValue)
498{
499 int rc = VINF_SUCCESS;
500 VBVACONF32 *p;
501 LogFunc(("u32Index = %d\n", u32Index));
502
503 rc = testQueryConf(pCtx);
504 if (RT_FAILURE(rc))
505 return rc;
506 /* Allocate the IO buffer. */
507 p = (VBVACONF32 *)VBoxHGSMIBufferAlloc(pCtx,
508 sizeof(VBVACONF32), HGSMI_CH_VBVA,
509 VBVA_QUERY_CONF32);
510 if (p)
511 {
512 /* Prepare data to be sent to the host. */
513 p->u32Index = u32Index;
514 p->u32Value = UINT32_MAX;
515 rc = VBoxHGSMIBufferSubmit(pCtx, p);
516 if (RT_SUCCESS(rc))
517 {
518 *pulValue = p->u32Value;
519 LogFunc(("u32Value = %d\n", p->u32Value));
520 }
521 /* Free the IO buffer. */
522 VBoxHGSMIBufferFree(pCtx, p);
523 }
524 else
525 rc = VERR_NO_MEMORY;
526 LogFunc(("rc = %d\n", rc));
527 return rc;
528}
529
530
531/**
532 * Pass the host a new mouse pointer shape via an HGSMI command.
533 *
534 * @returns success or failure
535 * @param fFlags cursor flags, @see VMMDevReqMousePointer::fFlags
536 * @param cHotX horizontal position of the hot spot
537 * @param cHotY vertical position of the hot spot
538 * @param cWidth width in pixels of the cursor
539 * @param cHeight height in pixels of the cursor
540 * @param pPixels pixel data, @see VMMDevReqMousePointer for the format
541 * @param cbLength size in bytes of the pixel data
542 */
543RTDECL(int) VBoxHGSMIUpdatePointerShape(PHGSMIGUESTCOMMANDCONTEXT pCtx,
544 uint32_t fFlags,
545 uint32_t cHotX,
546 uint32_t cHotY,
547 uint32_t cWidth,
548 uint32_t cHeight,
549 uint8_t *pPixels,
550 uint32_t cbLength)
551{
552 VBVAMOUSEPOINTERSHAPE *p;
553 uint32_t cbData = 0;
554 int rc = VINF_SUCCESS;
555
556 if (fFlags & VBOX_MOUSE_POINTER_SHAPE)
557 {
558 /* Size of the pointer data: sizeof (AND mask) + sizeof (XOR_MASK) */
559 cbData = ((((cWidth + 7) / 8) * cHeight + 3) & ~3)
560 + cWidth * 4 * cHeight;
561 /* If shape is supplied, then always create the pointer visible.
562 * See comments in 'vboxUpdatePointerShape'
563 */
564 fFlags |= VBOX_MOUSE_POINTER_VISIBLE;
565 }
566 LogFlowFunc(("cbData %d, %dx%d\n", cbData, cWidth, cHeight));
567 if (cbData > cbLength)
568 {
569 LogFunc(("calculated pointer data size is too big (%d bytes, limit %d)\n",
570 cbData, cbLength));
571 return VERR_INVALID_PARAMETER;
572 }
573 /* Allocate the IO buffer. */
574 p = (VBVAMOUSEPOINTERSHAPE *)VBoxHGSMIBufferAlloc(pCtx,
575 sizeof(VBVAMOUSEPOINTERSHAPE)
576 + cbData,
577 HGSMI_CH_VBVA,
578 VBVA_MOUSE_POINTER_SHAPE);
579 if (p)
580 {
581 /* Prepare data to be sent to the host. */
582 /* Will be updated by the host. */
583 p->i32Result = VINF_SUCCESS;
584 /* We have our custom flags in the field */
585 p->fu32Flags = fFlags;
586 p->u32HotX = cHotX;
587 p->u32HotY = cHotY;
588 p->u32Width = cWidth;
589 p->u32Height = cHeight;
590 if (p->fu32Flags & VBOX_MOUSE_POINTER_SHAPE)
591 /* Copy the actual pointer data. */
592 memcpy (p->au8Data, pPixels, cbData);
593 rc = VBoxHGSMIBufferSubmit(pCtx, p);
594 if (RT_SUCCESS(rc))
595 rc = p->i32Result;
596 /* Free the IO buffer. */
597 VBoxHGSMIBufferFree(pCtx, p);
598 }
599 else
600 rc = VERR_NO_MEMORY;
601 LogFlowFunc(("rc %d\n", rc));
602 return rc;
603}
604
605
606/**
607 * Report the guest cursor position. The host may wish to use this information
608 * to re-position its own cursor (though this is currently unlikely). The
609 * current host cursor position is returned.
610 * @param pCtx The context containing the heap used.
611 * @param fReportPosition Are we reporting a position?
612 * @param x Guest cursor X position.
613 * @param y Guest cursor Y position.
614 * @param pxHost Host cursor X position is stored here. Optional.
615 * @param pyHost Host cursor Y position is stored here. Optional.
616 * @returns iprt status code.
617 * @returns VERR_NO_MEMORY HGSMI heap allocation failed.
618 */
619RTDECL(int) VBoxHGSMICursorPosition(PHGSMIGUESTCOMMANDCONTEXT pCtx, bool fReportPosition, uint32_t x, uint32_t y,
620 uint32_t *pxHost, uint32_t *pyHost)
621{
622 int rc = VINF_SUCCESS;
623 VBVACURSORPOSITION *p;
624 Log(("%s: x=%u, y=%u\n", __PRETTY_FUNCTION__, (unsigned)x, (unsigned)y));
625
626 /* Allocate the IO buffer. */
627 p = (VBVACURSORPOSITION *)VBoxHGSMIBufferAlloc(pCtx, sizeof(VBVACURSORPOSITION), HGSMI_CH_VBVA, VBVA_CURSOR_POSITION);
628 if (p)
629 {
630 /* Prepare data to be sent to the host. */
631 p->fReportPosition = fReportPosition ? 1 : 0;
632 p->x = x;
633 p->y = y;
634 rc = VBoxHGSMIBufferSubmit(pCtx, p);
635 if (RT_SUCCESS(rc))
636 {
637 if (pxHost)
638 *pxHost = p->x;
639 if (pyHost)
640 *pyHost = p->y;
641 Log(("%s: return: x=%u, y=%u\n", __PRETTY_FUNCTION__, (unsigned)x, (unsigned)y));
642 }
643 /* Free the IO buffer. */
644 VBoxHGSMIBufferFree(pCtx, p);
645 }
646 else
647 rc = VERR_NO_MEMORY;
648 LogFunc(("rc = %d\n", rc));
649 return rc;
650}
651
652
653/** @todo Mouse pointer position to be read from VMMDev memory, address of the memory region
654 * can be queried from VMMDev via an IOCTL. This VMMDev memory region will contain
655 * host information which is needed by the guest.
656 *
657 * Reading will not cause a switch to the host.
658 *
659 * Have to take into account:
660 * * synchronization: host must write to the memory only from EMT,
661 * large structures must be read under flag, which tells the host
662 * that the guest is currently reading the memory (OWNER flag?).
663 * * guest writes: may be allocate a page for the host info and make
664 * the page readonly for the guest.
665 * * the information should be available only for additions drivers.
666 * * VMMDev additions driver will inform the host which version of the info it expects,
667 * host must support all versions.
668 *
669 */
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