[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

xserver-xorg-video-amdgpu: Changes to 'upstream-unstable'



 autogen.sh                        |   11 
 configure.ac                      |   21 +
 man/amdgpu.man                    |   15 -
 src/Makefile.am                   |    8 
 src/amdgpu_chipinfo_gen.h         |  194 --------------
 src/amdgpu_chipset_gen.h          |  216 ----------------
 src/amdgpu_dri2.c                 |   54 ++--
 src/amdgpu_dri3.c                 |   37 ++
 src/amdgpu_drv.h                  |   35 ++
 src/amdgpu_glamor.c               |    7 
 src/amdgpu_kms.c                  |  363 ++++++++++++++-------------
 src/amdgpu_pci_chipset_gen.h      |  195 --------------
 src/amdgpu_pci_device_match_gen.h |  195 --------------
 src/amdgpu_present.c              |   18 +
 src/amdgpu_probe.c                |   40 +--
 src/amdgpu_probe.h                |   33 --
 src/amdpciids.h                   |   39 --
 src/ati_pciids_gen.h              |  191 --------------
 src/drmmode_display.c             |  500 ++++++++++++++++++++++++++------------
 src/drmmode_display.h             |   19 +
 src/pcidb/ati_pciids.csv          |  192 --------------
 src/pcidb/parse_pci_ids.pl        |   82 ------
 22 files changed, 736 insertions(+), 1729 deletions(-)

New commits:
commit 804e30e14e51f94403a0721ef2aae28f1fa9e9f2
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Thu Mar 16 17:28:11 2017 +0900

    Bump version for 1.3.0 release

diff --git a/configure.ac b/configure.ac
index 591c2b9..8d86f52 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@
 # Initialize Autoconf
 AC_PREREQ([2.60])
 AC_INIT([xf86-video-amdgpu],
-        [1.2.99],
+        [1.3.0],
         [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
         [xf86-video-amdgpu])
 

commit 3a8582944ed3fef1b75f8871489e6e19963e2ea6
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Thu Mar 9 15:56:59 2017 +0900

    Pass TRUE to drmmode_set_desired_modes the first time for GPU screens
    
    This is the only place we call drmmode_set_desired_modes for GPU screens
    during server startup. Without this change, the display outputs of
    secondary GPUs may stay on even while Xorg isn't using them.
    
    (Ported from radeon commit 9a71445094b728f3d78db8f6808b4782ee19a453)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index 3deaef7..4821e93 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -243,7 +243,8 @@ static Bool AMDGPUCreateScreenResources_KMS(ScreenPtr pScreen)
 		}
 	}
 
-	if (!drmmode_set_desired_modes(pScrn, &info->drmmode, FALSE))
+	if (!drmmode_set_desired_modes(pScrn, &info->drmmode,
+				       amdgpu_is_gpu_screen(pScreen)))
 		return FALSE;
 
 	drmmode_uevent_init(pScrn, &info->drmmode);

commit 82b15a4da156e18da4c8fc0093500c32b549e487
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Thu Mar 9 15:47:24 2017 +0900

    Skip some initialization steps for GPU screens
    
    Xorg doesn't use the following functionality of GPU screens, so don't
    bother initializing it:
    
    * DRI page flipping
    * DRI3 / Present / SYNC fences
    * XVideo / XvMC
    * Root window with background None
    
    (Ported from radeon commit 67ae5e00a748ad52cf92738d401afff2947b1891)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_drv.h b/src/amdgpu_drv.h
index 0700dae..532d99d 100644
--- a/src/amdgpu_drv.h
+++ b/src/amdgpu_drv.h
@@ -169,8 +169,10 @@ typedef enum {
 #if XF86_CRTC_VERSION >= 5
 #define AMDGPU_PIXMAP_SHARING 1
 #define amdgpu_is_gpu_screen(screen) (screen)->isGPU
+#define amdgpu_is_gpu_scrn(scrn) (scrn)->is_gpu
 #else
 #define amdgpu_is_gpu_screen(screen) 0
+#define amdgpu_is_gpu_scrn(scrn) 0
 #endif
 
 #define AMDGPU_VSYNC_TIMEOUT	20000	/* Maximum wait for VSYNC (in usecs) */
diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index 92bf5fa..3deaef7 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -1397,23 +1397,26 @@ Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 			xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ShadowPrimary enabled\n");
 	}
 
-	sw_cursor = xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE);
-
-	info->allowPageFlip = xf86ReturnOptValBool(info->Options,
-						   OPTION_PAGE_FLIP,
-						   TRUE);
-	if (sw_cursor || info->shadow_primary) {
-		xf86DrvMsg(pScrn->scrnIndex,
-			   info->allowPageFlip ? X_WARNING : X_DEFAULT,
-			   "KMS Pageflipping: disabled%s\n",
-			   info->allowPageFlip ?
-			   (sw_cursor ? " because of SWcursor" :
-			    " because of ShadowPrimary") : "");
-		info->allowPageFlip = FALSE;
-	} else {
-		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-			   "KMS Pageflipping: %sabled\n",
-			   info->allowPageFlip ? "en" : "dis");
+	if (!amdgpu_is_gpu_scrn(pScrn)) {
+		sw_cursor = xf86ReturnOptValBool(info->Options,
+						 OPTION_SW_CURSOR, FALSE);
+
+		info->allowPageFlip = xf86ReturnOptValBool(info->Options,
+							   OPTION_PAGE_FLIP,
+							   TRUE);
+		if (sw_cursor || info->shadow_primary) {
+			xf86DrvMsg(pScrn->scrnIndex,
+				   info->allowPageFlip ? X_WARNING : X_DEFAULT,
+				   "KMS Pageflipping: disabled%s\n",
+				   info->allowPageFlip ?
+				   (sw_cursor ? " because of SWcursor" :
+				    " because of ShadowPrimary") : "");
+			info->allowPageFlip = FALSE;
+		} else {
+			xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+				   "KMS Pageflipping: %sabled\n",
+				   info->allowPageFlip ? "en" : "dis");
+		}
 	}
 
 	if (xf86ReturnOptValBool(info->Options, OPTION_DELETE_DP12, FALSE)) {
@@ -1736,30 +1739,32 @@ Bool AMDGPUScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
 	}
 #endif
 
-	value = xorgGetVersion() >= XORG_VERSION_NUMERIC(1,18,3,0,0);
-	from = X_DEFAULT;
+	if (!amdgpu_is_gpu_screen(pScreen)) {
+		value = xorgGetVersion() >= XORG_VERSION_NUMERIC(1,18,3,0,0);
+		from = X_DEFAULT;
 
-	if (info->use_glamor) {
-		if (xf86GetOptValBool(info->Options, OPTION_DRI3, &value))
-			from = X_CONFIG;
+		if (info->use_glamor) {
+			if (xf86GetOptValBool(info->Options, OPTION_DRI3, &value))
+				from = X_CONFIG;
 
-		if (xf86GetOptValInteger(info->Options, OPTION_DRI, &driLevel) &&
-			(driLevel == 2 || driLevel == 3)) {
-			from = X_CONFIG;
-			value = driLevel == 3;
+			if (xf86GetOptValInteger(info->Options, OPTION_DRI, &driLevel) &&
+			    (driLevel == 2 || driLevel == 3)) {
+				from = X_CONFIG;
+				value = driLevel == 3;
+			}
 		}
-	}
 
-	if (value) {
-		value = amdgpu_sync_init(pScreen) &&
-			amdgpu_present_screen_init(pScreen) &&
-			amdgpu_dri3_screen_init(pScreen);
+		if (value) {
+			value = amdgpu_sync_init(pScreen) &&
+				amdgpu_present_screen_init(pScreen) &&
+				amdgpu_dri3_screen_init(pScreen);
 
-		if (!value)
-			from = X_WARNING;
-	}
+			if (!value)
+				from = X_WARNING;
+		}
 
-	xf86DrvMsg(pScrn->scrnIndex, from, "DRI3 %sabled\n", value ? "en" : "dis");
+		xf86DrvMsg(pScrn->scrnIndex, from, "DRI3 %sabled\n", value ? "en" : "dis");
+	}
 
 	pScrn->vtSema = TRUE;
 	xf86SetBackingStore(pScreen);
@@ -1819,7 +1824,8 @@ Bool AMDGPUScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
 	 */
 	/* xf86DiDGAInit(pScreen, info->LinearAddr + pScrn->fbOffset); */
 #endif
-	if (info->shadow_fb == FALSE) {
+	if (info->shadow_fb == FALSE &&
+	    !amdgpu_is_gpu_screen(pScreen)) {
 		/* Init Xv */
 		xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, AMDGPU_LOGLEVEL_DEBUG,
 			       "Initializing Xv\n");
@@ -1835,12 +1841,14 @@ Bool AMDGPUScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
 	}
 	pScrn->pScreen = pScreen;
 
-	if (serverGeneration == 1 && bgNoneRoot && info->use_glamor) {
-		info->CreateWindow = pScreen->CreateWindow;
-		pScreen->CreateWindow = AMDGPUCreateWindow_oneshot;
+	if (!amdgpu_is_gpu_screen(pScreen)) {
+		if (serverGeneration == 1 && bgNoneRoot && info->use_glamor) {
+			info->CreateWindow = pScreen->CreateWindow;
+			pScreen->CreateWindow = AMDGPUCreateWindow_oneshot;
+		}
+		info->WindowExposures = pScreen->WindowExposures;
+		pScreen->WindowExposures = AMDGPUWindowExposures_oneshot;
 	}
-	info->WindowExposures = pScreen->WindowExposures;
-	pScreen->WindowExposures = AMDGPUWindowExposures_oneshot;
 
 	/* Provide SaveScreen & wrap BlockHandler and CloseScreen */
 	/* Wrap CloseScreen */

commit fa85331f0ce27e16a9338516518433955133840e
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Tue Mar 7 18:02:29 2017 +0900

    glamor: Use glamor_finish when available
    
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/configure.ac b/configure.ac
index 00249a5..591c2b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,9 +138,14 @@ if test "x$GLAMOR" != "xno"; then
 					 [Have glamor_egl_destroy_textured_pixmap API])], [],
 			      [#include "xorg-server.h"
 			       #include "glamor.h"])
-	fi
 
-	PKG_CHECK_MODULES(LIBGL, [gl])
+		AC_CHECK_DECL(glamor_finish,
+			      [AC_DEFINE(HAVE_GLAMOR_FINISH, 1,
+					 [Have glamor_finish API])],
+					 [PKG_CHECK_MODULES(LIBGL, [gl])],
+			      [#include "xorg-server.h"
+			       #include "glamor.h"])
+	fi
 
 	if test "x$GLAMOR_XSERVER" != xyes; then
 		PKG_CHECK_MODULES(LIBGLAMOR, [glamor >= 0.6.0])
diff --git a/src/amdgpu_glamor.c b/src/amdgpu_glamor.c
index d29b096..1c5dfc2 100644
--- a/src/amdgpu_glamor.c
+++ b/src/amdgpu_glamor.c
@@ -36,7 +36,9 @@
 
 #include <gbm.h>
 
+#ifndef HAVE_GLAMOR_FINISH
 #include <GL/gl.h>
+#endif
 
 DevPrivateKeyRec amdgpu_pixmap_index;
 
@@ -470,8 +472,13 @@ void amdgpu_glamor_finish(ScrnInfoPtr pScrn)
 	AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
 
 	if (info->use_glamor) {
+#if HAVE_GLAMOR_FINISH
+		glamor_finish(pScrn->pScreen);
+		info->gpu_flushed++;
+#else
 		amdgpu_glamor_flush(pScrn);
 		glFinish();
+#endif
 	}
 }
 

commit 7884e38e94c2cbd6c205f556f2b31ad59b4089b4
Author: Hans De Goede <hdegoede@redhat.com>
Date:   Tue Oct 18 16:48:40 2016 +0200

    amdgpu_probe: Do not close server managed drm fds
    
    This fixes the xserver only seeing AMD/ATI devices supported by the amdgpu
    driver, as by the time xf86-video-ati gets a chance to probe them, the
    fd has been closed.
    
    This fixes e.g. Xorg not seeing the dGPU on a Lenovo Thinkpad E465 laptop
    with a CARRIZO iGPU and a HAINAN dGPU.
    
    Signed-off-by: Hans de Goede <hdegoede@redhat.com>
    
    v2: Rebased on top of new patch 1.
    
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
index fc93ac6..fb62cb8 100644
--- a/src/amdgpu_probe.c
+++ b/src/amdgpu_probe.c
@@ -166,7 +166,7 @@ static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn, AMDGPUEntPtr pAMDGPUEnt,
 	if (err != 0) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 			   "[drm] failed to set drm interface version.\n");
-		drmClose(pAMDGPUEnt->fd);
+		amdgpu_kernel_close_fd(pAMDGPUEnt);
 		return FALSE;
 	}
 
@@ -254,7 +254,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 	return TRUE;
 
 error_amdgpu:
-	drmClose(pAMDGPUEnt->fd);
+	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error_fd:
 	free(pPriv->ptr);
 error:
@@ -349,6 +349,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 
 		pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
 		pAMDGPUEnt = pPriv->ptr;
+		pAMDGPUEnt->platform_dev = dev;
 		pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, busid, dev);
 		if (pAMDGPUEnt->fd < 0)
 			goto error_fd;
@@ -367,7 +368,6 @@ amdgpu_platform_probe(DriverPtr pDriver,
 		pAMDGPUEnt = pPriv->ptr;
 		pAMDGPUEnt->fd_ref++;
 	}
-	pAMDGPUEnt->platform_dev = dev;
 
 	xf86SetEntityInstanceForScreen(pScrn, pEnt->index,
 				       xf86GetNumEntityInstances(pEnt->
@@ -379,7 +379,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 	return TRUE;
 
 error_amdgpu:
-	drmClose(pAMDGPUEnt->fd);
+	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error_fd:
 	free(pPriv->ptr);
 error:

commit a2c360fa1d33d6a5aa64c396197e119ff77d1379
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Mon Mar 6 18:59:23 2017 +0900

    Refactor amdgpu_kernel_close_fd helper
    
    Preparation for the following change.
    
    Assign pAMDGPUEnt->fd = -1 instead of 0 when we're not using the file
    descriptor anymore.
    
    Reviewed-by: Hans de Goede <hdegoede@redhat.com>
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index 31c2e86..92bf5fa 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -132,12 +132,7 @@ static void AMDGPUFreeRec(ScrnInfoPtr pScrn)
 		pAMDGPUEnt->fd_ref--;
 		if (!pAMDGPUEnt->fd_ref) {
 			amdgpu_device_deinitialize(pAMDGPUEnt->pDev);
-#ifdef XF86_PDEV_SERVER_FD
-			if (!(pAMDGPUEnt->platform_dev &&
-			      pAMDGPUEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
-#endif
-				drmClose(pAMDGPUEnt->fd);
-			pAMDGPUEnt->fd = 0;
+			amdgpu_kernel_close_fd(pAMDGPUEnt);
 		}
 	}
 
diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
index 94da7f6..fc93ac6 100644
--- a/src/amdgpu_probe.c
+++ b/src/amdgpu_probe.c
@@ -134,6 +134,16 @@ static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, char *busid,
 	return fd;
 }
 
+void amdgpu_kernel_close_fd(AMDGPUEntPtr pAMDGPUEnt)
+{
+#ifdef XF86_PDEV_SERVER_FD
+	if (!(pAMDGPUEnt->platform_dev &&
+	      pAMDGPUEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
+#endif
+		drmClose(pAMDGPUEnt->fd);
+	pAMDGPUEnt->fd = -1;
+}
+
 static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn, AMDGPUEntPtr pAMDGPUEnt,
 				   char *busid)
 {
diff --git a/src/amdgpu_probe.h b/src/amdgpu_probe.h
index 0f43233..9e4a9a4 100644
--- a/src/amdgpu_probe.h
+++ b/src/amdgpu_probe.h
@@ -71,6 +71,8 @@ typedef struct {
 	char *render_node;
 } AMDGPUEntRec, *AMDGPUEntPtr;
 
+extern void amdgpu_kernel_close_fd(AMDGPUEntPtr pAMDGPUEnt);
+
 extern const OptionInfoRec *AMDGPUOptionsWeak(void);
 
 extern Bool AMDGPUPreInit_KMS(ScrnInfoPtr, int);

commit 947017194d07e32876a43ee0efc45fdc71385748
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 17:59:19 2017 +0900

    glamor: Don't flush in BlockHandler with Xorg >= 1.19
    
    This was only necessary with older versions for driving the FBO cache
    expiry mechanism.
    
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index d48ad48..31c2e86 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -1035,8 +1035,10 @@ static void AMDGPUBlockHandler_KMS(BLOCKHANDLER_ARGS_DECL)
 		}
 	}
 
+#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,19,0,0,0)
 	if (info->use_glamor)
 		amdgpu_glamor_flush(pScrn);
+#endif
 
 #ifdef AMDGPU_PIXMAP_SHARING
 	amdgpu_dirty_update(pScrn);

commit 86907a5e4ce33154167b330570491f88218725d3
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Mon Mar 6 18:23:41 2017 +0900

    Only define transform_region for XF86_CRTC_VERSION >= 4
    
    Not used with older versions of Xorg. Fixes warning in that case:
    
    ../../src/amdgpu_kms.c:328:1: warning: ‘transform_region’ defined but not used [-Wunused-function]
     transform_region(RegionPtr region, struct pict_f_transform *transform,
     ^~~~~~~~~~~~~~~~
    
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index bfc3530..d48ad48 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -324,6 +324,8 @@ amdgpu_scanout_extents_intersect(xf86CrtcPtr xf86_crtc, BoxPtr extents)
 	return (extents->x1 < extents->x2 && extents->y1 < extents->y2);
 }
 
+#if XF86_CRTC_VERSION >= 4
+
 static RegionPtr
 transform_region(RegionPtr region, struct pict_f_transform *transform,
 		 int w, int h)
@@ -362,6 +364,8 @@ transform_region(RegionPtr region, struct pict_f_transform *transform,
 	return transformed;
 }
 
+#endif
+
 static void
 amdgpu_sync_scanout_pixmaps(xf86CrtcPtr xf86_crtc, RegionPtr new_region,
 							int scanout_id)

commit 8d2b7d1758e3fcac520a18a0684c073f0ac62389
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Mon Mar 6 18:09:58 2017 +0900

    Use local implementation of RegionDuplicate for older xserver
    
    It was only added in xserver 1.15. Fixes build against older xserver.
    
    Reported-by: Pali Rohár <pali.rohar@gmail.com>
    (Ported from radeon commit 80cc892ee1ce54fad3cb7dd11bd9df18c359136f)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/configure.ac b/configure.ac
index 11dc285..00249a5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -152,6 +152,12 @@ else
 fi
 AM_CONDITIONAL(GLAMOR, test x$GLAMOR != xno)
 
+AC_CHECK_DECL(RegionDuplicate,
+	      [AC_DEFINE(HAVE_REGIONDUPLICATE, 1,
+	      [Have RegionDuplicate API])], [],
+	      [#include <xorg-server.h>
+	       #include <regionstr.h>])
+
 AC_CHECK_DECL(fbGlyphs,
 	      [AC_DEFINE(HAVE_FBGLYPHS, 1, [Have fbGlyphs API])], [],
 	      [#include <X11/Xmd.h>
diff --git a/src/amdgpu_drv.h b/src/amdgpu_drv.h
index ae5b6f9..0700dae 100644
--- a/src/amdgpu_drv.h
+++ b/src/amdgpu_drv.h
@@ -89,6 +89,25 @@
 
 struct _SyncFence;
 
+#ifndef HAVE_REGIONDUPLICATE
+
+static inline RegionPtr
+RegionDuplicate(RegionPtr pOld)
+{
+	RegionPtr pNew;
+
+	pNew = RegionCreate(&pOld->extents, 0);
+	if (!pNew)
+		return NULL;
+	if (!RegionCopy(pNew, pOld)) {
+		RegionDestroy(pNew);
+		return NULL;
+	}
+	return pNew;
+}
+
+#endif
+
 #ifndef MAX
 #define MAX(a,b) ((a)>(b)?(a):(b))
 #endif

commit cd73100114a18642d9c40f1df33cef8311e96a8b
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Mon Mar 6 18:07:19 2017 +0900

    Don't use pScrn->is_gpu in AMDGPUCreateScreenResources_KMS
    
    Looks like this snuck in accidentally.
    
    Brings us back in line with the radeon driver, and fixes the build
    against older versions of xserver which didn't have the is_gpu field
    yet.
    
    Fixes: 6bab8fabb37e ("Remove info->dri2.drm_fd and info->drmmode->fd")
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index c5205e2..bfc3530 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -248,7 +248,7 @@ static Bool AMDGPUCreateScreenResources_KMS(ScreenPtr pScreen)
 		}
 	}
 
-	if (!drmmode_set_desired_modes(pScrn, &info->drmmode, pScrn->is_gpu))
+	if (!drmmode_set_desired_modes(pScrn, &info->drmmode, FALSE))
 		return FALSE;
 
 	drmmode_uevent_init(pScrn, &info->drmmode);

commit 351baa89b9b0ecfb6c666af3a2d10c559a9224a9
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:44:15 2017 +0900

    Don't call amdgpu_glamor_flush in drmmode_copy_fb
    
    AMDGPUWindowExposures_oneshot takes care of it.
    
    (Ported from radeon commit d63881623f0686a66a2e3e3c1f84e496aa52ec6b)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 406b5ee..2cdea90 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -429,8 +429,6 @@ void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 
 	FreeScratchGC(gc);
 
-	amdgpu_glamor_finish(pScrn);
-
 	pScreen->canDoBGNoneRoot = TRUE;
 
 	if (info->fbcon_pixmap)

commit ad53635af150cda9b8da413be5a011d74f972ac7
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:41:49 2017 +0900

    Move DPMS check from amdgpu_scanout_do_update to amdgpu_scanout_flip
    
    When amdgpu_scanout_do_update is called from
    drmmode_crtc_scanout_update, drmmode_crtc->pending_dpms_mode may still
    be != DPMSModeOn, e.g. during server startup.
    
    Fixes intermittently showing garbage with TearFree enabled.
    
    (Ported from radeon commit cc9d6b7db9c2078be1e530a64af6d517c6a42024)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index ce1ae43..c5205e2 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -787,7 +787,6 @@ amdgpu_scanout_do_update(xf86CrtcPtr xf86_crtc, int scanout_id)
 	BoxRec extents;
 
 	if (!xf86_crtc->enabled ||
-	    drmmode_crtc->pending_dpms_mode != DPMSModeOn ||
 	    !drmmode_crtc->scanout[scanout_id].pixmap)
 		return FALSE;
 
@@ -970,7 +969,8 @@ amdgpu_scanout_flip(ScreenPtr pScreen, AMDGPUInfoPtr info,
 	uintptr_t drm_queue_seq;
 	unsigned scanout_id;
 
-	if (drmmode_crtc->scanout_update_pending)
+	if (drmmode_crtc->scanout_update_pending ||
+	    drmmode_crtc->pending_dpms_mode != DPMSModeOn)
 		return;
 
 	scanout_id = drmmode_crtc->scanout_id ^ 1;

commit 378bd05c849ad3092f138bdc8917d35d0b967389
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:36:24 2017 +0900

    Call drmmode_set_desired_modes from a WindowExposures hook
    
    This is the earliest opportunity where the root window contents are
    guaranteed to be initialized, and prevents drmmode_set_mode_major from
    getting called before drmmode_set_desired_modes via AMDGPUUnblank ->
    drmmode_crtc_dpms. Also, in contrast to the BlockHandler hook, this is
    called when running Xorg with -pogo.
    
    Fixes intermittently showing garbage on server startup or after server
    reset.
    
    As a bonus, this avoids trouble due to higher layers (e.g. the tigervnc
    Xorg module) calling AMDGPUBlockHandler_oneshot repeatedly even after
    we set pScreen->BlockHandler = AMDGPUBlockHandler_KMS.
    
    Bugzilla: https://bugs.freedesktop.org/99457
    (Ported from radeon commits 0a12bf1085505017068dfdfd31d23133e51b45b9 and
    f0e7948e1c0e984fc27f235f365639e9cf628291)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_drv.h b/src/amdgpu_drv.h
index 2aaafe4..ae5b6f9 100644
--- a/src/amdgpu_drv.h
+++ b/src/amdgpu_drv.h
@@ -230,6 +230,7 @@ typedef struct {
 
 	CreateScreenResourcesProcPtr CreateScreenResources;
 	CreateWindowProcPtr CreateWindow;
+	WindowExposuresProcPtr WindowExposures;
 
 	Bool IsSecondary;
 
diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index bafcb9b..ce1ae43 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -1039,17 +1039,6 @@ static void AMDGPUBlockHandler_KMS(BLOCKHANDLER_ARGS_DECL)
 #endif
 }
 
-static void AMDGPUBlockHandler_oneshot(BLOCKHANDLER_ARGS_DECL)
-{
-	SCREEN_PTR(arg);
-	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-	AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
-
-	AMDGPUBlockHandler_KMS(BLOCKHANDLER_ARGS);
-
-	drmmode_set_desired_modes(pScrn, &info->drmmode, TRUE);
-}
-
 /* This is called by AMDGPUPreInit to set up the default visual */
 static Bool AMDGPUPreInitVisual(ScrnInfoPtr pScrn)
 {
@@ -1266,6 +1255,31 @@ static Bool AMDGPUCreateWindow_oneshot(WindowPtr pWin)
 	return ret;
 }
 
+/* When the root window is mapped, set the initial modes */
+static void AMDGPUWindowExposures_oneshot(WindowPtr pWin, RegionPtr pRegion
+#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,16,99,901,0)
+					  , RegionPtr pBSRegion
+#endif
+	)
+{
+	ScreenPtr pScreen = pWin->drawable.pScreen;
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+	AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
+
+	if (pWin != pScreen->root)
+		ErrorF("%s called for non-root window %p\n", __func__, pWin);
+
+	pScreen->WindowExposures = info->WindowExposures;
+#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,16,99,901,0)
+	pScreen->WindowExposures(pWin, pRegion, pBSRegion);
+#else
+	pScreen->WindowExposures(pWin, pRegion);
+#endif
+
+	amdgpu_glamor_finish(pScrn);
+	drmmode_set_desired_modes(pScrn, &info->drmmode, TRUE);
+}
+
 Bool AMDGPUPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 {
 	AMDGPUInfoPtr info;
@@ -1824,6 +1838,8 @@ Bool AMDGPUScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
 		info->CreateWindow = pScreen->CreateWindow;
 		pScreen->CreateWindow = AMDGPUCreateWindow_oneshot;
 	}
+	info->WindowExposures = pScreen->WindowExposures;
+	pScreen->WindowExposures = AMDGPUWindowExposures_oneshot;
 
 	/* Provide SaveScreen & wrap BlockHandler and CloseScreen */
 	/* Wrap CloseScreen */
@@ -1831,7 +1847,7 @@ Bool AMDGPUScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
 	pScreen->CloseScreen = AMDGPUCloseScreen_KMS;
 	pScreen->SaveScreen = AMDGPUSaveScreen_KMS;
 	info->BlockHandler = pScreen->BlockHandler;
-	pScreen->BlockHandler = AMDGPUBlockHandler_oneshot;
+	pScreen->BlockHandler = AMDGPUBlockHandler_KMS;
 
 	info->CreateScreenResources = pScreen->CreateScreenResources;
 	pScreen->CreateScreenResources = AMDGPUCreateScreenResources_KMS;

commit 8d4d73e05ce34eb353daec7b2c0e7c844113c7de
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:34:16 2017 +0900

    present: Flush before flipping
    
    This isn't necessary for DRI clients, but the Present extension can also
    be used for presenting normal pixmaps rendered to via the X11 protocol.
    
    (Ported from radeon commit 9035b6abea557828e672ee455f0c84e43da0906f)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index d381e15..3c4bc52 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -327,6 +327,8 @@ amdgpu_present_flip(RRCrtcPtr crtc, uint64_t event_id, uint64_t target_msc,
 
 	event->event_id = event_id;
 
+	amdgpu_glamor_flush(scrn);
+
 	ret = amdgpu_do_pageflip(scrn, AMDGPU_DRM_QUEUE_CLIENT_DEFAULT,
 				 pixmap, event_id, event, crtc_id,
 				 amdgpu_present_flip_event,

commit 88725b68cad92418c9bb03cb7f20526ce238d64e
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:30:27 2017 +0900

    present: Use async flip for unflip if possible
    
    In that case, unflip operations should finish faster in general.
    
    (Ported from radeon commit 0a4eb0e12f0c9c653cf4cea6fd62e1a507eb261c)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index 4048f98..d381e15 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -48,6 +48,8 @@
 
 #include "present.h"
 
+static present_screen_info_rec amdgpu_present_screen_info;
+
 struct amdgpu_present_vblank_event {
 	uint64_t event_id;
 	Bool unflip;
@@ -351,6 +353,9 @@ amdgpu_present_unflip(ScreenPtr screen, uint64_t event_id)
 	xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
 	struct amdgpu_present_vblank_event *event;
 	PixmapPtr pixmap = screen->GetScreenPixmap(screen);
+	enum drmmode_flip_sync flip_sync =
+		(amdgpu_present_screen_info.capabilities & PresentCapabilityAsync) ?
+		FLIP_ASYNC : FLIP_VSYNC;
 	int old_fb_id;
 	int i;
 
@@ -369,7 +374,7 @@ amdgpu_present_unflip(ScreenPtr screen, uint64_t event_id)
 	amdgpu_glamor_flush(scrn);
 	if (amdgpu_do_pageflip(scrn, AMDGPU_DRM_QUEUE_CLIENT_DEFAULT, pixmap,
 			       event_id, event, -1, amdgpu_present_flip_event,
-			       amdgpu_present_flip_abort, FLIP_VSYNC, 0))
+			       amdgpu_present_flip_abort, flip_sync, 0))
 		return;
 
 modeset:

commit b31489c086b4bc50c824e85fa26d97c0f43afb20
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:28:41 2017 +0900

    present: Also flush before using a flip to unflip
    
    Not doing so might result in intermittently scanning out stale contents
    of the screen pixmap.
    
    (Ported from radeon commit 9a951a3e551db58ba50e7a594521ceac54d90615)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index cf6e36b..4048f98 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -366,6 +366,7 @@ amdgpu_present_unflip(ScreenPtr screen, uint64_t event_id)
 	event->event_id = event_id;
 	event->unflip = TRUE;
 
+	amdgpu_glamor_flush(scrn);
 	if (amdgpu_do_pageflip(scrn, AMDGPU_DRM_QUEUE_CLIENT_DEFAULT, pixmap,
 			       event_id, event, -1, amdgpu_present_flip_event,
 			       amdgpu_present_flip_abort, FLIP_VSYNC, 0))

commit f6a3c87c3097e8d5c1d2159bc90d6541a46ed8be
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:26:26 2017 +0900

    present: Wait for GPU idle before setting modes for unflip
    
    To make sure the screen pixmap contents are up to date when it starts
    being scanned out.
    
    (Ported from radeon commit 244d4bc7f8c8f6bc90f49556c0b9344c8aa40295)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index 5a345cb..cf6e36b 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -378,6 +378,7 @@ modeset:
 	old_fb_id = info->drmmode.fb_id;
 	info->drmmode.fb_id = 0;
 
+	amdgpu_glamor_finish(scrn);
 	for (i = 0; i < config->num_crtc; i++) {
 		xf86CrtcPtr crtc = config->crtc[i];
 		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;

commit 012ffffb45119059f3610fb8fd6ae103186b3e3c
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:22:39 2017 +0900

    present: Only call drmModeRmFB after setting modes for unflip
    
    Fixes display intermittently blanking when a modeset is used for unflip.
    
    (Ported from radeon commit 3ff29e5a14451916bc66b4e0028e9a317f0723f8)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index 3646190..5a345cb 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -351,6 +351,7 @@ amdgpu_present_unflip(ScreenPtr screen, uint64_t event_id)
 	xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
 	struct amdgpu_present_vblank_event *event;
 	PixmapPtr pixmap = screen->GetScreenPixmap(screen);
+	int old_fb_id;
 	int i;
 
 	if (!amdgpu_present_check_unflip(scrn))
@@ -374,7 +375,7 @@ modeset:
 	/* info->drmmode.fb_id still points to the FB for the last flipped BO.
 	 * Clear it, drmmode_set_mode_major will re-create it
 	 */
-	drmModeRmFB(pAMDGPUEnt->fd, info->drmmode.fb_id);
+	old_fb_id = info->drmmode.fb_id;
 	info->drmmode.fb_id = 0;
 
 	for (i = 0; i < config->num_crtc; i++) {
@@ -391,6 +392,7 @@ modeset:
 			drmmode_crtc->need_modeset = TRUE;
 	}
 
+	drmModeRmFB(pAMDGPUEnt->fd, old_fb_id);
 	present_event_notify(event_id, 0, 0);
 	info->drmmode.present_flipping = FALSE;
 }

commit f4719bb473df897012f8830f46e99cb781d67b6f
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Mar 3 16:19:11 2017 +0900

    Use drmmode_crtc_scanout_free in drmmode_fini
    
    We were leaking drmmode_crtc->scanout_damage, which caused trouble on
    server reset. Fixes server reset with active separate scanout pixmaps.
    
    (Cherry picked from radeon commit 0c29deb5a97d9a57e994cc0053c49ddf7aca6ecb)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 40439dd..406b5ee 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -2415,13 +2415,8 @@ void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 #endif
 	}
 
-	for (c = 0; c < config->num_crtc; c++) {
-		xf86CrtcPtr crtc = config->crtc[c];
-		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-
-		drmmode_crtc_scanout_destroy(&info->drmmode, &drmmode_crtc->scanout[0]);
-		drmmode_crtc_scanout_destroy(&info->drmmode, &drmmode_crtc->scanout[1]);
-	}
+	for (c = 0; c < config->num_crtc; c++)
+		drmmode_crtc_scanout_free(config->crtc[c]->driver_private);
 }
 
 void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id,

commit af0b24c1aca4cba2692d5aa410e63cb536478dbe
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Thu Mar 2 17:24:03 2017 +0900

    Allow toggling TearFree at runtime via output property
    
    Option "TearFree" now sets the default value of the output property.
    See the manpage update for details.
    
    TearFree is now enabled by default for outputs using rotation or other
    RandR transforms, and for RandR 1.4 slave outputs.
    
    (Ported from radeon commit 58cd1600057e41aade0106d4acf78e23eac6e44f)
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

diff --git a/man/amdgpu.man b/man/amdgpu.man
index 0e5c291..53bd768 100644
--- a/man/amdgpu.man
+++ b/man/amdgpu.man
@@ -73,10 +73,17 @@ Enable DRI2 page flipping.  The default is
 .B on.
 .TP
 .BI "Option \*qTearFree\*q \*q" boolean \*q
-Enable tearing prevention using the hardware page flipping mechanism. Requires allocating two
-separate scanout buffers for each CRTC. Enabling this option currently disables Option
-\*qEnablePageFlip\*q. The default is
-.B off.
+Set the default value of the per-output 'TearFree' property, which controls
+tearing prevention using the hardware page flipping mechanism. TearFree is
+on for any CRTC associated with one or more outputs with TearFree on. Two
+separate scanout buffers need to be allocated for each CRTC with TearFree
+on. While TearFree is on for any CRTC, it currently prevents clients from using
+DRI page flipping. If this option is set, the default value of the property is
+'on' or 'off' accordingly. If this option isn't set, the default value of the
+property is
+.B auto,
+which means that TearFree is on for outputs with rotation or other RandR
+transforms, and for RandR 1.4 slave outputs, otherwise off.
 .TP
 .BI "Option \*qAccelMethod\*q \*q" string \*q
 Setting this option to
diff --git a/src/amdgpu_dri2.c b/src/amdgpu_dri2.c
index a83d217..8dde293 100644
--- a/src/amdgpu_dri2.c
+++ b/src/amdgpu_dri2.c
@@ -51,6 +51,7 @@
 #include "amdgpu_list.h"
 
 #include <xf86Priv.h>
+#include <X11/extensions/dpmsconst.h>
 
 #if DRI2INFOREC_VERSION >= 9
 #define USE_DRI2_PRIME
@@ -637,13 +638,34 @@ can_flip(ScrnInfoPtr pScrn, DrawablePtr draw,


Reply to: