diff options
Diffstat (limited to 'drivers/gpu/drm/drm_vblank.c')
-rw-r--r-- | drivers/gpu/drm/drm_vblank.c | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 98e091175921..cde71ee95a8f 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c | |||
@@ -105,13 +105,20 @@ static void store_vblank(struct drm_device *dev, unsigned int pipe, | |||
105 | write_sequnlock(&vblank->seqlock); | 105 | write_sequnlock(&vblank->seqlock); |
106 | } | 106 | } |
107 | 107 | ||
108 | static u32 drm_max_vblank_count(struct drm_device *dev, unsigned int pipe) | ||
109 | { | ||
110 | struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; | ||
111 | |||
112 | return vblank->max_vblank_count ?: dev->max_vblank_count; | ||
113 | } | ||
114 | |||
108 | /* | 115 | /* |
109 | * "No hw counter" fallback implementation of .get_vblank_counter() hook, | 116 | * "No hw counter" fallback implementation of .get_vblank_counter() hook, |
110 | * if there is no useable hardware frame counter available. | 117 | * if there is no useable hardware frame counter available. |
111 | */ | 118 | */ |
112 | static u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe) | 119 | static u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe) |
113 | { | 120 | { |
114 | WARN_ON_ONCE(dev->max_vblank_count != 0); | 121 | WARN_ON_ONCE(drm_max_vblank_count(dev, pipe) != 0); |
115 | return 0; | 122 | return 0; |
116 | } | 123 | } |
117 | 124 | ||
@@ -198,6 +205,7 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe, | |||
198 | ktime_t t_vblank; | 205 | ktime_t t_vblank; |
199 | int count = DRM_TIMESTAMP_MAXRETRIES; | 206 | int count = DRM_TIMESTAMP_MAXRETRIES; |
200 | int framedur_ns = vblank->framedur_ns; | 207 | int framedur_ns = vblank->framedur_ns; |
208 | u32 max_vblank_count = drm_max_vblank_count(dev, pipe); | ||
201 | 209 | ||
202 | /* | 210 | /* |
203 | * Interrupts were disabled prior to this call, so deal with counter | 211 | * Interrupts were disabled prior to this call, so deal with counter |
@@ -216,9 +224,9 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe, | |||
216 | rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, in_vblank_irq); | 224 | rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, in_vblank_irq); |
217 | } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); | 225 | } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); |
218 | 226 | ||
219 | if (dev->max_vblank_count != 0) { | 227 | if (max_vblank_count) { |
220 | /* trust the hw counter when it's around */ | 228 | /* trust the hw counter when it's around */ |
221 | diff = (cur_vblank - vblank->last) & dev->max_vblank_count; | 229 | diff = (cur_vblank - vblank->last) & max_vblank_count; |
222 | } else if (rc && framedur_ns) { | 230 | } else if (rc && framedur_ns) { |
223 | u64 diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time)); | 231 | u64 diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time)); |
224 | 232 | ||
@@ -1205,6 +1213,37 @@ void drm_crtc_vblank_reset(struct drm_crtc *crtc) | |||
1205 | EXPORT_SYMBOL(drm_crtc_vblank_reset); | 1213 | EXPORT_SYMBOL(drm_crtc_vblank_reset); |
1206 | 1214 | ||
1207 | /** | 1215 | /** |
1216 | * drm_crtc_set_max_vblank_count - configure the hw max vblank counter value | ||
1217 | * @crtc: CRTC in question | ||
1218 | * @max_vblank_count: max hardware vblank counter value | ||
1219 | * | ||
1220 | * Update the maximum hardware vblank counter value for @crtc | ||
1221 | * at runtime. Useful for hardware where the operation of the | ||
1222 | * hardware vblank counter depends on the currently active | ||
1223 | * display configuration. | ||
1224 | * | ||
1225 | * For example, if the hardware vblank counter does not work | ||
1226 | * when a specific connector is active the maximum can be set | ||
1227 | * to zero. And when that specific connector isn't active the | ||
1228 | * maximum can again be set to the appropriate non-zero value. | ||
1229 | * | ||
1230 | * If used, must be called before drm_vblank_on(). | ||
1231 | */ | ||
1232 | void drm_crtc_set_max_vblank_count(struct drm_crtc *crtc, | ||
1233 | u32 max_vblank_count) | ||
1234 | { | ||
1235 | struct drm_device *dev = crtc->dev; | ||
1236 | unsigned int pipe = drm_crtc_index(crtc); | ||
1237 | struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; | ||
1238 | |||
1239 | WARN_ON(dev->max_vblank_count); | ||
1240 | WARN_ON(!READ_ONCE(vblank->inmodeset)); | ||
1241 | |||
1242 | vblank->max_vblank_count = max_vblank_count; | ||
1243 | } | ||
1244 | EXPORT_SYMBOL(drm_crtc_set_max_vblank_count); | ||
1245 | |||
1246 | /** | ||
1208 | * drm_crtc_vblank_on - enable vblank events on a CRTC | 1247 | * drm_crtc_vblank_on - enable vblank events on a CRTC |
1209 | * @crtc: CRTC in question | 1248 | * @crtc: CRTC in question |
1210 | * | 1249 | * |