diff options
author | Keith Packard <keithp@keithp.com> | 2018-02-12 13:51:56 -0800 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2018-02-27 12:39:50 -0500 |
commit | e4e3447603b5fd3a38a92c3f972396d1f81168ad (patch) | |
tree | 46492faafe60037e5112d6b6702b7dc9b17987df /hw/xfree86/modes | |
parent | 023d4aba8d45e9e3630b944ecfb650c081799b96 (diff) |
Add RandR leases with modesetting driver support [v6]
This adds support for RandR CRTC/Output leases through the modesetting
driver, creating a lease using new kernel infrastructure and returning
that to a client through an fd which will have access to only those
resources.
v2: Restore CRTC mode when leases terminate
When a lease terminates for a crtc we have saved data for, go
ahead and restore the saved mode.
v3: Report RR_Rotate_0 rotations for leased crtcs.
Ignore leased CRTCs when selecting screen size.
Stop leasing encoders, the kernel doesn't do that anymore.
Turn off crtc->enabled while leased so that modesetting
ignores them.
Check lease status before calling any driver mode functions
When starting a lease, mark leased CRTCs as disabled and hide
their cursors. Also, check to see if there are other
non-leased CRTCs which are driving leased Outputs and mark
them as disabled as well. Sometimes an application will lease
an idle crtc instead of the one already associated with the
leased output.
When terminating a lease, reset any CRTCs which are driving
outputs that are no longer leased so that they start working
again.
This required splitting the DIX level lease termination code
into two pieces, one to remove the lease from the system
(RRLeaseTerminated) and a new function that frees the lease
data structure (RRLeaseFree).
v4: Report RR_Rotate_0 rotation for leased crtcs.
v5: Terminate all leases on server reset.
Leases hang around after the associated client exits so that
the client doesn't need to occupy an X server client slot and
consume a file descriptor once it has gotten the output
resources necessary.
Any leases still hanging around when the X server resets or
shuts down need to be cleaned up by calling the kernel to
terminate the lease and freeing any DIX structures.
Note that we cannot simply use the existing
drmmode_terminate_lease function on each lease as that wants
to also reset the video mode, and during server shut down that
modesetting: Validate leases on VT enter
The kernel doesn't allow any master ioctls to run when another
VT is active, including simple things like listing the active
leases. To deal with that, we check the list of leases
whenever the X server VT is activated.
xfree86: hide disabled cursors when resetting after lease termination
The lessee may well have played with cursors and left one
active on our screen. Just tell the kernel to turn it off.
v6: Add meson build infrastructure
[Also bumped libdrm requirement - ajax]
Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'hw/xfree86/modes')
-rw-r--r-- | hw/xfree86/modes/xf86Crtc.c | 24 | ||||
-rw-r--r-- | hw/xfree86/modes/xf86Crtc.h | 76 | ||||
-rw-r--r-- | hw/xfree86/modes/xf86Cursors.c | 6 | ||||
-rw-r--r-- | hw/xfree86/modes/xf86RandR12.c | 128 |
4 files changed, 228 insertions, 6 deletions
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c index 3ed7347df..4aa77a244 100644 --- a/hw/xfree86/modes/xf86Crtc.c +++ b/hw/xfree86/modes/xf86Crtc.c @@ -254,7 +254,7 @@ xf86CrtcSetModeTransform(xf86CrtcPtr crtc, DisplayModePtr mode, RRTransformRec saved_transform; Bool saved_transform_present; - crtc->enabled = xf86CrtcInUse(crtc); + crtc->enabled = xf86CrtcInUse(crtc) && !RRCrtcIsLeased(crtc->randr_crtc);; /* We only hit this if someone explicitly sends a "disabled" modeset. */ if (!crtc->enabled) { @@ -411,6 +411,10 @@ xf86CrtcSetOrigin(xf86CrtcPtr crtc, int x, int y) crtc->x = x; crtc->y = y; + + if (RRCrtcIsLeased(crtc->randr_crtc)) + return; + if (crtc->funcs->set_origin) { if (!xf86CrtcRotate(crtc)) return; @@ -2652,6 +2656,9 @@ xf86InitialConfiguration(ScrnInfoPtr scrn, Bool canGrow) static void xf86DisableCrtc(xf86CrtcPtr crtc) { + if (RRCrtcIsLeased(crtc->randr_crtc)) + return; + crtc->funcs->dpms(crtc, DPMSModeOff); xf86_crtc_hide_cursor(crtc); } @@ -2670,6 +2677,9 @@ xf86PrepareOutputs(ScrnInfoPtr scrn) for (o = 0; o < config->num_output; o++) { xf86OutputPtr output = config->output[o]; + if (RROutputIsLeased(output->randr_output)) + continue; + #if RANDR_GET_CRTC_INTERFACE /* Disable outputs that are unused or will be re-routed */ if (!output->funcs->get_crtc || @@ -2687,12 +2697,15 @@ xf86PrepareCrtcs(ScrnInfoPtr scrn) int c; for (c = 0; c < config->num_crtc; c++) { -#if RANDR_GET_CRTC_INTERFACE xf86CrtcPtr crtc = config->crtc[c]; +#if RANDR_GET_CRTC_INTERFACE xf86OutputPtr output = NULL; uint32_t desired_outputs = 0, current_outputs = 0; int o; + if (RRCrtcIsLeased(crtc->randr_crtc)) + continue; + for (o = 0; o < config->num_output; o++) { output = config->output[o]; if (output->crtc == crtc) @@ -2713,6 +2726,9 @@ xf86PrepareCrtcs(ScrnInfoPtr scrn) if (desired_outputs != current_outputs || !desired_outputs) xf86DisableCrtc(crtc); #else + if (RRCrtcIsLeased(crtc->randr_crtc)) + continue; + xf86DisableCrtc(crtc); #endif } @@ -2948,7 +2964,7 @@ xf86DPMSSet(ScrnInfoPtr scrn, int mode, int flags) for (i = 0; i < config->num_output; i++) { xf86OutputPtr output = config->output[i]; - if (output->crtc != NULL) + if (!RROutputIsLeased(output->randr_output) && output->crtc != NULL) (*output->funcs->dpms) (output, mode); } } @@ -2964,7 +2980,7 @@ xf86DPMSSet(ScrnInfoPtr scrn, int mode, int flags) for (i = 0; i < config->num_output; i++) { xf86OutputPtr output = config->output[i]; - if (output->crtc != NULL) + if (!RROutputIsLeased(output->randr_output) && output->crtc != NULL) (*output->funcs->dpms) (output, mode); } } diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h index ae81417f6..1d1124a1b 100644 --- a/hw/xfree86/modes/xf86Crtc.h +++ b/hw/xfree86/modes/xf86Crtc.h @@ -47,6 +47,7 @@ typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr; typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr; +typedef struct _xf86Lease xf86LeaseRec, *xf86LeasePtr; /* define a standard for connector types */ typedef enum _xf86ConnectorType { @@ -677,6 +678,54 @@ typedef struct _xf86ProviderFuncs { } xf86ProviderFuncsRec, *xf86ProviderFuncsPtr; +#define XF86_LEASE_VERSION 1 + +struct _xf86Lease { + /** + * ABI versioning + */ + int version; + + /** + * Associated ScrnInfo + */ + ScrnInfoPtr scrn; + + /** + * Driver private + */ + void *driver_private; + + /** + * RandR lease + */ + RRLeasePtr randr_lease; + + /* + * Contents of the lease + */ + + /** + * Number of leased CRTCs + */ + int num_crtc; + + /** + * Number of leased outputs + */ + int num_output; + + /** + * Array of pointers to leased CRTCs + */ + RRCrtcPtr *crtcs; + + /** + * Array of pointers to leased outputs + */ + RROutputPtr *outputs; +}; + typedef struct _xf86CrtcConfigFuncs { /** * Requests that the driver resize the screen. @@ -692,8 +741,29 @@ typedef struct _xf86CrtcConfigFuncs { */ Bool (*resize) (ScrnInfoPtr scrn, int width, int height); + + /** + * Requests that the driver create a lease + */ + int (*create_lease)(RRLeasePtr lease, int *fd); + + /** + * Ask the driver to terminate a lease, freeing all + * driver resources + */ + void (*terminate_lease)(RRLeasePtr lease); } xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr; +/* + * The driver calls this when it detects that a lease + * has been terminated + */ +extern _X_EXPORT void +xf86CrtcLeaseTerminated(RRLeasePtr lease); + +extern _X_EXPORT void +xf86CrtcLeaseStarted(RRLeasePtr lease); + typedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen); typedef struct _xf86CrtcConfig { @@ -1010,6 +1080,12 @@ extern _X_EXPORT void xf86_crtc_hide_cursor(xf86CrtcPtr crtc); /** + * Called by the driver to turn a single crtc's cursor on + */ +extern _X_EXPORT Bool +xf86_crtc_show_cursor(xf86CrtcPtr crtc); + +/** * Called by the driver to turn cursors off */ extern _X_EXPORT void diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c index ae2137d80..dba5f8877 100644 --- a/hw/xfree86/modes/xf86Cursors.c +++ b/hw/xfree86/modes/xf86Cursors.c @@ -344,11 +344,13 @@ xf86_hide_cursors(ScrnInfoPtr scrn) } } -static Bool +Bool xf86_crtc_show_cursor(xf86CrtcPtr crtc) { - if (!crtc->cursor_in_range) + if (!crtc->cursor_in_range) { + crtc->funcs->hide_cursor(crtc); return TRUE; + } if (!crtc->cursor_shown) crtc->cursor_shown = xf86_driver_show_cursor(crtc); diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c index 818048335..b49d4c789 100644 --- a/hw/xfree86/modes/xf86RandR12.c +++ b/hw/xfree86/modes/xf86RandR12.c @@ -2205,6 +2205,131 @@ xf86RandR14ProviderDestroy(ScreenPtr screen, RRProviderPtr provider) config->randr_provider = NULL; } +static void +xf86CrtcCheckReset(xf86CrtcPtr crtc) { + if (xf86CrtcInUse(crtc)) { + RRTransformPtr transform; + + if (crtc->desiredTransformPresent) + transform = &crtc->desiredTransform; + else + transform = NULL; + xf86CrtcSetModeTransform(crtc, &crtc->desiredMode, + crtc->desiredRotation, transform, + crtc->desiredX, crtc->desiredY); + xf86_crtc_show_cursor(crtc); + } +} + +void +xf86CrtcLeaseTerminated(RRLeasePtr lease) +{ + int c; + int o; + + RRLeaseTerminated(lease); + /* + * Force a full mode set on any crtc in the expiring lease which + * was running before the lease started + */ + for (c = 0; c < lease->numCrtcs; c++) { + RRCrtcPtr randr_crtc = lease->crtcs[c]; + xf86CrtcPtr crtc = randr_crtc->devPrivate; + + xf86CrtcCheckReset(crtc); + } + + /* Check to see if any leased output is using a crtc which + * was not reset in the above loop + */ + for (o = 0; o < lease->numOutputs; o++) { + RROutputPtr randr_output = lease->outputs[o]; + xf86OutputPtr output = randr_output->devPrivate; + xf86CrtcPtr crtc = output->crtc; + + if (crtc) { + for (c = 0; c < lease->numCrtcs; c++) + if (lease->crtcs[c] == crtc->randr_crtc) + break; + if (c != lease->numCrtcs) + continue; + xf86CrtcCheckReset(crtc); + } + } + RRLeaseFree(lease); +} + +static Bool +xf86CrtcSoleOutput(xf86CrtcPtr crtc, xf86OutputPtr output) +{ + ScrnInfoPtr scrn = crtc->scrn; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int o; + + for (o = 0; o < config->num_output; o++) { + xf86OutputPtr other = config->output[o]; + + if (other != output && other->crtc == crtc) + return FALSE; + } + return TRUE; +} + +void +xf86CrtcLeaseStarted(RRLeasePtr lease) +{ + int c; + int o; + + for (c = 0; c < lease->numCrtcs; c++) { + RRCrtcPtr randr_crtc = lease->crtcs[c]; + xf86CrtcPtr crtc = randr_crtc->devPrivate; + + if (crtc->enabled) { + /* + * Leave the primary plane enabled so we can + * flip without blanking the screen. Hide + * the cursor so it doesn't remain on the screen + * while the lease is active + */ + xf86_crtc_hide_cursor(crtc); + crtc->enabled = FALSE; + } + } + for (o = 0; o < lease->numOutputs; o++) { + RROutputPtr randr_output = lease->outputs[o]; + xf86OutputPtr output = randr_output->devPrivate; + xf86CrtcPtr crtc = output->crtc; + + if (crtc) + if (xf86CrtcSoleOutput(crtc, output)) + crtc->enabled = FALSE; + } +} + +static int +xf86RandR16CreateLease(ScreenPtr screen, RRLeasePtr randr_lease, int *fd) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + + if (config->funcs->create_lease) + return config->funcs->create_lease(randr_lease, fd); + else + return BadMatch; +} + + +static void +xf86RandR16TerminateLease(ScreenPtr screen, RRLeasePtr randr_lease) +{ + ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + + if (config->funcs->terminate_lease) + config->funcs->terminate_lease(randr_lease); +} + static Bool xf86RandR12Init12(ScreenPtr pScreen) { @@ -2234,6 +2359,9 @@ xf86RandR12Init12(ScreenPtr pScreen) rp->rrCrtcSetScanoutPixmap = xf86CrtcSetScanoutPixmap; rp->rrProviderDestroy = xf86RandR14ProviderDestroy; + rp->rrCreateLease = xf86RandR16CreateLease; + rp->rrTerminateLease = xf86RandR16TerminateLease; + pScrn->PointerMoved = xf86RandR12PointerMoved; pScrn->ChangeGamma = xf86RandR12ChangeGamma; |