[PATCH] drm/i915/gvt: clean up kernel-doc in gtt.c

2021-10-02 Thread Randy Dunlap
Fix kernel-doc warnings in gtt.c:

gtt.c:1152: warning: This comment starts with '/**', but isn't a kernel-doc 
comment. Refer Documentation/doc-guide/kernel-doc.rst
 * Check if can do 2M page
gtt.c:1152: warning: missing initial short description on line:
 * Check if can do 2M page
gtt.c:2209: warning: expecting prototype for 
intel_vgpu_emulate_gtt_mmio_read(). Prototype was for 
intel_vgpu_emulate_ggtt_mmio_read() instead

Fixes: a752b070a678 ("drm/i915/gvt: Fix function comment doc errors")
Fixes: 2707e4446688 ("drm/i915/gvt: vGPU graphics memory virtualization")
Signed-off-by: Randy Dunlap 
Reported-by: kernel test robot 
Cc: Zhenyu Wang 
Cc: Zhi Wang 
Cc: Colin Xu 
Cc: Jani Nikula 
Cc: Joonas Lahtinen 
Cc: Rodrigo Vivi 
Cc: intel-...@lists.freedesktop.org
Cc: intel-gvt-...@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Cc: David Airlie 
Cc: Daniel Vetter 
---
 drivers/gpu/drm/i915/gvt/gtt.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- linux-next-20211001.orig/drivers/gpu/drm/i915/gvt/gtt.c
+++ linux-next-20211001/drivers/gpu/drm/i915/gvt/gtt.c
@@ -1148,7 +1148,7 @@ static inline void ppgtt_generate_shadow
ops->set_pfn(se, s->shadow_page.mfn);
 }
 
-/**
+/*
  * Check if can do 2M page
  * @vgpu: target vgpu
  * @entry: target pfn's gtt entry
@@ -2193,7 +2193,7 @@ static int emulate_ggtt_mmio_read(struct
 }
 
 /**
- * intel_vgpu_emulate_gtt_mmio_read - emulate GTT MMIO register read
+ * intel_vgpu_emulate_ggtt_mmio_read - emulate GTT MMIO register read
  * @vgpu: a vGPU
  * @off: register offset
  * @p_data: data will be returned to guest


Re: [PATCH v2 6/8] drm/msm/dsi: stop setting clock parents manually

2021-10-02 Thread Dmitry Baryshkov

On 10/07/2021 00:07, Dmitry Baryshkov wrote:

There is no reason to set clock parents manually, use device tree to
assign DSI/display clock parents to DSI PHY clocks. Dropping this manual
setup allows us to drop repeating code and to move registration of hw
clock providers to generic place.

Signed-off-by: Dmitry Baryshkov 
Reviewed-by: Abhinav Kumar 


As the DTS changes were merged for the 5.15, would it be time to merge 
the rest of this patch series for the 5.16?



---
  drivers/gpu/drm/msm/dsi/dsi.h |  2 --
  drivers/gpu/drm/msm/dsi/dsi_host.c| 51 ---
  drivers/gpu/drm/msm/dsi/dsi_manager.c |  5 ---
  drivers/gpu/drm/msm/dsi/phy/dsi_phy.c | 11 --
  4 files changed, 69 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
index 9b8e9b07eced..1f0ec78c6b05 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.h
+++ b/drivers/gpu/drm/msm/dsi/dsi.h
@@ -170,8 +170,6 @@ void msm_dsi_phy_get_shared_timings(struct msm_dsi_phy *phy,
struct msm_dsi_phy_shared_timings *shared_timing);
  void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
 enum msm_dsi_phy_usecase uc);
-int msm_dsi_phy_get_clk_provider(struct msm_dsi_phy *phy,
-   struct clk **byte_clk_provider, struct clk **pixel_clk_provider);
  void msm_dsi_phy_pll_save_state(struct msm_dsi_phy *phy);
  int msm_dsi_phy_pll_restore_state(struct msm_dsi_phy *phy);
  void msm_dsi_phy_snapshot(struct msm_disp_state *disp_state, struct 
msm_dsi_phy *phy);
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index ed504fe5074f..1fa6ee12395b 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -2219,57 +2219,6 @@ void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host 
*host, u32 dma_base,
wmb();
  }
  
-int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,

-   struct msm_dsi_phy *src_phy)
-{
-   struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
-   struct clk *byte_clk_provider, *pixel_clk_provider;
-   int ret;
-
-   ret = msm_dsi_phy_get_clk_provider(src_phy,
-   _clk_provider, _clk_provider);
-   if (ret) {
-   pr_info("%s: can't get provider from pll, don't set parent\n",
-   __func__);
-   return 0;
-   }
-
-   ret = clk_set_parent(msm_host->byte_clk_src, byte_clk_provider);
-   if (ret) {
-   pr_err("%s: can't set parent to byte_clk_src. ret=%d\n",
-   __func__, ret);
-   goto exit;
-   }
-
-   ret = clk_set_parent(msm_host->pixel_clk_src, pixel_clk_provider);
-   if (ret) {
-   pr_err("%s: can't set parent to pixel_clk_src. ret=%d\n",
-   __func__, ret);
-   goto exit;
-   }
-
-   if (msm_host->dsi_clk_src) {
-   ret = clk_set_parent(msm_host->dsi_clk_src, pixel_clk_provider);
-   if (ret) {
-   pr_err("%s: can't set parent to dsi_clk_src. ret=%d\n",
-   __func__, ret);
-   goto exit;
-   }
-   }
-
-   if (msm_host->esc_clk_src) {
-   ret = clk_set_parent(msm_host->esc_clk_src, byte_clk_provider);
-   if (ret) {
-   pr_err("%s: can't set parent to esc_clk_src. ret=%d\n",
-   __func__, ret);
-   goto exit;
-   }
-   }
-
-exit:
-   return ret;
-}
-
  void msm_dsi_host_reset_phy(struct mipi_dsi_host *host)
  {
struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
diff --git a/drivers/gpu/drm/msm/dsi/dsi_manager.c 
b/drivers/gpu/drm/msm/dsi/dsi_manager.c
index 4ebfedc4a9ac..4a17f12b9316 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_manager.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_manager.c
@@ -78,7 +78,6 @@ static int dsi_mgr_setup_components(int id)
return ret;
  
  		msm_dsi_phy_set_usecase(msm_dsi->phy, MSM_DSI_PHY_STANDALONE);

-   ret = msm_dsi_host_set_src_pll(msm_dsi->host, msm_dsi->phy);
} else if (!other_dsi) {
ret = 0;
} else {
@@ -105,10 +104,6 @@ static int dsi_mgr_setup_components(int id)
MSM_DSI_PHY_MASTER);
msm_dsi_phy_set_usecase(clk_slave_dsi->phy,
MSM_DSI_PHY_SLAVE);
-   ret = msm_dsi_host_set_src_pll(msm_dsi->host, 
clk_master_dsi->phy);
-   if (ret)
-   return ret;
-   ret = msm_dsi_host_set_src_pll(other_dsi->host, 
clk_master_dsi->phy);
}
  
  	return ret;

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index 6ca6bfd4809b..952fd0b95865 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ 

Re: [V2] drm: msm: adreno: use IS_ERR() instead of null pointer check

2021-10-02 Thread Dmitry Baryshkov

On 07/11/2020 06:19, Wang Qing wrote:

a6xx_gmu_get_mmio() never return null in case of error, but ERR_PTR(), so
we should use IS_ERR() instead of null pointer check and IS_ERR_OR_NULL().

Signed-off-by: Wang Qing 


As a second thought, ioremap's NULL is converted to ERR_PTR(-EINVAL), so 
the patch is correct.



---
  drivers/gpu/drm/msm/adreno/a6xx_gmu.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c 
b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
index 491fee4..82420f7
--- a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
+++ b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
@@ -492,7 +492,7 @@ static void a6xx_gmu_rpmh_init(struct a6xx_gmu *gmu)
void __iomem *seqptr = a6xx_gmu_get_mmio(pdev, "gmu_pdc_seq");
uint32_t pdc_address_offset;
  
-	if (!pdcptr || !seqptr)

+   if (IS_ERR(pdcptr) || IS_ERR(seqptr))
goto err;
  
  	if (adreno_is_a618(adreno_gpu) || adreno_is_a640(adreno_gpu))

@@ -580,9 +580,9 @@ static void a6xx_gmu_rpmh_init(struct a6xx_gmu *gmu)
wmb();
  
  err:

-   if (!IS_ERR_OR_NULL(pdcptr))
+   if (!IS_ERR(pdcptr))
iounmap(pdcptr);
-   if (!IS_ERR_OR_NULL(seqptr))
+   if (!IS_ERR(seqptr))
iounmap(seqptr);
  }
  




--
With best wishes
Dmitry


Re: [V2] drm: msm: adreno: use IS_ERR() instead of null pointer check

2021-10-02 Thread Dmitry Baryshkov

On 07/11/2020 06:19, Wang Qing wrote:

a6xx_gmu_get_mmio() never return null in case of error, but ERR_PTR(), so
we should use IS_ERR() instead of null pointer check and IS_ERR_OR_NULL().


Not quite. a6xx_gmu_get_mmio() can return NULL, as it uses ioremap() 
internally. And ioremap returns NULL in case of error. So the proper 
check should be IS_ERR_OR_NULL().




Signed-off-by: Wang Qing 
---
  drivers/gpu/drm/msm/adreno/a6xx_gmu.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c 
b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
index 491fee4..82420f7
--- a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
+++ b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
@@ -492,7 +492,7 @@ static void a6xx_gmu_rpmh_init(struct a6xx_gmu *gmu)
void __iomem *seqptr = a6xx_gmu_get_mmio(pdev, "gmu_pdc_seq");
uint32_t pdc_address_offset;
  
-	if (!pdcptr || !seqptr)

+   if (IS_ERR(pdcptr) || IS_ERR(seqptr))
goto err;
  
  	if (adreno_is_a618(adreno_gpu) || adreno_is_a640(adreno_gpu))

@@ -580,9 +580,9 @@ static void a6xx_gmu_rpmh_init(struct a6xx_gmu *gmu)
wmb();
  
  err:

-   if (!IS_ERR_OR_NULL(pdcptr))
+   if (!IS_ERR(pdcptr))
iounmap(pdcptr);
-   if (!IS_ERR_OR_NULL(seqptr))
+   if (!IS_ERR(seqptr))
iounmap(seqptr);
  }
  




--
With best wishes
Dmitry


[PATCH v1 5/5] drm/bridge: tc358768: Correct BTACNTRL1 programming

2021-10-02 Thread Dmitry Osipenko
TXTAGOCNT and RXTASURECNT bitfields of BTACNTRL1 register are swapped in
the code, correct them. Driver doesn't implement low power mode for now,
so this change doesn't make a practical difference yet.

Tested-by: Andreas Westman Dorcsak  # Asus TF700T
Tested-by: Maxim Schwalm  #TF700T
Signed-off-by: Dmitry Osipenko 
---
 drivers/gpu/drm/bridge/tc358768.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/tc358768.c 
b/drivers/gpu/drm/bridge/tc358768.c
index cfceba5ef3b8..fd585bf925fe 100644
--- a/drivers/gpu/drm/bridge/tc358768.c
+++ b/drivers/gpu/drm/bridge/tc358768.c
@@ -790,7 +790,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
val = tc358768_ns_to_cnt(val, dsibclk_nsk) - 1;
val2 = tc358768_ns_to_cnt(tc358768_to_ns((lptxcnt + 1) * dsibclk_nsk),
  dsibclk_nsk) - 2;
-   val |= val2 << 16;
+   val = val << 16 | val2;
dev_dbg(priv->dev, "BTACNTRL1: 0x%x\n", val);
tc358768_write(priv, TC358768_BTACNTRL1, val);
 
-- 
2.32.0



[PATCH v1 4/5] drm/bridge: tc358768: Disable non-continuous clock mode

2021-10-02 Thread Dmitry Osipenko
Non-continuous clock mode doesn't work because driver doesn't support it
properly. The bridge driver programs wrong bitfields that are required by
the non-continuous mode (BTACNTRL1 register bitfields are swapped in the
code), but fixing them doesn't help.

Display panel of ASUS Transformer TF700T tablet supports non-continuous
mode and display doesn't work at all using that mode. There are no
device-trees that are actively using this DSI bridge in upstream yet,
so clearly the broken mode wasn't ever tested properly. It's a bit too
difficult to get LP mode working, hence let's disable the offending mode
for now and fall back to continuous mode.

Tested-by: Andreas Westman Dorcsak  # Asus TF700T
Tested-by: Maxim Schwalm  #TF700T
Signed-off-by: Dmitry Osipenko 
---
 drivers/gpu/drm/bridge/tc358768.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/tc358768.c 
b/drivers/gpu/drm/bridge/tc358768.c
index 5b3f8723bd3d..cfceba5ef3b8 100644
--- a/drivers/gpu/drm/bridge/tc358768.c
+++ b/drivers/gpu/drm/bridge/tc358768.c
@@ -631,6 +631,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
 {
struct tc358768_priv *priv = bridge_to_tc358768(bridge);
struct mipi_dsi_device *dsi_dev = priv->output.dev;
+   unsigned long mode_flags = dsi_dev->mode_flags;
u32 val, val2, lptxcnt, hact, data_type;
const struct drm_display_mode *mode;
u32 dsibclk_nsk, dsiclk_nsk, ui_nsk, phy_delay_nsk;
@@ -638,6 +639,11 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
const u32 internal_delay = 40;
int ret, i;
 
+   if (mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) {
+   dev_warn_once(priv->dev, "Non-continuous mode unimplemented, 
falling back to continuous\n");
+   mode_flags &= ~MIPI_DSI_CLOCK_NON_CONTINUOUS;
+   }
+
tc358768_hw_enable(priv);
 
ret = tc358768_sw_reset(priv);
@@ -776,7 +782,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
val |= BIT(i + 1);
tc358768_write(priv, TC358768_HSTXVREGEN, val);
 
-   if (!(dsi_dev->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS))
+   if (!(mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS))
tc358768_write(priv, TC358768_TXOPTIONCNTRL, 0x1);
 
/* TXTAGOCNT[26:16] RXTASURECNT[10:0] */
@@ -864,7 +870,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
if (!(dsi_dev->mode_flags & MIPI_DSI_MODE_LPM))
val |= TC358768_DSI_CONTROL_TXMD;
 
-   if (!(dsi_dev->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS))
+   if (!(mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS))
val |= TC358768_DSI_CONTROL_HSCKMD;
 
if (dsi_dev->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET)
-- 
2.32.0



[PATCH v1 3/5] drm/bridge: tc358768: Calculate video start delay

2021-10-02 Thread Dmitry Osipenko
Calculate video start delay based on the display timing instead
of hardcoding it to a default value. This fixes "trembling" display
output on Asus Transformer TF700T which uses Panasonic VVX10F004B00
display panel.

Tested-by: Andreas Westman Dorcsak  # Asus TF700T
Tested-by: Maxim Schwalm  #TF700T
Signed-off-by: Dmitry Osipenko 
---
 drivers/gpu/drm/bridge/tc358768.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/tc358768.c 
b/drivers/gpu/drm/bridge/tc358768.c
index 10ebd0621ad3..5b3f8723bd3d 100644
--- a/drivers/gpu/drm/bridge/tc358768.c
+++ b/drivers/gpu/drm/bridge/tc358768.c
@@ -634,7 +634,8 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
u32 val, val2, lptxcnt, hact, data_type;
const struct drm_display_mode *mode;
u32 dsibclk_nsk, dsiclk_nsk, ui_nsk, phy_delay_nsk;
-   u32 dsiclk, dsibclk;
+   u32 dsiclk, dsibclk, video_start;
+   const u32 internal_delay = 40;
int ret, i;
 
tc358768_hw_enable(priv);
@@ -663,23 +664,27 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
case MIPI_DSI_FMT_RGB888:
val |= (0x3 << 4);
hact = mode->hdisplay * 3;
+   video_start = (mode->htotal - mode->hsync_start) * 3;
data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
break;
case MIPI_DSI_FMT_RGB666:
val |= (0x4 << 4);
hact = mode->hdisplay * 3;
+   video_start = (mode->htotal - mode->hsync_start) * 3;
data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
break;
 
case MIPI_DSI_FMT_RGB666_PACKED:
val |= (0x4 << 4) | BIT(3);
hact = mode->hdisplay * 18 / 8;
+   video_start = (mode->htotal - mode->hsync_start) * 18 / 8;
data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
break;
 
case MIPI_DSI_FMT_RGB565:
val |= (0x5 << 4);
hact = mode->hdisplay * 2;
+   video_start = (mode->htotal - mode->hsync_start) * 2;
data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
break;
default:
@@ -690,7 +695,8 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
}
 
/* VSDly[9:0] */
-   tc358768_write(priv, TC358768_VSDLY, 1);
+   video_start = max(video_start, internal_delay + 1) - internal_delay;
+   tc358768_write(priv, TC358768_VSDLY, video_start);
 
tc358768_write(priv, TC358768_DATAFMT, val);
tc358768_write(priv, TC358768_DSITX_DT, data_type);
-- 
2.32.0



[PATCH v1 2/5] drm/bridge: tc358768: Support pulse mode

2021-10-02 Thread Dmitry Osipenko
Support pulse-mode synchronization which is supported and used by simple
DSI panels like Panasonic VVX10F004B00.

Tested-by: Andreas Westman Dorcsak  # Asus TF700T
Tested-by: Maxim Schwalm  #TF700T
Signed-off-by: Dmitry Osipenko 
---
 drivers/gpu/drm/bridge/tc358768.c | 66 ++-
 1 file changed, 48 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/bridge/tc358768.c 
b/drivers/gpu/drm/bridge/tc358768.c
index 18ae6605a803..10ebd0621ad3 100644
--- a/drivers/gpu/drm/bridge/tc358768.c
+++ b/drivers/gpu/drm/bridge/tc358768.c
@@ -785,24 +785,54 @@ static void tc358768_bridge_pre_enable(struct drm_bridge 
*bridge)
/* START[0] */
tc358768_write(priv, TC358768_STARTCNTRL, 1);
 
-   /* Set event mode */
-   tc358768_write(priv, TC358768_DSI_EVENT, 1);
-
-   /* vsw (+ vbp) */
-   tc358768_write(priv, TC358768_DSI_VSW,
-  mode->vtotal - mode->vsync_start);
-   /* vbp (not used in event mode) */
-   tc358768_write(priv, TC358768_DSI_VBPR, 0);
-   /* vact */
-   tc358768_write(priv, TC358768_DSI_VACT, mode->vdisplay);
-
-   /* (hsw + hbp) * byteclk * ndl / pclk */
-   val = (u32)div_u64((mode->htotal - mode->hsync_start) *
-  ((u64)priv->dsiclk / 4) * priv->dsi_lanes,
-  mode->clock * 1000);
-   tc358768_write(priv, TC358768_DSI_HSW, val);
-   /* hbp (not used in event mode) */
-   tc358768_write(priv, TC358768_DSI_HBPR, 0);
+   if (dsi_dev->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) {
+   /* Set pulse mode */
+   tc358768_write(priv, TC358768_DSI_EVENT, 0);
+
+   /* vact */
+   tc358768_write(priv, TC358768_DSI_VACT, mode->vdisplay);
+
+   /* vsw */
+   tc358768_write(priv, TC358768_DSI_VSW,
+  mode->vsync_end - mode->vsync_start);
+   /* vbp */
+   tc358768_write(priv, TC358768_DSI_VBPR,
+  mode->vtotal - mode->vsync_end);
+
+   /* hsw * byteclk * ndl / pclk */
+   val = (u32)div_u64((mode->hsync_end - mode->hsync_start) *
+  ((u64)priv->dsiclk / 4) * priv->dsi_lanes,
+  mode->clock * 1000);
+   tc358768_write(priv, TC358768_DSI_HSW, val);
+
+   /* hbp * byteclk * ndl / pclk */
+   val = (u32)div_u64((mode->htotal - mode->hsync_end) *
+  ((u64)priv->dsiclk / 4) * priv->dsi_lanes,
+  mode->clock * 1000);
+   tc358768_write(priv, TC358768_DSI_HBPR, val);
+   } else {
+   /* Set event mode */
+   tc358768_write(priv, TC358768_DSI_EVENT, 1);
+
+   /* vact */
+   tc358768_write(priv, TC358768_DSI_VACT, mode->vdisplay);
+
+   /* vsw (+ vbp) */
+   tc358768_write(priv, TC358768_DSI_VSW,
+  mode->vtotal - mode->vsync_start);
+   /* vbp (not used in event mode) */
+   tc358768_write(priv, TC358768_DSI_VBPR, 0);
+
+   /* (hsw + hbp) * byteclk * ndl / pclk */
+   val = (u32)div_u64((mode->htotal - mode->hsync_start) *
+  ((u64)priv->dsiclk / 4) * priv->dsi_lanes,
+  mode->clock * 1000);
+   tc358768_write(priv, TC358768_DSI_HSW, val);
+
+   /* hbp (not used in event mode) */
+   tc358768_write(priv, TC358768_DSI_HBPR, 0);
+   }
+
/* hact (bytes) */
tc358768_write(priv, TC358768_DSI_HACT, hact);
 
-- 
2.32.0



[PATCH v1 1/5] drm/bridge: tc358768: Enable reference clock

2021-10-02 Thread Dmitry Osipenko
The driver assumes that reference clock is always-enabled, but this is
hardware-dependent and not true for ASUS Transformer TF700T. Make driver
enable / disable the reference clock.

Tested-by: Andreas Westman Dorcsak  # Asus TF700T
Tested-by: Maxim Schwalm  #TF700T
Signed-off-by: Dmitry Osipenko 
---
 drivers/gpu/drm/bridge/tc358768.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/bridge/tc358768.c 
b/drivers/gpu/drm/bridge/tc358768.c
index a3db532bbdd1..18ae6605a803 100644
--- a/drivers/gpu/drm/bridge/tc358768.c
+++ b/drivers/gpu/drm/bridge/tc358768.c
@@ -237,6 +237,10 @@ static void tc358768_hw_enable(struct tc358768_priv *priv)
if (priv->enabled)
return;
 
+   ret = clk_prepare_enable(priv->refclk);
+   if (ret < 0)
+   dev_err(priv->dev, "error enabling refclk (%d)\n", ret);
+
ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
if (ret < 0)
dev_err(priv->dev, "error enabling regulators (%d)\n", ret);
@@ -274,6 +278,8 @@ static void tc358768_hw_disable(struct tc358768_priv *priv)
if (ret < 0)
dev_err(priv->dev, "error disabling regulators (%d)\n", ret);
 
+   clk_disable_unprepare(priv->refclk);
+
priv->enabled = false;
 }
 
-- 
2.32.0



[PATCH v1 0/5] Improvements for TC358768 DSI bridge driver

2021-10-02 Thread Dmitry Osipenko
This series adds couple improvements to the TC358768 DSI bridge driver,
enabling Panasonic VVX10F004B00 DSI panel support. This panel is used by
ASUS Transformer TF700T tablet, which is ready for upstream kernel and
display panel support is the biggest missing part.

Dmitry Osipenko (5):
  drm/bridge: tc358768: Enable reference clock
  drm/bridge: tc358768: Support pulse mode
  drm/bridge: tc358768: Calculate video start delay
  drm/bridge: tc358768: Disable non-continuous clock mode
  drm/bridge: tc358768: Correct BTACNTRL1 programming

 drivers/gpu/drm/bridge/tc358768.c | 94 +++
 1 file changed, 71 insertions(+), 23 deletions(-)

-- 
2.32.0



Re: [Intel-gfx] [PATCH v2 00/17] drm: cleanup: Use DRM_MODESET_LOCK_ALL_* helpers where possible

2021-10-02 Thread Fernando Ramos
On 21/10/02 09:13AM, Fernando Ramos wrote:
> 
> Sean, could you revert the whole patch series? I'll have a deeper look into 
> the
> patch set and come up with a v3 where all these issues will be addressed.
> 

Hi Sean,

I now understand the nature of the issue that caused the problem with i915 and
have proceed to remove the global context structure (which revealed a similar
issue in the amdgpu driver).

I have prepared a V3 version of the patch set where these issues should
hopefully be fixed for both the i915 and amdgpu drivers.

In order to prevent causing more disruption, could you tell me what the proper
way to proceed would be? In particular:

  1. Is there any place where I can push my changes so that they are tested
 on a i915 machine? (Some type of automated pool)

  2. I can test the amdgpu driver on my machine but, what about all the other
 architectures? What is the standard procedure? Should I simply publish V3
 and wait for feedback from the different vendors? (I would hate to cause a
 simular situation again)

  3. Should I post V3 on top of drm-next or drm-misc-next?

Thanks for your patience :)


Re: [PATCH 10/10] drm/gma500: Rename struct gtt_range to struct psb_gem_object

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> struct gtt_range represents a GEM object. Rename the structure to struct
> psb_gem_object and update all users. No functional changes.
>
> Signed-off-by: Thomas Zimmermann 

Acked-by: Patrik Jakobsson 


> ---
>  drivers/gpu/drm/gma500/framebuffer.c   |   9 +-
>  drivers/gpu/drm/gma500/gem.c   | 106 +++--
>  drivers/gpu/drm/gma500/gem.h   |  25 -
>  drivers/gpu/drm/gma500/gma_display.c   |  50 +-
>  drivers/gpu/drm/gma500/gtt.c   |  15 +--
>  drivers/gpu/drm/gma500/gtt.h   |  15 ---
>  drivers/gpu/drm/gma500/oaktrail_crtc.c |   3 +-
>  drivers/gpu/drm/gma500/psb_intel_display.c |  15 ++-
>  drivers/gpu/drm/gma500/psb_intel_drv.h |   2 +-
>  9 files changed, 123 insertions(+), 117 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/framebuffer.c 
> b/drivers/gpu/drm/gma500/framebuffer.c
> index 3ea6679ccd38..45df9de22007 100644
> --- a/drivers/gpu/drm/gma500/framebuffer.c
> +++ b/drivers/gpu/drm/gma500/framebuffer.c
> @@ -81,14 +81,13 @@ static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
> struct drm_framebuffer *fb = vma->vm_private_data;
> struct drm_device *dev = fb->dev;
> struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> -   struct gtt_range *gtt = to_gtt_range(fb->obj[0]);
> +   struct psb_gem_object *pobj = to_psb_gem_object(fb->obj[0]);
> int page_num;
> int i;
> unsigned long address;
> vm_fault_t ret = VM_FAULT_SIGBUS;
> unsigned long pfn;
> -   unsigned long phys_addr = (unsigned long)dev_priv->stolen_base +
> - gtt->offset;
> +   unsigned long phys_addr = (unsigned long)dev_priv->stolen_base + 
> pobj->offset;
>
> page_num = vma_pages(vma);
> address = vmf->address - (vmf->pgoff << PAGE_SHIFT);
> @@ -242,7 +241,7 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
> struct drm_mode_fb_cmd2 mode_cmd;
> int size;
> int ret;
> -   struct gtt_range *backing;
> +   struct psb_gem_object *backing;
> struct drm_gem_object *obj;
> u32 bpp, depth;
>
> @@ -264,7 +263,7 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
> backing = psb_gem_create(dev, size, "fb", true, PAGE_SIZE);
> if (IS_ERR(backing))
> return PTR_ERR(backing);
> -   obj = >gem;
> +   obj = >base;
>
> memset(dev_priv->vram_addr + backing->offset, 0, size);
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index fd556ba2c044..9b7052153cab 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -21,9 +21,10 @@
>  #include "gem.h"
>  #include "psb_drv.h"
>
> -int psb_gem_pin(struct gtt_range *gt)
> +int psb_gem_pin(struct psb_gem_object *pobj)
>  {
> -   struct drm_device *dev = gt->gem.dev;
> +   struct drm_gem_object *obj = >base;
> +   struct drm_device *dev = obj->dev;
> struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> u32 gpu_base = dev_priv->gtt.gatt_start;
> struct page **pages;
> @@ -31,57 +32,58 @@ int psb_gem_pin(struct gtt_range *gt)
>
> mutex_lock(_priv->gtt_mutex);
>
> -   if (gt->in_gart || gt->stolen)
> +   if (pobj->in_gart || pobj->stolen)
> goto out; /* already mapped */
>
> -   pages = drm_gem_get_pages(>gem);
> +   pages = drm_gem_get_pages(obj);
> if (IS_ERR(pages))
> return PTR_ERR(pages);
>
> -   npages = gt->gem.size / PAGE_SIZE;
> +   npages = obj->size / PAGE_SIZE;
>
> set_pages_array_wc(pages, npages);
>
> -   psb_gtt_insert_pages(dev_priv, >resource, pages);
> +   psb_gtt_insert_pages(dev_priv, >resource, pages);
> psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu), pages,
> -(gpu_base + gt->offset), npages, 0, 0,
> +(gpu_base + pobj->offset), npages, 0, 0,
>  PSB_MMU_CACHED_MEMORY);
>
> -   gt->npage = npages;
> -   gt->pages = pages;
> +   pobj->npage = npages;
> +   pobj->pages = pages;
>
>  out:
> -   ++gt->in_gart;
> +   ++pobj->in_gart;
> mutex_unlock(_priv->gtt_mutex);
>
> return 0;
>  }
>
> -void psb_gem_unpin(struct gtt_range *gt)
> +void psb_gem_unpin(struct psb_gem_object *pobj)
>  {
> -   struct drm_device *dev = gt->gem.dev;
> +   struct drm_gem_object *obj = >base;
> +   struct drm_device *dev = obj->dev;
> struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> u32 gpu_base = dev_priv->gtt.gatt_start;
>
> mutex_lock(_priv->gtt_mutex);
>
> -   WARN_ON(!gt->in_gart);
> +   WARN_ON(!pobj->in_gart);
>
> -   --gt->in_gart;
> +   --pobj->in_gart;
>
> -   if (gt->in_gart || gt->stolen)
> +   if 

Re: [PATCH 09/10] drm/gma500: Rewrite GTT page insert/remove without struct gtt_range

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> struct gtt_range represents a GEM object and should not be used for GTT
> setup. Change psb_gtt_insert() and psb_gtt_remove() to receive all
> necessary parameters from their caller. This also eliminates possible
> failure from psb_gtt_insert().
>
> There's one exception in psb_gtt_restore(), which requires an upcast
> from struct resource to struct gtt_range when restoring the GTT after
> hibernation. A possible solution would track the GEM objects that need
> restoration separately from the GTT resource.

We could also treat the GTT as registers and save/restore it that way.
OFC that approach would waste a bit of memory.


>
> Rename the functions to psb_gtt_insert_pages() and psb_gtt_remove_pages()
> to reflect their similarity to MMU interfaces.
>
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/gma500/gem.c | 13 ++
>  drivers/gpu/drm/gma500/gtt.c | 87 
>  drivers/gpu/drm/gma500/gtt.h |  5 ++-
>  3 files changed, 35 insertions(+), 70 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index a88d51a3aa2a..fd556ba2c044 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -23,7 +23,6 @@
>
>  int psb_gem_pin(struct gtt_range *gt)
>  {
> -   int ret = 0;
> struct drm_device *dev = gt->gem.dev;
> struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> u32 gpu_base = dev_priv->gtt.gatt_start;
> @@ -43,10 +42,7 @@ int psb_gem_pin(struct gtt_range *gt)
>
> set_pages_array_wc(pages, npages);
>
> -   ret = psb_gtt_insert(dev, gt);
> -   if (ret)
> -   goto err_drm_gem_put_pages;
> -
> +   psb_gtt_insert_pages(dev_priv, >resource, pages);
> psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu), pages,
>  (gpu_base + gt->offset), npages, 0, 0,
>  PSB_MMU_CACHED_MEMORY);
> @@ -59,10 +55,6 @@ int psb_gem_pin(struct gtt_range *gt)
> mutex_unlock(_priv->gtt_mutex);
>
> return 0;
> -
> -err_drm_gem_put_pages:
> -   drm_gem_put_pages(>gem, pages, true, false);
> -   return ret;
>  }
>
>  void psb_gem_unpin(struct gtt_range *gt)
> @@ -82,13 +74,14 @@ void psb_gem_unpin(struct gtt_range *gt)
>
> psb_mmu_remove_pages(psb_mmu_get_default_pd(dev_priv->mmu),
>  (gpu_base + gt->offset), gt->npage, 0, 
> 0);
> -   psb_gtt_remove(dev, gt);
> +   psb_gtt_remove_pages(dev_priv, >resource);
>
> /* Reset caching flags */
> set_pages_array_wb(gt->pages, gt->npage);
>
> drm_gem_put_pages(>gem, gt->pages, true, false);
> gt->pages = NULL;
> +   gt->npage = 0;
>
>  out:
> mutex_unlock(_priv->gtt_mutex);
> diff --git a/drivers/gpu/drm/gma500/gtt.c b/drivers/gpu/drm/gma500/gtt.c
> index 244de618e612..cf71a2396c16 100644
> --- a/drivers/gpu/drm/gma500/gtt.c
> +++ b/drivers/gpu/drm/gma500/gtt.c
> @@ -66,85 +66,51 @@ static inline uint32_t psb_gtt_mask_pte(uint32_t pfn, int 
> type)
> return (pfn << PAGE_SHIFT) | mask;
>  }
>
> -/**
> - * psb_gtt_entry   -   find the GTT entries for a gtt_range
> - * @dev: our DRM device
> - * @r: our GTT range
> - *
> - * Given a gtt_range object return the GTT offset of the page table
> - * entries for this gtt_range
> - */
> -static u32 __iomem *psb_gtt_entry(struct drm_device *dev, struct gtt_range 
> *r)
> +static u32 __iomem *psb_gtt_entry(struct drm_psb_private *pdev, const struct 
> resource *res)
>  {
> -   struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> -   unsigned long offset;
> -
> -   offset = r->resource.start - dev_priv->gtt_mem->start;
> +   unsigned long offset = res->start - pdev->gtt_mem->start;
>
> -   return dev_priv->gtt_map + (offset >> PAGE_SHIFT);
> +   return pdev->gtt_map + (offset >> PAGE_SHIFT);
>  }
>
> -/**
> - * psb_gtt_insert  -   put an object into the GTT
> - * @dev: our DRM device
> - * @r: our GTT range
> - *
> - * Take our preallocated GTT range and insert the GEM object into
> - * the GTT. This is protected via the gtt mutex which the caller
> - * must hold.
> - */
> -int psb_gtt_insert(struct drm_device *dev, struct gtt_range *r)
> +void psb_gtt_insert_pages(struct drm_psb_private *pdev, const struct 
> resource *res,
> + struct page **pages)
>  {
> +   resource_size_t npages, i;
> u32 __iomem *gtt_slot;
> u32 pte;
> -   int i;
>
> -   if (r->pages == NULL) {
> -   WARN_ON(1);
> -   return -EINVAL;
> -   }
> -
> -   WARN_ON(r->stolen); /* refcount these maybe ? */
> +   /* Write our page entries into the GTT itself */
>
> -   gtt_slot = psb_gtt_entry(dev, r);
> +   npages = resource_size(res) >> PAGE_SHIFT;
> +   gtt_slot = 

Re: [PATCH 08/10] drm/gma500: Set page-caching flags in GEM pin/unpin

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> Caching of the GEM object's backing pages are unrelated to GTT
> management. Move the respective calls from GTT code to GEM code.
>
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/gma500/gem.c |  9 -
>  drivers/gpu/drm/gma500/gtt.c | 17 ++---
>  drivers/gpu/drm/gma500/gtt.h |  2 +-
>  3 files changed, 11 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index 46209e10dcc2..a88d51a3aa2a 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -13,6 +13,8 @@
>
>  #include 
>
> +#include 
> +
>  #include 
>  #include 
>
> @@ -39,7 +41,9 @@ int psb_gem_pin(struct gtt_range *gt)
>
> npages = gt->gem.size / PAGE_SIZE;
>
> -   ret = psb_gtt_insert(dev, gt, 0);
> +   set_pages_array_wc(pages, npages);
> +
> +   ret = psb_gtt_insert(dev, gt);
> if (ret)
> goto err_drm_gem_put_pages;
>
> @@ -80,6 +84,9 @@ void psb_gem_unpin(struct gtt_range *gt)
>  (gpu_base + gt->offset), gt->npage, 0, 
> 0);
> psb_gtt_remove(dev, gt);
>
> +   /* Reset caching flags */
> +   set_pages_array_wb(gt->pages, gt->npage);
> +
> drm_gem_put_pages(>gem, gt->pages, true, false);
> gt->pages = NULL;
>
> diff --git a/drivers/gpu/drm/gma500/gtt.c b/drivers/gpu/drm/gma500/gtt.c
> index 5d940fdbe6b8..244de618e612 100644
> --- a/drivers/gpu/drm/gma500/gtt.c
> +++ b/drivers/gpu/drm/gma500/gtt.c
> @@ -7,10 +7,6 @@
>   * Alan Cox 
>   */
>
> -#include 
> -
> -#include 
> -
>  #include "psb_drv.h"
>
>
> @@ -92,17 +88,15 @@ static u32 __iomem *psb_gtt_entry(struct drm_device *dev, 
> struct gtt_range *r)
>   * psb_gtt_insert  -   put an object into the GTT
>   * @dev: our DRM device
>   * @r: our GTT range
> - * @resume: on resume
>   *
>   * Take our preallocated GTT range and insert the GEM object into
>   * the GTT. This is protected via the gtt mutex which the caller
>   * must hold.
>   */
> -int psb_gtt_insert(struct drm_device *dev, struct gtt_range *r, int resume)
> +int psb_gtt_insert(struct drm_device *dev, struct gtt_range *r)
>  {
> u32 __iomem *gtt_slot;
> u32 pte;
> -   struct page **pages;
> int i;
>
> if (r->pages == NULL) {
> @@ -113,12 +107,6 @@ int psb_gtt_insert(struct drm_device *dev, struct 
> gtt_range *r, int resume)
> WARN_ON(r->stolen); /* refcount these maybe ? */
>
> gtt_slot = psb_gtt_entry(dev, r);
> -   pages = r->pages;
> -
> -   if (!resume) {
> -   /* Make sure changes are visible to the GPU */
> -   set_pages_array_wc(pages, r->npage);
> -   }

I don't quite remember why we have this but I suspect something bad
happened when setting WC on a page with WC already set. Did you try
hibernation?

>
> /* Write our page entries into the GTT itself */
> for (i = 0; i < r->npage; i++) {
> @@ -158,7 +146,6 @@ void psb_gtt_remove(struct drm_device *dev, struct 
> gtt_range *r)
> for (i = 0; i < r->npage; i++)
> iowrite32(pte, gtt_slot++);
> ioread32(gtt_slot - 1);
> -   set_pages_array_wb(r->pages, r->npage);
>  }
>
>  static void psb_gtt_alloc(struct drm_device *dev)
> @@ -349,7 +336,7 @@ int psb_gtt_restore(struct drm_device *dev)
> while (r != NULL) {
> range = container_of(r, struct gtt_range, resource);
> if (range->pages) {
> -   psb_gtt_insert(dev, range, 1);
> +   psb_gtt_insert(dev, range);
> size += range->resource.end - range->resource.start;
> restored++;
> }
> diff --git a/drivers/gpu/drm/gma500/gtt.h b/drivers/gpu/drm/gma500/gtt.h
> index 459a03141e8b..7af71617e0c5 100644
> --- a/drivers/gpu/drm/gma500/gtt.h
> +++ b/drivers/gpu/drm/gma500/gtt.h
> @@ -49,7 +49,7 @@ int psb_gtt_allocate_resource(struct drm_psb_private *pdev, 
> struct resource *res
>   const char *name, resource_size_t size, 
> resource_size_t align,
>   bool stolen, u32 offset[static 1]);
>
> -int psb_gtt_insert(struct drm_device *dev, struct gtt_range *r, int resume);
> +int psb_gtt_insert(struct drm_device *dev, struct gtt_range *r);
>  void psb_gtt_remove(struct drm_device *dev, struct gtt_range *r);
>
>  #endif
> --
> 2.33.0
>


Re: [PATCH 07/10] drm/gma500: Inline psb_gtt_{alloc,free}_range() into rsp callers

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> psb_gtt_alloc_range() allocates struct gtt_range, create the GTT resource
> and performs some half-baked initialization. Inline the function into its
> only caller psb_gem_create(). For creating the GTT resource, introduce a
> new helper, psb_gtt_alloc_resource() that hides the details of the GTT.
>
> For psb_gtt_free_range(), inline the function into its only caller
> psb_gem_free_object(). While at it, remove the explicit invocation of
> drm_gem_free_mmap_offset(). The mmap offset is already released by
> drm_gem_object_release().
>
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/gma500/gem.c | 94 
>  drivers/gpu/drm/gma500/gtt.c | 27 +++
>  drivers/gpu/drm/gma500/gtt.h |  6 +++
>  3 files changed, 65 insertions(+), 62 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index a48d7d5ed026..46209e10dcc2 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -87,30 +87,22 @@ void psb_gem_unpin(struct gtt_range *gt)
> mutex_unlock(_priv->gtt_mutex);
>  }
>
> -static void psb_gtt_free_range(struct drm_device *dev, struct gtt_range *gt)
> -{
> -   /* Undo the mmap pin if we are destroying the object */
> -   if (gt->mmapping) {
> -   psb_gem_unpin(gt);
> -   gt->mmapping = 0;
> -   }
> -   WARN_ON(gt->in_gart && !gt->stolen);
> -   release_resource(>resource);
> -   kfree(gt);
> -}
> -
>  static vm_fault_t psb_gem_fault(struct vm_fault *vmf);
>
>  static void psb_gem_free_object(struct drm_gem_object *obj)
>  {
> -   struct gtt_range *gtt = to_gtt_range(obj);
> +   struct gtt_range *gt = to_gtt_range(obj);
>
> -   /* Remove the list map if one is present */
> -   drm_gem_free_mmap_offset(obj);
> drm_gem_object_release(obj);
>
> -   /* This must occur last as it frees up the memory of the GEM object */
> -   psb_gtt_free_range(obj->dev, gtt);
> +   /* Undo the mmap pin if we are destroying the object */
> +   if (gt->mmapping)
> +   psb_gem_unpin(gt);
> +
> +   WARN_ON(gt->in_gart && !gt->stolen);
> +
> +   release_resource(>resource);
> +   kfree(gt);
>  }
>
>  static const struct vm_operations_struct psb_gem_vm_ops = {
> @@ -124,59 +116,35 @@ static const struct drm_gem_object_funcs 
> psb_gem_object_funcs = {
> .vm_ops = _gem_vm_ops,
>  };
>
> -static struct gtt_range *psb_gtt_alloc_range(struct drm_device *dev, int len,
> -const char *name, int backed, 
> u32 align)
> -{
> -   struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> -   struct gtt_range *gt;
> -   struct resource *r = dev_priv->gtt_mem;
> -   int ret;
> -   unsigned long start, end;
> -
> -   if (backed) {
> -   /* The start of the GTT is the stolen pages */
> -   start = r->start;
> -   end = r->start + dev_priv->gtt.stolen_size - 1;
> -   } else {
> -   /* The rest we will use for GEM backed objects */
> -   start = r->start + dev_priv->gtt.stolen_size;
> -   end = r->end;
> -   }
> -
> -   gt = kzalloc(sizeof(struct gtt_range), GFP_KERNEL);
> -   if (gt == NULL)
> -   return NULL;
> -   gt->resource.name = name;
> -   gt->stolen = backed;
> -   gt->in_gart = backed;
> -   /* Ensure this is set for non GEM objects */
> -   gt->gem.dev = dev;
> -   ret = allocate_resource(dev_priv->gtt_mem, >resource,
> -   len, start, end, align, NULL, NULL);
> -   if (ret == 0) {
> -   gt->offset = gt->resource.start - r->start;
> -   return gt;
> -   }
> -   kfree(gt);
> -   return NULL;
> -}
> -
>  struct gtt_range *
>  psb_gem_create(struct drm_device *dev, u64 size, const char *name, bool 
> stolen, u32 align)
>  {
> +   struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> struct gtt_range *gt;
> struct drm_gem_object *obj;
> int ret;
>
> size = roundup(size, PAGE_SIZE);
>
> -   gt = psb_gtt_alloc_range(dev, size, name, stolen, align);
> -   if (!gt) {
> -   dev_err(dev->dev, "no memory for %lld byte GEM object\n", 
> size);
> -   return ERR_PTR(-ENOSPC);
> -   }
> +   gt = kzalloc(sizeof(*gt), GFP_KERNEL);
> +   if (!gt)
> +   return ERR_PTR(-ENOMEM);
> obj = >gem;
>
> +   /* GTT resource */
> +
> +   ret = psb_gtt_allocate_resource(dev_priv, >resource, name, size, 
> align, stolen,
> +   >offset);
> +   if (ret)
> +   goto err_kfree;
> +
> +   if (stolen) {
> +   gt->stolen = true;
> +   gt->in_gart = 1;
> +   }
> +
> +   /* GEM object */
> +
> obj->funcs = 

Re: [PATCH 06/10] drm/gma500: Inline psb_gtt_attach_pages() and psb_gtt_detach_pages()

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> psb_gtt_attach_pages() are not GTT functions but deal with the GEM
> object's SHMEM pages. The only callers of psb_gtt_attach_pages() and
> psb_gtt_detach_pages() are the GEM pin helpers. Inline the calls and
> cleanup the resulting code.
>
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/gma500/gem.c | 75 +---
>  1 file changed, 36 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index 369910d0091e..a48d7d5ed026 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -19,53 +19,45 @@
>  #include "gem.h"
>  #include "psb_drv.h"
>
> -static int psb_gtt_attach_pages(struct gtt_range *gt)
> +int psb_gem_pin(struct gtt_range *gt)
>  {
> +   int ret = 0;
> +   struct drm_device *dev = gt->gem.dev;
> +   struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> +   u32 gpu_base = dev_priv->gtt.gatt_start;
> struct page **pages;
> +   unsigned int npages;
>
> -   WARN_ON(gt->pages);
> +   mutex_lock(_priv->gtt_mutex);
> +
> +   if (gt->in_gart || gt->stolen)
> +   goto out; /* already mapped */
>
> pages = drm_gem_get_pages(>gem);
> if (IS_ERR(pages))
> return PTR_ERR(pages);

You're not releasing gtt_mutex here


>
> -   gt->npage = gt->gem.size / PAGE_SIZE;
> -   gt->pages = pages;
> -
> -   return 0;
> -}
> +   npages = gt->gem.size / PAGE_SIZE;
>
> -static void psb_gtt_detach_pages(struct gtt_range *gt)
> -{
> -   drm_gem_put_pages(>gem, gt->pages, true, false);
> -   gt->pages = NULL;
> -}
> +   ret = psb_gtt_insert(dev, gt, 0);
> +   if (ret)
> +   goto err_drm_gem_put_pages;
>
> -int psb_gem_pin(struct gtt_range *gt)
> -{
> -   int ret = 0;
> -   struct drm_device *dev = gt->gem.dev;
> -   struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> -   u32 gpu_base = dev_priv->gtt.gatt_start;
> +   psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu), pages,
> +(gpu_base + gt->offset), npages, 0, 0,
> +PSB_MMU_CACHED_MEMORY);
>
> -   mutex_lock(_priv->gtt_mutex);
> +   gt->npage = npages;
> +   gt->pages = pages;
>
> -   if (gt->in_gart == 0 && gt->stolen == 0) {
> -   ret = psb_gtt_attach_pages(gt);
> -   if (ret < 0)
> -   goto out;
> -   ret = psb_gtt_insert(dev, gt, 0);
> -   if (ret < 0) {
> -   psb_gtt_detach_pages(gt);
> -   goto out;
> -   }
> -   psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu),
> -gt->pages, (gpu_base + gt->offset),
> -gt->npage, 0, 0, PSB_MMU_CACHED_MEMORY);
> -   }
> -   gt->in_gart++;
>  out:
> +   ++gt->in_gart;
> mutex_unlock(_priv->gtt_mutex);
> +
> +   return 0;
> +
> +err_drm_gem_put_pages:
> +   drm_gem_put_pages(>gem, pages, true, false);
> return ret;
>  }
>
> @@ -79,14 +71,19 @@ void psb_gem_unpin(struct gtt_range *gt)
>
> WARN_ON(!gt->in_gart);
>
> -   gt->in_gart--;
> -   if (gt->in_gart == 0 && gt->stolen == 0) {
> -   psb_mmu_remove_pages(psb_mmu_get_default_pd(dev_priv->mmu),
> +   --gt->in_gart;
> +
> +   if (gt->in_gart || gt->stolen)
> +   goto out;
> +
> +   psb_mmu_remove_pages(psb_mmu_get_default_pd(dev_priv->mmu),
>  (gpu_base + gt->offset), gt->npage, 0, 
> 0);
> -   psb_gtt_remove(dev, gt);
> -   psb_gtt_detach_pages(gt);
> -   }
> +   psb_gtt_remove(dev, gt);
>
> +   drm_gem_put_pages(>gem, gt->pages, true, false);
> +   gt->pages = NULL;
> +
> +out:
> mutex_unlock(_priv->gtt_mutex);
>  }
>
> --
> 2.33.0
>


Re: [PATCH 05/10] drm/gma500: Rename psb_gtt_{pin, unpin}() to psb_gem_{pin, unpin}()

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> Rename psb_gtt_pin() to psb_gem_pin() to reflect the semantics of the
> function. Same for psb_gtt_unpin(). No functional changes.

Acked-by: Patrik Jakobsson 


>
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/gma500/gem.c |  8 
>  drivers/gpu/drm/gma500/gem.h |  4 ++--
>  drivers/gpu/drm/gma500/gma_display.c | 12 ++--
>  3 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index 4acab39a583a..369910d0091e 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -41,7 +41,7 @@ static void psb_gtt_detach_pages(struct gtt_range *gt)
> gt->pages = NULL;
>  }
>
> -int psb_gtt_pin(struct gtt_range *gt)
> +int psb_gem_pin(struct gtt_range *gt)
>  {
> int ret = 0;
> struct drm_device *dev = gt->gem.dev;
> @@ -69,7 +69,7 @@ int psb_gtt_pin(struct gtt_range *gt)
> return ret;
>  }
>
> -void psb_gtt_unpin(struct gtt_range *gt)
> +void psb_gem_unpin(struct gtt_range *gt)
>  {
> struct drm_device *dev = gt->gem.dev;
> struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> @@ -94,7 +94,7 @@ static void psb_gtt_free_range(struct drm_device *dev, 
> struct gtt_range *gt)
>  {
> /* Undo the mmap pin if we are destroying the object */
> if (gt->mmapping) {
> -   psb_gtt_unpin(gt);
> +   psb_gem_unpin(gt);
> gt->mmapping = 0;
> }
> WARN_ON(gt->in_gart && !gt->stolen);
> @@ -290,7 +290,7 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
> /* For now the mmap pins the object and it stays pinned. As things
>stand that will do us no harm */
> if (r->mmapping == 0) {
> -   err = psb_gtt_pin(r);
> +   err = psb_gem_pin(r);
> if (err < 0) {
> dev_err(dev->dev, "gma500: pin failed: %d\n", err);
> ret = vmf_error(err);
> diff --git a/drivers/gpu/drm/gma500/gem.h b/drivers/gpu/drm/gma500/gem.h
> index 6b67c58cbed5..21c86df482a6 100644
> --- a/drivers/gpu/drm/gma500/gem.h
> +++ b/drivers/gpu/drm/gma500/gem.h
> @@ -15,7 +15,7 @@ struct drm_device;
>  struct gtt_range *
>  psb_gem_create(struct drm_device *dev, u64 size, const char *name, bool 
> stolen, u32 align);
>
> -int psb_gtt_pin(struct gtt_range *gt);
> -void psb_gtt_unpin(struct gtt_range *gt);
> +int psb_gem_pin(struct gtt_range *gt);
> +void psb_gem_unpin(struct gtt_range *gt);
>
>  #endif
> diff --git a/drivers/gpu/drm/gma500/gma_display.c 
> b/drivers/gpu/drm/gma500/gma_display.c
> index 8c95b50034a5..6d0470b27bc5 100644
> --- a/drivers/gpu/drm/gma500/gma_display.c
> +++ b/drivers/gpu/drm/gma500/gma_display.c
> @@ -75,7 +75,7 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
>
> /* We are displaying this buffer, make sure it is actually loaded
>into the GTT */
> -   ret = psb_gtt_pin(gtt);
> +   ret = psb_gem_pin(gtt);
> if (ret < 0)
> goto gma_pipe_set_base_exit;
> start = gtt->offset;
> @@ -126,7 +126,7 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
>  gma_pipe_cleaner:
> /* If there was a previous display we can now unpin it */
> if (old_fb)
> -   psb_gtt_unpin(to_gtt_range(old_fb->obj[0]));
> +   psb_gem_unpin(to_gtt_range(old_fb->obj[0]));
>
>  gma_pipe_set_base_exit:
> gma_power_end(dev);
> @@ -350,7 +350,7 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
> /* Unpin the old GEM object */
> if (gma_crtc->cursor_obj) {
> gt = to_gtt_range(gma_crtc->cursor_obj);
> -   psb_gtt_unpin(gt);
> +   psb_gem_unpin(gt);
> drm_gem_object_put(gma_crtc->cursor_obj);
> gma_crtc->cursor_obj = NULL;
> }
> @@ -378,7 +378,7 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
> gt = to_gtt_range(obj);
>
> /* Pin the memory into the GTT */
> -   ret = psb_gtt_pin(gt);
> +   ret = psb_gem_pin(gt);
> if (ret) {
> dev_err(dev->dev, "Can not pin down handle 0x%x\n", handle);
> goto unref_cursor;
> @@ -426,7 +426,7 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
> /* unpin the old bo */
> if (gma_crtc->cursor_obj) {
> gt = to_gtt_range(gma_crtc->cursor_obj);
> -   psb_gtt_unpin(gt);
> +   psb_gem_unpin(gt);
> drm_gem_object_put(gma_crtc->cursor_obj);
> }
>
> @@ -490,7 +490,7 @@ void gma_crtc_disable(struct drm_crtc *crtc)
>
> if (crtc->primary->fb) {
> gt = to_gtt_range(crtc->primary->fb->obj[0]);
> -   psb_gtt_unpin(gt);
> +   psb_gem_unpin(gt);
> }

Re: [PATCH 04/10] drm/gma500: Allocate GTT ranges in stolen memory with psb_gem_create()

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> Support private objects for stolen memory in psb_gem_create() and
> convert users to psb_gem_create(). For stolen memory, psb_gem_create()
> now initializes the GEM object via drm_gem_private_object_init().
>
> In the fbdev setup, replace the open-coded initialization of struct
> gtt_range with a call to psb_gem_create(). Use drm_gem_object_put()
> for release.
>
> In the cursor setup, use psb_gem_create() and get a real GEM object.
> Previously the allocated instance of struct gtt_range was only partially
> initialized. Release the cursor GEM object in gma_crtc_destroy(). The
> release was missing from the original code.
>
> With the conversion of all callers to psb_gem_create(), the extern
> declarations of psb_gtt_alloc_range, psb_gtt_free_range and
> psb_gem_object_func are not required any longer. Declare them as
> static inline.
>
> Signed-off-by: Thomas Zimmermann 

Acked-by: Patrik Jakobsson 


> ---
>  drivers/gpu/drm/gma500/framebuffer.c   | 44 ++
>  drivers/gpu/drm/gma500/gem.c   | 22 ++-
>  drivers/gpu/drm/gma500/gem.h   |  5 ---
>  drivers/gpu/drm/gma500/gma_display.c   |  3 ++
>  drivers/gpu/drm/gma500/psb_intel_display.c |  5 +--
>  5 files changed, 29 insertions(+), 50 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/framebuffer.c 
> b/drivers/gpu/drm/gma500/framebuffer.c
> index ce92d11bd20f..3ea6679ccd38 100644
> --- a/drivers/gpu/drm/gma500/framebuffer.c
> +++ b/drivers/gpu/drm/gma500/framebuffer.c
> @@ -224,31 +224,6 @@ static struct drm_framebuffer *psb_framebuffer_create
> return fb;
>  }
>
> -/**
> - * psbfb_alloc -   allocate frame buffer memory
> - * @dev: the DRM device
> - * @aligned_size: space needed
> - *
> - * Allocate the frame buffer. In the usual case we get a GTT range that
> - * is stolen memory backed and life is simple. If there isn't sufficient
> - * we fail as we don't have the virtual mapping space to really vmap it
> - * and the kernel console code can't handle non linear framebuffers.
> - *
> - * Re-address this as and if the framebuffer layer grows this ability.
> - */
> -static struct gtt_range *psbfb_alloc(struct drm_device *dev, int 
> aligned_size)
> -{
> -   struct gtt_range *backing;
> -   /* Begin by trying to use stolen memory backing */
> -   backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1, PAGE_SIZE);
> -   if (backing) {
> -   backing->gem.funcs = _gem_object_funcs;
> -   drm_gem_private_object_init(dev, >gem, aligned_size);
> -   return backing;
> -   }
> -   return NULL;
> -}
> -
>  /**
>   * psbfb_create-   create a framebuffer
>   * @fb_helper: the framebuffer helper
> @@ -268,6 +243,7 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
> int size;
> int ret;
> struct gtt_range *backing;
> +   struct drm_gem_object *obj;
> u32 bpp, depth;
>
> mode_cmd.width = sizes->surface_width;
> @@ -285,24 +261,25 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
> size = ALIGN(size, PAGE_SIZE);
>
> /* Allocate the framebuffer in the GTT with stolen page backing */
> -   backing = psbfb_alloc(dev, size);
> -   if (backing == NULL)
> -   return -ENOMEM;
> +   backing = psb_gem_create(dev, size, "fb", true, PAGE_SIZE);
> +   if (IS_ERR(backing))
> +   return PTR_ERR(backing);
> +   obj = >gem;
>
> memset(dev_priv->vram_addr + backing->offset, 0, size);
>
> info = drm_fb_helper_alloc_fbi(fb_helper);
> if (IS_ERR(info)) {
> ret = PTR_ERR(info);
> -   goto out;
> +   goto err_drm_gem_object_put;
> }
>
> mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
>
> -   fb = psb_framebuffer_create(dev, _cmd, >gem);
> +   fb = psb_framebuffer_create(dev, _cmd, obj);
> if (IS_ERR(fb)) {
> ret = PTR_ERR(fb);
> -   goto out;
> +   goto err_drm_gem_object_put;
> }
>
> fb_helper->fb = fb;
> @@ -333,8 +310,9 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
> dev_dbg(dev->dev, "allocated %dx%d fb\n", fb->width, fb->height);
>
> return 0;
> -out:
> -   psb_gtt_free_range(dev, backing);
> +
> +err_drm_gem_object_put:
> +   drm_gem_object_put(obj);
> return ret;
>  }
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index 8f4bcf9cf912..4acab39a583a 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -90,7 +90,7 @@ void psb_gtt_unpin(struct gtt_range *gt)
> mutex_unlock(_priv->gtt_mutex);
>  }
>
> -void psb_gtt_free_range(struct drm_device *dev, struct gtt_range *gt)
> +static void psb_gtt_free_range(struct drm_device 

Re: [PATCH 03/10] drm/gma500: Reimplement psb_gem_create()

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> Implement psb_gem_create() for general use. Create the GEM handle in
> psb_gem_create_dumb(). Allows to use psb_gem_create() for creating all
> of the GEM objects.
>
> While at it, clean-up drm_gem_dumb_create() to make it more readable.
>
> Signed-off-by: Thomas Zimmermann 

Acked-by: Patrik Jakobsson 


> ---
>  drivers/gpu/drm/gma500/gem.c | 93 ++--
>  drivers/gpu/drm/gma500/gem.h |  4 +-
>  2 files changed, 59 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index ff2c1d64689e..8f4bcf9cf912 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -164,45 +164,36 @@ struct gtt_range *psb_gtt_alloc_range(struct drm_device 
> *dev, int len,
> return NULL;
>  }
>
> -int psb_gem_create(struct drm_file *file, struct drm_device *dev, u64 size,
> -  u32 *handlep, int stolen, u32 align)
> +struct gtt_range *
> +psb_gem_create(struct drm_device *dev, u64 size, const char *name, bool 
> stolen, u32 align)
>  {
> -   struct gtt_range *r;
> +   struct gtt_range *gt;
> +   struct drm_gem_object *obj;
> int ret;
> -   u32 handle;
>
> size = roundup(size, PAGE_SIZE);
>
> -   /* Allocate our object - for now a direct gtt range which is not
> -  stolen memory backed */
> -   r = psb_gtt_alloc_range(dev, size, "gem", 0, PAGE_SIZE);
> -   if (r == NULL) {
> +   gt = psb_gtt_alloc_range(dev, size, name, stolen, align);
> +   if (!gt) {
> dev_err(dev->dev, "no memory for %lld byte GEM object\n", 
> size);
> -   return -ENOSPC;
> +   return ERR_PTR(-ENOSPC);
> }
> -   r->gem.funcs = _gem_object_funcs;
> -   /* Initialize the extra goodies GEM needs to do all the hard work */
> -   if (drm_gem_object_init(dev, >gem, size) != 0) {
> -   psb_gtt_free_range(dev, r);
> -   /* GEM doesn't give an error code so use -ENOMEM */
> -   dev_err(dev->dev, "GEM init failed for %lld\n", size);
> -   return -ENOMEM;
> -   }
> -   /* Limit the object to 32bit mappings */
> -   mapping_set_gfp_mask(r->gem.filp->f_mapping, GFP_KERNEL | 
> __GFP_DMA32);
> -   /* Give the object a handle so we can carry it more easily */
> -   ret = drm_gem_handle_create(file, >gem, );
> -   if (ret) {
> -   dev_err(dev->dev, "GEM handle failed for %p, %lld\n",
> -   >gem, size);
> -   drm_gem_object_release(>gem);
> -   psb_gtt_free_range(dev, r);
> -   return ret;
> -   }
> -   /* We have the initial and handle reference but need only one now */
> -   drm_gem_object_put(>gem);
> -   *handlep = handle;
> -   return 0;
> +   obj = >gem;
> +
> +   obj->funcs = _gem_object_funcs;
> +
> +   ret = drm_gem_object_init(dev, obj, size);
> +   if (ret)
> +   goto err_psb_gtt_free_range;
> +
> +   /* Limit the object to 32-bit mappings */
> +   mapping_set_gfp_mask(obj->filp->f_mapping, GFP_KERNEL | __GFP_DMA32);
> +
> +   return gt;
> +
> +err_psb_gtt_free_range:
> +   psb_gtt_free_range(dev, gt);
> +   return ERR_PTR(ret);
>  }
>
>  /**
> @@ -218,10 +209,40 @@ int psb_gem_create(struct drm_file *file, struct 
> drm_device *dev, u64 size,
>  int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
> struct drm_mode_create_dumb *args)
>  {
> -   args->pitch = ALIGN(args->width * ((args->bpp + 7) / 8), 64);
> -   args->size = args->pitch * args->height;
> -   return psb_gem_create(file, dev, args->size, >handle, 0,
> - PAGE_SIZE);
> +   size_t pitch, size;
> +   struct gtt_range *gt;
> +   struct drm_gem_object *obj;
> +   u32 handle;
> +   int ret;
> +
> +   pitch = args->width * DIV_ROUND_UP(args->bpp, 8);
> +   pitch = ALIGN(pitch, 64);
> +
> +   size = pitch * args->height;
> +   size = roundup(size, PAGE_SIZE);
> +   if (!size)
> +   return -EINVAL;
> +
> +   gt = psb_gem_create(dev, size, "gem", false, PAGE_SIZE);
> +   if (IS_ERR(gt))
> +   return PTR_ERR(gt);
> +   obj = >gem;
> +
> +   ret = drm_gem_handle_create(file, obj, );
> +   if (ret)
> +   goto err_drm_gem_object_put;
> +
> +   drm_gem_object_put(obj);
> +
> +   args->pitch = pitch;
> +   args->size = size;
> +   args->handle = handle;
> +
> +   return 0;
> +
> +err_drm_gem_object_put:
> +   drm_gem_object_put(obj);
> +   return ret;
>  }
>
>  /**
> diff --git a/drivers/gpu/drm/gma500/gem.h b/drivers/gpu/drm/gma500/gem.h
> index 275494aedd4c..ad76127dc719 100644
> --- a/drivers/gpu/drm/gma500/gem.h
> +++ b/drivers/gpu/drm/gma500/gem.h
> @@ -14,8 

Re: [PATCH 02/10] drm/gma500: Use to_gtt_range() everywhere

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> Convert upcasts from struct drm_gem_object to struct gtt_range to
> to_gtt_range(). Some places used container_of() directly.
>
> Signed-off-by: Thomas Zimmermann 

Acked-by: Patrik Jakobsson 


> ---
>  drivers/gpu/drm/gma500/gem.c | 4 ++--
>  drivers/gpu/drm/gma500/gma_display.c | 7 +++
>  2 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index 734bcb7a80c8..ff2c1d64689e 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -106,7 +106,7 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf);
>
>  static void psb_gem_free_object(struct drm_gem_object *obj)
>  {
> -   struct gtt_range *gtt = container_of(obj, struct gtt_range, gem);
> +   struct gtt_range *gtt = to_gtt_range(obj);
>
> /* Remove the list map if one is present */
> drm_gem_free_mmap_offset(obj);
> @@ -256,7 +256,7 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
> dev = obj->dev;
> dev_priv = to_drm_psb_private(dev);
>
> -   r = container_of(obj, struct gtt_range, gem);   /* Get the gtt range 
> */
> +   r = to_gtt_range(obj);
>
> /* Make sure we don't parallel update on a fault, nor move or remove
>something from beneath our feet */
> diff --git a/drivers/gpu/drm/gma500/gma_display.c 
> b/drivers/gpu/drm/gma500/gma_display.c
> index ecf8153416ac..8285358fac01 100644
> --- a/drivers/gpu/drm/gma500/gma_display.c
> +++ b/drivers/gpu/drm/gma500/gma_display.c
> @@ -349,8 +349,7 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
>
> /* Unpin the old GEM object */
> if (gma_crtc->cursor_obj) {
> -   gt = container_of(gma_crtc->cursor_obj,
> - struct gtt_range, gem);
> +   gt = to_gtt_range(gma_crtc->cursor_obj);
> psb_gtt_unpin(gt);
> drm_gem_object_put(gma_crtc->cursor_obj);
> gma_crtc->cursor_obj = NULL;
> @@ -376,7 +375,7 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
> goto unref_cursor;
> }
>
> -   gt = container_of(obj, struct gtt_range, gem);
> +   gt = to_gtt_range(obj);
>
> /* Pin the memory into the GTT */
> ret = psb_gtt_pin(gt);
> @@ -426,7 +425,7 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
>
> /* unpin the old bo */
> if (gma_crtc->cursor_obj) {
> -   gt = container_of(gma_crtc->cursor_obj, struct gtt_range, 
> gem);
> +   gt = to_gtt_range(gma_crtc->cursor_obj);
> psb_gtt_unpin(gt);
> drm_gem_object_put(gma_crtc->cursor_obj);
> }
> --
> 2.33.0
>


Re: [PATCH 01/10] drm/gma500: Move helpers for struct gtt_range from gtt.c to gem.c

2021-10-02 Thread Patrik Jakobsson
On Tue, Sep 28, 2021 at 10:44 AM Thomas Zimmermann  wrote:
>
> Allocation and pinning helpers for struct gtt_range are GEM functions,
> so move them to gem.c. No functional changes.
>
> Signed-off-by: Thomas Zimmermann 
> ---
>  drivers/gpu/drm/gma500/framebuffer.c   |   1 -
>  drivers/gpu/drm/gma500/gem.c   | 133 +--
>  drivers/gpu/drm/gma500/gem.h   |   8 +
>  drivers/gpu/drm/gma500/gma_display.c   |   1 +
>  drivers/gpu/drm/gma500/gtt.c   | 190 +
>  drivers/gpu/drm/gma500/gtt.h   |  11 +-
>  drivers/gpu/drm/gma500/psb_intel_display.c |   1 +
>  7 files changed, 136 insertions(+), 209 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/framebuffer.c 
> b/drivers/gpu/drm/gma500/framebuffer.c
> index 321e416489a9..ce92d11bd20f 100644
> --- a/drivers/gpu/drm/gma500/framebuffer.c
> +++ b/drivers/gpu/drm/gma500/framebuffer.c
> @@ -25,7 +25,6 @@
>
>  #include "framebuffer.h"
>  #include "gem.h"
> -#include "gtt.h"
>  #include "psb_drv.h"
>  #include "psb_intel_drv.h"
>  #include "psb_intel_reg.h"
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index 5ae54c9d2819..734bcb7a80c8 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -19,6 +19,89 @@
>  #include "gem.h"
>  #include "psb_drv.h"
>
> +static int psb_gtt_attach_pages(struct gtt_range *gt)
> +{
> +   struct page **pages;
> +
> +   WARN_ON(gt->pages);
> +
> +   pages = drm_gem_get_pages(>gem);
> +   if (IS_ERR(pages))
> +   return PTR_ERR(pages);
> +
> +   gt->npage = gt->gem.size / PAGE_SIZE;
> +   gt->pages = pages;
> +
> +   return 0;
> +}
> +
> +static void psb_gtt_detach_pages(struct gtt_range *gt)
> +{
> +   drm_gem_put_pages(>gem, gt->pages, true, false);
> +   gt->pages = NULL;
> +}
> +
> +int psb_gtt_pin(struct gtt_range *gt)
> +{
> +   int ret = 0;
> +   struct drm_device *dev = gt->gem.dev;
> +   struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> +   u32 gpu_base = dev_priv->gtt.gatt_start;
> +
> +   mutex_lock(_priv->gtt_mutex);
> +
> +   if (gt->in_gart == 0 && gt->stolen == 0) {
> +   ret = psb_gtt_attach_pages(gt);
> +   if (ret < 0)
> +   goto out;
> +   ret = psb_gtt_insert(dev, gt, 0);
> +   if (ret < 0) {
> +   psb_gtt_detach_pages(gt);
> +   goto out;
> +   }
> +   psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu),
> +gt->pages, (gpu_base + gt->offset),
> +gt->npage, 0, 0, PSB_MMU_CACHED_MEMORY);
> +   }
> +   gt->in_gart++;
> +out:
> +   mutex_unlock(_priv->gtt_mutex);
> +   return ret;
> +}
> +
> +void psb_gtt_unpin(struct gtt_range *gt)
> +{
> +   struct drm_device *dev = gt->gem.dev;
> +   struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> +   u32 gpu_base = dev_priv->gtt.gatt_start;
> +
> +   mutex_lock(_priv->gtt_mutex);
> +
> +   WARN_ON(!gt->in_gart);
> +
> +   gt->in_gart--;
> +   if (gt->in_gart == 0 && gt->stolen == 0) {
> +   psb_mmu_remove_pages(psb_mmu_get_default_pd(dev_priv->mmu),
> +(gpu_base + gt->offset), gt->npage, 0, 
> 0);
> +   psb_gtt_remove(dev, gt);
> +   psb_gtt_detach_pages(gt);
> +   }
> +
> +   mutex_unlock(_priv->gtt_mutex);
> +}
> +
> +void psb_gtt_free_range(struct drm_device *dev, struct gtt_range *gt)
> +{
> +   /* Undo the mmap pin if we are destroying the object */
> +   if (gt->mmapping) {
> +   psb_gtt_unpin(gt);
> +   gt->mmapping = 0;
> +   }
> +   WARN_ON(gt->in_gart && !gt->stolen);
> +   release_resource(>resource);
> +   kfree(gt);
> +}
> +
>  static vm_fault_t psb_gem_fault(struct vm_fault *vmf);
>
>  static void psb_gem_free_object(struct drm_gem_object *obj)
> @@ -44,19 +127,43 @@ const struct drm_gem_object_funcs psb_gem_object_funcs = 
> {
> .vm_ops = _gem_vm_ops,
>  };
>
> -/**
> - * psb_gem_create  -   create a mappable object
> - * @file: the DRM file of the client
> - * @dev: our device
> - * @size: the size requested
> - * @handlep: returned handle (opaque number)
> - * @stolen: unused
> - * @align: unused
> - *
> - * Create a GEM object, fill in the boilerplate and attach a handle to
> - * it so that userspace can speak about it. This does the core work
> - * for the various methods that do/will create GEM objects for things
> - */
> +struct gtt_range *psb_gtt_alloc_range(struct drm_device *dev, int len,
> + const char *name, int backed, u32 align)
> +{
> +   struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
> +   struct gtt_range *gt;
> +   

Re: [PATCH v13 06/35] clk: tegra: Support runtime PM and power domain

2021-10-02 Thread Dmitry Osipenko
01.10.2021 15:32, Ulf Hansson пишет:
>> +static __maybe_unused int tegra_clock_pm_suspend(struct device *dev)
>> +{
>> +   struct tegra_clk_device *clk_dev = dev_get_drvdata(dev);
>> +
>> +   /*
>> +* Power management of the clock is entangled with the Tegra PMC
>> +* GENPD because PMC driver enables/disables clocks for toggling
>> +* of the PD's on/off state.
>> +*
>> +* The PMC GENPD is resumed in NOIRQ phase, before RPM of the clocks
>> +* becomes available, hence PMC can't use clocks at the early resume
>> +* phase if RPM is involved. For example when 3d clock is enabled,
>> +* it may enable the parent PLL clock that needs to be RPM-resumed.
>> +*
>> +* Secondly, the PLL clocks may be enabled by the low level suspend
>> +* code, so we need to assume that PLL is in enabled state during
>> +* suspend.
>> +*
>> +* We will keep PLLs and system clock resumed during suspend time.
>> +* All PLLs on all SoCs are low power and system clock is always-on,
>> +* so practically not much is changed here.
>> +*/
>> +
>> +   return clk_prepare(clk_dev->hw->clk);
> I am trying to understand, more exactly, what you intend to achieve
> with the clk_prepare() here. It looks a bit weird, to me. Can you try
> to elaborate a bit more on the use case?

The Tegra GENPD driver enable/disable clocks when domain is turned on.
This can't be done during early system resume, when domains are getting
turned on by the drivers core, because when clock is enabled, it's
getting prepared (RPM-resumed) and this preparation fails because
performance state of the clock goes up and it doesn't work during the
early resume time since I2C, which applies the state to hardware, is
suspended and can't work at that early time.

Secondly, Tegra has arch-specific low level assembly which touches
clocks during last phase of system suspend and in the beginning of
resume. Hence, clocks should stay prepared during suspend just because
technically clock should be prepared before it can be enabled.

> Is this rather about making sure that the clock's corresponding PM
> domain stays powered on during system suspend? In that case, I think
> there may be an alternative option
> 

This is not about domain staying powered on, this is about keeping the
performance state of the domain high during suspend.


[PATCH] drm/panel-simple: Add Vivax TPC-9150 panel v5

2021-10-02 Thread Nikola Pavlica
The model and make of the LCD panel of the Vivax TPC-9150 is unknown,
hence the panel settings that were retrieved with a FEX dump are named
after the device NOT the actual panel.

The LCD in question is a 50 pin MISO TFT LCD panel of the resolution
1024x600 used by the aforementioned device.

Version 2, as Thierry kindly suggested that I fix the order in which the
panel was ordered compared to others.

Version 3, filling in the required info suggested by Sam. Plus some
factual issues that I've corrected myself (tested working)

Version 4, rearranged the display parameters and fix invalid bit format
issue. (Thanks Sam)

Version 5, referred to FEX file instead of manual debugging for
information.

NOTE: Seperate dt-binding patch has been sent to THAT mailing list. So
that's why they're NOT included here. Advise freely if that's not how
you're supposed to do it.

Thanks,
Nikola

Signed-off-by: Nikola Pavlica 
---
 drivers/gpu/drm/panel/panel-simple.c | 29 
 1 file changed, 29 insertions(+)

diff --git a/drivers/gpu/drm/panel/panel-simple.c 
b/drivers/gpu/drm/panel/panel-simple.c
index 9b6c4e6c3..680fd3f72 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -4363,6 +4363,32 @@ static const struct panel_desc urt_umsh_8596md_parallel 
= {
.bus_format = MEDIA_BUS_FMT_RGB666_1X18,
 };

+static const struct drm_display_mode vivax_tpc9150_panel_mode = {
+   .clock = 6,
+   .hdisplay = 1024,
+   .hsync_start = 1024 + 160,
+   .hsync_end = 1024 + 160 + 100,
+   .htotal = 1024 + 160 + 100 + 60,
+   .vdisplay = 600,
+   .vsync_start = 600 + 12,
+   .vsync_end = 600 + 12 + 10,
+   .vtotal = 600 + 12 + 10 + 13,
+};
+
+static const struct panel_desc vivax_tpc9150_panel = {
+   .modes = _tpc9150_panel_mode,
+   .num_modes = 1,
+   .bpc = 6,
+   .size = {
+   .width = 200,
+   .height = 115,
+   },
+   .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
+   .bus_flags = DRM_BUS_FLAG_DE_HIGH,
+   .connector_type = DRM_MODE_CONNECTOR_LVDS,
+};
+
+
 static const struct drm_display_mode vl050_8048nt_c01_mode = {
.clock = 3,
.hdisplay = 800,
@@ -4891,6 +4917,9 @@ static const struct of_device_id platform_of_match[] = {
}, {
.compatible = "urt,umsh-8596md-20t",
.data = _umsh_8596md_parallel,
+   }, {
+   .compatible = "vivax,tpc9150-panel",
+   .data = _tpc9150_panel,
}, {
.compatible = "vxt,vl050-8048nt-c01",
.data = _8048nt_c01,
--
2.33.0



Re: [PATCH] drm/msm: delete conversion from bool value to bool return

2021-10-02 Thread Dmitry Baryshkov

On 02/11/2020 15:50, Bernard Zhao wrote:

Delete the conversion from bool value to bool function return.

Signed-off-by: Bernard Zhao 


Reviewed-by: Dmitry Baryshkov 


---
  drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c
index 8493d68ad841..411222f4cd6f 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c
@@ -37,7 +37,7 @@
  
  static bool dpu_encoder_phys_cmd_is_master(struct dpu_encoder_phys *phys_enc)

  {
-   return (phys_enc->split_role != ENC_ROLE_SLAVE) ? true : false;
+   return (phys_enc->split_role != ENC_ROLE_SLAVE);
  }
  
  static bool dpu_encoder_phys_cmd_mode_fixup(





--
With best wishes
Dmitry


Re: [PATCH] drm/msm: dsi: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare

2021-10-02 Thread Dmitry Baryshkov

On 31/12/2020 12:56, Xu Wang wrote:

Because clk_prepare_enable() and clk_disable_unprepare() already checked
NULL clock parameter, so the additional checks are unnecessary, just
remove them.

Signed-off-by: Xu Wang 


Reviewed-by: Dmitry Baryshkov 


---
  drivers/gpu/drm/msm/dsi/dsi_host.c | 15 ++-
  1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index ab281cba0f08..e7af90f045bf 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -565,13 +565,11 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host)
goto pixel_clk_err;
}
  
-	if (msm_host->byte_intf_clk) {

-   ret = clk_prepare_enable(msm_host->byte_intf_clk);
-   if (ret) {
-   pr_err("%s: Failed to enable byte intf clk\n",
-  __func__);
-   goto byte_intf_clk_err;
-   }
+   ret = clk_prepare_enable(msm_host->byte_intf_clk);
+   if (ret) {
+   pr_err("%s: Failed to enable byte intf clk\n",
+  __func__);
+   goto byte_intf_clk_err;
}
  
  	return 0;

@@ -667,8 +665,7 @@ void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host)
dev_pm_opp_set_rate(_host->pdev->dev, 0);
clk_disable_unprepare(msm_host->esc_clk);
clk_disable_unprepare(msm_host->pixel_clk);
-   if (msm_host->byte_intf_clk)
-   clk_disable_unprepare(msm_host->byte_intf_clk);
+   clk_disable_unprepare(msm_host->byte_intf_clk);
clk_disable_unprepare(msm_host->byte_clk);
  }
  




--
With best wishes
Dmitry


Re: [PATCH] drm/msm/mdp5: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare

2021-10-02 Thread Dmitry Baryshkov

On 31/12/2020 12:49, Xu Wang wrote:

Because clk_prepare_enable() and clk_disable_unprepare() already checked
NULL clock parameter, so the additional checks are unnecessary, just
remove them.

Signed-off-by: Xu Wang 


Reviewed-by: Dmitry Baryshkov 


---
  drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c  | 18 ++
  drivers/gpu/drm/msm/disp/mdp5/mdp5_mdss.c | 12 
  2 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c 
b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
index 15aed45022bc..8d373d2ffd51 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
@@ -303,15 +303,12 @@ static int mdp5_disable(struct mdp5_kms *mdp5_kms)
mdp5_kms->enable_count--;
WARN_ON(mdp5_kms->enable_count < 0);
  
-	if (mdp5_kms->tbu_rt_clk)

-   clk_disable_unprepare(mdp5_kms->tbu_rt_clk);
-   if (mdp5_kms->tbu_clk)
-   clk_disable_unprepare(mdp5_kms->tbu_clk);
+   clk_disable_unprepare(mdp5_kms->tbu_rt_clk);
+   clk_disable_unprepare(mdp5_kms->tbu_clk);
clk_disable_unprepare(mdp5_kms->ahb_clk);
clk_disable_unprepare(mdp5_kms->axi_clk);
clk_disable_unprepare(mdp5_kms->core_clk);
-   if (mdp5_kms->lut_clk)
-   clk_disable_unprepare(mdp5_kms->lut_clk);
+   clk_disable_unprepare(mdp5_kms->lut_clk);
  
  	return 0;

  }
@@ -325,12 +322,9 @@ static int mdp5_enable(struct mdp5_kms *mdp5_kms)
clk_prepare_enable(mdp5_kms->ahb_clk);
clk_prepare_enable(mdp5_kms->axi_clk);
clk_prepare_enable(mdp5_kms->core_clk);
-   if (mdp5_kms->lut_clk)
-   clk_prepare_enable(mdp5_kms->lut_clk);
-   if (mdp5_kms->tbu_clk)
-   clk_prepare_enable(mdp5_kms->tbu_clk);
-   if (mdp5_kms->tbu_rt_clk)
-   clk_prepare_enable(mdp5_kms->tbu_rt_clk);
+   clk_prepare_enable(mdp5_kms->lut_clk);
+   clk_prepare_enable(mdp5_kms->tbu_clk);
+   clk_prepare_enable(mdp5_kms->tbu_rt_clk);
  
  	return 0;

  }
diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_mdss.c 
b/drivers/gpu/drm/msm/disp/mdp5/mdp5_mdss.c
index 09bd46ad820b..02c6c4b68c68 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_mdss.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_mdss.c
@@ -137,10 +137,8 @@ static int mdp5_mdss_enable(struct msm_mdss *mdss)
DBG("");
  
  	clk_prepare_enable(mdp5_mdss->ahb_clk);

-   if (mdp5_mdss->axi_clk)
-   clk_prepare_enable(mdp5_mdss->axi_clk);
-   if (mdp5_mdss->vsync_clk)
-   clk_prepare_enable(mdp5_mdss->vsync_clk);
+   clk_prepare_enable(mdp5_mdss->axi_clk);
+   clk_prepare_enable(mdp5_mdss->vsync_clk);
  
  	return 0;

  }
@@ -150,10 +148,8 @@ static int mdp5_mdss_disable(struct msm_mdss *mdss)
struct mdp5_mdss *mdp5_mdss = to_mdp5_mdss(mdss);
DBG("");
  
-	if (mdp5_mdss->vsync_clk)

-   clk_disable_unprepare(mdp5_mdss->vsync_clk);
-   if (mdp5_mdss->axi_clk)
-   clk_disable_unprepare(mdp5_mdss->axi_clk);
+   clk_disable_unprepare(mdp5_mdss->vsync_clk);
+   clk_disable_unprepare(mdp5_mdss->axi_clk);
clk_disable_unprepare(mdp5_mdss->ahb_clk);
  
  	return 0;





--
With best wishes
Dmitry


Re: [PATCH] drm/msm/mdp4: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare

2021-10-02 Thread Dmitry Baryshkov

On 31/12/2020 12:41, Xu Wang wrote:

Because clk_prepare_enable() and clk_disable_unprepare() already checked
NULL clock parameter, so the additional checks are unnecessary, just
remove them.

Signed-off-by: Xu Wang 


Reviewed-by: Dmitry Baryshkov 


---
  drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 18 ++
  1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c 
b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
index 3d729270bde1..696a22d571ad 100644
--- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
+++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
@@ -207,12 +207,9 @@ int mdp4_disable(struct mdp4_kms *mdp4_kms)
DBG("");
  
  	clk_disable_unprepare(mdp4_kms->clk);

-   if (mdp4_kms->pclk)
-   clk_disable_unprepare(mdp4_kms->pclk);
-   if (mdp4_kms->lut_clk)
-   clk_disable_unprepare(mdp4_kms->lut_clk);
-   if (mdp4_kms->axi_clk)
-   clk_disable_unprepare(mdp4_kms->axi_clk);
+   clk_disable_unprepare(mdp4_kms->pclk);
+   clk_disable_unprepare(mdp4_kms->lut_clk);
+   clk_disable_unprepare(mdp4_kms->axi_clk);
  
  	return 0;

  }
@@ -222,12 +219,9 @@ int mdp4_enable(struct mdp4_kms *mdp4_kms)
DBG("");
  
  	clk_prepare_enable(mdp4_kms->clk);

-   if (mdp4_kms->pclk)
-   clk_prepare_enable(mdp4_kms->pclk);
-   if (mdp4_kms->lut_clk)
-   clk_prepare_enable(mdp4_kms->lut_clk);
-   if (mdp4_kms->axi_clk)
-   clk_prepare_enable(mdp4_kms->axi_clk);
+   clk_prepare_enable(mdp4_kms->pclk);
+   clk_prepare_enable(mdp4_kms->lut_clk);
+   clk_prepare_enable(mdp4_kms->axi_clk);
  
  	return 0;

  }




--
With best wishes
Dmitry


[PATCH] drm/msm/a6xx: correct cx_debugbus_read arguments

2021-10-02 Thread Dmitry Baryshkov
First argument of cx_debugbus_read() should be 'void __iomem *' rather
than 'void * __iomem' to make sparse happy.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c 
b/drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c
index e8f65cd8eca6..7501849ed15d 100644
--- a/drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c
+++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu_state.c
@@ -180,7 +180,7 @@ static int debugbus_read(struct msm_gpu *gpu, u32 block, 
u32 offset,
msm_readl((ptr) + ((offset) << 2))
 
 /* read a value from the CX debug bus */
-static int cx_debugbus_read(void *__iomem cxdbg, u32 block, u32 offset,
+static int cx_debugbus_read(void __iomem *cxdbg, u32 block, u32 offset,
u32 *data)
 {
u32 reg = A6XX_CX_DBGC_CFG_DBGBUS_SEL_A_PING_INDEX(offset) |
-- 
2.33.0



Re: [Intel-gfx] [PATCH v2 00/17] drm: cleanup: Use DRM_MODESET_LOCK_ALL_* helpers where possible

2021-10-02 Thread Fernando Ramos
On 21/10/02 09:13AM, Fernando Ramos wrote:
> On 21/10/02 05:30AM, Ville Syrjälä wrote:
> > On Sat, Oct 02, 2021 at 01:05:47AM +0300, Ville Syrjälä wrote:
> > > On Fri, Oct 01, 2021 at 04:48:15PM -0400, Sean Paul wrote:
> > > > On Fri, Oct 01, 2021 at 10:00:50PM +0300, Ville Syrjälä wrote:
> > > > > On Fri, Oct 01, 2021 at 02:36:55PM -0400, Sean Paul wrote:
> > > > > > 
> > > > > > Thank you for revising, Fernando! I've pushed the set to 
> > > > > > drm-misc-next (along
> > > > > > with the necessary drm-tip conflict resolutions).
> > > > > 
> > > > > Ugh. Did anyone actually review the locking changes this does?
> > > > > I shot the previous i915 stuff down because the commit messages
> > > > > did not address any of it.
> > > > 
> > > > I reviewed the set on 9/17, I didn't see your feedback on that thread.
> > > 
> > > It was much earlir than that.
> > > https://lists.freedesktop.org/archives/dri-devel/2021-June/313193.html

Sorry, I'm new to this and it did not occur to me to search for similar patches
in the mailing list archives in case there were additional comments that applied
to my change set.

In case I had done that I would have found that, as you mentioned, you had
already raised two issues back in June:

On Tue, Jun 29, 2021, Ville Syrjälä wrote:
>
> That looks wrong. You're using a private ctx here, but still
> passing dev->mode_config.acquire_ctx to the lower level stuff.
> 
> Also DRM_MODESET_LOCK_ALL_{BEGIN,END}() do not seem to be
> equivalent to drm_modeset_{lock,unlock}_all() when it comes to 
> mode_config.mutex. So would need a proper review whether we
> actually need that lock or not.

The first one was pointing out the same error I would later repeat in my patch
series (ups).

After further inspection of the code it looks to me that changing this:

intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);

...into this:

intel_modeset_setup_hw_state(dev, );

...would be enough.

Why? The only difference between the old drm_modeset_{lock,unlock}_all()
functions and the new DRM_MODESET_LOCK_ALL_{BEGIN,END}() macros is that the
former use a global context stored in dev->mode_config.acquire_ctx while the
latter depend on a user provided one (typically in the stack).

In the old (working) code the global context structure is freed in
drm_modeset_unlock_all() thus we are sure no one is holding a reference to it at
that point. This means that as long as no one accesses the global
dev->mode_config.acquire_ctx context in the block that runs between lock/BEGIN
and unlock/END, the code should be equivalent before and after my changes.

In fact, now that my patch series removes the drm_modeset_{lock,unlock}_all()
functions, the acquire_ctx field of the drm_mode_config structure should be
deleted:

/**
 * @acquire_ctx:
 *
 * Global implicit acquire context used by atomic drivers for legacy
 * IOCTLs. Deprecated, since implicit locking contexts make it
 * impossible to use driver-private  drm_modeset_lock. Users of
 * this must hold @mutex.
 */
struct drm_modeset_acquire_ctx *acquire_ctx;

If I had done that (ie. removing this field) I would have detected the problem
when compiling.

There is another place (in the amdgpu driver) where this field is still being
referenced, but before I investigate that I would like to know if you agree that
this is a good path to follow.

Regarding the second issue you raised...

> Also DRM_MODESET_LOCK_ALL_{BEGIN,END}() do not seem to be
> equivalent to drm_modeset_{lock,unlock}_all() when it comes to 
> mode_config.mutex. So would need a proper review whether we
> actually need that lock or not.

...the only difference regarding mode_config.mutex I see is that in the new
macros the mutex is locked only under this condition:

if (!drm_drv_uses_atomic_modeset(dev))

...which seems reasonable, right? Is this what you were referring to or is it
something else?

Please let me know what you think.

Thanks!





Re: Handling DRM master transitions cooperatively

2021-10-02 Thread Hans de Goede
Hi,

On 10/1/21 6:33 PM, Simon Ser wrote:
> On Wednesday, September 22nd, 2021 at 11:21, Hans de Goede 
>  wrote:
> 
>> I would be happy to work on the plymouth side of this, so that we
>> have at least one consumer of such a flag lined up for merging.
> 
> Do you have plans to work on the kernel side part of this?

No I don't have any plans to work on the kernel side of this.

> If so, feel free to
> CC me for a review. If not, let me know if you'd like to switch roles, I could
> work on a patch.

I would be happy to review any kernel patches for this
(together with adding support to plymouth for this).

Regards,

Hans



Re: [BUG 5.15-rc3] kernel BUG at drivers/gpu/drm/i915/i915_sw_fence.c:245!

2021-10-02 Thread Linus Torvalds
On Sat, Oct 2, 2021 at 5:17 AM Steven Rostedt  wrote:
>
> On Sat, 2 Oct 2021 03:17:29 -0700 (PDT)
> Hugh Dickins  wrote:
>
> > Yes (though bisection doesn't work right on this one): the fix
>
> Interesting, as it appeared to be very reliable. But I didn't do the
> "try before / after" on the patch.

Well, even the before/after might well have worked, since the problem
depended on how that sw_fence_dummy_notify() function ended up
aligned. So random unrelated changes could re-align it just by
mistake.

Patch applied directly.

I'd also like to point out how that BUG_ON() actually made things
worse, and made this harder to debug. If it had been a WARN_ON_ONCE(),
this would presumably not even have needed bisecting, it would have
been obvious.

BUG_ON() really is pretty much *always* the wrong thing to do. It
onl;y results in problems being harder to see because you end up with
a dead machine and the message is often hidden.

  Linus


[PATCH 06/10] platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey() helper

2021-10-02 Thread Hans de Goede
Factor the extended hotkey handling out of hotkey_notify_hotkey() and
into a new hotkey_notify_extended_hotkey() helper.

This is a preparation patch for adding support the privacy-screen hotkey
toggle (which needs some special handling, it should NOT send an evdev
key-event to userspace...).

Reviewed-by: Emil Velikov 
Reviewed-by: Lyude Paul 
Signed-off-by: Hans de Goede 
---
 drivers/platform/x86/thinkpad_acpi.c | 30 ++--
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c 
b/drivers/platform/x86/thinkpad_acpi.c
index 50ff04c84650..83c88a8ebaf2 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3885,6 +3885,24 @@ static bool 
adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
}
 }
 
+static bool hotkey_notify_extended_hotkey(const u32 hkey)
+{
+   unsigned int scancode;
+
+   /* Extended keycodes start at 0x300 and our offset into the map
+* TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
+* will be positive, but might not be in the correct range.
+*/
+   scancode = (hkey & 0xfff) - (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
+   if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
+   scancode < TPACPI_HOTKEY_MAP_LEN) {
+   tpacpi_input_send_key(scancode);
+   return true;
+   }
+
+   return false;
+}
+
 static bool hotkey_notify_hotkey(const u32 hkey,
 bool *send_acpi_ev,
 bool *ignore_acpi_ev)
@@ -3919,17 +3937,7 @@ static bool hotkey_notify_hotkey(const u32 hkey,
return adaptive_keyboard_hotkey_notify_hotkey(scancode);
 
case 3:
-   /* Extended keycodes start at 0x300 and our offset into the map
-* TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
-* will be positive, but might not be in the correct range.
-*/
-   scancode -= (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
-   if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
-   scancode < TPACPI_HOTKEY_MAP_LEN) {
-   tpacpi_input_send_key(scancode);
-   return true;
-   }
-   break;
+   return hotkey_notify_extended_hotkey(hkey);
}
 
return false;
-- 
2.31.1



[PATCH 08/10] platform/x86: thinkpad_acpi: Register a privacy-screen device

2021-10-02 Thread Hans de Goede
Register a privacy-screen device on laptops with a privacy-screen,
this exports the PrivacyGuard features to user-space using a
standardized vendor-agnostic sysfs interface. Note the sysfs interface
is read-only.

Registering a privacy-screen device with the new privacy-screen class
code will also allow the GPU driver to get a handle to it and export
the privacy-screen setting as a property on the DRM connector object
for the LCD panel. This DRM connector property is a new standardized
interface which all user-space code should use to query and control
the privacy-screen.

Reviewed-by: Emil Velikov 
Reviewed-by: Lyude Paul 
Signed-off-by: Hans de Goede 
---
Changes in v3:
- On receiving a TP_HKEY_EV_PRIVACYGUARD_TOGGLE event only call
  drm_privacy_screen_call_notifier_chain() if the privacy-screen state
  has actually changed

Changes in v2:
- Make the new lcdshadow_set_sw_state, lcdshadow_get_hw_state and
  lcdshadow_ops symbols static
- Update state and call drm_privacy_screen_call_notifier_chain()
  when the state is changed by pressing the Fn + D hotkey combo
---
 drivers/platform/x86/Kconfig |  2 +
 drivers/platform/x86/thinkpad_acpi.c | 97 +---
 2 files changed, 74 insertions(+), 25 deletions(-)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index e21ea3d23e6f..20208207e366 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -501,7 +501,9 @@ config THINKPAD_ACPI
depends on ACPI_VIDEO || ACPI_VIDEO = n
depends on BACKLIGHT_CLASS_DEVICE
depends on I2C
+   depends on DRM
select ACPI_PLATFORM_PROFILE
+   select DRM_PRIVACY_SCREEN
select HWMON
select NVRAM
select NEW_LEDS
diff --git a/drivers/platform/x86/thinkpad_acpi.c 
b/drivers/platform/x86/thinkpad_acpi.c
index b8f2556c4797..291cd18c9c8f 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -73,6 +73,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "dual_accel_detect.h"
 
 /* ThinkPad CMOS commands */
@@ -157,6 +158,7 @@ enum tpacpi_hkey_event_t {
TP_HKEY_EV_VOL_UP   = 0x1015, /* Volume up or unmute */
TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */
TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */
+   TP_HKEY_EV_PRIVACYGUARD_TOGGLE  = 0x130f, /* Toggle priv.guard on/off */
 
/* Reasons for waking up from S3/S4 */
TP_HKEY_EV_WKUP_S3_UNDOCK   = 0x2304, /* undock requested, S3 */
@@ -3889,6 +3891,12 @@ static bool hotkey_notify_extended_hotkey(const u32 hkey)
 {
unsigned int scancode;
 
+   switch (hkey) {
+   case TP_HKEY_EV_PRIVACYGUARD_TOGGLE:
+   tpacpi_driver_event(hkey);
+   return true;
+   }
+
/* Extended keycodes start at 0x300 and our offset into the map
 * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
 * will be positive, but might not be in the correct range.
@@ -9819,30 +9827,40 @@ static struct ibm_struct battery_driver_data = {
  * LCD Shadow subdriver, for the Lenovo PrivacyGuard feature
  */
 
+static struct drm_privacy_screen *lcdshadow_dev;
 static acpi_handle lcdshadow_get_handle;
 static acpi_handle lcdshadow_set_handle;
-static int lcdshadow_state;
 
-static int lcdshadow_on_off(bool state)
+static int lcdshadow_set_sw_state(struct drm_privacy_screen *priv,
+ enum drm_privacy_screen_status state)
 {
int output;
 
+   if (WARN_ON(!mutex_is_locked(>lock)))
+   return -EIO;
+
if (!acpi_evalf(lcdshadow_set_handle, , NULL, "dd", (int)state))
return -EIO;
 
-   lcdshadow_state = state;
+   priv->hw_state = priv->sw_state = state;
return 0;
 }
 
-static int lcdshadow_set(bool on)
+static void lcdshadow_get_hw_state(struct drm_privacy_screen *priv)
 {
-   if (lcdshadow_state < 0)
-   return lcdshadow_state;
-   if (lcdshadow_state == on)
-   return 0;
-   return lcdshadow_on_off(on);
+   int output;
+
+   if (!acpi_evalf(lcdshadow_get_handle, , NULL, "dd", 0))
+   return;
+
+   priv->hw_state = priv->sw_state = output & 0x1;
 }
 
+static const struct drm_privacy_screen_ops lcdshadow_ops = {
+   .set_sw_state = lcdshadow_set_sw_state,
+   .get_hw_state = lcdshadow_get_hw_state,
+};
+
 static int tpacpi_lcdshadow_init(struct ibm_init_struct *iibm)
 {
acpi_status status1, status2;
@@ -9850,36 +9868,44 @@ static int tpacpi_lcdshadow_init(struct ibm_init_struct 
*iibm)
 
status1 = acpi_get_handle(hkey_handle, "GSSS", _get_handle);
status2 = acpi_get_handle(hkey_handle, "", _set_handle);
-   if (ACPI_FAILURE(status1) || ACPI_FAILURE(status2)) {
-   lcdshadow_state = -ENODEV;
+   if (ACPI_FAILURE(status1) || ACPI_FAILURE(status2))
return 0;
-

[PATCH 09/10] drm/i915: Add intel_modeset_probe_defer() helper

2021-10-02 Thread Hans de Goede
The upcoming privacy-screen support adds another check for
deferring probe till some other drivers have bound first.

Factor out the current vga_switcheroo_client_probe_defer() check
into an intel_modeset_probe_defer() helper, so that further
probe-deferral checks can be added there.

Signed-off-by: Hans de Goede 
---
 drivers/gpu/drm/i915/display/intel_display.c | 13 +
 drivers/gpu/drm/i915/display/intel_display.h |  1 +
 drivers/gpu/drm/i915/i915_pci.c  |  9 ++---
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
b/drivers/gpu/drm/i915/display/intel_display.c
index 60b2bc3ad011..e67f3207ba54 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -12690,6 +12691,18 @@ void intel_modeset_driver_remove_nogem(struct 
drm_i915_private *i915)
intel_bios_driver_remove(i915);
 }
 
+bool intel_modeset_probe_defer(struct pci_dev *pdev)
+{
+   /*
+* apple-gmux is needed on dual GPU MacBook Pro
+* to probe the panel if we're the inactive GPU.
+*/
+   if (vga_switcheroo_client_probe_defer(pdev))
+   return true;
+
+   return false;
+}
+
 void intel_display_driver_register(struct drm_i915_private *i915)
 {
if (!HAS_DISPLAY(i915))
diff --git a/drivers/gpu/drm/i915/display/intel_display.h 
b/drivers/gpu/drm/i915/display/intel_display.h
index 3028072c2cf3..d3d34acb6c08 100644
--- a/drivers/gpu/drm/i915/display/intel_display.h
+++ b/drivers/gpu/drm/i915/display/intel_display.h
@@ -633,6 +633,7 @@ void intel_display_driver_register(struct drm_i915_private 
*i915);
 void intel_display_driver_unregister(struct drm_i915_private *i915);
 
 /* modesetting */
+bool intel_modeset_probe_defer(struct pci_dev *pdev);
 void intel_modeset_init_hw(struct drm_i915_private *i915);
 int intel_modeset_init_noirq(struct drm_i915_private *i915);
 int intel_modeset_init_nogem(struct drm_i915_private *i915);
diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c
index d4a6a9dcf182..cf4ad648b742 100644
--- a/drivers/gpu/drm/i915/i915_pci.c
+++ b/drivers/gpu/drm/i915/i915_pci.c
@@ -22,8 +22,6 @@
  *
  */
 
-#include 
-
 #include 
 #include 
 
@@ -1187,11 +1185,8 @@ static int i915_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
if (PCI_FUNC(pdev->devfn))
return -ENODEV;
 
-   /*
-* apple-gmux is needed on dual GPU MacBook Pro
-* to probe the panel if we're the inactive GPU.
-*/
-   if (vga_switcheroo_client_probe_defer(pdev))
+   /* Detect if we need to wait for other drivers early on */
+   if (intel_modeset_probe_defer(pdev))
return -EPROBE_DEFER;
 
err = i915_driver_probe(pdev, ent);
-- 
2.31.1



[PATCH 10/10] drm/i915: Add privacy-screen support (v2)

2021-10-02 Thread Hans de Goede
Add support for eDP panels with a built-in privacy screen using the
new drm_privacy_screen class.

Changes in v2:
- Call drm_connector_update_privacy_screen() from
  intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
  for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
- Move the probe-deferral check to the intel_modeset_probe_defer() helper

Signed-off-by: Hans de Goede 
---
 drivers/gpu/drm/i915/display/intel_atomic.c  |  1 +
 drivers/gpu/drm/i915/display/intel_ddi.c |  3 +++
 drivers/gpu/drm/i915/display/intel_display.c | 10 ++
 drivers/gpu/drm/i915/display/intel_dp.c  | 10 ++
 4 files changed, 24 insertions(+)

diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c 
b/drivers/gpu/drm/i915/display/intel_atomic.c
index b4e7ac51aa31..a62550711e98 100644
--- a/drivers/gpu/drm/i915/display/intel_atomic.c
+++ b/drivers/gpu/drm/i915/display/intel_atomic.c
@@ -139,6 +139,7 @@ int intel_digital_connector_atomic_check(struct 
drm_connector *conn,
new_conn_state->base.picture_aspect_ratio != 
old_conn_state->base.picture_aspect_ratio ||
new_conn_state->base.content_type != 
old_conn_state->base.content_type ||
new_conn_state->base.scaling_mode != 
old_conn_state->base.scaling_mode ||
+   new_conn_state->base.privacy_screen_sw_state != 
old_conn_state->base.privacy_screen_sw_state ||
!drm_connector_atomic_hdr_metadata_equal(old_state, new_state))
crtc_state->mode_changed = true;
 
diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c 
b/drivers/gpu/drm/i915/display/intel_ddi.c
index 51cd0420e00e..e4496c830a35 100644
--- a/drivers/gpu/drm/i915/display/intel_ddi.c
+++ b/drivers/gpu/drm/i915/display/intel_ddi.c
@@ -25,6 +25,7 @@
  *
  */
 
+#include 
 #include 
 
 #include "i915_drv.h"
@@ -3022,6 +3023,7 @@ static void intel_enable_ddi_dp(struct intel_atomic_state 
*state,
if (port == PORT_A && DISPLAY_VER(dev_priv) < 9)
intel_dp_stop_link_train(intel_dp, crtc_state);
 
+   drm_connector_update_privacy_screen(conn_state);
intel_edp_backlight_on(crtc_state, conn_state);
 
if (!dig_port->lspcon.active || dig_port->dp.has_hdmi_sink)
@@ -3247,6 +3249,7 @@ static void intel_ddi_update_pipe_dp(struct 
intel_atomic_state *state,
intel_drrs_update(intel_dp, crtc_state);
 
intel_backlight_update(state, encoder, crtc_state, conn_state);
+   drm_connector_update_privacy_screen(conn_state);
 }
 
 void intel_ddi_update_pipe(struct intel_atomic_state *state,
diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
b/drivers/gpu/drm/i915/display/intel_display.c
index e67f3207ba54..9a5dbe51458d 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -12693,6 +12694,8 @@ void intel_modeset_driver_remove_nogem(struct 
drm_i915_private *i915)
 
 bool intel_modeset_probe_defer(struct pci_dev *pdev)
 {
+   struct drm_privacy_screen *privacy_screen;
+
/*
 * apple-gmux is needed on dual GPU MacBook Pro
 * to probe the panel if we're the inactive GPU.
@@ -12700,6 +12703,13 @@ bool intel_modeset_probe_defer(struct pci_dev *pdev)
if (vga_switcheroo_client_probe_defer(pdev))
return true;
 
+   /* If the LCD panel has a privacy-screen, wait for it */
+   privacy_screen = drm_privacy_screen_get(>dev, NULL);
+   if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
+   return true;
+
+   drm_privacy_screen_put(privacy_screen);
+
return false;
 }
 
diff --git a/drivers/gpu/drm/i915/display/intel_dp.c 
b/drivers/gpu/drm/i915/display/intel_dp.c
index 74a657ae131a..91207310dc0d 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "g4x_dp.h"
@@ -4808,6 +4809,7 @@ static bool intel_edp_init_connector(struct intel_dp 
*intel_dp,
struct drm_connector *connector = _connector->base;
struct drm_display_mode *fixed_mode = NULL;
struct drm_display_mode *downclock_mode = NULL;
+   struct drm_privacy_screen *privacy_screen;
bool has_dpcd;
enum pipe pipe = INVALID_PIPE;
struct edid *edid;
@@ -4902,6 +4904,14 @@ static bool intel_edp_init_connector(struct intel_dp 
*intel_dp,
fixed_mode->hdisplay, fixed_mode->vdisplay);
}
 
+   privacy_screen = drm_privacy_screen_get(dev->dev, NULL);
+   if (!IS_ERR(privacy_screen)) {
+   drm_connector_attach_privacy_screen_provider(connector,
+privacy_screen);
+   } else if (PTR_ERR(privacy_screen) != -ENODEV) {
+   drm_warn(_priv->drm, "Error getting 

[PATCH 07/10] platform/x86: thinkpad_acpi: Get privacy-screen / lcdshadow ACPI handles only once

2021-10-02 Thread Hans de Goede
Get the privacy-screen / lcdshadow ACPI handles once and cache them,
instead of retrieving them every time we need them.

Reviewed-by: Emil Velikov 
Reviewed-by: Lyude Paul 
Signed-off-by: Hans de Goede 
---
 drivers/platform/x86/thinkpad_acpi.c | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c 
b/drivers/platform/x86/thinkpad_acpi.c
index 83c88a8ebaf2..b8f2556c4797 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -9819,19 +9819,15 @@ static struct ibm_struct battery_driver_data = {
  * LCD Shadow subdriver, for the Lenovo PrivacyGuard feature
  */
 
+static acpi_handle lcdshadow_get_handle;
+static acpi_handle lcdshadow_set_handle;
 static int lcdshadow_state;
 
 static int lcdshadow_on_off(bool state)
 {
-   acpi_handle set_shadow_handle;
int output;
 
-   if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "", 
_shadow_handle))) {
-   pr_warn("Thinkpad ACPI has no %s interface.\n", "");
-   return -EIO;
-   }
-
-   if (!acpi_evalf(set_shadow_handle, , NULL, "dd", (int)state))
+   if (!acpi_evalf(lcdshadow_set_handle, , NULL, "dd", (int)state))
return -EIO;
 
lcdshadow_state = state;
@@ -9849,15 +9845,17 @@ static int lcdshadow_set(bool on)
 
 static int tpacpi_lcdshadow_init(struct ibm_init_struct *iibm)
 {
-   acpi_handle get_shadow_handle;
+   acpi_status status1, status2;
int output;
 
-   if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GSSS", 
_shadow_handle))) {
+   status1 = acpi_get_handle(hkey_handle, "GSSS", _get_handle);
+   status2 = acpi_get_handle(hkey_handle, "", _set_handle);
+   if (ACPI_FAILURE(status1) || ACPI_FAILURE(status2)) {
lcdshadow_state = -ENODEV;
return 0;
}
 
-   if (!acpi_evalf(get_shadow_handle, , NULL, "dd", 0)) {
+   if (!acpi_evalf(lcdshadow_get_handle, , NULL, "dd", 0)) {
lcdshadow_state = -EIO;
return -EIO;
}
-- 
2.31.1



[PATCH 05/10] drm/connector: Add a drm_connector privacy-screen helper functions (v2)

2021-10-02 Thread Hans de Goede
Add 2 drm_connector privacy-screen helper functions:

1. drm_connector_attach_privacy_screen_provider(), this function creates
and attaches the standard privacy-screen properties and registers a
generic notifier for generating sysfs-connector-status-events on external
changes to the privacy-screen status.

2. drm_connector_update_privacy_screen(), update the privacy-screen's
sw_state if the connector has a privacy-screen.

Changes in v2:
- Do not update connector->state->privacy_screen_sw_state on
  atomic-commits.
- Change drm_connector_update_privacy_screen() to take drm_connector_state
  as argument instead of a full drm_atomic_state. This allows the helper
  to be called by drivers when they are enabling crtcs/encoders/connectors.

Reviewed-by: Emil Velikov 
Reviewed-by: Lyude Paul 
Signed-off-by: Hans de Goede 
---
 drivers/gpu/drm/drm_connector.c | 102 
 include/drm/drm_connector.h |  11 
 2 files changed, 113 insertions(+)

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index b2f1f1b1bfb4..00cf3b6135f6 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -462,6 +463,11 @@ void drm_connector_cleanup(struct drm_connector *connector)
DRM_CONNECTOR_REGISTERED))
drm_connector_unregister(connector);
 
+   if (connector->privacy_screen) {
+   drm_privacy_screen_put(connector->privacy_screen);
+   connector->privacy_screen = NULL;
+   }
+
if (connector->tile_group) {
drm_mode_put_tile_group(dev, connector->tile_group);
connector->tile_group = NULL;
@@ -543,6 +549,10 @@ int drm_connector_register(struct drm_connector *connector)
/* Let userspace know we have a new connector */
drm_sysfs_hotplug_event(connector->dev);
 
+   if (connector->privacy_screen)
+   drm_privacy_screen_register_notifier(connector->privacy_screen,
+  >privacy_screen_notifier);
+
mutex_lock(_list_lock);
list_add_tail(>global_connector_list_entry, _list);
mutex_unlock(_list_lock);
@@ -578,6 +588,11 @@ void drm_connector_unregister(struct drm_connector 
*connector)
list_del_init(>global_connector_list_entry);
mutex_unlock(_list_lock);
 
+   if (connector->privacy_screen)
+   drm_privacy_screen_unregister_notifier(
+   connector->privacy_screen,
+   >privacy_screen_notifier);
+
if (connector->funcs->early_unregister)
connector->funcs->early_unregister(connector);
 
@@ -2442,6 +2457,93 @@ drm_connector_attach_privacy_screen_properties(struct 
drm_connector *connector)
 }
 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
 
+static void drm_connector_update_privacy_screen_properties(
+   struct drm_connector *connector, bool set_sw_state)
+{
+   enum drm_privacy_screen_status sw_state, hw_state;
+
+   drm_privacy_screen_get_state(connector->privacy_screen,
+_state, _state);
+
+   if (set_sw_state)
+   connector->state->privacy_screen_sw_state = sw_state;
+   drm_object_property_set_value(>base,
+   connector->privacy_screen_hw_state_property, hw_state);
+}
+
+static int drm_connector_privacy_screen_notifier(
+   struct notifier_block *nb, unsigned long action, void *data)
+{
+   struct drm_connector *connector =
+   container_of(nb, struct drm_connector, privacy_screen_notifier);
+   struct drm_device *dev = connector->dev;
+
+   drm_modeset_lock(>mode_config.connection_mutex, NULL);
+   drm_connector_update_privacy_screen_properties(connector, true);
+   drm_modeset_unlock(>mode_config.connection_mutex);
+
+   drm_sysfs_connector_status_event(connector,
+   connector->privacy_screen_sw_state_property);
+   drm_sysfs_connector_status_event(connector,
+   connector->privacy_screen_hw_state_property);
+
+   return NOTIFY_DONE;
+}
+
+/**
+ * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
+ *the connector
+ * @connector: connector to attach the privacy-screen to
+ * @priv: drm_privacy_screen to attach
+ *
+ * Create and attach the standard privacy-screen properties and register
+ * a generic notifier for generating sysfs-connector-status-events
+ * on external changes to the privacy-screen status.
+ * This function takes ownership of the passed in drm_privacy_screen and will
+ * call drm_privacy_screen_put() on it when the connector is destroyed.
+ */
+void drm_connector_attach_privacy_screen_provider(
+   struct drm_connector *connector, struct drm_privacy_screen *priv)
+{
+   

[PATCH 04/10] drm/privacy-screen: Add notifier support (v2)

2021-10-02 Thread Hans de Goede
Add support for privacy-screen consumers to register a notifier to
be notified of external (e.g. done by the hw itself on a hotkey press)
state changes.

Changes in v2:
- Drop WARN_ON(mutex_is_locked(>lock)) check in
  drm_privacy_screen_call_notifier_chain() it may be locked by
  another thread, which would lead to a false-positive triggering
  of the check

Reviewed-by: Emil Velikov 
Reviewed-by: Lyude Paul 
Signed-off-by: Hans de Goede 
---
 drivers/gpu/drm/drm_privacy_screen.c  | 64 +++
 include/drm/drm_privacy_screen_consumer.h | 15 ++
 include/drm/drm_privacy_screen_driver.h   |  4 ++
 3 files changed, 83 insertions(+)

diff --git a/drivers/gpu/drm/drm_privacy_screen.c 
b/drivers/gpu/drm/drm_privacy_screen.c
index 183a6011adf0..beaf99e9120a 100644
--- a/drivers/gpu/drm/drm_privacy_screen.c
+++ b/drivers/gpu/drm/drm_privacy_screen.c
@@ -257,6 +257,49 @@ void drm_privacy_screen_get_state(struct 
drm_privacy_screen *priv,
 }
 EXPORT_SYMBOL(drm_privacy_screen_get_state);
 
+/**
+ * drm_privacy_screen_register_notifier - register a notifier
+ * @priv: Privacy screen to register the notifier with
+ * @nb: Notifier-block for the notifier to register
+ *
+ * Register a notifier with the privacy-screen to be notified of changes made
+ * to the privacy-screen state from outside of the privacy-screen class.
+ * E.g. the state may be changed by the hardware itself in response to a
+ * hotkey press.
+ *
+ * The notifier is called with no locks held. The new hw_state and sw_state
+ * can be retrieved using the drm_privacy_screen_get_state() function.
+ * A pointer to the drm_privacy_screen's struct is passed as the void *data
+ * argument of the notifier_block's notifier_call.
+ *
+ * The notifier will NOT be called when changes are made through
+ * drm_privacy_screen_set_sw_state(). It is only called for external changes.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int drm_privacy_screen_register_notifier(struct drm_privacy_screen *priv,
+struct notifier_block *nb)
+{
+   return blocking_notifier_chain_register(>notifier_head, nb);
+}
+EXPORT_SYMBOL(drm_privacy_screen_register_notifier);
+
+/**
+ * drm_privacy_screen_unregister_notifier - unregister a notifier
+ * @priv: Privacy screen to register the notifier with
+ * @nb: Notifier-block for the notifier to register
+ *
+ * Unregister a notifier registered with 
drm_privacy_screen_register_notifier().
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int drm_privacy_screen_unregister_notifier(struct drm_privacy_screen *priv,
+  struct notifier_block *nb)
+{
+   return blocking_notifier_chain_unregister(>notifier_head, nb);
+}
+EXPORT_SYMBOL(drm_privacy_screen_unregister_notifier);
+
 /*** drm_privacy_screen_driver.h functions ***/
 
 static ssize_t sw_state_show(struct device *dev,
@@ -354,6 +397,7 @@ struct drm_privacy_screen *drm_privacy_screen_register(
return ERR_PTR(-ENOMEM);
 
mutex_init(>lock);
+   BLOCKING_INIT_NOTIFIER_HEAD(>notifier_head);
 
priv->dev.class = drm_class;
priv->dev.type = _privacy_screen_type;
@@ -401,3 +445,23 @@ void drm_privacy_screen_unregister(struct 
drm_privacy_screen *priv)
device_unregister(>dev);
 }
 EXPORT_SYMBOL(drm_privacy_screen_unregister);
+
+/**
+ * drm_privacy_screen_call_notifier_chain - notify consumers of state change
+ * @priv: Privacy screen to register the notifier with
+ *
+ * A privacy-screen provider driver can call this functions upon external
+ * changes to the privacy-screen state. E.g. the state may be changed by the
+ * hardware itself in response to a hotkey press.
+ * This function must be called without holding the privacy-screen lock.
+ * the driver must update sw_state and hw_state to reflect the new state before
+ * calling this function.
+ * The expected behavior from the driver upon receiving an external state
+ * change event is: 1. Take the lock; 2. Update sw_state and hw_state;
+ * 3. Release the lock. 4. Call drm_privacy_screen_call_notifier_chain().
+ */
+void drm_privacy_screen_call_notifier_chain(struct drm_privacy_screen *priv)
+{
+   blocking_notifier_call_chain(>notifier_head, 0, priv);
+}
+EXPORT_SYMBOL(drm_privacy_screen_call_notifier_chain);
diff --git a/include/drm/drm_privacy_screen_consumer.h 
b/include/drm/drm_privacy_screen_consumer.h
index 0cbd23b0453d..7f66a90d15b7 100644
--- a/include/drm/drm_privacy_screen_consumer.h
+++ b/include/drm/drm_privacy_screen_consumer.h
@@ -24,6 +24,11 @@ int drm_privacy_screen_set_sw_state(struct 
drm_privacy_screen *priv,
 void drm_privacy_screen_get_state(struct drm_privacy_screen *priv,
  enum drm_privacy_screen_status *sw_state_ret,
  enum drm_privacy_screen_status *hw_state_ret);
+
+int drm_privacy_screen_register_notifier(struct drm_privacy_screen *priv,
+  

[PATCH 03/10] drm/privacy-screen: Add X86 specific arch init code

2021-10-02 Thread Hans de Goede
Add X86 specific arch init code, which fills the privacy-screen lookup
table by checking for various vendor specific ACPI interfaces for
controlling the privacy-screen.

This initial version only checks for the Lenovo Thinkpad specific ACPI
methods for privacy-screen control.

Reviewed-by: Emil Velikov 
Reviewed-by: Lyude Paul 
Signed-off-by: Hans de Goede 
---
 drivers/gpu/drm/Makefile |  2 +-
 drivers/gpu/drm/drm_privacy_screen_x86.c | 86 
 include/drm/drm_privacy_screen_machine.h |  5 ++
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_privacy_screen_x86.c

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 788fc37096f6..12997ca5670d 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -32,7 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_PCI) += drm_pci.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
-drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
+drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o 
drm_privacy_screen_x86.o
 
 obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
 
diff --git a/drivers/gpu/drm/drm_privacy_screen_x86.c 
b/drivers/gpu/drm/drm_privacy_screen_x86.c
new file mode 100644
index ..a2cafb294ca6
--- /dev/null
+++ b/drivers/gpu/drm/drm_privacy_screen_x86.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright (C) 2020 Red Hat, Inc.
+ *
+ * Authors:
+ * Hans de Goede 
+ */
+
+#include 
+#include 
+
+#ifdef CONFIG_X86
+static struct drm_privacy_screen_lookup arch_lookup;
+
+struct arch_init_data {
+   struct drm_privacy_screen_lookup lookup;
+   bool (*detect)(void);
+};
+
+#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
+static acpi_status __init acpi_set_handle(acpi_handle handle, u32 level,
+ void *context, void **return_value)
+{
+   *(acpi_handle *)return_value = handle;
+   return AE_CTRL_TERMINATE;
+}
+
+static bool __init detect_thinkpad_privacy_screen(void)
+{
+   union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
+   struct acpi_object_list args = { .count = 1, .pointer = , };
+   acpi_handle ec_handle = NULL;
+   unsigned long long output;
+   acpi_status status;
+
+   /* Get embedded-controller handle */
+   status = acpi_get_devices("PNP0C09", acpi_set_handle, NULL, _handle);
+   if (ACPI_FAILURE(status) || !ec_handle)
+   return false;
+
+   /* And call the privacy-screen get-status method */
+   status = acpi_evaluate_integer(ec_handle, "HKEY.GSSS", , );
+   if (ACPI_FAILURE(status))
+   return false;
+
+   return (output & 0x1) ? true : false;
+}
+#endif
+
+static const struct arch_init_data arch_init_data[] __initconst = {
+#if IS_ENABLED(CONFIG_THINKPAD_ACPI)
+   {
+   .lookup = {
+   .dev_id = NULL,
+   .con_id = NULL,
+   .provider = "privacy_screen-thinkpad_acpi",
+   },
+   .detect = detect_thinkpad_privacy_screen,
+   },
+#endif
+};
+
+void __init drm_privacy_screen_lookup_init(void)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(arch_init_data); i++) {
+   if (!arch_init_data[i].detect())
+   continue;
+
+   pr_info("Found '%s' privacy-screen provider\n",
+   arch_init_data[i].lookup.provider);
+
+   /* Make a copy because arch_init_data is __initconst */
+   arch_lookup = arch_init_data[i].lookup;
+   drm_privacy_screen_lookup_add(_lookup);
+   break;
+   }
+}
+
+void drm_privacy_screen_lookup_exit(void)
+{
+   if (arch_lookup.provider)
+   drm_privacy_screen_lookup_remove(_lookup);
+}
+#endif /* ifdef CONFIG_X86 */
diff --git a/include/drm/drm_privacy_screen_machine.h 
b/include/drm/drm_privacy_screen_machine.h
index aaa0d38cce92..02e5371904d3 100644
--- a/include/drm/drm_privacy_screen_machine.h
+++ b/include/drm/drm_privacy_screen_machine.h
@@ -31,11 +31,16 @@ struct drm_privacy_screen_lookup {
 void drm_privacy_screen_lookup_add(struct drm_privacy_screen_lookup *lookup);
 void drm_privacy_screen_lookup_remove(struct drm_privacy_screen_lookup 
*lookup);
 
+#if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) && IS_ENABLED(CONFIG_X86)
+void drm_privacy_screen_lookup_init(void);
+void drm_privacy_screen_lookup_exit(void);
+#else
 static inline void drm_privacy_screen_lookup_init(void)
 {
 }
 static inline void drm_privacy_screen_lookup_exit(void)
 {
 }
+#endif
 
 #endif
-- 
2.31.1



[PATCH 01/10] drm/connector: Add support for privacy-screen properties (v4)

2021-10-02 Thread Hans de Goede
From: Rajat Jain 

Add support for generic electronic privacy screen properties, that
can be added by systems that have an integrated EPS.

Changes in v2 (Hans de Goede)
- Create 2 properties, "privacy-screen sw-state" and
  "privacy-screen hw-state", to deal with devices where the OS might be
  locked out of making state changes
- Write kerneldoc explaining how the 2 properties work together, what
  happens when changes to the state are made outside of the DRM code's
  control, etc.

Changes in v3 (Hans de Goede)
- Some small tweaks to the kerneldoc describing the 2 properties

Changes in v4 (Hans de Goede)
- Change the "Enabled, locked" and "Disabled, locked" hw-state enum value
  names to "Enabled-locked" and "Disabled-locked". The xrandr command shows
  all possible enum values separated by commas in its output, so having a
  comma in an enum name is not a good idea.
- Do not add a privacy_screen_hw_state member to drm_connector_state
  since this property is immutable its value must be directly stored in the
  obj->properties->values array

Signed-off-by: Rajat Jain 
Acked-by: Pekka Paalanen 
Reviewed-by: Mario Limonciello 
Reviewed-by: Emil Velikov 
Reviewed-by: Lyude Paul 
Co-developed-by: Hans de Goede 
Signed-off-by: Hans de Goede 
---
 Documentation/gpu/drm-kms.rst |   2 +
 drivers/gpu/drm/drm_atomic_uapi.c |   4 ++
 drivers/gpu/drm/drm_connector.c   | 101 ++
 include/drm/drm_connector.h   |  44 +
 4 files changed, 151 insertions(+)

diff --git a/Documentation/gpu/drm-kms.rst b/Documentation/gpu/drm-kms.rst
index 1ef7951ded5e..d14bf1c35d7e 100644
--- a/Documentation/gpu/drm-kms.rst
+++ b/Documentation/gpu/drm-kms.rst
@@ -506,6 +506,8 @@ Property Types and Blob Property Support
 .. kernel-doc:: drivers/gpu/drm/drm_property.c
:export:
 
+.. _standard_connector_properties:
+
 Standard Connector Properties
 -
 
diff --git a/drivers/gpu/drm/drm_atomic_uapi.c 
b/drivers/gpu/drm/drm_atomic_uapi.c
index 909f31833181..cdd31fc78bfc 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -797,6 +797,8 @@ static int drm_atomic_connector_set_property(struct 
drm_connector *connector,
   fence_ptr);
} else if (property == connector->max_bpc_property) {
state->max_requested_bpc = val;
+   } else if (property == connector->privacy_screen_sw_state_property) {
+   state->privacy_screen_sw_state = val;
} else if (connector->funcs->atomic_set_property) {
return connector->funcs->atomic_set_property(connector,
state, property, val);
@@ -874,6 +876,8 @@ drm_atomic_connector_get_property(struct drm_connector 
*connector,
*val = 0;
} else if (property == connector->max_bpc_property) {
*val = state->max_requested_bpc;
+   } else if (property == connector->privacy_screen_sw_state_property) {
+   *val = state->privacy_screen_sw_state;
} else if (connector->funcs->atomic_get_property) {
return connector->funcs->atomic_get_property(connector,
state, property, val);
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 3bc782b630b9..b2f1f1b1bfb4 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -1264,6 +1264,46 @@ static const struct drm_prop_enum_list dp_colorspaces[] 
= {
  * For DVI-I and TVout there is also a matching property "select 
subconnector"
  * allowing to switch between signal types.
  * DP subconnector corresponds to a downstream port.
+ *
+ * privacy-screen sw-state, privacy-screen hw-state:
+ * These 2 optional properties can be used to query the state of the
+ * electronic privacy screen that is available on some displays; and in
+ * some cases also control the state. If a driver implements these
+ * properties then both properties must be present.
+ *
+ * "privacy-screen hw-state" is read-only and reflects the actual state
+ * of the privacy-screen, possible values: "Enabled", "Disabled,
+ * "Enabled-locked", "Disabled-locked". The locked states indicate
+ * that the state cannot be changed through the DRM API. E.g. there
+ * might be devices where the firmware-setup options, or a hardware
+ * slider-switch, offer always on / off modes.
+ *
+ * "privacy-screen sw-state" can be set to change the privacy-screen state
+ * when not locked. In this case the driver must update the hw-state
+ * property to reflect the new state on completion of the commit of the
+ * sw-state property. Setting the sw-state property when the hw-state is
+ * locked must be interpreted by the driver as a request to change the
+ * state to the set state when the hw-state becomes unlocked. E.g. if
+ * "privacy-screen hw-state" 

[PATCH 02/10] drm: Add privacy-screen class (v4)

2021-10-02 Thread Hans de Goede
On some new laptops the LCD panel has a builtin electronic privacy-screen.
We want to export this functionality as a property on the drm connector
object. But often this functionality is not exposed on the GPU but on some
other (ACPI) device.

This commit adds a privacy-screen class allowing the driver for these
other devices to register themselves as a privacy-screen provider; and
allowing the drm/kms code to get a privacy-screen provider associated
with a specific GPU/connector combo.

Changes in v2:
- Make CONFIG_DRM_PRIVACY_SCREEN a bool which controls if the drm_privacy
  code gets built as part of the main drm module rather then making it
  a tristate which builds its own module.
- Add a #if IS_ENABLED(CONFIG_DRM_PRIVACY_SCREEN) check to
  drm_privacy_screen_consumer.h and define stubs when the check fails.
  Together these 2 changes fix several dependency issues.
- Remove module related code now that this is part of the main drm.ko
- Use drm_class as class for the privacy-screen devices instead of
  adding a separate class for this

Changes in v3:
- Make the static inline drm_privacy_screen_get_state() stub set sw_state
  and hw_state to PRIVACY_SCREEN_DISABLED to squelch an uninitialized
  variable warning when CONFIG_DRM_PRIVICAY_SCREEN is not set

Changes in v4:
- Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
  hw_state == new_sw_state

Reviewed-by: Emil Velikov 
Reviewed-by: Lyude Paul 
Signed-off-by: Hans de Goede 
---
 Documentation/gpu/drm-kms-helpers.rst |  15 +
 MAINTAINERS   |   8 +
 drivers/gpu/drm/Kconfig   |   4 +
 drivers/gpu/drm/Makefile  |   1 +
 drivers/gpu/drm/drm_drv.c |   4 +
 drivers/gpu/drm/drm_privacy_screen.c  | 403 ++
 include/drm/drm_privacy_screen_consumer.h |  50 +++
 include/drm/drm_privacy_screen_driver.h   |  80 +
 include/drm/drm_privacy_screen_machine.h  |  41 +++
 9 files changed, 606 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_privacy_screen.c
 create mode 100644 include/drm/drm_privacy_screen_consumer.h
 create mode 100644 include/drm/drm_privacy_screen_driver.h
 create mode 100644 include/drm/drm_privacy_screen_machine.h

diff --git a/Documentation/gpu/drm-kms-helpers.rst 
b/Documentation/gpu/drm-kms-helpers.rst
index ec2f65b31930..5bb55ec1b9b5 100644
--- a/Documentation/gpu/drm-kms-helpers.rst
+++ b/Documentation/gpu/drm-kms-helpers.rst
@@ -435,3 +435,18 @@ Legacy CRTC/Modeset Helper Functions Reference
 
 .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
:export:
+
+Privacy-screen class
+
+
+.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
+   :doc: overview
+
+.. kernel-doc:: include/drm/drm_privacy_screen_driver.h
+   :internal:
+
+.. kernel-doc:: include/drm/drm_privacy_screen_machine.h
+   :internal:
+
+.. kernel-doc:: drivers/gpu/drm/drm_privacy_screen.c
+   :export:
diff --git a/MAINTAINERS b/MAINTAINERS
index e3556c63081d..0e70c81d3ddc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6421,6 +6421,14 @@ F:   drivers/gpu/drm/drm_panel.c
 F: drivers/gpu/drm/panel/
 F: include/drm/drm_panel.h
 
+DRM PRIVACY-SCREEN CLASS
+M: Hans de Goede 
+L: dri-devel@lists.freedesktop.org
+S: Maintained
+T: git git://anongit.freedesktop.org/drm/drm-misc
+F: drivers/gpu/drm/drm_privacy_screen*
+F: include/drm/drm_privacy_screen*
+
 DRM TTM SUBSYSTEM
 M: Christian Koenig 
 M: Huang Rui 
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 2a926d0de423..c686c08447ac 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -481,3 +481,7 @@ config DRM_PANEL_ORIENTATION_QUIRKS
 config DRM_LIB_RANDOM
bool
default n
+
+config DRM_PRIVACY_SCREEN
+   bool
+   default n
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 0dff40bb863c..788fc37096f6 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -32,6 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_PCI) += drm_pci.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
+drm-$(CONFIG_DRM_PRIVACY_SCREEN) += drm_privacy_screen.o
 
 obj-$(CONFIG_DRM_DP_AUX_BUS) += drm_dp_aux_bus.o
 
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 7a5097467ba5..dc293b771c3f 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -43,6 +43,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
@@ -1029,6 +1030,7 @@ static const struct file_operations drm_stub_fops = {
 
 static void drm_core_exit(void)
 {
+   drm_privacy_screen_lookup_exit();
unregister_chrdev(DRM_MAJOR, "drm");
debugfs_remove(drm_debugfs_root);
drm_sysfs_destroy();
@@ -1056,6 +1058,8 @@ static int __init drm_core_init(void)
if (ret < 0)
goto error;
 
+   

[PATCH 00/10] drm: Add privacy-screen class and connector properties

2021-10-02 Thread Hans de Goede
Hi all,

Here is a new version of my privacy-screen series, addressing the
(few) review-remarks from the version posted on September 6th.
This new version contains the following changes:

- drm: Add privacy-screen class (v4)
 - Make drm_privacy_screen_set_sw_state() skip calling out to the hw if
   hw_state == new_sw_state

- drm/privacy-screen: Add notifier support (v2)
 - Drop WARN_ON(mutex_is_locked(>lock)) check in
   drm_privacy_screen_call_notifier_chain() it may be locked by
   another thread, which would lead to a false-positive triggering
   of the check (change requested by Lyude)

- drm/connector: Add a drm_connector privacy-screen helper functions (v2)
 - Do not update connector->state->privacy_screen_sw_state on
   atomic-commits (change requested by Ville)
 - Change drm_connector_update_privacy_screen() to take drm_connector_state
   as argument instead of a full drm_atomic_state. This allows the helper
   to be called by drivers when they are enabling crtcs/encoders/connectors.

- platform/x86: thinkpad_acpi: Register a privacy-screen device (v3)
 - On receiving a TP_HKEY_EV_PRIVACYGUARD_TOGGLE event only call
   drm_privacy_screen_call_notifier_chain() if the privacy-screen state
   has actually changed

- drm/i915: Add intel_modeset_probe_defer() helper
 - New patch in this version of the series (change requested by Jani)

- drm/i915: Add privacy-screen support (v2)
 - Call drm_connector_update_privacy_screen() from
   intel_enable_ddi_dp() / intel_ddi_update_pipe_dp() instead of adding a
   for_each_new_connector_in_state() loop to intel_atomic_commit_tail()
   (change requested by Ville)
 - Move the probe-deferral check to the intel_modeset_probe_defer() helper
   (change requested by Jani)

With these changes I believe that this series now is fully ready for
merging, but the last 2 patches need to be (re)reviewed.

Here is some more info from the previous cover-letters:

The first userspace consumer of the new properties is now fully ready
for merging (it is just waiting for the kernel bits to land first):

 - https://gitlab.gnome.org/GNOME/gsettings-desktop-schemas/-/merge_requests/49
 - https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1952
 - https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/1032

The new API works as designed and add the following features to GNOME:

1. Showing an OSD notification when the privacy-screen is toggled on/off
   through hotkeys handled by the embedded-controller
2. Allowing control of the privacy-screen from the GNOME control-panel,
   including the on/off slider shown there updating to match the hw-setting
   when the setting is changed with the control-panel open.
3. Restoring the last user-setting at login

This series consists of a number of different parts:

1. A new version of Rajat's privacy-screen connector properties patch,
this adds new userspace API in the form of new properties

2. Since on most devices the privacy screen is actually controlled by
some vendor specific ACPI/WMI interface which has a driver under
drivers/platform/x86, we need some "glue" code to make this functionality
available to KMS drivers. Patches 2-4 add a new privacy-screen class for
this, which allows non KMS drivers (and possibly KMS drivers too) to
register a privacy-screen device and also adds an interface for KMS drivers
to get access to the privacy-screen associated with a specific connector.
This is modelled similar to how we deal with e.g. PWMs and GPIOs in the
kernel, including separate includes for consumers and providers(drivers).

3. Some drm_connector helper functions to keep the actual changes needed
for this in individual KMS drivers as small as possible (patch 5).

4. Make the thinkpad_acpi code register a privacy-screen device on
ThinkPads with a privacy-screen (patches 6-8)

5. Make the i915 driver export the privacy-screen functionality through
the connector properties on the eDP connector.

I believe that it would be best to merge the entire series, including
the thinkpad_acpi changes through drm-misc in one go. As the pdx86
subsys maintainer I hereby give my ack for merging the thinkpad_acpi
changes through drm-misc.

There is one small caveat with this series, which it is good to be
aware of. The i915 driver will now return -EPROBE_DEFER on Thinkpads
with an eprivacy screen, until the thinkpad_acpi driver is loaded.
This means that initrd generation tools will need to be updated to
include thinkpad_acpi when the i915 driver is added to the initrd.
Without this the loading of the i915 driver will be delayed to after
the switch to real rootfs.

Regards,

Hans


Hans de Goede (9):
  drm: Add privacy-screen class (v4)
  drm/privacy-screen: Add X86 specific arch init code
  drm/privacy-screen: Add notifier support (v2)
  drm/connector: Add a drm_connector privacy-screen helper functions
(v2)
  platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey()
helper
  platform/x86: thinkpad_acpi: Get privacy-screen / 

[PATCH 16/16] Revert "drm: cleanup: drm_modeset_lock_all_ctx() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 21dde40902d2636f70766b3154931de57e1215e9.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/drm_client_modeset.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_client_modeset.c 
b/drivers/gpu/drm/drm_client_modeset.c
index 5f5184f071ed..ced09c7c06f9 100644
--- a/drivers/gpu/drm/drm_client_modeset.c
+++ b/drivers/gpu/drm/drm_client_modeset.c
@@ -574,7 +574,6 @@ static bool drm_client_firmware_config(struct 
drm_client_dev *client,
int num_connectors_detected = 0;
int num_tiled_conns = 0;
struct drm_modeset_acquire_ctx ctx;
-   int err;
 
if (!drm_drv_uses_atomic_modeset(dev))
return false;
@@ -586,7 +585,10 @@ static bool drm_client_firmware_config(struct 
drm_client_dev *client,
if (!save_enabled)
return false;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err);
+   drm_modeset_acquire_init(, 0);
+
+   while (drm_modeset_lock_all_ctx(dev, ) != 0)
+   drm_modeset_backoff();
 
memcpy(save_enabled, enabled, count);
mask = GENMASK(count - 1, 0);
@@ -741,7 +743,8 @@ static bool drm_client_firmware_config(struct 
drm_client_dev *client,
ret = false;
}
 
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, err);
+   drm_modeset_drop_locks();
+   drm_modeset_acquire_fini();
 
kfree(save_enabled);
return ret;
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 15/16] Revert "drm/i915: cleanup: drm_modeset_lock_all_ctx() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 399190e70816886e2bca1f3f3bc3d9c544af88e7.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/i915/display/intel_display.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
b/drivers/gpu/drm/i915/display/intel_display.c
index 2bf01416d656..134a6acbd8fb 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -43,7 +43,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "display/intel_audio.h"
 #include "display/intel_crt.h"
@@ -13477,13 +13476,22 @@ void intel_display_resume(struct drm_device *dev)
if (state)
state->acquire_ctx = 
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_acquire_init(, 0);
 
-   ret = __intel_display_resume(dev, state, );
+   while (1) {
+   ret = drm_modeset_lock_all_ctx(dev, );
+   if (ret != -EDEADLK)
+   break;
 
-   intel_enable_ipc(dev_priv);
+   drm_modeset_backoff();
+   }
+
+   if (!ret)
+   ret = __intel_display_resume(dev, state, );
 
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   intel_enable_ipc(dev_priv);
+   drm_modeset_drop_locks();
+   drm_modeset_acquire_fini();
 
if (ret)
drm_err(_priv->drm,
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 13/16] Revert "drm: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 7c5f2eecc21f44fba1b1f13ce09c2533db9d781a.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/drm_client_modeset.c |  5 ++---
 drivers/gpu/drm/drm_crtc_helper.c| 18 ++
 drivers/gpu/drm/drm_fb_helper.c  | 10 --
 drivers/gpu/drm/drm_framebuffer.c|  6 ++
 4 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/drm_client_modeset.c 
b/drivers/gpu/drm/drm_client_modeset.c
index 43f772543d2a..5f5184f071ed 100644
--- a/drivers/gpu/drm/drm_client_modeset.c
+++ b/drivers/gpu/drm/drm_client_modeset.c
@@ -1062,10 +1062,9 @@ static int drm_client_modeset_commit_legacy(struct 
drm_client_dev *client)
struct drm_device *dev = client->dev;
struct drm_mode_set *mode_set;
struct drm_plane *plane;
-   struct drm_modeset_acquire_ctx ctx;
int ret = 0;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
drm_for_each_plane(plane, dev) {
if (plane->type != DRM_PLANE_TYPE_PRIMARY)
drm_plane_force_disable(plane);
@@ -1094,7 +1093,7 @@ static int drm_client_modeset_commit_legacy(struct 
drm_client_dev *client)
goto out;
}
 out:
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
 
return ret;
 }
diff --git a/drivers/gpu/drm/drm_crtc_helper.c 
b/drivers/gpu/drm/drm_crtc_helper.c
index f3ce073dff79..bff917531f33 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -218,14 +218,11 @@ static void __drm_helper_disable_unused_functions(struct 
drm_device *dev)
  */
 void drm_helper_disable_unused_functions(struct drm_device *dev)
 {
-   struct drm_modeset_acquire_ctx ctx;
-   int ret;
-
WARN_ON(drm_drv_uses_atomic_modeset(dev));
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
__drm_helper_disable_unused_functions(dev);
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
 }
 EXPORT_SYMBOL(drm_helper_disable_unused_functions);
 
@@ -945,14 +942,12 @@ void drm_helper_resume_force_mode(struct drm_device *dev)
struct drm_crtc *crtc;
struct drm_encoder *encoder;
const struct drm_crtc_helper_funcs *crtc_funcs;
-   struct drm_modeset_acquire_ctx ctx;
int encoder_dpms;
bool ret;
-   int err;
 
WARN_ON(drm_drv_uses_atomic_modeset(dev));
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err);
+   drm_modeset_lock_all(dev);
drm_for_each_crtc(crtc, dev) {
 
if (!crtc->enabled)
@@ -987,7 +982,7 @@ void drm_helper_resume_force_mode(struct drm_device *dev)
 
/* disable the unused connectors while restoring the modesetting */
__drm_helper_disable_unused_functions(dev);
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, err);
+   drm_modeset_unlock_all(dev);
 }
 EXPORT_SYMBOL(drm_helper_resume_force_mode);
 
@@ -1007,10 +1002,9 @@ EXPORT_SYMBOL(drm_helper_resume_force_mode);
 int drm_helper_force_disable_all(struct drm_device *dev)
 {
struct drm_crtc *crtc;
-   struct drm_modeset_acquire_ctx ctx;
int ret = 0;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
drm_for_each_crtc(crtc, dev)
if (crtc->enabled) {
struct drm_mode_set set = {
@@ -1022,7 +1016,7 @@ int drm_helper_force_disable_all(struct drm_device *dev)
goto out;
}
 out:
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
return ret;
 }
 EXPORT_SYMBOL(drm_helper_force_disable_all);
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 6860223f0068..3ab078321045 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -940,11 +940,10 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct 
fb_info *info)
struct drm_fb_helper *fb_helper = info->par;
struct drm_mode_set *modeset;
struct drm_crtc *crtc;
-   struct drm_modeset_acquire_ctx ctx;
u16 *r, *g, *b;
int ret = 0;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(fb_helper->dev, ctx, 0, ret);
+   drm_modeset_lock_all(fb_helper->dev);
drm_client_for_each_modeset(modeset, _helper->client) {
crtc = modeset->crtc;
if (!crtc->funcs->gamma_set || !crtc->gamma_size) {
@@ -971,7 +970,7 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct 
fb_info *info)
goto out;
}
 out:
-   DRM_MODESET_LOCK_ALL_END(fb_helper->dev, ctx, ret);
+   drm_modeset_unlock_all(fb_helper->dev);
 
return ret;
 }
@@ -1442,11 +1441,10 @@ static int 

[PATCH 14/16] Revert "drm/msm: cleanup: drm_modeset_lock_all_ctx() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 4c048437ef7adb2d81fe4ddc5c04179126eefcf2.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c 
b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c
index abda52f09b09..cabe15190ec1 100644
--- a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c
+++ b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c
@@ -5,8 +5,6 @@
 
 #define pr_fmt(fmt)"[drm:%s:%d] " fmt, __func__, __LINE__
 
-#include 
-
 #include "msm_disp_snapshot.h"
 
 static void msm_disp_state_dump_regs(u32 **reg, u32 aligned_len, void __iomem 
*base_addr)
@@ -101,18 +99,20 @@ static void msm_disp_capture_atomic_state(struct 
msm_disp_state *disp_state)
 {
struct drm_device *ddev;
struct drm_modeset_acquire_ctx ctx;
-   int ret;
 
disp_state->timestamp = ktime_get();
 
ddev = disp_state->drm_dev;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(ddev, ctx, 0, ret);
+   drm_modeset_acquire_init(, 0);
+
+   while (drm_modeset_lock_all_ctx(ddev, ) != 0)
+   drm_modeset_backoff();
 
disp_state->atomic_state = drm_atomic_helper_duplicate_state(ddev,
);
-
-   DRM_MODESET_LOCK_ALL_END(ddev, ctx, ret);
+   drm_modeset_drop_locks();
+   drm_modeset_acquire_fini();
 }
 
 void msm_disp_snapshot_capture_state(struct msm_disp_state *disp_state)
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 12/16] Revert "drm/vmwgfx: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 6b92e77156c5adf6606c8ad825c71404417d88af.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c | 11 ---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   | 12 
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
index 7df35c6f1458..28af34ab6ed6 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
@@ -28,7 +28,6 @@
 #include "vmwgfx_drv.h"
 #include "vmwgfx_devcaps.h"
 #include 
-#include 
 #include "vmwgfx_kms.h"
 
 int vmw_getparam_ioctl(struct drm_device *dev, void *data,
@@ -173,7 +172,6 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
struct drm_vmw_rect __user *clips_ptr;
struct drm_vmw_rect *clips = NULL;
struct drm_framebuffer *fb;
-   struct drm_modeset_acquire_ctx ctx;
struct vmw_framebuffer *vfb;
struct vmw_resource *res;
uint32_t num_clips;
@@ -205,7 +203,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
goto out_no_copy;
}
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
 
fb = drm_framebuffer_lookup(dev, file_priv, arg->fb_id);
if (!fb) {
@@ -233,7 +231,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
 out_no_surface:
drm_framebuffer_put(fb);
 out_no_fb:
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
 out_no_copy:
kfree(clips);
 out_clips:
@@ -252,7 +250,6 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void 
*data,
struct drm_vmw_rect __user *clips_ptr;
struct drm_vmw_rect *clips = NULL;
struct drm_framebuffer *fb;
-   struct drm_modeset_acquire_ctx ctx;
struct vmw_framebuffer *vfb;
uint32_t num_clips;
int ret;
@@ -283,7 +280,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void 
*data,
goto out_no_copy;
}
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
 
fb = drm_framebuffer_lookup(dev, file_priv, arg->fb_id);
if (!fb) {
@@ -306,7 +303,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void 
*data,
 out_no_ttm_lock:
drm_framebuffer_put(fb);
 out_no_fb:
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
 out_no_copy:
kfree(clips);
 out_clips:
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 268095cb8c84..74fa41909213 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -33,7 +33,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "vmwgfx_kms.h"
 
@@ -244,17 +243,15 @@ void vmw_kms_legacy_hotspot_clear(struct vmw_private 
*dev_priv)
struct drm_device *dev = _priv->drm;
struct vmw_display_unit *du;
struct drm_crtc *crtc;
-   struct drm_modeset_acquire_ctx ctx;
-   int ret;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
drm_for_each_crtc(crtc, dev) {
du = vmw_crtc_to_du(crtc);
 
du->hotspot_x = 0;
du->hotspot_y = 0;
}
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
 }
 
 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv)
@@ -1015,10 +1012,9 @@ static int vmw_framebuffer_bo_dirty(struct 
drm_framebuffer *framebuffer,
struct vmw_framebuffer_bo *vfbd =
vmw_framebuffer_to_vfbd(framebuffer);
struct drm_clip_rect norect;
-   struct drm_modeset_acquire_ctx ctx;
int ret, increment = 1;
 
-   DRM_MODESET_LOCK_ALL_BEGIN((_priv->drm), ctx, 0, ret);
+   drm_modeset_lock_all(_priv->drm);
 
if (!num_clips) {
num_clips = 1;
@@ -1044,7 +1040,7 @@ static int vmw_framebuffer_bo_dirty(struct 
drm_framebuffer *framebuffer,
 
vmw_cmd_flush(dev_priv, false);
 
-   DRM_MODESET_LOCK_ALL_END((_priv->drm), ctx, ret);
+   drm_modeset_unlock_all(_priv->drm);
 
return ret;
 }
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 11/16] Revert "drm/tegra: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit a2cd9947d99b54c959fce20dc19d81af53f4674e.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/tegra/dsi.c  |  6 ++
 drivers/gpu/drm/tegra/hdmi.c |  6 ++
 drivers/gpu/drm/tegra/sor.c  | 11 ---
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
index 28050c188c1c..f46d377f0c30 100644
--- a/drivers/gpu/drm/tegra/dsi.c
+++ b/drivers/gpu/drm/tegra/dsi.c
@@ -23,7 +23,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "dc.h"
 #include "drm.h"
@@ -203,11 +202,10 @@ static int tegra_dsi_show_regs(struct seq_file *s, void 
*data)
struct tegra_dsi *dsi = node->info_ent->data;
struct drm_crtc *crtc = dsi->output.encoder.crtc;
struct drm_device *drm = node->minor->dev;
-   struct drm_modeset_acquire_ctx ctx;
unsigned int i;
int err = 0;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(drm, ctx, 0, err);
+   drm_modeset_lock_all(drm);
 
if (!crtc || !crtc->state->active) {
err = -EBUSY;
@@ -222,7 +220,7 @@ static int tegra_dsi_show_regs(struct seq_file *s, void 
*data)
}
 
 unlock:
-   DRM_MODESET_LOCK_ALL_END(drm, ctx, err);
+   drm_modeset_unlock_all(drm);
return err;
 }
 
diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
index a62de7f92414..e5d2a4026028 100644
--- a/drivers/gpu/drm/tegra/hdmi.c
+++ b/drivers/gpu/drm/tegra/hdmi.c
@@ -22,7 +22,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "hda.h"
 #include "hdmi.h"
@@ -1032,11 +1031,10 @@ static int tegra_hdmi_show_regs(struct seq_file *s, 
void *data)
struct tegra_hdmi *hdmi = node->info_ent->data;
struct drm_crtc *crtc = hdmi->output.encoder.crtc;
struct drm_device *drm = node->minor->dev;
-   struct drm_modeset_acquire_ctx ctx;
unsigned int i;
int err = 0;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(drm, ctx, 0, err);
+   drm_modeset_lock_all(drm);
 
if (!crtc || !crtc->state->active) {
err = -EBUSY;
@@ -1051,7 +1049,7 @@ static int tegra_hdmi_show_regs(struct seq_file *s, void 
*data)
}
 
 unlock:
-   DRM_MODESET_LOCK_ALL_END(drm, ctx, err);
+   drm_modeset_unlock_all(drm);
return err;
 }
 
diff --git a/drivers/gpu/drm/tegra/sor.c b/drivers/gpu/drm/tegra/sor.c
index 3d1c8b3d1358..0ea320c1092b 100644
--- a/drivers/gpu/drm/tegra/sor.c
+++ b/drivers/gpu/drm/tegra/sor.c
@@ -23,7 +23,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "dc.h"
 #include "dp.h"
@@ -1491,11 +1490,10 @@ static int tegra_sor_show_crc(struct seq_file *s, void 
*data)
struct tegra_sor *sor = node->info_ent->data;
struct drm_crtc *crtc = sor->output.encoder.crtc;
struct drm_device *drm = node->minor->dev;
-   struct drm_modeset_acquire_ctx ctx;
int err = 0;
u32 value;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(drm, ctx, 0, err);
+   drm_modeset_lock_all(drm);
 
if (!crtc || !crtc->state->active) {
err = -EBUSY;
@@ -1524,7 +1522,7 @@ static int tegra_sor_show_crc(struct seq_file *s, void 
*data)
seq_printf(s, "%08x\n", value);
 
 unlock:
-   DRM_MODESET_LOCK_ALL_END(drm, ctx, err);
+   drm_modeset_unlock_all(drm);
return err;
 }
 
@@ -1654,11 +1652,10 @@ static int tegra_sor_show_regs(struct seq_file *s, void 
*data)
struct tegra_sor *sor = node->info_ent->data;
struct drm_crtc *crtc = sor->output.encoder.crtc;
struct drm_device *drm = node->minor->dev;
-   struct drm_modeset_acquire_ctx ctx;
unsigned int i;
int err = 0;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(drm, ctx, 0, err);
+   drm_modeset_lock_all(drm);
 
if (!crtc || !crtc->state->active) {
err = -EBUSY;
@@ -1673,7 +1670,7 @@ static int tegra_sor_show_regs(struct seq_file *s, void 
*data)
}
 
 unlock:
-   DRM_MODESET_LOCK_ALL_END(drm, ctx, err);
+   drm_modeset_unlock_all(drm);
return err;
 }
 
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 10/16] Revert "drm/shmobile: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 9b8c437ef1a5f34686fc96b391c201a80f1a2ea0.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/shmobile/shmob_drm_drv.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/shmobile/shmob_drm_drv.c 
b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
index 8ee215ab614e..7db01904d18d 100644
--- a/drivers/gpu/drm/shmobile/shmob_drm_drv.c
+++ b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
@@ -156,12 +156,10 @@ static int shmob_drm_pm_suspend(struct device *dev)
 static int shmob_drm_pm_resume(struct device *dev)
 {
struct shmob_drm_device *sdev = dev_get_drvdata(dev);
-   struct drm_modeset_acquire_ctx ctx;
-   int ret;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(sdev->ddev, ctx, 0, ret);
+   drm_modeset_lock_all(sdev->ddev);
shmob_drm_crtc_resume(>crtc);
-   DRM_MODESET_LOCK_ALL_END(sdev->ddev, ctx, ret);
+   drm_modeset_unlock_all(sdev->ddev);
 
drm_kms_helper_poll_enable(sdev->ddev);
return 0;
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 09/16] Revert "drm/radeon: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 26723c3d6b930775f9a85521d09655c533a839e6.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/radeon/radeon_device.c | 21 ++---
 drivers/gpu/drm/radeon/radeon_dp_mst.c | 10 --
 2 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_device.c 
b/drivers/gpu/drm/radeon/radeon_device.c
index 7e31e5ce7f61..4f0fbf667431 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -37,7 +37,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -1560,8 +1559,7 @@ int radeon_suspend_kms(struct drm_device *dev, bool 
suspend,
struct pci_dev *pdev;
struct drm_crtc *crtc;
struct drm_connector *connector;
-   struct drm_modeset_acquire_ctx ctx;
-   int i, r, ret;
+   int i, r;
 
if (dev == NULL || dev->dev_private == NULL) {
return -ENODEV;
@@ -1575,15 +1573,12 @@ int radeon_suspend_kms(struct drm_device *dev, bool 
suspend,
 
drm_kms_helper_poll_disable(dev);
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
/* turn off display hw */
list_for_each_entry(connector, >mode_config.connector_list, head) {
drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
}
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
-
-   if (ret)
-   return ret;
+   drm_modeset_unlock_all(dev);
 
/* unpin the front buffers and cursors */
list_for_each_entry(crtc, >mode_config.crtc_list, head) {
@@ -1668,8 +1663,7 @@ int radeon_resume_kms(struct drm_device *dev, bool 
resume, bool fbcon)
struct radeon_device *rdev = dev->dev_private;
struct pci_dev *pdev = to_pci_dev(dev->dev);
struct drm_crtc *crtc;
-   struct drm_modeset_acquire_ctx ctx;
-   int r, ret;
+   int r;
 
if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
return 0;
@@ -1747,14 +1741,11 @@ int radeon_resume_kms(struct drm_device *dev, bool 
resume, bool fbcon)
if (fbcon) {
drm_helper_resume_force_mode(dev);
/* turn on display hw */
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
list_for_each_entry(connector, 
>mode_config.connector_list, head) {
drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
}
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
-
-   if (ret)
-   return ret;
+   drm_modeset_unlock_all(dev);
}
 
drm_kms_helper_poll_enable(dev);
diff --git a/drivers/gpu/drm/radeon/radeon_dp_mst.c 
b/drivers/gpu/drm/radeon/radeon_dp_mst.c
index 3f83ee75b100..ec867fa880a4 100644
--- a/drivers/gpu/drm/radeon/radeon_dp_mst.c
+++ b/drivers/gpu/drm/radeon/radeon_dp_mst.c
@@ -4,7 +4,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "atom.h"
 #include "ni_reg.h"
@@ -738,12 +737,11 @@ static int radeon_debugfs_mst_info_show(struct seq_file 
*m, void *unused)
struct radeon_device *rdev = (struct radeon_device *)m->private;
struct drm_device *dev = rdev->ddev;
struct drm_connector *connector;
-   struct drm_modeset_acquire_ctx ctx;
struct radeon_connector *radeon_connector;
struct radeon_connector_atom_dig *dig_connector;
-   int i, ret;
+   int i;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
list_for_each_entry(connector, >mode_config.connector_list, head) {
if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
continue;
@@ -761,8 +759,8 @@ static int radeon_debugfs_mst_info_show(struct seq_file *m, 
void *unused)
   radeon_connector->cur_stream_attribs[i].fe,
   
radeon_connector->cur_stream_attribs[i].slots);
}
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
-   return ret;
+   drm_modeset_unlock_all(dev);
+   return 0;
 }
 
 DEFINE_SHOW_ATTRIBUTE(radeon_debugfs_mst_info);
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 08/16] Revert "drm/omapdrm: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 6067fddc1a4fdf155787ab6182c192e4b360b73c.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/omapdrm/omap_fb.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c 
b/drivers/gpu/drm/omapdrm/omap_fb.c
index fa7636c13c19..190afc564914 100644
--- a/drivers/gpu/drm/omapdrm/omap_fb.c
+++ b/drivers/gpu/drm/omapdrm/omap_fb.c
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "omap_dmm_tiler.h"
 #include "omap_drv.h"
@@ -63,17 +62,15 @@ static int omap_framebuffer_dirty(struct drm_framebuffer 
*fb,
  unsigned num_clips)
 {
struct drm_crtc *crtc;
-   struct drm_modeset_acquire_ctx ctx;
-   int ret;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(fb->dev, ctx, 0, ret);
+   drm_modeset_lock_all(fb->dev);
 
drm_for_each_crtc(crtc, fb->dev)
omap_crtc_flush(crtc);
 
-   DRM_MODESET_LOCK_ALL_END(fb->dev, ctx, ret);
+   drm_modeset_unlock_all(fb->dev);
 
-   return ret;
+   return 0;
 }
 
 static const struct drm_framebuffer_funcs omap_framebuffer_funcs = {
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 07/16] Revert "drm/nouveau: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 6aa2daae589b63e8b39fe6f7f2b59fb3063efa05.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/nouveau/dispnv50/disp.c | 15 +--
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c 
b/drivers/gpu/drm/nouveau/dispnv50/disp.c
index 86e18a844953..d7b9f7f8c9e3 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
@@ -42,7 +42,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 
@@ -668,18 +667,16 @@ nv50_audio_component_bind(struct device *kdev, struct 
device *hda_kdev,
struct drm_device *drm_dev = dev_get_drvdata(kdev);
struct nouveau_drm *drm = nouveau_drm(drm_dev);
struct drm_audio_component *acomp = data;
-   struct drm_modeset_acquire_ctx ctx;
-   int ret;
 
if (WARN_ON(!device_link_add(hda_kdev, kdev, DL_FLAG_STATELESS)))
return -ENOMEM;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(drm_dev, ctx, 0, ret);
+   drm_modeset_lock_all(drm_dev);
acomp->ops = _audio_component_ops;
acomp->dev = kdev;
drm->audio.component = acomp;
-   DRM_MODESET_LOCK_ALL_END(drm_dev, ctx, ret);
-   return ret;
+   drm_modeset_unlock_all(drm_dev);
+   return 0;
 }
 
 static void
@@ -689,14 +686,12 @@ nv50_audio_component_unbind(struct device *kdev, struct 
device *hda_kdev,
struct drm_device *drm_dev = dev_get_drvdata(kdev);
struct nouveau_drm *drm = nouveau_drm(drm_dev);
struct drm_audio_component *acomp = data;
-   struct drm_modeset_acquire_ctx ctx;
-   int ret;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(drm_dev, ctx, 0, ret);
+   drm_modeset_lock_all(drm_dev);
drm->audio.component = NULL;
acomp->ops = NULL;
acomp->dev = NULL;
-   DRM_MODESET_LOCK_ALL_END(drm_dev, ctx, ret);
+   drm_modeset_unlock_all(drm_dev);
 }
 
 static const struct component_ops nv50_audio_component_bind_ops = {
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 06/16] Revert "drm/msm: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit fd49ef52e2db015ce69ad02bab0702489d141a41.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
index b89687074890..768012243b44 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
@@ -18,7 +18,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "dpu_kms.h"
 #include "dpu_hw_lm.h"
@@ -1173,15 +1172,14 @@ static int _dpu_debugfs_status_show(struct seq_file *s, 
void *data)
struct drm_display_mode *mode;
struct drm_framebuffer *fb;
struct drm_plane_state *state;
-   struct drm_modeset_acquire_ctx ctx;
struct dpu_crtc_state *cstate;
 
-   int i, out_width, ret;
+   int i, out_width;
 
dpu_crtc = s->private;
crtc = _crtc->base;
 
-   DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, ret);
+   drm_modeset_lock_all(crtc->dev);
cstate = to_dpu_crtc_state(crtc->state);
 
mode = >state->adjusted_mode;
@@ -1265,9 +1263,9 @@ static int _dpu_debugfs_status_show(struct seq_file *s, 
void *data)
dpu_crtc->vblank_cb_time = ktime_set(0, 0);
}
 
-   DRM_MODESET_LOCK_ALL_END(crtc->dev, ctx, ret);
+   drm_modeset_unlock_all(crtc->dev);
 
-   return ret;
+   return 0;
 }
 
 DEFINE_SHOW_ATTRIBUTE(_dpu_debugfs_status);
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 05/16] Revert "drm/i915: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 746826bcf8fdf682668ff1c415d6b91dbf5858be.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/i915/display/intel_audio.c| 16 +++
 drivers/gpu/drm/i915/display/intel_display.c  |  5 +-
 .../drm/i915/display/intel_display_debugfs.c  | 46 +++
 drivers/gpu/drm/i915/display/intel_overlay.c  |  6 +--
 drivers/gpu/drm/i915/display/intel_pipe_crc.c |  7 +--
 drivers/gpu/drm/i915/i915_drv.c   | 13 ++
 6 files changed, 32 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_audio.c 
b/drivers/gpu/drm/i915/display/intel_audio.c
index c64f738cc062..532237588511 100644
--- a/drivers/gpu/drm/i915/display/intel_audio.c
+++ b/drivers/gpu/drm/i915/display/intel_audio.c
@@ -26,7 +26,6 @@
 
 #include 
 #include 
-#include 
 
 #include "i915_drv.h"
 #include "intel_atomic.h"
@@ -1215,8 +1214,7 @@ static int i915_audio_component_bind(struct device 
*i915_kdev,
 {
struct i915_audio_component *acomp = data;
struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev);
-   struct drm_modeset_acquire_ctx ctx;
-   int i, ret;
+   int i;
 
if (drm_WARN_ON(_priv->drm, acomp->base.ops || acomp->base.dev))
return -EEXIST;
@@ -1226,16 +1224,16 @@ static int i915_audio_component_bind(struct device 
*i915_kdev,
 DL_FLAG_STATELESS)))
return -ENOMEM;
 
-   DRM_MODESET_LOCK_ALL_BEGIN((_priv->drm), ctx, 0, ret);
+   drm_modeset_lock_all(_priv->drm);
acomp->base.ops = _audio_component_ops;
acomp->base.dev = i915_kdev;
BUILD_BUG_ON(MAX_PORTS != I915_MAX_PORTS);
for (i = 0; i < ARRAY_SIZE(acomp->aud_sample_rate); i++)
acomp->aud_sample_rate[i] = 0;
dev_priv->audio_component = acomp;
-   DRM_MODESET_LOCK_ALL_END((_priv->drm), ctx, ret);
+   drm_modeset_unlock_all(_priv->drm);
 
-   return ret;
+   return 0;
 }
 
 static void i915_audio_component_unbind(struct device *i915_kdev,
@@ -1243,14 +1241,12 @@ static void i915_audio_component_unbind(struct device 
*i915_kdev,
 {
struct i915_audio_component *acomp = data;
struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev);
-   struct drm_modeset_acquire_ctx ctx;
-   int ret;
 
-   DRM_MODESET_LOCK_ALL_BEGIN((_priv->drm), ctx, 0, ret);
+   drm_modeset_lock_all(_priv->drm);
acomp->base.ops = NULL;
acomp->base.dev = NULL;
dev_priv->audio_component = NULL;
-   DRM_MODESET_LOCK_ALL_END((_priv->drm), ctx, ret);
+   drm_modeset_unlock_all(_priv->drm);
 
device_link_remove(hda_kdev, i915_kdev);
 
diff --git a/drivers/gpu/drm/i915/display/intel_display.c 
b/drivers/gpu/drm/i915/display/intel_display.c
index 297359411c5f..2bf01416d656 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -12512,7 +12512,6 @@ int intel_modeset_init_noirq(struct drm_i915_private 
*i915)
 int intel_modeset_init_nogem(struct drm_i915_private *i915)
 {
struct drm_device *dev = >drm;
-   struct drm_modeset_acquire_ctx ctx;
enum pipe pipe;
struct intel_crtc *crtc;
int ret;
@@ -12564,9 +12563,9 @@ int intel_modeset_init_nogem(struct drm_i915_private 
*i915)
intel_vga_disable(i915);
intel_setup_outputs(i915);
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
 
for_each_intel_crtc(dev, crtc) {
struct intel_initial_plane_config plane_config = {};
diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c 
b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
index e0a6837996e7..8fdacb252bb1 100644
--- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c
+++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
@@ -5,7 +5,6 @@
 
 #include 
 #include 
-#include 
 
 #include "i915_debugfs.h"
 #include "intel_display_debugfs.h"
@@ -1058,13 +1057,11 @@ static int i915_display_info(struct seq_file *m, void 
*unused)
struct intel_crtc *crtc;
struct drm_connector *connector;
struct drm_connector_list_iter conn_iter;
-   struct drm_modeset_acquire_ctx ctx;
intel_wakeref_t wakeref;
-   int ret;
 
wakeref = intel_runtime_pm_get(_priv->runtime_pm);
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
 
seq_printf(m, "CRTC info\n");
seq_printf(m, "-\n");
@@ -1079,21 +1076,20 @@ static int i915_display_info(struct seq_file *m, void 
*unused)
intel_connector_info(m, connector);

[PATCH 04/16] Revert "drm/i915: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN() part 2"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 984c9949f1c4cf36c35aa2de5ee2b65c39379fd9.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/i915/display/intel_overlay.c | 40 ++--
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_overlay.c 
b/drivers/gpu/drm/i915/display/intel_overlay.c
index c623738c59c8..c0ee135e5499 100644
--- a/drivers/gpu/drm/i915/display/intel_overlay.c
+++ b/drivers/gpu/drm/i915/display/intel_overlay.c
@@ -1105,7 +1105,6 @@ int intel_overlay_put_image_ioctl(struct drm_device *dev, 
void *data,
struct drm_crtc *drmmode_crtc;
struct intel_crtc *crtc;
struct drm_i915_gem_object *new_bo;
-   struct drm_modeset_acquire_ctx ctx;
int ret;
 
overlay = dev_priv->overlay;
@@ -1114,24 +1113,24 @@ int intel_overlay_put_image_ioctl(struct drm_device 
*dev, void *data,
return -ENODEV;
}
 
-   if (params->flags & I915_OVERLAY_ENABLE) {
-
-   drmmode_crtc = drm_crtc_find(dev, file_priv, params->crtc_id);
-   if (!drmmode_crtc)
-   return -ENOENT;
-   crtc = to_intel_crtc(drmmode_crtc);
+   if (!(params->flags & I915_OVERLAY_ENABLE)) {
+   drm_modeset_lock_all(dev);
+   ret = intel_overlay_switch_off(overlay);
+   drm_modeset_unlock_all(dev);
 
-   new_bo = i915_gem_object_lookup(file_priv, params->bo_handle);
-   if (!new_bo)
-   return -ENOENT;
+   return ret;
}
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drmmode_crtc = drm_crtc_find(dev, file_priv, params->crtc_id);
+   if (!drmmode_crtc)
+   return -ENOENT;
+   crtc = to_intel_crtc(drmmode_crtc);
 
-   if (!(params->flags & I915_OVERLAY_ENABLE)) {
-   ret = intel_overlay_switch_off(overlay);
-   goto out_unlock;
-   }
+   new_bo = i915_gem_object_lookup(file_priv, params->bo_handle);
+   if (!new_bo)
+   return -ENOENT;
+
+   drm_modeset_lock_all(dev);
 
if (i915_gem_object_is_tiled(new_bo)) {
drm_dbg_kms(_priv->drm,
@@ -1196,11 +1195,14 @@ int intel_overlay_put_image_ioctl(struct drm_device 
*dev, void *data,
if (ret != 0)
goto out_unlock;
 
-out_unlock:
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
+   i915_gem_object_put(new_bo);
+
+   return 0;
 
-   if (params->flags & I915_OVERLAY_ENABLE)
-   i915_gem_object_put(new_bo);
+out_unlock:
+   drm_modeset_unlock_all(dev);
+   i915_gem_object_put(new_bo);
 
return ret;
 }
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 03/16] Revert "drm/gma500: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 4f9e860e6ad65ff4ea8ce165a1407d96ff1b2211.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/gma500/psb_device.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/gma500/psb_device.c 
b/drivers/gpu/drm/gma500/psb_device.c
index 021a7238508f..3030f18ba022 100644
--- a/drivers/gpu/drm/gma500/psb_device.c
+++ b/drivers/gpu/drm/gma500/psb_device.c
@@ -8,7 +8,6 @@
 #include 
 
 #include 
-#include 
 
 #include "gma_device.h"
 #include "intel_bios.h"
@@ -170,10 +169,8 @@ static int psb_save_display_registers(struct drm_device 
*dev)
 {
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
struct drm_crtc *crtc;
-   struct drm_modeset_acquire_ctx ctx;
struct gma_connector *connector;
struct psb_state *regs = _priv->regs.psb;
-   int ret;
 
/* Display arbitration control + watermarks */
regs->saveDSPARB = PSB_RVDC32(DSPARB);
@@ -186,7 +183,7 @@ static int psb_save_display_registers(struct drm_device 
*dev)
regs->saveCHICKENBIT = PSB_RVDC32(DSPCHICKENBIT);
 
/* Save crtc and output state */
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
list_for_each_entry(crtc, >mode_config.crtc_list, head) {
if (drm_helper_crtc_in_use(crtc))
dev_priv->ops->save_crtc(crtc);
@@ -196,9 +193,8 @@ static int psb_save_display_registers(struct drm_device 
*dev)
if (connector->save)
connector->save(>base);
 
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
-
-   return ret;
+   drm_modeset_unlock_all(dev);
+   return 0;
 }
 
 /**
@@ -211,10 +207,8 @@ static int psb_restore_display_registers(struct drm_device 
*dev)
 {
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
struct drm_crtc *crtc;
-   struct drm_modeset_acquire_ctx ctx;
struct gma_connector *connector;
struct psb_state *regs = _priv->regs.psb;
-   int ret;
 
/* Display arbitration + watermarks */
PSB_WVDC32(regs->saveDSPARB, DSPARB);
@@ -229,7 +223,7 @@ static int psb_restore_display_registers(struct drm_device 
*dev)
/*make sure VGA plane is off. it initializes to on after reset!*/
PSB_WVDC32(0x8000, VGACNTRL);
 
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
list_for_each_entry(crtc, >mode_config.crtc_list, head)
if (drm_helper_crtc_in_use(crtc))
dev_priv->ops->restore_crtc(crtc);
@@ -238,8 +232,8 @@ static int psb_restore_display_registers(struct drm_device 
*dev)
if (connector->restore)
connector->restore(>base);
 
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
-   return ret;
+   drm_modeset_unlock_all(dev);
+   return 0;
 }
 
 static int psb_power_down(struct drm_device *dev)
-- 
Sean Paul, Software Engineer, Google / Chromium OS



[PATCH 02/16] Revert "drm/amd: cleanup: drm_modeset_lock_all() --> DRM_MODESET_LOCK_ALL_BEGIN()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 299f040e855b69c29522cde446777902381a07f5.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c   | 21 +++-
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 50 +--
 .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 25 --
 3 files changed, 43 insertions(+), 53 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index b07e845a2600..7a7316731911 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -40,7 +40,6 @@
 #include 
 #include 
 #include 
-#include 
 
 static void amdgpu_display_flip_callback(struct dma_fence *f,
 struct dma_fence_cb *cb)
@@ -1544,21 +1543,16 @@ int amdgpu_display_suspend_helper(struct amdgpu_device 
*adev)
struct drm_crtc *crtc;
struct drm_connector *connector;
struct drm_connector_list_iter iter;
-   struct drm_modeset_acquire_ctx ctx;
-   int r, ret;
+   int r;
 
/* turn off display hw */
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
drm_connector_list_iter_begin(dev, );
drm_for_each_connector_iter(connector, )
drm_helper_connector_dpms(connector,
  DRM_MODE_DPMS_OFF);
drm_connector_list_iter_end();
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
-
-   if (ret)
-   return ret;
-
+   drm_modeset_unlock_all(dev);
/* unpin the front buffers and cursors */
list_for_each_entry(crtc, >mode_config.crtc_list, head) {
struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
@@ -1596,8 +1590,7 @@ int amdgpu_display_resume_helper(struct amdgpu_device 
*adev)
struct drm_connector *connector;
struct drm_connector_list_iter iter;
struct drm_crtc *crtc;
-   struct drm_modeset_acquire_ctx ctx;
-   int r, ret;
+   int r;
 
/* pin cursors */
list_for_each_entry(crtc, >mode_config.crtc_list, head) {
@@ -1619,7 +1612,7 @@ int amdgpu_display_resume_helper(struct amdgpu_device 
*adev)
drm_helper_resume_force_mode(dev);
 
/* turn on display hw */
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
+   drm_modeset_lock_all(dev);
 
drm_connector_list_iter_begin(dev, );
drm_for_each_connector_iter(connector, )
@@ -1627,8 +1620,8 @@ int amdgpu_display_resume_helper(struct amdgpu_device 
*adev)
  DRM_MODE_DPMS_ON);
drm_connector_list_iter_end();
 
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
+   drm_modeset_unlock_all(dev);
 
-   return ret;
+   return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 5196c1d26f87..9b1fc54555ee 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -80,7 +80,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #if defined(CONFIG_DRM_AMD_DC_DCN)
 #include "ivsrcid/dcn/irqsrcs_dcn_1_0.h"
@@ -2622,9 +2621,6 @@ static void handle_hpd_irq(void *param)
 #ifdef CONFIG_DRM_AMD_DC_HDCP
struct dm_connector_state *dm_con_state = 
to_dm_connector_state(connector->state);
 #endif
-   struct drm_modeset_acquire_ctx ctx;
-   int ret;
-
 
if (adev->dm.disable_hpd_irq)
return;
@@ -2650,6 +2646,14 @@ static void handle_hpd_irq(void *param)
if (aconnector->base.force && new_connection_type == 
dc_connection_none) {
emulated_link_detect(aconnector->dc_link);
 
+
+   drm_modeset_lock_all(dev);
+   dm_restore_drm_connector_state(dev, connector);
+   drm_modeset_unlock_all(dev);
+
+   if (aconnector->base.force == DRM_FORCE_UNSPECIFIED)
+   drm_kms_helper_hotplug_event(dev);
+
} else if (dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD)) {
if (new_connection_type == dc_connection_none &&
aconnector->dc_link->type == dc_connection_none)
@@ -2657,18 +2661,13 @@ static void handle_hpd_irq(void *param)
 
amdgpu_dm_update_connector_after_detect(aconnector);
 
-   } else {
-   goto out;
-   }
-
-   DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
-   dm_restore_drm_connector_state(dev, connector);
-   DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
-
-   if (aconnector->base.force == DRM_FORCE_UNSPECIFIED)
-   drm_kms_helper_hotplug_event(dev);
+   drm_modeset_lock_all(dev);
+   dm_restore_drm_connector_state(dev, connector);
+   drm_modeset_unlock_all(dev);
 
-out:
+  

[PATCH 01/16] Revert "drm: cleanup: remove drm_modeset_(un)lock_all()"

2021-10-02 Thread Sean Paul
From: Sean Paul 

This reverts commit 8d813d1a535c8c7503a5f4061654a73026be8c5e.

This patchset breaks on intel platforms and was previously NACK'd by
Ville.

Cc: Ville Syrjälä 
Cc: Fernando Ramos 
Signed-off-by: Sean Paul 
---
 drivers/gpu/drm/drm_modeset_lock.c | 94 +-
 include/drm/drm_modeset_lock.h |  2 +
 2 files changed, 93 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_modeset_lock.c 
b/drivers/gpu/drm/drm_modeset_lock.c
index afd1351749a5..fcfe1a03c4a1 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -77,6 +77,93 @@
 
 static DEFINE_WW_CLASS(crtc_ww_class);
 
+/**
+ * drm_modeset_lock_all - take all modeset locks
+ * @dev: DRM device
+ *
+ * This function takes all modeset locks, suitable where a more fine-grained
+ * scheme isn't (yet) implemented. Locks must be dropped by calling the
+ * drm_modeset_unlock_all() function.
+ *
+ * This function is deprecated. It allocates a lock acquisition context and
+ * stores it in _device.mode_config. This facilitate conversion of
+ * existing code because it removes the need to manually deal with the
+ * acquisition context, but it is also brittle because the context is global
+ * and care must be taken not to nest calls. New code should use the
+ * drm_modeset_lock_all_ctx() function and pass in the context explicitly.
+ */
+void drm_modeset_lock_all(struct drm_device *dev)
+{
+   struct drm_mode_config *config = >mode_config;
+   struct drm_modeset_acquire_ctx *ctx;
+   int ret;
+
+   ctx = kzalloc(sizeof(*ctx), GFP_KERNEL | __GFP_NOFAIL);
+   if (WARN_ON(!ctx))
+   return;
+
+   mutex_lock(>mutex);
+
+   drm_modeset_acquire_init(ctx, 0);
+
+retry:
+   ret = drm_modeset_lock_all_ctx(dev, ctx);
+   if (ret < 0) {
+   if (ret == -EDEADLK) {
+   drm_modeset_backoff(ctx);
+   goto retry;
+   }
+
+   drm_modeset_acquire_fini(ctx);
+   kfree(ctx);
+   return;
+   }
+   ww_acquire_done(>ww_ctx);
+
+   WARN_ON(config->acquire_ctx);
+
+   /*
+* We hold the locks now, so it is safe to stash the acquisition
+* context for drm_modeset_unlock_all().
+*/
+   config->acquire_ctx = ctx;
+
+   drm_warn_on_modeset_not_all_locked(dev);
+}
+EXPORT_SYMBOL(drm_modeset_lock_all);
+
+/**
+ * drm_modeset_unlock_all - drop all modeset locks
+ * @dev: DRM device
+ *
+ * This function drops all modeset locks taken by a previous call to the
+ * drm_modeset_lock_all() function.
+ *
+ * This function is deprecated. It uses the lock acquisition context stored
+ * in _device.mode_config. This facilitates conversion of existing
+ * code because it removes the need to manually deal with the acquisition
+ * context, but it is also brittle because the context is global and care must
+ * be taken not to nest calls. New code should pass the acquisition context
+ * directly to the drm_modeset_drop_locks() function.
+ */
+void drm_modeset_unlock_all(struct drm_device *dev)
+{
+   struct drm_mode_config *config = >mode_config;
+   struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx;
+
+   if (WARN_ON(!ctx))
+   return;
+
+   config->acquire_ctx = NULL;
+   drm_modeset_drop_locks(ctx);
+   drm_modeset_acquire_fini(ctx);
+
+   kfree(ctx);
+
+   mutex_unlock(>mode_config.mutex);
+}
+EXPORT_SYMBOL(drm_modeset_unlock_all);
+
 /**
  * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
  * @dev: device
@@ -293,9 +380,10 @@ EXPORT_SYMBOL(drm_modeset_unlock);
  * This function takes all modeset locks, suitable where a more fine-grained
  * scheme isn't (yet) implemented.
  *
- * It doesn't take the _mode_config.mutex since that lock isn't required 
for
- * modeset state changes. Callers which need to grab that lock too need to do 
so
- * outside of the acquire context @ctx.
+ * Unlike drm_modeset_lock_all(), it doesn't take the _mode_config.mutex
+ * since that lock isn't required for modeset state changes. Callers which
+ * need to grab that lock too need to do so outside of the acquire context
+ * @ctx.
  *
  * Locks acquired with this function should be released by calling the
  * drm_modeset_drop_locks() function on @ctx.
diff --git a/include/drm/drm_modeset_lock.h b/include/drm/drm_modeset_lock.h
index 865e64bcc4cb..aafd07388eb7 100644
--- a/include/drm/drm_modeset_lock.h
+++ b/include/drm/drm_modeset_lock.h
@@ -132,6 +132,8 @@ struct drm_device;
 struct drm_crtc;
 struct drm_plane;
 
+void drm_modeset_lock_all(struct drm_device *dev);
+void drm_modeset_unlock_all(struct drm_device *dev);
 void drm_warn_on_modeset_not_all_locked(struct drm_device *dev);
 
 int drm_modeset_lock_all_ctx(struct drm_device *dev,
-- 
Sean Paul, Software Engineer, Google / Chromium OS



Re: [PATCH 1/2] drm: Add Gamma and Degamma LUT sizes props to drm_crtc to validate.

2021-10-02 Thread Sean Paul
On Fri, Oct 01, 2021 at 04:34:34PM -0400, Sean Paul wrote:
> On Wed, Sep 29, 2021 at 03:39:25PM -0400, Mark Yacoub wrote:
> > From: Mark Yacoub 
> > 
> > [Why]
> > 1. drm_atomic_helper_check doesn't check for the LUT sizes of either Gamma
> > or Degamma props in the new CRTC state, allowing any invalid size to
> > be passed on.
> > 2. Each driver has its own LUT size, which could also be different for
> > legacy users.
> > 
> > [How]
> > 1. Create |degamma_lut_size| and |gamma_lut_size| to save the LUT sizes
> > assigned by the driver when it's initializing its color and CTM
> > management.
> > 2. Create drm_atomic_helper_check_crtc which is called by
> > drm_atomic_helper_check to check the LUT sizes saved in drm_crtc that
> > they match the sizes in the new CRTC state.
> > 
> 
> Did you consider extending drm_color_lut_check() with the size checks?
> 
> > Fixes: igt@kms_color@pipe-A-invalid-gamma-lut-sizes on MTK
> > Tested on Zork(amdgpu) and Jacuzzi(mediatek)
> > 
> > Signed-off-by: Mark Yacoub
> 
> nit: missing a space between name and email
> 
> 
> > ---
> >  drivers/gpu/drm/drm_atomic_helper.c | 56 +
> >  drivers/gpu/drm/drm_color_mgmt.c|  2 ++
> >  include/drm/drm_atomic_helper.h |  1 +
> >  include/drm/drm_crtc.h  | 11 ++
> >  4 files changed, 70 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
> > b/drivers/gpu/drm/drm_atomic_helper.c
> > index 2c0c6ec928200..265b9747250d1 100644
> > --- a/drivers/gpu/drm/drm_atomic_helper.c
> > +++ b/drivers/gpu/drm/drm_atomic_helper.c
> > @@ -930,6 +930,58 @@ drm_atomic_helper_check_planes(struct drm_device *dev,
> >  }
> >  EXPORT_SYMBOL(drm_atomic_helper_check_planes);
> >  
> > +/**
> > + * drm_atomic_helper_check_planes - validate state object for CRTC changes
> 
> Ctrl+c/Ctrl+v error here
> 
> > + * @state: the driver state object
> > + *
> > + * Check the CRTC state object such as the Gamma/Degamma LUT sizes if the 
> > new
> 
> Are there missing words between "object" and "such"?
> 
> > + * state holds them.
> > + *
> > + * RETURNS:
> > + * Zero for success or -errno
> > + */
> > +int drm_atomic_helper_check_crtc(struct drm_atomic_state *state)
> 
> drm_atomic_helper_check_crtcs to be consistent with
> drm_atomic_helper_check_planes
> 
> > +{
> > +   struct drm_crtc *crtc;
> > +   struct drm_crtc_state *new_crtc_state;
> > +   int i;
> > +
> > +   for_each_new_crtc_in_state (state, crtc, new_crtc_state, i) {
> 
> no space before (

Ignore this, parsing error on my behalf.

> 
> > +   if (new_crtc_state->gamma_lut) {
> 
> Perhaps gate these with a check of state->color_mgmt_changed first?
> 
> > +   uint64_t supported_lut_size = crtc->gamma_lut_size;
> > +   uint32_t supported_legacy_lut_size = crtc->gamma_size;
> > +   uint32_t new_state_lut_size =
> > +   drm_color_lut_size(new_crtc_state->gamma_lut);
> 
> nit: new_state_lut_size and supported_lut_size can be pulled out to top level 
> scope
> to avoid re-instantiation on each iteration
> 
> > +
> > +   if (new_state_lut_size != supported_lut_size &&
> > +   new_state_lut_size != supported_legacy_lut_size) {
> 
> According to the docbook, "If drivers support multiple LUT sizes then they
> should publish the largest size, and sub-sample smaller sized LUTs". So
> should this check be > instead of != ?
> 
> > +   DRM_DEBUG_DRIVER(
> 
> drm_dbg_state() is probably more appropriate
> 
> > +   "Invalid Gamma LUT size. Should be %u 
> > (or %u for legacy) but got %u.\n",
> > +   supported_lut_size,
> > +   supported_legacy_lut_size,
> > +   new_state_lut_size);
> > +   return -EINVAL;
> > +   }
> > +   }
> > +
> > +   if (new_crtc_state->degamma_lut) {
> > +   uint32_t new_state_lut_size =
> > +   drm_color_lut_size(new_crtc_state->degamma_lut);
> > +   uint64_t supported_lut_size = crtc->degamma_lut_size;
> > +
> > +   if (new_state_lut_size != supported_lut_size) {
> > +   DRM_DEBUG_DRIVER(
> 
> drm_dbg_state()
> 
> > +   "Invalid Degamma LUT size. Should be %u 
> > but got %u.\n",
> > +   supported_lut_size, new_state_lut_size);
> > +   return -EINVAL;
> > +   }
> > +   }
> > +   }
> > +
> > +   return 0;
> > +}
> > +EXPORT_SYMBOL(drm_atomic_helper_check_crtc);
> > +
> >  /**
> >   * drm_atomic_helper_check - validate state object
> >   * @dev: DRM device
> > @@ -975,6 +1027,10 @@ int drm_atomic_helper_check(struct drm_device *dev,
> > if (ret)
> > return ret;
> >  
> > +   ret = 

Re: [PATCH v2 0/3] drm/etnaviv: IOMMU related fixes

2021-10-02 Thread Michael Walle

Am 2021-09-07 18:49, schrieb Michael Walle:

This patch series fixes usage of the etnaviv driver with GPUs behind a
IOMMU. It was tested on a NXP LS1028A SoC. Together with Lucas' MMU 
patches
[1] there are not more (GPU internal) MMU nor (system) IOMMU faults on 
the

LS1028A.

[1] 
https://lists.freedesktop.org/archives/etnaviv/2021-August/003682.html


changes since v1:
 - don't move the former dma_mask setup code around in patch 2/3. Will
   avoid any confusion.

Michael Walle (3):
  drm/etnaviv: use PLATFORM_DEVID_NONE
  drm/etnaviv: fix dma configuration of the virtual device
  drm/etnaviv: use a 32 bit mask as coherent DMA mask

 drivers/gpu/drm/etnaviv/etnaviv_drv.c | 41 ---
 1 file changed, 31 insertions(+), 10 deletions(-)


ping? :)

-michael


Re: [BUG 5.15-rc3] kernel BUG at drivers/gpu/drm/i915/i915_sw_fence.c:245!

2021-10-02 Thread Steven Rostedt
On Sat, 2 Oct 2021 03:17:29 -0700 (PDT)
Hugh Dickins  wrote:

> Yes (though bisection doesn't work right on this one): the fix

Interesting, as it appeared to be very reliable. But I didn't do the
"try before / after" on the patch.

> https://lore.kernel.org/lkml/1f955bff-fd9e-d2ee-132a-f758add9e...@google.com/
> seems to have got lost in the system: it has not even appeared in
> linux-next yet. I was going to send a reminder later this weekend.
> 
> Here it is again (but edited to replace "__aligned(4)" in the original
> by the official "__i915_sw_fence_call" I discovered afterwards; and
> ignoring recent discussions of where __attributes ought to appear :-)
> 
> 
> [PATCH] drm/i915: fix blank screen booting crashes

Thanks, I added it to my "fixes" patch set that I apply before testing.
It looks to have done the trick, and the kernel boots now.

Tested-by: Steven Rostedt (VMware) 

-- Steve



Re: [Intel-gfx] [PATCH v2 0/4] drm/dp, drm/i915: Finish basic PWM support for VESA backlight helpers

2021-10-02 Thread Hans de Goede
Hi Lyude,

On 10/2/21 12:53 AM, Lyude Paul wrote:
> When I originally moved all of the VESA backlight code in i915 into DRM
> helpers, one of the things I didn't have the hardware or time for
> testing was machines that used a combination of PWM and DPCD in order to
> control their backlights. This has since then caused some breakages and
> resulted in us disabling DPCD backlight support on such machines. This
> works fine, unless you have a machine that actually needs this
> functionality for backlight controls to work at all. Additionally, we
> will need to support PWM for when we start adding support for VESA's
> product (as in the product of multiplication) control mode for better
> brightness ranges.
> 
> So - let's finally finish up implementing basic support for these types
> of backlights to solve these problems in our DP helpers, along with
> implementing support for this in i915. And since digging into this issue
> solved the last questions we really had about probing backlights in i915
> for the most part, let's update some of the comments around that as
> well!

Backlight control is a topic which I'm reasonably familiar with,
do you want me to review this series for you ?

Regards,

Hans



> 
> Changes:
> * Fixup docs
> * Add patch to stop us from breaking nouveau
> 
> Lyude Paul (4):
>   drm/i915: Add support for panels with VESA backlights with PWM
> enable/disable
>   drm/nouveau/kms/nv50-: Explicitly check DPCD backlights for aux
> enable/brightness
>   drm/dp, drm/i915: Add support for VESA backlights using PWM for
> brightness control
>   drm/i915: Clarify probing order in intel_dp_aux_init_backlight_funcs()
> 
>  drivers/gpu/drm/drm_dp_helper.c   | 75 +++--
>  .../drm/i915/display/intel_dp_aux_backlight.c | 80 ++-
>  drivers/gpu/drm/nouveau/nouveau_backlight.c   |  5 +-
>  include/drm/drm_dp_helper.h   |  7 +-
>  4 files changed, 122 insertions(+), 45 deletions(-)
> 



[PATCH] drm: panel-orientation-quirks: Add quirk for Aya Neo 2021

2021-10-02 Thread Bryant Mairs
Signed-off-by: Bryant Mairs 
---
 drivers/gpu/drm/drm_panel_orientation_quirks.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/drm_panel_orientation_quirks.c 
b/drivers/gpu/drm/drm_panel_orientation_quirks.c
index f6bdec7fa925..30c17a76f49a 100644
--- a/drivers/gpu/drm/drm_panel_orientation_quirks.c
+++ b/drivers/gpu/drm/drm_panel_orientation_quirks.c
@@ -134,6 +134,12 @@ static const struct dmi_system_id orientation_data[] = {
  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T103HAF"),
},
.driver_data = (void *)_rightside_up,
+   }, {/* AYA NEO 2021 */
+   .matches = {
+ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "AYADEVICE"),
+ DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "AYA NEO 2021"),
+   },
+   .driver_data = (void *)_rightside_up,
}, {/* GPD MicroPC (generic strings, also match on bios date) */
.matches = {
  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Default string"),
-- 
2.31.1



Re: [Intel-gfx] [PATCH v2 00/17] drm: cleanup: Use DRM_MODESET_LOCK_ALL_* helpers where possible

2021-10-02 Thread Fernando Ramos
On 21/10/02 05:30AM, Ville Syrjälä wrote:
> On Sat, Oct 02, 2021 at 01:05:47AM +0300, Ville Syrjälä wrote:
> > On Fri, Oct 01, 2021 at 04:48:15PM -0400, Sean Paul wrote:
> > > On Fri, Oct 01, 2021 at 10:00:50PM +0300, Ville Syrjälä wrote:
> > > > On Fri, Oct 01, 2021 at 02:36:55PM -0400, Sean Paul wrote:
> > > > > 
> > > > > Thank you for revising, Fernando! I've pushed the set to 
> > > > > drm-misc-next (along
> > > > > with the necessary drm-tip conflict resolutions).
> > > > 
> > > > Ugh. Did anyone actually review the locking changes this does?
> > > > I shot the previous i915 stuff down because the commit messages
> > > > did not address any of it.
> > > 
> > > I reviewed the set on 9/17, I didn't see your feedback on that thread.
> > 
> > It was much earlir than that.
> > https://lists.freedesktop.org/archives/dri-devel/2021-June/313193.html
> > 
> > And I think I might have also shot down a similar thing earlier.
> > 
> > I was actually half considering sending a patch to nuke that
> > misleading TODO item. I don't think anything which changes
> > which locks are taken should be considred a starter level task.
> > And the commit messages here don't seem to address any of it.
> 
> And i915 is now broken :(
> 
> https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10680/fi-bwr-2160/boot.html

I completely overlooked the side effects of not having a global context anymore.
Sorry for all the trouble.

Sean, could you revert the whole patch series? I'll have a deeper look into the
patch set and come up with a v3 where all these issues will be addressed.

Thanks and sorry once again for the extra overhead this might have caused.




[BUG 5.15-rc3] kernel BUG at drivers/gpu/drm/i915/i915_sw_fence.c:245!

2021-10-02 Thread Steven Rostedt
When I tried to test patches applied to v5.15-rc3, I hit this bug (and
hence can not test my code), on 32 bit x86.

[ cut here ]
kernel BUG at drivers/gpu/drm/i915/i915_sw_fence.c:245!
invalid opcode:  [#1] SMP PTI
CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.14.0-rc1-test+ #456
Hardware name: MSI MS-7823/CSM-H87M-G43 (MS-7823), BIOS V1.6 02/22/2014
EIP: __i915_sw_fence_init+0x15/0x38
Code: 2b 3d 58 98 88 c1 74 05 e8 60 d9 58 00 8d 65 f4 5b 5e 5f 5d c3 3e
8d 74 26 00 55 89 e5 56 89 d6 53 85 d2 74 05 f6 c2 03 74 02 <0f> 0b 89
ca 8b 4d 08 89 c3 e8 48 94 ab ff 89 73 34 c7 43 38 01 00
EAX: c2508260 EBX: c2508000 ECX: c143de1e EDX: c09dfadd
ESI: c09dfadd EDI: c45e7200 EBP: c26c9c68 ESP: c26c9c60
DS: 007b ES: 007b FS: 00d8 GS:  SS: 0068 EFLAGS: 00010202
CR0: 80050033 CR2:  CR3: 019e2000 CR4: 001506f0
Call Trace:
 intel_context_init+0x112/0x145
 intel_context_create+0x29/0x37
 intel_ring_submission_setup+0x3cb/0x5a8
 ? kfree+0x135/0x1c6
 ? wa_init_finish+0x32/0x59
 ? wa_init_finish+0x4f/0x59
 ? intel_engine_init_ctx_wa+0x39a/0x3b3
 intel_engines_init+0x2dd/0x4d0
 ? gen6_bsd_submit_request+0x97/0x97
 intel_gt_init+0x122/0x20d
 i915_gem_init+0x80/0xef
 i915_driver_probe+0x880/0xa90
 ? i915_pci_remove+0x27/0x27
 i915_pci_probe+0xdd/0xf6
 ? __pm_runtime_resume+0x63/0x6b
 ? i915_pci_remove+0x27/0x27
 pci_device_probe+0xbc/0x11e
 really_probe+0x13e/0x328
 __driver_probe_device+0x140/0x176
 driver_probe_device+0x1f/0x71
 __driver_attach+0xf6/0x109
 ? __device_attach_driver+0xbd/0xbd
 bus_for_each_dev+0x5b/0x88
 driver_attach+0x19/0x1b
 ? __device_attach_driver+0xbd/0xbd
 bus_add_driver+0xf2/0x199
 driver_register+0x8c/0xbe
 __pci_register_driver+0x5b/0x60
 i915_register_pci_driver+0x19/0x1b
 i915_init+0x15/0x67
 ? radeon_module_init+0x6a/0x6a
 do_one_initcall+0xce/0x21c
 ? rcu_read_lock_sched_held+0x35/0x6d
 ? trace_initcall_level+0x5f/0x99
 kernel_init_freeable+0x1fb/0x247
 ? rest_init+0x129/0x129
 kernel_init+0x17/0xfd
 ret_from_fork+0x1c/0x28
Modules linked in:
---[ end trace 791dc89810d853da ]---
EIP: __i915_sw_fence_init+0x15/0x38
Code: 2b 3d 58 98 88 c1 74 05 e8 60 d9 58 00 8d 65 f4 5b 5e 5f 5d c3 3e
8d 74 26 00 55 89 e5 56 89 d6 53 85 d2 74 05 f6 c2 03 74 02 <0f> 0b 89
ca 8b 4d 08 89 c3 e8 48 94 ab ff 89 73 34 c7 43 38 01 00
EAX: c2508260 EBX: c2508000 ECX: c143de1e EDX: c09dfadd
ESI: c09dfadd EDI: c45e7200 EBP: c26c9c68 ESP: c26c9c60
DS: 007b ES: 007b FS: 00d8 GS:  SS: 0068 EFLAGS: 00010202
CR0: 80050033 CR2:  CR3: 019e2000 CR4: 001506f0
Kernel panic - not syncing: Attempted to kill init! exitcode=0x000b
Kernel Offset: disabled
---[ end Kernel panic - not syncing: Attempted to kill init! 
exitcode=0x000b ]---

Attached is the dmesg and the config.

I bisected it down to this commit:

3ffe82d701a4 ("drm/i915/xehp: handle new steering options")

-- Steve


mitest-config.gz
Description: application/gzip


mitest-dmesg.gz
Description: application/gzip