Skip to contentSkip to conversation

drm/tegra: Miscellaneous fixes

PATCH Superseded Thierry Reding 2 participants 26 messages Nov 28, 2019 – Dec 3, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover drm/tegra: Miscellaneous fixes

From: Thierry Reding <[email protected]>

Here's a random assortment of fixes for issues that I ran into as I've been testing suspend/resume and other things recently.

Thierry

Thierry Reding (9):
drm/tegra: hub: Remove bogus connection mutex check drm/tegra: gem: Properly pin imported buffers drm/tegra: gem: Remove premature import restrictions drm/tegra: Use proper IOVA address for cursor image drm/tegra: sor: Implement system suspend/resume drm/tegra: vic: Export module device table drm/tegra: Silence expected errors on IOMMU attach drm/tegra: dpaux: Add missing runtime PM references drm/tegra: sor: Make the +5V HDMI supply optional

 drivers/gpu/drm/tegra/dc.c    | 18 ++++++-------
 drivers/gpu/drm/tegra/dpaux.c | 16 +++++++++--
 drivers/gpu/drm/tegra/drm.c   |  4 +--
 drivers/gpu/drm/tegra/gem.c   | 50 ++++++++++++++++++++++++++++++-----
 drivers/gpu/drm/tegra/hub.c   |  3 ---
 drivers/gpu/drm/tegra/sor.c   | 38 ++++++++++++++++++++++----
 drivers/gpu/drm/tegra/vic.c   |  7 ++---
 7 files changed, 104 insertions(+), 32 deletions(-)
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 1/9 drm/tegra: hub: Remove bogus connection mutex check

From: Thierry Reding <[email protected]>

I have no recollection why that check is there, but it seems to trigger all the time, so remove it. Everything works fine without.

---
 drivers/gpu/drm/tegra/hub.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/tegra/hub.c +0 -3
index 6aca0fd5a8e5..e56c0f7d3a13 100644
@@ -615,11 +615,8 @@ static struct tegra_display_hub_state *
 tegra_display_hub_get_state(struct tegra_display_hub *hub,
 			    struct drm_atomic_state *state)
 {
-	struct drm_device *drm = dev_get_drvdata(hub->client.parent);
 	struct drm_private_state *priv;
 
-	WARN_ON(!drm_modeset_is_locked(&drm->mode_config.connection_mutex));
-
 	priv = drm_atomic_get_private_obj_state(state, &hub->base);
 	if (IS_ERR(priv))
 		return ERR_CAST(priv);
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] drm/tegra: hub: Remove bogus connection mutex check

Quoted 15 lines · Thierry Reding

From: Thierry Reding <[email protected]>

I have no recollection why that check is there, but it seems to trigger all the time, so remove it. Everything works fine without.

---
 drivers/gpu/drm/tegra/hub.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/tegra/hub.c +0 -0
index 6aca0fd5a8e5..e56c0f7d3a13 100644

drivers/gpu/drm/tegra/hub.c static struct tegra_display_hub_state * · line 621

Quoted 7 lines
drivers/gpu/drm/tegra/hub.c +0 -2
@@ -615,11 +615,8 @@ static struct tegra_display_hub_state *
 tegra_display_hub_get_state(struct tegra_display_hub *hub,
 			    struct drm_atomic_state *state)
 {
-	struct drm_device *drm = dev_get_drvdata(hub->client.parent);
 	struct drm_private_state *priv;
 
-	WARN_ON(!drm_modeset_is_locked(&drm->mode_config.connection_mutex));

I suspect copypasta from the mst private state stuff, which relied on this lock to protect it. Except your code never bothered to grab that lock (or any other) so was technically broken until we added generic locking in

commit b962a12050a387e4bbf3a48745afe1d29d396b0d

Author: Rob Clark <[email protected]>
Date:   Mon Oct 22 14:31:22 2018 +0200

drm/atomic: integrate modeset lock with private objects

Hence this is now ok to drop, originally it wasnt.

Aside: You're single-thread all your atomic updates on the hub->lock, which might not be what you want. At least updates to separate crtc should go through in parallel. Usual way to fix this is to add a tegra_crtc_state->hub_changed that your earlier code sets, and then you walk the crtc states in the atomic commit (only those, not all, otherwise you just rebuild that global lock again), and then only grab the hub state when you need to update something.

Cheers, Daniel

Quoted 11 lines
drivers/gpu/drm/tegra/hub.c +0 -1
-
 	priv = drm_atomic_get_private_obj_state(state, &hub->base);
 	if (IS_ERR(priv))
 		return ERR_CAST(priv);
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

Re: [PATCH 1/9] drm/tegra: hub: Remove bogus connection mutex check

Quoted 29 lines · Daniel Vetter
Quoted 15 lines · Thierry Reding

From: Thierry Reding <[email protected]>

I have no recollection why that check is there, but it seems to trigger all the time, so remove it. Everything works fine without.

---
 drivers/gpu/drm/tegra/hub.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/tegra/hub.c +0 -0
index 6aca0fd5a8e5..e56c0f7d3a13 100644

drivers/gpu/drm/tegra/hub.c static struct tegra_display_hub_state * · line 621

Quoted 7 lines
drivers/gpu/drm/tegra/hub.c +0 -2
@@ -615,11 +615,8 @@ static struct tegra_display_hub_state *
 tegra_display_hub_get_state(struct tegra_display_hub *hub,
 			    struct drm_atomic_state *state)
 {
-	struct drm_device *drm = dev_get_drvdata(hub->client.parent);
 	struct drm_private_state *priv;
 
-	WARN_ON(!drm_modeset_is_locked(&drm->mode_config.connection_mutex));

I suspect copypasta from the mst private state stuff, which relied on this lock to protect it. Except your code never bothered to grab that lock (or any other) so was technically broken until we added generic locking in

commit b962a12050a387e4bbf3a48745afe1d29d396b0d

Quoted 8 lines
Author: Rob Clark <[email protected]>
Date:   Mon Oct 22 14:31:22 2018 +0200

drm/atomic: integrate modeset lock with private objects

Hence this is now ok to drop, originally it wasnt.

Great, thanks for pointing that out. I'll update the commit message with that explanation.

Quoted 7 lines

Aside: You're single-thread all your atomic updates on the hub->lock, which might not be what you want. At least updates to separate crtc should go through in parallel. Usual way to fix this is to add a tegra_crtc_state->hub_changed that your earlier code sets, and then you walk the crtc states in the atomic commit (only those, not all, otherwise you just rebuild that global lock again), and then only grab the hub state when you need to update something.

I'm confused. Where do you see hub->lock? Did you mean wgrp->lock?

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Re: [PATCH 1/9] drm/tegra: hub: Remove bogus connection mutex check

Quoted 50 lines · Thierry Reding
Quoted 29 lines · Daniel Vetter
Quoted 15 lines · Thierry Reding

From: Thierry Reding <[email protected]>

I have no recollection why that check is there, but it seems to trigger all the time, so remove it. Everything works fine without.

---
 drivers/gpu/drm/tegra/hub.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/tegra/hub.c +0 -0
index 6aca0fd5a8e5..e56c0f7d3a13 100644

drivers/gpu/drm/tegra/hub.c static struct tegra_display_hub_state * · line 621

Quoted 7 lines
drivers/gpu/drm/tegra/hub.c +0 -2
@@ -615,11 +615,8 @@ static struct tegra_display_hub_state *
 tegra_display_hub_get_state(struct tegra_display_hub *hub,
 			    struct drm_atomic_state *state)
 {
-	struct drm_device *drm = dev_get_drvdata(hub->client.parent);
 	struct drm_private_state *priv;
 
-	WARN_ON(!drm_modeset_is_locked(&drm->mode_config.connection_mutex));

I suspect copypasta from the mst private state stuff, which relied on this lock to protect it. Except your code never bothered to grab that lock (or any other) so was technically broken until we added generic locking in

commit b962a12050a387e4bbf3a48745afe1d29d396b0d

Quoted 8 lines
Author: Rob Clark <[email protected]>
Date:   Mon Oct 22 14:31:22 2018 +0200

drm/atomic: integrate modeset lock with private objects

Hence this is now ok to drop, originally it wasnt.

Great, thanks for pointing that out. I'll update the commit message with that explanation.

Quoted 7 lines

Aside: You're single-thread all your atomic updates on the hub->lock, which might not be what you want. At least updates to separate crtc should go through in parallel. Usual way to fix this is to add a tegra_crtc_state->hub_changed that your earlier code sets, and then you walk the crtc states in the atomic commit (only those, not all, otherwise you just rebuild that global lock again), and then only grab the hub state when you need to update something.

Quoted 1 line

I'm confused. Where do you see hub->lock? Did you mean wgrp->lock?

struct tegra_display_hub->base.lock I have no idea what wgrp->lock is protecting - the functions seem to be only called from driver load/cleanup code, and that is single-threaded. If I'm not missing anything then wgrp->lock does nothing for you.

Cheers, Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

Re: [PATCH 1/9] drm/tegra: hub: Remove bogus connection mutex check

Quoted 51 lines · Daniel Vetter
Quoted 50 lines · Thierry Reding
Quoted 29 lines · Daniel Vetter
Quoted 15 lines · Thierry Reding

From: Thierry Reding <[email protected]>

I have no recollection why that check is there, but it seems to trigger all the time, so remove it. Everything works fine without.

---
 drivers/gpu/drm/tegra/hub.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/tegra/hub.c +0 -0
index 6aca0fd5a8e5..e56c0f7d3a13 100644

drivers/gpu/drm/tegra/hub.c static struct tegra_display_hub_state * · line 621

Quoted 7 lines
drivers/gpu/drm/tegra/hub.c +0 -2
@@ -615,11 +615,8 @@ static struct tegra_display_hub_state *
 tegra_display_hub_get_state(struct tegra_display_hub *hub,
 			    struct drm_atomic_state *state)
 {
-	struct drm_device *drm = dev_get_drvdata(hub->client.parent);
 	struct drm_private_state *priv;
 
-	WARN_ON(!drm_modeset_is_locked(&drm->mode_config.connection_mutex));

I suspect copypasta from the mst private state stuff, which relied on this lock to protect it. Except your code never bothered to grab that lock (or any other) so was technically broken until we added generic locking in

commit b962a12050a387e4bbf3a48745afe1d29d396b0d

Quoted 8 lines
Author: Rob Clark <[email protected]>
Date:   Mon Oct 22 14:31:22 2018 +0200

drm/atomic: integrate modeset lock with private objects

Hence this is now ok to drop, originally it wasnt.

Great, thanks for pointing that out. I'll update the commit message with that explanation.

Quoted 7 lines

Aside: You're single-thread all your atomic updates on the hub->lock, which might not be what you want. At least updates to separate crtc should go through in parallel. Usual way to fix this is to add a tegra_crtc_state->hub_changed that your earlier code sets, and then you walk the crtc states in the atomic commit (only those, not all, otherwise you just rebuild that global lock again), and then only grab the hub state when you need to update something.

Quoted 6 lines
Quoted 1 line

I'm confused. Where do you see hub->lock? Did you mean wgrp->lock?

struct tegra_display_hub->base.lock I have no idea what wgrp->lock is protecting - the functions seem to be only called from driver load/cleanup code, and that is single-threaded. If I'm not missing anything then wgrp->lock does nothing for you.

This is currently single-threaded, but the idea was to make window group assignment more dynamic. I currently always enable window groups because there's no good place to dynamically do that. Once I figure that out the lock would become necessary, so I'd prefer to leave it in place as sort of a reminder that I need to actually worry about the locking.

I'll have to look into the hub->base.lock, I don't recall exactly what I thought at the time and it seems like I didn't leave enough comments in the code to quickly refresh my memory...

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

PATCH 2/9 drm/tegra: gem: Properly pin imported buffers

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Buffers that are imported from a DMA-BUF don't have pages allocated with them. At the same time an SG table for them can't be derived using the DMA API helpers because the necessary information doesn't exist. However there's already an SG table that was created during import, so this can simply be duplicated.

---
 drivers/gpu/drm/tegra/gem.c | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/gpu/drm/tegra/gem.c +43 -0
index 746dae32c484..6dfad56eee2b 100644
@@ -27,6 +27,29 @@ static void tegra_bo_put(struct host1x_bo *bo)
 	drm_gem_object_put_unlocked(&obj->gem);
 }
 
+/* XXX move this into lib/scatterlist.c? */
+static int sg_alloc_table_from_sg(struct sg_table *sgt, struct scatterlist *sg,
+				  unsigned int nents, gfp_t gfp_mask)
+{
+	struct scatterlist *dst;
+	unsigned int i;
+	int err;
+
+	err = sg_alloc_table(sgt, nents, gfp_mask);
+	if (err < 0)
+		return err;
+
+	dst = sgt->sgl;
+
+	for (i = 0; i < nents; i++) {
+		sg_set_page(dst, sg_page(sg), sg->length, 0);
+		dst = sg_next(dst);
+		sg = sg_next(sg);
+	}
+
+	return 0;
+}
+
 static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo,
 				     dma_addr_t *phys)
 {
@@ -52,11 +75,31 @@ static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo,
 		return ERR_PTR(-ENOMEM);
 
 	if (obj->pages) {
+		/*
+		 * If the buffer object was allocated from the explicit IOMMU
+		 * API code paths, construct an SG table from the pages.
+		 */
 		err = sg_alloc_table_from_pages(sgt, obj->pages, obj->num_pages,
 						0, obj->gem.size, GFP_KERNEL);
 		if (err < 0)
 			goto free;
+	} else if (obj->sgt) {
+		/*
+		 * If the buffer object already has an SG table but no pages
+		 * were allocated for it, it means the buffer was imported and
+		 * the SG table needs to be copied to avoid overwriting any
+		 * other potential users of the original SG table.
+		 */
+		err = sg_alloc_table_from_sg(sgt, obj->sgt->sgl, obj->sgt->nents,
+					     GFP_KERNEL);
+		if (err < 0)
+			goto free;
 	} else {
+		/*
+		 * If the buffer object had no pages allocated and if it was
+		 * not imported, it had to be allocated with the DMA API, so
+		 * the DMA API helper can be used.
+		 */
 		err = dma_get_sgtable(dev, sgt, obj->vaddr, obj->iova,
 				      obj->gem.size);
 		if (err < 0)
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Re: [PATCH 2/9] drm/tegra: gem: Properly pin imported buffers

Quoted 58 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Buffers that are imported from a DMA-BUF don't have pages allocated with them. At the same time an SG table for them can't be derived using the DMA API helpers because the necessary information doesn't exist. However there's already an SG table that was created during import, so this can simply be duplicated.

---
 drivers/gpu/drm/tegra/gem.c | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/gpu/drm/tegra/gem.c +27 -0
index 746dae32c484..6dfad56eee2b 100644
@@ -27,6 +27,29 @@ static void tegra_bo_put(struct host1x_bo *bo)
 	drm_gem_object_put_unlocked(&obj->gem);
 }
 
+/* XXX move this into lib/scatterlist.c? */
+static int sg_alloc_table_from_sg(struct sg_table *sgt, struct scatterlist *sg,
+				  unsigned int nents, gfp_t gfp_mask)
+{
+	struct scatterlist *dst;
+	unsigned int i;
+	int err;
+
+	err = sg_alloc_table(sgt, nents, gfp_mask);
+	if (err < 0)
+		return err;
+
+	dst = sgt->sgl;
+
+	for (i = 0; i < nents; i++) {
+		sg_set_page(dst, sg_page(sg), sg->length, 0);
+		dst = sg_next(dst);
+		sg = sg_next(sg);
+	}
+
+	return 0;
+}
+
 static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo,
 				     dma_addr_t *phys)
 {
@@ -52,11 +75,31 @@ static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo,
 		return ERR_PTR(-ENOMEM);
 
 	if (obj->pages) {
+		/*
+		 * If the buffer object was allocated from the explicit IOMMU
+		 * API code paths, construct an SG table from the pages.
+		 */
 		err = sg_alloc_table_from_pages(sgt, obj->pages, obj->num_pages,
 						0, obj->gem.size, GFP_KERNEL);
 		if (err < 0)

drivers/gpu/drm/tegra/gem.c static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, · line 94

Quoted 10 lines
drivers/gpu/drm/tegra/gem.c +9 -0
 			goto free;
+	} else if (obj->sgt) {
+		/*
+		 * If the buffer object already has an SG table but no pages
+		 * were allocated for it, it means the buffer was imported and
+		 * the SG table needs to be copied to avoid overwriting any
+		 * other potential users of the original SG table.
+		 */
+		err = sg_alloc_table_from_sg(sgt, obj->sgt->sgl, obj->sgt->nents,
+					     GFP_KERNEL);

Why duplicate this instead of just handing out obj->sgt, and then in unpin making sure you don't release it? You could also only map/unmap the dma_buf here in your pin/unpin, but that's a pile of work plus the mapping is cached anyway so won't change a thing.
-Daniel

Quoted 18 lines
drivers/gpu/drm/tegra/gem.c +7 -0
+		if (err < 0)
+			goto free;
 	} else {
+		/*
+		 * If the buffer object had no pages allocated and if it was
+		 * not imported, it had to be allocated with the DMA API, so
+		 * the DMA API helper can be used.
+		 */
 		err = dma_get_sgtable(dev, sgt, obj->vaddr, obj->iova,
 				      obj->gem.size);
 		if (err < 0)
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

Re: [PATCH 2/9] drm/tegra: gem: Properly pin imported buffers

Quoted 66 lines · Daniel Vetter
Quoted 65 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Buffers that are imported from a DMA-BUF don't have pages allocated with them. At the same time an SG table for them can't be derived using the DMA API helpers because the necessary information doesn't exist. However there's already an SG table that was created during import, so this can simply be duplicated.

---
 drivers/gpu/drm/tegra/gem.c | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/gpu/drm/tegra/gem.c +33 -0
index 746dae32c484..6dfad56eee2b 100644
@@ -27,6 +27,29 @@ static void tegra_bo_put(struct host1x_bo *bo)
 	drm_gem_object_put_unlocked(&obj->gem);
 }
 
+/* XXX move this into lib/scatterlist.c? */
+static int sg_alloc_table_from_sg(struct sg_table *sgt, struct scatterlist *sg,
+				  unsigned int nents, gfp_t gfp_mask)
+{
+	struct scatterlist *dst;
+	unsigned int i;
+	int err;
+
+	err = sg_alloc_table(sgt, nents, gfp_mask);
+	if (err < 0)
+		return err;
+
+	dst = sgt->sgl;
+
+	for (i = 0; i < nents; i++) {
+		sg_set_page(dst, sg_page(sg), sg->length, 0);
+		dst = sg_next(dst);
+		sg = sg_next(sg);
+	}
+
+	return 0;
+}
+
 static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo,
 				     dma_addr_t *phys)
 {
@@ -52,11 +75,31 @@ static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo,
 		return ERR_PTR(-ENOMEM);
 
 	if (obj->pages) {
+		/*
+		 * If the buffer object was allocated from the explicit IOMMU
+		 * API code paths, construct an SG table from the pages.
+		 */
 		err = sg_alloc_table_from_pages(sgt, obj->pages, obj->num_pages,
 						0, obj->gem.size, GFP_KERNEL);
 		if (err < 0)
 			goto free;
+	} else if (obj->sgt) {
+		/*
+		 * If the buffer object already has an SG table but no pages
+		 * were allocated for it, it means the buffer was imported and
+		 * the SG table needs to be copied to avoid overwriting any
+		 * other potential users of the original SG table.
Quoted 8 lines

drivers/gpu/drm/tegra/gem.c static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, · line 94

Quoted 3 lines
drivers/gpu/drm/tegra/gem.c +3 -0
+		 */
+		err = sg_alloc_table_from_sg(sgt, obj->sgt->sgl, obj->sgt->nents,
+					     GFP_KERNEL);

Why duplicate this instead of just handing out obj->sgt, and then in unpin making sure you don't release it? You could also only map/unmap the dma_buf here in your pin/unpin, but that's a pile of work plus the mapping is cached anyway so won't change a thing.

The problem with just handing out obj->sgt is that these buffers may be used by several of the host1x engines in the same job. This means that they may end up getting dma_map()'ed by multiple devices. dma_map_*() stores the DMA addresses for the buffer in the SG entries, so subsequent calls would effectively overwrite the earlier mappings, so we need a new SG table for each device.

Thierry

Quoted 16 lines

-Daniel

Quoted 14 lines
drivers/gpu/drm/tegra/gem.c +7 -0
+		if (err < 0)
+			goto free;
 	} else {
+		/*
+		 * If the buffer object had no pages allocated and if it was
+		 * not imported, it had to be allocated with the DMA API, so
+		 * the DMA API helper can be used.
+		 */
 		err = dma_get_sgtable(dev, sgt, obj->vaddr, obj->iova,
 				      obj->gem.size);
 		if (err < 0)
Signature · 1 line
2.23.0
Quoted 9 lines
Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw

Re: [PATCH 2/9] drm/tegra: gem: Properly pin imported buffers

Quoted 76 lines · Thierry Reding
Quoted 66 lines · Daniel Vetter
Quoted 65 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Buffers that are imported from a DMA-BUF don't have pages allocated with them. At the same time an SG table for them can't be derived using the DMA API helpers because the necessary information doesn't exist. However there's already an SG table that was created during import, so this can simply be duplicated.

---
 drivers/gpu/drm/tegra/gem.c | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/gpu/drm/tegra/gem.c +33 -0
index 746dae32c484..6dfad56eee2b 100644
@@ -27,6 +27,29 @@ static void tegra_bo_put(struct host1x_bo *bo)
 	drm_gem_object_put_unlocked(&obj->gem);
 }
 
+/* XXX move this into lib/scatterlist.c? */
+static int sg_alloc_table_from_sg(struct sg_table *sgt, struct scatterlist *sg,
+				  unsigned int nents, gfp_t gfp_mask)
+{
+	struct scatterlist *dst;
+	unsigned int i;
+	int err;
+
+	err = sg_alloc_table(sgt, nents, gfp_mask);
+	if (err < 0)
+		return err;
+
+	dst = sgt->sgl;
+
+	for (i = 0; i < nents; i++) {
+		sg_set_page(dst, sg_page(sg), sg->length, 0);
+		dst = sg_next(dst);
+		sg = sg_next(sg);
+	}
+
+	return 0;
+}
+
 static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo,
 				     dma_addr_t *phys)
 {
@@ -52,11 +75,31 @@ static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo,
 		return ERR_PTR(-ENOMEM);
 
 	if (obj->pages) {
+		/*
+		 * If the buffer object was allocated from the explicit IOMMU
+		 * API code paths, construct an SG table from the pages.
+		 */
 		err = sg_alloc_table_from_pages(sgt, obj->pages, obj->num_pages,
 						0, obj->gem.size, GFP_KERNEL);
 		if (err < 0)
 			goto free;
+	} else if (obj->sgt) {
+		/*
+		 * If the buffer object already has an SG table but no pages
+		 * were allocated for it, it means the buffer was imported and
+		 * the SG table needs to be copied to avoid overwriting any
+		 * other potential users of the original SG table.
Quoted 8 lines

drivers/gpu/drm/tegra/gem.c static struct sg_table *tegra_bo_pin(struct device *dev, struct host1x_bo *bo, · line 94

Quoted 3 lines
drivers/gpu/drm/tegra/gem.c +3 -0
+		 */
+		err = sg_alloc_table_from_sg(sgt, obj->sgt->sgl, obj->sgt->nents,
+					     GFP_KERNEL);

Why duplicate this instead of just handing out obj->sgt, and then in unpin making sure you don't release it? You could also only map/unmap the dma_buf here in your pin/unpin, but that's a pile of work plus the mapping is cached anyway so won't change a thing.

Quoted 6 lines

The problem with just handing out obj->sgt is that these buffers may be used by several of the host1x engines in the same job. This means that they may end up getting dma_map()'ed by multiple devices. dma_map_*() stores the DMA addresses for the buffer in the SG entries, so subsequent calls would effectively overwrite the earlier mappings, so we need a new SG table for each device.

So strictly speaking, i.e. if you don't want to contribute to the living mess that's called dma-buf, you're supposed to dma_buf_attach each and every device (definitely those with different iommu/dma-api routing). That entire "let me peak behind the abstraction" thing is kinda not how this was meant to be used. But the first drm prime drivers did it really badly, plus drm_prime.c is somewhat backwards in some regards by always attaching for you right away to /something/, but maybe not the right thing.

Adding more dma-buf interface abuse doesn't feel like the right thing really.

Also, you're not supposed to call dma_map_sg on the sg tables you get from dma-buf, they're supposed to be mapped already.
-Daniel

Quoted 28 lines

Thierry

Quoted 25 lines

-Daniel

Quoted 18 lines
drivers/gpu/drm/tegra/gem.c +7 -0
+		if (err < 0)
+			goto free;
 	} else {
+		/*
+		 * If the buffer object had no pages allocated and if it was
+		 * not imported, it had to be allocated with the DMA API, so
+		 * the DMA API helper can be used.
+		 */
 		err = dma_get_sgtable(dev, sgt, obj->vaddr, obj->iova,
 				      obj->gem.size);
 		if (err < 0)
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

PATCH 3/9 drm/tegra: gem: Remove premature import restrictions

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

It's not known at import time whether or not all users of a DMA-BUF will be able to deal with non-contiguous memory. Each user needs to verify at map-time whether it can access the buffer.

---
 drivers/gpu/drm/tegra/gem.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/tegra/gem.c +0 -7
index 6dfad56eee2b..bc15b430156d 100644
@@ -440,13 +440,6 @@ static struct tegra_bo *tegra_bo_import(struct drm_device *drm,
 		err = tegra_bo_iommu_map(tegra, bo);
 		if (err < 0)
 			goto detach;
-	} else {
-		if (bo->sgt->nents > 1) {
-			err = -EINVAL;
-			goto detach;
-		}
-
-		bo->iova = sg_dma_address(bo->sgt->sgl);
 	}
 
 	bo->gem.import_attach = attach;
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw

Re: [PATCH 3/9] drm/tegra: gem: Remove premature import restrictions

Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

It's not known at import time whether or not all users of a DMA-BUF will be able to deal with non-contiguous memory. Each user needs to verify at map-time whether it can access the buffer.

I'm not seeing any other check for nents ... does this mean that there's not actually any block that requires contig mem?
-Daniel

Quoted 29 lines
---
 drivers/gpu/drm/tegra/gem.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/tegra/gem.c +0 -7
index 6dfad56eee2b..bc15b430156d 100644
@@ -440,13 +440,6 @@ static struct tegra_bo *tegra_bo_import(struct drm_device *drm,
 		err = tegra_bo_iommu_map(tegra, bo);
 		if (err < 0)
 			goto detach;
-	} else {
-		if (bo->sgt->nents > 1) {
-			err = -EINVAL;
-			goto detach;
-		}
-
-		bo->iova = sg_dma_address(bo->sgt->sgl);
 	}
 
 	bo->gem.import_attach = attach;
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw

Re: [PATCH 3/9] drm/tegra: gem: Remove premature import restrictions

Quoted 11 lines · Daniel Vetter
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

It's not known at import time whether or not all users of a DMA-BUF will be able to deal with non-contiguous memory. Each user needs to verify at map-time whether it can access the buffer.

I'm not seeing any other check for nents ... does this mean that there's not actually any block that requires contig mem?

All the blocks require contiguous memory. However, they are all behind an IOMMU and in practice will always end up mapping the buffers through the IOMMU. Techically this check should now be in tegra_dc_pin(), which is called by the ->prepare_fb() callback. I didn't add it because there are no practical use-cases where this happens, although I guess you could come up with a kernel and DTB combination where this is actually possible by jumping through some hoops.

This fix here is to make Tegra DRM interoperation with Nouveau work again since that's currently broken after moving to the IOMMU-backed DMA API as an alternative to explicit IOMMU usage. With explicit IOMMU usage (that's the if corresponding to the else removed below) the IOMMU domain was shared between the display controllers at the driver level, so it was fine to make this determination in the else branch because this was the case where no IOMMU was in play. After the move to the DMA API, this else branch is also taken when the DMA API is backed by an IOMMU and at it is unfortunately not known at import time which display controller ends up scanning out the DMA BUF, nor if that display controller is behind an IOMMU. We only know that when the actual mapping takes place, so we'd need to look at sgt->nents after dma_map_sg() in in tegra_dc_pin().

I'll add that check there, just in case anyone manages to conjure up such a configuration.

Thierry

Quoted 23 lines

-Daniel

Quoted 21 lines
---
 drivers/gpu/drm/tegra/gem.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/tegra/gem.c +0 -7
index 6dfad56eee2b..bc15b430156d 100644
@@ -440,13 +440,6 @@ static struct tegra_bo *tegra_bo_import(struct drm_device *drm,
 		err = tegra_bo_iommu_map(tegra, bo);
 		if (err < 0)
 			goto detach;
-	} else {
-		if (bo->sgt->nents > 1) {
-			err = -EINVAL;
-			goto detach;
-		}
-
-		bo->iova = sg_dma_address(bo->sgt->sgl);
 	}
 
Quoted 13 lines
Quoted 8 lines
drivers/gpu/drm/tegra/gem.c +0 -0
 	bo->gem.import_attach = attach;
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by
#13 lore raw

Re: [PATCH 3/9] drm/tegra: gem: Remove premature import restrictions

Quoted 35 lines · Thierry Reding
Quoted 11 lines · Daniel Vetter
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

It's not known at import time whether or not all users of a DMA-BUF will be able to deal with non-contiguous memory. Each user needs to verify at map-time whether it can access the buffer.

I'm not seeing any other check for nents ... does this mean that there's not actually any block that requires contig mem?

All the blocks require contiguous memory. However, they are all behind an IOMMU and in practice will always end up mapping the buffers through the IOMMU. Techically this check should now be in tegra_dc_pin(), which is called by the ->prepare_fb() callback. I didn't add it because there are no practical use-cases where this happens, although I guess you could come up with a kernel and DTB combination where this is actually possible by jumping through some hoops.

This fix here is to make Tegra DRM interoperation with Nouveau work again since that's currently broken after moving to the IOMMU-backed DMA API as an alternative to explicit IOMMU usage. With explicit IOMMU usage (that's the if corresponding to the else removed below) the IOMMU domain was shared between the display controllers at the driver level, so it was fine to make this determination in the else branch because this was the case where no IOMMU was in play. After the move to the DMA API, this else branch is also taken when the DMA API is backed by an IOMMU and at it is unfortunately not known at import time which display controller ends up scanning out the DMA BUF, nor if that display controller is behind an IOMMU. We only know that when the actual mapping takes place, so we'd need to look at sgt->nents after dma_map_sg() in in tegra_dc_pin().

Quoted 2 lines

I'll add that check there, just in case anyone manages to conjure up such a configuration.

Imo just paste the above explanation into the commit message and

Or also add the check, but imo the explanation here is the important part. -Daniel

Quoted 39 lines

Thierry

Quoted 36 lines

-Daniel

Quoted 29 lines
---
 drivers/gpu/drm/tegra/gem.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/tegra/gem.c +0 -7
index 6dfad56eee2b..bc15b430156d 100644
@@ -440,13 +440,6 @@ static struct tegra_bo *tegra_bo_import(struct drm_device *drm,
 		err = tegra_bo_iommu_map(tegra, bo);
 		if (err < 0)
 			goto detach;
-	} else {
-		if (bo->sgt->nents > 1) {
-			err = -EINVAL;
-			goto detach;
-		}
-
-		bo->iova = sg_dma_address(bo->sgt->sgl);
 	}
 
 	bo->gem.import_attach = attach;
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#14 lore raw

PATCH 4/9 drm/tegra: Use proper IOVA address for cursor image

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

The IOVA address for the cursor is the result of mapping the buffer object for the given display controller. Make sure to use the proper IOVA address as stored in the cursor's plane state.

---
 drivers/gpu/drm/tegra/dc.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/tegra/dc.c +8 -8
index d03b33c3b114..0a5f86b61fda 100644
@@ -847,16 +847,15 @@ static int tegra_cursor_atomic_check(struct drm_plane *plane,
 static void tegra_cursor_atomic_update(struct drm_plane *plane,
 				       struct drm_plane_state *old_state)
 {
-	struct tegra_bo *bo = tegra_fb_get_plane(plane->state->fb, 0);
+	struct tegra_plane_state *state = to_tegra_plane_state(plane->state);
 	struct tegra_dc *dc = to_tegra_dc(plane->state->crtc);
-	struct drm_plane_state *state = plane->state;
 	u32 value = CURSOR_CLIP_DISPLAY;
 
 	/* rien ne va plus */
 	if (!plane->state->crtc || !plane->state->fb)
 		return;
 
-	switch (state->crtc_w) {
+	switch (plane->state->crtc_w) {
 	case 32:
 		value |= CURSOR_SIZE_32x32;
 		break;
@@ -874,16 +873,16 @@ static void tegra_cursor_atomic_update(struct drm_plane *plane,
 		break;
 
 	default:
-		WARN(1, "cursor size %ux%u not supported\n", state->crtc_w,
-		     state->crtc_h);
+		WARN(1, "cursor size %ux%u not supported\n",
+		     plane->state->crtc_w, plane->state->crtc_h);
 		return;
 	}
 
-	value |= (bo->iova >> 10) & 0x3fffff;
+	value |= (state->iova[0] >> 10) & 0x3fffff;
 	tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR);
 
 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
-	value = (bo->iova >> 32) & 0x3;
+	value = (state->iova[0] >> 32) & 0x3;
 	tegra_dc_writel(dc, value, DC_DISP_CURSOR_START_ADDR_HI);
 #endif
 
@@ -902,7 +901,8 @@ static void tegra_cursor_atomic_update(struct drm_plane *plane,
 	tegra_dc_writel(dc, value, DC_DISP_BLEND_CURSOR_CONTROL);
 
 	/* position the cursor */
-	value = (state->crtc_y & 0x3fff) << 16 | (state->crtc_x & 0x3fff);
+	value = (plane->state->crtc_y & 0x3fff) << 16 |
+		(plane->state->crtc_x & 0x3fff);
 	tegra_dc_writel(dc, value, DC_DISP_CURSOR_POSITION);
 }
 
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#15 lore raw

PATCH 5/9 drm/tegra: sor: Implement system suspend/resume

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Upon system suspend, make sure the +5V HDMI regulator is disabled. This avoids potentially leaking current to the HDMI connector. This also makes sure that upon resume the regulator is enabled again, which in some cases is necessary to properly restore the state of the supply on resume.

---
 drivers/gpu/drm/tegra/sor.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/gpu/drm/tegra/sor.c +19 -5
index 615cb319fa8b..2200f4cd397a 100644
@@ -3912,8 +3912,7 @@ static int tegra_sor_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int tegra_sor_suspend(struct device *dev)
+static int tegra_sor_runtime_suspend(struct device *dev)
 {
 	struct tegra_sor *sor = dev_get_drvdata(dev);
 	int err;
@@ -3935,7 +3934,7 @@ static int tegra_sor_suspend(struct device *dev)
 	return 0;
 }
 
-static int tegra_sor_resume(struct device *dev)
+static int tegra_sor_runtime_resume(struct device *dev)
 {
 	struct tegra_sor *sor = dev_get_drvdata(dev);
 	int err;
@@ -3967,10 +3966,25 @@ static int tegra_sor_resume(struct device *dev)
 
 	return 0;
 }
-#endif
+
+static int tegra_sor_suspend(struct device *dev)
+{
+	struct tegra_sor *sor = dev_get_drvdata(dev);
+
+	return regulator_disable(sor->hdmi_supply);
+}
+
+static int tegra_sor_resume(struct device *dev)
+{
+	struct tegra_sor *sor = dev_get_drvdata(dev);
+
+	return regulator_enable(sor->hdmi_supply);
+}
 
 static const struct dev_pm_ops tegra_sor_pm_ops = {
-	SET_RUNTIME_PM_OPS(tegra_sor_suspend, tegra_sor_resume, NULL)
+	SET_RUNTIME_PM_OPS(tegra_sor_runtime_suspend, tegra_sor_runtime_resume,
+			   NULL)
+	SET_SYSTEM_SLEEP_PM_OPS(tegra_sor_suspend, tegra_sor_resume)
 };
 
 struct platform_driver tegra_sor_driver = {
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#16 lore raw

PATCH 6/9 drm/tegra: vic: Export module device table

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Export the module device table to ensure the VIC compatible strings are listed in the module's aliases table. This in turn causes the driver to be automatically loaded on boot if VIC is the only enabled subdevice of the logical host1x DRM device.

---
 drivers/gpu/drm/tegra/vic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/vic.c +3 -2
index 9444ba183990..c4d82b8b3065 100644
@@ -386,13 +386,14 @@ static const struct vic_config vic_t194_config = {
 	.supports_sid = true,
 };
 
-static const struct of_device_id vic_match[] = {
+static const struct of_device_id tegra_vic_of_match[] = {
 	{ .compatible = "nvidia,tegra124-vic", .data = &vic_t124_config },
 	{ .compatible = "nvidia,tegra210-vic", .data = &vic_t210_config },
 	{ .compatible = "nvidia,tegra186-vic", .data = &vic_t186_config },
 	{ .compatible = "nvidia,tegra194-vic", .data = &vic_t194_config },
 	{ },
 };
+MODULE_DEVICE_TABLE(of, tegra_vic_of_match);
 
 static int vic_probe(struct platform_device *pdev)
 {
@@ -516,7 +517,7 @@ static const struct dev_pm_ops vic_pm_ops = {
 struct platform_driver tegra_vic_driver = {
 	.driver = {
 		.name = "tegra-vic",
-		.of_match_table = vic_match,
+		.of_match_table = tegra_vic_of_match,
 		.pm = &vic_pm_ops
 	},
 	.probe = vic_probe,
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#17 lore raw

PATCH 7/9 drm/tegra: Silence expected errors on IOMMU attach

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Subdevices may not be hooked up to an IOMMU via device tree. Detect such situations and avoid confusing users by not emitting an error message.

---
 drivers/gpu/drm/tegra/dc.c  | 2 +-
 drivers/gpu/drm/tegra/drm.c | 4 +---
 drivers/gpu/drm/tegra/vic.c | 2 +-
 3 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/tegra/dc.c +1 -1
index 0a5f86b61fda..2b9a25c977c0 100644
@@ -2027,7 +2027,7 @@ static int tegra_dc_init(struct host1x_client *client)
 		dev_warn(dc->dev, "failed to allocate syncpoint\n");
 
 	err = host1x_client_iommu_attach(client);
-	if (err < 0) {
+	if (err < 0 && err != -ENODEV) {
 		dev_err(client->dev, "failed to attach to domain: %d\n", err);
 		return err;
 	}
drivers/gpu/drm/tegra/drm.c +1 -3
index 56e5e7a5c108..7a16b51eaa2d 100644
@@ -920,10 +920,8 @@ int host1x_client_iommu_attach(struct host1x_client *client)
 
 	if (tegra->domain) {
 		group = iommu_group_get(client->dev);
-		if (!group) {
-			dev_err(client->dev, "failed to get IOMMU group\n");
+		if (!group)
 			return -ENODEV;
-		}
 
 		if (domain != tegra->domain) {
 			err = iommu_attach_group(tegra->domain, group);
drivers/gpu/drm/tegra/vic.c +1 -1
index c4d82b8b3065..3526c2892ddb 100644
@@ -167,7 +167,7 @@ static int vic_init(struct host1x_client *client)
 	int err;
 
 	err = host1x_client_iommu_attach(client);
-	if (err < 0) {
+	if (err < 0 && err != -ENODEV) {
 		dev_err(vic->dev, "failed to attach to domain: %d\n", err);
 		return err;
 	}
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#18 lore raw

PATCH 8/9 drm/tegra: dpaux: Add missing runtime PM references

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Ensure that a runtime PM reference is acquired each time the DPAUX registers are accessed. Otherwise the code may end up running without the controller being powered, out-of-reset or clocked in some corner cases, resulting in a crash.

---
 drivers/gpu/drm/tegra/dpaux.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/dpaux.c +14 -2
index 622cdf1ad246..4b2b86aed1a5 100644
@@ -434,8 +434,13 @@ static int tegra_dpaux_set_mux(struct pinctrl_dev *pinctrl,
 			       unsigned int function, unsigned int group)
 {
 	struct tegra_dpaux *dpaux = pinctrl_dev_get_drvdata(pinctrl);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, function);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, function);
+	return err;
 }
 
 static const struct pinmux_ops tegra_dpaux_pinmux_ops = {
@@ -809,15 +814,22 @@ enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux)
 int drm_dp_aux_enable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	return err;
 }
 
 int drm_dp_aux_disable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
 
+	pm_runtime_get_sync(dpaux->dev);
 	tegra_dpaux_pad_power_down(dpaux);
+	pm_runtime_put(dpaux->dev);
 
 	return 0;
 }
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#19 lore raw

Re: [PATCH 8/9] drm/tegra: dpaux: Add missing runtime PM references

Quoted 8 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Ensure that a runtime PM reference is acquired each time the DPAUX registers are accessed. Otherwise the code may end up running without the controller being powered, out-of-reset or clocked in some corner cases, resulting in a crash.

On patches 4,5,7 in this series Acked-by: Daniel Vetter <[email protected]>

On this one here I'm very confused.

- Why do you drop the runtime pm between enable and disable? Is that just how the hw works, i.e. the pad config stays, just the registers go away?

- I'm not seeing any locking between the different users (dp aux and pinctrl). We might want to change drm_dp_aux->hw_mutex to a pointer to make this easier (but I'm not super fond of that pattern from i2c).

- Your drm_dp_aux_enable/disable needs to be moved into the ->transfer callback, otherwise the various userspace interface (dp aux, but also i2c on top of that) won't work. Some pre/post_transfer functions like i2c has might be useful for stuff like this.

Cheers, Daniel

Quoted 54 lines
---
 drivers/gpu/drm/tegra/dpaux.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/dpaux.c +14 -2
index 622cdf1ad246..4b2b86aed1a5 100644
@@ -434,8 +434,13 @@ static int tegra_dpaux_set_mux(struct pinctrl_dev *pinctrl,
 			       unsigned int function, unsigned int group)
 {
 	struct tegra_dpaux *dpaux = pinctrl_dev_get_drvdata(pinctrl);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, function);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, function);
+	return err;
 }
 
 static const struct pinmux_ops tegra_dpaux_pinmux_ops = {
@@ -809,15 +814,22 @@ enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux)
 int drm_dp_aux_enable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	return err;
 }
 
 int drm_dp_aux_disable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
 
+	pm_runtime_get_sync(dpaux->dev);
 	tegra_dpaux_pad_power_down(dpaux);
+	pm_runtime_put(dpaux->dev);
 
 	return 0;
 }
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#20 lore raw

Re: [PATCH 8/9] drm/tegra: dpaux: Add missing runtime PM references

Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Ensure that a runtime PM reference is acquired each time the DPAUX registers are accessed. Otherwise the code may end up running without the controller being powered, out-of-reset or clocked in some corner cases, resulting in a crash.

Quoted 8 lines
Quoted 1 line

On patches 4,5,7 in this series Acked-by: Daniel Vetter <[email protected]>

On this one here I'm very confused.

- Why do you drop the runtime pm between enable and disable? Is that just how the hw works, i.e. the pad config stays, just the registers go away?

Now you've made me doubt this. I don't think the pad configuration stays across runtime suspend/resume, so you're right, this shouldn't work. I'll need to go retest this one specifically.

I had added these runtime PM references to ensure the device was properly configured at resume from suspend, but there ended up being an additional issue with the I2C driver that relies on this, so perhaps this may not be necessary in the end.

Quoted 3 lines

- I'm not seeing any locking between the different users (dp aux and pinctrl). We might want to change drm_dp_aux->hw_mutex to a pointer to make this easier (but I'm not super fond of that pattern from i2c).

There should be no need to lock here. DP AUX transfers will only be used between drm_dp_aux_enable() and drm_dp_aux_disable().

Quoted 4 lines

- Your drm_dp_aux_enable/disable needs to be moved into the ->transfer callback, otherwise the various userspace interface (dp aux, but also i2c on top of that) won't work. Some pre/post_transfer functions like i2c has might be useful for stuff like this.

I suppose it would be possible for someone to attempt to use those userspace interfaces outside of drm_dp_aux_enable()/drm_dp_aux_disable() and then the locking would be required.

I'll look into that.

Thierry

Quoted 53 lines

Cheers, Daniel

Quoted 50 lines
---
 drivers/gpu/drm/tegra/dpaux.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/dpaux.c +14 -2
index 622cdf1ad246..4b2b86aed1a5 100644
@@ -434,8 +434,13 @@ static int tegra_dpaux_set_mux(struct pinctrl_dev *pinctrl,
 			       unsigned int function, unsigned int group)
 {
 	struct tegra_dpaux *dpaux = pinctrl_dev_get_drvdata(pinctrl);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, function);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, function);
+	return err;
 }
 
 static const struct pinmux_ops tegra_dpaux_pinmux_ops = {
@@ -809,15 +814,22 @@ enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux)
 int drm_dp_aux_enable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	return err;
 }
 
 int drm_dp_aux_disable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
 
+	pm_runtime_get_sync(dpaux->dev);
 	tegra_dpaux_pad_power_down(dpaux);
+	pm_runtime_put(dpaux->dev);
 
 	return 0;
 }
Signature · 1 line
2.23.0
Quoted 9 lines
Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#21 lore raw

Re: [PATCH 8/9] drm/tegra: dpaux: Add missing runtime PM references

Quoted 27 lines · Thierry Reding
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Ensure that a runtime PM reference is acquired each time the DPAUX registers are accessed. Otherwise the code may end up running without the controller being powered, out-of-reset or clocked in some corner cases, resulting in a crash.

Quoted 8 lines
Quoted 1 line

On patches 4,5,7 in this series Acked-by: Daniel Vetter <[email protected]>

On this one here I'm very confused.

- Why do you drop the runtime pm between enable and disable? Is that just how the hw works, i.e. the pad config stays, just the registers go away?

Now you've made me doubt this. I don't think the pad configuration stays across runtime suspend/resume, so you're right, this shouldn't work. I'll need to go retest this one specifically.

I had added these runtime PM references to ensure the device was properly configured at resume from suspend, but there ended up being an additional issue with the I2C driver that relies on this, so perhaps this may not be necessary in the end.

Quoted 6 lines
Quoted 3 lines

- I'm not seeing any locking between the different users (dp aux and pinctrl). We might want to change drm_dp_aux->hw_mutex to a pointer to make this easier (but I'm not super fond of that pattern from i2c).

There should be no need to lock here. DP AUX transfers will only be used between drm_dp_aux_enable() and drm_dp_aux_disable().

So dp aux vs. dp aux aside (that's the next point below), there's guaranteed no one else can get at that pinctrl mux? Since the other setting is labelled I2C I assumed there's an i2c controller hanging of it, exposed to userspace, and userspace might probe that whenever it feels like (similar to the issue below). But I don't know your hw, nor do I really know pinctrl. Just looked a bit strange.

Cheers, Daniel

Quoted 75 lines
Quoted 4 lines

- Your drm_dp_aux_enable/disable needs to be moved into the ->transfer callback, otherwise the various userspace interface (dp aux, but also i2c on top of that) won't work. Some pre/post_transfer functions like i2c has might be useful for stuff like this.

I suppose it would be possible for someone to attempt to use those userspace interfaces outside of drm_dp_aux_enable()/drm_dp_aux_disable() and then the locking would be required.

I'll look into that.

Thierry

Quoted 62 lines

Cheers, Daniel

Quoted 54 lines
---
 drivers/gpu/drm/tegra/dpaux.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/dpaux.c +14 -2
index 622cdf1ad246..4b2b86aed1a5 100644
@@ -434,8 +434,13 @@ static int tegra_dpaux_set_mux(struct pinctrl_dev *pinctrl,
 			       unsigned int function, unsigned int group)
 {
 	struct tegra_dpaux *dpaux = pinctrl_dev_get_drvdata(pinctrl);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, function);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, function);
+	return err;
 }
 
 static const struct pinmux_ops tegra_dpaux_pinmux_ops = {
@@ -809,15 +814,22 @@ enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux)
 int drm_dp_aux_enable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	return err;
 }
 
 int drm_dp_aux_disable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
 
+	pm_runtime_get_sync(dpaux->dev);
 	tegra_dpaux_pad_power_down(dpaux);
+	pm_runtime_put(dpaux->dev);
 
 	return 0;
 }
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#22 lore raw

Re: [PATCH 8/9] drm/tegra: dpaux: Add missing runtime PM references

Quoted 35 lines · Daniel Vetter
Quoted 27 lines · Thierry Reding
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Ensure that a runtime PM reference is acquired each time the DPAUX registers are accessed. Otherwise the code may end up running without the controller being powered, out-of-reset or clocked in some corner cases, resulting in a crash.

Quoted 8 lines
Quoted 1 line

On patches 4,5,7 in this series Acked-by: Daniel Vetter <[email protected]>

On this one here I'm very confused.

- Why do you drop the runtime pm between enable and disable? Is that just how the hw works, i.e. the pad config stays, just the registers go away?

Now you've made me doubt this. I don't think the pad configuration stays across runtime suspend/resume, so you're right, this shouldn't work. I'll need to go retest this one specifically.

