Skip to content

Commit bbc8764

Browse files
danvetairlied
authored andcommitted
drm/nouveau: Fix pre-nv50 pageflip events (v4)
Apparently pre-nv50 pageflip events happen before the actual vblank period. Therefore that functionality got semi-disabled in commit af4870e Author: Mario Kleiner <mario.kleiner.de@gmail.com> Date: Tue May 13 00:42:08 2014 +0200 drm/nouveau/kms/nv04-nv40: fix pageflip events via special case. Unfortunately that hack got uprooted in commit cc1ef11 Author: Thierry Reding <treding@nvidia.com> Date: Wed Aug 12 17:00:31 2015 +0200 drm/irq: Make pipe unsigned and name consistent Triggering a warning when trying to sample the vblank timestamp for a non-existing pipe. There's a few ways to fix this: - Open-code the old behaviour, which just enshrines this slight breakage of the userspace ABI. - Revert Mario's commit and again inflict broken timestamps, again not pretty. - Fix this for real by delaying the pageflip TS until the next vblank interrupt, thereby making it accurate. This patch implements the third option. Since having a page flip interrupt that happens when the pageflip gets armed and not when it completes in the next vblank seems to be fairly common (older i915 hw works very similarly) create a new helper to arm vblank events for such drivers. v2 (Mario Kleiner): - Fix function prototypes in drmP.h - Add missing vblank_put() for pageflip completion without pageflip event. - Initialize sequence number for queued pageflip event to avoid trouble in drm_handle_vblank_events(). - Remove dead code and spelling fix. v3 (Mario Kleiner): - Add a signed-off-by and cc stable tag per Ilja's advice. v4 (Thierry Reding): - Fix kerneldoc typo, discovered by Michel Dänzer - Rearrange tags and changelog Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=106431 Cc: Thierry Reding <treding@nvidia.com> Cc: Mario Kleiner <mario.kleiner.de@gmail.com> Acked-by: Ben Skeggs <bskeggs@redhat.com> Cc: Ilia Mirkin <imirkin@alum.mit.edu> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com> Cc: stable@vger.kernel.org # v4.3 Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com> Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent a0af2e5 commit bbc8764

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

drivers/gpu/drm/drm_irq.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,8 @@ static void send_vblank_event(struct drm_device *dev,
980980
struct drm_pending_vblank_event *e,
981981
unsigned long seq, struct timeval *now)
982982
{
983-
WARN_ON_SMP(!spin_is_locked(&dev->event_lock));
983+
assert_spin_locked(&dev->event_lock);
984+
984985
e->event.sequence = seq;
985986
e->event.tv_sec = now->tv_sec;
986987
e->event.tv_usec = now->tv_usec;
@@ -992,6 +993,57 @@ static void send_vblank_event(struct drm_device *dev,
992993
e->event.sequence);
993994
}
994995

996+
/**
997+
* drm_arm_vblank_event - arm vblank event after pageflip
998+
* @dev: DRM device
999+
* @pipe: CRTC index
1000+
* @e: the event to prepare to send
1001+
*
1002+
* A lot of drivers need to generate vblank events for the very next vblank
1003+
* interrupt. For example when the page flip interrupt happens when the page
1004+
* flip gets armed, but not when it actually executes within the next vblank
1005+
* period. This helper function implements exactly the required vblank arming
1006+
* behaviour.
1007+
*
1008+
* Caller must hold event lock. Caller must also hold a vblank reference for
1009+
* the event @e, which will be dropped when the next vblank arrives.
1010+
*
1011+
* This is the legacy version of drm_crtc_arm_vblank_event().
1012+
*/
1013+
void drm_arm_vblank_event(struct drm_device *dev, unsigned int pipe,
1014+
struct drm_pending_vblank_event *e)
1015+
{
1016+
assert_spin_locked(&dev->event_lock);
1017+
1018+
e->pipe = pipe;
1019+
e->event.sequence = drm_vblank_count(dev, pipe);
1020+
list_add_tail(&e->base.link, &dev->vblank_event_list);
1021+
}
1022+
EXPORT_SYMBOL(drm_arm_vblank_event);
1023+
1024+
/**
1025+
* drm_crtc_arm_vblank_event - arm vblank event after pageflip
1026+
* @crtc: the source CRTC of the vblank event
1027+
* @e: the event to send
1028+
*
1029+
* A lot of drivers need to generate vblank events for the very next vblank
1030+
* interrupt. For example when the page flip interrupt happens when the page
1031+
* flip gets armed, but not when it actually executes within the next vblank
1032+
* period. This helper function implements exactly the required vblank arming
1033+
* behaviour.
1034+
*
1035+
* Caller must hold event lock. Caller must also hold a vblank reference for
1036+
* the event @e, which will be dropped when the next vblank arrives.
1037+
*
1038+
* This is the native KMS version of drm_arm_vblank_event().
1039+
*/
1040+
void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
1041+
struct drm_pending_vblank_event *e)
1042+
{
1043+
drm_arm_vblank_event(crtc->dev, drm_crtc_index(crtc), e);
1044+
}
1045+
EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
1046+
9951047
/**
9961048
* drm_send_vblank_event - helper to send vblank event after pageflip
9971049
* @dev: DRM device

drivers/gpu/drm/nouveau/nouveau_display.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,6 @@ nouveau_finish_page_flip(struct nouveau_channel *chan,
829829
struct drm_device *dev = drm->dev;
830830
struct nouveau_page_flip_state *s;
831831
unsigned long flags;
832-
int crtcid = -1;
833832

834833
spin_lock_irqsave(&dev->event_lock, flags);
835834

@@ -841,15 +840,19 @@ nouveau_finish_page_flip(struct nouveau_channel *chan,
841840

842841
s = list_first_entry(&fctx->flip, struct nouveau_page_flip_state, head);
843842
if (s->event) {
844-
/* Vblank timestamps/counts are only correct on >= NV-50 */
845-
if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA)
846-
crtcid = s->crtc;
843+
if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
844+
drm_arm_vblank_event(dev, s->crtc, s->event);
845+
} else {
846+
drm_send_vblank_event(dev, s->crtc, s->event);
847847

848-
drm_send_vblank_event(dev, crtcid, s->event);
848+
/* Give up ownership of vblank for page-flipped crtc */
849+
drm_vblank_put(dev, s->crtc);
850+
}
851+
}
852+
else {
853+
/* Give up ownership of vblank for page-flipped crtc */
854+
drm_vblank_put(dev, s->crtc);
849855
}
850-
851-
/* Give up ownership of vblank for page-flipped crtc */
852-
drm_vblank_put(dev, s->crtc);
853856

854857
list_del(&s->head);
855858
if (ps)

include/drm/drmP.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,10 @@ extern void drm_send_vblank_event(struct drm_device *dev, unsigned int pipe,
953953
struct drm_pending_vblank_event *e);
954954
extern void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
955955
struct drm_pending_vblank_event *e);
956+
extern void drm_arm_vblank_event(struct drm_device *dev, unsigned int pipe,
957+
struct drm_pending_vblank_event *e);
958+
extern void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
959+
struct drm_pending_vblank_event *e);
956960
extern bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
957961
extern bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
958962
extern int drm_vblank_get(struct drm_device *dev, unsigned int pipe);

0 commit comments

Comments
 (0)