Upstream patches for xf86-video-modesetting-0.8.1
2014-02-28	modesetting: fix cursor rendering with hotspots.HEADmaster	Dave Airlie	1	-1/+1
2014-02-25	modesetting: Don't (brokenly) double-track software cursor	Adam Jackson	2	-2/+1
2014-02-21	modesetting: try and use hotspot cursor support	Dave Airlie	2	-1/+15
2014-02-21	modesetting: move closing fd to after we check outputs	Dave Airlie	1	-1/+1
2014-02-12	modesetting: query cursor size from the kernel

From 677935b2d20f54f21c645b5eb386b6c9485fee5f Mon Sep 17 00:00:00 2001
From: Alex Deucher <alexander.deucher@amd.com>
Date: Wed, 12 Feb 2014 18:06:51 +0000
Subject: modesetting: query cursor size from the kernel

Use new drm caps.  This allows hw cursors to work
correctly on gpus with non-64x64 cursors.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
diff --git a/src/driver.c b/src/driver.c
index b84624e..b28622a 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -566,6 +566,14 @@ FreeRec(ScrnInfoPtr pScrn)
 
 }
 
+#ifndef DRM_CAP_CURSOR_WIDTH
+#define DRM_CAP_CURSOR_WIDTH 0x8
+#endif
+
+#ifndef DRM_CAP_CURSOR_HEIGHT
+#define DRM_CAP_CURSOR_HEIGHT 0x9
+#endif
+
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
@@ -706,6 +714,17 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	prefer_shadow = !!value;
     }
 
+    ms->cursor_width = 64;
+    ms->cursor_height = 64;
+    ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_WIDTH, &value);
+    if (!ret) {
+	ms->cursor_width = value;
+    }
+    ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_HEIGHT, &value);
+    if (!ret) {
+	ms->cursor_height = value;
+    }
+
     ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
@@ -933,7 +952,7 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
 
     /* Need to extend HWcursor support to handle mask interleave */
     if (!ms->drmmode.sw_cursor)
-	xf86_cursors_init(pScreen, 64, 64,
+	xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height,
 			  HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
 			  HARDWARE_CURSOR_ARGB);
 
diff --git a/src/driver.h b/src/driver.h
index 79561c8..e84d748 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -76,6 +76,7 @@ typedef struct _modesettingRec
     DamagePtr damage;
     Bool dirty_enabled;
 
+    uint32_t cursor_width, cursor_height;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 25641ce..ccfd75f 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -52,6 +52,8 @@
 #endif
 #include "compat-api.h"
 
+#include "driver.h"
+
 static struct dumb_bo *dumb_bo_create(int fd,
 			  const unsigned width, const unsigned height,
 			  const unsigned bpp)
@@ -445,6 +447,7 @@ drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
 static void
 drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	int i;
 	uint32_t *ptr;
@@ -453,10 +456,11 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 	/* cursor should be mapped already */
 	ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr);
 
-	for (i = 0; i < 64 * 64; i++)
+	for (i = 0; i < ms->cursor_width * ms->cursor_height; i++)
 		ptr[i] = image[i];// cpu_to_le32(image[i]);
 
-	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
+			       ms->cursor_width, ms->cursor_height);
 	if (ret) {
 		xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
 		xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
@@ -471,21 +475,25 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 static void
 drmmode_hide_cursor (xf86CrtcPtr crtc)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
-	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, 64, 64);
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0,
+			 ms->cursor_width, ms->cursor_height);
 
 }
 
 static void
 drmmode_show_cursor (xf86CrtcPtr crtc)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	uint32_t handle = drmmode_crtc->cursor_bo->handle;
 
-	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
+			 ms->cursor_width, ms->cursor_height);
 }
 
 static void
@@ -1485,6 +1493,7 @@ void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode)
 /* create front and cursor BOs */
 Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
+	modesettingPtr ms = modesettingPTR(pScrn);
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	int width;
 	int height;
@@ -1500,7 +1509,8 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 		return FALSE;
 	pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
 
