summaryrefslogtreecommitdiff
path: root/hw/xfree86/drivers/modesetting/vblank.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-09-29 08:48:33 -0700
committerAdam Jackson <ajax@redhat.com>2017-10-04 15:25:51 -0400
commit388dc1aeac9acf2d51ad5103570beffd81d78b96 (patch)
treea05227d6afa40124e927ea0497376d6f27247de1 /hw/xfree86/drivers/modesetting/vblank.c
parent8bd33a2db7337b2801fc630a57e36b6aeea219d9 (diff)
xf86-video-modesetting: Add ms_queue_vblank helper [v3]
This provides an API wrapper around the kernel interface for queueing a vblank event, simplifying all of the callers. v2: Fix missing '|' in computing vbl.request.type v3: Remove spurious bit of next patch (thanks, Michel Dänzer) Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com> (cherry picked from commit 677c32bcda98a96585bb1f66b57e0755a157b772)
Diffstat (limited to 'hw/xfree86/drivers/modesetting/vblank.c')
-rw-r--r--hw/xfree86/drivers/modesetting/vblank.c67
1 files changed, 55 insertions, 12 deletions
diff --git a/hw/xfree86/drivers/modesetting/vblank.c b/hw/xfree86/drivers/modesetting/vblank.c
index 8682f4d91..31cf0bd70 100644
--- a/hw/xfree86/drivers/modesetting/vblank.c
+++ b/hw/xfree86/drivers/modesetting/vblank.c
@@ -173,7 +173,7 @@ ms_dri2_crtc_covering_drawable(DrawablePtr pDraw)
static Bool
ms_get_kernel_ust_msc(xf86CrtcPtr crtc,
- uint32_t *msc, uint64_t *ust)
+ uint64_t *msc, uint64_t *ust)
{
ScreenPtr screen = crtc->randr_crtc->pScreen;
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
@@ -198,13 +198,50 @@ ms_get_kernel_ust_msc(xf86CrtcPtr crtc,
}
}
+Bool
+ms_queue_vblank(xf86CrtcPtr crtc, ms_queue_flag flags,
+ uint64_t msc, uint64_t *msc_queued, uint32_t seq)
+{
+ ScreenPtr screen = crtc->randr_crtc->pScreen;
+ ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+ modesettingPtr ms = modesettingPTR(scrn);
+ drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+ drmVBlank vbl;
+ int ret;
+
+ for (;;) {
+ /* Queue an event at the specified sequence */
+ vbl.request.type = DRM_VBLANK_EVENT | drmmode_crtc->vblank_pipe;
+ if (flags & MS_QUEUE_RELATIVE)
+ vbl.request.type |= DRM_VBLANK_RELATIVE;
+ else
+ vbl.request.type |= DRM_VBLANK_ABSOLUTE;
+ if (flags & MS_QUEUE_NEXT_ON_MISS)
+ vbl.request.type |= DRM_VBLANK_NEXTONMISS;
+
+ vbl.request.sequence = ms_crtc_msc_to_kernel_msc(crtc, msc);
+ vbl.request.signal = seq;
+ ret = drmWaitVBlank(ms->fd, &vbl);
+ if (ret == 0) {
+ if (msc_queued)
+ *msc_queued = ms_kernel_msc_to_crtc_msc(crtc, vbl.reply.sequence);
+ return TRUE;
+ }
+ if (errno != EBUSY) {
+ ms_drm_abort_seq(scrn, msc);
+ return FALSE;
+ }
+ ms_flush_drm_events(screen);
+ }
+}
+
/**
* Convert a 32-bit kernel MSC sequence number to a 64-bit local sequence
* number, adding in the vblank_offset and high 32 bits, and dealing
* with 64-bit wrapping
*/
uint64_t
-ms_kernel_msc_to_crtc_msc(xf86CrtcPtr crtc, uint32_t sequence)
+ms_kernel_msc_to_crtc_msc(xf86CrtcPtr crtc, uint64_t sequence)
{
drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private;
sequence += drmmode_crtc->vblank_offset;
@@ -218,7 +255,7 @@ ms_kernel_msc_to_crtc_msc(xf86CrtcPtr crtc, uint32_t sequence)
int
ms_get_crtc_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc)
{
- uint32_t kernel_msc;
+ uint64_t kernel_msc;
if (!ms_get_kernel_ust_msc(crtc, &kernel_msc, ust))
return BadMatch;
@@ -230,13 +267,13 @@ ms_get_crtc_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc)
#define MAX_VBLANK_OFFSET 1000
/**
- * Convert a 64-bit adjusted MSC value into a 32-bit kernel sequence number,
- * removing the high 32 bits and subtracting out the vblank_offset term.
+ * Convert a 64-bit adjusted MSC value into a 64-bit kernel sequence number,
+ * by subtracting out the vblank_offset term.
*
* This also updates the vblank_offset when it notices that the value should
* change.
*/
-uint32_t
+uint64_t
ms_crtc_msc_to_kernel_msc(xf86CrtcPtr crtc, uint64_t expect)
{
drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private;
@@ -257,7 +294,7 @@ ms_crtc_msc_to_kernel_msc(xf86CrtcPtr crtc, uint64_t expect)
drmmode_crtc->vblank_offset = 0;
}
}
- return (uint32_t) (expect - drmmode_crtc->vblank_offset);
+ return (expect - drmmode_crtc->vblank_offset);
}
/**
@@ -375,25 +412,31 @@ ms_drm_abort(ScrnInfoPtr scrn, Bool (*match)(void *data, void *match_data),
* drm event queue and calls the handler for it.
*/
static void
-ms_drm_handler(int fd, uint32_t frame, uint32_t sec, uint32_t usec,
- void *user_ptr)
+ms_drm_sequence_handler(int fd, uint64_t frame, uint64_t ns, uint64_t user_data)
{
struct ms_drm_queue *q, *tmp;
- uint32_t user_data = (uint32_t) (intptr_t) user_ptr;
+ uint32_t seq = (uint32_t) user_data;
xorg_list_for_each_entry_safe(q, tmp, &ms_drm_queue, list) {
- if (q->seq == user_data) {
+ if (q->seq == seq) {
uint64_t msc;
msc = ms_kernel_msc_to_crtc_msc(q->crtc, frame);
xorg_list_del(&q->list);
- q->handler(msc, (uint64_t) sec * 1000000 + usec, q->data);
+ q->handler(msc, ns / 1000, q->data);
free(q);
break;
}
}
}
+static void
+ms_drm_handler(int fd, uint32_t frame, uint32_t sec, uint32_t usec,
+ void *user_ptr)
+{
+ ms_drm_sequence_handler(fd, frame, ((uint64_t) sec * 1000000 + usec) * 1000, (uint32_t) (uintptr_t) user_ptr);
+}
+
Bool
ms_vblank_screen_init(ScreenPtr screen)
{