Skip to contentSkip to conversation

drm/tegra: Remove existing framebuffer only if we support display

PATCH Superseded Thierry Reding 5 participants 10 messages Aug 25, 2023 – Sep 7, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/tegra: Remove existing framebuffer only if we support display

From: Thierry Reding <[email protected]>

Tegra DRM doesn't support display on Tegra234 and later, so make sure not to remove any existing framebuffers in that case.

---
 drivers/gpu/drm/tegra/drm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/tegra/drm.c +5 -3
index b1e1a78e30c6..7a38dadbc264 100644
@@ -1220,9 +1220,11 @@ static int host1x_drm_probe(struct host1x_device *dev)
 
 	drm_mode_config_reset(drm);
 
-	err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
-	if (err < 0)
-		goto hub;
+	if (drm->mode_config.num_crtc > 0) {
+		err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
+		if (err < 0)
+			goto hub;
+	}
 
 	err = drm_dev_register(drm, 0);
 	if (err < 0)
Signature · 1 line
2.41.0
Acked-by on v1 1/1
#1 lore raw

Thierry Reding <[email protected]> writes:

Hello Thierry,

Quoted 5 lines

From: Thierry Reding <[email protected]>

Tegra DRM doesn't support display on Tegra234 and later, so make sure not to remove any existing framebuffers in that case.

I see, this makes sense to me.

A couple of comments below though:

Quoted 10 lines
---
 drivers/gpu/drm/tegra/drm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/tegra/drm.c +0 -0
index b1e1a78e30c6..7a38dadbc264 100644

drivers/gpu/drm/tegra/drm.c static int host1x_drm_probe(struct host1x_device *dev) · line 1223

Quoted 7 lines
drivers/gpu/drm/tegra/drm.c +1 -3
@@ -1220,9 +1220,11 @@ static int host1x_drm_probe(struct host1x_device *dev)
 
 	drm_mode_config_reset(drm);
 
