VirtualBox

Changeset 49628 in vbox


Ignore:
Timestamp:
Nov 22, 2013 3:17:39 PM (11 years ago)
Author:
vboxsync
Message:

Additions/x11/vboxvideo: try to use KMS driver IOCtls to co-ordinate access to the graphics card.

Location:
trunk/src/VBox/Additions/x11/vboxvideo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/vboxvideo/undefined

    r49477 r49628  
    3030drmFreeVersion
    3131drmGetVersion
     32drmIoctl
    3233fbPictureInit
    3334fbScreenInit
  • trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c

    r49187 r49628  
    7676
    7777#include "vboxvideo.h"
     78#include <VBox/VBoxGuest.h>
    7879#include "version-generated.h"
    7980#include "product-generated.h"
     
    101102# include "xf86Modes.h"
    102103# include <X11/Xatom.h>
     104#endif
     105
     106#ifdef VBOX_DRI
     107# include "xf86drm.h"
    103108#endif
    104109
     
    10141019#ifdef VBOX_DRI
    10151020    pVBox->useDRI = VBOXDRIScreenInit(pScrn, pScreen, pVBox);
     1021# ifndef VBOX_DRI_OLD  /* DRI2 */
     1022    if (pVBox->drmFD >= 0)
     1023        /* Tell the kernel driver, if present, that we are taking over. */
     1024        drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_DISABLE_HGSMI, NULL);
     1025# endif
    10161026#endif
    10171027
     
    11791189    TRACE_ENTRY();
    11801190    vboxClearVRAM(pScrn, 0, 0);
    1181     if (pVBox->fHaveHGSMI)
    1182         vboxEnableVbva(pScrn);
    11831191#ifdef VBOX_DRI_OLD
    11841192    if (pVBox->useDRI)
    11851193        DRIUnlock(xf86ScrnToScreen(pScrn));
    1186 #endif
     1194#elif defined(VBOX_DRI)  /* DRI2 */
     1195    if (pVBox->drmFD >= 0)
     1196        /* Tell the kernel driver, if present, that we are taking over. */
     1197        drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_DISABLE_HGSMI, NULL);
     1198#endif
     1199    if (pVBox->fHaveHGSMI)
     1200        vboxEnableVbva(pScrn);
    11871201    /* Re-assert this in case we had a change request while switched out. */
    11881202    if (pVBox->FBSize.cx && pVBox->FBSize.cy)
     
    12081222        vboxDisableVbva(pScrn);
    12091223    vboxClearVRAM(pScrn, 0, 0);
    1210     VBOXRestoreMode(pScrn);
    12111224    vboxDisableGraphicsCap(pVBox);
    12121225#ifdef VBOX_DRI_OLD
    12131226    if (pVBox->useDRI)
    12141227        DRILock(xf86ScrnToScreen(pScrn), 0);
    1215 #endif
     1228#elif defined(VBOX_DRI)  /* DRI2 */
     1229    if (pVBox->drmFD >= 0)
     1230        /* Tell the kernel driver, if present, that it can use the framebuffer
     1231         * driver again. */
     1232        drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_ENABLE_HGSMI, NULL);
     1233    else
     1234#endif
     1235        VBOXRestoreMode(pScrn);
    12161236    TRACE_EXIT();
    12171237}
     
    12311251    }
    12321252#ifdef VBOX_DRI
     1253# ifndef VBOX_DRI_OLD  /* DRI2 */
     1254    if (pVBox->drmFD >= 0)
     1255        /* Tell the kernel driver, if present, that we are going away. */
     1256        drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_ENABLE_HGSMI, NULL);
     1257# endif
    12331258    if (pVBox->useDRI)
    12341259        VBOXDRICloseScreen(pScreen, pVBox);
  • trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.h

    r49187 r49628  
    5757
    5858#ifdef DEBUG
     59
     60#include <xf86.h>
    5961
    6062#define TRACE_ENTRY() \
     
    196198    __GLXvisualConfig *pVisualConfigs;
    197199    DRIInfoRec *pDRIInfo;
     200# endif
    198201    int drmFD;
    199 # endif
    200202#endif
    201203} VBOXRec, *VBOXPtr;
  • trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_dri2.c

    r49187 r49628  
    1717
    1818#include "vboxvideo.h"
     19#include <xf86drm.h>
    1920#include <drm.h>
    2021#include <dri2.h>
     22#include <fcntl.h>
     23#include <unistd.h>
    2124
    2225static void VBOXDRICopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
     
    3740}
    3841
     42/* We need to pass a constant path string to the screen initialisation function.
     43 * The format is hard-coded in "drmOpen" in libdrm, and libdrm contains a
     44 * comment to say that open should be done manually in future and not using
     45 * "drmOpen", so we will do it manually but also hard-coding the format.  The
     46 * maximum minor number (15) is also hard-coded. */
     47#define PATH(minor) "/dev/dri/card" #minor
     48const char *devicePaths[] =
     49{
     50    PATH(0), PATH(1), PATH(2), PATH(3), PATH(4), PATH(5), PATH(6), PATH(7),
     51    PATH(8), PATH(9), PATH(10), PATH(11), PATH(12), PATH(13), PATH(14), PATH(15)
     52};
     53#undef PATH
     54
    3955/** As long as we are using our fake DRI driver inside of Mesa, we only want
    4056 *  to implement the minimum here to make Mesa load it.  Notably we just set
     
    4359{
    4460    DRI2InfoRec DRI2Info;
     61    unsigned i;
    4562
    4663    memset(&DRI2Info, 0, sizeof(DRI2Info));
     64    for (i = 0; i < RT_ELEMENTS(devicePaths); ++i)
     65    {
     66        int fd = open(devicePaths[i], O_RDWR);
     67        if (fd >= 0)
     68        {
     69            drmVersionPtr pVersion = drmGetVersion(fd);
     70            if (   pVersion
     71                && pVersion->name_len
     72                && !strcmp(pVersion->name, VBOX_DRM_DRIVER_NAME))
     73            {
     74                TRACE_LOG("Opened drm device %s\n", devicePaths[i]);
     75                DRI2Info.deviceName = devicePaths[i];
     76                /* Keep the driver open and hope that the path won't change. */
     77                pVBox->drmFD = fd;
     78                drmFreeVersion(pVersion);
     79                break;
     80            }
     81            close(fd);
     82            drmFreeVersion(pVersion);
     83        }
     84    }
     85    if (!DRI2Info.deviceName)
     86        return FALSE;
    4787    DRI2Info.version = 3;
    4888    DRI2Info.fd = -1;
    4989    DRI2Info.driverName = VBOX_DRI_DRIVER_NAME;
    50     DRI2Info.deviceName = "/dev/dri/card0";  /** @todo: do this right. */
    5190    DRI2Info.CopyRegion = VBOXDRICopyRegion;
    5291    DRI2Info.Wait = NULL;
     
    5695}
    5796
    58 void
    59 VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox)
     97void VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox)
    6098{
    6199    DRI2CloseScreen(pScreen);
     100    if (pVBox->drmFD)
     101        close(pVBox->drmFD);
    62102}
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