bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0901-drm-vc4-drv-Register-a-different-driver-on-BCM2711.patch
1 From bf001e8bacbf627525ec90027bfea19b788d6d8e Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Thu, 21 Apr 2022 11:08:22 +0200
4 Subject: [PATCH] drm/vc4: drv: Register a different driver on BCM2711
5
6 Prior to the BCM2711/RaspberryPi4, the GPU was a part of the display
7 components of the SoC. It was thus a part of the vc4 driver.
8
9 However, with the BCM2711, it got split out and thus the v3d driver was
10 created. The vc4 driver now only handles the display part.
11
12 We didn't properly split out the code when doing the BCM2711 support
13 though, and most of the code around buffer allocations is still
14 involved, even though it doesn't have the backing hardware anymore.
15
16 Let's start the split out by creating a new drm_driver that only reports
17 and uses what we support on the BCM2711. The ioctl were properly
18 filtered already, but we were still exposing a .gem_create_object hook,
19 as well as having an .open and .postclose hooks which are only relevant
20 on older generations.
21
22 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
23 ---
24 drivers/gpu/drm/vc4/vc4_drv.c | 51 ++++++++++++++++++++++++++++-------
25 1 file changed, 42 insertions(+), 9 deletions(-)
26
27 --- a/drivers/gpu/drm/vc4/vc4_drv.c
28 +++ b/drivers/gpu/drm/vc4/vc4_drv.c
29 @@ -78,6 +78,19 @@ int vc4_dumb_fixup_args(struct drm_mode_
30 return 0;
31 }
32
33 +static int vc4_dumb_create(struct drm_file *file_priv,
34 + struct drm_device *dev,
35 + struct drm_mode_create_dumb *args)
36 +{
37 + int ret;
38 +
39 + ret = vc4_dumb_fixup_args(args);
40 + if (ret)
41 + return ret;
42 +
43 + return drm_gem_cma_dumb_create_internal(file_priv, dev, args);
44 +}
45 +
46 static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
47 struct drm_file *file_priv)
48 {
49 @@ -175,7 +188,7 @@ static const struct drm_ioctl_desc vc4_d
50 DRM_IOCTL_DEF_DRV(VC4_PERFMON_GET_VALUES, vc4_perfmon_get_values_ioctl, DRM_RENDER_ALLOW),
51 };
52
53 -static struct drm_driver vc4_drm_driver = {
54 +static const struct drm_driver vc4_drm_driver = {
55 .driver_features = (DRIVER_MODESET |
56 DRIVER_ATOMIC |
57 DRIVER_GEM |
58 @@ -204,6 +217,27 @@ static struct drm_driver vc4_drm_driver
59 .patchlevel = DRIVER_PATCHLEVEL,
60 };
61
62 +static const struct drm_driver vc5_drm_driver = {
63 + .driver_features = (DRIVER_MODESET |
64 + DRIVER_ATOMIC |
65 + DRIVER_GEM),
66 +
67 +#if defined(CONFIG_DEBUG_FS)
68 + .debugfs_init = vc4_debugfs_init,
69 +#endif
70 +
71 + DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE(vc4_dumb_create),
72 +
73 + .fops = &vc4_drm_fops,
74 +
75 + .name = DRIVER_NAME,
76 + .desc = DRIVER_DESC,
77 + .date = DRIVER_DATE,
78 + .major = DRIVER_MAJOR,
79 + .minor = DRIVER_MINOR,
80 + .patchlevel = DRIVER_PATCHLEVEL,
81 +};
82 +
83 static int compare_dev(struct device *dev, void *data)
84 {
85 return dev == data;
86 @@ -254,6 +288,7 @@ static bool firmware_kms(void)
87 static int vc4_drm_bind(struct device *dev)
88 {
89 struct platform_device *pdev = to_platform_device(dev);
90 + const struct drm_driver *driver;
91 struct rpi_firmware *firmware = NULL;
92 struct drm_device *drm;
93 struct vc4_dev *vc4;
94 @@ -265,12 +300,10 @@ static int vc4_drm_bind(struct device *d
95 dev->coherent_dma_mask = DMA_BIT_MASK(32);
96
97 is_vc5 = of_device_is_compatible(dev->of_node, "brcm,bcm2711-vc5");
98 -
99 - /* If VC4 V3D is missing, don't advertise render nodes. */
100 - node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
101 - if (!node || !of_device_is_available(node))
102 - vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
103 - of_node_put(node);
104 + if (is_vc5)
105 + driver = &vc5_drm_driver;
106 + else
107 + driver = &vc4_drm_driver;
108
109 node = of_find_matching_node_and_match(NULL, vc4_dma_range_matches,
110 NULL);
111 @@ -282,7 +315,7 @@ static int vc4_drm_bind(struct device *d
112 return ret;
113 }
114
115 - vc4 = devm_drm_dev_alloc(dev, &vc4_drm_driver, struct vc4_dev, base);
116 + vc4 = devm_drm_dev_alloc(dev, driver, struct vc4_dev, base);
117 if (IS_ERR(vc4))
118 return PTR_ERR(vc4);
119 vc4->is_vc5 = is_vc5;
120 @@ -314,7 +347,7 @@ static int vc4_drm_bind(struct device *d
121 return -EPROBE_DEFER;
122 }
123
124 - ret = drm_aperture_remove_framebuffers(false, &vc4_drm_driver);
125 + ret = drm_aperture_remove_framebuffers(false, driver);
126 if (ret)
127 return ret;
128