[KMS/DRM] Bugfix number #5535: Improve reliability, by wahil1976.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/src/video/kmsdrm/SDL_kmsdrmsym.h b/src/video/kmsdrm/SDL_kmsdrmsym.h
index cea8bb9..bb78677 100644
--- a/src/video/kmsdrm/SDL_kmsdrmsym.h
+++ b/src/video/kmsdrm/SDL_kmsdrmsym.h
@@ -41,6 +41,8 @@ SDL_KMSDRM_SYM(void,drmModeFreeCrtc,(drmModeCrtcPtr ptr))
SDL_KMSDRM_SYM(void,drmModeFreeConnector,(drmModeConnectorPtr ptr))
SDL_KMSDRM_SYM(void,drmModeFreeEncoder,(drmModeEncoderPtr ptr))
SDL_KMSDRM_SYM(int,drmGetCap,(int fd, uint64_t capability, uint64_t *value))
+SDL_KMSDRM_SYM(int,drmSetMaster,(int fd))
+SDL_KMSDRM_SYM(int,drmAuthMagic,(int fd, drm_magic_t magic))
SDL_KMSDRM_SYM(drmModeResPtr,drmModeGetResources,(int fd))
SDL_KMSDRM_SYM(int,drmModeAddFB,(int fd, uint32_t width, uint32_t height, uint8_t depth,
uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index cbbe7b0..f6f651d 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -70,6 +70,7 @@ check_modestting(int devindex)
SDL_bool available = SDL_FALSE;
char device[512];
int drm_fd;
+ int i;
SDL_snprintf(device, sizeof (device), KMSDRM_DRI_DEVFMT, KMSDRM_DRI_PATH, devindex);
@@ -89,7 +90,22 @@ check_modestting(int devindex)
&& resources->count_encoders > 0
&& resources->count_crtcs > 0)
{
- available = SDL_TRUE;
+ available = SDL_FALSE;
+ for (i = 0; i < resources->count_connectors; i++) {
+ drmModeConnector *conn = KMSDRM_drmModeGetConnector(drm_fd,
+ resources->connectors[i]);
+
+ if (!conn) {
+ continue;
+ }
+
+ if (conn->connection == DRM_MODE_CONNECTED && conn->count_modes) {
+ available = SDL_TRUE;
+ break;
+ }
+
+ KMSDRM_drmModeFreeConnector(conn);
+ }
}
KMSDRM_drmModeFreeResources(resources);
}
@@ -751,6 +767,15 @@ KMSDRM_GBMInit (_THIS, SDL_DisplayData *dispdata)
/* Reopen the FD! */
viddata->drm_fd = open(viddata->devpath, O_RDWR | O_CLOEXEC);
+ /* Set the FD we just opened as current DRM master. */
+ KMSDRM_drmSetMaster(viddata->drm_fd);
+
+ /* Check if we are the current DRM master. */
+ if (KMSDRM_drmAuthMagic(viddata->drm_fd, 0) == -EACCES) {
+ ret = SDL_SetError("DRM device is claimed by another program as master.");
+ return ret;
+ }
+
/* Create the GBM device. */
viddata->gbm_dev = KMSDRM_gbm_create_device(viddata->drm_fd);
if (!viddata->gbm_dev) {