Re: [PATCH v2 11/25] drm/loongson: Compute dumb-buffer sizes with drm_mode_size_dumb()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 2025/1/9 22:57, Thomas Zimmermann wrote:
Call drm_mode_size_dumb() to compute dumb-buffer scanline pitch and
buffer size. Align the pitch according to hardware requirements.

Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx>
Cc: Sui Jingfeng <suijingfeng@xxxxxxxxxxx>
Cc: Sui Jingfeng <sui.jingfeng@xxxxxxxxx>


Reviewed-by: Sui Jingfeng <sui.jingfeng@xxxxxxxxx>


---
  drivers/gpu/drm/loongson/lsdc_gem.c | 29 ++++++++---------------------
  1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/loongson/lsdc_gem.c b/drivers/gpu/drm/loongson/lsdc_gem.c
index a720d8f53209..9f982b85301f 100644
--- a/drivers/gpu/drm/loongson/lsdc_gem.c
+++ b/drivers/gpu/drm/loongson/lsdc_gem.c
@@ -6,6 +6,7 @@
  #include <linux/dma-buf.h>
#include <drm/drm_debugfs.h>
+#include <drm/drm_dumb_buffers.h>
  #include <drm/drm_file.h>
  #include <drm/drm_gem.h>
  #include <drm/drm_prime.h>
@@ -204,45 +205,31 @@ int lsdc_dumb_create(struct drm_file *file, struct drm_device *ddev,
  	const struct lsdc_desc *descp = ldev->descp;
  	u32 domain = LSDC_GEM_DOMAIN_VRAM;
  	struct drm_gem_object *gobj;
-	size_t size;
-	u32 pitch;
-	u32 handle;
  	int ret;
- if (!args->width || !args->height)
-		return -EINVAL;
-
-	if (args->bpp != 32 && args->bpp != 16)
-		return -EINVAL;
-
-	pitch = args->width * args->bpp / 8;
-	pitch = ALIGN(pitch, descp->pitch_align);
-	size = pitch * args->height;
-	size = ALIGN(size, PAGE_SIZE);
+	ret = drm_mode_size_dumb(ddev, args, descp->pitch_align, 0);
+	if (ret)
+		return ret;
/* Maximum single bo size allowed is the half vram size available */
-	if (size > ldev->vram_size / 2) {
-		drm_err(ddev, "Requesting(%zuMiB) failed\n", size >> 20);
+	if (args->size > ldev->vram_size / 2) {
+		drm_err(ddev, "Requesting(%zuMiB) failed\n", (size_t)(args->size >> PAGE_SHIFT));
  		return -ENOMEM;
  	}
- gobj = lsdc_gem_object_create(ddev, domain, size, false, NULL, NULL);
+	gobj = lsdc_gem_object_create(ddev, domain, args->size, false, NULL, NULL);
  	if (IS_ERR(gobj)) {
  		drm_err(ddev, "Failed to create gem object\n");
  		return PTR_ERR(gobj);
  	}
- ret = drm_gem_handle_create(file, gobj, &handle);
+	ret = drm_gem_handle_create(file, gobj, &args->handle);
/* drop reference from allocate, handle holds it now */
  	drm_gem_object_put(gobj);
  	if (ret)
  		return ret;
- args->pitch = pitch;
-	args->size = size;
-	args->handle = handle;
-
  	return 0;
  }

--
Best regards,
Sui





[Index of Archives]     [ARM Kernel]     [Linux ARM]     [Linux ARM MSM]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux