forked from luck/tmp_suning_uos_patched
drm: Widen vblank count to 64-bits [v3]
This modifies the datatypes used by the vblank code to provide 64 bits of vblank count. The driver interfaces have been left using 32 bits of vblank count; all of the code necessary to widen that value for the user API was already included to handle devices returning fewer than 32-bits. This will provide the necessary datatypes for the Vulkan API. v2: * Re-write wait_vblank ioctl to ABSOLUTE sequence When an application uses the WAIT_VBLANK ioctl with RELATIVE or NEXTONMISS bits set, the target vblank interval is updated within the kernel. We need to write that target back to the ioctl buffer and update the flags bits so that if the wait is interrupted by a signal, when it is re-started, it will target precisely the same vblank count as before. * Leave driver API with 32-bit vblank count v3: * Rebase on top of Arnd Bergmann's patch which had the switch to ktime_t parts. [airlied: fix conflict with Ville vblank change]. Suggested-by: Michel Dänzer <michel@daenzer.net> Suggested-by: Daniel Vetter <daniel@ffwll.ch> Signed-off-by: Keith Packard <keithp@keithp.com> Signed-off-by: Dave Airlie <airlied@redhat.com> (cherry picked from commit 2affbc16983e4fc90960bc7f70e7615f4228199b)
This commit is contained in:
parent
19f470b2e4
commit
570e86963a
|
@ -251,7 +251,7 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe,
|
||||||
}
|
}
|
||||||
|
|
||||||
DRM_DEBUG_VBL("updating vblank count on crtc %u:"
|
DRM_DEBUG_VBL("updating vblank count on crtc %u:"
|
||||||
" current=%u, diff=%u, hw=%u hw_last=%u\n",
|
" current=%llu, diff=%u, hw=%u hw_last=%u\n",
|
||||||
pipe, vblank->count, diff, cur_vblank, vblank->last);
|
pipe, vblank->count, diff, cur_vblank, vblank->last);
|
||||||
|
|
||||||
if (diff == 0) {
|
if (diff == 0) {
|
||||||
|
@ -740,17 +740,31 @@ drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe,
|
||||||
* Returns:
|
* Returns:
|
||||||
* The software vblank counter.
|
* The software vblank counter.
|
||||||
*/
|
*/
|
||||||
u32 drm_crtc_vblank_count(struct drm_crtc *crtc)
|
u64 drm_crtc_vblank_count(struct drm_crtc *crtc)
|
||||||
{
|
{
|
||||||
return drm_vblank_count(crtc->dev, drm_crtc_index(crtc));
|
return drm_vblank_count(crtc->dev, drm_crtc_index(crtc));
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(drm_crtc_vblank_count);
|
EXPORT_SYMBOL(drm_crtc_vblank_count);
|
||||||
|
|
||||||
static u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
|
/**
|
||||||
|
* drm_vblank_count_and_time - retrieve "cooked" vblank counter value and the
|
||||||
|
* system timestamp corresponding to that vblank counter value.
|
||||||
|
* @dev: DRM device
|
||||||
|
* @pipe: index of CRTC whose counter to retrieve
|
||||||
|
* @vblanktime: Pointer to ktime_t to receive the vblank timestamp.
|
||||||
|
*
|
||||||
|
* Fetches the "cooked" vblank count value that represents the number of
|
||||||
|
* vblank events since the system was booted, including lost events due to
|
||||||
|
* modesetting activity. Returns corresponding system timestamp of the time
|
||||||
|
* of the vblank interval that corresponds to the current vblank counter value.
|
||||||
|
*
|
||||||
|
* This is the legacy version of drm_crtc_vblank_count_and_time().
|
||||||
|
*/
|
||||||
|
static u64 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
|
||||||
ktime_t *vblanktime)
|
ktime_t *vblanktime)
|
||||||
{
|
{
|
||||||
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
|
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
|
||||||
u32 vblank_count;
|
u64 vblank_count;
|
||||||
unsigned int seq;
|
unsigned int seq;
|
||||||
|
|
||||||
if (WARN_ON(pipe >= dev->num_crtcs)) {
|
if (WARN_ON(pipe >= dev->num_crtcs)) {
|
||||||
|
@ -778,7 +792,7 @@ static u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
|
||||||
* modesetting activity. Returns corresponding system timestamp of the time
|
* modesetting activity. Returns corresponding system timestamp of the time
|
||||||
* of the vblank interval that corresponds to the current vblank counter value.
|
* of the vblank interval that corresponds to the current vblank counter value.
|
||||||
*/
|
*/
|
||||||
u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
|
u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
|
||||||
ktime_t *vblanktime)
|
ktime_t *vblanktime)
|
||||||
{
|
{
|
||||||
return drm_vblank_count_and_time(crtc->dev, drm_crtc_index(crtc),
|
return drm_vblank_count_and_time(crtc->dev, drm_crtc_index(crtc),
|
||||||
|
@ -788,7 +802,7 @@ EXPORT_SYMBOL(drm_crtc_vblank_count_and_time);
|
||||||
|
|
||||||
static void send_vblank_event(struct drm_device *dev,
|
static void send_vblank_event(struct drm_device *dev,
|
||||||
struct drm_pending_vblank_event *e,
|
struct drm_pending_vblank_event *e,
|
||||||
unsigned long seq, ktime_t now)
|
u64 seq, ktime_t now)
|
||||||
{
|
{
|
||||||
struct timespec64 tv = ktime_to_timespec64(now);
|
struct timespec64 tv = ktime_to_timespec64(now);
|
||||||
|
|
||||||
|
@ -854,7 +868,7 @@ void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
|
||||||
assert_spin_locked(&dev->event_lock);
|
assert_spin_locked(&dev->event_lock);
|
||||||
|
|
||||||
e->pipe = pipe;
|
e->pipe = pipe;
|
||||||
e->event.sequence = drm_crtc_accurate_vblank_count(crtc) + 1;
|
e->sequence = drm_crtc_accurate_vblank_count(crtc) + 1;
|
||||||
e->event.crtc_id = crtc->base.id;
|
e->event.crtc_id = crtc->base.id;
|
||||||
list_add_tail(&e->base.link, &dev->vblank_event_list);
|
list_add_tail(&e->base.link, &dev->vblank_event_list);
|
||||||
}
|
}
|
||||||
|
@ -875,7 +889,8 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
|
||||||
struct drm_pending_vblank_event *e)
|
struct drm_pending_vblank_event *e)
|
||||||
{
|
{
|
||||||
struct drm_device *dev = crtc->dev;
|
struct drm_device *dev = crtc->dev;
|
||||||
unsigned int seq, pipe = drm_crtc_index(crtc);
|
u64 seq;
|
||||||
|
unsigned int pipe = drm_crtc_index(crtc);
|
||||||
ktime_t now;
|
ktime_t now;
|
||||||
|
|
||||||
if (dev->num_crtcs > 0) {
|
if (dev->num_crtcs > 0) {
|
||||||
|
@ -1088,7 +1103,7 @@ void drm_crtc_vblank_off(struct drm_crtc *crtc)
|
||||||
|
|
||||||
ktime_t now;
|
ktime_t now;
|
||||||
unsigned long irqflags;
|
unsigned long irqflags;
|
||||||
unsigned int seq;
|
u64 seq;
|
||||||
|
|
||||||
if (WARN_ON(pipe >= dev->num_crtcs))
|
if (WARN_ON(pipe >= dev->num_crtcs))
|
||||||
return;
|
return;
|
||||||
|
@ -1123,8 +1138,8 @@ void drm_crtc_vblank_off(struct drm_crtc *crtc)
|
||||||
if (e->pipe != pipe)
|
if (e->pipe != pipe)
|
||||||
continue;
|
continue;
|
||||||
DRM_DEBUG("Sending premature vblank event on disable: "
|
DRM_DEBUG("Sending premature vblank event on disable: "
|
||||||
"wanted %u, current %u\n",
|
"wanted %llu, current %llu\n",
|
||||||
e->event.sequence, seq);
|
e->sequence, seq);
|
||||||
list_del(&e->base.link);
|
list_del(&e->base.link);
|
||||||
drm_vblank_put(dev, pipe);
|
drm_vblank_put(dev, pipe);
|
||||||
send_vblank_event(dev, e, seq, now);
|
send_vblank_event(dev, e, seq, now);
|
||||||
|
@ -1296,12 +1311,13 @@ int drm_legacy_modeset_ctl_ioctl(struct drm_device *dev, void *data,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool vblank_passed(u32 seq, u32 ref)
|
static inline bool vblank_passed(u64 seq, u64 ref)
|
||||||
{
|
{
|
||||||
return (seq - ref) <= (1 << 23);
|
return (seq - ref) <= (1 << 23);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe,
|
static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe,
|
||||||
|
u64 req_seq,
|
||||||
union drm_wait_vblank *vblwait,
|
union drm_wait_vblank *vblwait,
|
||||||
struct drm_file *file_priv)
|
struct drm_file *file_priv)
|
||||||
{
|
{
|
||||||
|
@ -1309,7 +1325,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe,
|
||||||
struct drm_pending_vblank_event *e;
|
struct drm_pending_vblank_event *e;
|
||||||
ktime_t now;
|
ktime_t now;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
unsigned int seq;
|
u64 seq;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
e = kzalloc(sizeof(*e), GFP_KERNEL);
|
e = kzalloc(sizeof(*e), GFP_KERNEL);
|
||||||
|
@ -1344,21 +1360,20 @@ static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe,
|
||||||
|
|
||||||
seq = drm_vblank_count_and_time(dev, pipe, &now);
|
seq = drm_vblank_count_and_time(dev, pipe, &now);
|
||||||
|
|
||||||
DRM_DEBUG("event on vblank count %u, current %u, crtc %u\n",
|
DRM_DEBUG("event on vblank count %llu, current %llu, crtc %u\n",
|
||||||
vblwait->request.sequence, seq, pipe);
|
req_seq, seq, pipe);
|
||||||
|
|
||||||
trace_drm_vblank_event_queued(file_priv, pipe,
|
trace_drm_vblank_event_queued(file_priv, pipe, req_seq);
|
||||||
vblwait->request.sequence);
|
|
||||||
|
|
||||||
e->event.sequence = vblwait->request.sequence;
|
e->sequence = req_seq;
|
||||||
if (vblank_passed(seq, vblwait->request.sequence)) {
|
if (vblank_passed(seq, req_seq)) {
|
||||||
drm_vblank_put(dev, pipe);
|
drm_vblank_put(dev, pipe);
|
||||||
send_vblank_event(dev, e, seq, now);
|
send_vblank_event(dev, e, seq, now);
|
||||||
vblwait->reply.sequence = seq;
|
vblwait->reply.sequence = seq;
|
||||||
} else {
|
} else {
|
||||||
/* drm_handle_vblank_events will call drm_vblank_put */
|
/* drm_handle_vblank_events will call drm_vblank_put */
|
||||||
list_add_tail(&e->base.link, &dev->vblank_event_list);
|
list_add_tail(&e->base.link, &dev->vblank_event_list);
|
||||||
vblwait->reply.sequence = vblwait->request.sequence;
|
vblwait->reply.sequence = req_seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&dev->event_lock, flags);
|
spin_unlock_irqrestore(&dev->event_lock, flags);
|
||||||
|
@ -1384,6 +1399,22 @@ static bool drm_wait_vblank_is_query(union drm_wait_vblank *vblwait)
|
||||||
_DRM_VBLANK_NEXTONMISS));
|
_DRM_VBLANK_NEXTONMISS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Widen a 32-bit param to 64-bits.
|
||||||
|
*
|
||||||
|
* \param narrow 32-bit value (missing upper 32 bits)
|
||||||
|
* \param near 64-bit value that should be 'close' to near
|
||||||
|
*
|
||||||
|
* This function returns a 64-bit value using the lower 32-bits from
|
||||||
|
* 'narrow' and constructing the upper 32-bits so that the result is
|
||||||
|
* as close as possible to 'near'.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static u64 widen_32_to_64(u32 narrow, u64 near)
|
||||||
|
{
|
||||||
|
return near + (s32) (narrow - near);
|
||||||
|
}
|
||||||
|
|
||||||
static void drm_wait_vblank_reply(struct drm_device *dev, unsigned int pipe,
|
static void drm_wait_vblank_reply(struct drm_device *dev, unsigned int pipe,
|
||||||
struct drm_wait_vblank_reply *reply)
|
struct drm_wait_vblank_reply *reply)
|
||||||
{
|
{
|
||||||
|
@ -1407,7 +1438,8 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
|
||||||
struct drm_vblank_crtc *vblank;
|
struct drm_vblank_crtc *vblank;
|
||||||
union drm_wait_vblank *vblwait = data;
|
union drm_wait_vblank *vblwait = data;
|
||||||
int ret;
|
int ret;
|
||||||
unsigned int flags, seq, pipe, high_pipe;
|
u64 req_seq, seq;
|
||||||
|
unsigned int flags, pipe, high_pipe;
|
||||||
|
|
||||||
if (!dev->irq_enabled)
|
if (!dev->irq_enabled)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -1455,9 +1487,12 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
|
||||||
|
|
||||||
switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) {
|
switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) {
|
||||||
case _DRM_VBLANK_RELATIVE:
|
case _DRM_VBLANK_RELATIVE:
|
||||||
vblwait->request.sequence += seq;
|
req_seq = seq + vblwait->request.sequence;
|
||||||
|
vblwait->request.sequence = req_seq;
|
||||||
vblwait->request.type &= ~_DRM_VBLANK_RELATIVE;
|
vblwait->request.type &= ~_DRM_VBLANK_RELATIVE;
|
||||||
|
break;
|
||||||
case _DRM_VBLANK_ABSOLUTE:
|
case _DRM_VBLANK_ABSOLUTE:
|
||||||
|
req_seq = widen_32_to_64(vblwait->request.sequence, seq);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
|
@ -1465,22 +1500,25 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & _DRM_VBLANK_NEXTONMISS) &&
|
if ((flags & _DRM_VBLANK_NEXTONMISS) &&
|
||||||
vblank_passed(seq, vblwait->request.sequence))
|
vblank_passed(seq, req_seq)) {
|
||||||
vblwait->request.sequence = seq + 1;
|
req_seq = seq + 1;
|
||||||
|
vblwait->request.type &= ~_DRM_VBLANK_NEXTONMISS;
|
||||||
|
vblwait->request.sequence = req_seq;
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & _DRM_VBLANK_EVENT) {
|
if (flags & _DRM_VBLANK_EVENT) {
|
||||||
/* must hold on to the vblank ref until the event fires
|
/* must hold on to the vblank ref until the event fires
|
||||||
* drm_vblank_put will be called asynchronously
|
* drm_vblank_put will be called asynchronously
|
||||||
*/
|
*/
|
||||||
return drm_queue_vblank_event(dev, pipe, vblwait, file_priv);
|
return drm_queue_vblank_event(dev, pipe, req_seq, vblwait, file_priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vblwait->request.sequence != seq) {
|
if (req_seq != seq) {
|
||||||
DRM_DEBUG("waiting on vblank count %u, crtc %u\n",
|
DRM_DEBUG("waiting on vblank count %llu, crtc %u\n",
|
||||||
vblwait->request.sequence, pipe);
|
req_seq, pipe);
|
||||||
DRM_WAIT_ON(ret, vblank->queue, 3 * HZ,
|
DRM_WAIT_ON(ret, vblank->queue, 3 * HZ,
|
||||||
vblank_passed(drm_vblank_count(dev, pipe),
|
vblank_passed(drm_vblank_count(dev, pipe),
|
||||||
vblwait->request.sequence) ||
|
req_seq) ||
|
||||||
!READ_ONCE(vblank->enabled));
|
!READ_ONCE(vblank->enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1502,7 +1540,7 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
|
||||||
{
|
{
|
||||||
struct drm_pending_vblank_event *e, *t;
|
struct drm_pending_vblank_event *e, *t;
|
||||||
ktime_t now;
|
ktime_t now;
|
||||||
unsigned int seq;
|
u64 seq;
|
||||||
|
|
||||||
assert_spin_locked(&dev->event_lock);
|
assert_spin_locked(&dev->event_lock);
|
||||||
|
|
||||||
|
@ -1511,11 +1549,11 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
|
||||||
list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) {
|
list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) {
|
||||||
if (e->pipe != pipe)
|
if (e->pipe != pipe)
|
||||||
continue;
|
continue;
|
||||||
if (!vblank_passed(seq, e->event.sequence))
|
if (!vblank_passed(seq, e->sequence))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DRM_DEBUG("vblank event on %u, current %u\n",
|
DRM_DEBUG("vblank event on %llu, current %llu\n",
|
||||||
e->event.sequence, seq);
|
e->sequence, seq);
|
||||||
|
|
||||||
list_del(&e->base.link);
|
list_del(&e->base.link);
|
||||||
drm_vblank_put(dev, pipe);
|
drm_vblank_put(dev, pipe);
|
||||||
|
|
|
@ -47,6 +47,10 @@ struct drm_pending_vblank_event {
|
||||||
* @pipe: drm_crtc_index() of the &drm_crtc this event is for.
|
* @pipe: drm_crtc_index() of the &drm_crtc this event is for.
|
||||||
*/
|
*/
|
||||||
unsigned int pipe;
|
unsigned int pipe;
|
||||||
|
/**
|
||||||
|
* @sequence: frame event should be triggered at
|
||||||
|
*/
|
||||||
|
u64 sequence;
|
||||||
/**
|
/**
|
||||||
* @event: Actual event which will be sent to userspace.
|
* @event: Actual event which will be sent to userspace.
|
||||||
*/
|
*/
|
||||||
|
@ -88,7 +92,7 @@ struct drm_vblank_crtc {
|
||||||
/**
|
/**
|
||||||
* @count: Current software vblank counter.
|
* @count: Current software vblank counter.
|
||||||
*/
|
*/
|
||||||
u32 count;
|
u64 count;
|
||||||
/**
|
/**
|
||||||
* @time: Vblank timestamp corresponding to @count.
|
* @time: Vblank timestamp corresponding to @count.
|
||||||
*/
|
*/
|
||||||
|
@ -152,8 +156,8 @@ struct drm_vblank_crtc {
|
||||||
};
|
};
|
||||||
|
|
||||||
int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
|
int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
|
||||||
u32 drm_crtc_vblank_count(struct drm_crtc *crtc);
|
u64 drm_crtc_vblank_count(struct drm_crtc *crtc);
|
||||||
u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
|
u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
|
||||||
ktime_t *vblanktime);
|
ktime_t *vblanktime);
|
||||||
void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
|
void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
|
||||||
struct drm_pending_vblank_event *e);
|
struct drm_pending_vblank_event *e);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user