Skip to content

Commit 2c47c0d

Browse files
tom3qrkhuangtao
authored andcommitted
UPSTREAM: drm/rockchip: Replace custom wait_for_vblanks with helper
Currently the driver uses a custom function to wait for flip to complete after an atomic commit. It was needed before because of two problems: - there is no hardware vblank counter, so the original helper would have a race condition with the vblank interrupt, - the driver didn't support unreferencing cursor framebuffers asynchronously to the commit, which was what the helper expected. Since both problems have been solved by previous patches, we can now make the driver use the generic helper and remove custom waiting code. Signed-off-by: Tomasz Figa <tfiga@chromium.org> (cherry picked from commit 81c248f75a130c1ce46c67e8b05b37e8ffbbb33e) Change-Id: Ida5a38b71f9e7812f415eb8889d906d2fe3b093e Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
1 parent f097cd8 commit 2c47c0d

3 files changed

Lines changed: 3 additions & 78 deletions

File tree

drivers/gpu/drm/rockchip/rockchip_drm_drv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct rockchip_crtc_funcs {
4242
int (*loader_protect)(struct drm_crtc *crtc, bool on);
4343
int (*enable_vblank)(struct drm_crtc *crtc);
4444
void (*disable_vblank)(struct drm_crtc *crtc);
45-
void (*wait_for_update)(struct drm_crtc *crtc);
4645
void (*cancel_pending_vblank)(struct drm_crtc *crtc, struct drm_file *file_priv);
4746
int (*debugfs_dump)(struct drm_crtc *crtc, struct seq_file *s);
4847
void (*regs_dump)(struct drm_crtc *crtc, struct seq_file *s);

drivers/gpu/drm/rockchip/rockchip_drm_fb.c

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -208,68 +208,6 @@ static void rockchip_drm_output_poll_changed(struct drm_device *dev)
208208
drm_fb_helper_hotplug_event(fb_helper);
209209
}
210210

211-
static void rockchip_crtc_wait_for_update(struct drm_crtc *crtc)
212-
{
213-
struct rockchip_drm_private *priv = crtc->dev->dev_private;
214-
int pipe = drm_crtc_index(crtc);
215-
const struct rockchip_crtc_funcs *crtc_funcs = priv->crtc_funcs[pipe];
216-
217-
if (crtc_funcs && crtc_funcs->wait_for_update)
218-
crtc_funcs->wait_for_update(crtc);
219-
}
220-
221-
/*
222-
* We can't use drm_atomic_helper_wait_for_vblanks() because rk3288 and rk3066
223-
* have hardware counters for neither vblanks nor scanlines, which results in
224-
* a race where:
225-
* | <-- HW vsync irq and reg take effect
226-
* plane_commit --> |
227-
* get_vblank and wait --> |
228-
* | <-- handle_vblank, vblank->count + 1
229-
* cleanup_fb --> |
230-
* iommu crash --> |
231-
* | <-- HW vsync irq and reg take effect
232-
*
233-
* This function is equivalent but uses rockchip_crtc_wait_for_update() instead
234-
* of waiting for vblank_count to change.
235-
*/
236-
static void
237-
rockchip_atomic_wait_for_complete(struct drm_device *dev, struct drm_atomic_state *old_state)
238-
{
239-
struct drm_crtc_state *old_crtc_state;
240-
struct drm_crtc *crtc;
241-
int i, ret;
242-
243-
for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
244-
/* No one cares about the old state, so abuse it for tracking
245-
* and store whether we hold a vblank reference (and should do a
246-
* vblank wait) in the ->enable boolean.
247-
*/
248-
old_crtc_state->enable = false;
249-
250-
if (!crtc->state->active)
251-
continue;
252-
253-
if (!drm_atomic_helper_framebuffer_changed(dev,
254-
old_state, crtc))
255-
continue;
256-
257-
ret = drm_crtc_vblank_get(crtc);
258-
if (ret != 0)
259-
continue;
260-
261-
old_crtc_state->enable = true;
262-
}
263-
264-
for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
265-
if (!old_crtc_state->enable)
266-
continue;
267-
268-
rockchip_crtc_wait_for_update(crtc);
269-
drm_crtc_vblank_put(crtc);
270-
}
271-
}
272-
273211
static void
274212
rockchip_atomic_commit_complete(struct rockchip_atomic_commit *commit)
275213
{
@@ -301,7 +239,7 @@ rockchip_atomic_commit_complete(struct rockchip_atomic_commit *commit)
301239

302240
drm_atomic_helper_commit_planes(dev, state, true);
303241

304-
rockchip_atomic_wait_for_complete(dev, state);
242+
drm_atomic_helper_wait_for_vblanks(dev, state);
305243

306244
drm_atomic_helper_cleanup_planes(dev, state);
307245

drivers/gpu/drm/rockchip/rockchip_drm_vop.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ struct vop {
184184
bool vsync_work_pending;
185185
bool loader_protect;
186186
struct completion dsp_hold_completion;
187-
struct completion wait_update_complete;
187+
188+
/* protected by dev->event_lock */
188189
struct drm_pending_vblank_event *event;
189190

190191
struct drm_flip_work fb_unref_work;
@@ -1440,15 +1441,6 @@ static void vop_crtc_disable_vblank(struct drm_crtc *crtc)
14401441
spin_unlock_irqrestore(&vop->irq_lock, flags);
14411442
}
14421443

1443-
static void vop_crtc_wait_for_update(struct drm_crtc *crtc)
1444-
{
1445-
struct vop *vop = to_vop(crtc);
1446-
1447-
reinit_completion(&vop->wait_update_complete);
1448-
WARN_ON(!wait_for_completion_timeout(&vop->wait_update_complete,
1449-
msecs_to_jiffies(1000)));
1450-
}
1451-
14521444
static void vop_crtc_cancel_pending_vblank(struct drm_crtc *crtc,
14531445
struct drm_file *file_priv)
14541446
{
@@ -1625,7 +1617,6 @@ static const struct rockchip_crtc_funcs private_crtc_funcs = {
16251617
.loader_protect = vop_crtc_loader_protect,
16261618
.enable_vblank = vop_crtc_enable_vblank,
16271619
.disable_vblank = vop_crtc_disable_vblank,
1628-
.wait_for_update = vop_crtc_wait_for_update,
16291620
.cancel_pending_vblank = vop_crtc_cancel_pending_vblank,
16301621
.debugfs_dump = vop_crtc_debugfs_dump,
16311622
.regs_dump = vop_crtc_regs_dump,
@@ -2388,8 +2379,6 @@ static void vop_handle_vblank(struct vop *vop)
23882379

23892380
spin_unlock_irqrestore(&drm->event_lock, flags);
23902381
}
2391-
if (!completion_done(&vop->wait_update_complete))
2392-
complete(&vop->wait_update_complete);
23932382

23942383
if (test_and_clear_bit(VOP_PENDING_FB_UNREF, &vop->pending))
23952384
drm_flip_work_commit(&vop->fb_unref_work, system_unbound_wq);
@@ -2579,7 +2568,6 @@ static int vop_create_crtc(struct vop *vop)
25792568
vop_fb_unref_worker);
25802569

25812570
init_completion(&vop->dsp_hold_completion);
2582-
init_completion(&vop->wait_update_complete);
25832571
init_completion(&vop->line_flag_completion);
25842572
crtc->port = port;
25852573
rockchip_register_crtc_funcs(crtc, &private_crtc_funcs);

0 commit comments

Comments
 (0)