[Freedreno] [PATCH 2/2] drm/msm: Add MSM_WAIT_IOVA ioctl

2020-01-10 Thread Brian Ho
Implements an ioctl to wait until a value at a given iova is greater
than or equal to a supplied value.

This will initially be used by turnip (open-source Vulkan driver for
QC in mesa) for occlusion queries where the userspace driver can
block on a query becoming available before continuing via
vkGetQueryPoolResults.

Signed-off-by: Brian Ho 
---
 drivers/gpu/drm/msm/msm_drv.c | 60 +--
 include/uapi/drm/msm_drm.h| 12 +++
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index c84f0a8b3f2c..57b3f12182fe 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -36,10 +36,11 @@
  *   MSM_GEM_INFO ioctl.
  * - 1.4.0 - softpin, MSM_RELOC_BO_DUMP, and GEM_INFO support to set/get
  *   GEM object's debug name
- * - 1.5.0 - Add SUBMITQUERY_QUERY ioctl
+ * - 1.5.0 - Add SUBMITQUEUE_QUERY ioctl
+ * - 1.6.0 - Add WAIT_IOVA ioctl
  */
 #define MSM_VERSION_MAJOR  1
-#define MSM_VERSION_MINOR  5
+#define MSM_VERSION_MINOR  6
 #define MSM_VERSION_PATCHLEVEL 0
 
 static const struct drm_mode_config_funcs mode_config_funcs = {
@@ -952,6 +953,60 @@ static int msm_ioctl_submitqueue_close(struct drm_device 
*dev, void *data,
return msm_submitqueue_remove(file->driver_priv, id);
 }
 
+static int msm_ioctl_wait_iova(struct drm_device *dev, void *data,
+   struct drm_file *file)
+{
+   struct msm_drm_private *priv = dev->dev_private;
+   struct drm_gem_object *obj;
+   struct drm_msm_wait_iova *args = data;
+   ktime_t timeout = to_ktime(args->timeout);
+   unsigned long remaining_jiffies = timeout_to_jiffies();
+   struct msm_gpu *gpu = priv->gpu;
+   void *base_vaddr;
+   uint64_t *vaddr;
+   int ret;
+
+   if (!gpu)
+   return 0;
+
+   obj = drm_gem_object_lookup(file, args->handle);
+   if (!obj)
+   return -ENOENT;
+
+   base_vaddr = msm_gem_get_vaddr(obj);
+   if (IS_ERR(base_vaddr)) {
+   ret = PTR_ERR(base_vaddr);
+   goto err_put_gem_object;
+   }
+   if (args->offset + sizeof(*vaddr) > obj->size) {
+   ret = -EINVAL;
+   goto err_put_vaddr;
+   }
+
+   vaddr = base_vaddr + args->offset;
+
+   /* Assumes WC mapping */
+   ret = wait_event_interruptible_timeout(
+   gpu->event, *vaddr >= args->value, remaining_jiffies);
+
+   if (ret == 0) {
+   ret = -ETIMEDOUT;
+   goto err_put_vaddr;
+   } else if (ret == -ERESTARTSYS) {
+   goto err_put_vaddr;
+   }
+
+   msm_gem_put_vaddr(obj);
+   drm_gem_object_put_unlocked(obj);
+   return 0;
+
+err_put_vaddr:
+   msm_gem_put_vaddr(obj);
+err_put_gem_object:
+   drm_gem_object_put_unlocked(obj);
+   return ret;
+}
+
 static const struct drm_ioctl_desc msm_ioctls[] = {
DRM_IOCTL_DEF_DRV(MSM_GET_PARAM,msm_ioctl_get_param,
DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(MSM_GEM_NEW,  msm_ioctl_gem_new,  
DRM_RENDER_ALLOW),
@@ -964,6 +1019,7 @@ static const struct drm_ioctl_desc msm_ioctls[] = {
DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_NEW,   msm_ioctl_submitqueue_new,   
DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_CLOSE, msm_ioctl_submitqueue_close, 
DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, 
DRM_RENDER_ALLOW),
+   DRM_IOCTL_DEF_DRV(MSM_WAIT_IOVA, msm_ioctl_wait_iova, DRM_RENDER_ALLOW),
 };
 
 static const struct vm_operations_struct vm_ops = {
diff --git a/include/uapi/drm/msm_drm.h b/include/uapi/drm/msm_drm.h
index 0b85ed6a3710..8069e5628c5e 100644
--- a/include/uapi/drm/msm_drm.h
+++ b/include/uapi/drm/msm_drm.h
@@ -298,6 +298,16 @@ struct drm_msm_submitqueue_query {
__u32 pad;
 };
 
+/* This ioctl blocks until the u64 value at bo + offset is greater than or
+ * equal to the reference value.
+ */
+struct drm_msm_wait_iova {
+   __u32 handle;  /* in, GEM handle */
+   struct drm_msm_timespec timeout;   /* in */
+   __u64 offset;  /* offset into bo */
+   __u64 value;   /* reference value */
+};
+
 #define DRM_MSM_GET_PARAM  0x00
 /* placeholder:
 #define DRM_MSM_SET_PARAM  0x01
@@ -315,6 +325,7 @@ struct drm_msm_submitqueue_query {
 #define DRM_MSM_SUBMITQUEUE_NEW0x0A
 #define DRM_MSM_SUBMITQUEUE_CLOSE  0x0B
 #define DRM_MSM_SUBMITQUEUE_QUERY  0x0C
+#define DRM_MSM_WAIT_IOVA  0x0D
 
 #define DRM_IOCTL_MSM_GET_PARAMDRM_IOWR(DRM_COMMAND_BASE + 
DRM_MSM_GET_PARAM, struct drm_msm_param)
 #define DRM_IOCTL_MSM_GEM_NEW  DRM_IOWR(DRM_COMMAND_BASE + 
DRM_MSM_GEM_NEW, struct drm_msm_gem_new)
@@ -327,6 +338,7 @@ struct drm_msm_submitqueue_query {
 #define DRM_IOCTL_MSM_SUBMITQUEUE_NEWDRM_IOWR(DRM_COMMAND_BASE + 
DRM_MSM_SUBMITQUEUE_NEW, struct 

[Freedreno] [PATCH 1/2] drm/msm: Add a GPU-wide wait queue

2020-01-10 Thread Brian Ho
This wait queue is signaled on all IRQs for a given GPU and will be
used as part of the new MSM_WAIT_IOVA ioctl so userspace can sleep
until the value at a given iova reaches a certain condition.

Signed-off-by: Brian Ho 
---
 drivers/gpu/drm/msm/msm_gpu.c | 4 
 drivers/gpu/drm/msm/msm_gpu.h | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c
index a052364a5d74..d7310c1336e5 100644
--- a/drivers/gpu/drm/msm/msm_gpu.c
+++ b/drivers/gpu/drm/msm/msm_gpu.c
@@ -779,6 +779,8 @@ void msm_gpu_submit(struct msm_gpu *gpu, struct 
msm_gem_submit *submit,
 static irqreturn_t irq_handler(int irq, void *data)
 {
struct msm_gpu *gpu = data;
+   wake_up_all(>event);
+
return gpu->funcs->irq(gpu);
 }
 
@@ -871,6 +873,8 @@ int msm_gpu_init(struct drm_device *drm, struct 
platform_device *pdev,
 
spin_lock_init(>perf_lock);
 
+   init_waitqueue_head(>event);
+
 
/* Map registers: */
gpu->mmio = msm_ioremap(pdev, config->ioname, name);
diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h
index ab8f0f9c9dc8..60562f065dbc 100644
--- a/drivers/gpu/drm/msm/msm_gpu.h
+++ b/drivers/gpu/drm/msm/msm_gpu.h
@@ -104,6 +104,9 @@ struct msm_gpu {
 
struct msm_gem_address_space *aspace;
 
+   /* GPU-wide wait queue that is signaled on all IRQs */
+   wait_queue_head_t event;
+
/* Power Control: */
struct regulator *gpu_reg, *gpu_cx;
struct clk_bulk_data *grp_clks;
-- 
2.25.0.rc1.283.g88dfdc4193-goog

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 0/2] drm/msm: Add the MSM_WAIT_IOVA ioctl

2020-01-10 Thread Brian Ho
This patch set implements the MSM_WAIT_IOVA ioctl which lets
userspace sleep until the value at a given iova reaches a certain
condition. This is needed in turnip to implement the
VK_QUERY_RESULT_WAIT_BIT flag for vkGetQueryPoolResults.

First, we add a GPU-wide wait queue that is signaled on all IRQs.
We can then wait on this wait queue inside MSM_WAIT_IOVA until the
condition is met.

The corresponding merge request in mesa can be found at:
https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3279

Brian Ho (2):
  drm/msm: Add a GPU-wide wait queue
  drm/msm: Add MSM_WAIT_IOVA ioctl

 drivers/gpu/drm/msm/msm_drv.c | 60 +--
 drivers/gpu/drm/msm/msm_gpu.c |  4 +++
 drivers/gpu/drm/msm/msm_gpu.h |  3 ++
 include/uapi/drm/msm_drm.h| 12 +++
 4 files changed, 77 insertions(+), 2 deletions(-)

-- 
2.25.0.rc1.283.g88dfdc4193-goog

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH] drm/msm/dpu: Allow UBWC on NV12

2020-01-10 Thread Fritz Koenig
NV12 is a valid format for UBWC

Signed-off-by: Fritz Koenig 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog_format.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog_format.h 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog_format.h
index fbcb3c4bbfee..3766f0fd0bf0 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog_format.h
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog_format.h
@@ -10,6 +10,8 @@ static const uint32_t qcom_compressed_supported_formats[] = {
DRM_FORMAT_XBGR,
DRM_FORMAT_XRGB,
DRM_FORMAT_BGR565,
+
+   DRM_FORMAT_NV12,
 };
 
 static const uint32_t plane_formats[] = {
-- 
2.25.0.rc1.283.g88dfdc4193-goog

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


Re: [Freedreno] [PATCH 03/23] drm/i915: Don't use struct drm_driver.get_scanout_position()

2020-01-10 Thread Ville Syrjälä
On Fri, Jan 10, 2020 at 03:56:06PM +0200, Jani Nikula wrote:
> On Fri, 10 Jan 2020, Thomas Zimmermann  wrote:
> > Hi
> >
> > Am 10.01.20 um 12:59 schrieb Jani Nikula:
> >> On Fri, 10 Jan 2020, Thomas Zimmermann  wrote:
> >>> The callback struct drm_driver.get_scanout_position() is deprecated in
> >>> favor of struct drm_crtc_helper_funcs.get_scanout_position().
> >>>
> >>> i915 doesn't use CRTC helpers. The patch duplicates the caller
> >>> drm_calc_vbltimestamp_from_scanoutpos() for i915, such that the callback
> >>> function is not needed.
> >>>
> >>> Signed-off-by: Thomas Zimmermann 
> >>> ---
> >>>  drivers/gpu/drm/i915/i915_drv.c |   3 +-
> >>>  drivers/gpu/drm/i915/i915_irq.c | 117 ++--
> >>>  drivers/gpu/drm/i915/i915_irq.h |   9 +--
> >>>  3 files changed, 119 insertions(+), 10 deletions(-)
> >> 
> >> Not really enthusiastic about the diffstat in a "cleanup" series.
> >
> > Well, the cleanup is about the content of drm_driver :)
> >
> >> 
> >> I wonder if you could add a generic helper version of
> >> drm_calc_vbltimestamp_from_scanoutpos where you pass the
> >> get_scanout_position function as a parameter. Both
> >> drm_calc_vbltimestamp_from_scanoutpos and the new
> >> i915_calc_vbltimestamp_from_scanoutpos would then be fairly thin
> >> wrappers passing in the relevant get_scanout_position function.
> >
> > Of course. Will be in v2 of the series.
> 
> Please give Ville (Cc'd) a moment before sending v2 in case he wants to
> chime in on this.

Passing the function pointer was one option I considered for this a while
back. Can't remeber what other solutions I condsidered. But I guess I
didn't like any of them enough to make an actual patch.

-- 
Ville Syrjälä
Intel
___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


Re: [Freedreno] [PATCH 03/23] drm/i915: Don't use struct drm_driver.get_scanout_position()

2020-01-10 Thread Jani Nikula
On Fri, 10 Jan 2020, Thomas Zimmermann  wrote:
> Hi
>
> Am 10.01.20 um 12:59 schrieb Jani Nikula:
>> On Fri, 10 Jan 2020, Thomas Zimmermann  wrote:
>>> The callback struct drm_driver.get_scanout_position() is deprecated in
>>> favor of struct drm_crtc_helper_funcs.get_scanout_position().
>>>
>>> i915 doesn't use CRTC helpers. The patch duplicates the caller
>>> drm_calc_vbltimestamp_from_scanoutpos() for i915, such that the callback
>>> function is not needed.
>>>
>>> Signed-off-by: Thomas Zimmermann 
>>> ---
>>>  drivers/gpu/drm/i915/i915_drv.c |   3 +-
>>>  drivers/gpu/drm/i915/i915_irq.c | 117 ++--
>>>  drivers/gpu/drm/i915/i915_irq.h |   9 +--
>>>  3 files changed, 119 insertions(+), 10 deletions(-)
>> 
>> Not really enthusiastic about the diffstat in a "cleanup" series.
>
> Well, the cleanup is about the content of drm_driver :)
>
>> 
>> I wonder if you could add a generic helper version of
>> drm_calc_vbltimestamp_from_scanoutpos where you pass the
>> get_scanout_position function as a parameter. Both
>> drm_calc_vbltimestamp_from_scanoutpos and the new
>> i915_calc_vbltimestamp_from_scanoutpos would then be fairly thin
>> wrappers passing in the relevant get_scanout_position function.
>
> Of course. Will be in v2 of the series.

Please give Ville (Cc'd) a moment before sending v2 in case he wants to
chime in on this.

Thanks,
Jani.


>
> Best regards
> Thomas
>
>> 
>> This would reduce the almost identical duplication of the function in
>> i915.
>> 
>> BR,
>> Jani.
>> 
>>>
>>> diff --git a/drivers/gpu/drm/i915/i915_drv.c 
>>> b/drivers/gpu/drm/i915/i915_drv.c
>>> index f7385abdd74b..4a0a7fb85c53 100644
>>> --- a/drivers/gpu/drm/i915/i915_drv.c
>>> +++ b/drivers/gpu/drm/i915/i915_drv.c
>>> @@ -2769,8 +2769,7 @@ static struct drm_driver driver = {
>>> .gem_prime_export = i915_gem_prime_export,
>>> .gem_prime_import = i915_gem_prime_import,
>>>  
>>> -   .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
>>> -   .get_scanout_position = i915_get_crtc_scanoutpos,
>>> +   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
>>>  
>>> .dumb_create = i915_gem_dumb_create,
>>> .dumb_map_offset = i915_gem_dumb_mmap_offset,
>>> diff --git a/drivers/gpu/drm/i915/i915_irq.c 
>>> b/drivers/gpu/drm/i915/i915_irq.c
>>> index afc6aad9bf8c..99d0c3b0feae 100644
>>> --- a/drivers/gpu/drm/i915/i915_irq.c
>>> +++ b/drivers/gpu/drm/i915/i915_irq.c
>>> @@ -52,6 +52,11 @@
>>>  #include "i915_trace.h"
>>>  #include "intel_pm.h"
>>>  
>>> +/* Retry timestamp calculation up to 3 times to satisfy
>>> + * drm_timestamp_precision before giving up.
>>> + */
>>> +#define I915_TIMESTAMP_MAXRETRIES 3
>>> +
>>>  /**
>>>   * DOC: interrupt handling
>>>   *
>>> @@ -762,10 +767,11 @@ static int __intel_get_crtc_scanline(struct 
>>> intel_crtc *crtc)
>>> return (position + crtc->scanline_offset) % vtotal;
>>>  }
>>>  
>>> -bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int index,
>>> - bool in_vblank_irq, int *vpos, int *hpos,
>>> - ktime_t *stime, ktime_t *etime,
>>> - const struct drm_display_mode *mode)
>>> +static bool i915_get_crtc_scanoutpos(struct drm_device *dev,
>>> +unsigned int index, bool in_vblank_irq,
>>> +int *vpos, int *hpos,
>>> +ktime_t *stime, ktime_t *etime,
>>> +const struct drm_display_mode *mode)
>>>  {
>>> struct drm_i915_private *dev_priv = to_i915(dev);
>>> struct intel_crtc *crtc = to_intel_crtc(drm_crtc_from_index(dev, 
>>> index));
>>> @@ -879,6 +885,109 @@ bool i915_get_crtc_scanoutpos(struct drm_device *dev, 
>>> unsigned int index,
>>> return true;
>>>  }
>>>  
>>> +bool i915_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
>>> +   unsigned int pipe,
>>> +   int *max_error,
>>> +   ktime_t *vblank_time,
>>> +   bool in_vblank_irq)
>>> +{
>>> +   struct timespec64 ts_etime, ts_vblank_time;
>>> +   ktime_t stime, etime;
>>> +   bool vbl_status;
>>> +   struct drm_crtc *crtc;
>>> +   const struct drm_display_mode *mode;
>>> +   struct drm_vblank_crtc *vblank = >vblank[pipe];
>>> +   int vpos, hpos, i;
>>> +   int delta_ns, duration_ns;
>>> +
>>> +   crtc = drm_crtc_from_index(dev, pipe);
>>> +
>>> +   if (pipe >= dev->num_crtcs || !crtc) {
>>> +   DRM_ERROR("Invalid crtc %u\n", pipe);
>>> +   return false;
>>> +   }
>>> +
>>> +   if (drm_drv_uses_atomic_modeset(dev))
>>> +   mode = >hwmode;
>>> +   else
>>> +   mode = >hwmode;
>>> +
>>> +   /* If mode timing undefined, just return as no-op:
>>> +* Happens during initial modesetting of a crtc.
>>> +*/
>>> +   if (mode->crtc_clock == 0) {
>>> +   DRM_DEBUG("crtc %u: Noop 

Re: [Freedreno] [PATCH 03/23] drm/i915: Don't use struct drm_driver.get_scanout_position()

2020-01-10 Thread Thomas Zimmermann
Hi

Am 10.01.20 um 12:59 schrieb Jani Nikula:
> On Fri, 10 Jan 2020, Thomas Zimmermann  wrote:
>> The callback struct drm_driver.get_scanout_position() is deprecated in
>> favor of struct drm_crtc_helper_funcs.get_scanout_position().
>>
>> i915 doesn't use CRTC helpers. The patch duplicates the caller
>> drm_calc_vbltimestamp_from_scanoutpos() for i915, such that the callback
>> function is not needed.
>>
>> Signed-off-by: Thomas Zimmermann 
>> ---
>>  drivers/gpu/drm/i915/i915_drv.c |   3 +-
>>  drivers/gpu/drm/i915/i915_irq.c | 117 ++--
>>  drivers/gpu/drm/i915/i915_irq.h |   9 +--
>>  3 files changed, 119 insertions(+), 10 deletions(-)
> 
> Not really enthusiastic about the diffstat in a "cleanup" series.

Well, the cleanup is about the content of drm_driver :)

> 
> I wonder if you could add a generic helper version of
> drm_calc_vbltimestamp_from_scanoutpos where you pass the
> get_scanout_position function as a parameter. Both
> drm_calc_vbltimestamp_from_scanoutpos and the new
> i915_calc_vbltimestamp_from_scanoutpos would then be fairly thin
> wrappers passing in the relevant get_scanout_position function.

Of course. Will be in v2 of the series.

Best regards
Thomas

> 
> This would reduce the almost identical duplication of the function in
> i915.
> 
> BR,
> Jani.
> 
>>
>> diff --git a/drivers/gpu/drm/i915/i915_drv.c 
>> b/drivers/gpu/drm/i915/i915_drv.c
>> index f7385abdd74b..4a0a7fb85c53 100644
>> --- a/drivers/gpu/drm/i915/i915_drv.c
>> +++ b/drivers/gpu/drm/i915/i915_drv.c
>> @@ -2769,8 +2769,7 @@ static struct drm_driver driver = {
>>  .gem_prime_export = i915_gem_prime_export,
>>  .gem_prime_import = i915_gem_prime_import,
>>  
>> -.get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
>> -.get_scanout_position = i915_get_crtc_scanoutpos,
>> +.get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
>>  
>>  .dumb_create = i915_gem_dumb_create,
>>  .dumb_map_offset = i915_gem_dumb_mmap_offset,
>> diff --git a/drivers/gpu/drm/i915/i915_irq.c 
>> b/drivers/gpu/drm/i915/i915_irq.c
>> index afc6aad9bf8c..99d0c3b0feae 100644
>> --- a/drivers/gpu/drm/i915/i915_irq.c
>> +++ b/drivers/gpu/drm/i915/i915_irq.c
>> @@ -52,6 +52,11 @@
>>  #include "i915_trace.h"
>>  #include "intel_pm.h"
>>  
>> +/* Retry timestamp calculation up to 3 times to satisfy
>> + * drm_timestamp_precision before giving up.
>> + */
>> +#define I915_TIMESTAMP_MAXRETRIES 3
>> +
>>  /**
>>   * DOC: interrupt handling
>>   *
>> @@ -762,10 +767,11 @@ static int __intel_get_crtc_scanline(struct intel_crtc 
>> *crtc)
>>  return (position + crtc->scanline_offset) % vtotal;
>>  }
>>  
>> -bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int index,
>> -  bool in_vblank_irq, int *vpos, int *hpos,
>> -  ktime_t *stime, ktime_t *etime,
>> -  const struct drm_display_mode *mode)
>> +static bool i915_get_crtc_scanoutpos(struct drm_device *dev,
>> + unsigned int index, bool in_vblank_irq,
>> + int *vpos, int *hpos,
>> + ktime_t *stime, ktime_t *etime,
>> + const struct drm_display_mode *mode)
>>  {
>>  struct drm_i915_private *dev_priv = to_i915(dev);
>>  struct intel_crtc *crtc = to_intel_crtc(drm_crtc_from_index(dev, 
>> index));
>> @@ -879,6 +885,109 @@ bool i915_get_crtc_scanoutpos(struct drm_device *dev, 
>> unsigned int index,
>>  return true;
>>  }
>>  
>> +bool i915_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
>> +unsigned int pipe,
>> +int *max_error,
>> +ktime_t *vblank_time,
>> +bool in_vblank_irq)
>> +{
>> +struct timespec64 ts_etime, ts_vblank_time;
>> +ktime_t stime, etime;
>> +bool vbl_status;
>> +struct drm_crtc *crtc;
>> +const struct drm_display_mode *mode;
>> +struct drm_vblank_crtc *vblank = >vblank[pipe];
>> +int vpos, hpos, i;
>> +int delta_ns, duration_ns;
>> +
>> +crtc = drm_crtc_from_index(dev, pipe);
>> +
>> +if (pipe >= dev->num_crtcs || !crtc) {
>> +DRM_ERROR("Invalid crtc %u\n", pipe);
>> +return false;
>> +}
>> +
>> +if (drm_drv_uses_atomic_modeset(dev))
>> +mode = >hwmode;
>> +else
>> +mode = >hwmode;
>> +
>> +/* If mode timing undefined, just return as no-op:
>> + * Happens during initial modesetting of a crtc.
>> + */
>> +if (mode->crtc_clock == 0) {
>> +DRM_DEBUG("crtc %u: Noop due to uninitialized mode.\n", pipe);
>> +WARN_ON_ONCE(drm_drv_uses_atomic_modeset(dev));
>> +
>> +return false;
>> +}
>> +
>> +/* Get current scanout position with system timestamp.
>> + * Repeat query up to 

Re: [Freedreno] [PATCH 01/23] drm: Add get_scanout_position() to struct drm_crtc_helper_funcs

2020-01-10 Thread Jani Nikula
On Fri, 10 Jan 2020, Thomas Zimmermann  wrote:
> The new callback get_scanout_position() reads the current location of
> the scanout process. The operation is currentyl located in struct
> drm_driver, but really belongs to the CRTC. Drivers will be converted
> in separate patches.
>
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/drm_vblank.c | 24 
>  include/drm/drm_drv.h|  7 +---
>  include/drm/drm_modeset_helper_vtables.h | 47 
>  3 files changed, 65 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 1659b13b178c..c12f0b333e14 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  
> @@ -590,7 +591,7 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
>   * Implements calculation of exact vblank timestamps from given 
> drm_display_mode
>   * timings and current video scanout position of a CRTC. This can be directly
>   * used as the _driver.get_vblank_timestamp implementation of a kms 
> driver
> - * if _driver.get_scanout_position is implemented.
> + * if _crtc_helper_funcs.get_scanout_position is implemented.
>   *
>   * The current implementation only handles standard video modes. For double 
> scan
>   * and interlaced modes the driver is supposed to adjust the hardware mode
> @@ -632,8 +633,9 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct 
> drm_device *dev,
>   }
>  
>   /* Scanout position query not supported? Should not happen. */
> - if (!dev->driver->get_scanout_position) {
> - DRM_ERROR("Called from driver w/o get_scanout_position()!?\n");
> + if (!dev->driver->get_scanout_position ||
> + !crtc->helper_private->get_scanout_position) {

ITYM s/||/&&/

BR,
Jani.


> + DRM_ERROR("Called from CRTC w/o get_scanout_position()!?\n");
>   return false;
>   }
>  
> @@ -664,11 +666,17 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct 
> drm_device *dev,
>* Get vertical and horizontal scanout position vpos, hpos,
>* and bounding timestamps stime, etime, pre/post query.
>*/
> - vbl_status = dev->driver->get_scanout_position(dev, pipe,
> -in_vblank_irq,
> -, ,
> -, ,
> -mode);
> + if (crtc->helper_private->get_scanout_position) {
> + vbl_status =
> + crtc->helper_private->get_scanout_position(
> + crtc, in_vblank_irq, , ,
> + , , mode);
> + } else {
> + vbl_status =
> + dev->driver->get_scanout_position(
> + dev, pipe, in_vblank_irq, ,
> + , , , mode);
> + }
>  
>   /* Return as no-op if scanout query unsupported or failed. */
>   if (!vbl_status) {
> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> index cf13470810a5..d0049e5786fc 100644
> --- a/include/drm/drm_drv.h
> +++ b/include/drm/drm_drv.h
> @@ -362,11 +362,8 @@ struct drm_driver {
>* True on success, false if a reliable scanout position counter could
>* not be read out.
>*
> -  * FIXME:
> -  *
> -  * Since this is a helper to implement @get_vblank_timestamp, we should
> -  * move it to  drm_crtc_helper_funcs, like all the other
> -  * helper-internal hooks.
> +  * This is deprecated and should not be used by new drivers.
> +  * Use _crtc_helper_funcs.get_scanout_position instead.
>*/
>   bool (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
> bool in_vblank_irq, int *vpos, int *hpos,
> diff --git a/include/drm/drm_modeset_helper_vtables.h 
> b/include/drm/drm_modeset_helper_vtables.h
> index 5a87f1bd7a3f..e398512bfd5f 100644
> --- a/include/drm/drm_modeset_helper_vtables.h
> +++ b/include/drm/drm_modeset_helper_vtables.h
> @@ -450,6 +450,53 @@ struct drm_crtc_helper_funcs {
>*/
>   void (*atomic_disable)(struct drm_crtc *crtc,
>  struct drm_crtc_state *old_crtc_state);
> +
> + /**
> +  * @get_scanout_position:
> +  *
> +  * Called by vblank timestamping code.
> +  *
> +  * Returns the current display scanout position from a CRTC and an
> +  * optional accurate ktime_get() timestamp of when the position was
> +  * measured. Note that this is a helper callback which is only used
> +  * if a driver uses 

[Freedreno] [PATCH 18/23] drm/sti: Convert to CRTC VBLANK callbacks

2020-01-10 Thread Thomas Zimmermann
VBLANK callbacks in struct drm_driver are deprecated in favor of
their equivalents in struct drm_crtc_funcs. Convert sti over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/sti/sti_crtc.c | 11 ---
 drivers/gpu/drm/sti/sti_crtc.h |  2 --
 drivers/gpu/drm/sti/sti_drv.c  |  3 ---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/sti/sti_crtc.c b/drivers/gpu/drm/sti/sti_crtc.c
index dc64fbfc4e61..49e6cb8f5836 100644
--- a/drivers/gpu/drm/sti/sti_crtc.c
+++ b/drivers/gpu/drm/sti/sti_crtc.c
@@ -279,12 +279,13 @@ int sti_crtc_vblank_cb(struct notifier_block *nb,
return 0;
 }
 
-int sti_crtc_enable_vblank(struct drm_device *dev, unsigned int pipe)
+static int sti_crtc_enable_vblank(struct drm_crtc *crtc)
 {
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
struct sti_private *dev_priv = dev->dev_private;
struct sti_compositor *compo = dev_priv->compo;
struct notifier_block *vtg_vblank_nb = >vtg_vblank_nb[pipe];
-   struct drm_crtc *crtc = >mixer[pipe]->drm_crtc;
struct sti_vtg *vtg = compo->vtg[pipe];
 
DRM_DEBUG_DRIVER("\n");
@@ -297,8 +298,10 @@ int sti_crtc_enable_vblank(struct drm_device *dev, 
unsigned int pipe)
return 0;
 }
 
-void sti_crtc_disable_vblank(struct drm_device *drm_dev, unsigned int pipe)
+static void sti_crtc_disable_vblank(struct drm_crtc *crtc)
 {
+   struct drm_device *drm_dev = crtc->dev;
+   unsigned int pipe = crtc->index;
struct sti_private *priv = drm_dev->dev_private;
struct sti_compositor *compo = priv->compo;
struct notifier_block *vtg_vblank_nb = >vtg_vblank_nb[pipe];
@@ -330,6 +333,8 @@ static const struct drm_crtc_funcs sti_crtc_funcs = {
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
.late_register = sti_crtc_late_register,
+   .enable_vblank = sti_crtc_enable_vblank,
+   .disable_vblank = sti_crtc_disable_vblank,
 };
 
 bool sti_crtc_is_main(struct drm_crtc *crtc)
diff --git a/drivers/gpu/drm/sti/sti_crtc.h b/drivers/gpu/drm/sti/sti_crtc.h
index df489ab14e2b..1132b4586712 100644
--- a/drivers/gpu/drm/sti/sti_crtc.h
+++ b/drivers/gpu/drm/sti/sti_crtc.h
@@ -15,8 +15,6 @@ struct sti_mixer;
 
 int sti_crtc_init(struct drm_device *drm_dev, struct sti_mixer *mixer,
  struct drm_plane *primary, struct drm_plane *cursor);
-int sti_crtc_enable_vblank(struct drm_device *dev, unsigned int pipe);
-void sti_crtc_disable_vblank(struct drm_device *dev, unsigned int pipe);
 int sti_crtc_vblank_cb(struct notifier_block *nb,
   unsigned long event, void *data);
 bool sti_crtc_is_main(struct drm_crtc *drm_crtc);
diff --git a/drivers/gpu/drm/sti/sti_drv.c b/drivers/gpu/drm/sti/sti_drv.c
index a39fc36f815b..8e30001bf545 100644
--- a/drivers/gpu/drm/sti/sti_drv.c
+++ b/drivers/gpu/drm/sti/sti_drv.c
@@ -146,9 +146,6 @@ static struct drm_driver sti_driver = {
.dumb_create = drm_gem_cma_dumb_create,
.fops = _driver_fops,
 
-   .enable_vblank = sti_crtc_enable_vblank,
-   .disable_vblank = sti_crtc_disable_vblank,
-
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 20/23] drm/vc4: Convert to CRTC VBLANK callbacks

2020-01-10 Thread Thomas Zimmermann
VBLANK callbacks in struct drm_driver are deprecated in favor of
their equivalents in struct drm_crtc_funcs. Convert vc4 over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/vc4/vc4_crtc.c | 1 +
 drivers/gpu/drm/vc4/vc4_drv.c  | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c
index f1e7597ea17e..e4081634648d 100644
--- a/drivers/gpu/drm/vc4/vc4_crtc.c
+++ b/drivers/gpu/drm/vc4/vc4_crtc.c
@@ -1031,6 +1031,7 @@ static const struct drm_crtc_funcs vc4_crtc_funcs = {
.gamma_set = drm_atomic_helper_legacy_gamma_set,
.enable_vblank = vc4_enable_vblank,
.disable_vblank = vc4_disable_vblank,
+   .get_vblank_timestamp = drm_crtc_calc_vbltimestamp_from_scanoutpos,
 };
 
 static const struct drm_crtc_helper_funcs vc4_crtc_helper_funcs = {
diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index e6982a7b0c5e..76f93b662766 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -190,8 +190,6 @@ static struct drm_driver vc4_drm_driver = {
.irq_postinstall = vc4_irq_postinstall,
.irq_uninstall = vc4_irq_uninstall,
 
-   .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
-
 #if defined(CONFIG_DEBUG_FS)
.debugfs_init = vc4_debugfs_init,
 #endif
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 21/23] drm/vkms: Convert to CRTC VBLANK callbacks

2020-01-10 Thread Thomas Zimmermann
VBLANK callbacks in struct drm_driver are deprecated in favor of
their equivalents in struct drm_crtc_funcs. Convert vkms over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/vkms/vkms_crtc.c | 9 ++---
 drivers/gpu/drm/vkms/vkms_drv.c  | 1 -
 drivers/gpu/drm/vkms/vkms_drv.h  | 4 
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 74f703b8d22a..ac85e17428f8 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -76,10 +76,12 @@ static void vkms_disable_vblank(struct drm_crtc *crtc)
hrtimer_cancel(>vblank_hrtimer);
 }
 
-bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
-  int *max_error, ktime_t *vblank_time,
-  bool in_vblank_irq)
+static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
+ int *max_error, ktime_t *vblank_time,
+ bool in_vblank_irq)
 {
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
struct vkms_output *output = >output;
struct drm_vblank_crtc *vblank = >vblank[pipe];
@@ -154,6 +156,7 @@ static const struct drm_crtc_funcs vkms_crtc_funcs = {
.atomic_destroy_state   = vkms_atomic_crtc_destroy_state,
.enable_vblank  = vkms_enable_vblank,
.disable_vblank = vkms_disable_vblank,
+   .get_vblank_timestamp   = vkms_get_vblank_timestamp,
.get_crc_sources= vkms_get_crc_sources,
.set_crc_source = vkms_set_crc_source,
.verify_crc_source  = vkms_verify_crc_source,
diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index 25bd7519295f..860de052e820 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -103,7 +103,6 @@ static struct drm_driver vkms_driver = {
.dumb_create= vkms_dumb_create,
.gem_vm_ops = _gem_vm_ops,
.gem_free_object_unlocked = vkms_gem_free_object,
-   .get_vblank_timestamp   = vkms_get_vblank_timestamp,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_import_sg_table = vkms_prime_import_sg_table,
 
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 7d52e24564db..eda04ffba7b1 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -111,10 +111,6 @@ struct vkms_gem_object {
 int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
   struct drm_plane *primary, struct drm_plane *cursor);
 
-bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
-  int *max_error, ktime_t *vblank_time,
-  bool in_vblank_irq);
-
 int vkms_output_init(struct vkms_device *vkmsdev, int index);
 
 struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev,
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 23/23] drm: Cleanup VBLANK callbacks in struct drm_driver

2020-01-10 Thread Thomas Zimmermann
All non-legacy users of VBLANK functions in struct drm_driver have been
converted to use the respective interfaces in struct drm_crtc_funcs. The
remaining users of VBLANK callbacks in struct drm_driver are legacy drivers
with userspace modesetting.

There are no users left of get_vblank_timestamp(), so the callback is
being removed. The other VBLANK callbacks are being moved to the legacy
section at the end of struct drm_driver.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/drm_vblank.c |  39 +-
 include/drm/drm_drv.h| 101 ++-
 2 files changed, 17 insertions(+), 123 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 7cf436a4b908..ceff68474d4d 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -138,10 +138,9 @@ static u32 __get_vblank_counter(struct drm_device *dev, 
unsigned int pipe)
 
if (crtc->funcs->get_vblank_counter)
return crtc->funcs->get_vblank_counter(crtc);
-   }
-
-   if (dev->driver->get_vblank_counter)
+   } else if (dev->driver->get_vblank_counter) {
return dev->driver->get_vblank_counter(dev, pipe);
+   }
 
return drm_vblank_no_hw_counter(dev, pipe);
 }
@@ -334,8 +333,7 @@ u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
unsigned long flags;
 
WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) &&
- !crtc->funcs->get_vblank_timestamp &&
- !dev->driver->get_vblank_timestamp,
+ !crtc->funcs->get_vblank_timestamp,
  "This function requires support for accurate vblank 
timestamps.");
 
spin_lock_irqsave(>vblank_time_lock, flags);
@@ -357,13 +355,11 @@ static void __disable_vblank(struct drm_device *dev, 
unsigned int pipe)
if (WARN_ON(!crtc))
return;
 
-   if (crtc->funcs->disable_vblank) {
+   if (crtc->funcs->disable_vblank)
crtc->funcs->disable_vblank(crtc);
-   return;
-   }
+   } else {
+   dev->driver->disable_vblank(dev, pipe);
}
-
-   dev->driver->disable_vblank(dev, pipe);
 }
 
 /*
@@ -791,9 +787,6 @@ drm_get_last_vbltimestamp(struct drm_device *dev, unsigned 
int pipe,
 
ret = crtc->funcs->get_vblank_timestamp(crtc, _error,
tvblank, in_vblank_irq);
-   } else if (dev->driver->get_vblank_timestamp && (max_error > 0)) {
-   ret = dev->driver->get_vblank_timestamp(dev, pipe, _error,
-   tvblank, in_vblank_irq);
}
 
/* GPU high precision timestamp query unsupported or failed.
@@ -1016,9 +1009,11 @@ static int __enable_vblank(struct drm_device *dev, 
unsigned int pipe)
 
if (crtc->funcs->enable_vblank)
return crtc->funcs->enable_vblank(crtc);
+   } else if (dev->driver->enable_vblank) {
+   return dev->driver->enable_vblank(dev, pipe);
}
 
-   return dev->driver->enable_vblank(dev, pipe);
+   return -EINVAL;
 }
 
 static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
@@ -1109,13 +1104,10 @@ static bool __vblank_disable_immediate(struct 
drm_device *dev, unsigned int pipe
return false;
 
crtc = drm_crtc_from_index(dev, pipe);
-   if (crtc && crtc->funcs->get_vblank_timestamp)
-   return true;
-
-   if (dev->driver->get_vblank_timestamp)
-   return true;
+   if (!crtc || !crtc->funcs->get_vblank_timestamp)
+   return false;
 
-   return false;
+   return true;
 }
 
 static void drm_vblank_put(struct drm_device *dev, unsigned int pipe)
@@ -1798,7 +1790,6 @@ static void drm_handle_vblank_events(struct drm_device 
*dev, unsigned int pipe)
struct drm_pending_vblank_event *e, *t;
ktime_t now;
u64 seq;
-   bool high_prec;
 
assert_spin_locked(>event_lock);
 
@@ -1818,10 +1809,8 @@ static void drm_handle_vblank_events(struct drm_device 
*dev, unsigned int pipe)
send_vblank_event(dev, e, seq, now);
}
 
-   high_prec = crtc->funcs->get_vblank_timestamp ||
-   dev->driver->get_vblank_timestamp;
-
-   trace_drm_vblank_event(pipe, seq, now, high_prec);
+   trace_drm_vblank_event(pipe, seq, now,
+  crtc->funcs->get_vblank_timestamp != NULL);
 }
 
 /**
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index b704e252f3b2..e290b3aca6eb 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -268,104 +268,6 @@ struct drm_driver {
 */
void (*release) (struct drm_device *);
 
-   /**
-* @get_vblank_counter:
-*
-* Driver callback for fetching a raw hardware vblank counter for 

[Freedreno] [PATCH 17/23] drm/radeon: Convert to CRTC VBLANK callbacks

2020-01-10 Thread Thomas Zimmermann
VBLANK callbacks in struct drm_driver are deprecated in favor of
their equivalents in struct drm_crtc_funcs. Convert radeon over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/radeon/radeon_display.c | 12 --
 drivers/gpu/drm/radeon/radeon_drv.c |  7 --
 drivers/gpu/drm/radeon/radeon_kms.c | 29 ++---
 3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_display.c 
b/drivers/gpu/drm/radeon/radeon_display.c
index 7187158b9963..9116975b6eb9 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -45,6 +45,10 @@
 #include "atom.h"
 #include "radeon.h"
 
+u32 radeon_get_vblank_counter_kms(struct drm_crtc *crtc);
+int radeon_enable_vblank_kms(struct drm_crtc *crtc);
+void radeon_disable_vblank_kms(struct drm_crtc *crtc);
+
 static void avivo_crtc_load_lut(struct drm_crtc *crtc)
 {
struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
@@ -458,7 +462,7 @@ static void radeon_flip_work_func(struct work_struct 
*__work)
(DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_IN_VBLANK) &&
(!ASIC_IS_AVIVO(rdev) ||
((int) (work->target_vblank -
-   dev->driver->get_vblank_counter(dev, work->crtc_id)) > 0)))
+   crtc->funcs->get_vblank_counter(crtc)) > 0)))
usleep_range(1000, 2000);
 
/* We borrow the event spin lock for protecting flip_status */
@@ -574,7 +578,7 @@ static int radeon_crtc_page_flip_target(struct drm_crtc 
*crtc,
}
work->base = base;
work->target_vblank = target - (uint32_t)drm_crtc_vblank_count(crtc) +
-   dev->driver->get_vblank_counter(dev, work->crtc_id);
+   crtc->funcs->get_vblank_counter(crtc);
 
/* We borrow the event spin lock for protecting flip_work */
spin_lock_irqsave(>dev->event_lock, flags);
@@ -666,6 +670,10 @@ static const struct drm_crtc_funcs radeon_crtc_funcs = {
.set_config = radeon_crtc_set_config,
.destroy = radeon_crtc_destroy,
.page_flip_target = radeon_crtc_page_flip_target,
+   .get_vblank_counter = radeon_get_vblank_counter_kms,
+   .enable_vblank = radeon_enable_vblank_kms,
+   .disable_vblank = radeon_disable_vblank_kms,
+   .get_vblank_timestamp = drm_crtc_calc_vbltimestamp_from_scanoutpos,
 };
 
 static void radeon_crtc_init(struct drm_device *dev, int index)
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c 
b/drivers/gpu/drm/radeon/radeon_drv.c
index 1f597f166bff..49ce2e7d5f9e 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -119,9 +119,6 @@ void radeon_driver_postclose_kms(struct drm_device *dev,
 int radeon_suspend_kms(struct drm_device *dev, bool suspend,
   bool fbcon, bool freeze);
 int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
-u32 radeon_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
-int radeon_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
-void radeon_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
 void radeon_driver_irq_preinstall_kms(struct drm_device *dev);
 int radeon_driver_irq_postinstall_kms(struct drm_device *dev);
 void radeon_driver_irq_uninstall_kms(struct drm_device *dev);
@@ -571,10 +568,6 @@ static struct drm_driver kms_driver = {
.postclose = radeon_driver_postclose_kms,
.lastclose = radeon_driver_lastclose_kms,
.unload = radeon_driver_unload_kms,
-   .get_vblank_counter = radeon_get_vblank_counter_kms,
-   .enable_vblank = radeon_enable_vblank_kms,
-   .disable_vblank = radeon_disable_vblank_kms,
-   .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
.irq_preinstall = radeon_driver_irq_preinstall_kms,
.irq_postinstall = radeon_driver_irq_postinstall_kms,
.irq_uninstall = radeon_driver_irq_uninstall_kms,
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c 
b/drivers/gpu/drm/radeon/radeon_kms.c
index d24f23a81656..cab891f86dc0 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -739,14 +739,15 @@ void radeon_driver_postclose_kms(struct drm_device *dev,
 /**
  * radeon_get_vblank_counter_kms - get frame count
  *
- * @dev: drm dev pointer
- * @pipe: crtc to get the frame count from
+ * @crtc: crtc to get the frame count from
  *
  * Gets the frame count on the requested crtc (all asics).
  * Returns frame count on success, -EINVAL on failure.
  */
-u32 radeon_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe)
+u32 radeon_get_vblank_counter_kms(struct drm_crtc *crtc)
 {
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
int vpos, hpos, stat;
u32 count;
struct radeon_device *rdev = dev->dev_private;
@@ -808,25 +809,26 @@ u32 radeon_get_vblank_counter_kms(struct drm_device *dev, 
unsigned int pipe)
 /**
 

[Freedreno] [PATCH 13/23] drm/gma500: Convert to CRTC VBLANK callbacks

2020-01-10 Thread Thomas Zimmermann
VBLANK callbacks in struct drm_driver are deprecated in favor of
their equivalents in struct drm_crtc_funcs. Convert gma500 over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/gma500/cdv_intel_display.c |  3 +++
 drivers/gpu/drm/gma500/psb_drv.c   |  4 
 drivers/gpu/drm/gma500/psb_drv.h   |  6 +++---
 drivers/gpu/drm/gma500/psb_intel_display.c |  3 +++
 drivers/gpu/drm/gma500/psb_irq.c   | 12 +---
 drivers/gpu/drm/gma500/psb_irq.h   |  7 ---
 6 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/gma500/cdv_intel_display.c 
b/drivers/gpu/drm/gma500/cdv_intel_display.c
index 1ed854f498b7..686385a66167 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_display.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_display.c
@@ -977,6 +977,9 @@ const struct drm_crtc_funcs cdv_intel_crtc_funcs = {
.set_config = gma_crtc_set_config,
.destroy = gma_crtc_destroy,
.page_flip = gma_crtc_page_flip,
+   .enable_vblank = psb_enable_vblank,
+   .disable_vblank = psb_disable_vblank,
+   .get_vblank_counter = psb_get_vblank_counter,
 };
 
 const struct gma_clock_funcs cdv_clock_funcs = {
diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 52591416f8fe..36cb292fdebe 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -363,7 +363,6 @@ static int psb_driver_load(struct drm_device *dev, unsigned 
long flags)
drm_irq_install(dev, dev->pdev->irq);
 
dev->max_vblank_count = 0xff; /* only 24 bits of frame count */
-   dev->driver->get_vblank_counter = psb_get_vblank_counter;
 
psb_modeset_init(dev);
psb_fbdev_init(dev);
@@ -507,9 +506,6 @@ static struct drm_driver driver = {
.irq_postinstall = psb_irq_postinstall,
.irq_uninstall = psb_irq_uninstall,
.irq_handler = psb_irq_handler,
-   .enable_vblank = psb_enable_vblank,
-   .disable_vblank = psb_disable_vblank,
-   .get_vblank_counter = psb_get_vblank_counter,
 
.gem_free_object = psb_gem_free_object,
.gem_vm_ops = _gem_vm_ops,
diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
index 3d4ef3071d45..956926341316 100644
--- a/drivers/gpu/drm/gma500/psb_drv.h
+++ b/drivers/gpu/drm/gma500/psb_drv.h
@@ -681,15 +681,15 @@ extern void psb_irq_turn_off_dpst(struct drm_device *dev);
 extern void psb_irq_uninstall_islands(struct drm_device *dev, int hw_islands);
 extern int psb_vblank_wait2(struct drm_device *dev, unsigned int *sequence);
 extern int psb_vblank_wait(struct drm_device *dev, unsigned int *sequence);
-extern int psb_enable_vblank(struct drm_device *dev, unsigned int pipe);
-extern void psb_disable_vblank(struct drm_device *dev, unsigned int pipe);
+extern int psb_enable_vblank(struct drm_crtc *crtc);
+extern void psb_disable_vblank(struct drm_crtc *crtc);
 void
 psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
 
 void
 psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
 
-extern u32 psb_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
+extern u32 psb_get_vblank_counter(struct drm_crtc *crtc);
 
 /* framebuffer.c */
 extern int psbfb_probed(struct drm_device *dev);
diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c 
b/drivers/gpu/drm/gma500/psb_intel_display.c
index fed3b563e62e..531c5485be17 100644
--- a/drivers/gpu/drm/gma500/psb_intel_display.c
+++ b/drivers/gpu/drm/gma500/psb_intel_display.c
@@ -433,6 +433,9 @@ const struct drm_crtc_funcs psb_intel_crtc_funcs = {
.set_config = gma_crtc_set_config,
.destroy = gma_crtc_destroy,
.page_flip = gma_crtc_page_flip,
+   .enable_vblank = psb_enable_vblank,
+   .disable_vblank = psb_disable_vblank,
+   .get_vblank_counter = psb_get_vblank_counter,
 };
 
 const struct gma_clock_funcs psb_clock_funcs = {
diff --git a/drivers/gpu/drm/gma500/psb_irq.c b/drivers/gpu/drm/gma500/psb_irq.c
index 40a37e400b02..7ec031d28dc0 100644
--- a/drivers/gpu/drm/gma500/psb_irq.c
+++ b/drivers/gpu/drm/gma500/psb_irq.c
@@ -507,8 +507,10 @@ int psb_irq_disable_dpst(struct drm_device *dev)
 /*
  * It is used to enable VBLANK interrupt
  */
-int psb_enable_vblank(struct drm_device *dev, unsigned int pipe)
+int psb_enable_vblank(struct drm_crtc *crtc)
 {
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
struct drm_psb_private *dev_priv = dev->dev_private;
unsigned long irqflags;
uint32_t reg_val = 0;
@@ -546,8 +548,10 @@ int psb_enable_vblank(struct drm_device *dev, unsigned int 
pipe)
 /*
  * It is used to disable VBLANK interrupt
  */
-void psb_disable_vblank(struct drm_device *dev, unsigned int pipe)
+void psb_disable_vblank(struct drm_crtc *crtc)
 {
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
struct drm_psb_private *dev_priv = dev->dev_private;

[Freedreno] [PATCH 08/23] drm/stm: Convert to struct drm_crtc_helper_funcs.get_scanout_position()

2020-01-10 Thread Thomas Zimmermann
The callback struct drm_driver.get_scanout_position() is deprecated in
favor of struct drm_crtc_helper_funcs.get_scanout_position(). Convert stm
over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/stm/drv.c  |  1 -
 drivers/gpu/drm/stm/ltdc.c | 65 --
 drivers/gpu/drm/stm/ltdc.h |  5 ---
 3 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/stm/drv.c b/drivers/gpu/drm/stm/drv.c
index 5a9f9aca8bc2..486985604109 100644
--- a/drivers/gpu/drm/stm/drv.c
+++ b/drivers/gpu/drm/stm/drv.c
@@ -72,7 +72,6 @@ static struct drm_driver drv_driver = {
.gem_prime_vmap = drm_gem_cma_prime_vmap,
.gem_prime_vunmap = drm_gem_cma_prime_vunmap,
.gem_prime_mmap = drm_gem_cma_prime_mmap,
-   .get_scanout_position = ltdc_crtc_scanoutpos,
.get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
 };
 
diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c
index c2815e8ae1da..8b6d1a2252e3 100644
--- a/drivers/gpu/drm/stm/ltdc.c
+++ b/drivers/gpu/drm/stm/ltdc.c
@@ -636,38 +636,13 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc,
}
 }
 
-static const struct drm_crtc_helper_funcs ltdc_crtc_helper_funcs = {
-   .mode_valid = ltdc_crtc_mode_valid,
-   .mode_fixup = ltdc_crtc_mode_fixup,
-   .mode_set_nofb = ltdc_crtc_mode_set_nofb,
-   .atomic_flush = ltdc_crtc_atomic_flush,
-   .atomic_enable = ltdc_crtc_atomic_enable,
-   .atomic_disable = ltdc_crtc_atomic_disable,
-};
-
-static int ltdc_crtc_enable_vblank(struct drm_crtc *crtc)
-{
-   struct ltdc_device *ldev = crtc_to_ltdc(crtc);
-
-   DRM_DEBUG_DRIVER("\n");
-   reg_set(ldev->regs, LTDC_IER, IER_LIE);
-
-   return 0;
-}
-
-static void ltdc_crtc_disable_vblank(struct drm_crtc *crtc)
-{
-   struct ltdc_device *ldev = crtc_to_ltdc(crtc);
-
-   DRM_DEBUG_DRIVER("\n");
-   reg_clear(ldev->regs, LTDC_IER, IER_LIE);
-}
-
-bool ltdc_crtc_scanoutpos(struct drm_device *ddev, unsigned int pipe,
- bool in_vblank_irq, int *vpos, int *hpos,
- ktime_t *stime, ktime_t *etime,
- const struct drm_display_mode *mode)
+static bool ltdc_crtc_get_scanout_position(struct drm_crtc *crtc,
+  bool in_vblank_irq,
+  int *vpos, int *hpos,
+  ktime_t *stime, ktime_t *etime,
+  const struct drm_display_mode *mode)
 {
+   struct drm_device *ddev = crtc->dev;
struct ltdc_device *ldev = ddev->dev_private;
int line, vactive_start, vactive_end, vtotal;
 
@@ -710,6 +685,34 @@ bool ltdc_crtc_scanoutpos(struct drm_device *ddev, 
unsigned int pipe,
return true;
 }
 
+static const struct drm_crtc_helper_funcs ltdc_crtc_helper_funcs = {
+   .mode_valid = ltdc_crtc_mode_valid,
+   .mode_fixup = ltdc_crtc_mode_fixup,
+   .mode_set_nofb = ltdc_crtc_mode_set_nofb,
+   .atomic_flush = ltdc_crtc_atomic_flush,
+   .atomic_enable = ltdc_crtc_atomic_enable,
+   .atomic_disable = ltdc_crtc_atomic_disable,
+   .get_scanout_position = ltdc_crtc_get_scanout_position,
+};
+
+static int ltdc_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+   struct ltdc_device *ldev = crtc_to_ltdc(crtc);
+
+   DRM_DEBUG_DRIVER("\n");
+   reg_set(ldev->regs, LTDC_IER, IER_LIE);
+
+   return 0;
+}
+
+static void ltdc_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+   struct ltdc_device *ldev = crtc_to_ltdc(crtc);
+
+   DRM_DEBUG_DRIVER("\n");
+   reg_clear(ldev->regs, LTDC_IER, IER_LIE);
+}
+
 static const struct drm_crtc_funcs ltdc_crtc_funcs = {
.destroy = drm_crtc_cleanup,
.set_config = drm_atomic_helper_set_config,
diff --git a/drivers/gpu/drm/stm/ltdc.h b/drivers/gpu/drm/stm/ltdc.h
index a1ad0ae3b006..c5467d74e707 100644
--- a/drivers/gpu/drm/stm/ltdc.h
+++ b/drivers/gpu/drm/stm/ltdc.h
@@ -39,11 +39,6 @@ struct ltdc_device {
struct drm_atomic_state *suspend_state;
 };
 
-bool ltdc_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
- bool in_vblank_irq, int *vpos, int *hpos,
- ktime_t *stime, ktime_t *etime,
- const struct drm_display_mode *mode);
-
 int ltdc_load(struct drm_device *ddev);
 void ltdc_unload(struct drm_device *ddev);
 void ltdc_suspend(struct drm_device *ddev);
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 11/23] drm: Add get_vblank_timestamp() to struct drm_crtc_funcs

2020-01-10 Thread Thomas Zimmermann
The callback get_vblank_timestamp() is currently located in struct
drm_driver, but really belongs into struct drm_crtc_funcs. Add an
equivalent there. Driver will be converted in separate patches.

The default implementation is drm_calc_vbltimestamp_from_scanoutpos().
The patch adds drm_crtc_calc_vbltimestamp_from_scanoutpos(), which is
an implementation for the CRTC callback.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/drm_vblank.c | 83 +---
 include/drm/drm_crtc.h   | 41 
 include/drm/drm_modeset_helper_vtables.h |  2 +-
 include/drm/drm_vblank.h |  4 ++
 4 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index cbe8f3009df5..7cf436a4b908 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -333,7 +333,9 @@ u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
u64 vblank;
unsigned long flags;
 
-   WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) && 
!dev->driver->get_vblank_timestamp,
+   WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) &&
+ !crtc->funcs->get_vblank_timestamp &&
+ !dev->driver->get_vblank_timestamp,
  "This function requires support for accurate vblank 
timestamps.");
 
spin_lock_irqsave(>vblank_time_lock, flags);
@@ -563,6 +565,50 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 }
 EXPORT_SYMBOL(drm_calc_timestamping_constants);
 
+/**
+ * drm_crtc_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
+ * @crtc: CRTC whose vblank timestamp to retrieve
+ * @max_error: Desired maximum allowable error in timestamps (nanosecs)
+ * On return contains true maximum error of timestamp
+ * @vblank_time: Pointer to time which should receive the timestamp
+ * @in_vblank_irq:
+ * True when called from drm_crtc_handle_vblank().  Some drivers
+ * need to apply some workarounds for gpu-specific vblank irq quirks
+ * if flag is set.
+ *
+ * Implements calculation of exact vblank timestamps from given 
drm_display_mode
+ * timings and current video scanout position of a CRTC. This can be directly
+ * used as the _crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if _crtc_helper_funcs.get_scanout_position is implemented.
+ *
+ * The current implementation only handles standard video modes. For double 
scan
+ * and interlaced modes the driver is supposed to adjust the hardware mode
+ * (taken from _crtc_state.adjusted mode for atomic modeset drivers) to
+ * match the scanout position reported.
+ *
+ * Note that atomic drivers must call drm_calc_timestamping_constants() before
+ * enabling a CRTC. The atomic helpers already take care of that in
+ * drm_atomic_helper_update_legacy_modeset_state().
+ *
+ * Returns:
+ *
+ * Returns true on success, and false on failure, i.e. when no accurate
+ * timestamp could be acquired.
+ */
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+   int *max_error,
+   ktime_t *vblank_time,
+   bool in_vblank_irq)
+{
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
+
+   return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
+vblank_time,
+in_vblank_irq);
+}
+EXPORT_SYMBOL(drm_crtc_calc_vbltimestamp_from_scanoutpos);
+
 /**
  * drm_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
  * @dev: DRM device
@@ -577,8 +623,8 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  *
  * Implements calculation of exact vblank timestamps from given 
drm_display_mode
  * timings and current video scanout position of a CRTC. This can be directly
- * used as the _driver.get_vblank_timestamp implementation of a kms driver
- * if _crtc_helper_funcs.get_scanout_position is implemented.
+ * used as the _crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if _crtc_helper_funcs.get_scanout_position is implemented.
  *
  * The current implementation only handles standard video modes. For double 
scan
  * and interlaced modes the driver is supposed to adjust the hardware mode
@@ -733,15 +779,22 @@ static bool
 drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe,
  ktime_t *tvblank, bool in_vblank_irq)
 {
+   struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
bool ret = false;
 
/* Define requested maximum error on timestamps (nanoseconds). */
int max_error = (int) drm_timestamp_precision * 1000;
 
/* Query driver if possible and precision timestamping enabled. */
-   if (dev->driver->get_vblank_timestamp && (max_error > 0))
+   if 

[Freedreno] [PATCH 12/23] drm/amdgpu: Convert to CRTC VBLANK callbacks

2020-01-10 Thread Thomas Zimmermann
VBLANK callbacks in struct drm_driver are deprecated in favor of
their equivalents in struct drm_crtc_funcs. Convert amdgpu over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   |  4 
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   | 24 +++
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c|  4 
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c|  4 
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c |  4 
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c |  4 
 drivers/gpu/drm/amd/amdgpu/dce_virtual.c  |  4 
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  2 ++
 9 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 81a531b652aa..c1262ab588c9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1197,6 +1197,9 @@ int amdgpu_device_resume(struct drm_device *dev, bool 
fbcon);
 u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
 int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
 void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
+u32 amdgpu_crtc_get_vblank_counter(struct drm_crtc *crtc);
+int amdgpu_crtc_enable_vblank(struct drm_crtc *crtc);
+void amdgpu_crtc_disable_vblank(struct drm_crtc *crtc);
 long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
 unsigned long arg);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 0749285dd1c7..9baa1ddf8693 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1377,10 +1377,6 @@ static struct drm_driver kms_driver = {
.postclose = amdgpu_driver_postclose_kms,
.lastclose = amdgpu_driver_lastclose_kms,
.unload = amdgpu_driver_unload_kms,
-   .get_vblank_counter = amdgpu_get_vblank_counter_kms,
-   .enable_vblank = amdgpu_enable_vblank_kms,
-   .disable_vblank = amdgpu_disable_vblank_kms,
-   .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
.irq_handler = amdgpu_irq_handler,
.ioctls = amdgpu_ioctls_kms,
.gem_free_object_unlocked = amdgpu_gem_object_free,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 60591dbc2097..efe4671fb032 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -1174,6 +1174,14 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_device 
*dev, unsigned int pipe)
return count;
 }
 
+u32 amdgpu_crtc_get_vblank_counter(struct drm_crtc *crtc)
+{
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
+
+   return amdgpu_get_vblank_counter_kms(dev, pipe);
+}
+
 /**
  * amdgpu_enable_vblank_kms - enable vblank interrupt
  *
@@ -1191,6 +1199,14 @@ int amdgpu_enable_vblank_kms(struct drm_device *dev, 
unsigned int pipe)
return amdgpu_irq_get(adev, >crtc_irq, idx);
 }
 
+int amdgpu_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
+
+   return amdgpu_enable_vblank_kms(dev, pipe);
+}
+
 /**
  * amdgpu_disable_vblank_kms - disable vblank interrupt
  *
@@ -1207,6 +1223,14 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, 
unsigned int pipe)
amdgpu_irq_put(adev, >crtc_irq, idx);
 }
 
+void amdgpu_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
+
+   amdgpu_disable_vblank_kms(dev, pipe);
+}
+
 const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
DRM_IOCTL_DEF_DRV(AMDGPU_GEM_CREATE, amdgpu_gem_create_ioctl, 
DRM_AUTH|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(AMDGPU_CTX, amdgpu_ctx_ioctl, 
DRM_AUTH|DRM_RENDER_ALLOW),
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c 
b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index bdc1e0f036d4..8e62f46f0bfd 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -2494,6 +2494,10 @@ static const struct drm_crtc_funcs dce_v10_0_crtc_funcs 
= {
.set_config = amdgpu_display_crtc_set_config,
.destroy = dce_v10_0_crtc_destroy,
.page_flip_target = amdgpu_display_crtc_page_flip_target,
+   .get_vblank_counter = amdgpu_crtc_get_vblank_counter,
+   .enable_vblank = amdgpu_crtc_enable_vblank,
+   .disable_vblank = amdgpu_crtc_disable_vblank,
+   .get_vblank_timestamp = drm_crtc_calc_vbltimestamp_from_scanoutpos,
 };
 
 static void dce_v10_0_crtc_dpms(struct drm_crtc *crtc, int mode)
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index 0319da5f7bf9..9e37e4a78403 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ 

[Freedreno] [PATCH 09/23] drm: Remove struct drm_driver.get_scanout_position()

2020-01-10 Thread Thomas Zimmermann
All users of struct drm_driver.get_scanout_position() have been
covnerted to the respective CRTC helper function. Remove the callback
from struct drm_driver.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/drm_vblank.c | 13 ++---
 include/drm/drm_drv.h| 52 
 2 files changed, 2 insertions(+), 63 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index c12f0b333e14..b84065911d69 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -633,8 +633,7 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct 
drm_device *dev,
}
 
/* Scanout position query not supported? Should not happen. */
-   if (!dev->driver->get_scanout_position ||
-   !crtc->helper_private->get_scanout_position) {
+   if (!crtc->helper_private->get_scanout_position) {
DRM_ERROR("Called from CRTC w/o get_scanout_position()!?\n");
return false;
}
@@ -666,17 +665,9 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct 
drm_device *dev,
 * Get vertical and horizontal scanout position vpos, hpos,
 * and bounding timestamps stime, etime, pre/post query.
 */
-   if (crtc->helper_private->get_scanout_position) {
-   vbl_status =
-   crtc->helper_private->get_scanout_position(
+   vbl_status = crtc->helper_private->get_scanout_position(
crtc, in_vblank_irq, , ,
, , mode);
-   } else {
-   vbl_status =
-   dev->driver->get_scanout_position(
-   dev, pipe, in_vblank_irq, ,
-   , , , mode);
-   }
 
/* Return as no-op if scanout query unsupported or failed. */
if (!vbl_status) {
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index d0049e5786fc..b704e252f3b2 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -318,58 +318,6 @@ struct drm_driver {
 */
void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
 
-   /**
-* @get_scanout_position:
-*
-* Called by vblank timestamping code.
-*
-* Returns the current display scanout position from a crtc, and an
-* optional accurate ktime_get() timestamp of when position was
-* measured. Note that this is a helper callback which is only used if a
-* driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
-* @get_vblank_timestamp callback.
-*
-* Parameters:
-*
-* dev:
-* DRM device.
-* pipe:
-* Id of the crtc to query.
-* in_vblank_irq:
-* True when called from drm_crtc_handle_vblank().  Some drivers
-* need to apply some workarounds for gpu-specific vblank irq quirks
-* if flag is set.
-* vpos:
-* Target location for current vertical scanout position.
-* hpos:
-* Target location for current horizontal scanout position.
-* stime:
-* Target location for timestamp taken immediately before
-* scanout position query. Can be NULL to skip timestamp.
-* etime:
-* Target location for timestamp taken immediately after
-* scanout position query. Can be NULL to skip timestamp.
-* mode:
-* Current display timings.
-*
-* Returns vpos as a positive number while in active scanout area.
-* Returns vpos as a negative number inside vblank, counting the number
-* of scanlines to go until end of vblank, e.g., -1 means "one scanline
-* until start of active scanout / end of vblank."
-*
-* Returns:
-*
-* True on success, false if a reliable scanout position counter could
-* not be read out.
-*
-* This is deprecated and should not be used by new drivers.
-* Use _crtc_helper_funcs.get_scanout_position instead.
-*/
-   bool (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
- bool in_vblank_irq, int *vpos, int *hpos,
- ktime_t *stime, ktime_t *etime,
- const struct drm_display_mode *mode);
-
/**
 * @get_vblank_timestamp:
 *
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 04/23] drm/nouveau: Convert to struct drm_crtc_helper_funcs.get_scanout_position()

2020-01-10 Thread Thomas Zimmermann
The callback struct drm_driver.get_scanout_position() is deprecated in
favor of struct drm_crtc_helper_funcs.get_scanout_position(). Convert
nouveau over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   |  1 +
 drivers/gpu/drm/nouveau/dispnv50/head.c   |  1 +
 drivers/gpu/drm/nouveau/nouveau_display.c | 14 +++---
 drivers/gpu/drm/nouveau/nouveau_display.h |  2 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c |  1 -
 5 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c 
b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
index 37c50ea8f847..17e9d1c078a0 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
@@ -1258,6 +1258,7 @@ static const struct drm_crtc_helper_funcs 
nv04_crtc_helper_funcs = {
.mode_set_base = nv04_crtc_mode_set_base,
.mode_set_base_atomic = nv04_crtc_mode_set_base_atomic,
.disable = nv_crtc_disable,
+   .get_scanout_position = nouveau_display_scanoutpos,
 };
 
 static const uint32_t modeset_formats[] = {
diff --git a/drivers/gpu/drm/nouveau/dispnv50/head.c 
b/drivers/gpu/drm/nouveau/dispnv50/head.c
index c9692df2b76c..1354d19d9a18 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/head.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/head.c
@@ -403,6 +403,7 @@ nv50_head_atomic_check(struct drm_crtc *crtc, struct 
drm_crtc_state *state)
 static const struct drm_crtc_helper_funcs
 nv50_head_help = {
.atomic_check = nv50_head_atomic_check,
+   .get_scanout_position = nouveau_display_scanoutpos,
 };
 
 static void
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c 
b/drivers/gpu/drm/nouveau/nouveau_display.c
index 53f9bceaf17a..86f99dc8fcef 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -136,21 +136,13 @@ nouveau_display_scanoutpos_head(struct drm_crtc *crtc, 
int *vpos, int *hpos,
 }
 
 bool
-nouveau_display_scanoutpos(struct drm_device *dev, unsigned int pipe,
+nouveau_display_scanoutpos(struct drm_crtc *crtc,
   bool in_vblank_irq, int *vpos, int *hpos,
   ktime_t *stime, ktime_t *etime,
   const struct drm_display_mode *mode)
 {
-   struct drm_crtc *crtc;
-
-   list_for_each_entry(crtc, >mode_config.crtc_list, head) {
-   if (nouveau_crtc(crtc)->index == pipe) {
-   return nouveau_display_scanoutpos_head(crtc, vpos, hpos,
-  stime, etime);
-   }
-   }
-
-   return false;
+   return nouveau_display_scanoutpos_head(crtc, vpos, hpos,
+  stime, etime);
 }
 
 static void
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.h 
b/drivers/gpu/drm/nouveau/nouveau_display.h
index 6e8e66882e45..71e2af693f7f 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.h
+++ b/drivers/gpu/drm/nouveau/nouveau_display.h
@@ -63,7 +63,7 @@ int  nouveau_display_suspend(struct drm_device *dev, bool 
runtime);
 void nouveau_display_resume(struct drm_device *dev, bool runtime);
 int  nouveau_display_vblank_enable(struct drm_device *, unsigned int);
 void nouveau_display_vblank_disable(struct drm_device *, unsigned int);
-bool  nouveau_display_scanoutpos(struct drm_device *, unsigned int,
+bool  nouveau_display_scanoutpos(struct drm_crtc *,
 bool, int *, int *, ktime_t *,
 ktime_t *, const struct drm_display_mode *);
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c 
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 2cd83849600f..9fb38a018240 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -1123,7 +1123,6 @@ driver_stub = {
 
.enable_vblank = nouveau_display_vblank_enable,
.disable_vblank = nouveau_display_vblank_disable,
-   .get_scanout_position = nouveau_display_scanoutpos,
.get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
 
.ioctls = nouveau_ioctls,
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 14/23] drm/i915: Convert to CRTC VBLANK callbacks

2020-01-10 Thread Thomas Zimmermann
VBLANK callbacks in struct drm_driver are deprecated in favor of
their equivalents in struct drm_crtc_funcs. Convert i915 over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/i915/display/intel_display.c |  7 +++
 drivers/gpu/drm/i915/i915_drv.c  |  2 --
 drivers/gpu/drm/i915/i915_irq.c  | 13 +++--
 drivers/gpu/drm/i915/i915_irq.h  |  3 +--
 4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
b/drivers/gpu/drm/i915/display/intel_display.c
index da5266e76738..515788698298 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -16227,6 +16227,7 @@ static const struct drm_crtc_funcs bdw_crtc_funcs = {
.get_vblank_counter = g4x_get_vblank_counter,
.enable_vblank = bdw_enable_vblank,
.disable_vblank = bdw_disable_vblank,
+   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
 };
 
 static const struct drm_crtc_funcs ilk_crtc_funcs = {
@@ -16235,6 +16236,7 @@ static const struct drm_crtc_funcs ilk_crtc_funcs = {
.get_vblank_counter = g4x_get_vblank_counter,
.enable_vblank = ilk_enable_vblank,
.disable_vblank = ilk_disable_vblank,
+   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
 };
 
 static const struct drm_crtc_funcs g4x_crtc_funcs = {
@@ -16243,6 +16245,7 @@ static const struct drm_crtc_funcs g4x_crtc_funcs = {
.get_vblank_counter = g4x_get_vblank_counter,
.enable_vblank = i965_enable_vblank,
.disable_vblank = i965_disable_vblank,
+   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
 };
 
 static const struct drm_crtc_funcs i965_crtc_funcs = {
@@ -16251,6 +16254,7 @@ static const struct drm_crtc_funcs i965_crtc_funcs = {
.get_vblank_counter = i915_get_vblank_counter,
.enable_vblank = i965_enable_vblank,
.disable_vblank = i965_disable_vblank,
+   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
 };
 
 static const struct drm_crtc_funcs i915gm_crtc_funcs = {
@@ -16259,6 +16263,7 @@ static const struct drm_crtc_funcs i915gm_crtc_funcs = {
.get_vblank_counter = i915_get_vblank_counter,
.enable_vblank = i915gm_enable_vblank,
.disable_vblank = i915gm_disable_vblank,
+   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
 };
 
 static const struct drm_crtc_funcs i915_crtc_funcs = {
@@ -16267,6 +16272,7 @@ static const struct drm_crtc_funcs i915_crtc_funcs = {
.get_vblank_counter = i915_get_vblank_counter,
.enable_vblank = i8xx_enable_vblank,
.disable_vblank = i8xx_disable_vblank,
+   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
 };
 
 static const struct drm_crtc_funcs i8xx_crtc_funcs = {
@@ -16275,6 +16281,7 @@ static const struct drm_crtc_funcs i8xx_crtc_funcs = {
/* no hw vblank counter */
.enable_vblank = i8xx_enable_vblank,
.disable_vblank = i8xx_disable_vblank,
+   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
 };
 
 static struct intel_crtc *intel_crtc_alloc(void)
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 4a0a7fb85c53..30b9ba136a81 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -2769,8 +2769,6 @@ static struct drm_driver driver = {
.gem_prime_export = i915_gem_prime_export,
.gem_prime_import = i915_gem_prime_import,
 
-   .get_vblank_timestamp = i915_calc_vbltimestamp_from_scanoutpos,
-
.dumb_create = i915_gem_dumb_create,
.dumb_map_offset = i915_gem_dumb_mmap_offset,
 
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 99d0c3b0feae..dbbbdff8fa89 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -885,28 +885,21 @@ static bool i915_get_crtc_scanoutpos(struct drm_device 
*dev,
return true;
 }
 
-bool i915_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
-   unsigned int pipe,
+bool i915_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
int *max_error,
ktime_t *vblank_time,
bool in_vblank_irq)
 {
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
struct timespec64 ts_etime, ts_vblank_time;
ktime_t stime, etime;
bool vbl_status;
-   struct drm_crtc *crtc;
const struct drm_display_mode *mode;
struct drm_vblank_crtc *vblank = >vblank[pipe];
int vpos, hpos, i;
int delta_ns, duration_ns;
 
-   crtc = drm_crtc_from_index(dev, pipe);
-
-   if (pipe >= dev->num_crtcs || !crtc) {
-   DRM_ERROR("Invalid crtc %u\n", pipe);
-   return false;
-   }

[Freedreno] [PATCH 02/23] drm/amdgpu: Convert to struct drm_crtc_helper_funcs.get_scanout_position()

2020-01-10 Thread Thomas Zimmermann
The callback struct drm_driver.get_scanout_position() is deprecated in
favor of struct drm_crtc_helper_funcs.get_scanout_position(). Convert
amdgpu over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c   | 12 
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   | 11 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h  |  5 +
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c|  1 +
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c|  1 +
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c |  1 +
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c |  1 +
 drivers/gpu/drm/amd/amdgpu/dce_virtual.c  |  1 +
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  3 ++-
 9 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index 4e699071d144..a1e769d4417d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -914,3 +914,15 @@ int amdgpu_display_crtc_idx_to_irq_type(struct 
amdgpu_device *adev, int crtc)
return AMDGPU_CRTC_IRQ_NONE;
}
 }
+
+bool amdgpu_crtc_get_scanout_position(struct drm_crtc *crtc,
+   bool in_vblank_irq, int *vpos,
+   int *hpos, ktime_t *stime, ktime_t *etime,
+   const struct drm_display_mode *mode)
+{
+   struct drm_device *dev = crtc->dev;
+   unsigned int pipe = crtc->index;
+
+   return amdgpu_display_get_crtc_scanoutpos(dev, pipe, 0, vpos, hpos,
+ stime, etime, mode);
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 3f6f14ce1511..0749285dd1c7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1367,16 +1367,6 @@ int amdgpu_file_to_fpriv(struct file *filp, struct 
amdgpu_fpriv **fpriv)
return 0;
 }
 
-static bool
-amdgpu_get_crtc_scanout_position(struct drm_device *dev, unsigned int pipe,
-bool in_vblank_irq, int *vpos, int *hpos,
-ktime_t *stime, ktime_t *etime,
-const struct drm_display_mode *mode)
-{
-   return amdgpu_display_get_crtc_scanoutpos(dev, pipe, 0, vpos, hpos,
- stime, etime, mode);
-}
-
 static struct drm_driver kms_driver = {
.driver_features =
DRIVER_USE_AGP | DRIVER_ATOMIC |
@@ -1391,7 +1381,6 @@ static struct drm_driver kms_driver = {
.enable_vblank = amdgpu_enable_vblank_kms,
.disable_vblank = amdgpu_disable_vblank_kms,
.get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
-   .get_scanout_position = amdgpu_get_crtc_scanout_position,
.irq_handler = amdgpu_irq_handler,
.ioctls = amdgpu_ioctls_kms,
.gem_free_object_unlocked = amdgpu_gem_object_free,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
index eb9975f4decb..37ba07e2feb5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
@@ -612,6 +612,11 @@ void amdgpu_panel_mode_fixup(struct drm_encoder *encoder,
 struct drm_display_mode *adjusted_mode);
 int amdgpu_display_crtc_idx_to_irq_type(struct amdgpu_device *adev, int crtc);
 
+bool amdgpu_crtc_get_scanout_position(struct drm_crtc *crtc,
+   bool in_vblank_irq, int *vpos,
+   int *hpos, ktime_t *stime, ktime_t *etime,
+   const struct drm_display_mode *mode);
+
 /* fbdev layer */
 int amdgpu_fbdev_init(struct amdgpu_device *adev);
 void amdgpu_fbdev_fini(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c 
b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index 40d2ac723dd6..bdc1e0f036d4 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -2685,6 +2685,7 @@ static const struct drm_crtc_helper_funcs 
dce_v10_0_crtc_helper_funcs = {
.prepare = dce_v10_0_crtc_prepare,
.commit = dce_v10_0_crtc_commit,
.disable = dce_v10_0_crtc_disable,
+   .get_scanout_position = amdgpu_crtc_get_scanout_position,
 };
 
 static int dce_v10_0_crtc_init(struct amdgpu_device *adev, int index)
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index 898ef72d423c..0319da5f7bf9 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -2793,6 +2793,7 @@ static const struct drm_crtc_helper_funcs 
dce_v11_0_crtc_helper_funcs = {
.prepare = dce_v11_0_crtc_prepare,
.commit = dce_v11_0_crtc_commit,
.disable = dce_v11_0_crtc_disable,
+   .get_scanout_position = amdgpu_crtc_get_scanout_position,
 };
 
 static 

[Freedreno] [PATCH 01/23] drm: Add get_scanout_position() to struct drm_crtc_helper_funcs

2020-01-10 Thread Thomas Zimmermann
The new callback get_scanout_position() reads the current location of
the scanout process. The operation is currentyl located in struct
drm_driver, but really belongs to the CRTC. Drivers will be converted
in separate patches.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/drm_vblank.c | 24 
 include/drm/drm_drv.h|  7 +---
 include/drm/drm_modeset_helper_vtables.h | 47 
 3 files changed, 65 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 1659b13b178c..c12f0b333e14 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -590,7 +591,7 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  * Implements calculation of exact vblank timestamps from given 
drm_display_mode
  * timings and current video scanout position of a CRTC. This can be directly
  * used as the _driver.get_vblank_timestamp implementation of a kms driver
- * if _driver.get_scanout_position is implemented.
+ * if _crtc_helper_funcs.get_scanout_position is implemented.
  *
  * The current implementation only handles standard video modes. For double 
scan
  * and interlaced modes the driver is supposed to adjust the hardware mode
@@ -632,8 +633,9 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct 
drm_device *dev,
}
 
/* Scanout position query not supported? Should not happen. */
-   if (!dev->driver->get_scanout_position) {
-   DRM_ERROR("Called from driver w/o get_scanout_position()!?\n");
+   if (!dev->driver->get_scanout_position ||
+   !crtc->helper_private->get_scanout_position) {
+   DRM_ERROR("Called from CRTC w/o get_scanout_position()!?\n");
return false;
}
 
@@ -664,11 +666,17 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct 
drm_device *dev,
 * Get vertical and horizontal scanout position vpos, hpos,
 * and bounding timestamps stime, etime, pre/post query.
 */
-   vbl_status = dev->driver->get_scanout_position(dev, pipe,
-  in_vblank_irq,
-  , ,
-  , ,
-  mode);
+   if (crtc->helper_private->get_scanout_position) {
+   vbl_status =
+   crtc->helper_private->get_scanout_position(
+   crtc, in_vblank_irq, , ,
+   , , mode);
+   } else {
+   vbl_status =
+   dev->driver->get_scanout_position(
+   dev, pipe, in_vblank_irq, ,
+   , , , mode);
+   }
 
/* Return as no-op if scanout query unsupported or failed. */
if (!vbl_status) {
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index cf13470810a5..d0049e5786fc 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -362,11 +362,8 @@ struct drm_driver {
 * True on success, false if a reliable scanout position counter could
 * not be read out.
 *
-* FIXME:
-*
-* Since this is a helper to implement @get_vblank_timestamp, we should
-* move it to  drm_crtc_helper_funcs, like all the other
-* helper-internal hooks.
+* This is deprecated and should not be used by new drivers.
+* Use _crtc_helper_funcs.get_scanout_position instead.
 */
bool (*get_scanout_position) (struct drm_device *dev, unsigned int pipe,
  bool in_vblank_irq, int *vpos, int *hpos,
diff --git a/include/drm/drm_modeset_helper_vtables.h 
b/include/drm/drm_modeset_helper_vtables.h
index 5a87f1bd7a3f..e398512bfd5f 100644
--- a/include/drm/drm_modeset_helper_vtables.h
+++ b/include/drm/drm_modeset_helper_vtables.h
@@ -450,6 +450,53 @@ struct drm_crtc_helper_funcs {
 */
void (*atomic_disable)(struct drm_crtc *crtc,
   struct drm_crtc_state *old_crtc_state);
+
+   /**
+* @get_scanout_position:
+*
+* Called by vblank timestamping code.
+*
+* Returns the current display scanout position from a CRTC and an
+* optional accurate ktime_get() timestamp of when the position was
+* measured. Note that this is a helper callback which is only used
+* if a driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
+* @drm_driver.get_vblank_timestamp callback.
+*
+* Parameters:
+*
+* crtc:
+* The CRTC.
+

[Freedreno] [PATCH 00/23] drm: Clean up VBLANK callbacks in struct drm_driver

2020-01-10 Thread Thomas Zimmermann
VBLANK handlers in struct drm_driver are deprecated. Only legacy,
non-KMS drivers are supposed to used them. DRM drivers with kernel
modesetting are supposed to use VBLANK callbacks of the CRTC
infrastructure.

This patchset converts all DRM drivers to CRTC VBLANK callbacks and
cleans up struct drm_driver. The remaining VBLANK callbacks in struct
drm_driver are only used by legacy drivers.

Patches 1 to 9 move get_scanout_position() to struct drm_crtc_helper_funcs
and convert drivers over. The callback is a helper for the default
implementation of get_vblank_timestamp() (i.e.,
drm_calc_vbltimestamp_from_scanoutpos()). The original callback is removed
from struct drm_driver.

Patch 10 changes the VBLANK code to evaluate vblank_disable_immediate in
struct derm_device. This simplifies the later integration of CRTC VBLANK
callbacks. If necessary, a future patch could move vblank_disable_immedate
to struct drm_crtc, so that high-precision VBLANKs could be enabled on a
per-CRTC basis.

Patches 11 to 23 move get_vblank_timestamp() to struct drm_crtc_funcs
and convert DRM drivers over. All VBLANK callbacks are removed from
struct drm_driver, except for get_vblank_counter(), enable_vblank(), and
disable_vblank(). These interfaces are moved to the legacy section
at the end of the structure.

To cover all affected drivers, I build the patchset in x86, x86-64,
arm and aarch64. I smoke-tested amdgpu, gma500, i915, radeon and vc4 on
respective hardware.

Thomas Zimmermann (23):
  drm: Add get_scanout_position() to struct drm_crtc_helper_funcs
  drm/amdgpu: Convert to struct
drm_crtc_helper_funcs.get_scanout_position()
  drm/i915: Don't use struct drm_driver.get_scanout_position()
  drm/nouveau: Convert to struct
drm_crtc_helper_funcs.get_scanout_position()
  drm/radeon: Convert to struct
drm_crtc_helper_funcs.get_scanout_position()
  drm/msm: Convert to struct
drm_crtc_helper_funcs.get_scanout_position()
  drm/vc4: Convert to struct
drm_crtc_helper_funcs.get_scanout_position()
  drm/stm: Convert to struct
drm_crtc_helper_funcs.get_scanout_position()
  drm: Remove struct drm_driver.get_scanout_position()
  drm: Evaluate struct drm_device.vblank_disable_immediate on each use
  drm: Add get_vblank_timestamp() to struct drm_crtc_funcs
  drm/amdgpu: Convert to CRTC VBLANK callbacks
  drm/gma500: Convert to CRTC VBLANK callbacks
  drm/i915: Convert to CRTC VBLANK callbacks
  drm/msm: Convert to CRTC VBLANK callbacks
  drm/nouveau: Convert to CRTC VBLANK callbacks
  drm/radeon: Convert to CRTC VBLANK callbacks
  drm/sti: Convert to CRTC VBLANK callbacks
  drm/stm: Convert to CRTC VBLANK callbacks
  drm/vc4: Convert to CRTC VBLANK callbacks
  drm/vkms: Convert to CRTC VBLANK callbacks
  drm/vmwgfx: Convert to CRTC VBLANK callbacks
  drm: Cleanup VBLANK callbacks in struct drm_driver

 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c   |  12 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   |  15 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   |  24 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h  |   5 +
 drivers/gpu/drm/amd/amdgpu/dce_v10_0.c|   5 +
 drivers/gpu/drm/amd/amdgpu/dce_v11_0.c|   5 +
 drivers/gpu/drm/amd/amdgpu/dce_v6_0.c |   5 +
 drivers/gpu/drm/amd/amdgpu/dce_v8_0.c |   5 +
 drivers/gpu/drm/amd/amdgpu/dce_virtual.c  |   5 +
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   5 +-
 drivers/gpu/drm/drm_vblank.c  | 128 +-
 drivers/gpu/drm/gma500/cdv_intel_display.c|   3 +
 drivers/gpu/drm/gma500/psb_drv.c  |   4 -
 drivers/gpu/drm/gma500/psb_drv.h  |   6 +-
 drivers/gpu/drm/gma500/psb_intel_display.c|   3 +
 drivers/gpu/drm/gma500/psb_irq.c  |  12 +-
 drivers/gpu/drm/gma500/psb_irq.h  |   7 +-
 drivers/gpu/drm/i915/display/intel_display.c  |   7 +
 drivers/gpu/drm/i915/i915_drv.c   |   3 -
 drivers/gpu/drm/i915/i915_irq.c   | 110 +++-
 drivers/gpu/drm/i915/i915_irq.h   |   8 +-
 drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c  |   2 +
 drivers/gpu/drm/msm/disp/mdp4/mdp4_crtc.c |   2 +
 drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c |  82 +
 drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c  |  95 ---
 drivers/gpu/drm/msm/msm_drv.c |  10 +-
 drivers/gpu/drm/msm/msm_drv.h |   3 +
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   |   4 +
 drivers/gpu/drm/nouveau/dispnv50/head.c   |   5 +
 drivers/gpu/drm/nouveau/nouveau_display.c |  28 +---
 drivers/gpu/drm/nouveau/nouveau_display.h |   6 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c |   5 -
 drivers/gpu/drm/radeon/atombios_crtc.c|   1 +
 drivers/gpu/drm/radeon/radeon_display.c   |  25 ++-
 drivers/gpu/drm/radeon/radeon_drv.c   |  18 --
 drivers/gpu/drm/radeon/radeon_kms.c   |  29 ++--
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c   |   3 +-
 

[Freedreno] [PATCH 07/23] drm/vc4: Convert to struct drm_crtc_helper_funcs.get_scanout_position()

2020-01-10 Thread Thomas Zimmermann
The callback struct drm_driver.get_scanout_position() is deprecated in
favor of struct drm_crtc_helper_funcs.get_scanout_position(). Convert vc4
over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/vc4/vc4_crtc.c | 12 +++-
 drivers/gpu/drm/vc4/vc4_drv.c  |  1 -
 drivers/gpu/drm/vc4/vc4_drv.h  |  4 
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c
index b00e20f5ce05..f1e7597ea17e 100644
--- a/drivers/gpu/drm/vc4/vc4_crtc.c
+++ b/drivers/gpu/drm/vc4/vc4_crtc.c
@@ -84,13 +84,14 @@ static const struct debugfs_reg32 crtc_regs[] = {
VC4_REG32(PV_HACT_ACT),
 };
 
-bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
-bool in_vblank_irq, int *vpos, int *hpos,
-ktime_t *stime, ktime_t *etime,
-const struct drm_display_mode *mode)
+static bool vc4_crtc_get_scanout_position(struct drm_crtc *crtc,
+ bool in_vblank_irq,
+ int *vpos, int *hpos,
+ ktime_t *stime, ktime_t *etime,
+ const struct drm_display_mode *mode)
 {
+   struct drm_device *dev = crtc->dev;
struct vc4_dev *vc4 = to_vc4_dev(dev);
-   struct drm_crtc *crtc = drm_crtc_from_index(dev, crtc_id);
struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
u32 val;
int fifo_lines;
@@ -1039,6 +1040,7 @@ static const struct drm_crtc_helper_funcs 
vc4_crtc_helper_funcs = {
.atomic_flush = vc4_crtc_atomic_flush,
.atomic_enable = vc4_crtc_atomic_enable,
.atomic_disable = vc4_crtc_atomic_disable,
+   .get_scanout_position = vc4_crtc_get_scanout_position,
 };
 
 static const struct vc4_crtc_data pv0_data = {
diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index 5e6fb6c2307f..e6982a7b0c5e 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -190,7 +190,6 @@ static struct drm_driver vc4_drm_driver = {
.irq_postinstall = vc4_irq_postinstall,
.irq_uninstall = vc4_irq_uninstall,
 
-   .get_scanout_position = vc4_crtc_get_scanoutpos,
.get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
 
 #if defined(CONFIG_DEBUG_FS)
diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
index 6627b20c99e9..f90c0d08e740 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.h
+++ b/drivers/gpu/drm/vc4/vc4_drv.h
@@ -743,10 +743,6 @@ void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
 
 /* vc4_crtc.c */
 extern struct platform_driver vc4_crtc_driver;
-bool vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
-bool in_vblank_irq, int *vpos, int *hpos,
-ktime_t *stime, ktime_t *etime,
-const struct drm_display_mode *mode);
 void vc4_crtc_handle_vblank(struct vc4_crtc *crtc);
 void vc4_crtc_txp_armed(struct drm_crtc_state *state);
 void vc4_crtc_get_margins(struct drm_crtc_state *state,
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 10/23] drm: Evaluate struct drm_device.vblank_disable_immediate on each use

2020-01-10 Thread Thomas Zimmermann
VBLANK interrupts can be disabled immediately or with a delay, where the
latter is the default. The former option can be selected by setting
get_vblank_timestamp, and enabling vblank_disable_immediate in struct
drm_device.

The setup is only evaluated once when DRM initializes VBLANKs. Evaluating
the settings on each use of vblank_disable_immediate will allow for easy
integration of CRTC VBLANK functions.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/drm_vblank.c | 31 ++-
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index b84065911d69..cbe8f3009df5 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -481,19 +481,6 @@ int drm_vblank_init(struct drm_device *dev, unsigned int 
num_crtcs)
 
DRM_INFO("Supports vblank timestamp caching Rev 2 (21.10.2013).\n");
 
-   /* Driver specific high-precision vblank timestamping supported? */
-   if (dev->driver->get_vblank_timestamp)
-   DRM_INFO("Driver supports precise vblank timestamp query.\n");
-   else
-   DRM_INFO("No driver support for vblank timestamp query.\n");
-
-   /* Must have precise timestamping for reliable vblank instant disable */
-   if (dev->vblank_disable_immediate && 
!dev->driver->get_vblank_timestamp) {
-   dev->vblank_disable_immediate = false;
-   DRM_INFO("Setting vblank_disable_immediate to false because "
-"get_vblank_timestamp == NULL\n");
-   }
-
return 0;
 
 err:
@@ -1061,6 +1048,15 @@ int drm_crtc_vblank_get(struct drm_crtc *crtc)
 }
 EXPORT_SYMBOL(drm_crtc_vblank_get);
 
+static bool __vblank_disable_immediate(struct drm_device *dev, unsigned int 
pipe)
+{
+   if (!dev->vblank_disable_immediate)
+   return false;
+   if (!dev->driver->get_vblank_timestamp)
+   return false;
+   return true;
+}
+
 static void drm_vblank_put(struct drm_device *dev, unsigned int pipe)
 {
struct drm_vblank_crtc *vblank = >vblank[pipe];
@@ -1077,7 +1073,7 @@ static void drm_vblank_put(struct drm_device *dev, 
unsigned int pipe)
return;
else if (drm_vblank_offdelay < 0)
vblank_disable_fn(>disable_timer);
-   else if (!dev->vblank_disable_immediate)
+   else if (__vblank_disable_immediate(dev, pipe))
mod_timer(>disable_timer,
  jiffies + ((drm_vblank_offdelay * HZ)/1000));
}
@@ -1654,7 +1650,7 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void 
*data,
/* If the counter is currently enabled and accurate, short-circuit
 * queries to return the cached timestamp of the last vblank.
 */
-   if (dev->vblank_disable_immediate &&
+   if (__vblank_disable_immediate(dev, pipe) &&
drm_wait_vblank_is_query(vblwait) &&
READ_ONCE(vblank->enabled)) {
drm_wait_vblank_reply(dev, pipe, >reply);
@@ -1811,7 +1807,7 @@ bool drm_handle_vblank(struct drm_device *dev, unsigned 
int pipe)
 * been signaled. The disable has to be last (after
 * drm_handle_vblank_events) so that the timestamp is always accurate.
 */
-   disable_irq = (dev->vblank_disable_immediate &&
+   disable_irq = (__vblank_disable_immediate(dev, pipe) &&
   drm_vblank_offdelay > 0 &&
   !atomic_read(>refcount));
 
@@ -1884,7 +1880,8 @@ int drm_crtc_get_sequence_ioctl(struct drm_device *dev, 
void *data,
pipe = drm_crtc_index(crtc);
 
vblank = >vblank[pipe];
-   vblank_enabled = dev->vblank_disable_immediate && 
READ_ONCE(vblank->enabled);
+   vblank_enabled = __vblank_disable_immediate(dev, pipe) &&
+READ_ONCE(vblank->enabled);
 
if (!vblank_enabled) {
ret = drm_crtc_vblank_get(crtc);
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 16/23] drm/nouveau: Convert to CRTC VBLANK callbacks

2020-01-10 Thread Thomas Zimmermann
VBLANK callbacks in struct drm_driver are deprecated in favor of
their equivalents in struct drm_crtc_funcs. Convert nouvean over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   |  3 +++
 drivers/gpu/drm/nouveau/dispnv50/head.c   |  4 
 drivers/gpu/drm/nouveau/nouveau_display.c | 14 ++
 drivers/gpu/drm/nouveau/nouveau_display.h |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_drm.c |  4 
 5 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c 
b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
index 17e9d1c078a0..4a4122a1c057 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
@@ -1248,6 +1248,9 @@ static const struct drm_crtc_funcs nv04_crtc_funcs = {
.set_config = drm_crtc_helper_set_config,
.page_flip = nv04_crtc_page_flip,
.destroy = nv_crtc_destroy,
+   .enable_vblank = nouveau_display_vblank_enable,
+   .disable_vblank = nouveau_display_vblank_disable,
+   .get_vblank_timestamp = drm_crtc_calc_vbltimestamp_from_scanoutpos,
 };
 
 static const struct drm_crtc_helper_funcs nv04_crtc_helper_funcs = {
diff --git a/drivers/gpu/drm/nouveau/dispnv50/head.c 
b/drivers/gpu/drm/nouveau/dispnv50/head.c
index 1354d19d9a18..a6b7416ca270 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/head.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/head.c
@@ -29,6 +29,7 @@
 
 #include 
 #include 
+#include 
 #include "nouveau_connector.h"
 void
 nv50_head_flush_clr(struct nv50_head *head,
@@ -472,6 +473,9 @@ nv50_head_func = {
.page_flip = drm_atomic_helper_page_flip,
.atomic_duplicate_state = nv50_head_atomic_duplicate_state,
.atomic_destroy_state = nv50_head_atomic_destroy_state,
+   .enable_vblank = nouveau_display_vblank_enable,
+   .disable_vblank = nouveau_display_vblank_disable,
+   .get_vblank_timestamp = drm_crtc_calc_vbltimestamp_from_scanoutpos,
 };
 
 int
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c 
b/drivers/gpu/drm/nouveau/nouveau_display.c
index 86f99dc8fcef..700817dc4fa0 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -54,15 +54,10 @@ nouveau_display_vblank_handler(struct nvif_notify *notify)
 }
 
 int
-nouveau_display_vblank_enable(struct drm_device *dev, unsigned int pipe)
+nouveau_display_vblank_enable(struct drm_crtc *crtc)
 {
-   struct drm_crtc *crtc;
struct nouveau_crtc *nv_crtc;
 
-   crtc = drm_crtc_from_index(dev, pipe);
-   if (!crtc)
-   return -EINVAL;
-
nv_crtc = nouveau_crtc(crtc);
nvif_notify_get(_crtc->vblank);
 
@@ -70,15 +65,10 @@ nouveau_display_vblank_enable(struct drm_device *dev, 
unsigned int pipe)
 }
 
 void
-nouveau_display_vblank_disable(struct drm_device *dev, unsigned int pipe)
+nouveau_display_vblank_disable(struct drm_crtc *crtc)
 {
-   struct drm_crtc *crtc;
struct nouveau_crtc *nv_crtc;
 
-   crtc = drm_crtc_from_index(dev, pipe);
-   if (!crtc)
-   return;
-
nv_crtc = nouveau_crtc(crtc);
nvif_notify_put(_crtc->vblank);
 }
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.h 
b/drivers/gpu/drm/nouveau/nouveau_display.h
index 71e2af693f7f..71c7048948f3 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.h
+++ b/drivers/gpu/drm/nouveau/nouveau_display.h
@@ -61,8 +61,8 @@ int  nouveau_display_init(struct drm_device *dev, bool 
resume, bool runtime);
 void nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime);
 int  nouveau_display_suspend(struct drm_device *dev, bool runtime);
 void nouveau_display_resume(struct drm_device *dev, bool runtime);
-int  nouveau_display_vblank_enable(struct drm_device *, unsigned int);
-void nouveau_display_vblank_disable(struct drm_device *, unsigned int);
+int  nouveau_display_vblank_enable(struct drm_crtc *);
+void nouveau_display_vblank_disable(struct drm_crtc *);
 bool  nouveau_display_scanoutpos(struct drm_crtc *,
 bool, int *, int *, ktime_t *,
 ktime_t *, const struct drm_display_mode *);
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c 
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 9fb38a018240..0003343014ce 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -1121,10 +1121,6 @@ driver_stub = {
.debugfs_init = nouveau_drm_debugfs_init,
 #endif
 
-   .enable_vblank = nouveau_display_vblank_enable,
-   .disable_vblank = nouveau_display_vblank_disable,
-   .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
-
.ioctls = nouveau_ioctls,
.num_ioctls = ARRAY_SIZE(nouveau_ioctls),
.fops = _driver_fops,
-- 
2.24.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 06/23] drm/msm: Convert to struct drm_crtc_helper_funcs.get_scanout_position()

2020-01-10 Thread Thomas Zimmermann
The callback struct drm_driver.get_scanout_position() is deprecated in
favor of struct drm_crtc_helper_funcs.get_scanout_position(). Convert
mem over.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c | 67 +++
 drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c  | 61 -
 2 files changed, 67 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c 
b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
index 05cc04f729d6..4decf19847a8 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
@@ -405,6 +405,72 @@ static void mdp5_crtc_mode_set_nofb(struct drm_crtc *crtc)
spin_unlock_irqrestore(_crtc->lm_lock, flags);
 }
 
+static struct drm_encoder *get_encoder_from_crtc(struct drm_crtc *crtc)
+{
+   struct drm_device *dev = crtc->dev;
+   struct drm_encoder *encoder;
+
+   drm_for_each_encoder(encoder, dev)
+   if (encoder->crtc == crtc)
+   return encoder;
+
+   return NULL;
+}
+
+static bool mdp5_crtc_get_scanout_position(struct drm_crtc *crtc,
+  bool in_vblank_irq,
+  int *vpos, int *hpos,
+  ktime_t *stime, ktime_t *etime,
+  const struct drm_display_mode *mode)
+{
+   unsigned int pipe = crtc->index;
+   struct drm_encoder *encoder;
+   int line, vsw, vbp, vactive_start, vactive_end, vfp_end;
+
+
+   encoder = get_encoder_from_crtc(crtc);
+   if (!encoder) {
+   DRM_ERROR("no encoder found for crtc %d\n", pipe);
+   return false;
+   }
+
+   vsw = mode->crtc_vsync_end - mode->crtc_vsync_start;
+   vbp = mode->crtc_vtotal - mode->crtc_vsync_end;
+
+   /*
+* the line counter is 1 at the start of the VSYNC pulse and VTOTAL at
+* the end of VFP. Translate the porch values relative to the line
+* counter positions.
+*/
+
+   vactive_start = vsw + vbp + 1;
+
+   vactive_end = vactive_start + mode->crtc_vdisplay;
+
+   /* last scan line before VSYNC */
+   vfp_end = mode->crtc_vtotal;
+
+   if (stime)
+   *stime = ktime_get();
+
+   line = mdp5_encoder_get_linecount(encoder);
+
+   if (line < vactive_start)
+   line -= vactive_start;
+   else if (line > vactive_end)
+   line = line - vfp_end - vactive_start;
+   else
+   line -= vactive_start;
+
+   *vpos = line;
+   *hpos = 0;
+
+   if (etime)
+   *etime = ktime_get();
+
+   return true;
+}
+
 static void mdp5_crtc_atomic_disable(struct drm_crtc *crtc,
 struct drm_crtc_state *old_state)
 {
@@ -1063,6 +1129,7 @@ static const struct drm_crtc_helper_funcs 
mdp5_crtc_helper_funcs = {
.atomic_flush = mdp5_crtc_atomic_flush,
.atomic_enable = mdp5_crtc_atomic_enable,
.atomic_disable = mdp5_crtc_atomic_disable,
+   .get_scanout_position = mdp5_crtc_get_scanout_position,
 };
 
 static void mdp5_crtc_vblank_irq(struct mdp_irq *irq, uint32_t irqstatus)
diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c 
b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
index e43ecd4be10a..8b72ac44ce55 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
@@ -595,66 +595,6 @@ static struct drm_encoder *get_encoder_from_crtc(struct 
drm_crtc *crtc)
return NULL;
 }
 
-static bool mdp5_get_scanoutpos(struct drm_device *dev, unsigned int pipe,
-   bool in_vblank_irq, int *vpos, int *hpos,
-   ktime_t *stime, ktime_t *etime,
-   const struct drm_display_mode *mode)
-{
-   struct msm_drm_private *priv = dev->dev_private;
-   struct drm_crtc *crtc;
-   struct drm_encoder *encoder;
-   int line, vsw, vbp, vactive_start, vactive_end, vfp_end;
-
-   crtc = priv->crtcs[pipe];
-   if (!crtc) {
-   DRM_ERROR("Invalid crtc %d\n", pipe);
-   return false;
-   }
-
-   encoder = get_encoder_from_crtc(crtc);
-   if (!encoder) {
-   DRM_ERROR("no encoder found for crtc %d\n", pipe);
-   return false;
-   }
-
-   vsw = mode->crtc_vsync_end - mode->crtc_vsync_start;
-   vbp = mode->crtc_vtotal - mode->crtc_vsync_end;
-
-   /*
-* the line counter is 1 at the start of the VSYNC pulse and VTOTAL at
-* the end of VFP. Translate the porch values relative to the line
-* counter positions.
-*/
-
-   vactive_start = vsw + vbp + 1;
-
-   vactive_end = vactive_start + mode->crtc_vdisplay;
-
-   /* last scan line before VSYNC */
-   vfp_end = mode->crtc_vtotal;
-
-   if (stime)
-   *stime = ktime_get();
-
-   line =