Skip to content

Commit d12e364

Browse files
committed
drm/vblank: Introduce drm_crtc_vblank_crtc()
Make life easier by providing a function that hands out the correct drm_vblank_crtc for a given a drm_crtc. Also abstract the lower level internals of the vblank code in a similar fashion. Signed-off-by: Ville Syrjälä <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Dmitry Baryshkov <[email protected]>
1 parent f7ad2ce commit d12e364

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

drivers/gpu/drm/drm_vblank.c

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,24 @@ module_param_named(timestamp_precision_usec, drm_timestamp_precision, int, 0600)
166166
MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable [msecs] (0: never disable, <0: disable immediately)");
167167
MODULE_PARM_DESC(timestamp_precision_usec, "Max. error on timestamps [usecs]");
168168

169+
static struct drm_vblank_crtc *
170+
drm_vblank_crtc(struct drm_device *dev, unsigned int pipe)
171+
{
172+
return &dev->vblank[pipe];
173+
}
174+
175+
struct drm_vblank_crtc *
176+
drm_crtc_vblank_crtc(struct drm_crtc *crtc)
177+
{
178+
return drm_vblank_crtc(crtc->dev, drm_crtc_index(crtc));
179+
}
180+
EXPORT_SYMBOL(drm_crtc_vblank_crtc);
181+
169182
static void store_vblank(struct drm_device *dev, unsigned int pipe,
170183
u32 vblank_count_inc,
171184
ktime_t t_vblank, u32 last)
172185
{
173-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
186+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
174187

175188
assert_spin_locked(&dev->vblank_time_lock);
176189

@@ -184,7 +197,7 @@ static void store_vblank(struct drm_device *dev, unsigned int pipe,
184197

185198
static u32 drm_max_vblank_count(struct drm_device *dev, unsigned int pipe)
186199
{
187-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
200+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
188201

189202
return vblank->max_vblank_count ?: dev->max_vblank_count;
190203
}
@@ -273,7 +286,7 @@ static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe
273286
static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe,
274287
bool in_vblank_irq)
275288
{
276-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
289+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
277290
u32 cur_vblank, diff;
278291
bool rc;
279292
ktime_t t_vblank;
@@ -364,7 +377,7 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe,
364377

365378
u64 drm_vblank_count(struct drm_device *dev, unsigned int pipe)
366379
{
367-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
380+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
368381
u64 count;
369382

370383
if (drm_WARN_ON(dev, pipe >= dev->num_crtcs))
@@ -438,7 +451,7 @@ static void __disable_vblank(struct drm_device *dev, unsigned int pipe)
438451
*/
439452
void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
440453
{
441-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
454+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
442455
unsigned long irqflags;
443456

444457
assert_spin_locked(&dev->vbl_lock);
@@ -600,7 +613,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
600613
{
601614
struct drm_device *dev = crtc->dev;
602615
unsigned int pipe = drm_crtc_index(crtc);
603-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
616+
struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
604617
int linedur_ns = 0, framedur_ns = 0;
605618
int dotclock = mode->crtc_clock;
606619

@@ -930,7 +943,7 @@ EXPORT_SYMBOL(drm_crtc_vblank_count);
930943
static u64 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
931944
ktime_t *vblanktime)
932945
{
933-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
946+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
934947
u64 vblank_count;
935948
unsigned int seq;
936949

@@ -985,15 +998,14 @@ EXPORT_SYMBOL(drm_crtc_vblank_count_and_time);
985998
*/
986999
int drm_crtc_next_vblank_start(struct drm_crtc *crtc, ktime_t *vblanktime)
9871000
{
988-
unsigned int pipe = drm_crtc_index(crtc);
9891001
struct drm_vblank_crtc *vblank;
9901002
struct drm_display_mode *mode;
9911003
u64 vblank_start;
9921004

9931005
if (!drm_dev_has_vblank(crtc->dev))
9941006
return -EINVAL;
9951007

996-
vblank = &crtc->dev->vblank[pipe];
1008+
vblank = drm_crtc_vblank_crtc(crtc);
9971009
mode = &vblank->hwmode;
9981010

9991011
if (!vblank->framedur_ns || !vblank->linedur_ns)
@@ -1147,7 +1159,7 @@ static int __enable_vblank(struct drm_device *dev, unsigned int pipe)
11471159

11481160
static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
11491161
{
1150-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1162+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
11511163
int ret = 0;
11521164

11531165
assert_spin_locked(&dev->vbl_lock);
@@ -1185,7 +1197,7 @@ static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
11851197

11861198
int drm_vblank_get(struct drm_device *dev, unsigned int pipe)
11871199
{
1188-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1200+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
11891201
unsigned long irqflags;
11901202
int ret = 0;
11911203

@@ -1228,7 +1240,7 @@ EXPORT_SYMBOL(drm_crtc_vblank_get);
12281240

12291241
void drm_vblank_put(struct drm_device *dev, unsigned int pipe)
12301242
{
1231-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1243+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
12321244

12331245
if (drm_WARN_ON(dev, pipe >= dev->num_crtcs))
12341246
return;
@@ -1274,7 +1286,7 @@ EXPORT_SYMBOL(drm_crtc_vblank_put);
12741286
*/
12751287
void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe)
12761288
{
1277-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1289+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
12781290
int ret;
12791291
u64 last;
12801292

@@ -1327,7 +1339,7 @@ void drm_crtc_vblank_off(struct drm_crtc *crtc)
13271339
{
13281340
struct drm_device *dev = crtc->dev;
13291341
unsigned int pipe = drm_crtc_index(crtc);
1330-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1342+
struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
13311343
struct drm_pending_vblank_event *e, *t;
13321344
ktime_t now;
13331345
u64 seq;
@@ -1405,8 +1417,7 @@ EXPORT_SYMBOL(drm_crtc_vblank_off);
14051417
void drm_crtc_vblank_reset(struct drm_crtc *crtc)
14061418
{
14071419
struct drm_device *dev = crtc->dev;
1408-
unsigned int pipe = drm_crtc_index(crtc);
1409-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1420+
struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
14101421

14111422
spin_lock_irq(&dev->vbl_lock);
14121423
/*
@@ -1445,8 +1456,7 @@ void drm_crtc_set_max_vblank_count(struct drm_crtc *crtc,
14451456
u32 max_vblank_count)
14461457
{
14471458
struct drm_device *dev = crtc->dev;
1448-
unsigned int pipe = drm_crtc_index(crtc);
1449-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1459+
struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
14501460

14511461
drm_WARN_ON(dev, dev->max_vblank_count);
14521462
drm_WARN_ON(dev, !READ_ONCE(vblank->inmodeset));
@@ -1469,7 +1479,7 @@ void drm_crtc_vblank_on(struct drm_crtc *crtc)
14691479
{
14701480
struct drm_device *dev = crtc->dev;
14711481
unsigned int pipe = drm_crtc_index(crtc);
1472-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1482+
struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
14731483

14741484
if (drm_WARN_ON(dev, pipe >= dev->num_crtcs))
14751485
return;
@@ -1512,7 +1522,7 @@ static void drm_vblank_restore(struct drm_device *dev, unsigned int pipe)
15121522
assert_spin_locked(&dev->vbl_lock);
15131523
assert_spin_locked(&dev->vblank_time_lock);
15141524

1515-
vblank = &dev->vblank[pipe];
1525+
vblank = drm_vblank_crtc(dev, pipe);
15161526
drm_WARN_ONCE(dev,
15171527
drm_debug_enabled(DRM_UT_VBL) && !vblank->framedur_ns,
15181528
"Cannot compute missed vblanks without frame duration\n");
@@ -1564,7 +1574,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe,
15641574
union drm_wait_vblank *vblwait,
15651575
struct drm_file *file_priv)
15661576
{
1567-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1577+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
15681578
struct drm_pending_vblank_event *e;
15691579
ktime_t now;
15701580
u64 seq;
@@ -1872,7 +1882,7 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
18721882
*/
18731883
bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe)
18741884
{
1875-
struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1885+
struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
18761886
unsigned long irqflags;
18771887
bool disable_irq;
18781888

@@ -1981,7 +1991,7 @@ int drm_crtc_get_sequence_ioctl(struct drm_device *dev, void *data,
19811991

19821992
pipe = drm_crtc_index(crtc);
19831993

1984-
vblank = &dev->vblank[pipe];
1994+
vblank = drm_crtc_vblank_crtc(crtc);
19851995
vblank_enabled = dev->vblank_disable_immediate && READ_ONCE(vblank->enabled);
19861996

19871997
if (!vblank_enabled) {
@@ -2046,7 +2056,7 @@ int drm_crtc_queue_sequence_ioctl(struct drm_device *dev, void *data,
20462056

20472057
pipe = drm_crtc_index(crtc);
20482058

2049-
vblank = &dev->vblank[pipe];
2059+
vblank = drm_crtc_vblank_crtc(crtc);
20502060

20512061
e = kzalloc(sizeof(*e), GFP_KERNEL);
20522062
if (e == NULL)

drivers/gpu/drm/drm_vblank_work.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void drm_vblank_work_init(struct drm_vblank_work *work, struct drm_crtc *crtc,
245245
{
246246
kthread_init_work(&work->base, func);
247247
INIT_LIST_HEAD(&work->node);
248-
work->vblank = &crtc->dev->vblank[drm_crtc_index(crtc)];
248+
work->vblank = drm_crtc_vblank_crtc(crtc);
249249
}
250250
EXPORT_SYMBOL(drm_vblank_work_init);
251251

include/drm/drm_vblank.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ struct drm_vblank_crtc {
225225
wait_queue_head_t work_wait_queue;
226226
};
227227

228+
struct drm_vblank_crtc *drm_crtc_vblank_crtc(struct drm_crtc *crtc);
228229
int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
229230
bool drm_dev_has_vblank(const struct drm_device *dev);
230231
u64 drm_crtc_vblank_count(struct drm_crtc *crtc);

0 commit comments

Comments
 (0)