-	err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
-	if (err < 0)
-		goto hub;
+	if (drm->mode_config.num_crtc > 0) {

Maybe you can add a comment here explaining why the check is needed?

I also wonder if is worth to move the drm_num_crtcs() function from drivers/gpu/drm/drm_crtc.c to include/drm/drm_crtc.h and use that helper instead?

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#2 lore raw
Quoted 27 lines · Javier Martinez Canillas

Thierry Reding <[email protected]> writes:

Hello Thierry,

Quoted 5 lines

From: Thierry Reding <[email protected]>

Tegra DRM doesn't support display on Tegra234 and later, so make sure not to remove any existing framebuffers in that case.

I see, this makes sense to me.

A couple of comments below though:

Quoted 11 lines
---
 drivers/gpu/drm/tegra/drm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/tegra/drm.c +0 -0
index b1e1a78e30c6..7a38dadbc264 100644
@@ -1220,9 +1220,11 @@ static int host1x_drm_probe(struct host1x_device *dev)
 
Quoted 8 lines

drivers/gpu/drm/tegra/drm.c static int host1x_drm_probe(struct host1x_device *dev) · line 1223

Quoted 6 lines
drivers/gpu/drm/tegra/drm.c +1 -3
 	drm_mode_config_reset(drm);
 
-	err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
-	if (err < 0)
-		goto hub;
+	if (drm->mode_config.num_crtc > 0) {

Maybe you can add a comment here explaining why the check is needed?

Sure, will do.

Quoted 3 lines

I also wonder if is worth to move the drm_num_crtcs() function from drivers/gpu/drm/drm_crtc.c to include/drm/drm_crtc.h and use that helper instead?

I've been looking at this, there's a few things that come to mind. It seems like we have a couple of different ways to get the number of CRTCs for a device. We have struct drm_device's num_crtcs, which is set during drm_vblank_init(), then we have struct drm_mode_config's num_crtc, which is incremented every time a new CRTC is added (and decremented when a CRTC is removed), and finally we've got the drm_num_crtcs() which "computes" the number of CRTCs registered by iterating over all CRTCs that have been registered.

Are there any cases where these three can yield different values? Would it not make sense to consolidate these into a single variable?

Thierry

#3 lore raw

Thierry Reding <[email protected]> writes:

Hello Thierry,

Quoted 1 line · Javier Martinez Canillas

[...]

Quoted 13 lines
Quoted 3 lines

I also wonder if is worth to move the drm_num_crtcs() function from drivers/gpu/drm/drm_crtc.c to include/drm/drm_crtc.h and use that helper instead?

I've been looking at this, there's a few things that come to mind. It seems like we have a couple of different ways to get the number of CRTCs for a device. We have struct drm_device's num_crtcs, which is set during drm_vblank_init(), then we have struct drm_mode_config's num_crtc, which is incremented every time a new CRTC is added (and decremented when a CRTC is removed), and finally we've got the drm_num_crtcs() which "computes" the number of CRTCs registered by iterating over all CRTCs that have been registered.

Quoted 3 lines

Are there any cases where these three can yield different values? Would it not make sense to consolidate these into a single variable?

I als was confused by that when looked at the implementation of the mentioned helpers and couldn't find a reason why there are different ways to calculate the number of CRTCs.

Maybe Sima or someone else can shed some light?

Quoted 1 line

Thierry

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#4 lore raw
In reply to Thierry Reding

Hi

Am 25.08.23 um 15:22 schrieb Thierry Reding:

Quoted 15 lines

From: Thierry Reding <[email protected]>

Tegra DRM doesn't support display on Tegra234 and later, so make sure not to remove any existing framebuffers in that case.

---
  drivers/gpu/drm/tegra/drm.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/tegra/drm.c +0 -0
index b1e1a78e30c6..7a38dadbc264 100644

drivers/gpu/drm/tegra/drm.c static int host1x_drm_probe(struct host1x_device *dev) · line 1223

Quoted 7 lines
drivers/gpu/drm/tegra/drm.c +1 -3
@@ -1220,9 +1220,11 @@ static int host1x_drm_probe(struct host1x_device *dev)
 
  	drm_mode_config_reset(drm);
 
-	err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
-	if (err < 0)
-		goto hub;
+	if (drm->mode_config.num_crtc > 0) {

If you don't support the hardware, wouldn't it be better to return -ENODEV if !num_crtc?

Best regards
Thomas

Quoted 7 lines
drivers/gpu/drm/tegra/drm.c +4 -0
+		err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
+		if (err < 0)
+			goto hub;
+	}
 
  	err = drm_dev_register(drm, 0);
  	if (err < 0)
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#5 lore raw
Quoted 13 lines · Thomas Zimmermann

Hi

Am 25.08.23 um 15:22 schrieb Thierry Reding:

Quoted 10 lines

From: Thierry Reding <[email protected]>

Tegra DRM doesn't support display on Tegra234 and later, so make sure not to remove any existing framebuffers in that case.

---
  drivers/gpu/drm/tegra/drm.c | 8 +++++---

  1 file changed, 5 insertions(+), 3 deletions(-)
Quoted 14 lines

drivers/gpu/drm/tegra/drm.c static int host1x_drm_probe(struct · line 1222

Quoted 11 lines
drivers/gpu/drm/tegra/drm.c +1 -3
index b1e1a78e30c6..7a38dadbc264 100644
@@ -1220,9 +1220,11 @@ static int host1x_drm_probe(struct 
 host1x_device *dev)
       drm_mode_config_reset(drm);
-    err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
-    if (err < 0)
-        goto hub;
+    if (drm->mode_config.num_crtc > 0) {

If you don't support the hardware, wouldn't it be better to return -ENODEV if !num_crtc?

While display is not supported through TegraDRM on Tegra234+, certain multimedia accelerators are supported, so we need to finish probe for those.

Cheers,
Mikko

Quoted 11 lines

Best regards
Thomas

Quoted 6 lines
drivers/gpu/drm/tegra/drm.c +4 -0
+        err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
+        if (err < 0)
+            goto hub;
+    }
       err = drm_dev_register(drm, 0);
       if (err < 0)
#6 lore raw
Quoted 30 lines · Mikko Perttunen
Quoted 13 lines · Thomas Zimmermann

Hi

Am 25.08.23 um 15:22 schrieb Thierry Reding:

Quoted 10 lines

From: Thierry Reding <[email protected]>

Tegra DRM doesn't support display on Tegra234 and later, so make sure not to remove any existing framebuffers in that case.

---
  drivers/gpu/drm/tegra/drm.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
Quoted 14 lines

drivers/gpu/drm/tegra/drm.c static int host1x_drm_probe(struct · line 1222

Quoted 11 lines
drivers/gpu/drm/tegra/drm.c +1 -3
index b1e1a78e30c6..7a38dadbc264 100644
@@ -1220,9 +1220,11 @@ static int host1x_drm_probe(struct
 host1x_device *dev)
      drm_mode_config_reset(drm);
-    err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
-    if (err < 0)
-        goto hub;
+    if (drm->mode_config.num_crtc > 0) {

If you don't support the hardware, wouldn't it be better to return -ENODEV if !num_crtc?

Quoted 2 lines

While display is not supported through TegraDRM on Tegra234+, certain multimedia accelerators are supported, so we need to finish probe for those.

Ideally you also register the tegra driver without DRIVER_MODESET | DRIVER_ATOMIC in that case, to avoid unecessary userspace confusion. Most userspace can cope with a display driver without any crtc, but I think xorg-modesettting actually falls over. Or at least I've seen some hacks that the agx people added to make sure X doesn't accidentally open the wrong driver.
-Sima

Quoted 16 lines

Cheers,
Mikko

Quoted 11 lines

Best regards
Thomas

Quoted 6 lines
drivers/gpu/drm/tegra/drm.c +4 -0
+        err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
+        if (err < 0)
+            goto hub;
+    }
      err = drm_dev_register(drm, 0);
      if (err < 0)
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#7 lore raw
Quoted 34 lines · Daniel Vetter
Quoted 30 lines · Mikko Perttunen
Quoted 13 lines · Thomas Zimmermann

Hi

Am 25.08.23 um 15:22 schrieb Thierry Reding:

Quoted 10 lines

From: Thierry Reding <[email protected]>

Tegra DRM doesn't support display on Tegra234 and later, so make sure not to remove any existing framebuffers in that case.

---
  drivers/gpu/drm/tegra/drm.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
Quoted 14 lines

drivers/gpu/drm/tegra/drm.c static int host1x_drm_probe(struct · line 1222

Quoted 11 lines
drivers/gpu/drm/tegra/drm.c +1 -3
index b1e1a78e30c6..7a38dadbc264 100644
@@ -1220,9 +1220,11 @@ static int host1x_drm_probe(struct
 host1x_device *dev)
      drm_mode_config_reset(drm);
-    err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
-    if (err < 0)
-        goto hub;
+    if (drm->mode_config.num_crtc > 0) {

If you don't support the hardware, wouldn't it be better to return -ENODEV if !num_crtc?

Quoted 2 lines

While display is not supported through TegraDRM on Tegra234+, certain multimedia accelerators are supported, so we need to finish probe for those.

Quoted 6 lines

Ideally you also register the tegra driver without DRIVER_MODESET | DRIVER_ATOMIC in that case, to avoid unecessary userspace confusion. Most userspace can cope with a display driver without any crtc, but I think xorg-modesettting actually falls over. Or at least I've seen some hacks that the agx people added to make sure X doesn't accidentally open the wrong driver.

That's a good point. However I recall from earlier attempts at doing something like this in Nouveau (although this is now very long ago) that it's not very easy. The problem, as I recall, is that the driver is a singleton, so we would essentially be supporting either modesetting or not, for any device in the system.

Now, it's unlikely that we'd have a mix of one Tegra DRM driver with display support and another without, but it's something that I recall back at the time with Nouveau was problematic because you could have the Tegra integrated graphics (without display support) and a PCI-connected discrete GPU (with display support) within the same system.

I need to look into it a bit more to see if I can come up with something good to account for this.

Thierry

#8 lore raw

Hi

Am 07.09.23 um 10:03 schrieb Thierry Reding:

Quoted 42 lines · Daniel Vetter
Quoted 34 lines · Mikko Perttunen
Quoted 30 lines · Thomas Zimmermann
Quoted 13 lines

Hi

Am 25.08.23 um 15:22 schrieb Thierry Reding:

Quoted 10 lines

From: Thierry Reding <[email protected]>

Tegra DRM doesn't support display on Tegra234 and later, so make sure not to remove any existing framebuffers in that case.

---
   drivers/gpu/drm/tegra/drm.c | 8 +++++---
   1 file changed, 5 insertions(+), 3 deletions(-)
Quoted 14 lines

drivers/gpu/drm/tegra/drm.c static int host1x_drm_probe(struct · line 1222

Quoted 11 lines
drivers/gpu/drm/tegra/drm.c +1 -3
index b1e1a78e30c6..7a38dadbc264 100644
@@ -1220,9 +1220,11 @@ static int host1x_drm_probe(struct
 host1x_device *dev)
       drm_mode_config_reset(drm);
-    err = drm_aperture_remove_framebuffers(&tegra_drm_driver);
-    if (err < 0)
-        goto hub;
+    if (drm->mode_config.num_crtc > 0) {

If you don't support the hardware, wouldn't it be better to return -ENODEV if !num_crtc?

Quoted 2 lines

While display is not supported through TegraDRM on Tegra234+, certain multimedia accelerators are supported, so we need to finish probe for those.

Quoted 6 lines

Ideally you also register the tegra driver without DRIVER_MODESET | DRIVER_ATOMIC in that case, to avoid unecessary userspace confusion. Most userspace can cope with a display driver without any crtc, but I think xorg-modesettting actually falls over. Or at least I've seen some hacks that the agx people added to make sure X doesn't accidentally open the wrong driver.

Quoted 5 lines

That's a good point. However I recall from earlier attempts at doing something like this in Nouveau (although this is now very long ago) that it's not very easy. The problem, as I recall, is that the driver is a singleton, so we would essentially be supporting either modesetting or not, for any device in the system.

Take a look at struct drm_device.driver_features. It let's you clear the flags that your device doesn't support.

https://elixir.bootlin.com/linux/v6.5/source/include/drm/drm_device.h#L128

Best regards
Thomas

Quoted 11 lines

Now, it's unlikely that we'd have a mix of one Tegra DRM driver with display support and another without, but it's something that I recall back at the time with Nouveau was problematic because you could have the Tegra integrated graphics (without display support) and a PCI-connected discrete GPU (with display support) within the same system.

I need to look into it a bit more to see if I can come up with something good to account for this.

Thierry

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#9 lore raw

Thomas Zimmermann <[email protected]> writes:

[...]

Quoted 11 lines
Quoted 5 lines

That's a good point. However I recall from earlier attempts at doing something like this in Nouveau (although this is now very long ago) that it's not very easy. The problem, as I recall, is that the driver is a singleton, so we would essentially be supporting either modesetting or not, for any device in the system.

Take a look at struct drm_device.driver_features. It let's you clear the flags that your device doesn't support.

https://elixir.bootlin.com/linux/v6.5/source/include/drm/drm_device.h#L128

That sounds indeed as the best approach and I see that at least i915 does it:

https://elixir.bootlin.com/linux/v6.5/source/drivers/gpu/drm/i915/intel_device_info.c#L418

Quoted 3 lines

Best regards
Thomas

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat