Re: [Intel-gfx] [PATCH 06/19] drm/vmwgfx: Drop the cursor locking hack

2017-03-22 Thread Thomas Hellstrom
On 03/22/2017 10:50 PM, Daniel Vetter wrote:
> It's been around forever, no one bothered to address the FIXME, so I
> presume it's all fine.
>
> Cc: Sinclair Yeh 
> Cc: Thomas Hellstrom 
> Signed-off-by: Daniel Vetter 

NAK. We need to properly address this. Probably as part of the atomic
update.
/Thomas



> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 25 -
>  1 file changed, 25 deletions(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
> b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index d492d57d5309..424b3fc57203 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -148,15 +148,6 @@ int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, 
> struct drm_file *file_priv,
>   s32 hotspot_x, hotspot_y;
>   int ret;
>  
> - /*
> -  * FIXME: Unclear whether there's any global state touched by the
> -  * cursor_set function, especially vmw_cursor_update_position looks
> -  * suspicious. For now take the easy route and reacquire all locks. We
> -  * can do this since the caller in the drm core doesn't check anything
> -  * which is protected by any looks.
> -  */
> - drm_modeset_unlock_crtc(crtc);
> - drm_modeset_lock_all(dev_priv->dev);
>   hotspot_x = hot_x + du->hotspot_x;
>   hotspot_y = hot_y + du->hotspot_y;
>  
> @@ -224,9 +215,6 @@ int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct 
> drm_file *file_priv,
>   }
>  
>  out:
> - drm_modeset_unlock_all(dev_priv->dev);
> - drm_modeset_lock_crtc(crtc, crtc->cursor);
> -
>   return ret;
>  }
>  
> @@ -239,25 +227,12 @@ int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int 
> x, int y)
>   du->cursor_x = x + du->set_gui_x;
>   du->cursor_y = y + du->set_gui_y;
>  
> - /*
> -  * FIXME: Unclear whether there's any global state touched by the
> -  * cursor_set function, especially vmw_cursor_update_position looks
> -  * suspicious. For now take the easy route and reacquire all locks. We
> -  * can do this since the caller in the drm core doesn't check anything
> -  * which is protected by any looks.
> -  */
> - drm_modeset_unlock_crtc(crtc);
> - drm_modeset_lock_all(dev_priv->dev);
> -
>   vmw_cursor_update_position(dev_priv, shown,
>  du->cursor_x + du->hotspot_x +
>  du->core_hotspot_x,
>  du->cursor_y + du->hotspot_y +
>  du->core_hotspot_y);
>  
> - drm_modeset_unlock_all(dev_priv->dev);
> - drm_modeset_lock_crtc(crtc, crtc->cursor);
> -
>   return 0;
>  }
>  


___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v3] drm/i915/scheduler: add gvt notification for guc submission

2017-03-22 Thread Dong, Chuanxiao
Ping for review. GVT relies on the notification before a request submitted and 
after a request completed, just like when using execlist mode submission.

> -Original Message-
> From: Dong, Chuanxiao
> Sent: Wednesday, March 22, 2017 2:35 PM
> To: intel-gfx@lists.freedesktop.org
> Cc: intel-gvt-...@lists.freedesktop.org; Dong, Chuanxiao
> ; Zheng, Xiao ; Tian,
> Kevin 
> Subject: [PATCH v3] drm/i915/scheduler: add gvt notification for guc
> submission
> 
> GVT request needs a manual mmio load/restore. Before GuC submit a
> request, send notification to gvt for mmio loading. And after the GuC
> finished this GVT request, notify gvt again for mmio restore. This follows the
> usage when using execlists submission.
> 
> v2: use context_status_change instead of execlists_context_status_change
> for better understanding (ZhengXiao)
> v3: remove the comment as it is obvious and not friendly to
> the caller (Kevin)
> 
> Cc: xiao.zh...@intel.com
> Cc: kevin.t...@intel.com
> Signed-off-by: Chuanxiao Dong 
> ---
>  drivers/gpu/drm/i915/i915_guc_submission.c |  3 +++
>  drivers/gpu/drm/i915/intel_lrc.c   | 21 +++--
>  drivers/gpu/drm/i915/intel_lrc.h   | 13 +
>  3 files changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c
> b/drivers/gpu/drm/i915/i915_guc_submission.c
> index 055467a..0195547 100644
> --- a/drivers/gpu/drm/i915/i915_guc_submission.c
> +++ b/drivers/gpu/drm/i915/i915_guc_submission.c
> @@ -520,6 +520,8 @@ static void __i915_guc_submit(struct
> drm_i915_gem_request *rq)
>   unsigned long flags;
>   int b_ret;
> 
> + context_status_change(rq, INTEL_CONTEXT_SCHEDULE_IN);
> +
>   /* WA to flush out the pending GMADR writes to ring buffer. */
>   if (i915_vma_is_map_and_fenceable(rq->ring->vma))
>   POSTING_READ_FW(GUC_STATUS);
> @@ -634,6 +636,7 @@ static void i915_guc_irq_handler(unsigned long data)
>   rq = port[0].request;
>   while (rq && i915_gem_request_completed(rq)) {
>   trace_i915_gem_request_out(rq);
> + context_status_change(rq,
> INTEL_CONTEXT_SCHEDULE_OUT);
>   i915_gem_request_put(rq);
>   port[0].request = port[1].request;
>   port[1].request = NULL;
> diff --git a/drivers/gpu/drm/i915/intel_lrc.c
> b/drivers/gpu/drm/i915/intel_lrc.c
> index eec1e71..24c69b5 100644
> --- a/drivers/gpu/drm/i915/intel_lrc.c
> +++ b/drivers/gpu/drm/i915/intel_lrc.c
> @@ -295,21 +295,6 @@ uint64_t intel_lr_context_descriptor(struct
> i915_gem_context *ctx,
>   return ctx->engine[engine->id].lrc_desc;  }
> 
> -static inline void
> -execlists_context_status_change(struct drm_i915_gem_request *rq,
> - unsigned long status)
> -{
> - /*
> -  * Only used when GVT-g is enabled now. When GVT-g is disabled,
> -  * The compiler should eliminate this function as dead-code.
> -  */
> - if (!IS_ENABLED(CONFIG_DRM_I915_GVT))
> - return;
> -
> - atomic_notifier_call_chain(&rq->engine->context_status_notifier,
> -status, rq);
> -}
> -
>  static void
>  execlists_update_context_pdps(struct i915_hw_ppgtt *ppgtt, u32
> *reg_state)  { @@ -350,7 +335,7 @@ static void
> execlists_submit_ports(struct intel_engine_cs *engine)
> 
>   GEM_BUG_ON(port[0].count > 1);
>   if (!port[0].count)
> - execlists_context_status_change(port[0].request,
> + context_status_change(port[0].request,
> 
>   INTEL_CONTEXT_SCHEDULE_IN);
>   desc[0] = execlists_update_context(port[0].request);
>   GEM_DEBUG_EXEC(port[0].context_id = upper_32_bits(desc[0]));
> @@ -358,7 +343,7 @@ static void execlists_submit_ports(struct
> intel_engine_cs *engine)
> 
>   if (port[1].request) {
>   GEM_BUG_ON(port[1].count);
> - execlists_context_status_change(port[1].request,
> + context_status_change(port[1].request,
> 
>   INTEL_CONTEXT_SCHEDULE_IN);
>   desc[1] = execlists_update_context(port[1].request);
>   GEM_DEBUG_EXEC(port[1].context_id =
> upper_32_bits(desc[1])); @@ -581,7 +566,7 @@ static void
> intel_lrc_irq_handler(unsigned long data)
>   if (--port[0].count == 0) {
>   GEM_BUG_ON(status &
> GEN8_CTX_STATUS_PREEMPTED);
> 
>   GEM_BUG_ON(!i915_gem_request_completed(port[0].request));
> -
>   execlists_context_status_change(port[0].request,
> + context_status_change(port[0].request,
> 
>   INTEL_CONTEXT_SCHEDULE_OUT);
> 
> 
>   trace_i915_gem_request_out(port[0].request);
> diff --git a/drivers/gpu/drm/i915/intel_lrc.h
> b/drivers/gpu/drm/i915/intel_lrc.h
> index e8015e7..51e1be9 100644
> --- a/drivers/gpu/drm/i915/intel_lrc.h
> +++ b/drivers/gpu/drm/i915/intel_lrc.h
> @@ -87,5 +87,18 @@ uint64_t intel_

Re: [Intel-gfx] [PATCH v7 05/21] drm/i915/slpc: Sanitize GuC version

2017-03-22 Thread Kamble, Sagar A

Thanks Joonas, Michal. Will update this patch.

On 3/22/2017 9:00 PM, Joonas Lahtinen wrote:

On ke, 2017-03-22 at 16:18 +0100, Michal Wajdeczko wrote:

On Wed, Mar 22, 2017 at 03:33:38PM +0530, Sagar Arun Kamble wrote:

@@ -130,6 +130,8 @@ struct intel_uc_fw {
uint32_t ucode_offset;
  };
  
+#define FIRMWARE_URL  "https://01.org/linuxgraphics/intel-linux-gr

aphics-firmwares"

Is it ok that we use such generic macro name without any intel/i915
prefix?

Definitely not, this is result of moving from .c to .h. Need to add
I915_ prefix.

Regards, Joonas


___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v2] drm: Refactor vblank sequence number comparison

2017-03-22 Thread Michel Dänzer
On 22/03/17 07:06 PM, Chris Wilson wrote:
> Move the repeated (a - b) <= (1 << 23) to its own function.
> 
> v2: Catch the '1<<23' inside drm_handle_vblank() as well
> 
> Signed-off-by: Chris Wilson 

Reviewed-by: Michel Dänzer 


-- 
Earthling Michel Dänzer   |   http://www.amd.com
Libre software enthusiast | Mesa and X developer
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915: Reduce Data Link N value for 1 lane DP->hdmi converters

2017-03-22 Thread Manasi Navare
On Wed, Mar 22, 2017 at 04:27:36PM -0700, clinton.a.tay...@intel.com wrote:
> From: Clint Taylor 
> 
> Several major vendor USB-C->HDMI converters fail to recover a 5.4 GHz 1 lane
> signal if the Data Link N is greater than 0x8.
> Patch detects when 1 lane 5.4 GHz signal is being used and makes the maximum
> value 20 bit instead of the maximum specification supported 24 bit value.
> 
> Cc: Jani Nikula 
> Cc: Anusha Srivatsa 
> 
> Signed-off-by: Clint Taylor 
> ---
>  drivers/gpu/drm/i915/i915_reg.h  |2 ++
>  drivers/gpu/drm/i915/intel_display.c |   15 +++
>  2 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
> index 04c8f69..838d8d5 100644
> --- a/drivers/gpu/drm/i915/i915_reg.h
> +++ b/drivers/gpu/drm/i915/i915_reg.h
> @@ -4869,6 +4869,8 @@ enum {
>  
>  #define  DATA_LINK_M_N_MASK  (0xff)
>  #define  DATA_LINK_N_MAX (0x80)
> +/* Maximum N value useable on some DP->HDMI converters */
> +#define  DATA_LINK_REDUCED_N_MAX (0x8)
>  
>  #define _PIPEA_DATA_N_G4X0x70054
>  #define _PIPEB_DATA_N_G4X0x71054
> diff --git a/drivers/gpu/drm/i915/intel_display.c 
> b/drivers/gpu/drm/i915/intel_display.c
> index 010e5dd..6e1fdd2 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -6315,9 +6315,10 @@ static int intel_crtc_compute_config(struct intel_crtc 
> *crtc,
>  }
>  
>  static void compute_m_n(unsigned int m, unsigned int n,
> - uint32_t *ret_m, uint32_t *ret_n)
> + uint32_t *ret_m, uint32_t *ret_n,
> + uint32_t max_link_n)
>  {
> - *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
> + *ret_n = min_t(unsigned int, roundup_pow_of_two(n), max_link_n);
>   *ret_m = div_u64((uint64_t) m * *ret_n, n);
>   intel_reduce_m_n_ratio(ret_m, ret_n);
>  }
> @@ -6327,14 +6328,20 @@ static void compute_m_n(unsigned int m, unsigned int 
> n,
>  int pixel_clock, int link_clock,
>  struct intel_link_m_n *m_n)
>  {
> + uint32_t max_link_n = DATA_LINK_N_MAX;
>   m_n->tu = 64;
>  
> + if ((nlanes==1) && (link_clock >= 54))
> + max_link_n = DATA_LINK_REDUCED_N_MAX;
> +

Is this very specific to 1 lane 5.4Gbps configuration or you think
this will be needed for higher rates and 1 lane?

If not why dont we make it very specific link_clock ==54?

Regards
Manasi


>   compute_m_n(bits_per_pixel * pixel_clock,
>   link_clock * nlanes * 8,
> - &m_n->gmch_m, &m_n->gmch_n);
> + &m_n->gmch_m, &m_n->gmch_n,
> + max_link_n);
>  
>   compute_m_n(pixel_clock, link_clock,
> - &m_n->link_m, &m_n->link_n);
> + &m_n->link_m, &m_n->link_n,
> + max_link_n);
>  }
>  
>  static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
> -- 
> 1.7.9.5
> 
> ___
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915: Reduce Data Link N value for 1 lane DP->hdmi converters

2017-03-22 Thread Srivatsa, Anusha


>-Original Message-
>From: Taylor, Clinton A
>Sent: Wednesday, March 22, 2017 4:28 PM
>To: Intel-gfx@lists.freedesktop.org
>Cc: Taylor, Clinton A ; Nikula, Jani
>; Srivatsa, Anusha 
>Subject: [PATCH] drm/i915: Reduce Data Link N value for 1 lane DP->hdmi
>converters
>
>From: Clint Taylor 
>
>Several major vendor USB-C->HDMI converters fail to recover a 5.4 GHz 1 lane
>signal if the Data Link N is greater than 0x8.
>Patch detects when 1 lane 5.4 GHz signal is being used and makes the maximum
>value 20 bit instead of the maximum specification supported 24 bit value.

Reviewed-by: Anusha Srivatsa 
>Cc: Jani Nikula 
>Cc: Anusha Srivatsa 
>
>Signed-off-by: Clint Taylor 
>---
> drivers/gpu/drm/i915/i915_reg.h  |2 ++
> drivers/gpu/drm/i915/intel_display.c |   15 +++
> 2 files changed, 13 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
>index 04c8f69..838d8d5 100644
>--- a/drivers/gpu/drm/i915/i915_reg.h
>+++ b/drivers/gpu/drm/i915/i915_reg.h
>@@ -4869,6 +4869,8 @@ enum {
>
> #define  DATA_LINK_M_N_MASK   (0xff)
> #define  DATA_LINK_N_MAX  (0x80)
>+/* Maximum N value useable on some DP->HDMI converters */ #define
>+DATA_LINK_REDUCED_N_MAX (0x8)
>
> #define _PIPEA_DATA_N_G4X 0x70054
> #define _PIPEB_DATA_N_G4X 0x71054
>diff --git a/drivers/gpu/drm/i915/intel_display.c
>b/drivers/gpu/drm/i915/intel_display.c
>index 010e5dd..6e1fdd2 100644
>--- a/drivers/gpu/drm/i915/intel_display.c
>+++ b/drivers/gpu/drm/i915/intel_display.c
>@@ -6315,9 +6315,10 @@ static int intel_crtc_compute_config(struct intel_crtc
>*crtc,  }
>
> static void compute_m_n(unsigned int m, unsigned int n,
>-  uint32_t *ret_m, uint32_t *ret_n)
>+  uint32_t *ret_m, uint32_t *ret_n,
>+  uint32_t max_link_n)
> {
>-  *ret_n = min_t(unsigned int, roundup_pow_of_two(n),
>DATA_LINK_N_MAX);
>+  *ret_n = min_t(unsigned int, roundup_pow_of_two(n), max_link_n);
>   *ret_m = div_u64((uint64_t) m * *ret_n, n);
>   intel_reduce_m_n_ratio(ret_m, ret_n);
> }
>@@ -6327,14 +6328,20 @@ static void compute_m_n(unsigned int m, unsigned
>int n,
>  int pixel_clock, int link_clock,
>  struct intel_link_m_n *m_n)
> {
>+  uint32_t max_link_n = DATA_LINK_N_MAX;
>   m_n->tu = 64;
>
>+  if ((nlanes==1) && (link_clock >= 54))
>+  max_link_n = DATA_LINK_REDUCED_N_MAX;
>+
>   compute_m_n(bits_per_pixel * pixel_clock,
>   link_clock * nlanes * 8,
>-  &m_n->gmch_m, &m_n->gmch_n);
>+  &m_n->gmch_m, &m_n->gmch_n,
>+  max_link_n);
>
>   compute_m_n(pixel_clock, link_clock,
>-  &m_n->link_m, &m_n->link_n);
>+  &m_n->link_m, &m_n->link_n,
>+  max_link_n);
> }
>
> static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
>--
>1.7.9.5

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v3 10/13] drm/i915/guc: Refactor the concept "GuC context descriptor" into "GuC stage descriptor"

2017-03-22 Thread Oscar Mateo
A GuC context and a HW context are in no way related, so the name "GuC context 
descriptor"
is very unfortunate, because a new reader of the code gets overwhelmed very 
quickly with
a lot of things called "context" that refer to different things. We can improve 
legibility
a lot by simply renaming a few objects in the GuC code.

v2:
  - Rebased
  - s/ctx_desc_pool/stage_desc_pool
  - Move some explanations to the definition of the guc_stage_desc struct 
(Chris)

v3:
  - Calculate gemsize with less intermediate steps (Joonas)
  - Use BIT() macro (Joonas)

Cc: Chris Wilson 
Cc: Daniele Ceraolo Spurio 
Signed-off-by: Oscar Mateo 
Reviewed-by: Joonas Lahtinen 
---
 drivers/gpu/drm/i915/i915_debugfs.c|   4 +-
 drivers/gpu/drm/i915/i915_guc_submission.c | 118 +++--
 drivers/gpu/drm/i915/intel_guc_fwif.h  |  48 +++-
 drivers/gpu/drm/i915/intel_guc_loader.c|   4 +-
 drivers/gpu/drm/i915/intel_uc.h|   8 +-
 5 files changed, 96 insertions(+), 86 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c 
b/drivers/gpu/drm/i915/i915_debugfs.c
index 061f8a5..29eefe2 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -2474,8 +2474,8 @@ static void i915_guc_client_info(struct seq_file *m,
enum intel_engine_id id;
uint64_t tot = 0;
 
-   seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
-   client->priority, client->ctx_index, client->proc_desc_offset);
+   seq_printf(m, "\tPriority %d, GuC stage index: %u, PD offset 0x%x\n",
+   client->priority, client->stage_id, client->proc_desc_offset);
seq_printf(m, "\tDoorbell id %d, offset: 0x%lx, cookie 0x%x\n",
client->doorbell_id, client->doorbell_offset, 
client->doorbell_cookie);
seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index c9d324f..735dcba 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -37,16 +37,16 @@
  * descriptor and a workqueue (all of them inside a single gem object that
  * contains all required pages for these elements).
  *
- * GuC context descriptor:
+ * GuC stage descriptor:
  * During initialization, the driver allocates a static pool of 1024 such
  * descriptors, and shares them with the GuC.
  * Currently, there exists a 1:1 mapping between a i915_guc_client and a
- * guc_context_desc (via the client's context_index), so effectively only
- * one guc_context_desc gets used. This context descriptor lets the GuC know
- * about the doorbell, workqueue and process descriptor. Theoretically, it also
- * lets the GuC know about our HW contexts (Context ID, etc...), but we 
actually
+ * guc_stage_desc (via the client's stage_id), so effectively only one
+ * gets used. This stage descriptor lets the GuC know about the doorbell,
+ * workqueue and process descriptor. Theoretically, it also lets the GuC
+ * know about our HW contexts (context ID, etc...), but we actually
  * employ a kind of submission where the GuC uses the LRCA sent via the work
- * item instead (the single guc_context_desc associated to execbuf client
+ * item instead (the single guc_stage_desc associated to execbuf client
  * contains information about the default kernel context only, but this is
  * essentially unused). This is called a "proxy" submission.
  *
@@ -82,7 +82,7 @@
 
 static inline bool is_high_priority(struct i915_guc_client* client)
 {
-   return client->priority <= GUC_CTX_PRIORITY_HIGH;
+   return client->priority <= GUC_CLIENT_PRIORITY_HIGH;
 }
 
 static int __reserve_doorbell(struct i915_guc_client *client)
@@ -112,7 +112,7 @@ static int __reserve_doorbell(struct i915_guc_client 
*client)
__set_bit(id, client->guc->doorbell_bitmap);
client->doorbell_id = id;
DRM_DEBUG_DRIVER("client %u (high prio=%s) reserved doorbell: %d\n",
-client->ctx_index, yesno(is_high_priority(client)),
+client->stage_id, yesno(is_high_priority(client)),
 id);
return 0;
 }
@@ -129,31 +129,31 @@ static void __unreserve_doorbell(struct i915_guc_client 
*client)
  * Tell the GuC to allocate or deallocate a specific doorbell
  */
 
-static int __guc_allocate_doorbell(struct intel_guc *guc, u32 ctx_index)
+static int __guc_allocate_doorbell(struct intel_guc *guc, u32 stage_id)
 {
u32 action[] = {
INTEL_GUC_ACTION_ALLOCATE_DOORBELL,
-   ctx_index
+   stage_id
};
 
return intel_guc_send(guc, action, ARRAY_SIZE(action));
 }
 
-static int __guc_deallocate_doorbell(struct intel_guc *guc, u32 ctx_index)
+static int __guc_deallocate_doorbell(struct intel_guc *guc, u32 stage_id)
 {
u32 action[] = {
INTEL_GUC_ACTION_DEALLOCATE_DOORBELL,
-  

[Intel-gfx] [PATCH v3 06/13] drm/i915/guc: Make intel_guc_send a function pointer

2017-03-22 Thread Oscar Mateo
Prepare for an alternate GuC communication interface.

v2: Make a few functions static and name them correctly while we are at it 
(Oscar), but
leave an intel_guc_send_mmio interface for users that require old-style 
communication.

v3: Send intel_uc_init_early back to the top (Michal).

Signed-off-by: Michel Thierry 
Signed-off-by: Michal Wajdeczko 
Reviewed-by: Daniele Ceraolo Spurio 
Signed-off-by: Oscar Mateo 
---
 drivers/gpu/drm/i915/intel_uc.c | 16 +++-
 drivers/gpu/drm/i915/intel_uc.h |  9 -
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_uc.c b/drivers/gpu/drm/i915/intel_uc.c
index 516e57d..ea99c89 100644
--- a/drivers/gpu/drm/i915/intel_uc.c
+++ b/drivers/gpu/drm/i915/intel_uc.c
@@ -83,7 +83,10 @@ void intel_uc_sanitize_options(struct drm_i915_private 
*dev_priv)
 
 void intel_uc_init_early(struct drm_i915_private *dev_priv)
 {
-   mutex_init(&dev_priv->guc.send_mutex);
+   struct intel_guc *guc = &dev_priv->guc;
+
+   mutex_init(&guc->send_mutex);
+   guc->send = intel_guc_send_mmio;
 }
 
 void intel_uc_init_fw(struct drm_i915_private *dev_priv)
@@ -216,7 +219,7 @@ void intel_uc_fini_hw(struct drm_i915_private *dev_priv)
  * Read GuC command/status register (SOFT_SCRATCH_0)
  * Return true if it contains a response rather than a command
  */
-static bool intel_guc_recv(struct intel_guc *guc, u32 *status)
+static bool guc_recv(struct intel_guc *guc, u32 *status)
 {
struct drm_i915_private *dev_priv = guc_to_i915(guc);
 
@@ -225,7 +228,10 @@ static bool intel_guc_recv(struct intel_guc *guc, u32 
*status)
return INTEL_GUC_RECV_IS_RESPONSE(val);
 }
 
-int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
+/*
+ * This function implements the MMIO based host to GuC interface.
+ */
+int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len)
 {
struct drm_i915_private *dev_priv = guc_to_i915(guc);
u32 status;
@@ -253,9 +259,9 @@ int intel_guc_send(struct intel_guc *guc, const u32 
*action, u32 len)
 * up to that length of time, then switch to a slower sleep-wait loop.
 * No inte_guc_send command should ever take longer than 10ms.
 */
-   ret = wait_for_us(intel_guc_recv(guc, &status), 10);
+   ret = wait_for_us(guc_recv(guc, &status), 10);
if (ret)
-   ret = wait_for(intel_guc_recv(guc, &status), 10);
+   ret = wait_for(guc_recv(guc, &status), 10);
if (status != INTEL_GUC_STATUS_SUCCESS) {
/*
 * Either the GuC explicitly returned an error (which
diff --git a/drivers/gpu/drm/i915/intel_uc.h b/drivers/gpu/drm/i915/intel_uc.h
index c6f880c..3ec54a1 100644
--- a/drivers/gpu/drm/i915/intel_uc.h
+++ b/drivers/gpu/drm/i915/intel_uc.h
@@ -176,6 +176,9 @@ struct intel_guc {
 
/* To serialize the intel_guc_send actions */
struct mutex send_mutex;
+
+   /* GuC's FW specific send function */
+   int (*send)(struct intel_guc *guc, const u32 *data, u32 len);
 };
 
 struct intel_huc {
@@ -194,8 +197,12 @@ struct intel_huc {
 void intel_uc_fini_hw(struct drm_i915_private *dev_priv);
 void intel_uc_prepare_fw(struct drm_i915_private *dev_priv,
 struct intel_uc_fw *uc_fw);
-int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len);
 int intel_guc_sample_forcewake(struct intel_guc *guc);
+int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len);
+static inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 
len)
+{
+   return guc->send(guc, action, len);
+}
 
 /* intel_guc_loader.c */
 int intel_guc_select_fw(struct intel_guc *guc);
-- 
1.9.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v4 03/13] drm/i915/guc: Add onion teardown to the GuC setup

2017-03-22 Thread Oscar Mateo
Starting with intel_guc_loader, down to intel_guc_submission
and finally to intel_guc_log.

v2:
  - Null execbuf client outside guc_client_free (Daniele)
  - Assert if things try to get allocated twice (Daniele/Joonas)
  - Null guc->log.buf_addr when destroyed (Daniele)
  - Newline between returning success and error labels (Joonas)
  - Remove some unnecessary comments (Joonas)
  - Keep guc_log_create_extras naming convention (Joonas)
  - Helper function guc_log_has_extras (Joonas)
  - No need for separate relay_channel create/destroy. It's just another extra.
  - No need to nullify guc->log.flush_wq when destroyed (Joonas)
  - Hoist the check for has_extras out of guc_log_create_extras (Joonas)
  - Try to do i915_guc_log_register/unregister calls (kind of) symmetric 
(Daniele)
  - Make sure initel_guc_fini is not called before init is ever called (Daniele)

v3:
  - Remove unnecessary parenthesis (Joonas)
  - Check for logs enabled on debugfs registration
  - Rebase on top of Tvrtko's "Fix request re-submission after reset"

v4:
  - Rebased
  - Comment around enabling/disabling interrupts inside GuC logging (Joonas)

Cc: Daniele Ceraolo Spurio 
Reviewed-by: Joonas Lahtinen 
Signed-off-by: Oscar Mateo 
---
 drivers/gpu/drm/i915/i915_drv.c|  11 +-
 drivers/gpu/drm/i915/i915_gem.c|  10 +-
 drivers/gpu/drm/i915/i915_guc_submission.c |  97 
 drivers/gpu/drm/i915/intel_guc_loader.c|  21 --
 drivers/gpu/drm/i915/intel_guc_log.c   | 364 ++---
 drivers/gpu/drm/i915/intel_uc.c|  55 +++--
 drivers/gpu/drm/i915/intel_uc.h|   8 +-
 7 files changed, 297 insertions(+), 269 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 03d9e45..6d9944a 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -549,6 +549,8 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
 static void i915_gem_fini(struct drm_i915_private *dev_priv)
 {
mutex_lock(&dev_priv->drm.struct_mutex);
+   if (i915.enable_guc_loading)
+   intel_uc_fini_hw(dev_priv);
i915_gem_cleanup_engines(dev_priv);
i915_gem_context_fini(dev_priv);
mutex_unlock(&dev_priv->drm.struct_mutex);
@@ -609,7 +611,7 @@ static int i915_load_modeset_init(struct drm_device *dev)
 
ret = i915_gem_init(dev_priv);
if (ret)
-   goto cleanup_irq;
+   goto cleanup_uc;
 
intel_modeset_gem_init(dev);
 
@@ -631,9 +633,9 @@ static int i915_load_modeset_init(struct drm_device *dev)
if (i915_gem_suspend(dev_priv))
DRM_ERROR("failed to idle hardware; continuing to unload!\n");
i915_gem_fini(dev_priv);
+cleanup_uc:
+   intel_uc_fini_fw(dev_priv);
 cleanup_irq:
-   intel_guc_fini(dev_priv);
-   intel_huc_fini(dev_priv);
drm_irq_uninstall(dev);
intel_teardown_gmbus(dev_priv);
 cleanup_csr:
@@ -1369,9 +1371,8 @@ void i915_driver_unload(struct drm_device *dev)
/* Flush any outstanding unpin_work. */
drain_workqueue(dev_priv->wq);
 
-   intel_guc_fini(dev_priv);
-   intel_huc_fini(dev_priv);
i915_gem_fini(dev_priv);
+   intel_uc_fini_fw(dev_priv);
intel_fbc_cleanup_cfb(dev_priv);
 
intel_power_domains_fini(dev_priv);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index fd611b4..4eb46e4 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4596,10 +4596,12 @@ int i915_gem_init_hw(struct drm_i915_private *dev_priv)
 
intel_mocs_init_l3cc_table(dev_priv);
 
-   /* We can't enable contexts until all firmware is loaded */
-   ret = intel_uc_init_hw(dev_priv);
-   if (ret)
-   goto out;
+   if (i915.enable_guc_loading) {
+   /* We can't enable contexts until all firmware is loaded */
+   ret = intel_uc_init_hw(dev_priv);
+   if (ret)
+   goto out;
+   }
 
 out:
intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index d4b2a9b..08287f7 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -912,7 +912,6 @@ static int guc_init_doorbell_hw(struct intel_guc *guc)
ida_simple_remove(&guc->ctx_ids, client->ctx_index);
 err_client:
kfree(client);
-
return ERR_PTR(ret);
 }
 
@@ -938,7 +937,7 @@ static void guc_policies_init(struct guc_policies *policies)
policies->is_valid = 1;
 }
 
-static void guc_addon_create(struct intel_guc *guc)
+static int guc_addon_create(struct intel_guc *guc)
 {
struct drm_i915_private *dev_priv = guc_to_i915(guc);
struct i915_vma *vma;
@@ -954,14 +953,13 @@ static void guc_addon_create(struct intel_guc *guc)
enum intel_engine_id id;
   

[Intel-gfx] [PATCH 12/13] drm/i915/guc: Move guc_interrupts_release next to guc_interrupts_capture

2017-03-22 Thread Oscar Mateo
They go better together.

Cc: Joonas Lahtinen 
Signed-off-by: Oscar Mateo 
Reviewed-by: Daniele Ceraolo Spurio 
---
 drivers/gpu/drm/i915/i915_guc_submission.c | 48 +++---
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index 3d78a6b..3398204 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -1190,6 +1190,30 @@ static void guc_interrupts_capture(struct 
drm_i915_private *dev_priv)
dev_priv->rps.pm_intrmsk_mbz &= ~GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
 }
 
+static void guc_interrupts_release(struct drm_i915_private *dev_priv)
+{
+   struct intel_engine_cs *engine;
+   enum intel_engine_id id;
+   int irqs;
+
+   /*
+* tell all command streamers NOT to forward interrupts or vblank
+* to GuC.
+*/
+   irqs = _MASKED_FIELD(GFX_FORWARD_VBLANK_MASK, GFX_FORWARD_VBLANK_NEVER);
+   irqs |= _MASKED_BIT_DISABLE(GFX_INTERRUPT_STEERING);
+   for_each_engine(engine, dev_priv, id)
+   I915_WRITE(RING_MODE_GEN7(engine), irqs);
+
+   /* route all GT interrupts to the host */
+   I915_WRITE(GUC_BCS_RCS_IER, 0);
+   I915_WRITE(GUC_VCS2_VCS1_IER, 0);
+   I915_WRITE(GUC_WD_VECS_IER, 0);
+
+   dev_priv->rps.pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
+   dev_priv->rps.pm_intrmsk_mbz &= ~ARAT_EXPIRED_INTRMSK;
+}
+
 int i915_guc_submission_enable(struct drm_i915_private *dev_priv)
 {
struct intel_guc *guc = &dev_priv->guc;
@@ -1253,30 +1277,6 @@ int i915_guc_submission_enable(struct drm_i915_private 
*dev_priv)
return err;
 }
 
-static void guc_interrupts_release(struct drm_i915_private *dev_priv)
-{
-   struct intel_engine_cs *engine;
-   enum intel_engine_id id;
-   int irqs;
-
-   /*
-* tell all command streamers NOT to forward interrupts or vblank
-* to GuC.
-*/
-   irqs = _MASKED_FIELD(GFX_FORWARD_VBLANK_MASK, GFX_FORWARD_VBLANK_NEVER);
-   irqs |= _MASKED_BIT_DISABLE(GFX_INTERRUPT_STEERING);
-   for_each_engine(engine, dev_priv, id)
-   I915_WRITE(RING_MODE_GEN7(engine), irqs);
-
-   /* route all GT interrupts to the host */
-   I915_WRITE(GUC_BCS_RCS_IER, 0);
-   I915_WRITE(GUC_VCS2_VCS1_IER, 0);
-   I915_WRITE(GUC_WD_VECS_IER, 0);
-
-   dev_priv->rps.pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
-   dev_priv->rps.pm_intrmsk_mbz &= ~ARAT_EXPIRED_INTRMSK;
-}
-
 void i915_guc_submission_disable(struct drm_i915_private *dev_priv)
 {
struct intel_guc *guc = &dev_priv->guc;
-- 
1.9.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v5 01/13] drm/i915/guc: Sanitize GuC client initialization

2017-03-22 Thread Oscar Mateo
From: Joonas Lahtinen 

Started adding proper teardown to guc_client_alloc, ended up removing
quite a few dead ends where errors communicating with the GuC were
silently ignored. There also seemed to be quite a few erronous
teardown actions performed in case of an error (ordering wrong).

v2:
  - Increase function symmetry/proximity (Michal/Daniele)
  - Fix __reserve_doorbell accounting for high priority (Daniele)
  - Call __update_doorbell_desc! (Daniele)
  - Isolate __guc_{,de}allocate_doorbell (Michal/Daniele)

v3:
  - "Select" a cacheline is a more accurate verb than "reserve" (Daniele).
  - We cannot update & create the doorbell without reserving it first, so
move the whole doorbell creation for execbuf_client to the submission
enable (Oscar).i
  - Add a fixme for ignoring possible doorbell destroy errors.

v4:
  - Remove comment about is_high_priority (Daniele)
  - Debug message typo (Daniele)
  - Reuse __get_doorbell in more places (Daniele)
  - Do not do arithmetic on void pointers (Daniele)
  - Add comment to __reset_doorbell (Daniele)

v5:
  - gccisms like arithmetic on void pointers are not frowned upon (Oscar)

Signed-off-by: Joonas Lahtinen 
Cc: Michal Wajdeczko 
Cc: Arkadiusz Hiler 
Cc: Tvrtko Ursulin 
Cc: Chris Wilson 
Reviewed-by: Daniele Ceraolo Spurio 
Signed-off-by: Oscar Mateo 
---
 drivers/gpu/drm/i915/i915_debugfs.c|   4 +-
 drivers/gpu/drm/i915/i915_guc_submission.c | 398 -
 drivers/gpu/drm/i915/intel_guc_fwif.h  |   4 +-
 drivers/gpu/drm/i915/intel_uc.h|  11 +-
 4 files changed, 233 insertions(+), 184 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c 
b/drivers/gpu/drm/i915/i915_debugfs.c
index 47e707d..061f8a5 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -2476,7 +2476,7 @@ static void i915_guc_client_info(struct seq_file *m,
 
seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
client->priority, client->ctx_index, client->proc_desc_offset);
-   seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
+   seq_printf(m, "\tDoorbell id %d, offset: 0x%lx, cookie 0x%x\n",
client->doorbell_id, client->doorbell_offset, 
client->doorbell_cookie);
seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
client->wq_size, client->wq_offset, client->wq_tail);
@@ -2511,7 +2511,7 @@ static int i915_guc_info(struct seq_file *m, void *data)
}
 
seq_printf(m, "Doorbell map:\n");
-   seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc->doorbell_bitmap);
+   seq_printf(m, "\t%*pb\n", GUC_NUM_DOORBELLS, guc->doorbell_bitmap);
seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
 
seq_printf(m, "GuC total action count: %llu\n", guc->action_count);
diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index 832ac9e..b19753c 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -64,27 +64,70 @@
  *
  */
 
+static inline bool is_high_priority(struct i915_guc_client* client)
+{
+   return client->priority <= GUC_CTX_PRIORITY_HIGH;
+}
+
+static int __reserve_doorbell(struct i915_guc_client *client)
+{
+   unsigned long offset;
+   unsigned long end;
+   u16 id;
+
+   GEM_BUG_ON(client->doorbell_id != GUC_DOORBELL_INVALID);
+
+   /*
+* The bitmap tracks which doorbell registers are currently in use.
+* It is split into two halves; the first half is used for normal
+* priority contexts, the second half for high-priority ones.
+*/
+   offset = 0;
+   end = GUC_NUM_DOORBELLS/2;
+   if (is_high_priority(client)) {
+   offset = end;
+   end += offset;
+   }
+
+   id = find_next_zero_bit(client->guc->doorbell_bitmap, offset, end);
+   if (id == end)
+   return -ENOSPC;
+
+   __set_bit(id, client->guc->doorbell_bitmap);
+   client->doorbell_id = id;
+   DRM_DEBUG_DRIVER("client %u (high prio=%s) reserved doorbell: %d\n",
+client->ctx_index, yesno(is_high_priority(client)),
+id);
+   return 0;
+}
+
+static void __unreserve_doorbell(struct i915_guc_client *client)
+{
+   GEM_BUG_ON(client->doorbell_id == GUC_DOORBELL_INVALID);
+
+   __clear_bit(client->doorbell_id, client->guc->doorbell_bitmap);
+   client->doorbell_id = GUC_DOORBELL_INVALID;
+}
+
 /*
  * Tell the GuC to allocate or deallocate a specific doorbell
  */
 
-static int guc_allocate_doorbell(struct intel_guc *guc,
-struct i915_guc_client *client)
+static int __guc_allocate_doorbell(struct intel_guc *guc, u32 ctx_index)
 {
u32 action[] = {
INTEL_GUC_ACTION_ALLOCATE_DOORBELL,
-   client->ctx_index
+   ctx_index
};
 
  

[Intel-gfx] [PATCH v2 07/13] drm/i915/guc: Improve the GuC documentation & comments about proxy submissions

2017-03-22 Thread Oscar Mateo
While at it, fix a typo (s/ring_lcra/ring_lrca) and improve the naming of one
firware interface field (s/ring_tail/submit_element_info, since it can contain
more than just the ring tail).

No change in functionality.

v2:
  - Remove reference to "unique user" of the GuC (Daniele)
  - Keep mention to renaming from "GuC context" to "client" (Daniele)

Signed-off-by: Oscar Mateo 
Reviewed-by: Daniele Ceraolo Spurio 
---
 drivers/gpu/drm/i915/i915_guc_submission.c | 42 +++---
 drivers/gpu/drm/i915/intel_guc_fwif.h  |  4 +--
 drivers/gpu/drm/i915/intel_uc.h|  6 +++--
 3 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index b3d1d5c..c02167c 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -30,16 +30,25 @@
 /**
  * DOC: GuC-based command submission
  *
- * i915_guc_client:
- * We use the term client to avoid confusion with contexts. A i915_guc_client 
is
- * equivalent to GuC object guc_context_desc. This context descriptor is
- * allocated from a pool of 1024 entries. Kernel driver will allocate doorbell
- * and workqueue for it. Also the process descriptor (guc_process_desc), which
- * is mapped to client space. So the client can write Work Item then ring the
- * doorbell.
+ * GuC client:
+ * A i915_guc_client refers to a submission path through GuC. Currently, there
+ * is only one of these (the execbuf_client) and this one is charged with all
+ * submissions to the GuC. This struct is the owner of a doorbell, a process
+ * descriptor and a workqueue (all of them inside a single gem object that
+ * contains all required pages for these elements).
  *
- * To simplify the implementation, we allocate one gem object that contains all
- * pages for doorbell, process descriptor and workqueue.
+ * GuC context descriptor:
+ * During initialization, the driver allocates a static pool of 1024 such
+ * descriptors, and shares them with the GuC.
+ * Currently, there exists a 1:1 mapping between a i915_guc_client and a
+ * guc_context_desc (via the client's context_index), so effectively only
+ * one guc_context_desc gets used. This context descriptor lets the GuC know
+ * about the doorbell, workqueue and process descriptor. Theoretically, it also
+ * lets the GuC know about our HW contexts (Context ID, etc...), but we 
actually
+ * employ a kind of submission where the GuC uses the LRCA sent via the work
+ * item instead (the single guc_context_desc associated to execbuf client
+ * contains information about the default kernel context only, but this is
+ * essentially unused). This is called a "proxy" submission.
  *
  * The Scratch registers:
  * There are 16 MMIO-based registers start from 0xC180. The kernel driver 
writes
@@ -308,10 +317,17 @@ static void guc_ctx_desc_init(struct intel_guc *guc,
if (!ce->state)
break;  /* XXX: continue? */
 
+   /*
+* XXX: When this is a GUC_CTX_DESC_ATTR_KERNEL client (proxy
+* submission or, in other words, not using a direct submission
+* model) the KMD's LRCA is not used for any work submission.
+* Instead, the GuC uses the LRCA of the user mode context (see
+* guc_wq_item_append below).
+*/
lrc->context_desc = lower_32_bits(ce->lrc_desc);
 
/* The state page is after PPHWSP */
-   lrc->ring_lcra =
+   lrc->ring_lrca =
guc_ggtt_offset(ce->state) + LRC_STATE_PN * PAGE_SIZE;
lrc->context_id = (client->ctx_index << GUC_ELC_CTXID_OFFSET) |
(guc_engine_id << GUC_ELC_ENGINE_OFFSET);
@@ -341,10 +357,6 @@ static void guc_ctx_desc_init(struct intel_guc *guc,
desc->wq_addr = gfx_addr + client->wq_offset;
desc->wq_size = client->wq_size;
 
-   /*
-* XXX: Take LRCs from an existing context if this is not an
-* IsKMDCreatedContext client
-*/
desc->desc_private = (uintptr_t)client;
 }
 
@@ -468,7 +480,7 @@ static void guc_wq_item_append(struct i915_guc_client 
*client,
/* The GuC wants only the low-order word of the context descriptor */
wqi->context_desc = (u32)intel_lr_context_descriptor(rq->ctx, engine);
 
-   wqi->ring_tail = tail << WQ_RING_TAIL_SHIFT;
+   wqi->submit_element_info = tail << WQ_RING_TAIL_SHIFT;
wqi->fence_id = rq->global_seqno;
 }
 
diff --git a/drivers/gpu/drm/i915/intel_guc_fwif.h 
b/drivers/gpu/drm/i915/intel_guc_fwif.h
index 3ae8cef..4edf40f 100644
--- a/drivers/gpu/drm/i915/intel_guc_fwif.h
+++ b/drivers/gpu/drm/i915/intel_guc_fwif.h
@@ -251,7 +251,7 @@ struct guc_doorbell_info {
 struct guc_wq_item {
u32 header;
u32 context_desc;
-   u32 ring_tail;
+   u32 submit_element_info;
u32 fen

[Intel-gfx] [PATCH 13/13] HAX Enable GuC loading & submission

2017-03-22 Thread Oscar Mateo
This is just for CI testing, do not merge.

Signed-off-by: Oscar Mateo 
---
 drivers/gpu/drm/i915/i915_params.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_params.c 
b/drivers/gpu/drm/i915/i915_params.c
index b6a7e36..abd2894 100644
--- a/drivers/gpu/drm/i915/i915_params.c
+++ b/drivers/gpu/drm/i915/i915_params.c
@@ -56,8 +56,8 @@ struct i915_params i915 __read_mostly = {
.verbose_state_checks = 1,
.nuclear_pageflip = 0,
.edp_vswing = 0,
-   .enable_guc_loading = 0,
-   .enable_guc_submission = 0,
+   .enable_guc_loading = 1,
+   .enable_guc_submission = 1,
.guc_log_level = -1,
.guc_firmware_path = NULL,
.huc_firmware_path = NULL,
@@ -221,12 +221,12 @@ struct i915_params i915 __read_mostly = {
 module_param_named_unsafe(enable_guc_loading, i915.enable_guc_loading, int, 
0400);
 MODULE_PARM_DESC(enable_guc_loading,
"Enable GuC firmware loading "
-   "(-1=auto, 0=never [default], 1=if available, 2=required)");
+   "(-1=auto, 0=never, 1=if available [default], 2=required)");
 
 module_param_named_unsafe(enable_guc_submission, i915.enable_guc_submission, 
int, 0400);
 MODULE_PARM_DESC(enable_guc_submission,
"Enable GuC submission "
-   "(-1=auto, 0=never [default], 1=if available, 2=required)");
+   "(-1=auto, 0=never, 1=if available [default], 2=required)");
 
 module_param_named(guc_log_level, i915.guc_log_level, int, 0400);
 MODULE_PARM_DESC(guc_log_level,
-- 
1.9.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 00/13] Various improvements around the GuC topic

2017-03-22 Thread Oscar Mateo
Another go at it.

Joonas Lahtinen (1):
  drm/i915/guc: Sanitize GuC client initialization

Oscar Mateo (12):
  drm/i915/guc: Keep the ctx_pool_vaddr mapped, for easy access
  drm/i915/guc: Add onion teardown to the GuC setup
  drm/i915/guc: The Additional Data Struct (ADS) should get enabled
together with GuC submission
  drm/i915/guc: Break out the GuC log extras into their own "runtime"
struct
  drm/i915/guc: Make intel_guc_send a function pointer
  drm/i915/guc: Improve the GuC documentation & comments about proxy
submissions
  drm/i915/guc: Wait for doorbell to be inactive before deallocating
  drm/i915/guc: A little bit more of doorbell sanitization
  drm/i915/guc: Refactor the concept "GuC context descriptor" into "GuC
stage descriptor"
  drm/i915/guc: Split out the mmio_white_list struct
  drm/i915/guc: Move guc_interrupts_release next to
guc_interrupts_capture
  HAX Enable GuC loading & submission

 drivers/gpu/drm/i915/i915_debugfs.c|   8 +-
 drivers/gpu/drm/i915/i915_drv.c|  11 +-
 drivers/gpu/drm/i915/i915_gem.c|  10 +-
 drivers/gpu/drm/i915/i915_guc_submission.c | 787 +
 drivers/gpu/drm/i915/i915_irq.c|   4 +-
 drivers/gpu/drm/i915/i915_params.c |   8 +-
 drivers/gpu/drm/i915/intel_guc_fwif.h  |  71 +--
 drivers/gpu/drm/i915/intel_guc_loader.c|  33 +-
 drivers/gpu/drm/i915/intel_guc_log.c   | 386 +++---
 drivers/gpu/drm/i915/intel_uc.c|  62 ++-
 drivers/gpu/drm/i915/intel_uc.h|  51 +-
 11 files changed, 793 insertions(+), 638 deletions(-)

-- 
1.9.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v5 02/13] drm/i915/guc: Keep the ctx_pool_vaddr mapped, for easy access

2017-03-22 Thread Oscar Mateo
The GuC descriptor is big in size. If we use a local definition of
guc_desc we have a chance to overflow stack, so avoid it.

Also, Chris abhors scatterlists :)

v2: Rebased, helper function to retrieve the context descriptor,
s/ctx_pool_vma/ctx_pool/

v3: Zero out guc_context_desc before initialization

v4: Do not do arithmetic on void pointers (Daniele)

v5: Nicer than arithmetic on pointers (Chris, Joonas)

Cc: Daniele Ceraolo Spurio 
Reviewed-by: Chris Wilson 
Reviewed-by: Joonas Lahtinen 
Signed-off-by: Oscar Mateo 
---
 drivers/gpu/drm/i915/i915_guc_submission.c | 94 +++---
 drivers/gpu/drm/i915/intel_guc_loader.c|  2 +-
 drivers/gpu/drm/i915/intel_uc.h|  3 +-
 3 files changed, 49 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index b19753c..d4b2a9b 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -133,6 +133,13 @@ static int __guc_deallocate_doorbell(struct intel_guc 
*guc, u32 ctx_index)
return intel_guc_send(guc, action, ARRAY_SIZE(action));
 }
 
+static struct guc_context_desc *__get_context_desc(struct i915_guc_client 
*client)
+{
+   struct guc_context_desc *base = client->guc->ctx_pool_vaddr;
+
+   return &base[client->ctx_index];
+}
+
 /*
  * Initialise, update, or clear doorbell data shared with the GuC
  *
@@ -142,21 +149,11 @@ static int __guc_deallocate_doorbell(struct intel_guc 
*guc, u32 ctx_index)
 
 static int __update_doorbell_desc(struct i915_guc_client *client, u16 new_id)
 {
-   struct sg_table *sg = client->guc->ctx_pool_vma->pages;
-   struct guc_context_desc desc;
-   size_t len;
+   struct guc_context_desc *desc;
 
/* Update the GuC's idea of the doorbell ID */
-   len = sg_pcopy_to_buffer(sg->sgl, sg->nents, &desc, sizeof(desc),
-sizeof(desc) * client->ctx_index);
-   if (len != sizeof(desc))
-   return -EFAULT;
-
-   desc.db_id = new_id;
-   len = sg_pcopy_from_buffer(sg->sgl, sg->nents, &desc, sizeof(desc),
-  sizeof(desc) * client->ctx_index);
-   if (len != sizeof(desc))
-   return -EFAULT;
+   desc = __get_context_desc(client);
+   desc->db_id = new_id;
 
return 0;
 }
@@ -271,29 +268,28 @@ static void guc_proc_desc_init(struct intel_guc *guc,
  * data structures relating to this client (doorbell, process descriptor,
  * write queue, etc).
  */
-
 static void guc_ctx_desc_init(struct intel_guc *guc,
  struct i915_guc_client *client)
 {
struct drm_i915_private *dev_priv = guc_to_i915(guc);
struct intel_engine_cs *engine;
struct i915_gem_context *ctx = client->owner;
-   struct guc_context_desc desc;
-   struct sg_table *sg;
+   struct guc_context_desc *desc;
unsigned int tmp;
u32 gfx_addr;
 
-   memset(&desc, 0, sizeof(desc));
+   desc = __get_context_desc(client);
+   memset(desc, 0, sizeof(*desc));
 
-   desc.attribute = GUC_CTX_DESC_ATTR_ACTIVE | GUC_CTX_DESC_ATTR_KERNEL;
-   desc.context_id = client->ctx_index;
-   desc.priority = client->priority;
-   desc.db_id = client->doorbell_id;
+   desc->attribute = GUC_CTX_DESC_ATTR_ACTIVE | GUC_CTX_DESC_ATTR_KERNEL;
+   desc->context_id = client->ctx_index;
+   desc->priority = client->priority;
+   desc->db_id = client->doorbell_id;
 
for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
struct intel_context *ce = &ctx->engine[engine->id];
uint32_t guc_engine_id = engine->guc_id;
-   struct guc_execlist_context *lrc = &desc.lrc[guc_engine_id];
+   struct guc_execlist_context *lrc = &desc->lrc[guc_engine_id];
 
/* TODO: We have a design issue to be solved here. Only when we
 * receive the first batch, we know which engine is used by the
@@ -318,49 +314,40 @@ static void guc_ctx_desc_init(struct intel_guc *guc,
lrc->ring_next_free_location = lrc->ring_begin;
lrc->ring_current_tail_pointer_value = 0;
 
-   desc.engines_used |= (1 << guc_engine_id);
+   desc->engines_used |= (1 << guc_engine_id);
}
 
DRM_DEBUG_DRIVER("Host engines 0x%x => GuC engines used 0x%x\n",
-   client->engines, desc.engines_used);
-   WARN_ON(desc.engines_used == 0);
+   client->engines, desc->engines_used);
+   WARN_ON(desc->engines_used == 0);
 
/*
 * The doorbell, process descriptor, and workqueue are all parts
 * of the client object, which the GuC will reference via the GGTT
 */
gfx_addr = guc_ggtt_offset(client->vma);
-   desc.db_trigger_phy = sg_dma_address(client->vma->pages->sgl) +
+   desc->db_trigger_phy = sg_

[Intel-gfx] [PATCH v2 08/13] drm/i915/guc: Wait for doorbell to be inactive before deallocating

2017-03-22 Thread Oscar Mateo
Doorbell release flow requires that we wait for GEN8_DRB_VALID bit to go
to zero after updating db_status before we call the GuC to release the
doorbell.

Kudos to Daniele for finding this out.

v2: WARN instead of DRM_ERROR (Joonas)

Signed-off-by: Oscar Mateo 
Reviewed-by: Daniele Ceraolo Spurio 
Reviewed-by: Joonas Lahtinen 
---
 drivers/gpu/drm/i915/i915_guc_submission.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index c02167c..2d4d854 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -206,12 +206,22 @@ static int __create_doorbell(struct i915_guc_client 
*client)
 
 static int __destroy_doorbell(struct i915_guc_client *client)
 {
+   struct drm_i915_private *dev_priv = guc_to_i915(client->guc);
struct guc_doorbell_info *doorbell;
+   u16 db_id = client->doorbell_id;
+
+   GEM_BUG_ON(db_id >= GUC_DOORBELL_INVALID);
 
doorbell = __get_doorbell(client);
doorbell->db_status = GUC_DOORBELL_DISABLED;
doorbell->cookie = 0;
 
+   /* Doorbell release flow requires that we wait for GEN8_DRB_VALID bit
+* to go to zero after updating db_status before we call the GuC to
+* release the doorbell */
+   if (wait_for_us(!(I915_READ(GEN8_DRBREGL(db_id)) & GEN8_DRB_VALID), 10))
+   WARN_ONCE(true, "Doorbell never became invalid after 
disable\n");
+
return __guc_deallocate_doorbell(client->guc, client->ctx_index);
 }
 
-- 
1.9.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 04/13] drm/i915/guc: The Additional Data Struct (ADS) should get enabled together with GuC submission

2017-03-22 Thread Oscar Mateo
It's mandatory and it gets created if and only if GuC submission is enabled, so 
that should be
the condition for informing the GuC about it.

Also s/guc_addon_create/guc_ads_create and s/guc_addon_destroy/guc_ads_destroy 
and, while
at it, add an explanation of what things go inside the ADS object.

Cc: Joonas Lahtinen 
Signed-off-by: Oscar Mateo 
Reviewed-by: Daniele Ceraolo Spurio 
---
 drivers/gpu/drm/i915/i915_guc_submission.c | 17 -
 drivers/gpu/drm/i915/intel_guc_loader.c| 10 --
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index 08287f7..b3d1d5c 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -62,6 +62,13 @@
  * ELSP context descriptor dword into Work Item.
  * See guc_wq_item_append()
  *
+ * ADS:
+ * The Additional Data Struct (ADS) has pointers for different buffers used by
+ * the GuC. One single gem object contains the ADS struct itself (guc_ads), the
+ * scheduling policies (guc_policies), a structure describing a collection of
+ * register sets (guc_mmio_reg_state) and some extra pages for the GuC to save
+ * its internal state for sleep.
+ *
  */
 
 static inline bool is_high_priority(struct i915_guc_client* client)
@@ -937,7 +944,7 @@ static void guc_policies_init(struct guc_policies *policies)
policies->is_valid = 1;
 }
 
-static int guc_addon_create(struct intel_guc *guc)
+static int guc_ads_create(struct intel_guc *guc)
 {
struct drm_i915_private *dev_priv = guc_to_i915(guc);
struct i915_vma *vma;
@@ -1000,7 +1007,7 @@ static int guc_addon_create(struct intel_guc *guc)
return 0;
 }
 
-static void guc_addon_destroy(struct intel_guc *guc)
+static void guc_ads_destroy(struct intel_guc *guc)
 {
i915_vma_unpin_and_release(&guc->ads_vma);
 }
@@ -1050,7 +1057,7 @@ int i915_guc_submission_init(struct drm_i915_private 
*dev_priv)
if (ret < 0)
goto err_vaddr;
 
-   ret = guc_addon_create(guc);
+   ret = guc_ads_create(guc);
if (ret < 0)
goto err_log;
 
@@ -1069,7 +1076,7 @@ int i915_guc_submission_init(struct drm_i915_private 
*dev_priv)
return 0;
 
 err_ads:
-   guc_addon_destroy(guc);
+   guc_ads_destroy(guc);
 err_log:
intel_guc_log_destroy(guc);
 err_vaddr:
@@ -1089,7 +1096,7 @@ void i915_guc_submission_fini(struct drm_i915_private 
*dev_priv)
guc_client_free(guc->execbuf_client);
guc->execbuf_client = NULL;
ida_destroy(&guc->ctx_ids);
-   guc_addon_destroy(guc);
+   guc_ads_destroy(guc);
intel_guc_log_destroy(guc);
i915_gem_object_unpin_map(guc->ctx_pool->obj);
i915_vma_unpin_and_release(&guc->ctx_pool);
diff --git a/drivers/gpu/drm/i915/intel_guc_loader.c 
b/drivers/gpu/drm/i915/intel_guc_loader.c
index b8ba28d..62ebf56 100644
--- a/drivers/gpu/drm/i915/intel_guc_loader.c
+++ b/drivers/gpu/drm/i915/intel_guc_loader.c
@@ -148,17 +148,15 @@ static void guc_params_init(struct drm_i915_private 
*dev_priv)
} else
params[GUC_CTL_DEBUG] = GUC_LOG_DISABLED;
 
-   if (guc->ads_vma) {
-   u32 ads = guc_ggtt_offset(guc->ads_vma) >> PAGE_SHIFT;
-   params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT;
-   params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED;
-   }
-
/* If GuC submission is enabled, set up additional parameters here */
if (i915.enable_guc_submission) {
+   u32 ads = guc_ggtt_offset(guc->ads_vma) >> PAGE_SHIFT;
u32 pgs = guc_ggtt_offset(dev_priv->guc.ctx_pool);
u32 ctx_in_16 = GUC_MAX_GPU_CONTEXTS / 16;
 
+   params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT;
+   params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED;
+
pgs >>= PAGE_SHIFT;
params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) |
(ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT);
-- 
1.9.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v2 09/13] drm/i915/guc: A little bit more of doorbell sanitization

2017-03-22 Thread Oscar Mateo
Some recent refactoring patches have left the doorbell creation outside
the GuC client allocation, which does not make a lot of sense (a client
without a doorbell is something useless). Move it back there, and
refactor the init_doorbell_hw consequently.

Thanks to this, we can do some other improvements, like hoisting the
check for GuC submission enabled out of the enable function.

v2: Rebased.

Cc: Michal Wajdeczko 
Cc: Arkadiusz Hiler 
Cc: Tvrtko Ursulin 
Cc: Chris Wilson 
Cc: Daniele Ceraolo Spurio 
Signed-off-by: Oscar Mateo 
Reviewed-by: Joonas Lahtinen 
---
 drivers/gpu/drm/i915/i915_guc_submission.c | 231 -
 drivers/gpu/drm/i915/intel_uc.c|  21 +--
 2 files changed, 138 insertions(+), 114 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index 2d4d854..c9d324f 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -163,15 +163,13 @@ static struct guc_context_desc *__get_context_desc(struct 
i915_guc_client *clien
  * client object which contains the page being used for the doorbell
  */
 
-static int __update_doorbell_desc(struct i915_guc_client *client, u16 new_id)
+static void __update_doorbell_desc(struct i915_guc_client *client, u16 new_id)
 {
struct guc_context_desc *desc;
 
/* Update the GuC's idea of the doorbell ID */
desc = __get_context_desc(client);
desc->db_id = new_id;
-
-   return 0;
 }
 
 static struct guc_doorbell_info *__get_doorbell(struct i915_guc_client *client)
@@ -225,6 +223,28 @@ static int __destroy_doorbell(struct i915_guc_client 
*client)
return __guc_deallocate_doorbell(client->guc, client->ctx_index);
 }
 
+static int create_doorbell(struct i915_guc_client *client)
+{
+   int ret;
+
+   ret = __reserve_doorbell(client);
+   if (ret)
+   return ret;
+
+   __update_doorbell_desc(client, client->doorbell_id);
+
+   ret = __create_doorbell(client);
+   if (ret)
+   goto err;
+
+   return 0;
+
+err:
+   __update_doorbell_desc(client, GUC_DOORBELL_INVALID);
+   __unreserve_doorbell(client);
+   return ret;
+}
+
 static int destroy_doorbell(struct i915_guc_client *client)
 {
int err;
@@ -494,6 +514,17 @@ static void guc_wq_item_append(struct i915_guc_client 
*client,
wqi->fence_id = rq->global_seqno;
 }
 
+static void guc_reset_wq(struct i915_guc_client *client)
+{
+   struct guc_process_desc *desc = client->vaddr +
+   client->proc_desc_offset;
+
+   desc->head = 0;
+   desc->tail = 0;
+
+   client->wq_tail = 0;
+}
+
 static int guc_ring_doorbell(struct i915_guc_client *client)
 {
struct guc_process_desc *desc;
@@ -749,19 +780,6 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc 
*guc, u32 size)
return vma;
 }
 
-static void guc_client_free(struct i915_guc_client *client)
-{
-   /*
-* XXX: wait for any outstanding submissions before freeing memory.
-* Be sure to drop any locks
-*/
-   guc_ctx_desc_fini(client->guc, client);
-   i915_gem_object_unpin_map(client->vma->obj);
-   i915_vma_unpin_and_release(&client->vma);
-   ida_simple_remove(&client->guc->ctx_ids, client->ctx_index);
-   kfree(client);
-}
-
 /* Check that a doorbell register is in the expected state */
 static bool doorbell_ok(struct intel_guc *guc, u16 db_id)
 {
@@ -792,9 +810,8 @@ static int __reset_doorbell(struct i915_guc_client* client, 
u16 db_id)
 {
int err;
 
-   err = __update_doorbell_desc(client, db_id);
-   if (!err)
-   err = __create_doorbell(client);
+   __update_doorbell_desc(client, db_id);
+   err = __create_doorbell(client);
if (!err)
err = __destroy_doorbell(client);
 
@@ -802,48 +819,61 @@ static int __reset_doorbell(struct i915_guc_client* 
client, u16 db_id)
 }
 
 /*
- * Borrow the first client to set up & tear down each unused doorbell
- * in turn, to ensure that all doorbell h/w is (re)initialised.
+ * Set up & tear down each unused doorbell in turn, to ensure that all doorbell
+ * HW is (re)initialised. For that end, we might have to borrow the first
+ * client. Also, tell GuC about all the doorbells in use by all clients.
+ * We do this because the KMD, the GuC and the doorbell HW can easily go out of
+ * sync (e.g. we can reset the GuC, but not the doorbel HW).
  */
 static int guc_init_doorbell_hw(struct intel_guc *guc)
 {
struct i915_guc_client *client = guc->execbuf_client;
-   int err;
-   int i;
-
-   if (has_doorbell(client))
-   destroy_doorbell(client);
+   bool recreate_first_client = false;
+   u16 db_id;
+   int ret;
 
-   for (i = 0; i < GUC_NUM_DOORBELLS; ++i) {
-   if (doorbell_ok(guc, i))
+   /* For unused doorbells, make sure they are disabled */
+

[Intel-gfx] [PATCH v3 05/13] drm/i915/guc: Break out the GuC log extras into their own "runtime" struct

2017-03-22 Thread Oscar Mateo
When initializing the GuC log struct, there is an object we need to
allocate always, since the GuC needs its address at fw load time.
The rest is only needed during runtime, in the sense that we only
create if we actually enable GuC logging. Make that distinction
explicit by subdividing further the intel_guc_log struct.

v2: Call the new struct "runtime", instead of "extras" (Joonas)

v3: Check indent (Joonas)

Cc: Daniele Ceraolo Spurio 
Reviewed-by: Michal Wajdeczko 
Reviewed-by: Joonas Lahtinen 
Signed-off-by: Oscar Mateo 
---
 drivers/gpu/drm/i915/i915_irq.c  |  4 +-
 drivers/gpu/drm/i915/intel_guc_log.c | 72 ++--
 drivers/gpu/drm/i915/intel_uc.h  | 12 +++---
 3 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index cb20c94..3d2e623 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -1741,8 +1741,8 @@ static void gen9_guc_irq_handler(struct drm_i915_private 
*dev_priv, u32 gt_iir)
I915_WRITE(SOFT_SCRATCH(15), msg & ~flush);
 
/* Handle flush interrupt in bottom half */
-   queue_work(dev_priv->guc.log.flush_wq,
-  &dev_priv->guc.log.flush_work);
+   queue_work(dev_priv->guc.log.runtime.flush_wq,
+  &dev_priv->guc.log.runtime.flush_work);
 
dev_priv->guc.log.flush_interrupt_count++;
} else {
diff --git a/drivers/gpu/drm/i915/intel_guc_log.c 
b/drivers/gpu/drm/i915/intel_guc_log.c
index b39cdd6..6fb63a3 100644
--- a/drivers/gpu/drm/i915/intel_guc_log.c
+++ b/drivers/gpu/drm/i915/intel_guc_log.c
@@ -166,7 +166,7 @@ static int guc_log_relay_file_create(struct intel_guc *guc)
return -ENODEV;
}
 
-   ret = relay_late_setup_files(guc->log.relay_chan, "guc_log", log_dir);
+   ret = relay_late_setup_files(guc->log.runtime.relay_chan, "guc_log", 
log_dir);
if (ret < 0 && ret != -EEXIST) {
DRM_ERROR("Couldn't associate relay chan with file %d\n", ret);
return ret;
@@ -183,15 +183,15 @@ static void guc_move_to_next_buf(struct intel_guc *guc)
smp_wmb();
 
/* All data has been written, so now move the offset of sub buffer. */
-   relay_reserve(guc->log.relay_chan, guc->log.vma->obj->base.size);
+   relay_reserve(guc->log.runtime.relay_chan, 
guc->log.vma->obj->base.size);
 
/* Switch to the next sub buffer */
-   relay_flush(guc->log.relay_chan);
+   relay_flush(guc->log.runtime.relay_chan);
 }
 
 static void *guc_get_write_buffer(struct intel_guc *guc)
 {
-   if (!guc->log.relay_chan)
+   if (!guc->log.runtime.relay_chan)
return NULL;
 
/* Just get the base address of a new sub buffer and copy data into it
@@ -202,7 +202,7 @@ static void *guc_get_write_buffer(struct intel_guc *guc)
 * done without using relay_reserve() along with relay_write(). So its
 * better to use relay_reserve() alone.
 */
-   return relay_reserve(guc->log.relay_chan, 0);
+   return relay_reserve(guc->log.runtime.relay_chan, 0);
 }
 
 static bool guc_check_log_buf_overflow(struct intel_guc *guc,
@@ -253,11 +253,11 @@ static void guc_read_update_log_buffer(struct intel_guc 
*guc)
void *src_data, *dst_data;
bool new_overflow;
 
-   if (WARN_ON(!guc->log.buf_addr))
+   if (WARN_ON(!guc->log.runtime.buf_addr))
return;
 
/* Get the pointer to shared GuC log buffer */
-   log_buf_state = src_data = guc->log.buf_addr;
+   log_buf_state = src_data = guc->log.runtime.buf_addr;
 
/* Get the pointer to local buffer to store the logs */
log_buf_snapshot_state = dst_data = guc_get_write_buffer(guc);
@@ -343,17 +343,17 @@ static void guc_read_update_log_buffer(struct intel_guc 
*guc)
 static void capture_logs_work(struct work_struct *work)
 {
struct intel_guc *guc =
-   container_of(work, struct intel_guc, log.flush_work);
+   container_of(work, struct intel_guc, log.runtime.flush_work);
 
guc_log_capture_logs(guc);
 }
 
-static bool guc_log_has_extras(struct intel_guc *guc)
+static bool guc_log_has_runtime(struct intel_guc *guc)
 {
-   return guc->log.buf_addr != NULL;
+   return guc->log.runtime.buf_addr != NULL;
 }
 
-static int guc_log_create_extras(struct intel_guc *guc)
+static int guc_log_runtime_create(struct intel_guc *guc)
 {
struct drm_i915_private *dev_priv = guc_to_i915(guc);
void *vaddr;
@@ -363,7 +363,7 @@ static int guc_log_create_extras(struct intel_guc *guc)
 
lockdep_assert_held(&dev_priv->drm.struct_mutex);
 
-   GEM_BUG_ON(guc_log_has_extras(guc));
+   GEM_BUG_ON(guc_log_has_runtime(guc));
 
/* Create a WC (Uncached for read) vmalloc mapping of log
 * buffer 

[Intel-gfx] [PATCH 11/13] drm/i915/guc: Split out the mmio_white_list struct

2017-03-22 Thread Oscar Mateo
We are going to need it for future platforms.

Cc: Joonas Lahtinen 
Signed-off-by: Oscar Mateo 
Reviewed-by: Daniele Ceraolo Spurio 
---
 drivers/gpu/drm/i915/i915_guc_submission.c |  4 ++--
 drivers/gpu/drm/i915/intel_guc_fwif.h  | 15 ---
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index 735dcba..3d78a6b 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -1050,11 +1050,11 @@ static int guc_ads_create(struct intel_guc *guc)
 
/* MMIO reg state */
for_each_engine(engine, dev_priv, id) {
-   blob->reg_state.mmio_white_list[engine->guc_id].mmio_start =
+   blob->reg_state.white_list[engine->guc_id].mmio_start =
engine->mmio_base + GUC_MMIO_WHITE_LIST_START;
 
/* Nothing to be saved or restored for now. */
-   blob->reg_state.mmio_white_list[engine->guc_id].count = 0;
+   blob->reg_state.white_list[engine->guc_id].count = 0;
}
 
/*
diff --git a/drivers/gpu/drm/i915/intel_guc_fwif.h 
b/drivers/gpu/drm/i915/intel_guc_fwif.h
index 18131b7..cb36cbf 100644
--- a/drivers/gpu/drm/i915/intel_guc_fwif.h
+++ b/drivers/gpu/drm/i915/intel_guc_fwif.h
@@ -409,16 +409,17 @@ struct guc_mmio_regset {
u32 number_of_registers;
 } __packed;
 
+/* MMIO registers that are set as non privileged */
+struct mmio_white_list {
+   u32 mmio_start;
+   u32 offsets[GUC_MMIO_WHITE_LIST_MAX];
+   u32 count;
+} __packed;
+
 struct guc_mmio_reg_state {
struct guc_mmio_regset global_reg;
struct guc_mmio_regset engine_reg[GUC_MAX_ENGINES_NUM];
-
-   /* MMIO registers that are set as non privileged */
-   struct __packed {
-   u32 mmio_start;
-   u32 offsets[GUC_MMIO_WHITE_LIST_MAX];
-   u32 count;
-   } mmio_white_list[GUC_MAX_ENGINES_NUM];
+   struct mmio_white_list white_list[GUC_MAX_ENGINES_NUM];
 } __packed;
 
 /* GuC Additional Data Struct */
-- 
1.9.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH] drm/i915: Reduce Data Link N value for 1 lane DP->hdmi converters

2017-03-22 Thread clinton . a . taylor
From: Clint Taylor 

Several major vendor USB-C->HDMI converters fail to recover a 5.4 GHz 1 lane
signal if the Data Link N is greater than 0x8.
Patch detects when 1 lane 5.4 GHz signal is being used and makes the maximum
value 20 bit instead of the maximum specification supported 24 bit value.

Cc: Jani Nikula 
Cc: Anusha Srivatsa 

Signed-off-by: Clint Taylor 
---
 drivers/gpu/drm/i915/i915_reg.h  |2 ++
 drivers/gpu/drm/i915/intel_display.c |   15 +++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 04c8f69..838d8d5 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -4869,6 +4869,8 @@ enum {
 
 #define  DATA_LINK_M_N_MASK(0xff)
 #define  DATA_LINK_N_MAX   (0x80)
+/* Maximum N value useable on some DP->HDMI converters */
+#define  DATA_LINK_REDUCED_N_MAX (0x8)
 
 #define _PIPEA_DATA_N_G4X  0x70054
 #define _PIPEB_DATA_N_G4X  0x71054
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 010e5dd..6e1fdd2 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -6315,9 +6315,10 @@ static int intel_crtc_compute_config(struct intel_crtc 
*crtc,
 }
 
 static void compute_m_n(unsigned int m, unsigned int n,
-   uint32_t *ret_m, uint32_t *ret_n)
+   uint32_t *ret_m, uint32_t *ret_n,
+   uint32_t max_link_n)
 {
-   *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
+   *ret_n = min_t(unsigned int, roundup_pow_of_two(n), max_link_n);
*ret_m = div_u64((uint64_t) m * *ret_n, n);
intel_reduce_m_n_ratio(ret_m, ret_n);
 }
@@ -6327,14 +6328,20 @@ static void compute_m_n(unsigned int m, unsigned int n,
   int pixel_clock, int link_clock,
   struct intel_link_m_n *m_n)
 {
+   uint32_t max_link_n = DATA_LINK_N_MAX;
m_n->tu = 64;
 
+   if ((nlanes==1) && (link_clock >= 54))
+   max_link_n = DATA_LINK_REDUCED_N_MAX;
+
compute_m_n(bits_per_pixel * pixel_clock,
link_clock * nlanes * 8,
-   &m_n->gmch_m, &m_n->gmch_n);
+   &m_n->gmch_m, &m_n->gmch_n,
+   max_link_n);
 
compute_m_n(pixel_clock, link_clock,
-   &m_n->link_m, &m_n->link_n);
+   &m_n->link_m, &m_n->link_n,
+   max_link_n);
 }
 
 static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
-- 
1.7.9.5

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v4 4/6] drm/i915: Store brightness level in aux backlight driver

2017-03-22 Thread Puthikorn Voravootivat
Some panel will default to zero brightness when turning the
panel off and on again. This patch stores last brightness level
before turning off and set them back when panel is turning on.

Cc: Jani Nikula 
Signed-off-by: Puthikorn Voravootivat 
---
 drivers/gpu/drm/i915/intel_dp_aux_backlight.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c 
b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
index ae1b6fe67feb..f99cf0a6ae44 100644
--- a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
+++ b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
@@ -95,6 +95,7 @@ intel_dp_aux_set_backlight(struct intel_connector *connector, 
u32 level)
DRM_DEBUG_KMS("Failed to write aux backlight level\n");
return;
}
+   connector->panel.backlight.level = level;
 }
 
 /*
@@ -150,6 +151,7 @@ static void intel_dp_aux_enable_backlight(struct 
intel_connector *connector)
drm_dp_dpcd_writeb(&intel_dp->aux,
DP_EDP_BACKLIGHT_MODE_SET_REGISTER, new_dpcd_buf);
}
+   intel_dp_aux_set_backlight(connector, connector->panel.backlight.level);
 }
 
 static void intel_dp_aux_disable_backlight(struct intel_connector *connector)
-- 
2.12.1.500.gab5fba24ee-goog

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v4 0/6] Enhancement to intel_dp_aux_backlight driver

2017-03-22 Thread Puthikorn Voravootivat
Rebase since this is not applied cleanly now.

This patch set contain 6 patches.
- First two patches allow enable DPCD backlight control when panel
  can also do that via PWM pin and fix the usage of enable register.
- Next patch adds enable DBC by default
- Next patch makes the driver restore last brightness level after
  turning display off and on.
- Last two patches set the PWM freqency to match data in panel vbt.

Change log:
v2:
- Drop PWM frequency patch
- Addess suggestion from Jani Nikula

v3:
- Add new implementation of PWM frequency patch

v4:
- Rebase / minor typo fix.

Puthikorn Voravootivat (6):
  drm/i915: Add DPCD prefered mode for backlight control
  drm/i915: Correctly enable blacklight adjustment via DPCD
  drm/i915: Support dynamic backlight via DPCD register
  drm/i915: Store brightness level in aux backlight driver
  drm: Add definition for eDP backlight frequency
  drm/i915: Set PWM divider to match desired frequency in vbt

 drivers/gpu/drm/i915/i915_params.c|   6 +-
 drivers/gpu/drm/i915/i915_params.h|   2 +-
 drivers/gpu/drm/i915/intel_dp_aux_backlight.c | 143 +++---
 include/drm/drm_dp_helper.h   |   2 +
 4 files changed, 133 insertions(+), 20 deletions(-)

-- 
2.12.1.500.gab5fba24ee-goog

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v4 1/6] drm/i915: Add DPCD preferred mode for backlight control

2017-03-22 Thread Puthikorn Voravootivat
Currently the intel_dp_aux_backlight driver requires eDP panel
to not also support backlight adjustment via PWM pin to use
this driver.

This force the eDP panel that support both ways of backlight
adjustment to do it via PWM pin.

This patch adds the new prefer DPCD mode in the i915_param
to make it enable to prefer DPCD over the PWM via kernel param.

This patch also add a check to DP_EDP_BACKLIGHT_AUX_ENABLE_CAP
in set_aux_backlight_enable() since the backlight enablement
can be done via BL_ENABLE eDP connector pin in the case that
it does not support doing that via AUX.

Cc: Jani Nikula 
Signed-off-by: Puthikorn Voravootivat 
---
 drivers/gpu/drm/i915/i915_params.c|  6 ++---
 drivers/gpu/drm/i915/i915_params.h|  2 +-
 drivers/gpu/drm/i915/intel_dp_aux_backlight.c | 33 +++
 3 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_params.c 
b/drivers/gpu/drm/i915/i915_params.c
index b6a7e363d076..960393dd5edf 100644
--- a/drivers/gpu/drm/i915/i915_params.c
+++ b/drivers/gpu/drm/i915/i915_params.c
@@ -63,7 +63,7 @@ struct i915_params i915 __read_mostly = {
.huc_firmware_path = NULL,
.enable_dp_mst = true,
.inject_load_failure = 0,
-   .enable_dpcd_backlight = false,
+   .enable_dpcd_backlight = 0,
.enable_gvt = false,
 };
 
@@ -246,9 +246,9 @@ MODULE_PARM_DESC(enable_dp_mst,
 module_param_named_unsafe(inject_load_failure, i915.inject_load_failure, uint, 
0400);
 MODULE_PARM_DESC(inject_load_failure,
"Force an error after a number of failure check points (0:disabled 
(default), N:force failure at the Nth failure check point)");
-module_param_named(enable_dpcd_backlight, i915.enable_dpcd_backlight, bool, 
0600);
+module_param_named(enable_dpcd_backlight, i915.enable_dpcd_backlight, int, 
0600);
 MODULE_PARM_DESC(enable_dpcd_backlight,
-   "Enable support for DPCD backlight control (default:false)");
+   "Enable support for DPCD backlight control (0:disable (default), 
1:prefer PWM pin, 2: prefer DPCD)");
 
 module_param_named(enable_gvt, i915.enable_gvt, bool, 0400);
 MODULE_PARM_DESC(enable_gvt,
diff --git a/drivers/gpu/drm/i915/i915_params.h 
b/drivers/gpu/drm/i915/i915_params.h
index 34148cc8637c..bf6e2c60f697 100644
--- a/drivers/gpu/drm/i915/i915_params.h
+++ b/drivers/gpu/drm/i915/i915_params.h
@@ -51,6 +51,7 @@
func(int, use_mmio_flip); \
func(int, mmio_debug); \
func(int, edp_vswing); \
+   func(int, enable_dpcd_backlight); \
func(unsigned int, inject_load_failure); \
/* leave bools at the end to not create holes */ \
func(bool, alpha_support); \
@@ -66,7 +67,6 @@
func(bool, verbose_state_checks); \
func(bool, nuclear_pageflip); \
func(bool, enable_dp_mst); \
-   func(bool, enable_dpcd_backlight); \
func(bool, enable_gvt)
 
 #define MEMBER(T, member) T member
diff --git a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c 
b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
index 6532e226db29..42f73d9a3ccf 100644
--- a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
+++ b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
@@ -28,6 +28,10 @@ static void set_aux_backlight_enable(struct intel_dp 
*intel_dp, bool enable)
 {
uint8_t reg_val = 0;
 
+   /* Early return when display use other mechanism to enable backlight. */
+   if (!(intel_dp->edp_dpcd[1] & DP_EDP_BACKLIGHT_AUX_ENABLE_CAP))
+   return;
+
if (drm_dp_dpcd_readb(&intel_dp->aux, DP_EDP_DISPLAY_CONTROL_REGISTER,
  ®_val) < 0) {
DRM_DEBUG_KMS("Failed to read DPCD register 0x%x\n",
@@ -138,27 +142,36 @@ static bool
 intel_dp_aux_display_control_capable(struct intel_connector *connector)
 {
struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
+   bool supported;
 
/* Check the  eDP Display control capabilities registers to determine if
 * the panel can support backlight control over the aux channel
 */
-   if (intel_dp->edp_dpcd[1] & DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP &&
-   (intel_dp->edp_dpcd[1] & DP_EDP_BACKLIGHT_AUX_ENABLE_CAP) &&
-   !((intel_dp->edp_dpcd[1] & DP_EDP_BACKLIGHT_PIN_ENABLE_CAP) ||
- (intel_dp->edp_dpcd[2] & 
DP_EDP_BACKLIGHT_BRIGHTNESS_PWM_PIN_CAP))) {
-   DRM_DEBUG_KMS("AUX Backlight Control Supported!\n");
-   return true;
+   switch (i915.enable_dpcd_backlight) {
+   case 1: /* prefer PWM pin */
+   supported = (intel_dp->edp_dpcd[1] & 
DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP) &&
+   (intel_dp->edp_dpcd[1] & 
DP_EDP_BACKLIGHT_AUX_ENABLE_CAP) &&
+   !(intel_dp->edp_dpcd[1] & 
DP_EDP_BACKLIGHT_PIN_ENABLE_CAP) &&
+   !(intel_dp->edp_dpcd[2] & 
DP_EDP_BACKLIGHT_BRIGHTNESS_PWM_PIN_CAP);
+   break;
+   case 2: /* prefer DPCD */
+  

[Intel-gfx] [PATCH v4 2/6] drm/i915: Correctly enable blacklight adjustment via DPCD

2017-03-22 Thread Puthikorn Voravootivat
intel_dp_aux_enable_backlight() assumed that the register
BACKLIGHT_BRIGHTNESS_CONTROL_MODE can only has value 01
(DP_EDP_BACKLIGHT_CONTROL_MODE_PRESET) when initialize.

This patch fixed that by handling all cases of that register.

Cc: Jani Nikula 
Signed-off-by: Puthikorn Voravootivat 
---
 drivers/gpu/drm/i915/intel_dp_aux_backlight.c | 29 +--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c 
b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
index 42f73d9a3ccf..f06c8381c74e 100644
--- a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
+++ b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
@@ -101,15 +101,32 @@ static void intel_dp_aux_enable_backlight(struct 
intel_connector *connector)
 {
struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
uint8_t dpcd_buf = 0;
+   uint8_t edp_backlight_mode = 0;
 
set_aux_backlight_enable(intel_dp, true);
 
-   if ((drm_dp_dpcd_readb(&intel_dp->aux,
-  DP_EDP_BACKLIGHT_MODE_SET_REGISTER, &dpcd_buf) 
== 1) &&
-   ((dpcd_buf & DP_EDP_BACKLIGHT_CONTROL_MODE_MASK) ==
-DP_EDP_BACKLIGHT_CONTROL_MODE_PRESET))
-   drm_dp_dpcd_writeb(&intel_dp->aux, 
DP_EDP_BACKLIGHT_MODE_SET_REGISTER,
-  (dpcd_buf | 
DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD));
+   if (!drm_dp_dpcd_readb(&intel_dp->aux,
+  DP_EDP_BACKLIGHT_MODE_SET_REGISTER, &dpcd_buf)) {
+   return;
+   }
+
+   edp_backlight_mode = dpcd_buf & DP_EDP_BACKLIGHT_CONTROL_MODE_MASK;
+
+   switch (edp_backlight_mode) {
+   case DP_EDP_BACKLIGHT_CONTROL_MODE_PWM:
+   case DP_EDP_BACKLIGHT_CONTROL_MODE_PRESET:
+   case DP_EDP_BACKLIGHT_CONTROL_MODE_PRODUCT:
+   dpcd_buf &= ~DP_EDP_BACKLIGHT_CONTROL_MODE_MASK;
+   dpcd_buf |= DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD;
+   drm_dp_dpcd_writeb(&intel_dp->aux,
+   DP_EDP_BACKLIGHT_MODE_SET_REGISTER, dpcd_buf);
+   break;
+
+   /* Do nothing when it is already DPCD mode */
+   case DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD:
+   default:
+   break;
+   }
 }
 
 static void intel_dp_aux_disable_backlight(struct intel_connector *connector)
-- 
2.12.1.500.gab5fba24ee-goog

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v4 6/6] drm/i915: Set PWM divider to match desired frequency in vbt

2017-03-22 Thread Puthikorn Voravootivat
Read desired PWM frequency from panel vbt and calculate the
value for divider in DPCD address 0x724 and 0x728 to match
that frequency as close as possible.

Cc: Jani Nikula 
Signed-off-by: Puthikorn Voravootivat 
---
 drivers/gpu/drm/i915/intel_dp_aux_backlight.c | 56 +++
 1 file changed, 56 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c 
b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
index f99cf0a6ae44..9adc77bfb515 100644
--- a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
+++ b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
@@ -111,12 +111,60 @@ intel_dp_aux_set_dynamic_backlight_percent(struct 
intel_dp *intel_dp,
  dbc, sizeof(dbc));
 }
 
+/*
+ * Set PWM Frequency divider to match desired frequency in vbt.
+ * The PWM Frequency is calculated as 27Mhz / (F x P).
+ * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the
+ * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h)
+ * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the
+ * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h)
+ */
+static void intel_dp_aux_set_pwm_freq(struct intel_connector *connector)
+{
+   struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
+   struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
+   int freq, fxp, f;
+   u8 pn, pn_min, pn_max;
+
+   /* Find desired value of (F x P)
+* Note that, if F x P is out of supported range, the maximum value or
+* minimum value will applied automatically. So no need to check that.
+*/
+   freq = dev_priv->vbt.backlight.pwm_freq_hz;
+   fxp = DP_EDP_BACKLIGHT_FREQ_BASE / freq;
+
+   /* Use lowest possible value of Pn to try to make F to be between 1 and
+* 255 while still in the range Pn_min and Pn_max
+*/
+   if (!drm_dp_dpcd_readb(&intel_dp->aux,
+  DP_EDP_PWMGEN_BIT_COUNT_CAP_MIN, &pn_min)) {
+   return;
+   }
+   if (!drm_dp_dpcd_readb(&intel_dp->aux,
+  DP_EDP_PWMGEN_BIT_COUNT_CAP_MAX, &pn_max)) {
+   return;
+   }
+   pn_min &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
+   pn_max &= DP_EDP_PWMGEN_BIT_COUNT_MASK;
+   f = fxp / (1 << pn_min);
+   for (pn = pn_min; pn < pn_max && f > 255; pn++)
+   f /= 2;
+
+   /* Cap F to be in the range between 1 and 255. */
+   f = min(f, 255);
+   f = max(f, 1);
+
+   drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_PWMGEN_BIT_COUNT, pn);
+   drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_BACKLIGHT_FREQ_SET, (u8) f);
+}
+
 static void intel_dp_aux_enable_backlight(struct intel_connector *connector)
 {
struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
uint8_t dpcd_buf = 0;
uint8_t new_dpcd_buf = 0;
uint8_t edp_backlight_mode = 0;
+   bool freq_cap;
 
set_aux_backlight_enable(intel_dp, true);
 
@@ -147,10 +195,18 @@ static void intel_dp_aux_enable_backlight(struct 
intel_connector *connector)
intel_dp_aux_set_dynamic_backlight_percent(intel_dp, 0, 100);
}
 
+   freq_cap = intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP;
+   if (freq_cap)
+   new_dpcd_buf |= DP_EDP_BACKLIGHT_FREQ_AUX_SET_ENABLE;
+
if (new_dpcd_buf != dpcd_buf) {
drm_dp_dpcd_writeb(&intel_dp->aux,
DP_EDP_BACKLIGHT_MODE_SET_REGISTER, new_dpcd_buf);
}
+
+   if (freq_cap)
+   intel_dp_aux_set_pwm_freq(connector);
+
intel_dp_aux_set_backlight(connector, connector->panel.backlight.level);
 }
 
-- 
2.12.1.500.gab5fba24ee-goog

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v4 3/6] drm/i915: Support dynamic backlight via DPCD register

2017-03-22 Thread Puthikorn Voravootivat
This patch enables dynamic backlight by default for eDP
panel that supports this feature via DPCD register and
set minimum / maximum brightness to 0% and 100% of the
normal brightness.

Cc: Jani Nikula 
Signed-off-by: Puthikorn Voravootivat 
---
 drivers/gpu/drm/i915/intel_dp_aux_backlight.c | 31 +++
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c 
b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
index f06c8381c74e..ae1b6fe67feb 100644
--- a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
+++ b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c
@@ -97,10 +97,24 @@ intel_dp_aux_set_backlight(struct intel_connector 
*connector, u32 level)
}
 }
 
+/*
+ * Set minimum / maximum dynamic brightness percentage. This value is expressed
+ * as the percentage of normal brightness in 5% increments.
+ */
+static void
+intel_dp_aux_set_dynamic_backlight_percent(struct intel_dp *intel_dp,
+  u32 min, u32 max)
+{
+   u8 dbc[] = { DIV_ROUND_CLOSEST(min, 5), DIV_ROUND_CLOSEST(max, 5) };
+   drm_dp_dpcd_write(&intel_dp->aux, DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET,
+ dbc, sizeof(dbc));
+}
+
 static void intel_dp_aux_enable_backlight(struct intel_connector *connector)
 {
struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base);
uint8_t dpcd_buf = 0;
+   uint8_t new_dpcd_buf = 0;
uint8_t edp_backlight_mode = 0;
 
set_aux_backlight_enable(intel_dp, true);
@@ -110,16 +124,15 @@ static void intel_dp_aux_enable_backlight(struct 
intel_connector *connector)
return;
}
 
+   new_dpcd_buf = dpcd_buf;
edp_backlight_mode = dpcd_buf & DP_EDP_BACKLIGHT_CONTROL_MODE_MASK;
 
switch (edp_backlight_mode) {
case DP_EDP_BACKLIGHT_CONTROL_MODE_PWM:
case DP_EDP_BACKLIGHT_CONTROL_MODE_PRESET:
case DP_EDP_BACKLIGHT_CONTROL_MODE_PRODUCT:
-   dpcd_buf &= ~DP_EDP_BACKLIGHT_CONTROL_MODE_MASK;
-   dpcd_buf |= DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD;
-   drm_dp_dpcd_writeb(&intel_dp->aux,
-   DP_EDP_BACKLIGHT_MODE_SET_REGISTER, dpcd_buf);
+   new_dpcd_buf &= ~DP_EDP_BACKLIGHT_CONTROL_MODE_MASK;
+   new_dpcd_buf |= DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD;
break;
 
/* Do nothing when it is already DPCD mode */
@@ -127,6 +140,16 @@ static void intel_dp_aux_enable_backlight(struct 
intel_connector *connector)
default:
break;
}
+
+   if (intel_dp->edp_dpcd[2] & DP_EDP_DYNAMIC_BACKLIGHT_CAP) {
+   new_dpcd_buf |= DP_EDP_DYNAMIC_BACKLIGHT_ENABLE;
+   intel_dp_aux_set_dynamic_backlight_percent(intel_dp, 0, 100);
+   }
+
+   if (new_dpcd_buf != dpcd_buf) {
+   drm_dp_dpcd_writeb(&intel_dp->aux,
+   DP_EDP_BACKLIGHT_MODE_SET_REGISTER, new_dpcd_buf);
+   }
 }
 
 static void intel_dp_aux_disable_backlight(struct intel_connector *connector)
-- 
2.12.1.500.gab5fba24ee-goog

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v4 5/6] drm: Add definition for eDP backlight frequency

2017-03-22 Thread Puthikorn Voravootivat
This patch adds the following definition
- Bit mask for EDP_PWMGEN_BIT_COUNT and min/max cap
  register which only use bit 0:4
- Base frequency (27 MHz) for backlight PWM frequency
  generator.

Cc: Jani Nikula 
Signed-off-by: Puthikorn Voravootivat 
---
 include/drm/drm_dp_helper.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
index ba89295c8651..8fba8c6e6231 100644
--- a/include/drm/drm_dp_helper.h
+++ b/include/drm/drm_dp_helper.h
@@ -572,10 +572,12 @@
 #define DP_EDP_PWMGEN_BIT_COUNT 0x724
 #define DP_EDP_PWMGEN_BIT_COUNT_CAP_MIN 0x725
 #define DP_EDP_PWMGEN_BIT_COUNT_CAP_MAX 0x726
+# define  DP_EDP_PWMGEN_BIT_COUNT_MASK  (31 << 0)
 
 #define DP_EDP_BACKLIGHT_CONTROL_STATUS 0x727
 
 #define DP_EDP_BACKLIGHT_FREQ_SET   0x728
+# define DP_EDP_BACKLIGHT_FREQ_BASE 2700
 
 #define DP_EDP_BACKLIGHT_FREQ_CAP_MIN_MSB   0x72a
 #define DP_EDP_BACKLIGHT_FREQ_CAP_MIN_MID   0x72b
-- 
2.12.1.500.gab5fba24ee-goog

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH] drm/i915: Actually pass the reclaim gfp_t along to shmemfs!

2017-03-22 Thread Chris Wilson
Words cannot describe the embarrassment at creating a new gfp_t relaim to
only prevent the oomkiller but allow direct|kswapd reclaim, and then not
use it in the shmem_read_mapping_page_gfp().

Fixes: 24f8e00a8a2e ("drm/i915: Prefer to report ENOMEM rather than incur the 
oom for gfx allocations")
Signed-off-by: Chris Wilson 
Cc: Joonas Lahtinen 
Cc: Daniel Vetter 
---
 drivers/gpu/drm/i915/i915_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 96fc76d44145..174c85618450 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2312,7 +2312,7 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object 
*obj)
reclaim = mapping_gfp_constraint(mapping, 0);
reclaim |= __GFP_NORETRY; /* reclaim, but no oom */
 
-   page = shmem_read_mapping_page_gfp(mapping, i, gfp);
+   page = shmem_read_mapping_page_gfp(mapping, i, reclaim);
if (IS_ERR(page)) {
ret = PTR_ERR(page);
goto err_sg;
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v5 4/8] drm: Add driver-private objects to atomic state

2017-03-22 Thread Dhinakaran Pandiyan
From: "Pandiyan, Dhinakaran" 

It is necessary to track states for objects other than connector, crtc
and plane for atomic modesets. But adding objects like DP MST link
bandwidth to drm_atomic_state would mean that a non-core object will be
modified by the core helper functions for swapping and clearing
it's state. So, lets add void * objects and helper functions that operate
on void * types to keep these objects and states private to the core.
Drivers can then implement specific functions to swap and clear states.
The other advantage having just void * for these objects in
drm_atomic_state is that objects of different types can be managed in the
same state array.

v4: Avoid redundant NULL checks when private_objs array is empty (Maarten)
v3: Macro alignment (Chris)
v2: Added docs and new iterator to filter private objects (Daniel)

Acked-by: Harry Wentland 
Suggested-by: Daniel Vetter 
Signed-off-by: Dhinakaran Pandiyan 
---
 drivers/gpu/drm/drm_atomic.c| 69 +++
 drivers/gpu/drm/drm_atomic_helper.c |  5 ++
 include/drm/drm_atomic.h| 93 +
 3 files changed, 167 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 9b892af..e590148 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -57,6 +57,7 @@ void drm_atomic_state_default_release(struct drm_atomic_state 
*state)
kfree(state->connectors);
kfree(state->crtcs);
kfree(state->planes);
+   kfree(state->private_objs);
 }
 EXPORT_SYMBOL(drm_atomic_state_default_release);
 
@@ -184,6 +185,21 @@ void drm_atomic_state_default_clear(struct 
drm_atomic_state *state)
state->planes[i].ptr = NULL;
state->planes[i].state = NULL;
}
+
+   for (i = 0; i < state->num_private_objs; i++) {
+   void *private_obj = state->private_objs[i].obj;
+   void *obj_state = state->private_objs[i].obj_state;
+
+   if (!private_obj)
+   continue;
+
+   state->private_objs[i].funcs->destroy_state(obj_state);
+   state->private_objs[i].obj = NULL;
+   state->private_objs[i].obj_state = NULL;
+   state->private_objs[i].funcs = NULL;
+   }
+   state->num_private_objs = 0;
+
 }
 EXPORT_SYMBOL(drm_atomic_state_default_clear);
 
@@ -978,6 +994,59 @@ static void drm_atomic_plane_print_state(struct 
drm_printer *p,
 }
 
 /**
+ * drm_atomic_get_private_obj_state - get private object state
+ * @state: global atomic state
+ * @obj: private object to get the state for
+ * @funcs: pointer to the struct of function pointers that identify the object
+ * type
+ *
+ * This function returns the private object state for the given private object,
+ * allocating the state if needed. It does not grab any locks as the caller is
+ * expected to care of any required locking.
+ *
+ * RETURNS:
+ *
+ * Either the allocated state or the error code encoded into a pointer.
+ */
+void *
+drm_atomic_get_private_obj_state(struct drm_atomic_state *state, void *obj,
+ const struct drm_private_state_funcs *funcs)
+{
+   int index, num_objs, i;
+   size_t size;
+   struct __drm_private_objs_state *arr;
+
+   for (i = 0; i < state->num_private_objs; i++)
+   if (obj == state->private_objs[i].obj &&
+   state->private_objs[i].obj_state)
+   return state->private_objs[i].obj_state;
+
+   num_objs = state->num_private_objs + 1;
+   size = sizeof(*state->private_objs) * num_objs;
+   arr = krealloc(state->private_objs, size, GFP_KERNEL);
+   if (!arr)
+   return ERR_PTR(-ENOMEM);
+
+   state->private_objs = arr;
+   index = state->num_private_objs;
+   memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
+
+   state->private_objs[index].obj_state = funcs->duplicate_state(state, 
obj);
+   if (!state->private_objs[index].obj_state)
+   return ERR_PTR(-ENOMEM);
+
+   state->private_objs[index].obj = obj;
+   state->private_objs[index].funcs = funcs;
+   state->num_private_objs = num_objs;
+
+   DRM_DEBUG_ATOMIC("Added new private object state %p to %p\n",
+state->private_objs[index].obj_state, state);
+
+   return state->private_objs[index].obj_state;
+}
+EXPORT_SYMBOL(drm_atomic_get_private_obj_state);
+
+/**
  * drm_atomic_get_connector_state - get connector state
  * @state: global atomic state object
  * @connector: connector to get state object for
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 4e26b73..1403334 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2001,6 +2001,8 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state 
*state,
struct drm_plane *plane;
struct drm_plane_stat

[Intel-gfx] [PATCH 17/19] drm: Add explicit acquire ctx handling around ->set_config

2017-03-22 Thread Daniel Vetter
Just the groundwork to have something to feed into ->set_config.
Again we need a temporary hack to still fill out the legacy
ctx in mode_config.acquire_ctx.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_crtc.c | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 05447492483f..bfaa0e769ea6 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -444,7 +444,8 @@ int drm_mode_getcrtc(struct drm_device *dev,
return 0;
 }
 
-static int __drm_mode_set_config_internal(struct drm_mode_set *set)
+static int __drm_mode_set_config_internal(struct drm_mode_set *set,
+ struct drm_modeset_acquire_ctx *ctx)
 {
struct drm_crtc *crtc = set->crtc;
struct drm_framebuffer *fb;
@@ -494,7 +495,7 @@ int drm_mode_set_config_internal(struct drm_mode_set *set)
 {
WARN_ON(drm_drv_uses_atomic_modeset(set->crtc->dev));
 
-   return __drm_mode_set_config_internal(set);
+   return __drm_mode_set_config_internal(set, NULL);
 }
 EXPORT_SYMBOL(drm_mode_set_config_internal);
 
@@ -551,6 +552,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
struct drm_display_mode *mode = NULL;
struct drm_mode_set set;
uint32_t __user *set_connectors_ptr;
+   struct drm_modeset_acquire_ctx ctx;
int ret;
int i;
 
@@ -564,15 +566,19 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
if (crtc_req->x & 0x || crtc_req->y & 0x)
return -ERANGE;
 
-   drm_modeset_lock_all(dev);
crtc = drm_crtc_find(dev, crtc_req->crtc_id);
if (!crtc) {
DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
-   ret = -ENOENT;
-   goto out;
+   return -ENOENT;
}
DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
 
+   drm_modeset_acquire_init(&ctx, 0);
+retry:
+   ret = drm_modeset_lock_all_ctx(crtc->dev, &ctx);
+   if (ret)
+   goto out;
+   dev->mode_config.acquire_ctx = &ctx;
if (crtc_req->mode_valid) {
/* If we have a mode we need a framebuffer. */
/* If we pass -1, set the mode with the currently bound fb */
@@ -693,7 +699,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
set.connectors = connector_set;
set.num_connectors = crtc_req->count_connectors;
set.fb = fb;
-   ret = __drm_mode_set_config_internal(&set);
+   ret = __drm_mode_set_config_internal(&set, &ctx);
 
 out:
if (fb)
@@ -707,7 +713,13 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
}
kfree(connector_set);
drm_mode_destroy(dev, mode);
-   drm_modeset_unlock_all(dev);
+   if (ret == -EDEADLK) {
+   drm_modeset_backoff(&ctx);
+   goto retry;
+   }
+   drm_modeset_drop_locks(&ctx);
+   drm_modeset_acquire_fini(&ctx);
+
return ret;
 }
 
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 12/19] drm/atomic-helper: remove backoff hack from page_flip

2017-03-22 Thread Daniel Vetter
Yay, we can now properly retry in case of deadlocks or whatever!

Also don't forget to remove the transitional crtc->acquire_ctx
assignment again.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic_helper.c | 40 ++---
 drivers/gpu/drm/drm_plane.c |  1 -
 2 files changed, 2 insertions(+), 39 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 0e65ce4497b3..c0ec763ec538 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2885,34 +2885,16 @@ int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
if (!state)
return -ENOMEM;
 
-   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+   state->acquire_ctx = ctx;
 
-retry:
ret = page_flip_common(state, crtc, fb, event, flags);
if (ret != 0)
goto fail;
 
ret = drm_atomic_nonblocking_commit(state);
-
 fail:
-   if (ret == -EDEADLK)
-   goto backoff;
-
drm_atomic_state_put(state);
return ret;
-
-backoff:
-   drm_atomic_state_clear(state);
-   drm_atomic_legacy_backoff(state);
-
-   /*
-* Someone might have exchanged the framebuffer while we dropped locks
-* in the backoff code. We need to fix up the fb refcount tracking the
-* core does for us.
-*/
-   plane->old_fb = plane->fb;
-
-   goto retry;
 }
 EXPORT_SYMBOL(drm_atomic_helper_page_flip);
 
@@ -2949,9 +2931,8 @@ int drm_atomic_helper_page_flip_target(
if (!state)
return -ENOMEM;
 
-   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+   state->acquire_ctx = ctx;
 
-retry:
ret = page_flip_common(state, crtc, fb, event, flags);
if (ret != 0)
goto fail;
@@ -2964,26 +2945,9 @@ int drm_atomic_helper_page_flip_target(
crtc_state->target_vblank = target;
 
ret = drm_atomic_nonblocking_commit(state);
-
 fail:
-   if (ret == -EDEADLK)
-   goto backoff;
-
drm_atomic_state_put(state);
return ret;
-
-backoff:
-   drm_atomic_state_clear(state);
-   drm_atomic_legacy_backoff(state);
-
-   /*
-* Someone might have exchanged the framebuffer while we dropped locks
-* in the backoff code. We need to fix up the fb refcount tracking the
-* core does for us.
-*/
-   plane->old_fb = plane->fb;
-
-   goto retry;
 }
 EXPORT_SYMBOL(drm_atomic_helper_page_flip_target);
 
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 373e980d698d..ec3e2e757800 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -875,7 +875,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
ret = drm_modeset_lock(&crtc->cursor->mutex, &ctx);
if (ret)
goto out;
-   crtc->acquire_ctx = &ctx;
 
if (crtc->primary->fb == NULL) {
/* The framebuffer is currently unbound, presumably
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 15/19] drm: Remove drm_modeset_legacy_acquire_ctx and crtc->acquire_ctx

2017-03-22 Thread Daniel Vetter
With all the callers of drm_modeset_lock_crtc gone, and all the places
it was formerly used properly wiring the acquire ctx through, we can
remove this.

The only hidden context magic we still have is now the global one.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic.c  | 14 --
 drivers/gpu/drm/drm_atomic_helper.c   |  4 ++--
 drivers/gpu/drm/drm_modeset_lock.c| 21 -
 drivers/gpu/drm/i915/intel_display.c  |  4 ++--
 drivers/gpu/drm/i915/intel_pipe_crc.c |  2 +-
 include/drm/drm_crtc.h|  9 -
 include/drm/drm_modeset_lock.h|  2 --
 7 files changed, 5 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 9b892af7811a..345310213820 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1516,19 +1516,9 @@ EXPORT_SYMBOL(drm_atomic_add_affected_planes);
 void drm_atomic_legacy_backoff(struct drm_atomic_state *state)
 {
struct drm_device *dev = state->dev;
-   unsigned crtc_mask = 0;
-   struct drm_crtc *crtc;
int ret;
bool global = false;
 
-   drm_for_each_crtc(crtc, dev) {
-   if (crtc->acquire_ctx != state->acquire_ctx)
-   continue;
-
-   crtc_mask |= drm_crtc_mask(crtc);
-   crtc->acquire_ctx = NULL;
-   }
-
if (WARN_ON(dev->mode_config.acquire_ctx == state->acquire_ctx)) {
global = true;
 
@@ -1542,10 +1532,6 @@ void drm_atomic_legacy_backoff(struct drm_atomic_state 
*state)
if (ret)
goto retry;
 
-   drm_for_each_crtc(crtc, dev)
-   if (drm_crtc_mask(crtc) & crtc_mask)
-   crtc->acquire_ctx = state->acquire_ctx;
-
if (global)
dev->mode_config.acquire_ctx = state->acquire_ctx;
 }
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index c0ec763ec538..08d10abcece0 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2289,7 +2289,7 @@ int drm_atomic_helper_set_config(struct drm_mode_set *set)
return -ENOMEM;
 
state->legacy_set_config = true;
-   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+   state->acquire_ctx = crtc->dev->mode_config.acquire_ctx;
 retry:
ret = __drm_atomic_helper_set_config(set, state);
if (ret != 0)
@@ -2990,7 +2990,7 @@ int drm_atomic_helper_connector_dpms(struct drm_connector 
*connector,
if (!state)
return -ENOMEM;
 
-   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+   state->acquire_ctx = crtc->dev->mode_config.acquire_ctx;
 retry:
crtc_state = drm_atomic_get_crtc_state(state, crtc);
if (IS_ERR(crtc_state)) {
diff --git a/drivers/gpu/drm/drm_modeset_lock.c 
b/drivers/gpu/drm/drm_modeset_lock.c
index c3ca6b859236..64ef09a6cccb 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -149,27 +149,6 @@ void drm_modeset_unlock_all(struct drm_device *dev)
 EXPORT_SYMBOL(drm_modeset_unlock_all);
 
 /**
- * drm_modeset_legacy_acquire_ctx - find acquire ctx for legacy ioctls
- * @crtc: drm crtc
- *
- * Legacy ioctl operations like cursor updates or page flips only have per-crtc
- * locking, and store the acquire ctx in the corresponding crtc. All other
- * legacy operations take all locks and use a global acquire context. This
- * function grabs the right one.
- */
-struct drm_modeset_acquire_ctx *
-drm_modeset_legacy_acquire_ctx(struct drm_crtc *crtc)
-{
-   if (crtc->acquire_ctx)
-   return crtc->acquire_ctx;
-
-   WARN_ON(!crtc->dev->mode_config.acquire_ctx);
-
-   return crtc->dev->mode_config.acquire_ctx;
-}
-EXPORT_SYMBOL(drm_modeset_legacy_acquire_ctx);
-
-/**
  * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
  * @dev: device
  *
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index e27ea89efd67..84abff3f43d9 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -10715,7 +10715,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
state = drm_atomic_state_alloc(dev);
if (!state)
return -ENOMEM;
-   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+   state->acquire_ctx = dev->mode_config.acquire_ctx;
 
 retry:
plane_state = drm_atomic_get_plane_state(state, primary);
@@ -13075,7 +13075,7 @@ void intel_crtc_restore_mode(struct drm_crtc *crtc)
return;
}
 
-   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+   state->acquire_ctx = crtc->dev->mode_config.acquire_ctx;
 
 retry:
crtc_state = drm_atomic_get_crtc_state(state, crtc);
diff --git a/drivers/gpu/drm/i915/intel_pipe_crc.c 
b/drive

[Intel-gfx] [PATCH 13/19] drm: simplify the locking in the GETCRTC ioctl

2017-03-22 Thread Daniel Vetter
No need to grab both plane and crtc locks at the same time, we can do
them one after the other. If userspace races it'll get what it
deserves either way.

This removes another user of drm_modeset_lock_crtc. There's only one
left.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_crtc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 660b4c8715de..df1ff0b8818b 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -406,16 +406,18 @@ int drm_mode_getcrtc(struct drm_device *dev,
if (!crtc)
return -ENOENT;
 
-   drm_modeset_lock_crtc(crtc, crtc->primary);
crtc_resp->gamma_size = crtc->gamma_size;
 
+   drm_modeset_lock(&crtc->primary->mutex, NULL);
if (crtc->primary->state && crtc->primary->state->fb)
crtc_resp->fb_id = crtc->primary->state->fb->base.id;
else if (!crtc->primary->state && crtc->primary->fb)
crtc_resp->fb_id = crtc->primary->fb->base.id;
else
crtc_resp->fb_id = 0;
+   drm_modeset_unlock(&crtc->primary->mutex);
 
+   drm_modeset_lock(&crtc->mutex, NULL);
if (crtc->state) {
crtc_resp->x = crtc->primary->state->src_x >> 16;
crtc_resp->y = crtc->primary->state->src_y >> 16;
@@ -437,7 +439,7 @@ int drm_mode_getcrtc(struct drm_device *dev,
crtc_resp->mode_valid = 0;
}
}
-   drm_modeset_unlock_crtc(crtc);
+   drm_modeset_unlock(&crtc->mutex);
 
return 0;
 }
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 19/19] drm/atomic-helper: Remove the backoff hack from set_config

2017-03-22 Thread Daniel Vetter
Another one bites the dust.

Again let's not forget to remove the temporary hidden acquire_ctx
assignment, now that we pass this all around explicitly it can go
away again.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic_helper.c | 21 ++---
 drivers/gpu/drm/drm_crtc.c  |  1 -
 2 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index b502e2809ebd..2df4827305d4 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2291,32 +2291,15 @@ int drm_atomic_helper_set_config(struct drm_mode_set 
*set,
return -ENOMEM;
 
state->legacy_set_config = true;
-   state->acquire_ctx = crtc->dev->mode_config.acquire_ctx;
-retry:
+   state->acquire_ctx = ctx;
ret = __drm_atomic_helper_set_config(set, state);
if (ret != 0)
-   goto fail;
+   return ret;
 
ret = drm_atomic_commit(state);
-fail:
-   if (ret == -EDEADLK)
-   goto backoff;
 
drm_atomic_state_put(state);
return ret;
-
-backoff:
-   drm_atomic_state_clear(state);
-   drm_atomic_legacy_backoff(state);
-
-   /*
-* Someone might have exchanged the framebuffer while we dropped locks
-* in the backoff code. We need to fix up the fb refcount tracking the
-* core does for us.
-*/
-   crtc->primary->old_fb = crtc->primary->fb;
-
-   goto retry;
 }
 EXPORT_SYMBOL(drm_atomic_helper_set_config);
 
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 3fe1ec23c87e..46e5b97a8c87 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -578,7 +578,6 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
ret = drm_modeset_lock_all_ctx(crtc->dev, &ctx);
if (ret)
goto out;
-   dev->mode_config.acquire_ctx = &ctx;
if (crtc_req->mode_valid) {
/* If we have a mode we need a framebuffer. */
/* If we pass -1, set the mode with the currently bound fb */
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 18/19] drm: Add acquire ctx parameter to ->set_config

2017-03-22 Thread Daniel Vetter
Surprisingly a lot of legacy drivers roll their own, for
runtime pm and because vmwgfx.

Also make nouveau's set_config static while at it.

Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Cc: Ben Skeggs 
Cc: Patrik Jakobsson 
Cc: Alex Deucher 
Cc: Christian König 

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 5 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h| 3 ++-
 drivers/gpu/drm/drm_atomic_helper.c | 4 +++-
 drivers/gpu/drm/drm_crtc.c  | 2 +-
 drivers/gpu/drm/drm_crtc_helper.c   | 4 +++-
 drivers/gpu/drm/drm_plane_helper.c  | 2 +-
 drivers/gpu/drm/gma500/gma_display.c| 7 ---
 drivers/gpu/drm/gma500/gma_display.h| 3 ++-
 drivers/gpu/drm/nouveau/dispnv04/crtc.c | 7 ---
 drivers/gpu/drm/nouveau/nouveau_display.h   | 1 -
 drivers/gpu/drm/radeon/radeon_display.c | 5 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 3 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c| 3 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c| 3 ++-
 include/drm/drm_atomic_helper.h | 3 ++-
 include/drm/drm_crtc.h  | 3 ++-
 include/drm/drm_crtc_helper.h   | 3 ++-
 17 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index 7b4fe91d3aec..ce15721cadda 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -333,7 +333,8 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
return 0;
 }
 
-int amdgpu_crtc_set_config(struct drm_mode_set *set)
+int amdgpu_crtc_set_config(struct drm_mode_set *set,
+  struct drm_modeset_acquire_ctx *ctx)
 {
struct drm_device *dev;
struct amdgpu_device *adev;
@@ -350,7 +351,7 @@ int amdgpu_crtc_set_config(struct drm_mode_set *set)
if (ret < 0)
return ret;
 
-   ret = drm_crtc_helper_set_config(set);
+   ret = drm_crtc_helper_set_config(set, ctx);
 
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
if (crtc->enabled)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
index d19b803ba509..20d6522fd7b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
@@ -593,7 +593,8 @@ int amdgpu_align_pitch(struct amdgpu_device *adev, int 
width, int bpp, bool tile
 /* amdgpu_display.c */
 void amdgpu_print_display_setup(struct drm_device *dev);
 int amdgpu_modeset_create_props(struct amdgpu_device *adev);
-int amdgpu_crtc_set_config(struct drm_mode_set *set);
+int amdgpu_crtc_set_config(struct drm_mode_set *set,
+  struct drm_modeset_acquire_ctx *ctx);
 int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
 struct drm_framebuffer *fb,
 struct drm_pending_vblank_event *event,
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 08d10abcece0..b502e2809ebd 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2266,6 +2266,7 @@ static int update_output_state(struct drm_atomic_state 
*state,
 /**
  * drm_atomic_helper_set_config - set a new config from userspace
  * @set: mode set configuration
+ * @ctx: lock acquisition context
  *
  * Provides a default crtc set_config handler using the atomic driver 
interface.
  *
@@ -2278,7 +2279,8 @@ static int update_output_state(struct drm_atomic_state 
*state,
  * Returns:
  * Returns 0 on success, negative errno numbers on failure.
  */
-int drm_atomic_helper_set_config(struct drm_mode_set *set)
+int drm_atomic_helper_set_config(struct drm_mode_set *set,
+struct drm_modeset_acquire_ctx *ctx)
 {
struct drm_atomic_state *state;
struct drm_crtc *crtc = set->crtc;
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index bfaa0e769ea6..3fe1ec23c87e 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -462,7 +462,7 @@ static int __drm_mode_set_config_internal(struct 
drm_mode_set *set,
 
fb = set->fb;
 
-   ret = crtc->funcs->set_config(set);
+   ret = crtc->funcs->set_config(set, ctx);
if (ret == 0) {
crtc->primary->crtc = crtc;
crtc->primary->fb = fb;
diff --git a/drivers/gpu/drm/drm_crtc_helper.c 
b/drivers/gpu/drm/drm_crtc_helper.c
index 8aa8c1084121..4afdf7902eda 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -476,6 +476,7 @@ drm_crtc_helper_disable(struct drm_crtc *crtc)
 /**
  * drm_crtc_helper_set_config - set a new config from userspace
  * @set: mode set configuration
+ * @ctx: lock acquire context, not used here
  *
  * The drm_crtc_helper_set_config() helper function implements the of
  * &drm_crtc_funcs.set_con

[Intel-gfx] [PATCH 16/19] drm: Restrict drm_mode_set_config_internal to non-atomic drivers

2017-03-22 Thread Daniel Vetter
This is another case where we really can't reconstruct a acquire ctx
in any useful fashion because all the callers are legacy drivers. So
like drm_plane_force_disable simply restrict it to non-atomic drivers
so that it's clear we're ok with passing a NULL ctx.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_crtc.c | 34 +-
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index df1ff0b8818b..05447492483f 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -444,18 +444,7 @@ int drm_mode_getcrtc(struct drm_device *dev,
return 0;
 }
 
-/**
- * drm_mode_set_config_internal - helper to call 
&drm_mode_config_funcs.set_config
- * @set: modeset config to set
- *
- * This is a little helper to wrap internal calls to the
- * &drm_mode_config_funcs.set_config driver interface. The only thing it adds 
is
- * correct refcounting dance.
- *
- * Returns:
- * Zero on success, negative errno on failure.
- */
-int drm_mode_set_config_internal(struct drm_mode_set *set)
+static int __drm_mode_set_config_internal(struct drm_mode_set *set)
 {
struct drm_crtc *crtc = set->crtc;
struct drm_framebuffer *fb;
@@ -488,6 +477,25 @@ int drm_mode_set_config_internal(struct drm_mode_set *set)
 
return ret;
 }
+/**
+ * drm_mode_set_config_internal - helper to call 
&drm_mode_config_funcs.set_config
+ * @set: modeset config to set
+ *
+ * This is a little helper to wrap internal calls to the
+ * &drm_mode_config_funcs.set_config driver interface. The only thing it adds 
is
+ * correct refcounting dance.
+ *
+ * This should only be used by non-atomic legacy drivers.
+ *
+ * Returns:
+ * Zero on success, negative errno on failure.
+ */
+int drm_mode_set_config_internal(struct drm_mode_set *set)
+{
+   WARN_ON(drm_drv_uses_atomic_modeset(set->crtc->dev));
+
+   return __drm_mode_set_config_internal(set);
+}
 EXPORT_SYMBOL(drm_mode_set_config_internal);
 
 /**
@@ -685,7 +693,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
set.connectors = connector_set;
set.num_connectors = crtc_req->count_connectors;
set.fb = fb;
-   ret = drm_mode_set_config_internal(&set);
+   ret = __drm_mode_set_config_internal(&set);
 
 out:
if (fb)
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 11/19] drm: Add acquire ctx parameter to ->page_flip(_target)

2017-03-22 Thread Daniel Vetter
Again just going through the motions, no functional changes in here.

Cc: Gerd Hoffmann 
Cc: Ben Skeggs 
Cc: Russell King 
Cc: Laurent Pinchart 
Cc: Eric Anholt 
Cc: Alex Deucher 
Cc: Christian König 
Signed-off-by: Daniel Vetter t
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h| 3 ++-
 drivers/gpu/drm/armada/armada_crtc.c| 3 ++-
 drivers/gpu/drm/bochs/bochs_kms.c   | 3 ++-
 drivers/gpu/drm/drm_atomic_helper.c | 8 ++--
 drivers/gpu/drm/drm_plane.c | 6 --
 drivers/gpu/drm/nouveau/nouveau_display.c   | 3 ++-
 drivers/gpu/drm/nouveau/nouveau_display.h   | 3 ++-
 drivers/gpu/drm/radeon/radeon_display.c | 3 ++-
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c   | 3 ++-
 drivers/gpu/drm/udl/udl_modeset.c   | 3 ++-
 drivers/gpu/drm/vc4/vc4_crtc.c  | 5 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c| 3 ++-
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c| 3 ++-
 include/drm/drm_atomic_helper.h | 6 --
 include/drm/drm_crtc.h  | 6 --
 16 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index 39fc388f222a..7b4fe91d3aec 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -311,7 +311,8 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
 struct drm_framebuffer *fb,
 struct drm_pending_vblank_event *event,
 uint32_t page_flip_flags,
-uint32_t target)
+uint32_t target,
+struct drm_modeset_acquire_ctx *ctx)
 {
struct amdgpu_bo *new_abo;
struct amdgpu_flip_work *work;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
index 6b8f766a6a35..d19b803ba509 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h
@@ -597,7 +597,8 @@ int amdgpu_crtc_set_config(struct drm_mode_set *set);
 int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
 struct drm_framebuffer *fb,
 struct drm_pending_vblank_event *event,
-uint32_t page_flip_flags, uint32_t target);
+uint32_t page_flip_flags, uint32_t target,
+struct drm_modeset_acquire_ctx *ctx);
 void amdgpu_crtc_cleanup_flip_ctx(struct amdgpu_flip_work *work,
  struct amdgpu_bo *new_abo);
 int amdgpu_crtc_prepare_flip(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/armada/armada_crtc.c 
b/drivers/gpu/drm/armada/armada_crtc.c
index 1341e0b9368a..4fe19fde84f9 100644
--- a/drivers/gpu/drm/armada/armada_crtc.c
+++ b/drivers/gpu/drm/armada/armada_crtc.c
@@ -1027,7 +1027,8 @@ static void armada_drm_crtc_destroy(struct drm_crtc *crtc)
  * and a mode_set.
  */
 static int armada_drm_crtc_page_flip(struct drm_crtc *crtc,
-   struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, 
uint32_t page_flip_flags)
+   struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, 
uint32_t page_flip_flags,
+   struct drm_modeset_acquire_ctx *ctx)
 {
struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
struct armada_frame_work *work;
diff --git a/drivers/gpu/drm/bochs/bochs_kms.c 
b/drivers/gpu/drm/bochs/bochs_kms.c
index d5e63eff357b..6a91e62da2f4 100644
--- a/drivers/gpu/drm/bochs/bochs_kms.c
+++ b/drivers/gpu/drm/bochs/bochs_kms.c
@@ -96,7 +96,8 @@ static void bochs_crtc_commit(struct drm_crtc *crtc)
 static int bochs_crtc_page_flip(struct drm_crtc *crtc,
struct drm_framebuffer *fb,
struct drm_pending_vblank_event *event,
-   uint32_t page_flip_flags)
+   uint32_t page_flip_flags,
+   struct drm_modeset_acquire_ctx *ctx)
 {
struct bochs_device *bochs =
container_of(crtc, struct bochs_device, crtc);
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 845378c92ccb..0e65ce4497b3 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2860,6 +2860,7 @@ static int page_flip_common(
  * @fb: DRM framebuffer
  * @event: optional DRM event to signal upon completion
  * @flags: flip flags for non-vblank sync'ed updates
+ * @ctx: lock acquisition context
  *
  * Provides a default &drm_crtc_funcs.page_flip implementation
  * using the atomic driver interface.
@@ -2873,7 +2874,8 @@ static int page_flip_common(
 int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
struct drm_fr

[Intel-gfx] [PATCH 10/19] drm: Roll out acquire context for the page_flip ioctl

2017-03-22 Thread Daniel Vetter
Again just prep work.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_plane.c | 21 +++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 8535dc17db7e..62e833ffeffd 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -803,6 +803,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
struct drm_framebuffer *fb = NULL;
struct drm_pending_vblank_event *e = NULL;
u32 target_vblank = page_flip->sequence;
+   struct drm_modeset_acquire_ctx ctx;
int ret = -EINVAL;
 
if (!drm_core_check_feature(dev, DRIVER_MODESET))
@@ -866,7 +867,16 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
return -EINVAL;
}
 
-   drm_modeset_lock_crtc(crtc, crtc->primary);
+   drm_modeset_acquire_init(&ctx, 0);
+retry:
+   ret = drm_modeset_lock(&crtc->mutex, &ctx);
+   if (ret)
+   goto out;
+   ret = drm_modeset_lock(&crtc->cursor->mutex, &ctx);
+   if (ret)
+   goto out;
+   crtc->acquire_ctx = &ctx;
+
if (crtc->primary->fb == NULL) {
/* The framebuffer is currently unbound, presumably
 * due to a hotplug event, that userspace has not
@@ -944,7 +954,14 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
if (crtc->primary->old_fb)
drm_framebuffer_put(crtc->primary->old_fb);
crtc->primary->old_fb = NULL;
-   drm_modeset_unlock_crtc(crtc);
+
+   if (ret == -EDEADLK) {
+   drm_modeset_backoff(&ctx);
+   goto retry;
+   }
+
+   drm_modeset_drop_locks(&ctx);
+   drm_modeset_acquire_fini(&ctx);
 
return ret;
 }
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 14/19] drm: Remove drm_modeset_(un)lock_crtc

2017-03-22 Thread Daniel Vetter
The last user, the cursor ioctl, can just open-code this too. We
simply have to move the acquire ctx dance from the universal function
up into the top-level ioctl handler.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_crtc_internal.h |  3 --
 drivers/gpu/drm/drm_modeset_lock.c  | 67 -
 drivers/gpu/drm/drm_plane.c | 49 +--
 include/drm/drm_modeset_lock.h  |  1 -
 4 files changed, 24 insertions(+), 96 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc_internal.h 
b/drivers/gpu/drm/drm_crtc_internal.h
index de1047530e07..8c04275cf226 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -61,9 +61,6 @@ int drm_mode_getresources(struct drm_device *dev,
  void *data, struct drm_file *file_priv);
 
 
-/* drm_modeset_lock.c */
-void drm_modeset_lock_crtc(struct drm_crtc *crtc,
-  struct drm_plane *plane);
 /* drm_dumb_buffers.c */
 /* IOCTLs */
 int drm_mode_create_dumb_ioctl(struct drm_device *dev,
diff --git a/drivers/gpu/drm/drm_modeset_lock.c 
b/drivers/gpu/drm/drm_modeset_lock.c
index c94eff9d7544..c3ca6b859236 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -148,51 +148,6 @@ void drm_modeset_unlock_all(struct drm_device *dev)
 }
 EXPORT_SYMBOL(drm_modeset_unlock_all);
 
-void drm_modeset_lock_crtc(struct drm_crtc *crtc,
-  struct drm_plane *plane)
-{
-   struct drm_modeset_acquire_ctx *ctx;
-   int ret;
-
-   ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
-   if (WARN_ON(!ctx))
-   return;
-
-   drm_modeset_acquire_init(ctx, 0);
-
-retry:
-   ret = drm_modeset_lock(&crtc->mutex, ctx);
-   if (ret)
-   goto fail;
-
-   if (plane) {
-   ret = drm_modeset_lock(&plane->mutex, ctx);
-   if (ret)
-   goto fail;
-
-   if (plane->crtc) {
-   ret = drm_modeset_lock(&plane->crtc->mutex, ctx);
-   if (ret)
-   goto fail;
-   }
-   }
-
-   WARN_ON(crtc->acquire_ctx);
-
-   /* now we hold the locks, so now that it is safe, stash the
-* ctx for drm_modeset_unlock_crtc():
-*/
-   crtc->acquire_ctx = ctx;
-
-   return;
-
-fail:
-   if (ret == -EDEADLK) {
-   drm_modeset_backoff(ctx);
-   goto retry;
-   }
-}
-
 /**
  * drm_modeset_legacy_acquire_ctx - find acquire ctx for legacy ioctls
  * @crtc: drm crtc
@@ -215,28 +170,6 @@ drm_modeset_legacy_acquire_ctx(struct drm_crtc *crtc)
 EXPORT_SYMBOL(drm_modeset_legacy_acquire_ctx);
 
 /**
- * drm_modeset_unlock_crtc - drop crtc lock
- * @crtc: drm crtc
- *
- * This drops the crtc lock acquire with drm_modeset_lock_crtc() and all other
- * locks acquired through the hidden context.
- */
-void drm_modeset_unlock_crtc(struct drm_crtc *crtc)
-{
-   struct drm_modeset_acquire_ctx *ctx = crtc->acquire_ctx;
-
-   if (WARN_ON(!ctx))
-   return;
-
-   crtc->acquire_ctx = NULL;
-   drm_modeset_drop_locks(ctx);
-   drm_modeset_acquire_fini(ctx);
-
-   kfree(ctx);
-}
-EXPORT_SYMBOL(drm_modeset_unlock_crtc);
-
-/**
  * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
  * @dev: device
  *
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index ec3e2e757800..ec62221d64a9 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -620,7 +620,8 @@ int drm_mode_setplane(struct drm_device *dev, void *data,
 
 static int drm_mode_cursor_universal(struct drm_crtc *crtc,
 struct drm_mode_cursor2 *req,
-struct drm_file *file_priv)
+struct drm_file *file_priv,
+struct drm_modeset_acquire_ctx *ctx)
 {
struct drm_device *dev = crtc->dev;
struct drm_framebuffer *fb = NULL;
@@ -634,21 +635,11 @@ static int drm_mode_cursor_universal(struct drm_crtc 
*crtc,
int32_t crtc_x, crtc_y;
uint32_t crtc_w = 0, crtc_h = 0;
uint32_t src_w = 0, src_h = 0;
-   struct drm_modeset_acquire_ctx ctx;
int ret = 0;
 
BUG_ON(!crtc->cursor);
WARN_ON(crtc->cursor->crtc != crtc && crtc->cursor->crtc != NULL);
 
-   drm_modeset_acquire_init(&ctx, 0);
-retry:
-   ret = drm_modeset_lock(&crtc->mutex, &ctx);
-   if (ret)
-   goto fail;
-   ret = drm_modeset_lock(&crtc->cursor->mutex, &ctx);
-   if (ret)
-   goto fail;
-
/*
 * Obtain fb we'll be using (either new or existing) and take an extra
 * reference to it if fb != null.  setplane will take care of dropping
@@ -693,7 +684,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
 */
ret = __setplane

[Intel-gfx] [PATCH 04/19] drm: Add acquire ctx parameter to ->plane_disable

2017-03-22 Thread Daniel Vetter
Nouveau had a few direct calls to ->disable_plane, I replaced those
with drm_plane_force_disable. Same story for shmob.

Otherwise no code changes.

Cc: Ben Skeggs 
Cc: Russell King 
Cc: Laurent Pinchart 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/armada/armada_overlay.c|  3 ++-
 drivers/gpu/drm/drm_atomic_helper.c|  4 +++-
 drivers/gpu/drm/drm_plane.c|  4 ++--
 drivers/gpu/drm/drm_plane_helper.c |  5 +++--
 drivers/gpu/drm/nouveau/dispnv04/overlay.c | 12 +++-
 drivers/gpu/drm/shmobile/shmob_drm_plane.c |  5 +++--
 include/drm/drm_atomic_helper.h|  3 ++-
 include/drm/drm_plane.h|  3 ++-
 include/drm/drm_plane_helper.h |  3 ++-
 9 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/armada/armada_overlay.c 
b/drivers/gpu/drm/armada/armada_overlay.c
index b54fd8cbd3a6..424e465ff407 100644
--- a/drivers/gpu/drm/armada/armada_overlay.c
+++ b/drivers/gpu/drm/armada/armada_overlay.c
@@ -258,7 +258,8 @@ armada_ovl_plane_update(struct drm_plane *plane, struct 
drm_crtc *crtc,
return 0;
 }
 
-static int armada_ovl_plane_disable(struct drm_plane *plane)
+static int armada_ovl_plane_disable(struct drm_plane *plane,
+   struct drm_modeset_acquire_ctx *ctx)
 {
struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
struct drm_framebuffer *fb;
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 8ef7c808670b..1142075032a2 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2152,13 +2152,15 @@ EXPORT_SYMBOL(drm_atomic_helper_update_plane);
 /**
  * drm_atomic_helper_disable_plane - Helper for primary plane disable using * 
atomic
  * @plane: plane to disable
+ * @ctx: lock acquire context
  *
  * Provides a default plane disable handler using the atomic driver interface.
  *
  * RETURNS:
  * Zero on success, error code on failure
  */
-int drm_atomic_helper_disable_plane(struct drm_plane *plane)
+int drm_atomic_helper_disable_plane(struct drm_plane *plane,
+   struct drm_modeset_acquire_ctx *ctx)
 {
struct drm_atomic_state *state;
struct drm_plane_state *plane_state;
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 67119332c441..526e74b548b2 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -294,7 +294,7 @@ void drm_plane_force_disable(struct drm_plane *plane)
WARN_ON(drm_drv_uses_atomic_modeset(plane->dev));
 
plane->old_fb = plane->fb;
-   ret = plane->funcs->disable_plane(plane);
+   ret = plane->funcs->disable_plane(plane, NULL);
if (ret) {
DRM_ERROR("failed to disable plane with busy fb\n");
plane->old_fb = NULL;
@@ -473,7 +473,7 @@ static int __setplane_internal(struct drm_plane *plane,
/* No fb means shut it down */
if (!fb) {
plane->old_fb = plane->fb;
-   ret = plane->funcs->disable_plane(plane);
+   ret = plane->funcs->disable_plane(plane, ctx);
if (!ret) {
plane->crtc = NULL;
plane->fb = NULL;
diff --git a/drivers/gpu/drm/drm_plane_helper.c 
b/drivers/gpu/drm/drm_plane_helper.c
index 2339879f775d..775e94c30368 100644
--- a/drivers/gpu/drm/drm_plane_helper.c
+++ b/drivers/gpu/drm/drm_plane_helper.c
@@ -349,7 +349,7 @@ int drm_primary_helper_update(struct drm_plane *plane, 
struct drm_crtc *crtc,
 * provides their own disable function, this will just
 * wind up returning -EINVAL to userspace.
 */
-   return plane->funcs->disable_plane(plane);
+   return plane->funcs->disable_plane(plane, ctx);
 
/* Find current connectors for CRTC */
num_connectors = get_connectors_for_crtc(crtc, NULL, 0);
@@ -398,7 +398,8 @@ EXPORT_SYMBOL(drm_primary_helper_update);
  * RETURNS:
  * Unconditionally returns -EINVAL.
  */
-int drm_primary_helper_disable(struct drm_plane *plane)
+int drm_primary_helper_disable(struct drm_plane *plane,
+  struct drm_modeset_acquire_ctx *ctx)
 {
return -EINVAL;
 }
diff --git a/drivers/gpu/drm/nouveau/dispnv04/overlay.c 
b/drivers/gpu/drm/nouveau/dispnv04/overlay.c
index 2d90e7898ec8..e54944d23268 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/overlay.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/overlay.c
@@ -173,7 +173,8 @@ nv10_update_plane(struct drm_plane *plane, struct drm_crtc 
*crtc,
 }
 
 static int
-nv10_disable_plane(struct drm_plane *plane)
+nv10_disable_plane(struct drm_plane *plane,
+  struct drm_modeset_acquire_ctx *ctx)
 {
struct nvif_object *dev = 
&nouveau_drm(plane->dev)->client.device.object;
struct nouveau_plane *nv_plane =
@@ -191,7 +192,7 @@ nv10_disable_plane(struct drm_plane *pla

[Intel-gfx] [PATCH 06/19] drm/vmwgfx: Drop the cursor locking hack

2017-03-22 Thread Daniel Vetter
It's been around forever, no one bothered to address the FIXME, so I
presume it's all fine.

Cc: Sinclair Yeh 
Cc: Thomas Hellstrom 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 25 -
 1 file changed, 25 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index d492d57d5309..424b3fc57203 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -148,15 +148,6 @@ int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct 
drm_file *file_priv,
s32 hotspot_x, hotspot_y;
int ret;
 
-   /*
-* FIXME: Unclear whether there's any global state touched by the
-* cursor_set function, especially vmw_cursor_update_position looks
-* suspicious. For now take the easy route and reacquire all locks. We
-* can do this since the caller in the drm core doesn't check anything
-* which is protected by any looks.
-*/
-   drm_modeset_unlock_crtc(crtc);
-   drm_modeset_lock_all(dev_priv->dev);
hotspot_x = hot_x + du->hotspot_x;
hotspot_y = hot_y + du->hotspot_y;
 
@@ -224,9 +215,6 @@ int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct 
drm_file *file_priv,
}
 
 out:
-   drm_modeset_unlock_all(dev_priv->dev);
-   drm_modeset_lock_crtc(crtc, crtc->cursor);
-
return ret;
 }
 
@@ -239,25 +227,12 @@ int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, 
int y)
du->cursor_x = x + du->set_gui_x;
du->cursor_y = y + du->set_gui_y;
 
-   /*
-* FIXME: Unclear whether there's any global state touched by the
-* cursor_set function, especially vmw_cursor_update_position looks
-* suspicious. For now take the easy route and reacquire all locks. We
-* can do this since the caller in the drm core doesn't check anything
-* which is protected by any looks.
-*/
-   drm_modeset_unlock_crtc(crtc);
-   drm_modeset_lock_all(dev_priv->dev);
-
vmw_cursor_update_position(dev_priv, shown,
   du->cursor_x + du->hotspot_x +
   du->core_hotspot_x,
   du->cursor_y + du->hotspot_y +
   du->core_hotspot_y);
 
-   drm_modeset_unlock_all(dev_priv->dev);
-   drm_modeset_lock_crtc(crtc, crtc->cursor);
-
return 0;
 }
 
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 09/19] drm: Make drm_modeset_lock_crtc internal

2017-03-22 Thread Daniel Vetter
This is only for legacy paths that need to grab the crtc/plane lock
combo. If you want to lock a crtc, just use drm_modeset_lock().

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_crtc_internal.h |  3 +++
 drivers/gpu/drm/drm_modeset_lock.c  | 14 --
 include/drm/drm_modeset_lock.h  |  2 --
 3 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc_internal.h 
b/drivers/gpu/drm/drm_crtc_internal.h
index 8c04275cf226..de1047530e07 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -61,6 +61,9 @@ int drm_mode_getresources(struct drm_device *dev,
  void *data, struct drm_file *file_priv);
 
 
+/* drm_modeset_lock.c */
+void drm_modeset_lock_crtc(struct drm_crtc *crtc,
+  struct drm_plane *plane);
 /* drm_dumb_buffers.c */
 /* IOCTLs */
 int drm_mode_create_dumb_ioctl(struct drm_device *dev,
diff --git a/drivers/gpu/drm/drm_modeset_lock.c 
b/drivers/gpu/drm/drm_modeset_lock.c
index bf60f2645e55..c94eff9d7544 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -148,19 +148,6 @@ void drm_modeset_unlock_all(struct drm_device *dev)
 }
 EXPORT_SYMBOL(drm_modeset_unlock_all);
 
-/**
- * drm_modeset_lock_crtc - lock crtc with hidden acquire ctx for a plane update
- * @crtc: DRM CRTC
- * @plane: DRM plane to be updated on @crtc
- *
- * This function locks the given crtc and plane (which should be either the
- * primary or cursor plane) using a hidden acquire context. This is necessary 
so
- * that drivers internally using the atomic interfaces can grab further locks
- * with the lock acquire context.
- *
- * Note that @plane can be NULL, e.g. when the cursor support hasn't yet been
- * converted to universal planes yet.
- */
 void drm_modeset_lock_crtc(struct drm_crtc *crtc,
   struct drm_plane *plane)
 {
@@ -205,7 +192,6 @@ void drm_modeset_lock_crtc(struct drm_crtc *crtc,
goto retry;
}
 }
-EXPORT_SYMBOL(drm_modeset_lock_crtc);
 
 /**
  * drm_modeset_legacy_acquire_ctx - find acquire ctx for legacy ioctls
diff --git a/include/drm/drm_modeset_lock.h b/include/drm/drm_modeset_lock.h
index 96d39fbd12ca..88d35bfc9cd8 100644
--- a/include/drm/drm_modeset_lock.h
+++ b/include/drm/drm_modeset_lock.h
@@ -121,8 +121,6 @@ struct drm_plane;
 
 void drm_modeset_lock_all(struct drm_device *dev);
 void drm_modeset_unlock_all(struct drm_device *dev);
-void drm_modeset_lock_crtc(struct drm_crtc *crtc,
-  struct drm_plane *plane);
 void drm_modeset_unlock_crtc(struct drm_crtc *crtc);
 void drm_warn_on_modeset_not_all_locked(struct drm_device *dev);
 struct drm_modeset_acquire_ctx *
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 07/19] drm/tegra: Don't use modeset_lock_crtc

2017-03-22 Thread Daniel Vetter
Yes the help text is unhelpful, but atomic drivers should never use
this. Just grab the lock without context or anything.

Also an aside: Checking ->active like this doesn't protect against
nonblocking commits, this is rather bogus.

Cc: Thierry Reding 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/tegra/dc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index 0db5d5a8d3b9..95b373f739f2 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -1382,7 +1382,7 @@ static int tegra_dc_show_regs(struct seq_file *s, void 
*data)
struct tegra_dc *dc = node->info_ent->data;
int err = 0;
 
-   drm_modeset_lock_crtc(&dc->base, NULL);
+   drm_modeset_lock(&dc->base.mutex, NULL);
 
if (!dc->base.state->active) {
err = -EBUSY;
@@ -1609,7 +1609,7 @@ static int tegra_dc_show_regs(struct seq_file *s, void 
*data)
 #undef DUMP_REG
 
 unlock:
-   drm_modeset_unlock_crtc(&dc->base);
+   drm_modeset_unlock(&dc->base.mutex);
return err;
 }
 
@@ -1620,7 +1620,7 @@ static int tegra_dc_show_crc(struct seq_file *s, void 
*data)
int err = 0;
u32 value;
 
-   drm_modeset_lock_crtc(&dc->base, NULL);
+   drm_modeset_lock(&dc->base.mutex, NULL);
 
if (!dc->base.state->active) {
err = -EBUSY;
@@ -1640,7 +1640,7 @@ static int tegra_dc_show_crc(struct seq_file *s, void 
*data)
tegra_dc_writel(dc, 0, DC_COM_CRC_CONTROL);
 
 unlock:
-   drm_modeset_unlock_crtc(&dc->base);
+   drm_modeset_unlock(&dc->base.mutex);
return err;
 }
 
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 08/19] drm/tilcdc: Drop calls to modeset_lock_crtc

2017-03-22 Thread Daniel Vetter
Again this is an internal helper, not the official way to lock a crtc.

Cc: Jyri Sarha 
Cc: Tomi Valkeinen 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c 
b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
index c92faa8f7560..afd2a7b2aff7 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
@@ -579,7 +579,7 @@ static void tilcdc_crtc_recover_work(struct work_struct 
*work)
 
dev_info(crtc->dev->dev, "%s: Reset CRTC", __func__);
 
-   drm_modeset_lock_crtc(crtc, NULL);
+   drm_modeset_lock(&crtc->mutex, NULL);
 
if (!tilcdc_crtc_is_on(crtc))
goto out;
@@ -587,7 +587,7 @@ static void tilcdc_crtc_recover_work(struct work_struct 
*work)
tilcdc_crtc_disable(crtc);
tilcdc_crtc_enable(crtc);
 out:
-   drm_modeset_unlock_crtc(crtc);
+   drm_modeset_unlock(&crtc->mutex);
 }
 
 static void tilcdc_crtc_destroy(struct drm_crtc *crtc)
@@ -595,9 +595,9 @@ static void tilcdc_crtc_destroy(struct drm_crtc *crtc)
struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
struct tilcdc_drm_private *priv = crtc->dev->dev_private;
 
-   drm_modeset_lock_crtc(crtc, NULL);
+   drm_modeset_lock(&crtc->mutex, NULL);
tilcdc_crtc_disable(crtc);
-   drm_modeset_unlock_crtc(crtc);
+   drm_modeset_unlock(&crtc->mutex);
 
flush_workqueue(priv->wq);
 
@@ -856,7 +856,7 @@ void tilcdc_crtc_update_clk(struct drm_crtc *crtc)
struct tilcdc_drm_private *priv = dev->dev_private;
struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
 
-   drm_modeset_lock_crtc(crtc, NULL);
+   drm_modeset_lock(&crtc->mutex, NULL);
if (tilcdc_crtc->lcd_fck_rate != clk_get_rate(priv->clk)) {
if (tilcdc_crtc_is_on(crtc)) {
pm_runtime_get_sync(dev->dev);
@@ -868,7 +868,7 @@ void tilcdc_crtc_update_clk(struct drm_crtc *crtc)
pm_runtime_put_sync(dev->dev);
}
}
-   drm_modeset_unlock_crtc(crtc);
+   drm_modeset_unlock(&crtc->mutex);
 }
 
 #define SYNC_LOST_COUNT_LIMIT 50
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 05/19] drm/atomic-helper: remove backoff hack from disable/update_plane

2017-03-22 Thread Daniel Vetter
We can now properly retry at the top level, yay!

v2: Also remove the temporary acquire_ctx hack again, no longer
needed!

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_atomic_helper.c | 49 ++---
 drivers/gpu/drm/drm_plane.c |  2 --
 2 files changed, 2 insertions(+), 49 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 1142075032a2..845378c92ccb 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2102,8 +2102,7 @@ int drm_atomic_helper_update_plane(struct drm_plane 
*plane,
if (!state)
return -ENOMEM;
 
-   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
-retry:
+   state->acquire_ctx = ctx;
plane_state = drm_atomic_get_plane_state(state, plane);
if (IS_ERR(plane_state)) {
ret = PTR_ERR(plane_state);
@@ -2128,24 +2127,8 @@ int drm_atomic_helper_update_plane(struct drm_plane 
*plane,
 
ret = drm_atomic_commit(state);
 fail:
-   if (ret == -EDEADLK)
-   goto backoff;
-
drm_atomic_state_put(state);
return ret;
-
-backoff:
-   drm_atomic_state_clear(state);
-   drm_atomic_legacy_backoff(state);
-
-   /*
-* Someone might have exchanged the framebuffer while we dropped locks
-* in the backoff code. We need to fix up the fb refcount tracking the
-* core does for us.
-*/
-   plane->old_fb = plane->fb;
-
-   goto retry;
 }
 EXPORT_SYMBOL(drm_atomic_helper_update_plane);
 
@@ -2166,23 +2149,11 @@ int drm_atomic_helper_disable_plane(struct drm_plane 
*plane,
struct drm_plane_state *plane_state;
int ret = 0;
 
-   /*
-* FIXME: Without plane->crtc set we can't get at the implicit legacy
-* acquire context. The real fix will be to wire the acquire ctx through
-* everywhere we need it, but meanwhile prevent chaos by just skipping
-* this noop. The critical case is the cursor ioctls which a) only grab
-* crtc/cursor-plane locks (so we need the crtc to get at the right
-* acquire context) and b) can try to disable the plane multiple times.
-*/
-   if (!plane->crtc)
-   return 0;
-
state = drm_atomic_state_alloc(plane->dev);
if (!state)
return -ENOMEM;
 
-   state->acquire_ctx = drm_modeset_legacy_acquire_ctx(plane->crtc);
-retry:
+   state->acquire_ctx = ctx;
plane_state = drm_atomic_get_plane_state(state, plane);
if (IS_ERR(plane_state)) {
ret = PTR_ERR(plane_state);
@@ -2198,24 +2169,8 @@ int drm_atomic_helper_disable_plane(struct drm_plane 
*plane,
 
ret = drm_atomic_commit(state);
 fail:
-   if (ret == -EDEADLK)
-   goto backoff;
-
drm_atomic_state_put(state);
return ret;
-
-backoff:
-   drm_atomic_state_clear(state);
-   drm_atomic_legacy_backoff(state);
-
-   /*
-* Someone might have exchanged the framebuffer while we dropped locks
-* in the backoff code. We need to fix up the fb refcount tracking the
-* core does for us.
-*/
-   plane->old_fb = plane->fb;
-
-   goto retry;
 }
 EXPORT_SYMBOL(drm_atomic_helper_disable_plane);
 
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 526e74b548b2..8535dc17db7e 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -554,7 +554,6 @@ static int setplane_internal(struct drm_plane *plane,
ret = drm_modeset_lock_all_ctx(plane->dev, &ctx);
if (ret)
goto fail;
-   plane->dev->mode_config.acquire_ctx = &ctx;
ret = __setplane_internal(plane, crtc, fb,
  crtc_x, crtc_y, crtc_w, crtc_h,
  src_x, src_y, src_w, src_h, &ctx);
@@ -649,7 +648,6 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
ret = drm_modeset_lock(&crtc->cursor->mutex, &ctx);
if (ret)
goto fail;
-   crtc->acquire_ctx = &ctx;
 
/*
 * Obtain fb we'll be using (either new or existing) and take an extra
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 02/19] drm: Add acquire ctx parameter to ->update_plane

2017-03-22 Thread Daniel Vetter
Just rolling it out, no code change here.

Cc: Ben Skeggs 
Cc: Russell King 
Cc: Rob Clark 
Cc: Laurent Pinchart 
Cc: Eric Anholt 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/armada/armada_overlay.c| 3 ++-
 drivers/gpu/drm/drm_atomic_helper.c| 4 +++-
 drivers/gpu/drm/drm_plane.c| 2 +-
 drivers/gpu/drm/drm_plane_helper.c | 4 +++-
 drivers/gpu/drm/i915/intel_display.c   | 5 +++--
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c  | 8 +---
 drivers/gpu/drm/nouveau/dispnv04/overlay.c | 6 --
 drivers/gpu/drm/shmobile/shmob_drm_plane.c | 3 ++-
 drivers/gpu/drm/vc4/vc4_plane.c| 6 --
 include/drm/drm_atomic_helper.h| 3 ++-
 include/drm/drm_plane.h| 4 +++-
 include/drm/drm_plane_helper.h | 3 ++-
 12 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/armada/armada_overlay.c 
b/drivers/gpu/drm/armada/armada_overlay.c
index 34cb73d0db77..b54fd8cbd3a6 100644
--- a/drivers/gpu/drm/armada/armada_overlay.c
+++ b/drivers/gpu/drm/armada/armada_overlay.c
@@ -94,7 +94,8 @@ static int
 armada_ovl_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
struct drm_framebuffer *fb,
int crtc_x, int crtc_y, unsigned crtc_w, unsigned crtc_h,
-   uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h)
+   uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h,
+   struct drm_modeset_acquire_ctx *ctx)
 {
struct armada_ovl_plane *dplane = drm_to_armada_ovl_plane(plane);
struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 278d72aa012f..8ef7c808670b 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2078,6 +2078,7 @@ EXPORT_SYMBOL(drm_atomic_helper_swap_state);
  * @src_y: y offset of @fb for panning
  * @src_w: width of source rectangle in @fb
  * @src_h: height of source rectangle in @fb
+ * @ctx: lock acquire context
  *
  * Provides a default plane update handler using the atomic driver interface.
  *
@@ -2090,7 +2091,8 @@ int drm_atomic_helper_update_plane(struct drm_plane 
*plane,
   int crtc_x, int crtc_y,
   unsigned int crtc_w, unsigned int crtc_h,
   uint32_t src_x, uint32_t src_y,
-  uint32_t src_w, uint32_t src_h)
+  uint32_t src_w, uint32_t src_h,
+  struct drm_modeset_acquire_ctx *ctx)
 {
struct drm_atomic_state *state;
struct drm_plane_state *plane_state;
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 0d04888172a7..8a4e75929810 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -510,7 +510,7 @@ static int __setplane_internal(struct drm_plane *plane,
plane->old_fb = plane->fb;
ret = plane->funcs->update_plane(plane, crtc, fb,
 crtc_x, crtc_y, crtc_w, crtc_h,
-src_x, src_y, src_w, src_h);
+src_x, src_y, src_w, src_h, ctx);
if (!ret) {
plane->crtc = crtc;
plane->fb = fb;
diff --git a/drivers/gpu/drm/drm_plane_helper.c 
b/drivers/gpu/drm/drm_plane_helper.c
index de1ac5e08f4d..2339879f775d 100644
--- a/drivers/gpu/drm/drm_plane_helper.c
+++ b/drivers/gpu/drm/drm_plane_helper.c
@@ -275,6 +275,7 @@ EXPORT_SYMBOL(drm_plane_helper_check_update);
  * @src_y: y offset of @fb for panning
  * @src_w: width of source rectangle in @fb
  * @src_h: height of source rectangle in @fb
+ * @ctx: lock acquire context, not used here
  *
  * Provides a default plane update handler for primary planes.  This is handler
  * is called in response to a userspace SetPlane operation on the plane with a
@@ -303,7 +304,8 @@ int drm_primary_helper_update(struct drm_plane *plane, 
struct drm_crtc *crtc,
  int crtc_x, int crtc_y,
  unsigned int crtc_w, unsigned int crtc_h,
  uint32_t src_x, uint32_t src_y,
- uint32_t src_w, uint32_t src_h)
+ uint32_t src_w, uint32_t src_h,
+ struct drm_modeset_acquire_ctx *ctx)
 {
struct drm_mode_set set = {
.crtc = crtc,
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 010e5ddb198a..e27ea89efd67 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -13426,7 +13426,8 @@ intel_legacy_cursor_update(struct drm_plane *plane,
   int crtc_x, int crtc_y,
   unsigned int crtc_w, unsigned int crtc_h,
   uint32_t src_x, u

[Intel-gfx] [PATCH 00/19] wire acquire ctx through legacy modeset paths

2017-03-22 Thread Daniel Vetter
Hi all,

This is something I kinda had on my todo list ever since atomic landed. The
legacy_backoff() hack really doesn't work if you need to acquire additional
locks, which does restrict drivers in how they handle and protect legacy paths,
and kinda forces us to be overzealous with taking locks for legacy paths, just
in case.

This patch set here fixes this, with 2 huge exceptions:
- get/set_property calls aren't fixed. The locking in there is a mess and needs
  some serious attention. My goal would be that for atomic we take no lock at
  all, and entirely rely upon the magic of drm_modeset_lock and atomic to just
  grab the minimal set required to update a property.

- fbdev emulation helpers. It abused the modeset_lock_all bkl as its own lock,
  which prevents us from pushing it down just around the (atomic) modeset calls,
  and hence from switching over to handling the acquire context in an explicit
  fashion. Thierry started to fix this with the addition of proper locking for
  fbdev emulation, but it needs a pile more work.

Survived light testing with full ww mutex debugging, I'll rely on CI to catch
the remaining mixups :-)

Cheers, Daniel

Daniel Vetter (19):
  drm: Wire up proper acquire ctx for plane functions
  drm: Add acquire ctx parameter to ->update_plane
  drm: drm_plane_force_disable is not for atomic drivers
  drm: Add acquire ctx parameter to ->plane_disable
  drm/atomic-helper: remove backoff hack from disable/update_plane
  drm/vmwgfx: Drop the cursor locking hack
  drm/tegra: Don't use modeset_lock_crtc
  drm/tilcdc: Drop calls to modeset_lock_crtc
  drm: Make drm_modeset_lock_crtc internal
  drm: Roll out acquire context for the page_flip ioctl
  drm: Add acquire ctx parameter to ->page_flip(_target)
  drm/atomic-helper: remove backoff hack from page_flip
  drm: simplify the locking in the GETCRTC ioctl
  drm: Remove drm_modeset_(un)lock_crtc
  drm: Remove drm_modeset_legacy_acquire_ctx and crtc->acquire_ctx
  drm: Restrict drm_mode_set_config_internal to non-atomic drivers
  drm: Add explicit acquire ctx handling around ->set_config
  drm: Add acquire ctx parameter to ->set_config
  drm/atomic-helper: Remove the backoff hack from set_config

 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c |   8 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h|   6 +-
 drivers/gpu/drm/armada/armada_crtc.c|   3 +-
 drivers/gpu/drm/armada/armada_overlay.c |   6 +-
 drivers/gpu/drm/bochs/bochs_kms.c   |   3 +-
 drivers/gpu/drm/drm_atomic.c|  14 ---
 drivers/gpu/drm/drm_atomic_helper.c | 132 +---
 drivers/gpu/drm/drm_crtc.c  |  61 -
 drivers/gpu/drm/drm_crtc_helper.c   |   4 +-
 drivers/gpu/drm/drm_modeset_lock.c  | 102 -
 drivers/gpu/drm/drm_plane.c |  87 ++
 drivers/gpu/drm/drm_plane_helper.c  |  11 ++-
 drivers/gpu/drm/gma500/gma_display.c|   7 +-
 drivers/gpu/drm/gma500/gma_display.h|   3 +-
 drivers/gpu/drm/i915/intel_display.c|   9 +-
 drivers/gpu/drm/i915/intel_pipe_crc.c   |   2 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c   |   8 +-
 drivers/gpu/drm/nouveau/dispnv04/crtc.c |   7 +-
 drivers/gpu/drm/nouveau/dispnv04/overlay.c  |  18 ++--
 drivers/gpu/drm/nouveau/nouveau_display.c   |   3 +-
 drivers/gpu/drm/nouveau/nouveau_display.h   |   4 +-
 drivers/gpu/drm/radeon/radeon_display.c |   8 +-
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c   |   3 +-
 drivers/gpu/drm/shmobile/shmob_drm_plane.c  |   8 +-
 drivers/gpu/drm/tegra/dc.c  |   8 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c|  12 +--
 drivers/gpu/drm/udl/udl_modeset.c   |   3 +-
 drivers/gpu/drm/vc4/vc4_crtc.c  |   5 +-
 drivers/gpu/drm/vc4/vc4_plane.c |   6 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c |  25 --
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c |   3 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c|   6 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c|   6 +-
 include/drm/drm_atomic_helper.h |  15 ++--
 include/drm/drm_crtc.h  |  18 ++--
 include/drm/drm_crtc_helper.h   |   3 +-
 include/drm/drm_modeset_lock.h  |   5 --
 include/drm/drm_plane.h |   7 +-
 include/drm/drm_plane_helper.h  |   6 +-
 39 files changed, 265 insertions(+), 380 deletions(-)

-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 03/19] drm: drm_plane_force_disable is not for atomic drivers

2017-03-22 Thread Daniel Vetter
This way I can explain why it'll be fine to pass a NULL acquire ctx
here in the next patch.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_plane.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 8a4e75929810..67119332c441 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -277,6 +277,12 @@ EXPORT_SYMBOL(drm_plane_from_index);
  *
  * Used when the plane's current framebuffer is destroyed,
  * and when restoring fbdev mode.
+ *
+ * Note that this function is not suitable for atomic drivers, since it doesn't
+ * wire through the lock acquisition context properly and hence can't handle
+ * retries or driver private locks. You probably want to use
+ * drm_atomic_helper_disable_plane() or
+ * drm_atomic_helper_disable_planes_on_crtc() instead.
  */
 void drm_plane_force_disable(struct drm_plane *plane)
 {
@@ -285,6 +291,8 @@ void drm_plane_force_disable(struct drm_plane *plane)
if (!plane->fb)
return;
 
+   WARN_ON(drm_drv_uses_atomic_modeset(plane->dev));
+
plane->old_fb = plane->fb;
ret = plane->funcs->disable_plane(plane);
if (ret) {
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 01/19] drm: Wire up proper acquire ctx for plane functions

2017-03-22 Thread Daniel Vetter
This is just prep work to get an acquire ctx into every place where we
call ->update_plane or ->disable_plane.

v2: Keep the hidden acquire_ctx pointers valid while transitioning.

Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_plane.c | 52 -
 1 file changed, 42 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index a22e76837065..0d04888172a7 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -457,7 +457,8 @@ static int __setplane_internal(struct drm_plane *plane,
   uint32_t crtc_w, uint32_t crtc_h,
   /* src_{x,y,w,h} values are 16.16 fixed point */
   uint32_t src_x, uint32_t src_y,
-  uint32_t src_w, uint32_t src_h)
+  uint32_t src_w, uint32_t src_h,
+  struct drm_modeset_acquire_ctx *ctx)
 {
int ret = 0;
 
@@ -537,13 +538,26 @@ static int setplane_internal(struct drm_plane *plane,
 uint32_t src_x, uint32_t src_y,
 uint32_t src_w, uint32_t src_h)
 {
+   struct drm_modeset_acquire_ctx ctx;
int ret;
 
-   drm_modeset_lock_all(plane->dev);
+   drm_modeset_acquire_init(&ctx, 0);
+retry:
+   ret = drm_modeset_lock_all_ctx(plane->dev, &ctx);
+   if (ret)
+   goto fail;
+   plane->dev->mode_config.acquire_ctx = &ctx;
ret = __setplane_internal(plane, crtc, fb,
  crtc_x, crtc_y, crtc_w, crtc_h,
- src_x, src_y, src_w, src_h);
-   drm_modeset_unlock_all(plane->dev);
+ src_x, src_y, src_w, src_h, &ctx);
+
+fail:
+   if (ret == -EDEADLK) {
+   drm_modeset_backoff(&ctx);
+   goto retry;
+   }
+   drm_modeset_drop_locks(&ctx);
+   drm_modeset_acquire_fini(&ctx);
 
return ret;
 }
@@ -613,11 +627,22 @@ static int drm_mode_cursor_universal(struct drm_crtc 
*crtc,
int32_t crtc_x, crtc_y;
uint32_t crtc_w = 0, crtc_h = 0;
uint32_t src_w = 0, src_h = 0;
+   struct drm_modeset_acquire_ctx ctx;
int ret = 0;
 
BUG_ON(!crtc->cursor);
WARN_ON(crtc->cursor->crtc != crtc && crtc->cursor->crtc != NULL);
 
+   drm_modeset_acquire_init(&ctx, 0);
+retry:
+   ret = drm_modeset_lock(&crtc->mutex, &ctx);
+   if (ret)
+   goto fail;
+   ret = drm_modeset_lock(&crtc->cursor->mutex, &ctx);
+   if (ret)
+   goto fail;
+   crtc->acquire_ctx = &ctx;
+
/*
 * Obtain fb we'll be using (either new or existing) and take an extra
 * reference to it if fb != null.  setplane will take care of dropping
@@ -662,7 +687,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
 */
ret = __setplane_internal(crtc->cursor, crtc, fb,
crtc_x, crtc_y, crtc_w, crtc_h,
-   0, 0, src_w, src_h);
+   0, 0, src_w, src_h, &ctx);
 
/* Update successful; save new cursor position, if necessary */
if (ret == 0 && req->flags & DRM_MODE_CURSOR_MOVE) {
@@ -670,6 +695,15 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
crtc->cursor_y = req->y;
}
 
+fail:
+   if (ret == -EDEADLK) {
+   drm_modeset_backoff(&ctx);
+   goto retry;
+   }
+
+   drm_modeset_drop_locks(&ctx);
+   drm_modeset_acquire_fini(&ctx);
+
return ret;
 }
 
@@ -696,12 +730,10 @@ static int drm_mode_cursor_common(struct drm_device *dev,
 * If this crtc has a universal cursor plane, call that plane's update
 * handler rather than using legacy cursor handlers.
 */
-   drm_modeset_lock_crtc(crtc, crtc->cursor);
-   if (crtc->cursor) {
-   ret = drm_mode_cursor_universal(crtc, req, file_priv);
-   goto out;
-   }
+   if (crtc->cursor)
+   return drm_mode_cursor_universal(crtc, req, file_priv);
 
+   drm_modeset_lock_crtc(crtc, crtc->cursor);
if (req->flags & DRM_MODE_CURSOR_BO) {
if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) {
ret = -ENXIO;
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v3 06/10] drm/fb-helper: Support deferred setup

2017-03-22 Thread Daniel Vetter
On Wed, Mar 22, 2017 at 10:06 PM, Thierry Reding
 wrote:
> On Tue, Mar 21, 2017 at 11:10:22AM +0100, Daniel Vetter wrote:
>> On Tue, Mar 21, 2017 at 09:13:54AM +0100, Thierry Reding wrote:
> [...]
>> > diff --git a/drivers/gpu/drm/drm_fb_helper.c 
>> > b/drivers/gpu/drm/drm_fb_helper.c
> [...]
>> > @@ -2437,11 +2476,16 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
>> >  int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
>> >  {
>> > struct drm_device *dev = fb_helper->dev;
>> > +   unsigned int width, height;
>> > int err = 0;
>> >
>> > if (!drm_fbdev_emulation)
>> > return 0;
>> >
>> > +   if (fb_helper->deferred_setup)
>> > +   return drm_fb_helper_initial_config(fb_helper,
>> > +   fb_helper->preferred_bpp);
>>
>> I think this must be moved under the protection of ->lock, you might race
>> otherwise (e.g. hpd vs. userspace forcing a re-probe, both noticing the
>> change).
>
> I think I had originally put this under the lock only to see that result
> in a deadlock. I can't quite remember why that was, but testing shows
> that this still happens. It's getting rather late, so I'll have to defer
> tracking this down to tomorrow.

initial_config also grabs your new lock, which means you'd need more
static _unlocked variants to make it work. I didn't see any other
obvious problem this would cause.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v3 06/10] drm/fb-helper: Support deferred setup

2017-03-22 Thread Thierry Reding
On Tue, Mar 21, 2017 at 11:10:22AM +0100, Daniel Vetter wrote:
> On Tue, Mar 21, 2017 at 09:13:54AM +0100, Thierry Reding wrote:
[...]
> > diff --git a/drivers/gpu/drm/drm_fb_helper.c 
> > b/drivers/gpu/drm/drm_fb_helper.c
[...]
> > @@ -2437,11 +2476,16 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
> >  int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
> >  {
> > struct drm_device *dev = fb_helper->dev;
> > +   unsigned int width, height;
> > int err = 0;
> >  
> > if (!drm_fbdev_emulation)
> > return 0;
> >  
> > +   if (fb_helper->deferred_setup)
> > +   return drm_fb_helper_initial_config(fb_helper,
> > +   fb_helper->preferred_bpp);
> 
> I think this must be moved under the protection of ->lock, you might race
> otherwise (e.g. hpd vs. userspace forcing a re-probe, both noticing the
> change).

I think I had originally put this under the lock only to see that result
in a deadlock. I can't quite remember why that was, but testing shows
that this still happens. It's getting rather late, so I'll have to defer
tracking this down to tomorrow.

Thierry


signature.asc
Description: PGP signature
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v4 4/8] drm: Add driver-private objects to atomic state

2017-03-22 Thread Pandiyan, Dhinakaran
On Wed, 2017-03-22 at 11:00 +0100, Maarten Lankhorst wrote:
> Op 16-03-17 om 08:10 schreef Dhinakaran Pandiyan:
> > From: "Pandiyan, Dhinakaran" 
> >
> > It is necessary to track states for objects other than connector, crtc
> > and plane for atomic modesets. But adding objects like DP MST link
> > bandwidth to drm_atomic_state would mean that a non-core object will be
> > modified by the core helper functions for swapping and clearing
> > it's state. So, lets add void * objects and helper functions that operate
> > on void * types to keep these objects and states private to the core.
> > Drivers can then implement specific functions to swap and clear states.
> > The other advantage having just void * for these objects in
> > drm_atomic_state is that objects of different types can be managed in the
> > same state array.
> >
> > v2: Added docs and new iterator to filter private objects (Daniel)
> > v3: Macro alignment (Chris)
> >
> > Cc: Daniel Vetter 
> > Cc: Archit Taneja 
> > Cc: Maarten Lankhorst 
> > Cc: Chris Wilson 
> > Cc: Harry Wentland 
> > Acked-by: Harry Wentland 
> > Suggested-by: Daniel Vetter 
> > Signed-off-by: Dhinakaran Pandiyan 
> 
> Mostly looks good, but too many null checks. I think it's best to get rid of 
> them all
> by freeing state->driver_private in default_clear() or setting 
> num_private_objs to 0.
> It would remove the need for all null checks I think..
> 
> ~Maarten
> 

Did you mean the NULL checks in this loop inside
drm_atomic_get_private_obj_state()

+   for (i = 0; i < state->num_private_objs; i++)
+   if (obj == state->private_objs[i].obj &&
+   state->private_objs[i].obj_state)
+   return state->private_objs[i].obj_state;

and the fact that I am not setting num_private_objs = 0 in
drm_atomic_state_default_clear() ?

-DK
> ___
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH] drm/i915: Remove superfluous hw_flags from mi_set_context()

2017-03-22 Thread Chris Wilson
Why have both hw_flags and flags, when just one will do?

Signed-off-by: Chris Wilson 
---
 drivers/gpu/drm/i915/i915_gem_context.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c 
b/drivers/gpu/drm/i915/i915_gem_context.c
index 486051ed681d..8fc8b3d15a0f 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -576,25 +576,25 @@ void i915_gem_context_close(struct drm_device *dev, 
struct drm_file *file)
 }
 
 static inline int
-mi_set_context(struct drm_i915_gem_request *req, u32 hw_flags)
+mi_set_context(struct drm_i915_gem_request *req, u32 flags)
 {
struct drm_i915_private *dev_priv = req->i915;
struct intel_engine_cs *engine = req->engine;
enum intel_engine_id id;
-   u32 *cs, flags = hw_flags | MI_MM_SPACE_GTT;
const int num_rings =
/* Use an extended w/a on ivb+ if signalling from other rings */
i915.semaphores ?
INTEL_INFO(dev_priv)->num_rings - 1 :
0;
int len;
+   u32 *cs;
 
-   /* These flags are for resource streamer on HSW+ */
+   flags |= MI_MM_SPACE_GTT;
if (IS_HASWELL(dev_priv) || INTEL_GEN(dev_priv) >= 8)
-   flags |= (HSW_MI_RS_SAVE_STATE_EN | HSW_MI_RS_RESTORE_STATE_EN);
-   else if (INTEL_GEN(dev_priv) < 8)
-   flags |= (MI_SAVE_EXT_STATE_EN | MI_RESTORE_EXT_STATE_EN);
-
+   /* These flags are for resource streamer on HSW+ */
+   flags |= HSW_MI_RS_SAVE_STATE_EN | HSW_MI_RS_RESTORE_STATE_EN;
+   else
+   flags |= MI_SAVE_EXT_STATE_EN | MI_RESTORE_EXT_STATE_EN;
 
len = 4;
if (INTEL_GEN(dev_priv) >= 7)
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm: Extract drm_debugfs.h

2017-03-22 Thread Ville Syrjälä
On Wed, Mar 22, 2017 at 09:53:36PM +0100, Daniel Vetter wrote:
> Doc polish will follow in the next patch.
> 
> v2: Put the include guard #endif at the end (Ville).
> 
> Cc: Ville Syrjälä 
> Signed-off-by: Daniel Vetter 

Reviewed-by: Ville Syrjälä 

> ---
>  drivers/gpu/drm/drm_debugfs.c |  5 ++-
>  include/drm/drmP.h| 44 +
>  include/drm/drm_debugfs.h | 77 
> +++
>  3 files changed, 82 insertions(+), 44 deletions(-)
>  create mode 100644 include/drm/drm_debugfs.h
> 
> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> index 1d2d18d82d2e..4b02f4230562 100644
> --- a/drivers/gpu/drm/drm_debugfs.c
> +++ b/drivers/gpu/drm/drm_debugfs.c
> @@ -34,9 +34,12 @@
>  #include 
>  #include 
>  #include 
> -#include 
> +
> +#include 
>  #include 
>  #include 
> +#include 
> +
>  #include "drm_internal.h"
>  #include "drm_crtc_internal.h"
>  
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index 0e383438f793..60f3255c43a8 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -78,6 +78,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  struct module;
>  
> @@ -371,27 +372,6 @@ struct drm_ioctl_desc {
>  #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
>  
>  /**
> - * Info file list entry. This structure represents a debugfs or proc file to
> - * be created by the drm core
> - */
> -struct drm_info_list {
> - const char *name; /** file name */
> - int (*show)(struct seq_file*, void*); /** show callback */
> - u32 driver_features; /**< Required driver features for this entry */
> - void *data;
> -};
> -
> -/**
> - * debugfs node structure. This structure represents a debugfs file.
> - */
> -struct drm_info_node {
> - struct list_head list;
> - struct drm_minor *minor;
> - const struct drm_info_list *info_ent;
> - struct dentry *dent;
> -};
> -
> -/**
>   * DRM device structure. This structure represent a complete card that
>   * may contain multiple heads.
>   */
> @@ -592,28 +572,6 @@ int drm_invalid_op(struct drm_device *dev, void *data,
>   * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
>   */
>  
> - /* Debugfs support */
> -#if defined(CONFIG_DEBUG_FS)
> -extern int drm_debugfs_create_files(const struct drm_info_list *files,
> - int count, struct dentry *root,
> - struct drm_minor *minor);
> -extern int drm_debugfs_remove_files(const struct drm_info_list *files,
> - int count, struct drm_minor *minor);
> -#else
> -static inline int drm_debugfs_create_files(const struct drm_info_list *files,
> -int count, struct dentry *root,
> -struct drm_minor *minor)
> -{
> - return 0;
> -}
> -
> -static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
> -int count, struct drm_minor *minor)
> -{
> - return 0;
> -}
> -#endif
> -
>  /* sysfs support (drm_sysfs.c) */
>  extern void drm_sysfs_hotplug_event(struct drm_device *dev);
>  
> diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
> new file mode 100644
> index ..56924196d08d
> --- /dev/null
> +++ b/include/drm/drm_debugfs.h
> @@ -0,0 +1,77 @@
> +/*
> + * Internal Header for the Direct Rendering Manager
> + *
> + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
> + * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
> + * Copyright (c) 2009-2010, Code Aurora Forum.
> + * All rights reserved.
> + *
> + * Author: Rickard E. (Rik) Faith 
> + * Author: Gareth Hughes 
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef _DRM_DE

[Intel-gfx] [PATCH] drm/i915: Restore marking context objects as dirty on pinning

2017-03-22 Thread Chris Wilson
Commit e8a9c58fcd9a ("drm/i915: Unify active context tracking between
legacy/execlists/guc") converted the legacy intel_ringbuffer submission
to the same context pinning mechanism as execlists - that is to pin the
context until the subsequent request is retired. Previously it used the
vma retirement of the context object to keep itself pinned until the
next request (after i915_vma_move_to_active()). In the conversion, I
missed that the vma retirement was also responsible for marking the
object as dirty. Mark the context object as dirty when pinning
(equivalent to execlists) which ensures that if the context is swapped
out due to mempressure or suspend/hibernation, when it is loaded back in
it does so with the previous state (and not all zero).

Fixes: e8a9c58fcd9a ("drm/i915: Unify active context tracking between 
legacy/execlists/guc")
Reported-by: Dennis Gilmore 
Reported-by: Mathieu Marquer 
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=3
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100181
Signed-off-by: Chris Wilson 
Cc: Tvrtko Ursulin 
Cc:  # v4.11-rc1
---
 drivers/gpu/drm/i915/intel_ringbuffer.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c 
b/drivers/gpu/drm/i915/intel_ringbuffer.c
index 0ca5ea7a9407..62756eb2bd4a 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1440,6 +1440,8 @@ static int intel_ring_context_pin(struct intel_engine_cs 
*engine,
ret = context_pin(ctx);
if (ret)
goto error;
+
+   ce->state->obj->mm.dirty = true;
}
 
/* The kernel context is only used as a placeholder for flushing the
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH] drm/vblank: drop the mode argument from drm_calc_vbltimestamp_from_scanoutpos

2017-03-22 Thread Daniel Vetter
If we restrict this helper to only kms drivers (which is the case) we
can look up the correct mode easily ourselves. But it's a bit tricky:

- All legacy drivers look at crtc->hwmode. But that is update already
  at the beginning of the modeset helper, which means when we disable
  a pipe. Hence the final timestamps might be a bit off. But since
  this is an existing bug I'm not going to change it, but just try to
  be bug-for-bug compatible with the current code. This only applies
  to radeon&amdgpu.

- i915 tries to get it perfect by updating crtc->hwmode when the pipe
  is off (i.e. vblank->enabled = false).

- All other atomic drivers look at crtc->state->adjusted_mode. Those
  that look at state->requested_mode simply don't adjust their mode,
  so it's the same. That has two problems: Accessing crtc->state from
  interrupt handling code is unsafe, and it's updated before we shut
  down the pipe. For nonblocking modesets it's even worse.

For atomic drivers try to implement what i915 does. To do that we add
a new hwmode field to the vblank structure, and update it from
drm_calc_timestamping_constants(). For atomic drivers that's called
from the right spot by the helper library already, so all fine. But
for safety let's enforce that.

For legacy driver this function is only called at the end (oh the
fun), which is broken, so again let's not bother and just stay
bug-for-bug compatible.

The  benefit is that we can use drm_calc_vbltimestamp_from_scanoutpos
directly to implement ->get_vblank_timestamp in every driver, deleting
a lot of code.

v2: Completely new approach, trying to mimick the i915 solution.

v3: Fixup kerneldoc.

v4: Drop the WARN_ON to check that the vblank is off, atomic helpers
currently unconditionally call this. Recomputing the same stuff should
be harmless.

Cc: Mario Kleiner 
Cc: Eric Anholt 
Cc: Rob Clark 
Cc: linux-arm-...@vger.kernel.org
Cc: freedr...@lists.freedesktop.org
Cc: Alex Deucher 
Cc: Christian König 
Cc: Ben Skeggs 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  4 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   | 41 ---
 drivers/gpu/drm/drm_irq.c | 27 +---
 drivers/gpu/drm/i915/i915_irq.c   | 33 +
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c   | 26 +---
 drivers/gpu/drm/nouveau/nouveau_display.c | 22 -
 drivers/gpu/drm/nouveau/nouveau_display.h |  2 --
 drivers/gpu/drm/nouveau/nouveau_drm.c |  2 +-
 drivers/gpu/drm/radeon/radeon_drv.c   |  6 +
 drivers/gpu/drm/radeon/radeon_kms.c   | 37 
 drivers/gpu/drm/vc4/vc4_crtc.c| 13 --
 drivers/gpu/drm/vc4/vc4_drv.c |  2 +-
 drivers/gpu/drm/vc4/vc4_drv.h |  3 ---
 include/drm/drm_irq.h | 15 +--
 15 files changed, 42 insertions(+), 193 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index edb3bb83e1a9..61bef9609b24 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1768,10 +1768,6 @@ int amdgpu_device_resume(struct drm_device *dev, bool 
resume, 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);
-bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
-int *max_error,
-struct timeval *vblank_time,
-bool in_vblank_irq);
 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 8a61296fd4cc..ba169a0699d5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -692,7 +692,7 @@ static struct drm_driver kms_driver = {
.get_vblank_counter = amdgpu_get_vblank_counter_kms,
.enable_vblank = amdgpu_enable_vblank_kms,
.disable_vblank = amdgpu_disable_vblank_kms,
-   .get_vblank_timestamp = amdgpu_get_vblank_timestamp_kms,
+   .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
.get_scanout_position = amdgpu_get_crtc_scanoutpos,
 #if defined(CONFIG_DEBUG_FS)
.debugfs_init = amdgpu_debugfs_init,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index ad295e822d45..32a492bd4e51 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -827,47 +827,6 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, 
unsigned int pipe)
amdgpu_irq_put(adev, &adev->crtc_ir

[Intel-gfx] [PATCH] drm/vblank: Switch drm_driver->get_vblank_timestamp to return a bool

2017-03-22 Thread Daniel Vetter
There's really no reason for anything more:
- Calling this while the crtc vblank stuff isn't set up is a driver
  bug. Those places arlready DRM_ERROR.
- Calling this when the crtc is off is either a driver bug (callin
  drm_crtc_handle_vblank at the wrong time) or a core bug (for
  anything else). Again, we DRM_ERROR.
- EINVAL is checked at higher levels already, and if we'd use struct
  drm_crtc * instead of (dev, pipe) it would be real obvious that
  those are again core bugs.

The only valid failure mode is crap hardware that couldn't sample a
useful timestamp, to ask the core to just grab a not-so-accurate
timestampe. Bool is perfectly fine for that.

v2: Also fix up the one caller, I lost that in the shuffling (Jani).

Cc: Jani Nikula 
Cc: Mario Kleiner 
Cc: Eric Anholt 
Cc: Rob Clark 
Cc: linux-arm-...@vger.kernel.org
Cc: freedr...@lists.freedesktop.org
Cc: Alex Deucher 
Cc: Christian König 
Cc: Ben Skeggs 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  8 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   | 14 -
 drivers/gpu/drm/drm_irq.c | 49 ---
 drivers/gpu/drm/i915/i915_irq.c   |  8 ++---
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c   | 12 
 drivers/gpu/drm/nouveau/nouveau_display.c |  4 +--
 drivers/gpu/drm/nouveau/nouveau_display.h |  4 +--
 drivers/gpu/drm/radeon/radeon_drv.c   |  8 ++---
 drivers/gpu/drm/radeon/radeon_kms.c   | 14 -
 drivers/gpu/drm/vc4/vc4_crtc.c|  2 +-
 drivers/gpu/drm/vc4/vc4_drv.h |  2 +-
 include/drm/drmP.h|  1 -
 include/drm/drm_drv.h |  7 ++---
 include/drm/drm_irq.h | 10 +++
 14 files changed, 64 insertions(+), 79 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index c8860f05bfb9..acd8631d8024 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1768,10 +1768,10 @@ int amdgpu_device_resume(struct drm_device *dev, bool 
resume, 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);
-int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
-   int *max_error,
-   struct timeval *vblank_time,
-   unsigned flags);
+bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
+int *max_error,
+struct timeval *vblank_time,
+unsigned flags);
 long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
 unsigned long arg);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 55f951bcc91f..ac42f707c046 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -838,19 +838,19 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, 
unsigned int pipe)
  *
  * Gets the timestamp on the requested crtc based on the
  * scanout position.  (all asics).
- * Returns postive status flags on success, negative error on failure.
+ * Returns true on success, false on failure.
  */
-int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
-   int *max_error,
-   struct timeval *vblank_time,
-   unsigned flags)
+bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
+int *max_error,
+struct timeval *vblank_time,
+unsigned flags)
 {
struct drm_crtc *crtc;
struct amdgpu_device *adev = dev->dev_private;
 
if (pipe >= dev->num_crtcs) {
DRM_ERROR("Invalid crtc %u\n", pipe);
-   return -EINVAL;
+   return false;
}
 
/* Get associated drm_crtc: */
@@ -859,7 +859,7 @@ int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, 
unsigned int pipe,
/* This can occur on driver load if some component fails to
 * initialize completely and driver is unloaded */
DRM_ERROR("Uninitialized crtc %d\n", pipe);
-   return -EINVAL;
+   return false;
}
 
/* Helper routine in DRM core does all the work: */
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 4b0c7475ed13..0996e6091bf9 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -722,43 +722,32 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  * active. High

[Intel-gfx] [PATCH] drm: update todo.rst

2017-03-22 Thread Daniel Vetter
Just drive-by, but we have gsoc running so better to update it now.

Great news is that two entries can be removed because essentially all
done.

v2: Keep a bunch of the todos, Gabriel is working on them.

Cc: Gabriel Krisman Bertazi 
Signed-off-by: Daniel Vetter 
---
 Documentation/gpu/todo.rst | 31 ---
 1 file changed, 4 insertions(+), 27 deletions(-)

diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
index 0cdaddad2b9b..8f6943ccd834 100644
--- a/Documentation/gpu/todo.rst
+++ b/Documentation/gpu/todo.rst
@@ -16,7 +16,7 @@ De-midlayer drivers
 With the recent ``drm_bus`` cleanup patches for 3.17 it is no longer required
 to have a ``drm_bus`` structure set up. Drivers can directly set up the
 ``drm_device`` structure instead of relying on bus methods in ``drm_usb.c``
-and ``drm_platform.c``. The goal is to get rid of the driver's ``->load`` /
+and ``drm_pci.c``. The goal is to get rid of the driver's ``->load`` /
 ``->unload`` callbacks and open-code the load/unload sequence properly, using
 the new two-stage ``drm_device`` setup/teardown.
 
@@ -151,7 +151,7 @@ fine-grained per-buffer object and per-context lockings 
scheme. Currently the
 following drivers still use ``struct_mutex``: ``msm``, ``omapdrm`` and
 ``udl``.
 
-Contact: Daniel Vetter
+Contact: Daniel Vetter, respective driver maintainers
 
 Switch to drm_connector_list_iter for any connector_list walking
 
@@ -193,6 +193,8 @@ plan is to switch to per-file driver API headers, which 
will also structure
 the kerneldoc better. This should also allow more fine-grained ``#include``
 directives.
 
+In the end no .c file should need to include ``drmP.h`` anymore.
+
 Contact: Daniel Vetter
 
 Add missing kerneldoc for exported functions
@@ -220,13 +222,8 @@ be hidden so that driver writers don't accidentally end up 
using it. And to
 prevent security issues in those legacy IOCTLs from being exploited on modern
 drivers. This has multiple possible subtasks:
 
-* Make sure legacy IOCTLs can't be used on modern drivers.
 * Extract support code for legacy features into a ``drm-legacy.ko`` kernel
   module and compile it only when one of the legacy drivers is enabled.
-* Extract legacy functions into their own headers and remove it that from the
-  monolithic ``drmP.h`` header.
-* Remove any lingering cruft from the OS abstraction layer from modern
-  drivers.
 
 This is mostly done, the only thing left is to split up ``drm_irq.c`` into
 legacy cruft and the parts needed by modern KMS drivers.
@@ -338,23 +335,3 @@ Driver Specific
 
 Outside DRM
 ===
-
-Better kerneldoc
-
-
-This is pretty much done, but there's some advanced topics:
-
-Come up with a way to hyperlink to struct members. Currently you can hyperlink
-to the struct using ``#struct_name``, but not to a member within. Would need
-buy-in from kerneldoc maintainers, and the big question is how to make it work
-without totally unsightly
-``drm_foo_bar_really_long_structure->even_longer_memeber`` all over the text
-which breaks text flow.
-
-Figure out how to integrate the asciidoc support for ascii-diagrams. We have a
-few of those (e.g. to describe mode timings), and asciidoc supports converting
-some ascii-art dialect into pngs. Would be really pretty to make that work.
-
-Contact: Daniel Vetter, Jani Nikula
-
-Jani is working on this already, hopefully lands in 4.8.
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH] drm: Extract drm_ioctl.h

2017-03-22 Thread Daniel Vetter
To match the drm_ioctl.c we already have.

v2: Remove spurious space (Ville).

Cc: Ville Syrjälä 
Reviewed-by: Ville Syrjälä 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_ioctl.c |   1 +
 include/drm/drmP.h  |  61 +-
 include/drm/drm_ioctl.h | 102 
 3 files changed, 104 insertions(+), 60 deletions(-)
 create mode 100644 include/drm/drm_ioctl.h

diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 601bb0ded9d2..7f4f4f48e390 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -28,6 +28,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include 
 #include 
 #include 
 #include "drm_legacy.h"
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index fc2a0744413d..248d2408e56b 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -80,6 +80,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct module;
 
@@ -318,49 +319,6 @@ struct pci_controller;
 
 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
 
-/**
- * Ioctl function type.
- *
- * \param inode device inode.
- * \param file_priv DRM file private pointer.
- * \param cmd command.
- * \param arg argument.
- */
-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
-   struct drm_file *file_priv);
-
-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
-  unsigned long arg);
-
-#define DRM_IOCTL_NR(n)_IOC_NR(n)
-#define DRM_MAJOR   226
-
-#define DRM_AUTH   0x1
-#defineDRM_MASTER  0x2
-#define DRM_ROOT_ONLY  0x4
-#define DRM_CONTROL_ALLOW 0x8
-#define DRM_UNLOCKED   0x10
-#define DRM_RENDER_ALLOW 0x20
-
-struct drm_ioctl_desc {
-   unsigned int cmd;
-   int flags;
-   drm_ioctl_t *func;
-   const char *name;
-};
-
-/**
- * Creates a driver or general drm_ioctl_desc array entry for the given
- * ioctl, for use by drm_ioctl().
- */
-
-#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)
\
-   [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {\
-   .cmd = DRM_IOCTL_##ioctl,   \
-   .func = _func,  \
-   .flags = _flags,\
-   .name = #ioctl  \
-}
 
 /* Flags and return codes for get_vblank_timestamp() driver function. */
 #define DRM_CALLED_FROM_VBLIRQ 1
@@ -550,23 +508,6 @@ static inline int drm_device_is_unplugged(struct 
drm_device *dev)
 /*@{*/
 
/* Driver support (drm_drv.h) */
-extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
-extern long drm_ioctl(struct file *filp,
- unsigned int cmd, unsigned long arg);
-#ifdef CONFIG_COMPAT
-extern long drm_compat_ioctl(struct file *filp,
-unsigned int cmd, unsigned long arg);
-#else
-/* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
-#define drm_compat_ioctl NULL
-#endif
-extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
-
-/* Misc. IOCTL support (drm_ioctl.c) */
-int drm_noop(struct drm_device *dev, void *data,
-struct drm_file *file_priv);
-int drm_invalid_op(struct drm_device *dev, void *data,
-  struct drm_file *file_priv);
 
 /*
  * These are exported to drivers so that they can implement fencing using
diff --git a/include/drm/drm_ioctl.h b/include/drm/drm_ioctl.h
new file mode 100644
index ..f17ee077f649
--- /dev/null
+++ b/include/drm/drm_ioctl.h
@@ -0,0 +1,102 @@
+/*
+ * Internal Header for the Direct Rendering Manager
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * Copyright (c) 2009-2010, Code Aurora Forum.
+ * All rights reserved.
+ *
+ * Author: Rickard E. (Rik) Faith 
+ * Author: Gareth Hughes 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTH

[Intel-gfx] [PATCH] drm/debugfs: Add kerneldoc

2017-03-22 Thread Daniel Vetter
I've decided to not document drm_debugfs_remove_files, it's on the way
out.

The biggest part is a huge todo.rst entry with what all should be
improved.

v2: Nits from Gabriel.

Cc: Gabriel Krisman Bertazi 
Reviewed-by: Gabriel Krisman Bertazi 
Signed-off-by: Daniel Vetter 
---
 Documentation/gpu/drm-uapi.rst |  9 
 Documentation/gpu/todo.rst | 26 +
 drivers/gpu/drm/drm_debugfs.c  | 51 ++
 drivers/gpu/drm/drm_internal.h |  2 +-
 include/drm/drm_debugfs.h  | 38 +--
 5 files changed, 74 insertions(+), 52 deletions(-)

diff --git a/Documentation/gpu/drm-uapi.rst b/Documentation/gpu/drm-uapi.rst
index 369e8ca12b8e..76356c86e358 100644
--- a/Documentation/gpu/drm-uapi.rst
+++ b/Documentation/gpu/drm-uapi.rst
@@ -210,6 +210,15 @@ Display CRC Support
 .. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
:export:
 
+Debugfs Support
+---
+
+.. kernel-doc:: include/drm/drm_debugfs.h
+   :internal:
+
+.. kernel-doc:: drivers/gpu/drm/drm_debugfs.c
+   :export:
+
 VBlank event handling
 =
 
diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
index 64e9d16170ce..0cdaddad2b9b 100644
--- a/Documentation/gpu/todo.rst
+++ b/Documentation/gpu/todo.rst
@@ -272,6 +272,32 @@ This is a really varied tasks with lots of little bits and 
pieces:
 
 Contact: Daniel Vetter
 
+Clean up the debugfs support
+
+
+There's a bunch of issues with it:
+
+- The drm_info_list ->show() function doesn't even bother to cast to the drm
+  structure for you. This is lazy.
+
+- We probably want to have some support for debugfs files on crtc/connectors 
and
+  maybe other kms objects directly in core. There's even drm_print support in
+  the funcs for these objects to dump kms state, so it's all there. And then 
the
+  ->show() functions should obviously give you a pointer to the right object.
+
+- The drm_info_list stuff is centered on drm_minor instead of drm_device. For
+  anything we want to print drm_device (or maybe drm_file) is the right thing.
+
+- The drm_driver->debugfs_init hooks we have is just an artifact of the old
+  midlayered load sequence. DRM debugfs should work more like sysfs, where you
+  can create properties/files for an object anytime you want, and the core
+  takes care of publishing/unpuplishing all the files at register/unregister
+  time. Drivers shouldn't need to worry about these technicalities, and fixing
+  this (together with the drm_minor->drm_device move) would allow us to remove
+  debugfs_init.
+
+Contact: Daniel Vetter
+
 Better Testing
 ==
 
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 4b02f4230562..c1807d5754b2 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -1,10 +1,3 @@
-/**
- * \file drm_debugfs.c
- * debugfs support for DRM
- *
- * \author Ben Gamari 
- */
-
 /*
  * Created: Sun Dec 21 13:08:50 2008 by bgam...@gmail.com
  *
@@ -75,16 +68,15 @@ static const struct file_operations drm_debugfs_fops = {
 
 
 /**
- * Initialize a given set of debugfs files for a device
- *
- * \param files The array of files to create
- * \param count The number of files given
- * \param root DRI debugfs dir entry.
- * \param minor device minor number
- * \return Zero on success, non-zero on failure
+ * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM
+ * minor
+ * @files: The array of files to create
+ * @count: The number of files given
+ * @root: DRI debugfs dir entry.
+ * @minor: device minor number
  *
  * Create a given set of debugfs files represented by an array of
- * &drm_info_list in the given root directory. These files will be removed
+ * &struct drm_info_list in the given root directory. These files will be 
removed
  * automatically on drm_debugfs_cleanup().
  */
 int drm_debugfs_create_files(const struct drm_info_list *files, int count,
@@ -133,17 +125,6 @@ int drm_debugfs_create_files(const struct drm_info_list 
*files, int count,
 }
 EXPORT_SYMBOL(drm_debugfs_create_files);
 
-/**
- * Initialize the DRI debugfs filesystem for a device
- *
- * \param dev DRM device
- * \param minor device minor number
- * \param root DRI debugfs dir entry.
- *
- * Create the DRI debugfs root entry "/sys/kernel/debug/dri", the device 
debugfs root entry
- * "/sys/kernel/debug/dri/%minor%/", and each entry in debugfs_list as
- * "/sys/kernel/debug/dri/%minor%/%name%".
- */
 int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 struct dentry *root)
 {
@@ -189,16 +170,6 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 }
 
 
-/**
- * Remove a list of debugfs files
- *
- * \param files The list of files
- * \param count The number of files
- * \param minor The minor of which we should remove the files
- * \return always zero.
- *
- * Remove all debugfs entries created by debugfs_init().
-

[Intel-gfx] [PATCH] drm: Extract drm_debugfs.h

2017-03-22 Thread Daniel Vetter
Doc polish will follow in the next patch.

v2: Put the include guard #endif at the end (Ville).

Cc: Ville Syrjälä 
Signed-off-by: Daniel Vetter 
---
 drivers/gpu/drm/drm_debugfs.c |  5 ++-
 include/drm/drmP.h| 44 +
 include/drm/drm_debugfs.h | 77 +++
 3 files changed, 82 insertions(+), 44 deletions(-)
 create mode 100644 include/drm/drm_debugfs.h

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 1d2d18d82d2e..4b02f4230562 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -34,9 +34,12 @@
 #include 
 #include 
 #include 
-#include 
+
+#include 
 #include 
 #include 
+#include 
+
 #include "drm_internal.h"
 #include "drm_crtc_internal.h"
 
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 0e383438f793..60f3255c43a8 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -78,6 +78,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct module;
 
@@ -371,27 +372,6 @@ struct drm_ioctl_desc {
 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
 
 /**
- * Info file list entry. This structure represents a debugfs or proc file to
- * be created by the drm core
- */
-struct drm_info_list {
-   const char *name; /** file name */
-   int (*show)(struct seq_file*, void*); /** show callback */
-   u32 driver_features; /**< Required driver features for this entry */
-   void *data;
-};
-
-/**
- * debugfs node structure. This structure represents a debugfs file.
- */
-struct drm_info_node {
-   struct list_head list;
-   struct drm_minor *minor;
-   const struct drm_info_list *info_ent;
-   struct dentry *dent;
-};
-
-/**
  * DRM device structure. This structure represent a complete card that
  * may contain multiple heads.
  */
@@ -592,28 +572,6 @@ int drm_invalid_op(struct drm_device *dev, void *data,
  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
  */
 
-   /* Debugfs support */
-#if defined(CONFIG_DEBUG_FS)
-extern int drm_debugfs_create_files(const struct drm_info_list *files,
-   int count, struct dentry *root,
-   struct drm_minor *minor);
-extern int drm_debugfs_remove_files(const struct drm_info_list *files,
-   int count, struct drm_minor *minor);
-#else
-static inline int drm_debugfs_create_files(const struct drm_info_list *files,
-  int count, struct dentry *root,
-  struct drm_minor *minor)
-{
-   return 0;
-}
-
-static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
-  int count, struct drm_minor *minor)
-{
-   return 0;
-}
-#endif
-
   /* sysfs support (drm_sysfs.c) */
 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
 
diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
new file mode 100644
index ..56924196d08d
--- /dev/null
+++ b/include/drm/drm_debugfs.h
@@ -0,0 +1,77 @@
+/*
+ * Internal Header for the Direct Rendering Manager
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * Copyright (c) 2009-2010, Code Aurora Forum.
+ * All rights reserved.
+ *
+ * Author: Rickard E. (Rik) Faith 
+ * Author: Gareth Hughes 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _DRM_DEBUGFS_H_
+#define _DRM_DEBUGFS_H_
+
+/**
+ * Info file list entry. This structure represents a debugfs or proc file to
+ * be created by the drm core
+ */
+struct drm_info_list {
+   const char *name; /** file name */
+   int (*show)(struct seq_file*, void*); /** show callback */
+   u32 driver_features; /**< Required driv

Re: [Intel-gfx] [PATCH v4 8/8] drm/dp: Track MST link bandwidth

2017-03-22 Thread Daniel Vetter
On Wed, Mar 22, 2017 at 01:30:30PM +0100, Maarten Lankhorst wrote:
> Op 16-03-17 om 08:10 schreef Dhinakaran Pandiyan:
> Is there any issue into attempting to release vcpi slots when they're already 
> released? If not, for patches 1-3 5-8
> 
> Reviewed-by: Maarten Lankhorst 

Merged patches 1-3 to drm-misc-next, thanks.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v4 8/8] drm/dp: Track MST link bandwidth

2017-03-22 Thread Pandiyan, Dhinakaran
On Wed, 2017-03-22 at 13:30 +0100, Maarten Lankhorst wrote:
> Op 16-03-17 om 08:10 schreef Dhinakaran Pandiyan:
> > From: "Pandiyan, Dhinakaran" 
> >
> > Use the added helpers to track MST link bandwidth for atomic modesets.
> > Link bw is acquired in the ->atomic_check() phase when CRTCs are being
> > enabled with drm_atomic_find_vcpi_slots() instead of drm_find_vcpi_slots().
> > Similarly, link bw is released during ->atomic_check() with the connector
> > helper callback ->atomic_release() when CRTCs are disabled.
> >
> > v2:
> > Squashed atomic_release() implementation and caller (Daniel)
> > Fixed logic for connector-crtc switching case (Daniel)
> > Fixed logic for suspend-resume case.
> >
> > Cc: Daniel Vetter 
> > Cc: Archit Taneja 
> > Cc: Maarten Lankhorst 
> > Cc: Chris Wilson 
> > Cc: Harry Wentland 
> > Signed-off-by: Dhinakaran Pandiyan 
> > ---
> >  drivers/gpu/drm/i915/intel_dp_mst.c | 38 
> > ++---
> >  1 file changed, 31 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c 
> > b/drivers/gpu/drm/i915/intel_dp_mst.c
> > index c1f62eb..a8f40fa 100644
> > --- a/drivers/gpu/drm/i915/intel_dp_mst.c
> > +++ b/drivers/gpu/drm/i915/intel_dp_mst.c
> > @@ -39,9 +39,9 @@ static bool intel_dp_mst_compute_config(struct 
> > intel_encoder *encoder,
> > struct intel_dp *intel_dp = &intel_dig_port->dp;
> > struct intel_connector *connector =
> > to_intel_connector(conn_state->connector);
> > -   struct drm_atomic_state *state;
> > +   struct drm_atomic_state *state = pipe_config->base.state;
> > int bpp;
> > -   int lane_count, slots;
> > +   int lane_count, slots = 0;
> > const struct drm_display_mode *adjusted_mode = 
> > &pipe_config->base.adjusted_mode;
> > int mst_pbn;
> >  
> > @@ -57,30 +57,53 @@ static bool intel_dp_mst_compute_config(struct 
> > intel_encoder *encoder,
> >  * seem to suggest we should do otherwise.
> >  */
> > lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
> > -
> > pipe_config->lane_count = lane_count;
> >  
> > pipe_config->pipe_bpp = bpp;
> > pipe_config->port_clock = intel_dp_max_link_rate(intel_dp);
> >  
> > -   state = pipe_config->base.state;
> > -
> > if (drm_dp_mst_port_has_audio(&intel_dp->mst_mgr, connector->port))
> > pipe_config->has_audio = true;
> > -   mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
> >  
> > +   mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp);
> > pipe_config->pbn = mst_pbn;
> > -   slots = drm_dp_find_vcpi_slots(&intel_dp->mst_mgr, mst_pbn);
> >  
> > intel_link_compute_m_n(bpp, lane_count,
> >adjusted_mode->crtc_clock,
> >pipe_config->port_clock,
> >&pipe_config->dp_m_n);
> >  
> > +   if (pipe_config->base.active) {
> > +   slots = drm_dp_atomic_find_vcpi_slots(state, &intel_dp->mst_mgr,
> > + connector->port, mst_pbn);
> > +   if (slots < 0) {
> > +   DRM_DEBUG_KMS("failed finding vcpi slots:%d\n", slots);
> > +   return false;
> > +   }
> > +   }
> > pipe_config->dp_m_n.tu = slots;
> >  
> > return true;
> > +}
> > +
> > +static void intel_dp_mst_atomic_release(struct drm_connector *connector,
> > +   struct drm_connector_state *conn_state)
> > +{
> > +   struct intel_dp_mst_encoder *intel_mst;
> > +   struct drm_dp_mst_topology_mgr *mgr;
> > +   struct drm_encoder *encoder;
> > +   struct intel_connector *intel_connector = to_intel_connector(connector);
> > +   struct drm_atomic_state *state = conn_state->state;
> > +   int slots;
> > +
> > +   encoder = connector->state->best_encoder;
> > +   intel_mst = enc_to_mst(encoder);
> > +   mgr = &intel_mst->primary->dp.mst_mgr;
> >  
> > +   slots = drm_dp_atomic_release_vcpi_slots(state, mgr,
> > +intel_connector->port);
> > +   if (slots < 0)
> > +   DRM_DEBUG_KMS("failed releasing vcpi slots:%d\n", slots);
> >  }
> >  
> >  static void intel_mst_disable_dp(struct intel_encoder *encoder,
> > @@ -387,6 +410,7 @@ static const struct drm_connector_helper_funcs 
> > intel_dp_mst_connector_helper_fun
> > .mode_valid = intel_dp_mst_mode_valid,
> > .atomic_best_encoder = intel_mst_atomic_best_encoder,
> > .best_encoder = intel_mst_best_encoder,
> > +   .atomic_release = intel_dp_mst_atomic_release,
> >  };
> >  
> >  static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder)
> 
> Is there any issue into attempting to release vcpi slots when they're already 
> released? If not, for patches 1-3 5-8
> 
> Reviewed-by: Maarten Lankhorst 
> 

Thanks for the review.

If we already had an atomic commit that released the slots, then
vcpi.num_slots in 'struct drm_dp_mst_port' would have been reset to 0.
The second time, release_vcpi_slots() is

Re: [Intel-gfx] [PATCH 05/16] drm: update todo.rst

2017-03-22 Thread Daniel Vetter
On Wed, Mar 22, 2017 at 03:31:00PM -0300, Gabriel Krisman Bertazi wrote:
> Daniel Vetter  writes:
> 
> > Just drive-by, but we have gsoc running so better to update it now.
> >
> > Great news is that two entries can be removed because essentially all
> > done.
> >
> > Signed-off-by: Daniel Vetter 
> > ---
> >  Documentation/gpu/todo.rst | 51 
> > --
> >  1 file changed, 4 insertions(+), 47 deletions(-)
> >
> > diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
> > index 9ecd2ebb8dd8..7dc6de07a3bc 100644
> > --- a/Documentation/gpu/todo.rst
> > +++ b/Documentation/gpu/todo.rst
> > @@ -16,7 +16,7 @@ De-midlayer drivers
> >  With the recent ``drm_bus`` cleanup patches for 3.17 it is no longer 
> > required
> >  to have a ``drm_bus`` structure set up. Drivers can directly set up the
> >  ``drm_device`` structure instead of relying on bus methods in ``drm_usb.c``
> > -and ``drm_platform.c``. The goal is to get rid of the driver's ``->load`` /
> > +and ``drm_pci.c``. The goal is to get rid of the driver's ``->load`` /
> >  ``->unload`` callbacks and open-code the load/unload sequence properly, 
> > using
> >  the new two-stage ``drm_device`` setup/teardown.
> >  
> > @@ -151,7 +151,7 @@ fine-grained per-buffer object and per-context
> > lockings scheme. Currently the
> >  following drivers still use ``struct_mutex``: ``msm``, ``omapdrm`` and
> >  ``udl``.
> >  
> > -Contact: Daniel Vetter
> > +Contact: Daniel Vetter, respective driver maintainers
> >  
> >  Switch to drm_connector_list_iter for any connector_list walking
> >  
> > @@ -193,6 +193,8 @@ plan is to switch to per-file driver API headers, which 
> > will also structure
> >  the kerneldoc better. This should also allow more fine-grained ``#include``
> >  directives.
> >  
> > +In the end no .c file should need to include ``drmP.h`` anymore.
> > +
> >  Contact: Daniel Vetter
> >  
> >  Add missing kerneldoc for exported functions
> > @@ -208,31 +210,6 @@ See https://dri.freedesktop.org/docs/drm/ for what's 
> > there already.
> >  
> >  Contact: Daniel Vetter
> >  
> > -Hide legacy cruft better
> > -
> > -
> > -Way back DRM supported only drivers which shadow-attached to PCI devices 
> > with
> > -userspace or fbdev drivers setting up outputs. Modern DRM drivers take 
> > charge
> > -of the entire device, you can spot them with the DRIVER_MODESET flag.
> > -
> > -Unfortunately there's still large piles of legacy code around which needs 
> > to
> > -be hidden so that driver writers don't accidentally end up using it. And to
> > -prevent security issues in those legacy IOCTLs from being exploited on 
> > modern
> > -drivers. This has multiple possible subtasks:
> > -
> > -* Make sure legacy IOCTLs can't be used on modern drivers.
> > -* Extract support code for legacy features into a ``drm-legacy.ko`` kernel
> > -  module and compile it only when one of the legacy drivers is enabled.
> 
> I've been interested in taking up the work to split drm-legacy.ko from
> drm.ko.  The plan is to make it an optional module that legacy drivers
> depend on, in a way that you don't need to recompile drm.ko to use it.
> 
> I think the issue with the current CONFIG_DRM_VM, for instance, which
> hid some of the code for legacy drivers is the downside of requiring
> recompilation of drm.ko before using a legacy driver.
> 
> Anyway, if you agree with this change, can you keep this entry until
> that is done?

Yeah if you're working on this already I can keep it. But you could keep
working on this also even if there's no todo entry, we're not going to
reject good ideas :-)

I'll resend with only the first sub-task removed, since that is done.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 07/16] drm: Extract drm_ioctl.h

2017-03-22 Thread Ville Syrjälä
On Wed, Mar 22, 2017 at 09:15:23PM +0100, Daniel Vetter wrote:
> On Wed, Mar 22, 2017 at 03:47:31PM +0200, Ville Syrjälä wrote:
> > On Wed, Mar 22, 2017 at 09:36:08AM +0100, Daniel Vetter wrote:
> > > To match the drm_ioctl.c we already have.
> > > 
> > > Signed-off-by: Daniel Vetter 
> > > ---
> > >  drivers/gpu/drm/drm_ioctl.c |   1 +
> > >  include/drm/drmP.h  |  61 +-
> > >  include/drm/drm_ioctl.h | 102 
> > > 
> > >  3 files changed, 104 insertions(+), 60 deletions(-)
> > >  create mode 100644 include/drm/drm_ioctl.h
> > > 
> > > diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> > > index 601bb0ded9d2..7f4f4f48e390 100644
> > > --- a/drivers/gpu/drm/drm_ioctl.c
> > > +++ b/drivers/gpu/drm/drm_ioctl.c

> > > +#define DRM_MAJOR   226
> > > +
> > > +#define DRM_AUTH 0x1
> > > +#define  DRM_MASTER  0x2
> > > +#define DRM_ROOT_ONLY0x4
> > > +#define DRM_CONTROL_ALLOW 0x8
> > > +#define DRM_UNLOCKED 0x10
> > > +#define DRM_RENDER_ALLOW 0x20
> > > +
> > > +struct drm_ioctl_desc {
> > > + unsigned int cmd;
> > > + int flags;
> > > + drm_ioctl_t *func;
> > > + const char *name;
> > > +};
> > > +
> > > +/**
> > 
> > s/**/*/ ?
> 
> It'll get addressed in the next patch, where I clean up the kernel-doc. I
> assume I can still get your r-b for this patch here?

Sure thing.

-- 
Ville Syrjälä
Intel OTC
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 2/2] drm/i915: Fix SKL cursor watermarks

2017-03-22 Thread Ville Syrjälä
On Wed, Mar 22, 2017 at 11:51:56AM +0200, Ander Conselvan De Oliveira wrote:
> On Wed, 2017-03-22 at 10:01 +0100, Maarten Lankhorst wrote:
> > Op 14-03-17 om 16:10 schreef ville.syrj...@linux.intel.com:
> > > From: Ville Syrjälä 
> > > 
> > > Use intel_wm_plane_visible() to determine cursor visibility for SKL+
> > > also. Previously SKL+ would check the actual visibility which now
> > > conflicts with the assumptions in intel_legacy_cursor_update().
> > > 
> > > We also change SKL+ to compute the cursor watermarks based on the
> > > unclipped cursor size, just as we do on all the other platforms.
> > > Using the clipped size could now result in garbage results.
> > > 
> > > Testcase: igt/kms_chv_cursor_fail
> > > Fixes: a5509abda48e ("drm/i915: Fix legacy cursor vs. watermarks for 
> > > ILK-BDW")
> > > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100195
> > > Signed-off-by: Ville Syrjälä 
> > 
> > For patch 1 & 2:
> > 
> > Reviewed-by: Maarten Lankhorst 
> > 
> > Should be the right way to fix it. :)
> 
> In intel_legacy_cursor_update(), I see the comment below,
> 
> /*
>  * If any parameters change that may affect watermarks,
>  * take the slowpath. Only changing fb or position should be
>  * in the fastpath.
>  */
> 
> followed by a bunch of checks on the plane size and fb. My understanding is 
> that
> the bug was caused by those assumptions being out of sync with the actual
> watermark code. So IMO, a more proper way to fix this would be to have
> intel_legacy_cursor_update() call into watermark code to ask if it can proceed
> or not, instead of making assumptions of what can cause watermarks to change.

Yeah, we do (at at least used to) have some assumptions about watermarks
in other parts of the driver as well. That's potentially something we
should fix, probably when someone finally starts doing the
s/active/enable/ change for watermarks.

> 
> But since the duplicated assumptions were there before, this fix doesn't make
> the overall situation any worse.
> 
> Acked-by: Ander Conselvan de Oliveira 

Thank you all. Series pushed to dinq.

-- 
Ville Syrjälä
Intel OTC
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 07/16] drm: Extract drm_ioctl.h

2017-03-22 Thread Daniel Vetter
On Wed, Mar 22, 2017 at 03:47:31PM +0200, Ville Syrjälä wrote:
> On Wed, Mar 22, 2017 at 09:36:08AM +0100, Daniel Vetter wrote:
> > To match the drm_ioctl.c we already have.
> > 
> > Signed-off-by: Daniel Vetter 
> > ---
> >  drivers/gpu/drm/drm_ioctl.c |   1 +
> >  include/drm/drmP.h  |  61 +-
> >  include/drm/drm_ioctl.h | 102 
> > 
> >  3 files changed, 104 insertions(+), 60 deletions(-)
> >  create mode 100644 include/drm/drm_ioctl.h
> > 
> > diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> > index 601bb0ded9d2..7f4f4f48e390 100644
> > --- a/drivers/gpu/drm/drm_ioctl.c
> > +++ b/drivers/gpu/drm/drm_ioctl.c
> > @@ -28,6 +28,7 @@
> >   * OTHER DEALINGS IN THE SOFTWARE.
> >   */
> >  
> > +#include 
> >  #include 
> >  #include 
> >  #include "drm_legacy.h"
> > diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> > index fc2a0744413d..248d2408e56b 100644
> > --- a/include/drm/drmP.h
> > +++ b/include/drm/drmP.h
> > @@ -80,6 +80,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> 
> Same question as for the debugfs thing. Why do we need this?

I forgot to scroll down, oops :(

> >  struct module;
> >  
> > @@ -318,49 +319,6 @@ struct pci_controller;
> >  
> >  #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
> >  
> > -/**
> > - * Ioctl function type.
> > - *
> > - * \param inode device inode.
> > - * \param file_priv DRM file private pointer.
> > - * \param cmd command.
> > - * \param arg argument.
> > - */
> > -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
> > -   struct drm_file *file_priv);
> > -
> > -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
> > -  unsigned long arg);
> > -
> > -#define DRM_IOCTL_NR(n)_IOC_NR(n)
> > -#define DRM_MAJOR   226
> > -
> > -#define DRM_AUTH   0x1
> > -#defineDRM_MASTER  0x2
> > -#define DRM_ROOT_ONLY  0x4
> > -#define DRM_CONTROL_ALLOW 0x8
> > -#define DRM_UNLOCKED   0x10
> > -#define DRM_RENDER_ALLOW 0x20
> > -
> > -struct drm_ioctl_desc {
> > -   unsigned int cmd;
> > -   int flags;
> > -   drm_ioctl_t *func;
> > -   const char *name;
> > -};
> > -
> > -/**
> > - * Creates a driver or general drm_ioctl_desc array entry for the given
> > - * ioctl, for use by drm_ioctl().
> > - */
> > -
> > -#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)
> > \
> > -   [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {\
> > -   .cmd = DRM_IOCTL_##ioctl,   \
> > -   .func = _func,  \
> > -   .flags = _flags,\
> > -   .name = #ioctl  \
> > -}
> >  
> >  /* Flags and return codes for get_vblank_timestamp() driver function. */
> >  #define DRM_CALLED_FROM_VBLIRQ 1
> > @@ -550,23 +508,6 @@ static inline int drm_device_is_unplugged(struct 
> > drm_device *dev)
> >  /*@{*/
> >  
> > /* Driver support (drm_drv.h) */
> > -extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
> > -extern long drm_ioctl(struct file *filp,
> > - unsigned int cmd, unsigned long arg);
> > -#ifdef CONFIG_COMPAT
> > -extern long drm_compat_ioctl(struct file *filp,
> > -unsigned int cmd, unsigned long arg);
> > -#else
> > -/* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
> > -#define drm_compat_ioctl NULL
> > -#endif
> > -extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
> > -
> > -/* Misc. IOCTL support (drm_ioctl.c) */
> > -int drm_noop(struct drm_device *dev, void *data,
> > -struct drm_file *file_priv);
> > -int drm_invalid_op(struct drm_device *dev, void *data,
> > -  struct drm_file *file_priv);
> >  
> >  /*
> >   * These are exported to drivers so that they can implement fencing using
> > diff --git a/include/drm/drm_ioctl.h b/include/drm/drm_ioctl.h
> > new file mode 100644
> > index ..3c3677b5bdb2
> > --- /dev/null
> > +++ b/include/drm/drm_ioctl.h
> > @@ -0,0 +1,102 @@
> > +/*
> > + * Internal Header for the Direct Rendering Manager
> > + *
> > + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
> > + * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
> > + * Copyright (c) 2009-2010, Code Aurora Forum.
> > + * All rights reserved.
> > + *
> > + * Author: Rickard E. (Rik) Faith 
> > + * Author: Gareth Hughes 
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the 
> > "Software"),
> > + * to deal in the Software without restriction, including without 
> > limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the So

Re: [Intel-gfx] [PATCH 02/16] drm: Extract drm_debugfs.h

2017-03-22 Thread Daniel Vetter
On Wed, Mar 22, 2017 at 03:34:10PM +0200, Ville Syrjälä wrote:
> On Wed, Mar 22, 2017 at 09:36:03AM +0100, Daniel Vetter wrote:
> > Doc polish will follow in the next patch.
> > 
> > Signed-off-by: Daniel Vetter 
> > ---
> >  drivers/gpu/drm/drm_debugfs.c |  5 ++-
> >  include/drm/drmP.h| 44 +
> >  include/drm/drm_debugfs.h | 76 
> > +++
> >  3 files changed, 81 insertions(+), 44 deletions(-)
> >  create mode 100644 include/drm/drm_debugfs.h
> > 
> > diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> > index 1d2d18d82d2e..4b02f4230562 100644
> > --- a/drivers/gpu/drm/drm_debugfs.c
> > +++ b/drivers/gpu/drm/drm_debugfs.c
> > @@ -34,9 +34,12 @@
> >  #include 
> >  #include 
> >  #include 
> > -#include 
> > +
> > +#include 
> >  #include 
> >  #include 
> > +#include 
> > +
> >  #include "drm_internal.h"
> >  #include "drm_crtc_internal.h"
> >  
> > diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> > index 0e383438f793..60f3255c43a8 100644
> > --- a/include/drm/drmP.h
> > +++ b/include/drm/drmP.h
> > @@ -78,6 +78,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> 
> Why do we need this?
> 
> >  
> >  struct module;
> >  
> > @@ -371,27 +372,6 @@ struct drm_ioctl_desc {
> >  #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
> >  
> >  /**
> > - * Info file list entry. This structure represents a debugfs or proc file 
> > to
> > - * be created by the drm core
> > - */
> > -struct drm_info_list {
> > -   const char *name; /** file name */
> > -   int (*show)(struct seq_file*, void*); /** show callback */
> > -   u32 driver_features; /**< Required driver features for this entry */
> > -   void *data;
> > -};
> > -
> > -/**
> > - * debugfs node structure. This structure represents a debugfs file.
> > - */
> > -struct drm_info_node {
> > -   struct list_head list;
> > -   struct drm_minor *minor;
> > -   const struct drm_info_list *info_ent;
> > -   struct dentry *dent;
> > -};
> > -
> > -/**
> >   * DRM device structure. This structure represent a complete card that
> >   * may contain multiple heads.
> >   */
> > @@ -592,28 +572,6 @@ int drm_invalid_op(struct drm_device *dev, void *data,
> >   * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
> >   */
> >  
> > -   /* Debugfs support */
> > -#if defined(CONFIG_DEBUG_FS)
> > -extern int drm_debugfs_create_files(const struct drm_info_list *files,
> > -   int count, struct dentry *root,
> > -   struct drm_minor *minor);
> > -extern int drm_debugfs_remove_files(const struct drm_info_list *files,
> > -   int count, struct drm_minor *minor);
> > -#else
> > -static inline int drm_debugfs_create_files(const struct drm_info_list 
> > *files,
> > -  int count, struct dentry *root,
> > -  struct drm_minor *minor)
> > -{
> > -   return 0;
> > -}
> > -
> > -static inline int drm_debugfs_remove_files(const struct drm_info_list 
> > *files,
> > -  int count, struct drm_minor *minor)
> > -{
> > -   return 0;
> > -}
> > -#endif
> > -
> >/* sysfs support (drm_sysfs.c) */
> >  extern void drm_sysfs_hotplug_event(struct drm_device *dev);
> >  
> > diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
> > new file mode 100644
> > index ..17e47c073fa9
> > --- /dev/null
> > +++ b/include/drm/drm_debugfs.h
> > @@ -0,0 +1,76 @@
> > +/*
> > + * Internal Header for the Direct Rendering Manager
> > + *
> > + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
> > + * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
> > + * Copyright (c) 2009-2010, Code Aurora Forum.
> > + * All rights reserved.
> > + *
> > + * Author: Rickard E. (Rik) Faith 
> > + * Author: Gareth Hughes 
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the 
> > "Software"),
> > + * to deal in the Software without restriction, including without 
> > limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice (including the 
> > next
> > + * paragraph) shall be included in all copies or substantial portions of 
> > the
> > + * Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
> > OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIA

Re: [Intel-gfx] [PATCH 1/3] drm: Defer disabling the vblank IRQ until the next interrupt (for instant-off)

2017-03-22 Thread Ville Syrjälä
On Wed, Mar 22, 2017 at 04:06:32PM +0100, Mario Kleiner wrote:
> On 03/15/2017 10:00 PM, Ville Syrjälä wrote:
> > On Wed, Mar 15, 2017 at 08:40:25PM +, Chris Wilson wrote:
> >> On vblank instant-off systems, we can get into a situation where the cost
> >> of enabling and disabling the vblank IRQ around a drmWaitVblank query
> >> dominates. And with the advent of even deeper hardware sleep state,
> >> touching registers becomes ever more expensive.  However, we know that if
> >> the user wants the current vblank counter, they are also very likely to
> >> immediately queue a vblank wait and so we can keep the interrupt around
> >> and only turn it off if we have no further vblank requests queued within
> >> the interrupt interval.
> >>
> >> After vblank event delivery, this patch adds a shadow of one vblank where
> >> the interrupt is kept alive for the user to query and queue another vblank
> >> event. Similarly, if the user is using blocking drmWaitVblanks, the
> >> interrupt will be disabled on the IRQ following the wait completion.
> >> However, if the user is simply querying the current vblank counter and
> >> timestamp, the interrupt will be disabled after every IRQ and the user
> >> will enabled it again on the first query following the IRQ.
> >>
> >> v2: Mario Kleiner -
> >> After testing this, one more thing that would make sense is to move
> >> the disable block at the end of drm_handle_vblank() instead of at the
> >> top.
> >>
> >> Turns out that if high precision timestaming is disabled or doesn't
> >> work for some reason (as can be simulated by echo 0 >
> >> /sys/module/drm/parameters/timestamp_precision_usec), then with your
> >> delayed disable code at its current place, the vblank counter won't
> >> increment anymore at all for instant queries, ie. with your other
> >> "instant query" patches. Clients which repeatedly query the counter
> >> and wait for it to progress will simply hang, spinning in an endless
> >> query loop. There's that comment in vblank_disable_and_save:
> >>
> >> "* Skip this step if there isn't any high precision timestamp
> >>  * available. In that case we can't account for this and just
> >>  * hope for the best.
> >>  */
> >>
> >> With the disable happening after leading edge of vblank (== hw counter
> >> increment already happened) but before the vblank counter/timestamp
> >> handling in drm_handle_vblank, that step is needed to keep the counter
> >> progressing, so skipping it is bad.
> >>
> >> Now without high precision timestamping support, a kms driver must not
> >> set dev->vblank_disable_immediate = true, as this would cause problems
> >> for clients, so this shouldn't matter, but it would be good to still
> >> make this robust against a future kms driver which might have
> >> unreliable high precision timestamping, e.g., high precision
> >> timestamping that intermittently doesn't work.
> >>
> >> v3: Patch before coffee needs extra coffee.
> >>
> >> Testcase: igt/kms_vblank
> >> Signed-off-by: Chris Wilson 
> >> Cc: Ville Syrjälä 
> >> Cc: Daniel Vetter 
> >> Cc: Michel Dänzer 
> >> Cc: Laurent Pinchart 
> >> Cc: Dave Airlie ,
> >> Cc: Mario Kleiner 
> >
> > Yep. This seems like a good idea to me. I just neglected to review it
> > last time around (and maybe even before that?) for some reason. Locks
> > seem to be taken in the right order, so it at least looks safe to me.
> >
> > Reviewed-by: Ville Syrjälä 
> >
> 
> Hi,
> 
> as a followup to this one, maybe we should move the 
> drm_handle_vblank_events(dev, pipe); down, immediately after Chris new 
> delayed disable code?
> 
> The idea was to avoid lots of redundant enable->disable->enable... calls 
> by having some 1 frame delay before disable. This works for pure vblank 
> count/ts queries.
> 
> But both DRI2 and DRI3/Present use vblank events to trigger a 
> pageflip-ioctl at the right target vblank. With the current ordering we 
> may dispatch the vblank swap trigger event to the X-Server and drop the 
> vblank refcount to zero due to the vblank_put inside 
> drm_handle_vblank_events for the dispatched event, then detect in this 
> patch that refcount == 0 and disable vblanks, but a few microseconds 
> later the server will queue a pageflip ioctl which bumps the refcount 
> and reenables vblank irqs, so we have a redundant disable->enable.
> 
> Also many kms drivers now use drm_crtc_arm_vblank_event() for pageflip 
> completion handling at vblank, the pageflip completion events are also 
> dispatched via drm_handle_vblank_events(). After a pageflip completes, 
> it makes sense to have this "swap shadow" of 1 full frame, as animations 
> would likely queue a new vblank query/event immediately for the next 
> animation frame.

That does seem like a decent idea. It won't actually change anything for
i915 page flips since we still hang on to our vblank reference after
drm_handle_vblank() returns. But if you, for example, just call
glXWaitVideoSyncSGI(1,0,...) in a loop the current code will still
result o

Re: [Intel-gfx] Upgrading xserver-xorg-video-intel removed skylake support?

2017-03-22 Thread Clemens Eisserer
Hi,

Any idea what's going on?
>
> For now, I had to go back:
> saruman:/var/cache/apt/archives# dpkg -i xserver-xorg-video-intel_2%
> 3a2.99.917+git20160218-1_amd64.deb xserver-xorg-video-intel-dbg_
> 2%3a2.99.917+git20160218-1_amd64.deb xserver-common_2%3a1.18.1-1_all.deb
> xserver-xorg-core_2%3a1.18.1-1_amd64.deb
>

Because the intel DDX driver didn't have a stable release for years, many
distributions decided to go with modesetting + glamor acceleration instead:
https://tjaalton.wordpress.com/2016/07/23/intel-graphics-gen4-and-newer-now-defaults-to-modesetting-driver-on-x/

- Clemens
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 04/16] drm/debugfs: Add kerneldoc

2017-03-22 Thread Gabriel Krisman Bertazi
Daniel Vetter  writes:

> I've decided to not document drm_debugfs_remove_files, it's on the way
> out.
>
> The biggest part is a huge todor.rst entry with what all should be
> improved.

todo.rst

>
> Signed-off-by: Daniel Vetter 
> ---
>  Documentation/gpu/drm-uapi.rst |  9 
>  Documentation/gpu/todo.rst | 26 +
>  drivers/gpu/drm/drm_debugfs.c  | 51 
> ++
>  drivers/gpu/drm/drm_internal.h |  2 +-
>  include/drm/drm_debugfs.h  | 38 +--
>  5 files changed, 74 insertions(+), 52 deletions(-)
>
> diff --git a/Documentation/gpu/drm-uapi.rst b/Documentation/gpu/drm-uapi.rst
> index 369e8ca12b8e..76356c86e358 100644
> --- a/Documentation/gpu/drm-uapi.rst
> +++ b/Documentation/gpu/drm-uapi.rst
> @@ -210,6 +210,15 @@ Display CRC Support
>  .. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
> :export:
>  
> +Debugfs Support
> +---
> +
> +.. kernel-doc:: include/drm/drm_debugfs.h
> +   :internal:
> +
> +.. kernel-doc:: drivers/gpu/drm/drm_debugfs.c
> +   :export:
> +
>  VBlank event handling
>  =
>  
> diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
> index 64e9d16170ce..9ecd2ebb8dd8 100644
> --- a/Documentation/gpu/todo.rst
> +++ b/Documentation/gpu/todo.rst
> @@ -272,6 +272,32 @@ This is a really varied tasks with lots of little bits 
> and pieces:
>  
>  Contact: Daniel Vetter
>  
> +Clean up the debugfs support
> +
> +
> +There's a bunch of issues with it:
> +
> +- The drm_info_list -> show function doesn't even bother to cast to the drm
> +  structure for you. This is lazy.
> +
> +- We probably want to have some support for debugfs files on crtc/connectors 
> and
> +  maybe other kms objects directly in core. There's even drm_print support in
> +  the funcs for these objects to dump kms state, so it's all there. And then 
> the
> +  ->show functions should obviously give you a pointer to the right object.

should you use ->show() ?  not sure.  Either way, extra space on the
previuous "->show" instance.

> +
> +- The drm_info_list stuff is centered on drm_minor instead of drm_device. For
> +  anything we want to print drm_device (or maybe drm_file) is the right 
> thing.
> +
> +- The drm_driver->debugfs_init hooks we have is just an artifact of the old
> +  midlayered load sequence. DRM debugfs should work more like sysfs, where 
> you
> +  can create properties/files for an object anytime you want, and the core
> +  takes care of publishing/unpuplishing all the files at register/unregister
> +  time. Drivers shouldn't need to worry about these technicalities, and 
> fixing
> +  this (together with the drm_minor->drm_device move) would allow us to 
> remove
> +  debugfs_init.
> +
> +Contact: Daniel Vetter
> +
>  Better Testing
>  ==
>  
> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> index 4b02f4230562..c1807d5754b2 100644
> --- a/drivers/gpu/drm/drm_debugfs.c
> +++ b/drivers/gpu/drm/drm_debugfs.c
> @@ -1,10 +1,3 @@
> -/**
> - * \file drm_debugfs.c
> - * debugfs support for DRM
> - *
> - * \author Ben Gamari 
> - */
> -
>  /*
>   * Created: Sun Dec 21 13:08:50 2008 by bgam...@gmail.com
>   *
> @@ -75,16 +68,15 @@ static const struct file_operations drm_debugfs_fops = {
>  
>  
>  /**
> - * Initialize a given set of debugfs files for a device
> - *
> - * \param files The array of files to create
> - * \param count The number of files given
> - * \param root DRI debugfs dir entry.
> - * \param minor device minor number
> - * \return Zero on success, non-zero on failure
> + * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM
> + *   minor
> + * @files: The array of files to create
> + * @count: The number of files given
> + * @root: DRI debugfs dir entry.
> + * @minor: device minor number
>   *
>   * Create a given set of debugfs files represented by an array of
> - * &drm_info_list in the given root directory. These files will be removed
> + * &struct drm_info_list in the given root directory. These files will be 
> removed
>   * automatically on drm_debugfs_cleanup().
>   */
>  int drm_debugfs_create_files(const struct drm_info_list *files, int count,
> @@ -133,17 +125,6 @@ int drm_debugfs_create_files(const struct drm_info_list 
> *files, int count,
>  }
>  EXPORT_SYMBOL(drm_debugfs_create_files);
>  
> -/**
> - * Initialize the DRI debugfs filesystem for a device
> - *
> - * \param dev DRM device
> - * \param minor device minor number
> - * \param root DRI debugfs dir entry.
> - *
> - * Create the DRI debugfs root entry "/sys/kernel/debug/dri", the device 
> debugfs root entry
> - * "/sys/kernel/debug/dri/%minor%/", and each entry in debugfs_list as
> - * "/sys/kernel/debug/dri/%minor%/%name%".
> - */
>  int drm_debugfs_init(struct drm_minor *minor, int minor_id,
>struct dentry *root)
>  {
> @@ -189,16 +170,6 @@ int drm_debu

Re: [Intel-gfx] [PATCH] drm/i915: Prefer to report ENOMEM rather than incur the oom for gfx allocations

2017-03-22 Thread Chris Wilson
On Wed, Mar 22, 2017 at 02:24:51PM +0100, Daniel Vetter wrote:
> On Wed, Mar 22, 2017 at 03:11:58PM +0200, Joonas Lahtinen wrote:
> > On ke, 2017-03-22 at 11:05 +, Chris Wilson wrote:
> > > Since gfx allocations tend to be large, unmovable and disposable, report
> > > the allocation failure back to userspace as an ENOMEM rather than incur
> > > the oomkiller. We have already tried to make room by purging our own
> > > cached gfx objects, and the oomkiller doesn't attribute ownership of gfx
> > > objects so will likely pick the wrong candidate. Instead, let userspace
> > > see the ENOMEM.
> > > 
> > > Signed-off-by: Chris Wilson 
> > 
> > A-b from Daniel.
> > 
> > Reviewed-by: Joonas Lahtinen 
> 
> We suck. Oh well, Acked-by: Daniel Vetter 

Been mulling this over. It's not 100% (mostly deliberate in that I
didn't adjust the mapping's gfp and just this allocations), so some
oomkiller still creeps in, but it does greatly improve predictability of
failure. The only drawback is where a small client is unable to allocate
memory -- however, we already strived to recover enough memory from our
own pool, and gfx for the large part are recoverable, and userspace
should take ENOMEM in its stride. (Give or take the SIGBUS, but you get
those anyway on out of memory during GTT mmaps, and I only know of one
driver that took pains to handle that.) Still better than indescriminate
SIGKILL.

With that in mind, pushed.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 01/16] drm: drop extern from function decls

2017-03-22 Thread Gabriel Krisman Bertazi
Daniel Vetter  writes:

> It's the default storage class for functions, entirely redundant. And
> a lot of these headers are a bit inconsistent due to organically
> grown.
>

Reviewed-by: Gabriel Krisman Bertazi 


-- 
Gabriel Krisman Bertazi
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 2/2] drm/i915: kill intel_ddi_pll_select()

2017-03-22 Thread Ville Syrjälä
On Wed, Mar 22, 2017 at 03:58:45PM -0300, Paulo Zanoni wrote:
> All it does is pick the encoder and call intel_get_shared_dpll(). We
> can just do this in the caller. One less indirection level during code
> reading.
> 
> As another plus, now the two callers of intel_get_shared_dpll() are
> {ironlake,haswell}_crtc_compute_clock().
> 
> Reported-by: Ville Syrjälä 
> Signed-off-by: Paulo Zanoni 
> ---
>  drivers/gpu/drm/i915/intel_ddi.c | 25 ++---
>  drivers/gpu/drm/i915/intel_display.c |  8 +++-
>  drivers/gpu/drm/i915/intel_drv.h |  4 ++--
>  3 files changed, 11 insertions(+), 26 deletions(-)
> 
> 
> To be honest I'm not super sure if this change is an improvement. I like 
> keeping
> DDI-related code in intel_ddi.c. I'll let you guys decide with the
> upvote/downvote buttons in your email clients.

I guess the thing that sort of ruins is the
intel_ddi_get_crtc_new_encoder() call. First I thought we could nuke
that by using output_types instead of encoder->type, but looks like
BXT wants to disagree with us and really requires the encoder in
.get_dpll() :(

Oh well, we trade one ddi thing for another. Although
intel_ddi_get_crtc_new_encoder() doesn't really have anything truly ddi
specific in it so we could even move it elsewhere or even just inline it
in .compute_clock() since it's not even called from anywhere else.

I do like the fact that there's at least one less hoop to jump
through when tracing through the code. So this works for me.

Reviewed-by: Ville Syrjälä 

> 
> 
> diff --git a/drivers/gpu/drm/i915/intel_ddi.c 
> b/drivers/gpu/drm/i915/intel_ddi.c
> index 08a810d..3fbe498 100644
> --- a/drivers/gpu/drm/i915/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/intel_ddi.c
> @@ -837,7 +837,8 @@ intel_ddi_get_crtc_encoder(struct intel_crtc *crtc)
>   return ret;
>  }
>  
> -static struct intel_encoder *
> +/* Finds the only possible encoder associated with the given CRTC. */
> +struct intel_encoder *
>  intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
>  {
>   struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
> @@ -1127,28 +1128,6 @@ void intel_ddi_clock_get(struct intel_encoder *encoder,
>   bxt_ddi_clock_get(encoder, pipe_config);
>  }
>  
> -/*
> - * Tries to find a *shared* PLL for the CRTC and store it in
> - * intel_crtc->ddi_pll_sel.
> - *
> - * For private DPLLs, compute_config() should do the selection for us. This
> - * function should be folded into compute_config() eventually.
> - */
> -bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
> -   struct intel_crtc_state *crtc_state)
> -{
> - struct intel_encoder *encoder =
> - intel_ddi_get_crtc_new_encoder(crtc_state);
> - struct intel_shared_dpll *pll;
> -
> - pll = intel_get_shared_dpll(intel_crtc, crtc_state, encoder);
> - if (!pll)
> - DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
> -   pipe_name(intel_crtc->pipe));
> -
> - return pll != NULL;
> -}
> -
>  void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
>  {
>   struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
> diff --git a/drivers/gpu/drm/i915/intel_display.c 
> b/drivers/gpu/drm/i915/intel_display.c
> index 010e5dd..9cdf9b2 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -8862,8 +8862,14 @@ static int haswell_crtc_compute_clock(struct 
> intel_crtc *crtc,
> struct intel_crtc_state *crtc_state)
>  {
>   if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
> - if (!intel_ddi_pll_select(crtc, crtc_state))
> + struct intel_encoder *encoder =
> + intel_ddi_get_crtc_new_encoder(crtc_state);
> +
> + if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
> + DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
> +   pipe_name(crtc->pipe));
>   return -EINVAL;
> + }
>   }
>  
>   crtc->lowfreq_avail = false;
> diff --git a/drivers/gpu/drm/i915/intel_drv.h 
> b/drivers/gpu/drm/i915/intel_drv.h
> index 51228fe..ad7bdf5 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -1236,8 +1236,8 @@ void intel_ddi_disable_transcoder_func(struct 
> drm_i915_private *dev_priv,
>  enum transcoder cpu_transcoder);
>  void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state);
>  void intel_ddi_disable_pipe_clock(const  struct intel_crtc_state 
> *crtc_state);
> -bool intel_ddi_pll_select(struct intel_crtc *crtc,
> -   struct intel_crtc_state *crtc_state);
> +struct intel_encoder *
> +intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state);
>  void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_stat

[Intel-gfx] [PATCH 2/2] drm/i915: kill intel_ddi_pll_select()

2017-03-22 Thread Paulo Zanoni
All it does is pick the encoder and call intel_get_shared_dpll(). We
can just do this in the caller. One less indirection level during code
reading.

As another plus, now the two callers of intel_get_shared_dpll() are
{ironlake,haswell}_crtc_compute_clock().

Reported-by: Ville Syrjälä 
Signed-off-by: Paulo Zanoni 
---
 drivers/gpu/drm/i915/intel_ddi.c | 25 ++---
 drivers/gpu/drm/i915/intel_display.c |  8 +++-
 drivers/gpu/drm/i915/intel_drv.h |  4 ++--
 3 files changed, 11 insertions(+), 26 deletions(-)


To be honest I'm not super sure if this change is an improvement. I like keeping
DDI-related code in intel_ddi.c. I'll let you guys decide with the
upvote/downvote buttons in your email clients.


diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index 08a810d..3fbe498 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -837,7 +837,8 @@ intel_ddi_get_crtc_encoder(struct intel_crtc *crtc)
return ret;
 }
 
-static struct intel_encoder *
+/* Finds the only possible encoder associated with the given CRTC. */
+struct intel_encoder *
 intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
 {
struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
@@ -1127,28 +1128,6 @@ void intel_ddi_clock_get(struct intel_encoder *encoder,
bxt_ddi_clock_get(encoder, pipe_config);
 }
 
-/*
- * Tries to find a *shared* PLL for the CRTC and store it in
- * intel_crtc->ddi_pll_sel.
- *
- * For private DPLLs, compute_config() should do the selection for us. This
- * function should be folded into compute_config() eventually.
- */
-bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
- struct intel_crtc_state *crtc_state)
-{
-   struct intel_encoder *encoder =
-   intel_ddi_get_crtc_new_encoder(crtc_state);
-   struct intel_shared_dpll *pll;
-
-   pll = intel_get_shared_dpll(intel_crtc, crtc_state, encoder);
-   if (!pll)
-   DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
- pipe_name(intel_crtc->pipe));
-
-   return pll != NULL;
-}
-
 void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
 {
struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
diff --git a/drivers/gpu/drm/i915/intel_display.c 
b/drivers/gpu/drm/i915/intel_display.c
index 010e5dd..9cdf9b2 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -8862,8 +8862,14 @@ static int haswell_crtc_compute_clock(struct intel_crtc 
*crtc,
  struct intel_crtc_state *crtc_state)
 {
if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
-   if (!intel_ddi_pll_select(crtc, crtc_state))
+   struct intel_encoder *encoder =
+   intel_ddi_get_crtc_new_encoder(crtc_state);
+
+   if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
+   DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
+ pipe_name(crtc->pipe));
return -EINVAL;
+   }
}
 
crtc->lowfreq_avail = false;
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 51228fe..ad7bdf5 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1236,8 +1236,8 @@ void intel_ddi_disable_transcoder_func(struct 
drm_i915_private *dev_priv,
   enum transcoder cpu_transcoder);
 void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state);
 void intel_ddi_disable_pipe_clock(const  struct intel_crtc_state *crtc_state);
-bool intel_ddi_pll_select(struct intel_crtc *crtc,
- struct intel_crtc_state *crtc_state);
+struct intel_encoder *
+intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state);
 void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state);
 void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp);
 bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector);
-- 
2.7.4

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 1/2] drm/i915: simplify intel_ddi_pll_select()

2017-03-22 Thread Paulo Zanoni
Because {hsw,skl,bxt}_ddi_pll_select all pretty much do the same thing
in slightly different ways. Replace everything with a simple copy of
the function and inline it inside intle_ddi_pll_select().

v2: s/return pll/return pll != NULL/ (Ville)

Reviewed-by: Ville Syrjälä 
Signed-off-by: Paulo Zanoni 
---
 drivers/gpu/drm/i915/intel_ddi.c | 58 +---
 1 file changed, 7 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index d8214ba..08a810d 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -1127,47 +1127,6 @@ void intel_ddi_clock_get(struct intel_encoder *encoder,
bxt_ddi_clock_get(encoder, pipe_config);
 }
 
-static bool
-hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
-  struct intel_crtc_state *crtc_state,
-  struct intel_encoder *encoder)
-{
-   struct intel_shared_dpll *pll;
-
-   pll = intel_get_shared_dpll(intel_crtc, crtc_state,
-   encoder);
-   if (!pll)
-   DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
-pipe_name(intel_crtc->pipe));
-
-   return pll;
-}
-
-static bool
-skl_ddi_pll_select(struct intel_crtc *intel_crtc,
-  struct intel_crtc_state *crtc_state,
-  struct intel_encoder *encoder)
-{
-   struct intel_shared_dpll *pll;
-
-   pll = intel_get_shared_dpll(intel_crtc, crtc_state, encoder);
-   if (pll == NULL) {
-   DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
-pipe_name(intel_crtc->pipe));
-   return false;
-   }
-
-   return true;
-}
-
-static bool
-bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
-  struct intel_crtc_state *crtc_state,
-  struct intel_encoder *encoder)
-{
-   return !!intel_get_shared_dpll(intel_crtc, crtc_state, encoder);
-}
-
 /*
  * Tries to find a *shared* PLL for the CRTC and store it in
  * intel_crtc->ddi_pll_sel.
@@ -1178,19 +1137,16 @@ bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
 bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
  struct intel_crtc_state *crtc_state)
 {
-   struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
struct intel_encoder *encoder =
intel_ddi_get_crtc_new_encoder(crtc_state);
+   struct intel_shared_dpll *pll;
 
-   if (IS_GEN9_BC(dev_priv))
-   return skl_ddi_pll_select(intel_crtc, crtc_state,
- encoder);
-   else if (IS_GEN9_LP(dev_priv))
-   return bxt_ddi_pll_select(intel_crtc, crtc_state,
- encoder);
-   else
-   return hsw_ddi_pll_select(intel_crtc, crtc_state,
- encoder);
+   pll = intel_get_shared_dpll(intel_crtc, crtc_state, encoder);
+   if (!pll)
+   DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
+ pipe_name(intel_crtc->pipe));
+
+   return pll != NULL;
 }
 
 void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
-- 
2.7.4

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 2/5] drm: Remove fb hsub/vsub alignment requirement

2017-03-22 Thread Ville Syrjälä
On Tue, Mar 21, 2017 at 01:26:23PM -0700, Ben Widawsky wrote:
> On 17-03-21 20:12:15, Ville Syrjälä wrote:
> >From: Ville Syrjälä 
> >
> >Allow framebuffers dimesions to be misaligned w.r.t. the subsampling
> >factors. No real reason the core should have to enforce this, and
> >it definitely starts to cause us issues with the i915 CCS support.
> >So let's just lift the restriction.
> >
> >Let's start to round up when computing the color plane dimesions
> >so that we'll not end up with too low an estimate for the memory
> >requirements and whatnot.
> >
> >Cc: Ben Widawsky 
> >Cc: Jason Ekstrand 
> >Signed-off-by: Ville Syrjälä 
> 
> Both 1 and 2 are:
> Reviewed-by: Ben Widawsky 

Thanks. I've pushed patches 1-3 to drm-misc-next. That just leaves
us with the i915 stuff to deal with.

> 
> >---
> > drivers/gpu/drm/drm_framebuffer.c | 8 
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> >diff --git a/drivers/gpu/drm/drm_framebuffer.c 
> >b/drivers/gpu/drm/drm_framebuffer.c
> >index 1138f90a7d5d..69e4c1487420 100644
> >--- a/drivers/gpu/drm/drm_framebuffer.c
> >+++ b/drivers/gpu/drm/drm_framebuffer.c
> >@@ -132,7 +132,7 @@ static int fb_plane_width(int width,
> > if (plane == 0)
> > return width;
> >
> >-return width / format->hsub;
> >+return DIV_ROUND_UP(width, format->hsub);
> > }
> >
> > static int fb_plane_height(int height,
> >@@ -141,7 +141,7 @@ static int fb_plane_height(int height,
> > if (plane == 0)
> > return height;
> >
> >-return height / format->vsub;
> >+return DIV_ROUND_UP(height, format->vsub);
> > }
> >
> > static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
> >@@ -158,12 +158,12 @@ static int framebuffer_check(const struct 
> >drm_mode_fb_cmd2 *r)
> > return -EINVAL;
> > }
> >
> >-if (r->width == 0 || r->width % info->hsub) {
> >+if (r->width == 0) {
> > DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width);
> > return -EINVAL;
> > }
> >
> >-if (r->height == 0 || r->height % info->vsub) {
> >+if (r->height == 0) {
> > DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height);
> > return -EINVAL;
> > }
> >-- 
> >2.10.2
> >

-- 
Ville Syrjälä
Intel OTC
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 05/16] drm: update todo.rst

2017-03-22 Thread Gabriel Krisman Bertazi
Daniel Vetter  writes:

> Just drive-by, but we have gsoc running so better to update it now.
>
> Great news is that two entries can be removed because essentially all
> done.
>
> Signed-off-by: Daniel Vetter 
> ---
>  Documentation/gpu/todo.rst | 51 
> --
>  1 file changed, 4 insertions(+), 47 deletions(-)
>
> diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
> index 9ecd2ebb8dd8..7dc6de07a3bc 100644
> --- a/Documentation/gpu/todo.rst
> +++ b/Documentation/gpu/todo.rst
> @@ -16,7 +16,7 @@ De-midlayer drivers
>  With the recent ``drm_bus`` cleanup patches for 3.17 it is no longer required
>  to have a ``drm_bus`` structure set up. Drivers can directly set up the
>  ``drm_device`` structure instead of relying on bus methods in ``drm_usb.c``
> -and ``drm_platform.c``. The goal is to get rid of the driver's ``->load`` /
> +and ``drm_pci.c``. The goal is to get rid of the driver's ``->load`` /
>  ``->unload`` callbacks and open-code the load/unload sequence properly, using
>  the new two-stage ``drm_device`` setup/teardown.
>  
> @@ -151,7 +151,7 @@ fine-grained per-buffer object and per-context
> lockings scheme. Currently the
>  following drivers still use ``struct_mutex``: ``msm``, ``omapdrm`` and
>  ``udl``.
>  
> -Contact: Daniel Vetter
> +Contact: Daniel Vetter, respective driver maintainers
>  
>  Switch to drm_connector_list_iter for any connector_list walking
>  
> @@ -193,6 +193,8 @@ plan is to switch to per-file driver API headers, which 
> will also structure
>  the kerneldoc better. This should also allow more fine-grained ``#include``
>  directives.
>  
> +In the end no .c file should need to include ``drmP.h`` anymore.
> +
>  Contact: Daniel Vetter
>  
>  Add missing kerneldoc for exported functions
> @@ -208,31 +210,6 @@ See https://dri.freedesktop.org/docs/drm/ for what's 
> there already.
>  
>  Contact: Daniel Vetter
>  
> -Hide legacy cruft better
> -
> -
> -Way back DRM supported only drivers which shadow-attached to PCI devices with
> -userspace or fbdev drivers setting up outputs. Modern DRM drivers take charge
> -of the entire device, you can spot them with the DRIVER_MODESET flag.
> -
> -Unfortunately there's still large piles of legacy code around which needs to
> -be hidden so that driver writers don't accidentally end up using it. And to
> -prevent security issues in those legacy IOCTLs from being exploited on modern
> -drivers. This has multiple possible subtasks:
> -
> -* Make sure legacy IOCTLs can't be used on modern drivers.
> -* Extract support code for legacy features into a ``drm-legacy.ko`` kernel
> -  module and compile it only when one of the legacy drivers is enabled.

I've been interested in taking up the work to split drm-legacy.ko from
drm.ko.  The plan is to make it an optional module that legacy drivers
depend on, in a way that you don't need to recompile drm.ko to use it.

I think the issue with the current CONFIG_DRM_VM, for instance, which
hid some of the code for legacy drivers is the downside of requiring
recompilation of drm.ko before using a legacy driver.

Anyway, if you agree with this change, can you keep this entry until
that is done?

-- 
Gabriel Krisman Bertazi
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 12/16] drm/vblank: Switch to bool in_vblank_irq in get_vblank_timestamp

2017-03-22 Thread Ville Syrjälä
On Wed, Mar 22, 2017 at 09:36:13AM +0100, Daniel Vetter wrote:
> It's overkill to have a flag parameter which is essentially used just
> as a boolean. This takes care of core + adjusting drivers.
> 
> Adjusting the scanout position callback is a bit harder, since radeon
> also supplies it's own driver-private flags in there.

This part worried me, but indeed radeon only passes the custom flag to
the scanout position hook. Patch lgtm

Reviewed-by: Ville Syrjälä 

> 
> Cc: Mario Kleiner 
> Cc: Eric Anholt 
> Cc: Rob Clark 
> Cc: linux-arm-...@vger.kernel.org
> Cc: freedr...@lists.freedesktop.org
> Cc: Alex Deucher 
> Cc: Christian König 
> Cc: Ben Skeggs 
> Signed-off-by: Daniel Vetter 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   |  6 ++---
>  drivers/gpu/drm/drm_irq.c | 41 
> +--
>  drivers/gpu/drm/i915/i915_irq.c   |  4 +--
>  drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c   |  4 +--
>  drivers/gpu/drm/nouveau/nouveau_display.c |  5 ++--
>  drivers/gpu/drm/nouveau/nouveau_display.h |  2 +-
>  drivers/gpu/drm/radeon/radeon_drv.c   |  2 +-
>  drivers/gpu/drm/radeon/radeon_kms.c   |  4 +--
>  drivers/gpu/drm/vc4/vc4_crtc.c|  4 +--
>  drivers/gpu/drm/vc4/vc4_drv.h |  2 +-
>  include/drm/drm_drv.h | 11 -
>  include/drm/drm_irq.h |  2 +-
>  13 files changed, 46 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index acd8631d8024..edb3bb83e1a9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1771,7 +1771,7 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, 
> unsigned int pipe);
>  bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int 
> pipe,
>int *max_error,
>struct timeval *vblank_time,
> -  unsigned flags);
> +  bool in_vblank_irq);
>  long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
>unsigned long arg);
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index ac42f707c046..ad295e822d45 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -834,7 +834,7 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, 
> unsigned int pipe)
>   * @crtc: crtc to get the timestamp for
>   * @max_error: max error
>   * @vblank_time: time value
> - * @flags: flags passed to the driver
> + * @in_vblank_irq: called from drm_handle_vblank()
>   *
>   * Gets the timestamp on the requested crtc based on the
>   * scanout position.  (all asics).
> @@ -843,7 +843,7 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, 
> unsigned int pipe)
>  bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int 
> pipe,
>int *max_error,
>struct timeval *vblank_time,
> -  unsigned flags)
> +  bool in_vblank_irq)
>  {
>   struct drm_crtc *crtc;
>   struct amdgpu_device *adev = dev->dev_private;
> @@ -864,7 +864,7 @@ bool amdgpu_get_vblank_timestamp_kms(struct drm_device 
> *dev, unsigned int pipe,
>  
>   /* Helper routine in DRM core does all the work: */
>   return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
> -  vblank_time, flags,
> +  vblank_time, in_vblank_irq,
>&crtc->hwmode);
>  }
>  
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 2121ea29e1b2..059c3346db68 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -54,7 +54,7 @@
>  
>  static bool
>  drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe,
> -   struct timeval *tvblank, unsigned flags);
> +   struct timeval *tvblank, bool in_vblank_irq);
>  
>  static unsigned int drm_timestamp_precision = 20;  /* Default to 20 usecs. */
>  
> @@ -138,7 +138,7 @@ static void drm_reset_vblank_timestamp(struct drm_device 
> *dev, unsigned int pipe
>*/
>   do {
>   cur_vblank = __get_vblank_counter(dev, pipe);
> - rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, 0);
> + rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, false);
>   } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0);
>  
>   /*
> @@ -171,7 +171,7 @@ static void drm_reset_vblank_timestamp(struct drm_device 
> *dev, unsigned int pipe
>   * device vblank fields.
>   */
>  static void drm_updat

Re: [Intel-gfx] [PATCH 07/16] drm: Extract drm_ioctl.h

2017-03-22 Thread Ville Syrjälä
On Wed, Mar 22, 2017 at 06:56:32PM +0100, Daniel Vetter wrote:
> On Wed, Mar 22, 2017 at 03:47:31PM +0200, Ville Syrjälä wrote:
> > On Wed, Mar 22, 2017 at 09:36:08AM +0100, Daniel Vetter wrote:
> > > To match the drm_ioctl.c we already have.
> > > 
> > > Signed-off-by: Daniel Vetter 
> > > ---
> > >  drivers/gpu/drm/drm_ioctl.c |   1 +
> > >  include/drm/drmP.h  |  61 +-
> > >  include/drm/drm_ioctl.h | 102 
> > > 
> > >  3 files changed, 104 insertions(+), 60 deletions(-)
> > >  create mode 100644 include/drm/drm_ioctl.h
> > > 
> > > diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> > > index 601bb0ded9d2..7f4f4f48e390 100644
> > > --- a/drivers/gpu/drm/drm_ioctl.c
> > > +++ b/drivers/gpu/drm/drm_ioctl.c
> > > @@ -28,6 +28,7 @@
> > >   * OTHER DEALINGS IN THE SOFTWARE.
> > >   */
> > >  
> > > +#include 
> > >  #include 
> > >  #include 
> > >  #include "drm_legacy.h"
> > > diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> > > index fc2a0744413d..248d2408e56b 100644
> > > --- a/include/drm/drmP.h
> > > +++ b/include/drm/drmP.h
> > > @@ -80,6 +80,7 @@
> > >  #include 
> > >  #include 
> > >  #include 
> > > +#include 
> > 
> > Same question as for the debugfs thing. Why do we need this?
> 
> Try fixing up the drmP.h include hell, and you know that it'd take a few
> hundred patches. And right now it's impossible, because the most central
> structure (struct drm_device) is in here, so defacto we still have a
> monolithic header which needs everything.
> 
> First we need to split it completely, then all places that include drmP.h
> need to switch to individual headers (each time fixing up a pile of
> fallout), and then eventually (after fixing the few hundred places or so)
> we can remove all these include lines here (or well, get rid of drmP.h
> entirely). But not before. I tried.

OK. I thought this stuff wouldn't have spread that far beyond the
ioctl implementations, but I guess not.

Hmm. Had I spent any thought on this I would have realized that at
least DRM_IOCTL_DEF_DRV() is used in pretty much every driver.

-- 
Ville Syrjälä
Intel OTC
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 07/16] drm: Extract drm_ioctl.h

2017-03-22 Thread Daniel Vetter
On Wed, Mar 22, 2017 at 03:47:31PM +0200, Ville Syrjälä wrote:
> On Wed, Mar 22, 2017 at 09:36:08AM +0100, Daniel Vetter wrote:
> > To match the drm_ioctl.c we already have.
> > 
> > Signed-off-by: Daniel Vetter 
> > ---
> >  drivers/gpu/drm/drm_ioctl.c |   1 +
> >  include/drm/drmP.h  |  61 +-
> >  include/drm/drm_ioctl.h | 102 
> > 
> >  3 files changed, 104 insertions(+), 60 deletions(-)
> >  create mode 100644 include/drm/drm_ioctl.h
> > 
> > diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> > index 601bb0ded9d2..7f4f4f48e390 100644
> > --- a/drivers/gpu/drm/drm_ioctl.c
> > +++ b/drivers/gpu/drm/drm_ioctl.c
> > @@ -28,6 +28,7 @@
> >   * OTHER DEALINGS IN THE SOFTWARE.
> >   */
> >  
> > +#include 
> >  #include 
> >  #include 
> >  #include "drm_legacy.h"
> > diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> > index fc2a0744413d..248d2408e56b 100644
> > --- a/include/drm/drmP.h
> > +++ b/include/drm/drmP.h
> > @@ -80,6 +80,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> 
> Same question as for the debugfs thing. Why do we need this?

Try fixing up the drmP.h include hell, and you know that it'd take a few
hundred patches. And right now it's impossible, because the most central
structure (struct drm_device) is in here, so defacto we still have a
monolithic header which needs everything.

First we need to split it completely, then all places that include drmP.h
need to switch to individual headers (each time fixing up a pile of
fallout), and then eventually (after fixing the few hundred places or so)
we can remove all these include lines here (or well, get rid of drmP.h
entirely). But not before. I tried.
-Daniel

> 
> >  
> >  struct module;
> >  
> > @@ -318,49 +319,6 @@ struct pci_controller;
> >  
> >  #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
> >  
> > -/**
> > - * Ioctl function type.
> > - *
> > - * \param inode device inode.
> > - * \param file_priv DRM file private pointer.
> > - * \param cmd command.
> > - * \param arg argument.
> > - */
> > -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
> > -   struct drm_file *file_priv);
> > -
> > -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
> > -  unsigned long arg);
> > -
> > -#define DRM_IOCTL_NR(n)_IOC_NR(n)
> > -#define DRM_MAJOR   226
> > -
> > -#define DRM_AUTH   0x1
> > -#defineDRM_MASTER  0x2
> > -#define DRM_ROOT_ONLY  0x4
> > -#define DRM_CONTROL_ALLOW 0x8
> > -#define DRM_UNLOCKED   0x10
> > -#define DRM_RENDER_ALLOW 0x20
> > -
> > -struct drm_ioctl_desc {
> > -   unsigned int cmd;
> > -   int flags;
> > -   drm_ioctl_t *func;
> > -   const char *name;
> > -};
> > -
> > -/**
> > - * Creates a driver or general drm_ioctl_desc array entry for the given
> > - * ioctl, for use by drm_ioctl().
> > - */
> > -
> > -#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)
> > \
> > -   [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {\
> > -   .cmd = DRM_IOCTL_##ioctl,   \
> > -   .func = _func,  \
> > -   .flags = _flags,\
> > -   .name = #ioctl  \
> > -}
> >  
> >  /* Flags and return codes for get_vblank_timestamp() driver function. */
> >  #define DRM_CALLED_FROM_VBLIRQ 1
> > @@ -550,23 +508,6 @@ static inline int drm_device_is_unplugged(struct 
> > drm_device *dev)
> >  /*@{*/
> >  
> > /* Driver support (drm_drv.h) */
> > -extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
> > -extern long drm_ioctl(struct file *filp,
> > - unsigned int cmd, unsigned long arg);
> > -#ifdef CONFIG_COMPAT
> > -extern long drm_compat_ioctl(struct file *filp,
> > -unsigned int cmd, unsigned long arg);
> > -#else
> > -/* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
> > -#define drm_compat_ioctl NULL
> > -#endif
> > -extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
> > -
> > -/* Misc. IOCTL support (drm_ioctl.c) */
> > -int drm_noop(struct drm_device *dev, void *data,
> > -struct drm_file *file_priv);
> > -int drm_invalid_op(struct drm_device *dev, void *data,
> > -  struct drm_file *file_priv);
> >  
> >  /*
> >   * These are exported to drivers so that they can implement fencing using
> > diff --git a/include/drm/drm_ioctl.h b/include/drm/drm_ioctl.h
> > new file mode 100644
> > index ..3c3677b5bdb2
> > --- /dev/null
> > +++ b/include/drm/drm_ioctl.h
> > @@ -0,0 +1,102 @@
> > +/*
> > + * Internal Header for the Direct Rendering Manager
> > + *
> > + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
> > + * Copyright 2000 VA Linux Systems, Inc.

Re: [Intel-gfx] [PATCH 11/16] drm/vblank: Switch drm_driver->get_vblank_timestamp to return a bool

2017-03-22 Thread Daniel Vetter
On Wed, Mar 22, 2017 at 04:05:59PM +0200, Jani Nikula wrote:
> On Wed, 22 Mar 2017, Daniel Vetter  wrote:
> > On Wed, Mar 22, 2017 at 12:33:35PM +0200, Jani Nikula wrote:
> >> On Wed, 22 Mar 2017, Daniel Vetter  wrote:
> >> > There's really no reason for anything more:
> >> > - Calling this while the crtc vblank stuff isn't set up is a driver
> >> >   bug. Those places arlready DRM_ERROR.
> >> > - Calling this when the crtc is off is either a driver bug (callin
> >> >   drm_crtc_handle_vblank at the wrong time) or a core bug (for
> >> >   anything else). Again, we DRM_ERROR.
> >> > - EINVAL is checked at higher levels already, and if we'd use struct
> >> >   drm_crtc * instead of (dev, pipe) it would be real obvious that
> >> >   those are again core bugs.
> >> >
> >> > The only valid failure mode is crap hardware that couldn't sample a
> >> > useful timestamp, to ask the core to just grab a not-so-accurate
> >> > timestampe. Bool is perfectly fine for that.
> >> 
> >> FWIW, I'm not all that thrilled about changing int returns to bools,
> >> because it changes the check for success from !ret to ret, and the
> >> compiler won't help you. Sure, there aren't many call sites for the
> >> function, but, case in point, you forgot to change that lone call
> >> site. Though it still works by coincidence.
> >
> > The old call site treated > 0 as success, and 0 or anything negative as
> > failure. That the lone caller still works is the reason why I've switched
> > to bool, because besides all the funny values that the caller gets and
> > ignreos, it already is.
> >
> > Or did I miss something?
> 
> Don't you think you should fix the call site too, if you insist on
> changing the return type?

Oops, I thought I've done that. Will fix up.
-Daniel

> 
> BR,
> Jani.
> 
> 
> 
> 
> > -Daniel
> >
> >> 
> >> BR,
> >> Jani.
> >> 
> >> >
> >> > Cc: Mario Kleiner 
> >> > Cc: Eric Anholt 
> >> > Cc: Rob Clark 
> >> > Cc: linux-arm-...@vger.kernel.org
> >> > Cc: freedr...@lists.freedesktop.org
> >> > Cc: Alex Deucher 
> >> > Cc: Christian König 
> >> > Cc: Ben Skeggs 
> >> > Signed-off-by: Daniel Vetter 
> >> > ---
> >> >  drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  8 +++
> >> >  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c   | 14 ++--
> >> >  drivers/gpu/drm/drm_irq.c | 37 
> >> > +++
> >> >  drivers/gpu/drm/i915/i915_irq.c   |  8 +++
> >> >  drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c   | 12 +-
> >> >  drivers/gpu/drm/nouveau/nouveau_display.c |  4 ++--
> >> >  drivers/gpu/drm/nouveau/nouveau_display.h |  4 ++--
> >> >  drivers/gpu/drm/radeon/radeon_drv.c   |  8 +++
> >> >  drivers/gpu/drm/radeon/radeon_kms.c   | 14 ++--
> >> >  drivers/gpu/drm/vc4/vc4_crtc.c|  2 +-
> >> >  drivers/gpu/drm/vc4/vc4_drv.h |  2 +-
> >> >  include/drm/drmP.h|  1 -
> >> >  include/drm/drm_drv.h |  7 +++---
> >> >  include/drm/drm_irq.h | 10 -
> >> >  14 files changed, 59 insertions(+), 72 deletions(-)
> >> >
> >> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> >> > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> >> > index c8860f05bfb9..acd8631d8024 100644
> >> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> >> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> >> > @@ -1768,10 +1768,10 @@ int amdgpu_device_resume(struct drm_device *dev, 
> >> > bool resume, 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);
> >> > -int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned 
> >> > int pipe,
> >> > -int *max_error,
> >> > -struct timeval *vblank_time,
> >> > -unsigned flags);
> >> > +bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned 
> >> > int pipe,
> >> > + int *max_error,
> >> > + struct timeval *vblank_time,
> >> > + unsigned flags);
> >> >  long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
> >> >   unsigned long arg);
> >> >  
> >> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
> >> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> >> > index 55f951bcc91f..ac42f707c046 100644
> >> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> >> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> >> > @@ -838,19 +838,19 @@ void amdgpu_disable_vblank_kms(struct drm_device 
> >> > *dev, unsigned int pipe)
> >> >   *
> >> >   * Gets the timestamp on the requested crtc based on the
> >> >   * scanout position.  (all asics).
> >> > - * Returns postive status flags on success, n

Re: [Intel-gfx] [PATCH] drm/i915: simplify intel_ddi_pll_select()

2017-03-22 Thread Ville Syrjälä
On Wed, Mar 22, 2017 at 02:40:01PM -0300, Paulo Zanoni wrote:
> Em Qua, 2017-03-22 às 15:21 +0200, Ville Syrjälä escreveu:
> > On Tue, Mar 21, 2017 at 06:57:10PM -0300, Paulo Zanoni wrote:
> > > 
> > > Because {hsw,skl,bxt}_ddi_pll_select all pretty much do the same
> > > thing
> > > in slightly different ways. Replace everything with a simple copy
> > > of
> > > the function and inline it inside intle_ddi_pll_select().
> > > 
> > > Signed-off-by: Paulo Zanoni 
> > > ---
> > >  drivers/gpu/drm/i915/intel_ddi.c | 58 +---
> > > 
> > >  1 file changed, 7 insertions(+), 51 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/i915/intel_ddi.c
> > > b/drivers/gpu/drm/i915/intel_ddi.c
> > > index d8214ba..bd6fd0b 100644
> > > --- a/drivers/gpu/drm/i915/intel_ddi.c
> > > +++ b/drivers/gpu/drm/i915/intel_ddi.c
> > > @@ -1127,47 +1127,6 @@ void intel_ddi_clock_get(struct
> > > intel_encoder *encoder,
> > >   bxt_ddi_clock_get(encoder, pipe_config);
> > >  }
> > >  
> > > -static bool
> > > -hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
> > > -    struct intel_crtc_state *crtc_state,
> > > -    struct intel_encoder *encoder)
> > > -{
> > > - struct intel_shared_dpll *pll;
> > > -
> > > - pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > > - encoder);
> > > - if (!pll)
> > > - DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > > %c\n",
> > > -  pipe_name(intel_crtc->pipe));
> > > -
> > > - return pll;
> > > -}
> > > -
> > > -static bool
> > > -skl_ddi_pll_select(struct intel_crtc *intel_crtc,
> > > -    struct intel_crtc_state *crtc_state,
> > > -    struct intel_encoder *encoder)
> > > -{
> > > - struct intel_shared_dpll *pll;
> > > -
> > > - pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > > encoder);
> > > - if (pll == NULL) {
> > > - DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > > %c\n",
> > > -  pipe_name(intel_crtc->pipe));
> > > - return false;
> > > - }
> > > -
> > > - return true;
> > > -}
> > > -
> > > -static bool
> > > -bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
> > > -    struct intel_crtc_state *crtc_state,
> > > -    struct intel_encoder *encoder)
> > > -{
> > > - return !!intel_get_shared_dpll(intel_crtc, crtc_state,
> > > encoder);
> > > -}
> > > -
> > >  /*
> > >   * Tries to find a *shared* PLL for the CRTC and store it in
> > >   * intel_crtc->ddi_pll_sel.
> > > @@ -1178,19 +1137,16 @@ bxt_ddi_pll_select(struct intel_crtc
> > > *intel_crtc,
> > >  bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
> > >     struct intel_crtc_state *crtc_state)
> > >  {
> > > - struct drm_i915_private *dev_priv = to_i915(intel_crtc-
> > > >base.dev);
> > >   struct intel_encoder *encoder =
> > >   intel_ddi_get_crtc_new_encoder(crtc_state);
> > > + struct intel_shared_dpll *pll;
> > >  
> > > - if (IS_GEN9_BC(dev_priv))
> > > - return skl_ddi_pll_select(intel_crtc, crtc_state,
> > > -   encoder);
> > > - else if (IS_GEN9_LP(dev_priv))
> > > - return bxt_ddi_pll_select(intel_crtc, crtc_state,
> > > -   encoder);
> > > - else
> > > - return hsw_ddi_pll_select(intel_crtc, crtc_state,
> > > -   encoder);
> > > + pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > > encoder);
> > 
> > I wonder if intel_ddi_pll_select() has any good reason to even exist
> > anymore. It's just calling this one function, so maybe we should just
> > call it directly?
> 
> You're right here. Then the two callers would be
> haswell_crtc_compute_clock() and ironlake_crtc_compute_clock(), which
> makes even more sene. I'll submit another patch.
> 
> > 
> > > 
> > > + if (!pll)
> > > + DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > > %c\n",
> > > +   pipe_name(intel_crtc->pipe));
> > > +
> > > + return pll;
> > 
> > I would probably write 'pll != NULL' for a bit of extra clarity.
> 
> Are you talking about the return statement or the if condition?

The return.

> 
> I'll assume you're talking about the return statement. I can fix this.
> Another thing would be "return !!pll". I'm fine with all approaches.

For whatever reason I've started to prefer !=NULL type of stuff.
Not really sure why since I used to dislike it when I was younger.

> 
> > 
> > Either way
> > Reviewed-by: Ville Syrjälä 
> 
> Thanks!
> 
> > 
> > > 
> > >  }
> > >  
> > >  void intel_ddi_set_pipe_settings(const struct intel_crtc_state
> > > *crtc_state)
> > > -- 
> > > 2.7.4
> > > 
> > > ___
> > > Intel-gfx mailing list
> > > Intel-gfx@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
> > 

-- 
Ville Syrjälä
Intel OTC
___
Intel-gfx mailing list
Intel-gfx@

Re: [Intel-gfx] [PATCH] drm/i915: simplify intel_ddi_pll_select()

2017-03-22 Thread Paulo Zanoni
Em Qua, 2017-03-22 às 15:21 +0200, Ville Syrjälä escreveu:
> On Tue, Mar 21, 2017 at 06:57:10PM -0300, Paulo Zanoni wrote:
> > 
> > Because {hsw,skl,bxt}_ddi_pll_select all pretty much do the same
> > thing
> > in slightly different ways. Replace everything with a simple copy
> > of
> > the function and inline it inside intle_ddi_pll_select().
> > 
> > Signed-off-by: Paulo Zanoni 
> > ---
> >  drivers/gpu/drm/i915/intel_ddi.c | 58 +---
> > 
> >  1 file changed, 7 insertions(+), 51 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/intel_ddi.c
> > b/drivers/gpu/drm/i915/intel_ddi.c
> > index d8214ba..bd6fd0b 100644
> > --- a/drivers/gpu/drm/i915/intel_ddi.c
> > +++ b/drivers/gpu/drm/i915/intel_ddi.c
> > @@ -1127,47 +1127,6 @@ void intel_ddi_clock_get(struct
> > intel_encoder *encoder,
> >     bxt_ddi_clock_get(encoder, pipe_config);
> >  }
> >  
> > -static bool
> > -hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
> > -      struct intel_crtc_state *crtc_state,
> > -      struct intel_encoder *encoder)
> > -{
> > -   struct intel_shared_dpll *pll;
> > -
> > -   pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > -   encoder);
> > -   if (!pll)
> > -   DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > %c\n",
> > -    pipe_name(intel_crtc->pipe));
> > -
> > -   return pll;
> > -}
> > -
> > -static bool
> > -skl_ddi_pll_select(struct intel_crtc *intel_crtc,
> > -      struct intel_crtc_state *crtc_state,
> > -      struct intel_encoder *encoder)
> > -{
> > -   struct intel_shared_dpll *pll;
> > -
> > -   pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > encoder);
> > -   if (pll == NULL) {
> > -   DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > %c\n",
> > -    pipe_name(intel_crtc->pipe));
> > -   return false;
> > -   }
> > -
> > -   return true;
> > -}
> > -
> > -static bool
> > -bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
> > -      struct intel_crtc_state *crtc_state,
> > -      struct intel_encoder *encoder)
> > -{
> > -   return !!intel_get_shared_dpll(intel_crtc, crtc_state,
> > encoder);
> > -}
> > -
> >  /*
> >   * Tries to find a *shared* PLL for the CRTC and store it in
> >   * intel_crtc->ddi_pll_sel.
> > @@ -1178,19 +1137,16 @@ bxt_ddi_pll_select(struct intel_crtc
> > *intel_crtc,
> >  bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
> >       struct intel_crtc_state *crtc_state)
> >  {
> > -   struct drm_i915_private *dev_priv = to_i915(intel_crtc-
> > >base.dev);
> >     struct intel_encoder *encoder =
> >     intel_ddi_get_crtc_new_encoder(crtc_state);
> > +   struct intel_shared_dpll *pll;
> >  
> > -   if (IS_GEN9_BC(dev_priv))
> > -   return skl_ddi_pll_select(intel_crtc, crtc_state,
> > -     encoder);
> > -   else if (IS_GEN9_LP(dev_priv))
> > -   return bxt_ddi_pll_select(intel_crtc, crtc_state,
> > -     encoder);
> > -   else
> > -   return hsw_ddi_pll_select(intel_crtc, crtc_state,
> > -     encoder);
> > +   pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > encoder);
> 
> I wonder if intel_ddi_pll_select() has any good reason to even exist
> anymore. It's just calling this one function, so maybe we should just
> call it directly?

You're right here. Then the two callers would be
haswell_crtc_compute_clock() and ironlake_crtc_compute_clock(), which
makes even more sene. I'll submit another patch.

> 
> > 
> > +   if (!pll)
> > +   DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > %c\n",
> > +     pipe_name(intel_crtc->pipe));
> > +
> > +   return pll;
> 
> I would probably write 'pll != NULL' for a bit of extra clarity.

Are you talking about the return statement or the if condition?

I'll assume you're talking about the return statement. I can fix this.
Another thing would be "return !!pll". I'm fine with all approaches.

> 
> Either way
> Reviewed-by: Ville Syrjälä 

Thanks!

> 
> > 
> >  }
> >  
> >  void intel_ddi_set_pipe_settings(const struct intel_crtc_state
> > *crtc_state)
> > -- 
> > 2.7.4
> > 
> > ___
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915: simplify intel_ddi_pll_select()

2017-03-22 Thread Paulo Zanoni
Em Ter, 2017-03-21 às 23:05 +, Pandiyan, Dhinakaran escreveu:
> On Tue, 2017-03-21 at 18:57 -0300, Paulo Zanoni wrote:
> > 
> > Because {hsw,skl,bxt}_ddi_pll_select all pretty much do the same
> > thing
> > in slightly different ways. Replace everything with a simple copy
> > of
> > the function and inline it inside intle_ddi_pll_select().
> > 
> > Signed-off-by: Paulo Zanoni 
> > ---
> >  drivers/gpu/drm/i915/intel_ddi.c | 58 +---
> > 
> >  1 file changed, 7 insertions(+), 51 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/intel_ddi.c
> > b/drivers/gpu/drm/i915/intel_ddi.c
> > index d8214ba..bd6fd0b 100644
> > --- a/drivers/gpu/drm/i915/intel_ddi.c
> > +++ b/drivers/gpu/drm/i915/intel_ddi.c
> > @@ -1127,47 +1127,6 @@ void intel_ddi_clock_get(struct
> > intel_encoder *encoder,
> >     bxt_ddi_clock_get(encoder, pipe_config);
> >  }
> >  
> > -static bool
> > -hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
> > -      struct intel_crtc_state *crtc_state,
> > -      struct intel_encoder *encoder)
> > -{
> > -   struct intel_shared_dpll *pll;
> > -
> > -   pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > -   encoder);
> 
> I have a related question, not a patch review :) Looks like we care
> only
> about the boolean returned from intel_get_shared_dpll(). Could not
> find
> any caller that uses the returned 'struct intel_shared_dpll *'.
> Should
> it's signature be simply changed to return a bool? 

There are only two callers. It would be possible to change the
signature, although I don't see many benefits from doing it now.

Perhaps it would be better to unify the error handling.

> 
> -DK
> > 
> > -   if (!pll)
> > -   DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > %c\n",
> > -    pipe_name(intel_crtc->pipe));
> > -
> > -   return pll;
> > -}
> > -
> > -static bool
> > -skl_ddi_pll_select(struct intel_crtc *intel_crtc,
> > -      struct intel_crtc_state *crtc_state,
> > -      struct intel_encoder *encoder)
> > -{
> > -   struct intel_shared_dpll *pll;
> > -
> > -   pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > encoder);
> > -   if (pll == NULL) {
> > -   DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > %c\n",
> > -    pipe_name(intel_crtc->pipe));
> > -   return false;
> > -   }
> > -
> > -   return true;
> > -}
> > -
> > -static bool
> > -bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
> > -      struct intel_crtc_state *crtc_state,
> > -      struct intel_encoder *encoder)
> > -{
> > -   return !!intel_get_shared_dpll(intel_crtc, crtc_state,
> > encoder);
> > -}
> > -
> >  /*
> >   * Tries to find a *shared* PLL for the CRTC and store it in
> >   * intel_crtc->ddi_pll_sel.
> > @@ -1178,19 +1137,16 @@ bxt_ddi_pll_select(struct intel_crtc
> > *intel_crtc,
> >  bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
> >       struct intel_crtc_state *crtc_state)
> >  {
> > -   struct drm_i915_private *dev_priv = to_i915(intel_crtc-
> > >base.dev);
> >     struct intel_encoder *encoder =
> >     intel_ddi_get_crtc_new_encoder(crtc_state);
> > +   struct intel_shared_dpll *pll;
> >  
> > -   if (IS_GEN9_BC(dev_priv))
> > -   return skl_ddi_pll_select(intel_crtc, crtc_state,
> > -     encoder);
> > -   else if (IS_GEN9_LP(dev_priv))
> > -   return bxt_ddi_pll_select(intel_crtc, crtc_state,
> > -     encoder);
> > -   else
> > -   return hsw_ddi_pll_select(intel_crtc, crtc_state,
> > -     encoder);
> > +   pll = intel_get_shared_dpll(intel_crtc, crtc_state,
> > encoder);
> > +   if (!pll)
> > +   DRM_DEBUG_DRIVER("failed to find PLL for pipe
> > %c\n",
> > +     pipe_name(intel_crtc->pipe));
> > +
> > +   return pll;
> >  }
> >  
> >  void intel_ddi_set_pipe_settings(const struct intel_crtc_state
> > *crtc_state)
> 
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 02/12] drm/i915/guc: Keep the ctx_pool_vaddr mapped, for easy access

2017-03-22 Thread Chris Wilson
On Wed, Mar 22, 2017 at 02:42:27AM -0700, Oscar Mateo wrote:
> 
> 
> On 03/22/2017 02:45 AM, Chris Wilson wrote:
> >On Tue, Mar 21, 2017 at 02:02:47AM -0700, Oscar Mateo wrote:
> >>The GuC descriptor is big in size. If we use a local definition of
> >>guc_desc we have a chance to overflow stack, so avoid it.
> >>
> >>Also, Chris abhors scatterlists :)
> >>
> >>v2: Rebased, helper function to retrieve the context descriptor,
> >>s/ctx_pool_vma/ctx_pool/
> >>
> >>v3: Zero out guc_context_desc before initialization
> >>
> >>v4: Do not do arithmetic on void pointers
> >>
> >>Cc: Daniele Ceraolo Spurio 
> >>Reviewed-by: Chris Wilson 
> >>Reviewed-by: Joonas Lahtinen 
> >>Signed-off-by: Oscar Mateo 
> >>---
> >>  drivers/gpu/drm/i915/i915_guc_submission.c | 93 
> >> +++---
> >>  drivers/gpu/drm/i915/intel_guc_loader.c|  2 +-
> >>  drivers/gpu/drm/i915/intel_uc.h|  3 +-
> >>  3 files changed, 48 insertions(+), 50 deletions(-)
> >>
> >>diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
> >>b/drivers/gpu/drm/i915/i915_guc_submission.c
> >>index 21dadc1..5870cec 100644
> >>--- a/drivers/gpu/drm/i915/i915_guc_submission.c
> >>+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
> >>@@ -133,6 +133,12 @@ static int __guc_deallocate_doorbell(struct intel_guc 
> >>*guc, u32 ctx_index)
> >>return intel_guc_send(guc, action, ARRAY_SIZE(action));
> >>  }
> >>+static struct guc_context_desc *__get_context_desc(struct i915_guc_client 
> >>*client)
> >>+{
> >>+   return (struct guc_context_desc *)((char *)client->guc->ctx_pool_vaddr +
> >We can use gccisms like using void * for arithmetic computations in the
> >kernel, i.e.
> > void *base = client->guc->ctx_pool_vaddr;
> > return base + sizeof(struct guc_context_desc) * client->ctx_index;
> >is just fine.
> >-Chris
> 
> :_(
> I got convinced by a previous review comment that arithmetic with
> void pointers was frowned upon.
> Ok, thanks!

Joonas mentioned trying:

struct guc_context_desc *base = client->guc->ctx_pool_vaddr;
return base + client->ctx_index;

or
return &base[client->ctx_index];

for even more idiomatic C.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 01/12] drm/i915/guc: Sanitize GuC client initialization

2017-03-22 Thread Oscar Mateo



On 03/22/2017 02:28 AM, Joonas Lahtinen wrote:

It's a good practice to use "git am" to apply the original patch and
then "git commit --amend" to it, so that the "From: " field stays
intact. Or use git commit --amend --author="John Doe " but
that is more prone to typos.

On ti, 2017-03-21 at 02:02 -0700, Oscar Mateo wrote:

Started adding proper teardown to guc_client_alloc, ended up removing
quite a few dead ends where errors communicating with the GuC were
silently ignored. There also seemed to be quite a few erronous
teardown actions performed in case of an error (ordering wrong).

v2:
   - Increase function symmetry/proximity (Michal/Daniele)
   - Fix __reserve_doorbell accounting for high priority (Daniele)
   - Call __update_doorbell_desc! (Daniele)
   - Isolate __guc_{,de}allocate_doorbell (Michal/Daniele)

v3:
   - "Select" a cacheline is a more accurate verb than "reserve" (Daniele).
   - We cannot update & create the doorbell without reserving it first, so
 move the whole doorbell creation for execbuf_client to the submission
 enable (Oscar).i
   - Add a fixme for ignoring possible doorbell destroy errors.

v4:
   - Remove comment about is_high_priority (Daniele)
   - Debug message typo (Daniele)
   - Reuse __get_doorbell in more places (Daniele)
   - Do not do arithmetic on void pointers (Daniele)
   - Add comment to __reset_doorbell (Daniele)

Signed-off-by: Joonas Lahtinen 
Cc: Michal Wajdeczko 
Cc: Arkadiusz Hiler 
Cc: Tvrtko Ursulin 
Cc: Chris Wilson 
Reviewed-by: Daniele Ceraolo Spurio 
Signed-off-by: Oscar Mateo 

The R-b should probably be after S-o-b if it was to last version.

Regards, Joonas
My bad. I have spent too much time without using Git I'm like wicked 
rusty (you have probably noticed other weird things I've done, like 
sending the last series without the word "PATCH" or sending this one 
without proper versions in the subject). I'll fix those things and resubmit.

Thanks,
Oscar
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 02/12] drm/i915/guc: Keep the ctx_pool_vaddr mapped, for easy access

2017-03-22 Thread Oscar Mateo



On 03/22/2017 02:45 AM, Chris Wilson wrote:

On Tue, Mar 21, 2017 at 02:02:47AM -0700, Oscar Mateo wrote:

The GuC descriptor is big in size. If we use a local definition of
guc_desc we have a chance to overflow stack, so avoid it.

Also, Chris abhors scatterlists :)

v2: Rebased, helper function to retrieve the context descriptor,
s/ctx_pool_vma/ctx_pool/

v3: Zero out guc_context_desc before initialization

v4: Do not do arithmetic on void pointers

Cc: Daniele Ceraolo Spurio 
Reviewed-by: Chris Wilson 
Reviewed-by: Joonas Lahtinen 
Signed-off-by: Oscar Mateo 
---
  drivers/gpu/drm/i915/i915_guc_submission.c | 93 +++---
  drivers/gpu/drm/i915/intel_guc_loader.c|  2 +-
  drivers/gpu/drm/i915/intel_uc.h|  3 +-
  3 files changed, 48 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c 
b/drivers/gpu/drm/i915/i915_guc_submission.c
index 21dadc1..5870cec 100644
--- a/drivers/gpu/drm/i915/i915_guc_submission.c
+++ b/drivers/gpu/drm/i915/i915_guc_submission.c
@@ -133,6 +133,12 @@ static int __guc_deallocate_doorbell(struct intel_guc 
*guc, u32 ctx_index)
return intel_guc_send(guc, action, ARRAY_SIZE(action));
  }
  
+static struct guc_context_desc *__get_context_desc(struct i915_guc_client *client)

+{
+   return (struct guc_context_desc *)((char *)client->guc->ctx_pool_vaddr +

We can use gccisms like using void * for arithmetic computations in the
kernel, i.e.
void *base = client->guc->ctx_pool_vaddr;
return base + sizeof(struct guc_context_desc) * client->ctx_index;
is just fine.
-Chris


:_(
I got convinced by a previous review comment that arithmetic with void 
pointers was frowned upon.

Ok, thanks!
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v10] drm/i915: Implement Link Rate fallback on Link training failure

2017-03-22 Thread Manasi Navare
Hi Jani/Ville,

I need to add another quick fix which would be required for the fallback
to happen as expected. Should I respin this patch to add that fix or
should I wait for this to get landed?

I have mentioned the fix suggested below, please let me know your thoughts on 
that.


On Tue, Mar 14, 2017 at 03:11:51PM -0700, Manasi Navare wrote:
> If link training at a link rate optimal for a particular
> mode fails during modeset's atomic commit phase, then we
> let the modeset complete and then retry. We save the link rate
> value at which link training failed, update the link status property
> to "BAD" and use a lower link rate to prune the modes. It will redo
> the modeset on the current mode at lower link rate or if the current
> mode gets pruned due to lower link constraints then, it will send a
> hotplug uevent for userspace to handle it.
> 
> This is also required to pass DP CTS tests 4.3.1.3, 4.3.1.4,
> 4.3.1.6.
> 
> This patch is a resend of the original commit id (233ce881dd91fb
> "drm/i915: Implement Link Rate fallback on Link training failure")
> which got reverted in this commit id (afc1ebf4562a14 Revert
> "drm/i915: Implement Link Rate fallback on Link training failure")
> due to CI failures.
> 
> After investigating the CI failures it was found that these
> were essentially the failures which were always there but hidden because
> they used to be DRM_DEBUG_KMS messages for link failures so never got
> caught by CI. But now this patch actually throws DRM_ERROR if the link
> training fails at RBR and 1 lane. So it caught these link train failures.
> 
> There were two failures:
> 1. On SKL 6700k this was because the machine in CI lab is a SKL desktop
> without eDP on Port A. But our VBT initialization code in the driver writes
> VBT defaults in a way that it always sets DP flag on Port A and this does
> not get cleared after parsing the VBT outputs. This has been fixed in
> commit id (bb1d132935c2f8 "drm/i915/vbt: split out defaults that are set
> when there is no VBT) and (665788572c6410b "drm/i915/vbt: don't propagate
> errors from intel_bios_init())
> 
> 2. On ILK-650 desktop - This was happening because of a bad monitor desktop
> combination. I switched the monitor in the CI lab and that helped get rid
> of the link failures on ILK system.
> 
> v10:
> * Rebase on drm-tip and resend after revert
> v9:
> * Use the trimmed max values of link rate/lane count based on
> link train fallback (Daniel Vetter)
> v8:
> * Set link_status to BAD first and then call mode_valid (Jani Nikula)
> v7:
> Remove the redundant variable in previous patch itself
> v6:
> * Obtain link rate index from fallback_link_rate using
> the helper intel_dp_link_rate_index (Jani Nikula)
> * Include fallback within intel_dp_start_link_train (Jani Nikula)
> v5:
> * Move set link status to drm core (Daniel Vetter, Jani Nikula)
> v4:
> * Add fallback support for non DDI platforms too
> * Set connector->link status inside set_link_status function
> (Jani Nikula)
> v3:
> * Set link status property to BAd unconditionally (Jani Nikula)
> * Dont use two separate variables link_train_failed and link_status
> to indicate same thing (Jani Nikula)
> v2:
> * Squashed a few patches (Jani Nikula)
> 
> Acked-by: Tony Cheng 
> Acked-by: Harry Wentland 
> Cc: Jani Nikula 
> Cc: Daniel Vetter 
> Cc: Ville Syrjala 
> Signed-off-by: Manasi Navare 
> Reviewed-by: Jani Nikula 
> Signed-off-by: Jani Nikula 
> ---
>  drivers/gpu/drm/i915/intel_dp.c   | 27 
> +++
>  drivers/gpu/drm/i915/intel_dp_link_training.c | 22 --
>  drivers/gpu/drm/i915/intel_drv.h  |  3 +++
>  3 files changed, 50 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index fd96a6c..895f934 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -5924,6 +5924,29 @@ intel_dp_init_connector_port_info(struct 
> intel_digital_port *intel_dig_port)
>   }
>  }
>  
> +static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
> +{
> + struct intel_connector *intel_connector;
> + struct drm_connector *connector;
> +
> + intel_connector = container_of(work, typeof(*intel_connector),
> +modeset_retry_work);
> + connector = &intel_connector->base;
> + DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
> +   connector->name);
> +
> + /* Grab the locks before changing connector property*/
> + mutex_lock(&connector->dev->mode_config.mutex);
> + /* Set connector link status to BAD and send a Uevent to notify
> +  * userspace to do a modeset.
> +  */
> + drm_mode_connector_set_link_status_property(connector,
> + DRM_MODE_LINK_STATUS_BAD);
> + mutex_unlock(&connector->dev->mode_config.mutex);
> + /* Send Hotplug uevent so userspace can reprobe */
> + drm_kms_hel

Re: [Intel-gfx] [PATCH v7 05/21] drm/i915/slpc: Sanitize GuC version

2017-03-22 Thread Joonas Lahtinen
On ke, 2017-03-22 at 16:18 +0100, Michal Wajdeczko wrote:
> On Wed, Mar 22, 2017 at 03:33:38PM +0530, Sagar Arun Kamble wrote:
> > @@ -130,6 +130,8 @@ struct intel_uc_fw {
> >     uint32_t ucode_offset;
> >  };
> >  
> > +#define FIRMWARE_URL  "https://01.org/linuxgraphics/intel-linux-gr
> > aphics-firmwares"
> 
> Is it ok that we use such generic macro name without any intel/i915
> prefix?

Definitely not, this is result of moving from .c to .h. Need to add
I915_ prefix.

Regards, Joonas
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v7 05/21] drm/i915/slpc: Sanitize GuC version

2017-03-22 Thread Michal Wajdeczko
On Wed, Mar 22, 2017 at 03:33:38PM +0530, Sagar Arun Kamble wrote:
> From: Tom O'Rourke 
> 
> The SLPC interface is dependent on GuC version.
> Only GuC versions known to be compatible are supported here.
> 
> SLPC with GuC firmware v9 is supported with this series.
> 
> v1: Updated with modified sanitize_slpc_option in earlier patch.
> 
> v2-v3: Rebase.
> 
> v4: Updated support for GuC firmware v9.
> 
> v5: Commit subject updated.
> 
> v6: Commit subject and message update. Add support condition as >=v9.
> 
> v7: Sanitizing GuC version in intel_uc_init_fw for SLPC compatibility.
> Added info. print for needed version and pointer to 01.org.
> 
> Signed-off-by: Tom O'Rourke 
> Signed-off-by: Sagar Arun Kamble 
> ---
>  drivers/gpu/drm/i915/intel_csr.c |  5 -
>  drivers/gpu/drm/i915/intel_uc.c  | 14 --
>  drivers/gpu/drm/i915/intel_uc.h  |  2 ++
>  3 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_csr.c 
> b/drivers/gpu/drm/i915/intel_csr.c
> index 3683225..b784b7b 100644
> --- a/drivers/gpu/drm/i915/intel_csr.c
> +++ b/drivers/gpu/drm/i915/intel_csr.c
> @@ -49,11 +49,6 @@
>  MODULE_FIRMWARE(I915_CSR_BXT);
>  #define BXT_CSR_VERSION_REQUIRED CSR_VERSION(1, 7)
>  
> -#define FIRMWARE_URL  
> "https://01.org/linuxgraphics/intel-linux-graphics-firmwares";
> -
> -
> -
> -
>  #define CSR_MAX_FW_SIZE  0x2FFF
>  #define CSR_DEFAULT_FW_OFFSET0x
>  
> diff --git a/drivers/gpu/drm/i915/intel_uc.c b/drivers/gpu/drm/i915/intel_uc.c
> index c0a1d14..8502ead 100644
> --- a/drivers/gpu/drm/i915/intel_uc.c
> +++ b/drivers/gpu/drm/i915/intel_uc.c
> @@ -101,11 +101,21 @@ void intel_uc_init_early(struct drm_i915_private 
> *dev_priv)
>  
>  void intel_uc_init_fw(struct drm_i915_private *dev_priv)
>  {
> + struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
> +
>   if (dev_priv->huc.fw.path)
>   intel_uc_prepare_fw(dev_priv, &dev_priv->huc.fw);
>  
> - if (dev_priv->guc.fw.path)
> - intel_uc_prepare_fw(dev_priv, &dev_priv->guc.fw);
> + if (guc_fw->path) {
> + intel_uc_prepare_fw(dev_priv, guc_fw);
> +
> + if (guc_fw->major_ver_found < 9) {

In intel_uc_prepare_fw() there is explicit check that 'found' major version
match the 'wanted' major version, thus I think you can do this slpc check
in intel_uc_sanitize_options() right after sucessful call to 
intel_guc_select_fw()


> + DRM_INFO("SLPC not supported with GuC firmware v%u,"
> +  " please use v9+ [" FIRMWARE_URL "].\n",

Hmm, as "9" is used here for the second time, maybe there shall be a definition

#define I915_SLPC_REQUIRED_GUC_MAJOR 9

Also, if FIRMWARE_URL is used more than once in the driver, maybe to save some 
driver
footprint it would be better to use %s ?

> +  guc_fw->major_ver_found);
> + i915.enable_slpc = 0;
> + }
> + }
>  }
>  
>  int intel_uc_init_hw(struct drm_i915_private *dev_priv)
> diff --git a/drivers/gpu/drm/i915/intel_uc.h b/drivers/gpu/drm/i915/intel_uc.h
> index a35eded..928c214 100644
> --- a/drivers/gpu/drm/i915/intel_uc.h
> +++ b/drivers/gpu/drm/i915/intel_uc.h
> @@ -130,6 +130,8 @@ struct intel_uc_fw {
>   uint32_t ucode_offset;
>  };
>  
> +#define FIRMWARE_URL  
> "https://01.org/linuxgraphics/intel-linux-graphics-firmwares";

Is it ok that we use such generic macro name without any intel/i915 prefix?

Regards,
-Michal


___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 1/3] drm: Defer disabling the vblank IRQ until the next interrupt (for instant-off)

2017-03-22 Thread Mario Kleiner

On 03/15/2017 10:00 PM, Ville Syrjälä wrote:

On Wed, Mar 15, 2017 at 08:40:25PM +, Chris Wilson wrote:

On vblank instant-off systems, we can get into a situation where the cost
of enabling and disabling the vblank IRQ around a drmWaitVblank query
dominates. And with the advent of even deeper hardware sleep state,
touching registers becomes ever more expensive.  However, we know that if
the user wants the current vblank counter, they are also very likely to
immediately queue a vblank wait and so we can keep the interrupt around
and only turn it off if we have no further vblank requests queued within
the interrupt interval.

After vblank event delivery, this patch adds a shadow of one vblank where
the interrupt is kept alive for the user to query and queue another vblank
event. Similarly, if the user is using blocking drmWaitVblanks, the
interrupt will be disabled on the IRQ following the wait completion.
However, if the user is simply querying the current vblank counter and
timestamp, the interrupt will be disabled after every IRQ and the user
will enabled it again on the first query following the IRQ.

v2: Mario Kleiner -
After testing this, one more thing that would make sense is to move
the disable block at the end of drm_handle_vblank() instead of at the
top.

Turns out that if high precision timestaming is disabled or doesn't
work for some reason (as can be simulated by echo 0 >
/sys/module/drm/parameters/timestamp_precision_usec), then with your
delayed disable code at its current place, the vblank counter won't
increment anymore at all for instant queries, ie. with your other
"instant query" patches. Clients which repeatedly query the counter
and wait for it to progress will simply hang, spinning in an endless
query loop. There's that comment in vblank_disable_and_save:

"* Skip this step if there isn't any high precision timestamp
 * available. In that case we can't account for this and just
 * hope for the best.
 */

With the disable happening after leading edge of vblank (== hw counter
increment already happened) but before the vblank counter/timestamp
handling in drm_handle_vblank, that step is needed to keep the counter
progressing, so skipping it is bad.

Now without high precision timestamping support, a kms driver must not
set dev->vblank_disable_immediate = true, as this would cause problems
for clients, so this shouldn't matter, but it would be good to still
make this robust against a future kms driver which might have
unreliable high precision timestamping, e.g., high precision
timestamping that intermittently doesn't work.

v3: Patch before coffee needs extra coffee.

Testcase: igt/kms_vblank
Signed-off-by: Chris Wilson 
Cc: Ville Syrjälä 
Cc: Daniel Vetter 
Cc: Michel Dänzer 
Cc: Laurent Pinchart 
Cc: Dave Airlie ,
Cc: Mario Kleiner 


Yep. This seems like a good idea to me. I just neglected to review it
last time around (and maybe even before that?) for some reason. Locks
seem to be taken in the right order, so it at least looks safe to me.

Reviewed-by: Ville Syrjälä 



Hi,

as a followup to this one, maybe we should move the 
drm_handle_vblank_events(dev, pipe); down, immediately after Chris new 
delayed disable code?


The idea was to avoid lots of redundant enable->disable->enable... calls 
by having some 1 frame delay before disable. This works for pure vblank 
count/ts queries.


But both DRI2 and DRI3/Present use vblank events to trigger a 
pageflip-ioctl at the right target vblank. With the current ordering we 
may dispatch the vblank swap trigger event to the X-Server and drop the 
vblank refcount to zero due to the vblank_put inside 
drm_handle_vblank_events for the dispatched event, then detect in this 
patch that refcount == 0 and disable vblanks, but a few microseconds 
later the server will queue a pageflip ioctl which bumps the refcount 
and reenables vblank irqs, so we have a redundant disable->enable.


Also many kms drivers now use drm_crtc_arm_vblank_event() for pageflip 
completion handling at vblank, the pageflip completion events are also 
dispatched via drm_handle_vblank_events(). After a pageflip completes, 
it makes sense to have this "swap shadow" of 1 full frame, as animations 
would likely queue a new vblank query/event immediately for the next 
animation frame.


-mario


---
 drivers/gpu/drm/drm_irq.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 9bdca69f754c..e64b05ea95ea 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -1198,9 +1198,9 @@ static void drm_vblank_put(struct drm_device *dev, 
unsigned int pipe)
if (atomic_dec_and_test(&vblank->refcount)) {
if (drm_vblank_offdelay == 0)
return;
-   else if (dev->vblank_disable_immediate || drm_vblank_offdelay < 
0)
+   else if (drm_vblank_offdelay < 0)
vblank_disable_fn((unsigned long)vb

[Intel-gfx] ✗ Fi.CI.BAT: warning for series starting with [v2,1/5] drm/i915: Eliminate per-fw_domain i915 backpointer

2017-03-22 Thread Patchwork
== Series Details ==

Series: series starting with [v2,1/5] drm/i915: Eliminate per-fw_domain i915 
backpointer
URL   : https://patchwork.freedesktop.org/series/21686/
State : warning

== Summary ==

Series 21686v1 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/21686/revisions/1/mbox/

Test gem_exec_flush:
Subgroup basic-batch-kernel-default-uc:
fail   -> PASS   (fi-snb-2600) fdo#17
Test kms_force_connector_basic:
Subgroup force-connector-state:
pass   -> SKIP   (fi-ivb-3520m)
Subgroup force-edid:
pass   -> SKIP   (fi-ivb-3520m)
Subgroup force-load-detect:
pass   -> SKIP   (fi-ivb-3520m)
Subgroup prune-stale-modes:
pass   -> SKIP   (fi-ivb-3520m)

fdo#17 https://bugs.freedesktop.org/show_bug.cgi?id=17

fi-bdw-5557u total:278  pass:267  dwarn:0   dfail:0   fail:0   skip:11  
time: 458s
fi-bdw-gvtdvmtotal:278  pass:256  dwarn:8   dfail:0   fail:0   skip:14  
time: 466s
fi-bsw-n3050 total:278  pass:239  dwarn:0   dfail:0   fail:0   skip:39  
time: 576s
fi-bxt-j4205 total:278  pass:259  dwarn:0   dfail:0   fail:0   skip:19  
time: 545s
fi-byt-j1900 total:278  pass:251  dwarn:0   dfail:0   fail:0   skip:27  
time: 508s
fi-byt-n2820 total:278  pass:247  dwarn:0   dfail:0   fail:0   skip:31  
time: 504s
fi-hsw-4770  total:278  pass:262  dwarn:0   dfail:0   fail:0   skip:16  
time: 442s
fi-hsw-4770r total:278  pass:262  dwarn:0   dfail:0   fail:0   skip:16  
time: 437s
fi-ilk-650   total:278  pass:228  dwarn:0   dfail:0   fail:0   skip:50  
time: 440s
fi-ivb-3520m total:278  pass:256  dwarn:0   dfail:0   fail:0   skip:22  
time: 517s
fi-ivb-3770  total:278  pass:260  dwarn:0   dfail:0   fail:0   skip:18  
time: 497s
fi-kbl-7500u total:278  pass:260  dwarn:0   dfail:0   fail:0   skip:18  
time: 478s
fi-skl-6260u total:278  pass:268  dwarn:0   dfail:0   fail:0   skip:10  
time: 489s
fi-skl-6700hqtotal:278  pass:261  dwarn:0   dfail:0   fail:0   skip:17  
time: 596s
fi-skl-6770hqtotal:278  pass:268  dwarn:0   dfail:0   fail:0   skip:10  
time: 519s
fi-skl-gvtdvmtotal:278  pass:265  dwarn:0   dfail:0   fail:0   skip:13  
time: 461s
fi-snb-2520m total:278  pass:250  dwarn:0   dfail:0   fail:0   skip:28  
time: 548s
fi-snb-2600  total:278  pass:249  dwarn:0   dfail:0   fail:0   skip:29  
time: 427s
fi-skl-6700k failed to collect. IGT log at Patchwork_4262/fi-skl-6700k/igt.log

1595c9b1bafa002ccfaa484f1dd3b2d7b9303a64 drm-tip: 2017y-03m-22d-09h-09m-59s UTC 
integration manifest
8b2459b drm/i915: Drop uncore spinlock for reading forcewake counters
307cf40 drm/i915: All fw_domains share the same set/clear/reset values
85a2834 drm/i915: Remove posting-read for forcewake put
0d766f0 drm/i915: Skip unused fw_domains
4c0323c drm/i915: Eliminate per-fw_domain i915 backpointer

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_4262/
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/scdc: declare drm_scdc_get_scrambling_status

2017-03-22 Thread Sharma, Shashank

Thanks for this patch, Jani.

Reviewed-by: Shashank Sharma 


Regards
Shashank
On 3/22/2017 4:33 PM, Jani Nikula wrote:

Fix sparse warning:

drivers/gpu/drm/drm_scdc_helper.c:138:6: warning: symbol
'drm_scdc_get_scrambling_status' was not declared. Should it be static?

Fixes: 62c58af32c93 ("drm/edid: detect SCDC support in HF-VSDB")
Cc: Shashank Sharma 
Signed-off-by: Jani Nikula 
---
  include/drm/drm_scdc_helper.h | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/include/drm/drm_scdc_helper.h b/include/drm/drm_scdc_helper.h
index ab6bcfbceba9..c25122bb490a 100644
--- a/include/drm/drm_scdc_helper.h
+++ b/include/drm/drm_scdc_helper.h
@@ -129,6 +129,8 @@ static inline int drm_scdc_writeb(struct i2c_adapter 
*adapter, u8 offset,
return drm_scdc_write(adapter, offset, &value, sizeof(value));
  }
  
+bool drm_scdc_get_scrambling_status(struct i2c_adapter *adapter);

+
  /**
   * drm_scdc_set_scrambling - enable scrambling
   * @adapter: I2C adapter for DDC channel


___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] ✓ Fi.CI.BAT: success for drm/scdc: declare drm_scdc_get_scrambling_status

2017-03-22 Thread Patchwork
== Series Details ==

Series: drm/scdc: declare drm_scdc_get_scrambling_status
URL   : https://patchwork.freedesktop.org/series/21690/
State : success

== Summary ==

Series 21690v1 drm/scdc: declare drm_scdc_get_scrambling_status
https://patchwork.freedesktop.org/api/1.0/series/21690/revisions/1/mbox/

fi-bdw-5557u total:278  pass:267  dwarn:0   dfail:0   fail:0   skip:11  
time: 457s
fi-bdw-gvtdvmtotal:278  pass:256  dwarn:8   dfail:0   fail:0   skip:14  
time: 465s
fi-bsw-n3050 total:278  pass:239  dwarn:0   dfail:0   fail:0   skip:39  
time: 579s
fi-bxt-j4205 total:278  pass:259  dwarn:0   dfail:0   fail:0   skip:19  
time: 546s
fi-byt-j1900 total:278  pass:251  dwarn:0   dfail:0   fail:0   skip:27  
time: 510s
fi-byt-n2820 total:278  pass:247  dwarn:0   dfail:0   fail:0   skip:31  
time: 505s
fi-hsw-4770  total:278  pass:262  dwarn:0   dfail:0   fail:0   skip:16  
time: 435s
fi-hsw-4770r total:278  pass:262  dwarn:0   dfail:0   fail:0   skip:16  
time: 435s
fi-ilk-650   total:278  pass:228  dwarn:0   dfail:0   fail:0   skip:50  
time: 448s
fi-ivb-3520m total:278  pass:260  dwarn:0   dfail:0   fail:0   skip:18  
time: 520s
fi-ivb-3770  total:278  pass:260  dwarn:0   dfail:0   fail:0   skip:18  
time: 498s
fi-kbl-7500u total:278  pass:260  dwarn:0   dfail:0   fail:0   skip:18  
time: 481s
fi-skl-6260u total:278  pass:268  dwarn:0   dfail:0   fail:0   skip:10  
time: 483s
fi-skl-6700hqtotal:278  pass:261  dwarn:0   dfail:0   fail:0   skip:17  
time: 599s
fi-skl-6700k total:278  pass:256  dwarn:4   dfail:0   fail:0   skip:18  
time: 492s
fi-skl-6770hqtotal:278  pass:268  dwarn:0   dfail:0   fail:0   skip:10  
time: 520s
fi-skl-gvtdvmtotal:278  pass:265  dwarn:0   dfail:0   fail:0   skip:13  
time: 458s
fi-snb-2520m total:278  pass:250  dwarn:0   dfail:0   fail:0   skip:28  
time: 548s
fi-snb-2600  total:278  pass:248  dwarn:0   dfail:0   fail:1   skip:29  
time: 415s

1595c9b1bafa002ccfaa484f1dd3b2d7b9303a64 drm-tip: 2017y-03m-22d-09h-09m-59s UTC 
integration manifest
da0347c drm/scdc: declare drm_scdc_get_scrambling_status

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_4263/
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v2 5/5] drm/i915: Drop uncore spinlock for reading forcewake counters

2017-03-22 Thread Joonas Lahtinen
On ke, 2017-03-22 at 12:37 +, Chris Wilson wrote:
> The set of available structs is not protected by the spinlock, and for
> the single read we can use READ_ONCE instead.
> 
> Signed-off-by: Chris Wilson 

Reviewed-by: Joonas Lahtinen 

Regards, Joonas
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH] drm/scdc: declare drm_scdc_get_scrambling_status

2017-03-22 Thread Jani Nikula
Fix sparse warning:

drivers/gpu/drm/drm_scdc_helper.c:138:6: warning: symbol
'drm_scdc_get_scrambling_status' was not declared. Should it be static?

Fixes: 62c58af32c93 ("drm/edid: detect SCDC support in HF-VSDB")
Cc: Shashank Sharma 
Signed-off-by: Jani Nikula 
---
 include/drm/drm_scdc_helper.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/drm/drm_scdc_helper.h b/include/drm/drm_scdc_helper.h
index ab6bcfbceba9..c25122bb490a 100644
--- a/include/drm/drm_scdc_helper.h
+++ b/include/drm/drm_scdc_helper.h
@@ -129,6 +129,8 @@ static inline int drm_scdc_writeb(struct i2c_adapter 
*adapter, u8 offset,
return drm_scdc_write(adapter, offset, &value, sizeof(value));
 }
 
+bool drm_scdc_get_scrambling_status(struct i2c_adapter *adapter);
+
 /**
  * drm_scdc_set_scrambling - enable scrambling
  * @adapter: I2C adapter for DDC channel
-- 
2.1.4

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH v2] drm/i915: Store a direct lookup from object handle to vma

2017-03-22 Thread Joonas Lahtinen
+ Daniel for the rsvd2

On ke, 2017-03-22 at 09:33 +, Chris Wilson wrote:
> The advent of full-ppgtt lead to an extra indirection between the object
> and its binding. That extra indirection has a noticeable impact on how
> fast we can convert from the user handles to our internal vma for
> execbuffer. In order to bypass the extra indirection, we use a
> resizable hashtable to jump from the object to the per-ctx vma.
> rhashtable was considered but we don't need the online resizing feature
> and the extra complexity proved to undermine its usefulness. Instead, we
> simply reallocate the hastable on demand in a background task and
> serialize it before iterating.
> 
> In non-full-ppgtt modes, multiple files and multiple contexts can share
> the same vma. This leads to having multiple possible handle->vma links,
> so we only use the first to establish the fast path. The majority of
> buffers are not shared and so we should still be able to realise
> speedups with multiple clients.
> 
> v2: Prettier names, more magic.
> 
> Signed-off-by: Chris Wilson 


 
> +static void resize_vma_ht(struct work_struct *work)
> +{
> + struct i915_gem_context_vma_lut *lut =
> + container_of(work, typeof(*lut), resize);
> + unsigned int size, bits, new_bits, i;
> + struct hlist_head *new_ht;
> +
> + bits = 1 + ilog2(4*lut->ht_count/3);
> + new_bits = min_t(unsigned int,
> +  max(bits, VMA_HT_BITS),
> +  sizeof(unsigned int)*8);

* BITS_PER_BYTE for extra clarity.

> + if (new_bits == lut->ht_bits)
> + goto out;
> +
> + new_ht = kzalloc(sizeof(*new_ht)< + if (!new_ht)
> + new_ht = vzalloc(sizeof(*new_ht)< @@ -266,6 +331,16 @@ __create_hw_context(struct drm_i915_private *dev_priv,
>   list_add_tail(&ctx->link, &dev_priv->context_list);
>   ctx->i915 = dev_priv;
>  
> + ctx->vma_lut.ht_bits = VMA_HT_BITS;
> + ctx->vma_lut.ht_size = BIT(VMA_HT_BITS);
> + ctx->vma_lut.ht = kcalloc(ctx->vma_lut.ht_size,
> +   sizeof(*ctx->vma_lut.ht),
> +   GFP_KERNEL);
> + if (!ctx->vma_lut.ht)
> + goto err_out;
> +

Errors after this point will leak lut. Need err_lut label and call it
from further error gotos.

> @@ -143,6 +143,31 @@ struct i915_gem_context {
>   /** ggtt_offset_bias: placement restriction for context objects */
>   u32 ggtt_offset_bias;
>  
> + struct i915_gem_context_vma_lut {
> + /** ht_size: last request size to allocate the hashtable for. */
> + unsigned int ht_size;
> +#define RESIZE_IN_PROGRESS BIT(0)

Easily conflicting name? Forward declare and hide in .c file? By making
ht[0] at the end, and maybe pull out work. Or maybe just prefix :P

> +#define to_ptr(T, x) ((T *)(uintptr_t)(x))

i915_utils.h so we some day push to core. from_uintptr might make more
sense, though.

The remainder is somewhat hard to review due to combined code motion
and changes becoming mess, but didn't find anything else but I still
dislike rsvd2 usage, and the magic bit it has.

We could at least #define proper_name rsvd2 in the .c file... Jani
would be glad, I guess. I think if somebody touches a reserved field by
name, they deserve to have their build broken.

Regards, Joonas
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /

2017-03-22 Thread Jani Nikula
On Wed, 22 Mar 2017, David Weinehall  wrote:
> On Wed, Mar 22, 2017 at 12:53:24PM +0200, Jani Nikula wrote:
>> On Wed, 22 Mar 2017, David Weinehall  wrote:
>> > rm -rf / woes can be remedied by always passing "--preserve-root" to rm
>> > (I believe that this is the default already though).
>> 
>> That doesn't help with 'rm -rf /*' though.
>
> Hmmm, but how would you end up with that if it does /$foo and $foo="" or
> unset?

There's a 'rm -rf $foo/*'

-- 
Jani Nikula, Intel Open Source Technology Center
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


  1   2   >