Skip to contentSkip to conversation

drm: Add drm_mode_display_size helper function

PATCH Superseded Jonathan Cavitt 3 participants 3 messages Sep 30, 2025 – Oct 1, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: Add drm_mode_display_size helper function

Add a helper function that computes the product of hdisplay and vdisplay.

Cc Matthew Auld <[email protected]>
Cc Himal Prasad Ghimiray <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 2 +-
 drivers/gpu/drm/drm_mipi_dbi.c        | 2 +-
 include/drm/drm_modes.h               | 5 +++++
 3 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_vram_helper.c +1 -1
index 90760d0ca071..4ac71c34f4c6 100644
@@ -967,7 +967,7 @@ drm_vram_helper_mode_valid_internal(struct drm_device *dev,
 
 	max_fbpages = (vmm->vram_size / 2) >> PAGE_SHIFT;
 
-	fbsize = mode->hdisplay * mode->vdisplay * max_bpp;
+	fbsize = drm_mode_display_size(mode) * max_bpp;
 	fbpages = DIV_ROUND_UP(fbsize, PAGE_SIZE);
 
 	if (fbpages > max_fbpages)
drivers/gpu/drm/drm_mipi_dbi.c +1 -1
index e33c78fc8fbd..54212bf85160 100644
@@ -691,7 +691,7 @@ int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
 		      const struct drm_simple_display_pipe_funcs *funcs,
 		      const struct drm_display_mode *mode, unsigned int rotation)
 {
-	size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16);
+	size_t bufsize = drm_mode_display_size(mode) * sizeof(u16);
 
 	dbidev->drm.mode_config.preferred_depth = 16;
 
include/drm/drm_modes.h +5 -0
index b9bb92e4b029..775c94c55cda 100644
@@ -572,4 +572,9 @@ struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 				  struct drm_cmdline_mode *cmd);
 
+static inline u32 drm_mode_display_size(const struct drm_display_mode *mode)
+{
+	return mode->hdisplay * mode->vdisplay;
+}
+
 #endif /* __DRM_MODES_H__ */
Signature · 1 line
2.43.0
#1 lore raw
Quoted 44 lines · Jonathan Cavitt

Add a helper function that computes the product of hdisplay and vdisplay.

Cc Matthew Auld <[email protected]>
Cc Himal Prasad Ghimiray <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 2 +-
 drivers/gpu/drm/drm_mipi_dbi.c        | 2 +-
 include/drm/drm_modes.h               | 5 +++++
 3 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_vram_helper.c +1 -1
index 90760d0ca071..4ac71c34f4c6 100644
@@ -967,7 +967,7 @@ drm_vram_helper_mode_valid_internal(struct drm_device *dev,
 
 	max_fbpages = (vmm->vram_size / 2) >> PAGE_SHIFT;
 
-	fbsize = mode->hdisplay * mode->vdisplay * max_bpp;
+	fbsize = drm_mode_display_size(mode) * max_bpp;
 	fbpages = DIV_ROUND_UP(fbsize, PAGE_SIZE);
 
 	if (fbpages > max_fbpages)
drivers/gpu/drm/drm_mipi_dbi.c +1 -1
index e33c78fc8fbd..54212bf85160 100644
@@ -691,7 +691,7 @@ int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
 		      const struct drm_simple_display_pipe_funcs *funcs,
 		      const struct drm_display_mode *mode, unsigned int rotation)
 {
-	size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16);
+	size_t bufsize = drm_mode_display_size(mode) * sizeof(u16);
 
 	dbidev->drm.mode_config.preferred_depth = 16;
 
include/drm/drm_modes.h +0 -0
index b9bb92e4b029..775c94c55cda 100644

include/drm/drm_modes.h struct drm_display_mode * · line 578

Quoted 7 lines
include/drm/drm_modes.h +4 -0
@@ -572,4 +572,9 @@ struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 				  struct drm_cmdline_mode *cmd);
 
+static inline u32 drm_mode_display_size(const struct drm_display_mode *mode)
+{
+	return mode->hdisplay * mode->vdisplay;
+}

All functions here need kernel-doc.

I wonder if "size" is specific enough.

BR,
Jani.

Quoted 2 lines
include/drm/drm_modes.h +1 -0
+
 #endif /* __DRM_MODES_H__ */
Signature · 1 line
Jani Nikula, Intel
#2 lore raw
In reply to Jonathan Cavitt
Quoted 18 lines · Jonathan Cavitt

Add a helper function that computes the product of hdisplay and vdisplay.

Cc Matthew Auld <[email protected]>
Cc Himal Prasad Ghimiray <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 2 +-
 drivers/gpu/drm/drm_mipi_dbi.c        | 2 +-
 include/drm/drm_modes.h               | 5 +++++
 3 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_vram_helper.c +0 -0
index 90760d0ca071..4ac71c34f4c6 100644

drivers/gpu/drm/drm_gem_vram_helper.c drm_vram_helper_mode_valid_internal(struct drm_device *dev, · line 970

Quoted 4 lines
drivers/gpu/drm/drm_gem_vram_helper.c +0 -1
@@ -967,7 +967,7 @@ drm_vram_helper_mode_valid_internal(struct drm_device *dev,
 
 	max_fbpages = (vmm->vram_size / 2) >> PAGE_SHIFT;
 
-	fbsize = mode->hdisplay * mode->vdisplay * max_bpp;

This calculation is quite inaccurate since it doesn't consider any stride alignment requirements. Maybe it works for a few cases, but certainly not usable on most hardware.

Quoted 22 lines
drivers/gpu/drm/drm_gem_vram_helper.c +1 -0
+	fbsize = drm_mode_display_size(mode) * max_bpp;
 	fbpages = DIV_ROUND_UP(fbsize, PAGE_SIZE);
 
 	if (fbpages > max_fbpages)
drivers/gpu/drm/drm_mipi_dbi.c +1 -1
index e33c78fc8fbd..54212bf85160 100644
@@ -691,7 +691,7 @@ int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
 		      const struct drm_simple_display_pipe_funcs *funcs,
 		      const struct drm_display_mode *mode, unsigned int rotation)
 {
-	size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16);
+	size_t bufsize = drm_mode_display_size(mode) * sizeof(u16);
 
 	dbidev->drm.mode_config.preferred_depth = 16;
 
include/drm/drm_modes.h +0 -0
index b9bb92e4b029..775c94c55cda 100644

include/drm/drm_modes.h struct drm_display_mode * · line 575

Quoted 4 lines
include/drm/drm_modes.h +1 -0
@@ -572,4 +572,9 @@ struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 				  struct drm_cmdline_mode *cmd);
 
+static inline u32 drm_mode_display_size(const struct drm_display_mode *mode)

"display size" isn't really a term that gives me any kind of idea what this does, so the name is rather poor. drm_mode_num_active_pixels() or something might make more sense. But I'm not sure there's much point in this helper since that value is very rarely useful for anything.

Quoted 7 lines
include/drm/drm_modes.h +4 -0
+{
+	return mode->hdisplay * mode->vdisplay;
+}
+
 #endif /* __DRM_MODES_H__ */
Signature · 1 line
2.43.0
Signature · 2 lines
Ville Syrjälä
Intel