I had added these runtime PM references to ensure the device was properly configured at resume from suspend, but there ended up being an additional issue with the I2C driver that relies on this, so perhaps this may not be necessary in the end.

Quoted 6 lines
Quoted 3 lines

- I'm not seeing any locking between the different users (dp aux and pinctrl). We might want to change drm_dp_aux->hw_mutex to a pointer to make this easier (but I'm not super fond of that pattern from i2c).

There should be no need to lock here. DP AUX transfers will only be used between drm_dp_aux_enable() and drm_dp_aux_disable().

Quoted 6 lines

So dp aux vs. dp aux aside (that's the next point below), there's guaranteed no one else can get at that pinctrl mux? Since the other setting is labelled I2C I assumed there's an i2c controller hanging of it, exposed to userspace, and userspace might probe that whenever it feels like (similar to the issue below). But I don't know your hw, nor do I really know pinctrl. Just looked a bit strange.

Well technically anyone could get at the mux, but since it controls the pins of a single I2C controller, only that I2C controller should ever get its hands on the pinmux. Anything else would be an error in the DT.

Now, the pins can also be used in AUX mode when the SOR is used in DP mode. However, since DP and HDMI are mutually exclusive, this is a board level decision, so in practice you're only ever going to see them used in either I2C or AUX mode. The "off" mode is used only for power saving when I2C or DPAUX don't use the pins.

Regarding the runtime PM references, it turns out that those are completely bogus because we already take a runtime PM reference at probe time. I'm going to drop this patch and look into fixing the other, real issues that you pointed out.

Thierry

Quoted 70 lines

Cheers, Daniel

Quoted 66 lines
Quoted 4 lines

- Your drm_dp_aux_enable/disable needs to be moved into the ->transfer callback, otherwise the various userspace interface (dp aux, but also i2c on top of that) won't work. Some pre/post_transfer functions like i2c has might be useful for stuff like this.

I suppose it would be possible for someone to attempt to use those userspace interfaces outside of drm_dp_aux_enable()/drm_dp_aux_disable() and then the locking would be required.

I'll look into that.

Thierry

Quoted 53 lines

Cheers, Daniel

Quoted 50 lines
---
 drivers/gpu/drm/tegra/dpaux.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/dpaux.c +14 -2
index 622cdf1ad246..4b2b86aed1a5 100644
@@ -434,8 +434,13 @@ static int tegra_dpaux_set_mux(struct pinctrl_dev *pinctrl,
 			       unsigned int function, unsigned int group)
 {
 	struct tegra_dpaux *dpaux = pinctrl_dev_get_drvdata(pinctrl);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, function);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, function);
