drm/vc4: bo: Split out Dumb buffers fixup
authorMaxime Ripard <maxime@cerno.tech>
Fri, 10 Jun 2022 11:51:39 +0000 (13:51 +0200)
committerMaxime Ripard <maxime@cerno.tech>
Thu, 16 Jun 2022 09:07:51 +0000 (11:07 +0200)
The vc4_bo_dumb_create() both fixes up the allocation arguments to match
the hardware constraints and actually performs the allocation.

Since we're going to introduce a new function that uses a different
allocator, let's split the arguments fixup to a separate function we
will be able to reuse.

Reviewed-by: Melissa Wen <mwen@igalia.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220610115149.964394-5-maxime@cerno.tech
drivers/gpu/drm/vc4/vc4_bo.c
drivers/gpu/drm/vc4/vc4_drv.c
drivers/gpu/drm/vc4/vc4_drv.h

index 6d505da6b6cfab58b3635aa8716a1d2c29d37d72..3ca16d682fc0fbfcff48947c4f3fafbbd1cb4c97 100644 (file)
@@ -475,15 +475,12 @@ int vc4_bo_dumb_create(struct drm_file *file_priv,
                       struct drm_device *dev,
                       struct drm_mode_create_dumb *args)
 {
-       int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
        struct vc4_bo *bo = NULL;
        int ret;
 
-       if (args->pitch < min_pitch)
-               args->pitch = min_pitch;
-
-       if (args->size < args->pitch * args->height)
-               args->size = args->pitch * args->height;
+       ret = vc4_dumb_fixup_args(args);
+       if (ret)
+               return ret;
 
        bo = vc4_bo_create(dev, args->size, false, VC4_BO_TYPE_DUMB);
        if (IS_ERR(bo))
index 5f39e40ef238519e5b510d4b764570fff1d9bc50..eb08940028d3958b2733b7959d17d68099e12ac4 100644 (file)
@@ -63,6 +63,19 @@ void __iomem *vc4_ioremap_regs(struct platform_device *pdev, int index)
        return map;
 }
 
+int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args)
+{
+       int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
+
+       if (args->pitch < min_pitch)
+               args->pitch = min_pitch;
+
+       if (args->size < args->pitch * args->height)
+               args->size = args->pitch * args->height;
+
+       return 0;
+}
+
 static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
                               struct drm_file *file_priv)
 {
index 37c93654480fe0ba047b60260f85115bed4fe31d..9c324c12c4106783d8c2ca892ddec50d3940d63d 100644 (file)
@@ -885,6 +885,7 @@ static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
 
 /* vc4_drv.c */
 void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
+int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args);
 
 /* vc4_dpi.c */
 extern struct platform_driver vc4_dpi_driver;