All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michel Dänzer" <michel-otUistvHUpPR7s880joybQ@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH xf86-video-ati 21/21] Add RandR leases support
Date: Wed, 11 Jul 2018 19:28:06 +0200	[thread overview]
Message-ID: <20180711172806.22849-22-michel@daenzer.net> (raw)
In-Reply-To: <20180711172806.22849-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org>

From: Keith Packard <keithp@keithp.com>

Signed-off-by: Keith Packard <keithp@keithp.com>
(Ported from xserver commit e4e3447603b5fd3a38a92c3f972396d1f81168ad)
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
(Ported from amdgpu commit 61040bdfa360975614fb47aa7ea1b3a1abac3427)
---
 configure.ac          |   2 +-
 src/drmmode_display.c | 159 +++++++++++++++++++++++++++++++++++++++++-
 src/drmmode_display.h |   6 ++
 src/radeon_kms.c      |   1 +
 4 files changed, 166 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 65206e7fc..15c7b2128 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,7 +70,7 @@ XORG_DRIVER_CHECK_EXT(XV, videoproto)
 XORG_DRIVER_CHECK_EXT(DPMSExtension, xextproto)
 
 # Checks for libraries.
-PKG_CHECK_MODULES(LIBDRM, [libdrm >= 2.4.78])
+PKG_CHECK_MODULES(LIBDRM, [libdrm >= 2.4.89])
 PKG_CHECK_MODULES(LIBDRM_RADEON, [libdrm_radeon])
 
 # Obtain compiler/linker options for the driver dependencies
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index d4bd76e12..2af64e3f3 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -2400,8 +2400,159 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	return FALSE;
 }
 
+static void
+drmmode_validate_leases(ScrnInfoPtr scrn)
+{
+#ifdef XF86_LEASE_VERSION
+	ScreenPtr screen = scrn->pScreen;
+	rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
+	RADEONEntPtr pRADEONEnt = RADEONEntPriv(scrn);
+	drmModeLesseeListPtr lessees;
+	RRLeasePtr lease, next;
+	int l;
+
+	/* We can't talk to the kernel about leases when VT switched */
+	if (!scrn->vtSema)
+		return;
+
+	lessees = drmModeListLessees(pRADEONEnt->fd);
+	if (!lessees)
+		return;
+
+	xorg_list_for_each_entry_safe(lease, next, &scr_priv->leases, list) {
+		drmmode_lease_private_ptr lease_private = lease->devPrivate;
+
+		for (l = 0; l < lessees->count; l++) {
+			if (lessees->lessees[l] == lease_private->lessee_id)
+				break;
+		}
+
+		/* check to see if the lease has gone away */
+		if (l == lessees->count) {
+			free(lease_private);
+			lease->devPrivate = NULL;
+			xf86CrtcLeaseTerminated(lease);
+		}
+	}
+
+	free(lessees);
+#endif
+}
+
+#ifdef XF86_LEASE_VERSION
+
+static int
+drmmode_create_lease(RRLeasePtr lease, int *fd)
+{
+	ScreenPtr screen = lease->screen;
+	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+	RADEONEntPtr pRADEONEnt = RADEONEntPriv(scrn);
+	drmmode_lease_private_ptr lease_private;
+	int noutput = lease->numOutputs;
+	int ncrtc = lease->numCrtcs;
+	uint32_t *objects;
+	size_t nobjects;
+	int lease_fd;
+	int c, o;
+	int i;
+
+	nobjects = ncrtc + noutput;
+	if (nobjects == 0 || nobjects > (SIZE_MAX / 4) ||
+	    ncrtc > (SIZE_MAX - noutput))
+		return BadValue;
+
+	lease_private = calloc(1, sizeof (drmmode_lease_private_rec));
+	if (!lease_private)
+		return BadAlloc;
+
+	objects = malloc(nobjects * 4);
+	if (!objects) {
+		free(lease_private);
+		return BadAlloc;
+	}
+
+	i = 0;
+
+	/* Add CRTC ids */
+	for (c = 0; c < ncrtc; c++) {
+		xf86CrtcPtr crtc = lease->crtcs[c]->devPrivate;
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+		objects[i++] = drmmode_crtc->mode_crtc->crtc_id;
+	}
+
+	/* Add connector ids */
+	for (o = 0; o < noutput; o++) {
+		xf86OutputPtr   output = lease->outputs[o]->devPrivate;
+		drmmode_output_private_ptr drmmode_output = output->driver_private;
+
+		objects[i++] = drmmode_output->mode_output->connector_id;
+	}
+
+	/* call kernel to create lease */
+	assert (i == nobjects);
+
+	lease_fd = drmModeCreateLease(pRADEONEnt->fd, objects, nobjects, 0,
+				      &lease_private->lessee_id);
+
+	free(objects);
+
+	if (lease_fd < 0) {
+		free(lease_private);
+		return BadMatch;
+	}
+
+	lease->devPrivate = lease_private;
+
+	xf86CrtcLeaseStarted(lease);
+
+	*fd = lease_fd;
+	return Success;
+}
+
+static void
+drmmode_terminate_lease(RRLeasePtr lease)
+{
+	drmmode_lease_private_ptr lease_private = lease->devPrivate;
+	ScreenPtr screen = lease->screen;
+	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+	RADEONEntPtr pRADEONEnt = RADEONEntPriv(scrn);
+
+	if (drmModeRevokeLease(pRADEONEnt->fd, lease_private->lessee_id) == 0) {
+		free(lease_private);
+		lease->devPrivate = NULL;
+		xf86CrtcLeaseTerminated(lease);
+	}
+}
+
+#endif // XF86_LEASE_VERSION
+
+void
+drmmode_terminate_leases(ScrnInfoPtr pScrn)
+{
+#ifdef XF86_LEASE_VERSION
+	ScreenPtr screen = xf86ScrnToScreen(pScrn);
+	RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn);
+	rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
+	RRLeasePtr lease, next;
+
+	xorg_list_for_each_entry_safe(lease, next, &scr_priv->leases, list) {
+		drmmode_lease_private_ptr lease_private = lease->devPrivate;
+		drmModeRevokeLease(pRADEONEnt->fd, lease_private->lessee_id);
+		free(lease_private);
+		lease->devPrivate = NULL;
+		RRLeaseTerminated(lease);
+		RRLeaseFree(lease);
+	}
+#endif
+}
+
 static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
-	drmmode_xf86crtc_resize
+	.resize = drmmode_xf86crtc_resize,
+#ifdef XF86_LEASE_VERSION
+	.create_lease = drmmode_create_lease,
+	.terminate_lease = drmmode_terminate_lease
+#endif
 };
 
 static void
@@ -2888,6 +3039,9 @@ Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode,
 		return FALSE;
 	}
 
+	/* Validate leases on VT re-entry */
+	drmmode_validate_leases(pScrn);
+
 	return TRUE;
 }
 
@@ -3055,6 +3209,9 @@ restart_destroy:
 			changed = TRUE;
 	}
 
+	/* Check to see if a lessee has disappeared */
+	drmmode_validate_leases(scrn);
+
 	if (changed && dixPrivateKeyRegistered(rrPrivKey)) {
 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
 		RRSetChanged(xf86ScrnToScreen(scrn));
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index 27c23c1a4..4551e0c77 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -139,6 +139,10 @@ typedef struct {
     int tear_free;
 } drmmode_output_private_rec, *drmmode_output_private_ptr;
 
+typedef struct {
+    uint32_t lessee_id;
+} drmmode_lease_private_rec, *drmmode_lease_private_ptr;
+
 
 enum drmmode_flip_sync {
     FLIP_VSYNC,
@@ -223,6 +227,8 @@ PixmapPtr drmmode_crtc_scanout_create(xf86CrtcPtr crtc,
 extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode);
 extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode);
 
+extern void drmmode_terminate_leases(ScrnInfoPtr scrn);
+
 Bool drmmode_set_mode(xf86CrtcPtr crtc, struct drmmode_fb *fb,
 		      DisplayModePtr mode, int x, int y);
 
diff --git a/src/radeon_kms.c b/src/radeon_kms.c
index 36840ad36..c8a5726ad 100644
--- a/src/radeon_kms.c
+++ b/src/radeon_kms.c
@@ -2154,6 +2154,7 @@ static Bool RADEONCloseScreen_KMS(ScreenPtr pScreen)
     /* Clear mask of assigned crtc's in this generation */
     pRADEONEnt->assigned_crtcs = 0;
 
+    drmmode_terminate_leases(pScrn);
     drmmode_uevent_fini(pScrn, &info->drmmode);
     radeon_drm_queue_close(pScrn);
     radeon_cs_flush_indirect(pScrn);
-- 
2.18.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-07-11 17:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-11 17:27 [PATCH xf86-video-ati 00/21] Port outstanding changes frm Michel Dänzer
     [not found] ` <20180711172806.22849-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-07-11 17:27   ` [PATCH xf86-video-ati 01/21] Wait for pending scanout update before calling drmmode_crtc_scanout_free Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 02/21] Do not export the DriverRec RADEON Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 03/21] Ignore RADEON_DRM_QUEUE_ERROR (0) in radeon_drm_abort_entry Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 04/21] Track DRM event queue sequence number in scanout_update_pending Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 05/21] Abort scanout_update_pending event when possible Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 06/21] Update RandR CRTC state if set_mode_major fails in set_desired_modes Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 07/21] Simplify drmmode_crtc_scanout_update Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 08/21] Don't call scanout_flip/update with a legacy RandR scanout buffer Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 09/21] Simplify drmmode_handle_transform Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 10/21] Set drmmode_crtc->scanout_id = 0 when TearFree is disabled Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 11/21] Refactor drmmode_output_set_tear_free helper Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 12/21] Wait for pending flips in drmmode_output_set_tear_free Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 13/21] Replace 'foo == NULL' with '!foo' Michel Dänzer
2018-07-11 17:27   ` [PATCH xf86-video-ati 14/21] Call drmmode_do_crtc_dpms from drmmode_crtc_dpms as well Michel Dänzer
2018-07-11 17:28   ` [PATCH xf86-video-ati 15/21] Use drmmode_crtc_dpms in drmmode_set_desired_modes Michel Dänzer
2018-07-11 17:28   ` [PATCH xf86-video-ati 16/21] Check dimensions passed to drmmode_xf86crtc_resize Michel Dänzer
2018-07-11 17:28   ` [PATCH xf86-video-ati 17/21] Remove #if 0'd code Michel Dänzer
2018-07-11 17:28   ` [PATCH xf86-video-ati 18/21] Call drmmode_crtc_gamma_do_set from drmmode_setup_colormap Michel Dänzer
2018-07-11 17:28   ` [PATCH xf86-video-ati 19/21] modesetting: Record non-desktop kernel property at PreInit time Michel Dänzer
2018-07-11 17:28   ` [PATCH xf86-video-ati 20/21] modesetting: Create CONNECTOR_ID properties for outputs [v2] Michel Dänzer
2018-07-11 17:28   ` Michel Dänzer [this message]
2018-07-12  4:48   ` [PATCH xf86-video-ati 00/21] Port outstanding changes frm Alex Deucher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180711172806.22849-22-michel@daenzer.net \
    --to=michel-otuistvhuppr7s880joybq@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.