+	return err;
 }
 
 static const struct pinmux_ops tegra_dpaux_pinmux_ops = {
@@ -809,15 +814,22 @@ enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux)
 int drm_dp_aux_enable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	return err;
 }
 
 int drm_dp_aux_disable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
 
+	pm_runtime_get_sync(dpaux->dev);
 	tegra_dpaux_pad_power_down(dpaux);
+	pm_runtime_put(dpaux->dev);
 
 	return 0;
 }
Signature · 1 line
2.23.0
Quoted 16 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#23 lore raw

Re: [PATCH 8/9] drm/tegra: dpaux: Add missing runtime PM references

Quoted 47 lines · Thierry Reding
Quoted 35 lines · Daniel Vetter
Quoted 27 lines · Thierry Reding
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Ensure that a runtime PM reference is acquired each time the DPAUX registers are accessed. Otherwise the code may end up running without the controller being powered, out-of-reset or clocked in some corner cases, resulting in a crash.

Quoted 8 lines
Quoted 1 line

On patches 4,5,7 in this series Acked-by: Daniel Vetter <[email protected]>

On this one here I'm very confused.

- Why do you drop the runtime pm between enable and disable? Is that just how the hw works, i.e. the pad config stays, just the registers go away?

Now you've made me doubt this. I don't think the pad configuration stays across runtime suspend/resume, so you're right, this shouldn't work. I'll need to go retest this one specifically.

I had added these runtime PM references to ensure the device was properly configured at resume from suspend, but there ended up being an additional issue with the I2C driver that relies on this, so perhaps this may not be necessary in the end.

Quoted 6 lines
Quoted 3 lines

- I'm not seeing any locking between the different users (dp aux and pinctrl). We might want to change drm_dp_aux->hw_mutex to a pointer to make this easier (but I'm not super fond of that pattern from i2c).

There should be no need to lock here. DP AUX transfers will only be used between drm_dp_aux_enable() and drm_dp_aux_disable().

Quoted 6 lines

So dp aux vs. dp aux aside (that's the next point below), there's guaranteed no one else can get at that pinctrl mux? Since the other setting is labelled I2C I assumed there's an i2c controller hanging of it, exposed to userspace, and userspace might probe that whenever it feels like (similar to the issue below). But I don't know your hw, nor do I really know pinctrl. Just looked a bit strange.

Well technically anyone could get at the mux, but since it controls the pins of a single I2C controller, only that I2C controller should ever get its hands on the pinmux. Anything else would be an error in the DT.

Quoted 5 lines

Now, the pins can also be used in AUX mode when the SOR is used in DP mode. However, since DP and HDMI are mutually exclusive, this is a board level decision, so in practice you're only ever going to see them used in either I2C or AUX mode. The "off" mode is used only for power saving when I2C or DPAUX don't use the pins.

Oh, so you don't support DP+ with some auto level shifter magic? At least in other drivers DP+ is why you need to have a lock between dp aux and i2c at runtime, because otherwise things go wrong if you reprobe DP while userspace is probing the hdmi i2c side (or the other way round).

Quoted 4 lines

Regarding the runtime PM references, it turns out that those are completely bogus because we already take a runtime PM reference at probe time. I'm going to drop this patch and look into fixing the other, real issues that you pointed out.

Ah that explains the confusion :-)
-Daniel

Quoted 89 lines

Thierry

Quoted 86 lines

Cheers, Daniel

Quoted 75 lines
Quoted 4 lines

- Your drm_dp_aux_enable/disable needs to be moved into the ->transfer callback, otherwise the various userspace interface (dp aux, but also i2c on top of that) won't work. Some pre/post_transfer functions like i2c has might be useful for stuff like this.

I suppose it would be possible for someone to attempt to use those userspace interfaces outside of drm_dp_aux_enable()/drm_dp_aux_disable() and then the locking would be required.

I'll look into that.

Thierry

Quoted 62 lines

Cheers, Daniel

Quoted 54 lines
---
 drivers/gpu/drm/tegra/dpaux.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/dpaux.c +14 -2
index 622cdf1ad246..4b2b86aed1a5 100644
@@ -434,8 +434,13 @@ static int tegra_dpaux_set_mux(struct pinctrl_dev *pinctrl,
 			       unsigned int function, unsigned int group)
 {
 	struct tegra_dpaux *dpaux = pinctrl_dev_get_drvdata(pinctrl);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, function);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, function);
+	return err;
 }
 
 static const struct pinmux_ops tegra_dpaux_pinmux_ops = {
@@ -809,15 +814,22 @@ enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux)
 int drm_dp_aux_enable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
+	int err;
+
+	pm_runtime_get_sync(dpaux->dev);
+	err = tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	pm_runtime_put(dpaux->dev);
 
-	return tegra_dpaux_pad_config(dpaux, DPAUX_PADCTL_FUNC_AUX);
+	return err;
 }
 
 int drm_dp_aux_disable(struct drm_dp_aux *aux)
 {
 	struct tegra_dpaux *dpaux = to_dpaux(aux);
 
+	pm_runtime_get_sync(dpaux->dev);
 	tegra_dpaux_pad_power_down(dpaux);
+	pm_runtime_put(dpaux->dev);
 
 	return 0;
 }
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#24 lore raw

PATCH 9/9 drm/tegra: sor: Make the +5V HDMI supply optional

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

The SOR supports multiple display modes, but only when driving an HDMI monitor does it make sense to control the +5V power supply. eDP and DP don't need this, so make it optional.

This fixes a crash observed during system suspend/resume.

---
 drivers/gpu/drm/tegra/sor.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/sor.c +16 -2
index 2200f4cd397a..a68d3b36b972 100644
@@ -3970,15 +3970,29 @@ static int tegra_sor_runtime_resume(struct device *dev)
 static int tegra_sor_suspend(struct device *dev)
 {
 	struct tegra_sor *sor = dev_get_drvdata(dev);
+	int err;
+
+	if (sor->hdmi_supply) {
+		err = regulator_disable(sor->hdmi_supply);
+		if (err < 0)
+			return err;
+	}
 
-	return regulator_disable(sor->hdmi_supply);
+	return 0;
 }
 
 static int tegra_sor_resume(struct device *dev)
 {
 	struct tegra_sor *sor = dev_get_drvdata(dev);
+	int err;
+
+	if (sor->hdmi_supply) {
+		err = regulator_enable(sor->hdmi_supply);
+		if (err < 0)
+			return err;
+	}
 
-	return regulator_enable(sor->hdmi_supply);
+	return 0;
 }
 
 static const struct dev_pm_ops tegra_sor_pm_ops = {
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Acked-by on v1 9/9
#25 lore raw

Re: [PATCH 9/9] drm/tegra: sor: Make the +5V HDMI supply optional

Quoted 9 lines · Thierry Reding

From: Thierry Reding <[email protected]>

The SOR supports multiple display modes, but only when driving an HDMI monitor does it make sense to control the +5V power supply. eDP and DP don't need this, so make it optional.

This fixes a crash observed during system suspend/resume.

Quoted 47 lines
---
 drivers/gpu/drm/tegra/sor.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/sor.c +16 -2
index 2200f4cd397a..a68d3b36b972 100644
@@ -3970,15 +3970,29 @@ static int tegra_sor_runtime_resume(struct device *dev)
 static int tegra_sor_suspend(struct device *dev)
 {
 	struct tegra_sor *sor = dev_get_drvdata(dev);
+	int err;
+
+	if (sor->hdmi_supply) {
+		err = regulator_disable(sor->hdmi_supply);
+		if (err < 0)
+			return err;
+	}
 
-	return regulator_disable(sor->hdmi_supply);
+	return 0;
 }
 
 static int tegra_sor_resume(struct device *dev)
 {
 	struct tegra_sor *sor = dev_get_drvdata(dev);
+	int err;
+
+	if (sor->hdmi_supply) {
+		err = regulator_enable(sor->hdmi_supply);
+		if (err < 0)
+			return err;
+	}
 
-	return regulator_enable(sor->hdmi_supply);
+	return 0;
 }
 
 static const struct dev_pm_ops tegra_sor_pm_ops = {
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel