bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0900-drm-vc4-bo-Split-out-Dumb-buffers-fixup.patch
1 From 5e59f19a966fa351cf9b5e59e2dbf2162a8542ce Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Thu, 21 Apr 2022 10:59:41 +0200
4 Subject: [PATCH] drm/vc4: bo: Split out Dumb buffers fixup
5
6 The vc4_bo_dumb_create() both fixes up the allocation arguments to match
7 the hardware constraints and actually performs the allocation.
8
9 Since we're going to introduce a new function that uses a different
10 allocator, let's split the arguments fixup to a separate function we
11 will be able to reuse.
12
13 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
14 ---
15 drivers/gpu/drm/vc4/vc4_bo.c | 9 +++------
16 drivers/gpu/drm/vc4/vc4_drv.c | 13 +++++++++++++
17 drivers/gpu/drm/vc4/vc4_drv.h | 1 +
18 3 files changed, 17 insertions(+), 6 deletions(-)
19
20 --- a/drivers/gpu/drm/vc4/vc4_bo.c
21 +++ b/drivers/gpu/drm/vc4/vc4_bo.c
22 @@ -477,15 +477,12 @@ int vc4_bo_dumb_create(struct drm_file *
23 struct drm_device *dev,
24 struct drm_mode_create_dumb *args)
25 {
26 - int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
27 struct vc4_bo *bo = NULL;
28 int ret;
29
30 - if (args->pitch < min_pitch)
31 - args->pitch = min_pitch;
32 -
33 - if (args->size < args->pitch * args->height)
34 - args->size = args->pitch * args->height;
35 + ret = vc4_dumb_fixup_args(args);
36 + if (ret)
37 + return ret;
38
39 bo = vc4_bo_create(dev, args->size, false, VC4_BO_TYPE_DUMB);
40 if (IS_ERR(bo))
41 --- a/drivers/gpu/drm/vc4/vc4_drv.c
42 +++ b/drivers/gpu/drm/vc4/vc4_drv.c
43 @@ -65,6 +65,19 @@ void __iomem *vc4_ioremap_regs(struct pl
44 return map;
45 }
46
47 +int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args)
48 +{
49 + int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
50 +
51 + if (args->pitch < min_pitch)
52 + args->pitch = min_pitch;
53 +
54 + if (args->size < args->pitch * args->height)
55 + args->size = args->pitch * args->height;
56 +
57 + return 0;
58 +}
59 +
60 static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
61 struct drm_file *file_priv)
62 {
63 --- a/drivers/gpu/drm/vc4/vc4_drv.h
64 +++ b/drivers/gpu/drm/vc4/vc4_drv.h
65 @@ -917,6 +917,7 @@ static inline void vc4_debugfs_add_regse
66
67 /* vc4_drv.c */
68 void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
69 +int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args);
70
71 /* vc4_dpi.c */
72 extern struct platform_driver vc4_dpi_driver;