-	width = height = 64;
+	width = ms->cursor_width;
+	height = ms->cursor_height;
 	bpp = 32;
 	for (i = 0; i < xf86_config->num_crtc; i++) {
 		xf86CrtcPtr crtc = xf86_config->crtc[i];
--
cgit v0.9.0.2-2-gbebe

From bf359b118a0870f18a229d33979270ac2f0f5dcd Mon Sep 17 00:00:00 2001
From: Dave Airlie <airlied@redhat.com>
Date: Fri, 21 Feb 2014 02:48:42 +0000
Subject: modesetting: move closing fd to after we check outputs

On something like cirrus, start X, then attempt to start a second
X while the first is running, if fbdev is installed it'll fail
hard.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
diff --git a/src/driver.c b/src/driver.c
index b28622a..4a74ece 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -258,11 +258,11 @@ static Bool probe_hw_pci(const char *dev, struct pci_device *pdev)
 
     id = drmGetBusid(fd);
     devid = ms_DRICreatePCIBusID(pdev);
-    close(fd);
 
     if (id && devid && !strcmp(id, devid))
         ret = check_outputs(fd);
 
+    close(fd);
     free(id);
     free(devid);
     return ret;
--
cgit v0.9.0.2-2-gbebe

From c36a5e298c36deb5f6fd0eef3029235aa58de295 Mon Sep 17 00:00:00 2001
From: Dave Airlie <airlied@redhat.com>
Date: Mon, 20 Jan 2014 01:06:42 +0000
Subject: modesetting: try and use hotspot cursor support

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
diff --git a/configure.ac b/configure.ac
index 0b04923..0ec8e18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,7 +74,7 @@ AM_CONDITIONAL(HAVE_XEXTPROTO_71, [ test "$HAVE_XEXTPROTO_71" = "yes" ])
 # Checks for header files.
 AC_HEADER_STDC
 
-PKG_CHECK_MODULES(DRM, [libdrm >= 2.2])
+PKG_CHECK_MODULES(DRM, [libdrm >= 2.4.46])
 PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.10])
 AM_CONDITIONAL(DRM, test "x$DRM" = xyes)
 
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index ccfd75f..5b796e0 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -43,6 +43,8 @@
 #include "xf86Crtc.h"
 #include "drmmode_display.h"
 
+#include <cursorstr.h>
+
 /* DPMS */
 #ifdef HAVE_XEXTPROTO_71
 #include <X11/extensions/dpmsconst.h>
@@ -491,6 +493,18 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	uint32_t handle = drmmode_crtc->cursor_bo->handle;
+       static Bool use_set_cursor2 = TRUE;
+
+       if (use_set_cursor2) {
+               xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+               CursorPtr cursor = xf86_config->cursor;
+               int ret;
+               ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot);
+               if (ret == -ENOSYS)
+                       use_set_cursor2 = FALSE;
+               else
+                       return;
+       }
 
 	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
 			 ms->cursor_width, ms->cursor_height);
--
cgit v0.9.0.2-2-gbebe

From b8840f5442f9fbd8ce47ab2dd555b75cf4bb114a Mon Sep 17 00:00:00 2001
From: Adam Jackson <ajax@redhat.com>
Date: Tue, 25 Feb 2014 14:06:55 +0000
Subject: modesetting: Don't (brokenly) double-track software cursor

Signed-off-by: Adam Jackson <ajax@redhat.com>
---
diff --git a/src/driver.c b/src/driver.c
index 4a74ece..0f9190a 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -801,7 +801,7 @@ CreateScreenResources(ScreenPtr pScreen)
 
     drmmode_uevent_init(pScrn, &ms->drmmode);
 
-    if (!ms->SWCursor)
+    if (!ms->drmmode.sw_cursor)
         drmmode_map_cursor_bos(pScrn, &ms->drmmode);
     pixels = drmmode_map_front_bo(&ms->drmmode);
     if (!pixels)
diff --git a/src/driver.h b/src/driver.h
index e84d748..450b29c 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -59,7 +59,6 @@ typedef struct _modesettingRec
 #endif
 
     Bool noAccel;
-    Bool SWCursor;
     CloseScreenProcPtr CloseScreen;
 
     /* Broken-out options. */
--
cgit v0.9.0.2-2-gbebe

From c9d377a19201973012bb6bbb07e3b8c3e9c3b856 Mon Sep 17 00:00:00 2001
From: Dave Airlie <airlied@redhat.com>
Date: Fri, 28 Feb 2014 02:04:30 +0000
Subject: modesetting: fix cursor rendering with hotspots.

older kernels report EINVAL not ENOSYS, doh.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 5b796e0..28a4abb 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -500,7 +500,7 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
                CursorPtr cursor = xf86_config->cursor;
                int ret;
                ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot);
-               if (ret == -ENOSYS)
+               if (ret == -EINVAL)
                        use_set_cursor2 = FALSE;
                else
                        return;
--
cgit v0.9.0.2-2-gbebe
