Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vblank: Switch to bool in_vblank_irq in get_vblank_timestamp

It's overkill to have a flag parameter which is essentially used just
as a boolean. This takes care of core + adjusting drivers.

Adjusting the scanout position callback is a bit harder, since radeon
also supplies it's own driver-private flags in there.

v2: Fixup misplaced hunks (Neil).

v3: kbuild says v1 was better ...

Cc: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
Cc: Eric Anholt <eric@anholt.net>
Cc: Rob Clark <robdclark@gmail.com>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170509140329.24114-2-daniel.vetter@ffwll.ch

+50 -45
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 1913 1913 bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, 1914 1914 int *max_error, 1915 1915 struct timeval *vblank_time, 1916 - unsigned flags); 1916 + bool in_vblank_irq); 1917 1917 long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd, 1918 1918 unsigned long arg); 1919 1919
+3 -3
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
··· 941 941 * @crtc: crtc to get the timestamp for 942 942 * @max_error: max error 943 943 * @vblank_time: time value 944 - * @flags: flags passed to the driver 944 + * @in_vblank_irq: called from drm_handle_vblank() 945 945 * 946 946 * Gets the timestamp on the requested crtc based on the 947 947 * scanout position. (all asics). ··· 950 950 bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, 951 951 int *max_error, 952 952 struct timeval *vblank_time, 953 - unsigned flags) 953 + bool in_vblank_irq) 954 954 { 955 955 struct drm_crtc *crtc; 956 956 struct amdgpu_device *adev = dev->dev_private; ··· 971 971 972 972 /* Helper routine in DRM core does all the work: */ 973 973 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 974 - vblank_time, flags, 974 + vblank_time, in_vblank_irq, 975 975 &crtc->hwmode); 976 976 } 977 977
+22 -19
drivers/gpu/drm/drm_irq.c
··· 54 54 55 55 static bool 56 56 drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe, 57 - struct timeval *tvblank, unsigned flags); 57 + struct timeval *tvblank, bool in_vblank_irq); 58 58 59 59 static unsigned int drm_timestamp_precision = 20; /* Default to 20 usecs. */ 60 60 ··· 138 138 */ 139 139 do { 140 140 cur_vblank = __get_vblank_counter(dev, pipe); 141 - rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, 0); 141 + rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, false); 142 142 } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); 143 143 144 144 /* ··· 171 171 * device vblank fields. 172 172 */ 173 173 static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe, 174 - unsigned long flags) 174 + bool in_vblank_irq) 175 175 { 176 176 struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 177 177 u32 cur_vblank, diff; ··· 194 194 */ 195 195 do { 196 196 cur_vblank = __get_vblank_counter(dev, pipe); 197 - rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, flags); 197 + rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, in_vblank_irq); 198 198 } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); 199 199 200 200 if (dev->max_vblank_count != 0) { ··· 214 214 */ 215 215 diff = DIV_ROUND_CLOSEST_ULL(diff_ns, framedur_ns); 216 216 217 - if (diff == 0 && flags & DRM_CALLED_FROM_VBLIRQ) 217 + if (diff == 0 && in_vblank_irq) 218 218 DRM_DEBUG_VBL("crtc %u: Redundant vblirq ignored." 219 219 " diff_ns = %lld, framedur_ns = %d)\n", 220 220 pipe, (long long) diff_ns, framedur_ns); 221 221 } else { 222 222 /* some kind of default for drivers w/o accurate vbl timestamping */ 223 - diff = (flags & DRM_CALLED_FROM_VBLIRQ) != 0; 223 + diff = in_vblank_irq ? 1 : 0; 224 224 } 225 225 226 226 /* ··· 253 253 * Otherwise reinitialize delayed at next vblank interrupt and assign 0 254 254 * for now, to mark the vblanktimestamp as invalid. 255 255 */ 256 - if (!rc && (flags & DRM_CALLED_FROM_VBLIRQ) == 0) 256 + if (!rc && in_vblank_irq) 257 257 t_vblank = (struct timeval) {0, 0}; 258 258 259 259 store_vblank(dev, pipe, diff, &t_vblank, cur_vblank); ··· 291 291 292 292 spin_lock_irqsave(&dev->vblank_time_lock, flags); 293 293 294 - drm_update_vblank_count(dev, pipe, 0); 294 + drm_update_vblank_count(dev, pipe, false); 295 295 vblank = drm_vblank_count(dev, pipe); 296 296 297 297 spin_unlock_irqrestore(&dev->vblank_time_lock, flags); ··· 349 349 * this time. This makes the count account for the entire time 350 350 * between drm_crtc_vblank_on() and drm_crtc_vblank_off(). 351 351 */ 352 - drm_update_vblank_count(dev, pipe, 0); 352 + drm_update_vblank_count(dev, pipe, false); 353 353 354 354 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags); 355 355 } ··· 700 700 * @max_error: Desired maximum allowable error in timestamps (nanosecs) 701 701 * On return contains true maximum error of timestamp 702 702 * @vblank_time: Pointer to struct timeval which should receive the timestamp 703 - * @flags: Flags to pass to driver: 704 - * 0 = Default, 705 - * DRM_CALLED_FROM_VBLIRQ = If function is called from vbl IRQ handler 703 + * @in_vblank_irq: 704 + * True when called from drm_crtc_handle_vblank(). Some drivers 705 + * need to apply some workarounds for gpu-specific vblank irq quirks 706 + * if flag is set. 706 707 * @mode: mode which defines the scanout timings 707 708 * 708 709 * Implements calculation of exact vblank timestamps from given drm_display_mode ··· 733 732 unsigned int pipe, 734 733 int *max_error, 735 734 struct timeval *vblank_time, 736 - unsigned flags, 735 + bool in_vblank_irq, 737 736 const struct drm_display_mode *mode) 738 737 { 739 738 struct timeval tv_etime; ··· 741 740 unsigned int vbl_status; 742 741 int vpos, hpos, i; 743 742 int delta_ns, duration_ns; 743 + unsigned flags = in_vblank_irq ? DRM_CALLED_FROM_VBLIRQ : 0; 744 744 745 745 if (pipe >= dev->num_crtcs) { 746 746 DRM_ERROR("Invalid crtc %u\n", pipe); ··· 845 843 * @dev: DRM device 846 844 * @pipe: index of CRTC whose vblank timestamp to retrieve 847 845 * @tvblank: Pointer to target struct timeval which should receive the timestamp 848 - * @flags: Flags to pass to driver: 849 - * 0 = Default, 850 - * DRM_CALLED_FROM_VBLIRQ = If function is called from vbl IRQ handler 846 + * @in_vblank_irq: 847 + * True when called from drm_crtc_handle_vblank(). Some drivers 848 + * need to apply some workarounds for gpu-specific vblank irq quirks 849 + * if flag is set. 851 850 * 852 851 * Fetches the system timestamp corresponding to the time of the most recent 853 852 * vblank interval on specified CRTC. May call into kms-driver to ··· 862 859 */ 863 860 static bool 864 861 drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe, 865 - struct timeval *tvblank, unsigned flags) 862 + struct timeval *tvblank, bool in_vblank_irq) 866 863 { 867 864 bool ret = false; 868 865 ··· 872 869 /* Query driver if possible and precision timestamping enabled. */ 873 870 if (dev->driver->get_vblank_timestamp && (max_error > 0)) 874 871 ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error, 875 - tvblank, flags); 872 + tvblank, in_vblank_irq); 876 873 877 874 /* GPU high precision timestamp query unsupported or failed. 878 875 * Return current monotonic/gettimeofday timestamp as best estimate. ··· 1750 1747 return false; 1751 1748 } 1752 1749 1753 - drm_update_vblank_count(dev, pipe, DRM_CALLED_FROM_VBLIRQ); 1750 + drm_update_vblank_count(dev, pipe, true); 1754 1751 1755 1752 spin_unlock(&dev->vblank_time_lock); 1756 1753
+2 -2
drivers/gpu/drm/i915/i915_irq.c
··· 967 967 static bool i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, 968 968 int *max_error, 969 969 struct timeval *vblank_time, 970 - unsigned flags) 970 + bool in_vblank_irq) 971 971 { 972 972 struct drm_i915_private *dev_priv = to_i915(dev); 973 973 struct intel_crtc *crtc; ··· 991 991 992 992 /* Helper routine in DRM core does all the work: */ 993 993 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 994 - vblank_time, flags, 994 + vblank_time, in_vblank_irq, 995 995 &crtc->base.hwmode); 996 996 } 997 997
+2 -2
drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c
··· 595 595 static bool mdp5_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, 596 596 int *max_error, 597 597 struct timeval *vblank_time, 598 - unsigned flags) 598 + bool in_vblank_irq) 599 599 { 600 600 struct msm_drm_private *priv = dev->dev_private; 601 601 struct drm_crtc *crtc; ··· 612 612 } 613 613 614 614 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, 615 - vblank_time, flags, 615 + vblank_time, in_vblank_irq, 616 616 &crtc->mode); 617 617 } 618 618
+3 -2
drivers/gpu/drm/nouveau/nouveau_display.c
··· 158 158 159 159 bool 160 160 nouveau_display_vblstamp(struct drm_device *dev, unsigned int pipe, 161 - int *max_error, struct timeval *time, unsigned flags) 161 + int *max_error, struct timeval *time, bool in_vblank_irq) 162 162 { 163 163 struct drm_crtc *crtc; 164 164 ··· 170 170 else 171 171 mode = &crtc->hwmode; 172 172 return drm_calc_vbltimestamp_from_scanoutpos(dev, 173 - pipe, max_error, time, flags, mode); 173 + pipe, max_error, time, in_vblank_irq, 174 + mode); 174 175 } 175 176 } 176 177
+1 -1
drivers/gpu/drm/nouveau/nouveau_display.h
··· 72 72 unsigned int, int *, int *, ktime_t *, 73 73 ktime_t *, const struct drm_display_mode *); 74 74 bool nouveau_display_vblstamp(struct drm_device *, unsigned int, int *, 75 - struct timeval *, unsigned); 75 + struct timeval *, bool); 76 76 77 77 int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, 78 78 struct drm_pending_vblank_event *event,
+1 -1
drivers/gpu/drm/radeon/radeon_drv.c
··· 118 118 bool radeon_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, 119 119 int *max_error, 120 120 struct timeval *vblank_time, 121 - unsigned flags); 121 + bool in_vblank_irq); 122 122 void radeon_driver_irq_preinstall_kms(struct drm_device *dev); 123 123 int radeon_driver_irq_postinstall_kms(struct drm_device *dev); 124 124 void radeon_driver_irq_uninstall_kms(struct drm_device *dev);
+2 -2
drivers/gpu/drm/radeon/radeon_kms.c
··· 874 874 bool radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc, 875 875 int *max_error, 876 876 struct timeval *vblank_time, 877 - unsigned flags) 877 + bool in_vblank_irq) 878 878 { 879 879 struct drm_crtc *drmcrtc; 880 880 struct radeon_device *rdev = dev->dev_private; ··· 891 891 892 892 /* Helper routine in DRM core does all the work: */ 893 893 return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error, 894 - vblank_time, flags, 894 + vblank_time, in_vblank_irq, 895 895 &drmcrtc->hwmode); 896 896 } 897 897
+2 -2
drivers/gpu/drm/vc4/vc4_crtc.c
··· 272 272 273 273 bool vc4_crtc_get_vblank_timestamp(struct drm_device *dev, unsigned int crtc_id, 274 274 int *max_error, struct timeval *vblank_time, 275 - unsigned flags) 275 + bool in_vblank_irq) 276 276 { 277 277 struct drm_crtc *crtc = drm_crtc_from_index(dev, crtc_id); 278 278 struct drm_crtc_state *state = crtc->state; 279 279 280 280 /* Helper routine in DRM core does all the work: */ 281 281 return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc_id, max_error, 282 - vblank_time, flags, 282 + vblank_time, in_vblank_irq, 283 283 &state->adjusted_mode); 284 284 } 285 285
+1 -1
drivers/gpu/drm/vc4/vc4_drv.h
··· 495 495 const struct drm_display_mode *mode); 496 496 bool vc4_crtc_get_vblank_timestamp(struct drm_device *dev, unsigned int crtc_id, 497 497 int *max_error, struct timeval *vblank_time, 498 - unsigned flags); 498 + bool in_vblank_irq); 499 499 500 500 /* vc4_debugfs.c */ 501 501 int vc4_debugfs_init(struct drm_minor *minor);
+9 -8
include/drm/drm_drv.h
··· 241 241 * DRM device. 242 242 * pipe: 243 243 * Id of the crtc to query. 244 - * flags: 245 - * Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0). 244 + * in_vblank_irq: 245 + * True when called from drm_crtc_handle_vblank(). Some drivers 246 + * need to apply some workarounds for gpu-specific vblank irq quirks 247 + * if flag is set. 246 248 * vpos: 247 249 * Target location for current vertical scanout position. 248 250 * hpos: ··· 310 308 * Returns true upper bound on error for timestamp. 311 309 * vblank_time: 312 310 * Target location for returned vblank timestamp. 313 - * flags: 314 - * 0 = Defaults, no special treatment needed. 315 - * DRM_CALLED_FROM_VBLIRQ = Function is called from vblank 316 - * irq handler. Some drivers need to apply some workarounds 317 - * for gpu-specific vblank irq quirks if flag is set. 311 + * in_vblank_irq: 312 + * True when called from drm_crtc_handle_vblank(). Some drivers 313 + * need to apply some workarounds for gpu-specific vblank irq quirks 314 + * if flag is set. 318 315 * 319 316 * Returns: 320 317 * ··· 323 322 bool (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe, 324 323 int *max_error, 325 324 struct timeval *vblank_time, 326 - unsigned flags); 325 + bool in_vblank_irq); 327 326 328 327 /* these have to be filled in */ 329 328
+1 -1
include/drm/drm_irq.h
··· 156 156 bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, 157 157 unsigned int pipe, int *max_error, 158 158 struct timeval *vblank_time, 159 - unsigned flags, 159 + bool in_vblank_irq, 160 160 const struct drm_display_mode *mode); 161 161 void drm_calc_timestamping_constants(struct drm_crtc *crtc, 162 162 const struct drm_display_mode *mode);