VirtualBox

Changeset 67066 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
May 24, 2017 1:37:42 PM (8 years ago)
Author:
vboxsync
Message:

bugref:8524: Additions/linux: play nicely with distribution-installed Additions
Re-arrange the file structure of the guest graphics APIs to make it easier to only include the necessary parts in the Linux vboxvideo driver.

Location:
trunk/src/VBox/Additions/common/VBoxVideo
Files:
1 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp

    r67065 r67066  
    2929#include <VBoxVideoVBE.h>
    3030#include <VBoxVideoIPRT.h>
    31 
    32 /**
    33  * Set up the HGSMI guest-to-host command context.
    34  * @returns iprt status value
    35  * @param  pCtx                    the context to set up
    36  * @param  pvGuestHeapMemory       a pointer to the mapped backing memory for
    37  *                                 the guest heap
    38  * @param  cbGuestHeapMemory       the size of the backing memory area
    39  * @param  offVRAMGuestHeapMemory  the offset of the memory pointed to by
    40  *                                 @a pvGuestHeapMemory within the video RAM
    41  * @param  pEnv                    HGSMI environment.
    42  */
    43 DECLHIDDEN(int) VBoxHGSMISetupGuestContext(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    44                                            void *pvGuestHeapMemory,
    45                                            uint32_t cbGuestHeapMemory,
    46                                            uint32_t offVRAMGuestHeapMemory,
    47                                            const HGSMIENV *pEnv)
    48 {
    49     /** @todo should we be using a fixed ISA port value here? */
    50     pCtx->port = (RTIOPORT)VGA_PORT_HGSMI_GUEST;
    51 #ifdef VBOX_WDDM_MINIPORT
    52     return VBoxSHGSMIInit(&pCtx->heapCtx, pvGuestHeapMemory,
    53                           cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
    54 #else
    55     return HGSMIHeapSetup(&pCtx->heapCtx, pvGuestHeapMemory,
    56                           cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
    57 #endif
    58 }
    59 
    60 
    61 /**
    62  * Allocate and initialise a command descriptor in the guest heap for a
    63  * guest-to-host command.
    64  *
    65  * @returns  pointer to the descriptor's command data buffer
    66  * @param  pCtx     the context containing the heap to be used
    67  * @param  cbData   the size of the command data to go into the descriptor
    68  * @param  u8Ch     the HGSMI channel to be used, set to the descriptor
    69  * @param  u16Op    the HGSMI command to be sent, set to the descriptor
    70  */
    71 DECLHIDDEN(void *) VBoxHGSMIBufferAlloc(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    72                                         HGSMISIZE cbData,
    73                                         uint8_t u8Ch,
    74                                         uint16_t u16Op)
    75 {
    76 #ifdef VBOX_WDDM_MINIPORT
    77     return VBoxSHGSMIHeapAlloc (&pCtx->heapCtx, cbData, u8Ch, u16Op);
    78 #else
    79     return HGSMIHeapAlloc (&pCtx->heapCtx, cbData, u8Ch, u16Op);
    80 #endif
    81 }
    82 
    83 
    84 /**
    85  * Free a descriptor allocated by @a VBoxHGSMIBufferAlloc.
    86  *
    87  * @param  pCtx      the context containing the heap used
    88  * @param  pvBuffer  the pointer returned by @a VBoxHGSMIBufferAlloc
    89  */
    90 DECLHIDDEN(void) VBoxHGSMIBufferFree(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    91                                      void *pvBuffer)
    92 {
    93 #ifdef VBOX_WDDM_MINIPORT
    94     VBoxSHGSMIHeapFree (&pCtx->heapCtx, pvBuffer);
    95 #else
    96     HGSMIHeapFree (&pCtx->heapCtx, pvBuffer);
    97 #endif
    98 }
    99 
    10031
    10132/**
  • trunk/src/VBox/Additions/common/VBoxVideo/HGSMIBufferAlloc.cpp

    r66696 r67066  
    11/* $Id$ */
    22/** @file
    3  * VirtualBox Video driver, common code - HGSMI guest-to-host communication.
     3 * VirtualBox Video driver, common code - HGSMI buffer management.
    44 */
    55
     
    9797#endif
    9898}
    99 
    100 
    101 /**
    102  * Submit a command descriptor allocated by @a VBoxHGSMIBufferAlloc.
    103  *
    104  * @param  pCtx      the context containing the heap used
    105  * @param  pvBuffer  the pointer returned by @a VBoxHGSMIBufferAlloc
    106  */
    107 DECLHIDDEN(int) VBoxHGSMIBufferSubmit(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    108                                       void *pvBuffer)
    109 {
    110     /* Initialize the buffer and get the offset for port IO. */
    111     HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (HGSMIGUESTCMDHEAP_GET(&pCtx->heapCtx), pvBuffer);
    112 
    113     Assert(offBuffer != HGSMIOFFSET_VOID);
    114     if (offBuffer != HGSMIOFFSET_VOID)
    115     {
    116         /* Submit the buffer to the host. */
    117         VBVO_PORT_WRITE_U32(pCtx->port, offBuffer);
    118         /* Make the compiler aware that the host has changed memory. */
    119         ASMCompilerBarrier();
    120         return VINF_SUCCESS;
    121     }
    122 
    123     return VERR_INVALID_PARAMETER;
    124 }
    125 
    126 
    127 /** Detect whether HGSMI is supported by the host. */
    128 DECLHIDDEN(bool) VBoxHGSMIIsSupported(void)
    129 {
    130     uint16_t DispiId;
    131 
    132     VBVO_PORT_WRITE_U16(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ID);
    133     VBVO_PORT_WRITE_U16(VBE_DISPI_IOPORT_DATA, VBE_DISPI_ID_HGSMI);
    134 
    135     DispiId = VBVO_PORT_READ_U16(VBE_DISPI_IOPORT_DATA);
    136 
    137     return (DispiId == VBE_DISPI_ID_HGSMI);
    138 }
    139 
    140 
    141 /**
    142  * Inform the host of the location of the host flags in VRAM via an HGSMI
    143  * command.
    144  * @returns  IPRT status value.
    145  * @returns  VERR_NOT_IMPLEMENTED  if the host does not support the command.
    146  * @returns  VERR_NO_MEMORY        if a heap allocation fails.
    147  * @param    pCtx                  the context of the guest heap to use.
    148  * @param    offLocation           the offset chosen for the flags withing guest
    149  *                                 VRAM.
    150  */
    151 DECLHIDDEN(int) VBoxHGSMIReportFlagsLocation(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    152                                              HGSMIOFFSET offLocation)
    153 {
    154     HGSMIBUFFERLOCATION *p;
    155     int rc = VINF_SUCCESS;
    156 
    157     /* Allocate the IO buffer. */
    158     p = (HGSMIBUFFERLOCATION *)VBoxHGSMIBufferAlloc(pCtx,
    159                                               sizeof(HGSMIBUFFERLOCATION),
    160                                               HGSMI_CH_HGSMI,
    161                                               HGSMI_CC_HOST_FLAGS_LOCATION);
    162     if (p)
    163     {
    164         /* Prepare data to be sent to the host. */
    165         p->offLocation = offLocation;
    166         p->cbLocation  = sizeof(HGSMIHOSTFLAGS);
    167         rc = VBoxHGSMIBufferSubmit(pCtx, p);
    168         /* Free the IO buffer. */
    169         VBoxHGSMIBufferFree(pCtx, p);
    170     }
    171     else
    172         rc = VERR_NO_MEMORY;
    173     return rc;
    174 }
    175 
    176 
    177 /**
    178  * Notify the host of HGSMI-related guest capabilities via an HGSMI command.
    179  * @returns  IPRT status value.
    180  * @returns  VERR_NOT_IMPLEMENTED  if the host does not support the command.
    181  * @returns  VERR_NO_MEMORY        if a heap allocation fails.
    182  * @param    pCtx                  the context of the guest heap to use.
    183  * @param    fCaps                 the capabilities to report, see VBVACAPS.
    184  */
    185 DECLHIDDEN(int) VBoxHGSMISendCapsInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    186                                       uint32_t fCaps)
    187 {
    188     VBVACAPS *pCaps;
    189     int rc = VINF_SUCCESS;
    190 
    191     /* Allocate the IO buffer. */
    192     pCaps = (VBVACAPS *)VBoxHGSMIBufferAlloc(pCtx,
    193                                        sizeof(VBVACAPS), HGSMI_CH_VBVA,
    194                                        VBVA_INFO_CAPS);
    195 
    196     if (pCaps)
    197     {
    198         /* Prepare data to be sent to the host. */
    199         pCaps->rc    = VERR_NOT_IMPLEMENTED;
    200         pCaps->fCaps = fCaps;
    201         rc = VBoxHGSMIBufferSubmit(pCtx, pCaps);
    202         if (RT_SUCCESS(rc))
    203         {
    204             AssertRC(pCaps->rc);
    205             rc = pCaps->rc;
    206         }
    207         /* Free the IO buffer. */
    208         VBoxHGSMIBufferFree(pCtx, pCaps);
    209     }
    210     else
    211         rc = VERR_NO_MEMORY;
    212     return rc;
    213 }
    214 
    215 
    216 /**
    217  * Get the information needed to map the basic communication structures in
    218  * device memory into our address space.  All pointer parameters are optional.
    219  *
    220  * @param  cbVRAM               how much video RAM is allocated to the device
    221  * @param  poffVRAMBaseMapping  where to save the offset from the start of the
    222  *                              device VRAM of the whole area to map
    223  * @param  pcbMapping           where to save the mapping size
    224  * @param  poffGuestHeapMemory  where to save the offset into the mapped area
    225  *                              of the guest heap backing memory
    226  * @param  pcbGuestHeapMemory   where to save the size of the guest heap
    227  *                              backing memory
    228  * @param  poffHostFlags        where to save the offset into the mapped area
    229  *                              of the host flags
    230  */
    231 DECLHIDDEN(void) VBoxHGSMIGetBaseMappingInfo(uint32_t cbVRAM,
    232                                              uint32_t *poffVRAMBaseMapping,
    233                                              uint32_t *pcbMapping,
    234                                              uint32_t *poffGuestHeapMemory,
    235                                              uint32_t *pcbGuestHeapMemory,
    236                                              uint32_t *poffHostFlags)
    237 {
    238     AssertPtrNullReturnVoid(poffVRAMBaseMapping);
    239     AssertPtrNullReturnVoid(pcbMapping);
    240     AssertPtrNullReturnVoid(poffGuestHeapMemory);
    241     AssertPtrNullReturnVoid(pcbGuestHeapMemory);
    242     AssertPtrNullReturnVoid(poffHostFlags);
    243     if (poffVRAMBaseMapping)
    244         *poffVRAMBaseMapping = cbVRAM - VBVA_ADAPTER_INFORMATION_SIZE;
    245     if (pcbMapping)
    246         *pcbMapping = VBVA_ADAPTER_INFORMATION_SIZE;
    247     if (poffGuestHeapMemory)
    248         *poffGuestHeapMemory = 0;
    249     if (pcbGuestHeapMemory)
    250         *pcbGuestHeapMemory =   VBVA_ADAPTER_INFORMATION_SIZE
    251                               - sizeof(HGSMIHOSTFLAGS);
    252     if (poffHostFlags)
    253         *poffHostFlags =   VBVA_ADAPTER_INFORMATION_SIZE
    254                          - sizeof(HGSMIHOSTFLAGS);
    255 }
    256 
    257 
    258 /** Sanity test on first call.  We do not worry about concurrency issues. */
    259 static int testQueryConf(PHGSMIGUESTCOMMANDCONTEXT pCtx)
    260 {
    261     static bool cOnce = false;
    262     uint32_t ulValue = 0;
    263     int rc;
    264 
    265     if (cOnce)
    266         return VINF_SUCCESS;
    267     cOnce = true;
    268     rc = VBoxQueryConfHGSMI(pCtx, UINT32_MAX, &ulValue);
    269     if (RT_SUCCESS(rc) && ulValue == UINT32_MAX)
    270         return VINF_SUCCESS;
    271     cOnce = false;
    272     if (RT_FAILURE(rc))
    273         return rc;
    274     return VERR_INTERNAL_ERROR;
    275 }
    276 
    277 
    278 /**
    279  * Query the host for an HGSMI configuration parameter via an HGSMI command.
    280  * @returns iprt status value
    281  * @param  pCtx      the context containing the heap used
    282  * @param  u32Index  the index of the parameter to query,
    283  *                   @see VBVACONF32::u32Index
    284  * @param  u32DefValue defaut value
    285  * @param  pulValue  where to store the value of the parameter on success
    286  */
    287 DECLHIDDEN(int) VBoxQueryConfHGSMIDef(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    288                                       uint32_t u32Index, uint32_t u32DefValue, uint32_t *pulValue)
    289 {
    290     int rc = VINF_SUCCESS;
    291     VBVACONF32 *p;
    292     // LogFunc(("u32Index = %d\n", u32Index));
    293 
    294     rc = testQueryConf(pCtx);
    295     if (RT_FAILURE(rc))
    296         return rc;
    297     /* Allocate the IO buffer. */
    298     p = (VBVACONF32 *)VBoxHGSMIBufferAlloc(pCtx,
    299                                      sizeof(VBVACONF32), HGSMI_CH_VBVA,
    300                                      VBVA_QUERY_CONF32);
    301     if (p)
    302     {
    303         /* Prepare data to be sent to the host. */
    304         p->u32Index = u32Index;
    305         p->u32Value = u32DefValue;
    306         rc = VBoxHGSMIBufferSubmit(pCtx, p);
    307         if (RT_SUCCESS(rc))
    308         {
    309             *pulValue = p->u32Value;
    310             // LogFunc(("u32Value = %d\n", p->u32Value));
    311         }
    312         /* Free the IO buffer. */
    313         VBoxHGSMIBufferFree(pCtx, p);
    314     }
    315     else
    316         rc = VERR_NO_MEMORY;
    317     // LogFunc(("rc = %d\n", rc));
    318     return rc;
    319 }
    320 
    321 DECLHIDDEN(int) VBoxQueryConfHGSMI(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    322                                    uint32_t u32Index, uint32_t *pulValue)
    323 {
    324     return VBoxQueryConfHGSMIDef(pCtx, u32Index, UINT32_MAX, pulValue);
    325 }
    326 
    327 /**
    328  * Pass the host a new mouse pointer shape via an HGSMI command.
    329  *
    330  * @returns  success or failure
    331  * @param  pCtx      the context containing the heap to be used
    332  * @param  fFlags    cursor flags, @see VMMDevReqMousePointer::fFlags
    333  * @param  cHotX     horizontal position of the hot spot
    334  * @param  cHotY     vertical position of the hot spot
    335  * @param  cWidth    width in pixels of the cursor
    336  * @param  cHeight   height in pixels of the cursor
    337  * @param  pPixels   pixel data, @see VMMDevReqMousePointer for the format
    338  * @param  cbLength  size in bytes of the pixel data
    339  */
    340 DECLHIDDEN(int)  VBoxHGSMIUpdatePointerShape(PHGSMIGUESTCOMMANDCONTEXT pCtx,
    341                                              uint32_t fFlags,
    342                                              uint32_t cHotX,
    343                                              uint32_t cHotY,
    344                                              uint32_t cWidth,
    345                                              uint32_t cHeight,
    346                                              uint8_t *pPixels,
    347                                              uint32_t cbLength)
    348 {
    349     VBVAMOUSEPOINTERSHAPE *p;
    350     uint32_t cbData = 0;
    351     int rc = VINF_SUCCESS;
    352 
    353     if (fFlags & VBOX_MOUSE_POINTER_SHAPE)
    354     {
    355         /* Size of the pointer data: sizeof (AND mask) + sizeof (XOR_MASK) */
    356         cbData = ((((cWidth + 7) / 8) * cHeight + 3) & ~3)
    357                  + cWidth * 4 * cHeight;
    358         /* If shape is supplied, then always create the pointer visible.
    359          * See comments in 'vboxUpdatePointerShape'
    360          */
    361         fFlags |= VBOX_MOUSE_POINTER_VISIBLE;
    362     }
    363     // LogFlowFunc(("cbData %d, %dx%d\n", cbData, cWidth, cHeight));
    364     if (cbData > cbLength)
    365     {
    366         // LogFunc(("calculated pointer data size is too big (%d bytes, limit %d)\n",
    367         //          cbData, cbLength));
    368         return VERR_INVALID_PARAMETER;
    369     }
    370     /* Allocate the IO buffer. */
    371     p = (VBVAMOUSEPOINTERSHAPE *)VBoxHGSMIBufferAlloc(pCtx,
    372                                                   sizeof(VBVAMOUSEPOINTERSHAPE)
    373                                                 + cbData,
    374                                                 HGSMI_CH_VBVA,
    375                                                 VBVA_MOUSE_POINTER_SHAPE);
    376     if (p)
    377     {
    378         /* Prepare data to be sent to the host. */
    379         /* Will be updated by the host. */
    380         p->i32Result = VINF_SUCCESS;
    381         /* We have our custom flags in the field */
    382         p->fu32Flags = fFlags;
    383         p->u32HotX   = cHotX;
    384         p->u32HotY   = cHotY;
    385         p->u32Width  = cWidth;
    386         p->u32Height = cHeight;
    387         if (p->fu32Flags & VBOX_MOUSE_POINTER_SHAPE)
    388             /* Copy the actual pointer data. */
    389             memcpy (p->au8Data, pPixels, cbData);
    390         rc = VBoxHGSMIBufferSubmit(pCtx, p);
    391         if (RT_SUCCESS(rc))
    392             rc = p->i32Result;
    393         /* Free the IO buffer. */
    394         VBoxHGSMIBufferFree(pCtx, p);
    395     }
    396     else
    397         rc = VERR_NO_MEMORY;
    398     // LogFlowFunc(("rc %d\n", rc));
    399     return rc;
    400 }
    401 
    402 
    403 /**
    404  * Report the guest cursor position.  The host may wish to use this information
    405  * to re-position its own cursor (though this is currently unlikely).  The
    406  * current host cursor position is returned.
    407  * @param  pCtx             The context containing the heap used.
    408  * @param  fReportPosition  Are we reporting a position?
    409  * @param  x                Guest cursor X position.
    410  * @param  y                Guest cursor Y position.
    411  * @param  pxHost           Host cursor X position is stored here.  Optional.
    412  * @param  pyHost           Host cursor Y position is stored here.  Optional.
    413  * @returns  iprt status code.
    414  * @returns  VERR_NO_MEMORY      HGSMI heap allocation failed.
    415  */
    416 DECLHIDDEN(int) VBoxHGSMICursorPosition(PHGSMIGUESTCOMMANDCONTEXT pCtx, bool fReportPosition, uint32_t x, uint32_t y,
    417                                         uint32_t *pxHost, uint32_t *pyHost)
    418 {
    419     int rc = VINF_SUCCESS;
    420     VBVACURSORPOSITION *p;
    421     // Log(("%s: x=%u, y=%u\n", __PRETTY_FUNCTION__, (unsigned)x, (unsigned)y));
    422 
    423     /* Allocate the IO buffer. */
    424     p = (VBVACURSORPOSITION *)VBoxHGSMIBufferAlloc(pCtx, sizeof(VBVACURSORPOSITION), HGSMI_CH_VBVA, VBVA_CURSOR_POSITION);
    425     if (p)
    426     {
    427         /* Prepare data to be sent to the host. */
    428         p->fReportPosition = fReportPosition ? 1 : 0;
    429         p->x = x;
    430         p->y = y;
    431         rc = VBoxHGSMIBufferSubmit(pCtx, p);
    432         if (RT_SUCCESS(rc))
    433         {
    434             if (pxHost)
    435                 *pxHost = p->x;
    436             if (pyHost)
    437                 *pyHost = p->y;
    438             // Log(("%s: return: x=%u, y=%u\n", __PRETTY_FUNCTION__, (unsigned)p->x, (unsigned)p->y));
    439         }
    440         /* Free the IO buffer. */
    441         VBoxHGSMIBufferFree(pCtx, p);
    442     }
    443     else
    444         rc = VERR_NO_MEMORY;
    445     // LogFunc(("rc = %d\n", rc));
    446     return rc;
    447 }
    448 
    449 
    450 /** @todo Mouse pointer position to be read from VMMDev memory, address of the memory region
    451  * can be queried from VMMDev via an IOCTL. This VMMDev memory region will contain
    452  * host information which is needed by the guest.
    453  *
    454  * Reading will not cause a switch to the host.
    455  *
    456  * Have to take into account:
    457  *  * synchronization: host must write to the memory only from EMT,
    458  *    large structures must be read under flag, which tells the host
    459  *    that the guest is currently reading the memory (OWNER flag?).
    460  *  * guest writes: may be allocate a page for the host info and make
    461  *    the page readonly for the guest.
    462  *  * the information should be available only for additions drivers.
    463  *  * VMMDev additions driver will inform the host which version of the info it expects,
    464  *    host must support all versions.
    465  *
    466  */
  • trunk/src/VBox/Additions/common/VBoxVideo/HGSMIHostCmd.cpp

    r67065 r67066  
    2929#include <VBoxVideoVBE.h>
    3030#include <VBoxVideoIPRT.h>
     31#include <HGSMIHostCmd.h>
    3132
    3233/**
Note: See TracChangeset for help on using the changeset viewer.

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