vboxutils_68.c revision b72771e8c6ba3b3d9ebdd7977730325131ae0f98
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Linux Additions X11 graphics driver helper module
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * available from http://www.virtualbox.org. This file is free software;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * General Public License (GPL) as published by the Free Software
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * additional information or have any questions.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define TRACE_ENTRY() do \
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define TRACE_LINE() do \
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync ErrorF ("%s: line %d\n", __FUNCTION__, __LINE__); \
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define PUT_PIXEL(c) do { } while(0)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define TRACE_ENTRY() do { } while(0)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define TRACE_LINE() do { } while(0)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define dolog(...) do { } while(0)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Macro to printf an error message and return from a function */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncstatic void vbox_show_shape (unsigned short w, unsigned short h,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync unsigned short pitch;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync unsigned char *mask;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync image += offsetof (VMMDevReqMousePointer, pointerData);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync for (x = 0; x < w; ++x)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncstatic Bool vbox_vmmcall (ScrnInfoPtr pScrn, VBOXPtr pVBox,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync err = ioctl (pVBox->vbox_fd, VBOXGUEST_IOCTL_VMMREQUEST(hdrp->size), hdrp);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @todo this should work fine on other platforms too, but it needs to be
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * checked for each one.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Ioctl call failed during a request to the virtual machine: %s\n",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "A request to the virtual machine returned %d\n",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* success */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync int vrc = vmmdevInitRequest ((VMMDevRequestHeader*)&req, VMMDevReq_GetMouseStatus);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Unable to determine whether the virtual machine supports mouse pointer integration - request initialization failed with return code %d\n", rc);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync && (ioctl(pVBox->vbox_fd, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(req)), (void*)&req) < 0))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Unable to determine whether the virtual machine supports mouse pointer integration - request system call failed: %s.\n",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync && !(req.mouseFeatures & VBOXGUEST_MOUSE_HOST_CANNOT_HWPOINTER)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync && (req.mouseFeatures & VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Unable to close the virtual machine device (file %d): %s\n",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Macro to disable VBVA extensions and return, for use when an
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * unexplained error occurs.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync xf86DrvMsg(pScrn->scrnIndex, X_ERROR, __VA_ARGS__); \
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Callback function called by the X server to tell us about dirty
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * rectangles in the video buffer.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pScreen pointer to the information structure for the current
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param iRects Number of dirty rectangles to update
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param aRects Array of structures containing the coordinates of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * rectangles
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncvboxHandleDirtyRect(ScrnInfoPtr pScrn, int iRects, BoxPtr aRects)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Just return quietly if VBVA is not currently active. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if ((pMem->fu32ModeFlags & VBVA_F_MODE_ENABLED) == 0)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync for (i = 0; i < iRects; i++)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cmdHdr.x = (int16_t)aRects[i].x1 - pVBox->viewportX;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cmdHdr.y = (int16_t)aRects[i].y1 - pVBox->viewportY;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cmdHdr.w = (uint16_t)(aRects[i].x2 - aRects[i].x1);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cmdHdr.h = (uint16_t)(aRects[i].y2 - aRects[i].y1);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Get the active record and move the pointer along */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* All slots in the records queue are used. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Unable to clear the VirtualBox graphics acceleration queue "
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "- the request to the virtual machine failed. Switching to "
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "unaccelerated mode.\n");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Failed to clear the VirtualBox graphics acceleration queue. "
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Switching to unaccelerated mode.\n");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Mark the record as being updated. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Compute how many bytes we have in the ring buffer. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Free is writing position. Data is reading position.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Data == Free means buffer is free.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * There must be always gap between free and data when data
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * are in the buffer.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Guest only changes free, host only changes data.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cbHwBufferAvail = i32Diff > 0? i32Diff: VBVA_RING_BUFFER_SIZE
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Unable to clear the VirtualBox graphics acceleration queue "
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "- the request to the virtual machine failed. Switching to "
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "unaccelerated mode.\n");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Calculate the free space again. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "No space left in the VirtualBox graphics acceleration command buffer, "
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "despite clearing the queue. Switching to unaccelerated mode.\n");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Now copy the data into the buffer */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (off32Free + sizeof(cmdHdr) < VBVA_RING_BUFFER_SIZE)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pMem->off32Free = pMem->off32Free + sizeof(cmdHdr);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync CARD32 u32First = VBVA_RING_BUFFER_SIZE - off32Free;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* The following is impressively ugly! */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync memcpy(&pMem->au8RingBuffer[off32Free], &cmdHdr, u32First);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync memcpy(&pMem->au8RingBuffer[0], (void *)pu8Second, u32Second);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Mark the record completed. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Initialise VirtualBox's accelerated video extensions.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Note that we assume that the PCI memory is 32bit mapped,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * as X doesn't seem to support mapping 64bit memory.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns True on success, false on failure
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncvboxInitVbva(int scrnIndex, ScreenPtr pScreen, VBOXPtr pVBox)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Locate the device. It should already have been enabled by
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync the kernel driver. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pciTag = pciFindFirst((unsigned) VMMDEV_DEVICEID << 16 | VMMDEV_VENDORID,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Could not find the VirtualBox base device on the PCI bus.\n");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Read the address and size of the second I/O region. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pciAddress = pciReadLong(pciTag, PCI_MAP_REG_START + 4);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "The VirtualBox base device contains an invalid memory address.\n");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "The VirtualBox base device has a 64bit mapping address. "
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "This is currently not supported.\n");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Map it. We hardcode the size as X does not export the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync function needed to determine it. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pVBox->pVMMDevMemory = xf86MapPciMem(scrnIndex, 0, pciTag, pciAddress,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "Failed to map VirtualBox video extension memory.\n");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pVBox->pVbvaMemory = &pVBox->pVMMDevMemory->vbvaMemory;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Initialise requests */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pVBox->reqf = xcalloc(1, vmmdevGetRequestSize(VMMDevReq_VideoAccelFlush));
return FALSE;
return FALSE;
return FALSE;
rc);
return FALSE;
return FALSE;
return TRUE;
void *p = NULL;
TRACE_ENTRY ();
#ifdef RT_OS_SOLARIS
return TRUE;
return TRUE;
if (fd < 0)
if (rc) {
if (NULL == p) {
(unsigned long) size);
if (rc) {
if (rc) {
#ifndef RT_OS_SOLARIS
if (NULL != p) {
xfree (p);
#ifdef RT_OS_SOLARIS
VbglR3Term();
return rc;
unsigned char *image)
#ifdef DEBUG_X
TRACE_ENTRY ();
(void) pScrn;
(void) bg;
(void) fg;
(void) pScrn; (void) x; (void) y;
TRACE_ENTRY ();
TRACE_ENTRY ();
TRACE_ENTRY ();
static Bool
static unsigned char color_to_byte (unsigned c)
(unsigned long) size);
xfree(p);
*cp++ = 0;
#ifdef DEBUG_X
#ifdef ARGB_CURSOR
if ( rc
return rc;
unsigned char *pm;
CARD8 *p;
int scrnIndex;
(unsigned long) size);
if (bitmask == 0)
pc += w;
xfree (p);
if (!pCurs)
#ifdef ARGB_CURSOR
return TRUE;
return FALSE;
!= TRUE)
return FALSE;
return TRUE;
return FALSE;
!= TRUE)
return TRUE;
return TRUE;
rc);
return FALSE;