forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/vc4/vc4_drv.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2014-2015 Broadcom
34 * Copyright (C) 2013 Red Hat
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 */
96
107 /**
....@@ -26,15 +23,21 @@
2623 #include <linux/clk.h>
2724 #include <linux/component.h>
2825 #include <linux/device.h>
26
+#include <linux/dma-mapping.h>
2927 #include <linux/io.h>
3028 #include <linux/module.h>
3129 #include <linux/of_platform.h>
3230 #include <linux/platform_device.h>
3331 #include <linux/pm_runtime.h>
32
+
33
+#include <drm/drm_atomic_helper.h>
34
+#include <drm/drm_drv.h>
3435 #include <drm/drm_fb_cma_helper.h>
3536 #include <drm/drm_fb_helper.h>
37
+#include <drm/drm_vblank.h>
3638
3739 #include "uapi/drm/vc4_drm.h"
40
+
3841 #include "vc4_drv.h"
3942 #include "vc4_regs.h"
4043
....@@ -71,30 +74,30 @@
7174 if (args->pad != 0)
7275 return -EINVAL;
7376
77
+ if (!vc4->v3d)
78
+ return -ENODEV;
79
+
7480 switch (args->param) {
7581 case DRM_VC4_PARAM_V3D_IDENT0:
76
- ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
77
- if (ret < 0)
82
+ ret = vc4_v3d_pm_get(vc4);
83
+ if (ret)
7884 return ret;
7985 args->value = V3D_READ(V3D_IDENT0);
80
- pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
81
- pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
86
+ vc4_v3d_pm_put(vc4);
8287 break;
8388 case DRM_VC4_PARAM_V3D_IDENT1:
84
- ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
85
- if (ret < 0)
89
+ ret = vc4_v3d_pm_get(vc4);
90
+ if (ret)
8691 return ret;
8792 args->value = V3D_READ(V3D_IDENT1);
88
- pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
89
- pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
93
+ vc4_v3d_pm_put(vc4);
9094 break;
9195 case DRM_VC4_PARAM_V3D_IDENT2:
92
- ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
93
- if (ret < 0)
96
+ ret = vc4_v3d_pm_get(vc4);
97
+ if (ret)
9498 return ret;
9599 args->value = V3D_READ(V3D_IDENT2);
96
- pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
97
- pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
100
+ vc4_v3d_pm_put(vc4);
98101 break;
99102 case DRM_VC4_PARAM_SUPPORTS_BRANCHES:
100103 case DRM_VC4_PARAM_SUPPORTS_ETC1:
....@@ -127,7 +130,11 @@
127130
128131 static void vc4_close(struct drm_device *dev, struct drm_file *file)
129132 {
133
+ struct vc4_dev *vc4 = to_vc4_dev(dev);
130134 struct vc4_file *vc4file = file->driver_priv;
135
+
136
+ if (vc4file->bin_bo_used)
137
+ vc4_v3d_bin_bo_put(vc4);
131138
132139 vc4_perfmon_close_file(vc4file);
133140 kfree(vc4file);
....@@ -174,20 +181,14 @@
174181 .driver_features = (DRIVER_MODESET |
175182 DRIVER_ATOMIC |
176183 DRIVER_GEM |
177
- DRIVER_HAVE_IRQ |
178184 DRIVER_RENDER |
179
- DRIVER_PRIME |
180185 DRIVER_SYNCOBJ),
181
- .lastclose = drm_fb_helper_lastclose,
182186 .open = vc4_open,
183187 .postclose = vc4_close,
184188 .irq_handler = vc4_irq,
185189 .irq_preinstall = vc4_irq_preinstall,
186190 .irq_postinstall = vc4_irq_postinstall,
187191 .irq_uninstall = vc4_irq_uninstall,
188
-
189
- .get_scanout_position = vc4_crtc_get_scanoutpos,
190
- .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
191192
192193 #if defined(CONFIG_DEBUG_FS)
193194 .debugfs_init = vc4_debugfs_init,
....@@ -199,9 +200,7 @@
199200
200201 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
201202 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
202
- .gem_prime_import = drm_gem_prime_import,
203203 .gem_prime_export = vc4_prime_export,
204
- .gem_prime_res_obj = vc4_prime_res_obj,
205204 .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
206205 .gem_prime_import_sg_table = vc4_prime_import_sg_table,
207206 .gem_prime_vmap = vc4_prime_vmap,
....@@ -238,8 +237,7 @@
238237 struct device_driver *drv = &drivers[i]->driver;
239238 struct device *p = NULL, *d;
240239
241
- while ((d = bus_find_device(&platform_bus_type, p, drv,
242
- (void *)platform_bus_type.match))) {
240
+ while ((d = platform_find_device_by_driver(p, drv))) {
243241 put_device(p);
244242 component_match_add(dev, match, compare_dev, d);
245243 p = d;
....@@ -248,91 +246,102 @@
248246 }
249247 }
250248
251
-static void vc4_kick_out_firmware_fb(void)
252
-{
253
- struct apertures_struct *ap;
254
-
255
- ap = alloc_apertures(1);
256
- if (!ap)
257
- return;
258
-
259
- /* Since VC4 is a UMA device, the simplefb node may have been
260
- * located anywhere in memory.
261
- */
262
- ap->ranges[0].base = 0;
263
- ap->ranges[0].size = ~0;
264
-
265
- drm_fb_helper_remove_conflicting_framebuffers(ap, "vc4drmfb", false);
266
- kfree(ap);
267
-}
249
+static const struct of_device_id vc4_dma_range_matches[] = {
250
+ { .compatible = "brcm,bcm2711-hvs" },
251
+ { .compatible = "brcm,bcm2835-hvs" },
252
+ { .compatible = "brcm,bcm2835-v3d" },
253
+ { .compatible = "brcm,cygnus-v3d" },
254
+ { .compatible = "brcm,vc4-v3d" },
255
+ {}
256
+};
268257
269258 static int vc4_drm_bind(struct device *dev)
270259 {
271260 struct platform_device *pdev = to_platform_device(dev);
272261 struct drm_device *drm;
273262 struct vc4_dev *vc4;
263
+ struct device_node *node;
264
+ struct drm_crtc *crtc;
274265 int ret = 0;
275266
276267 dev->coherent_dma_mask = DMA_BIT_MASK(32);
277268
278
- vc4 = devm_kzalloc(dev, sizeof(*vc4), GFP_KERNEL);
279
- if (!vc4)
280
- return -ENOMEM;
269
+ /* If VC4 V3D is missing, don't advertise render nodes. */
270
+ node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
271
+ if (!node || !of_device_is_available(node))
272
+ vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
273
+ of_node_put(node);
281274
282
- drm = drm_dev_alloc(&vc4_drm_driver, dev);
283
- if (IS_ERR(drm))
284
- return PTR_ERR(drm);
275
+ node = of_find_matching_node_and_match(NULL, vc4_dma_range_matches,
276
+ NULL);
277
+ if (node) {
278
+ ret = of_dma_configure(dev, node, true);
279
+ of_node_put(node);
280
+
281
+ if (ret)
282
+ return ret;
283
+ }
284
+
285
+ vc4 = devm_drm_dev_alloc(dev, &vc4_drm_driver, struct vc4_dev, base);
286
+ if (IS_ERR(vc4))
287
+ return PTR_ERR(vc4);
288
+
289
+ drm = &vc4->base;
285290 platform_set_drvdata(pdev, drm);
286
- vc4->dev = drm;
287
- drm->dev_private = vc4;
291
+ INIT_LIST_HEAD(&vc4->debugfs_list);
292
+
293
+ mutex_init(&vc4->bin_bo_lock);
288294
289295 ret = vc4_bo_cache_init(drm);
290296 if (ret)
291
- goto dev_put;
297
+ return ret;
292298
293
- drm_mode_config_init(drm);
299
+ ret = drmm_mode_config_init(drm);
300
+ if (ret)
301
+ return ret;
294302
295
- vc4_gem_init(drm);
303
+ ret = vc4_gem_init(drm);
304
+ if (ret)
305
+ return ret;
296306
297307 ret = component_bind_all(dev, drm);
298308 if (ret)
299
- goto gem_destroy;
309
+ return ret;
300310
301
- vc4_kick_out_firmware_fb();
311
+ ret = vc4_plane_create_additional_planes(drm);
312
+ if (ret)
313
+ goto unbind_all;
314
+
315
+ drm_fb_helper_remove_conflicting_framebuffers(NULL, "vc4drmfb", false);
316
+
317
+ ret = vc4_kms_load(drm);
318
+ if (ret < 0)
319
+ goto unbind_all;
320
+
321
+ drm_for_each_crtc(crtc, drm)
322
+ vc4_crtc_disable_at_boot(crtc);
302323
303324 ret = drm_dev_register(drm, 0);
304325 if (ret < 0)
305326 goto unbind_all;
306327
307
- vc4_kms_load(drm);
328
+ drm_fbdev_generic_setup(drm, 16);
308329
309330 return 0;
310331
311332 unbind_all:
312333 component_unbind_all(dev, drm);
313
-gem_destroy:
314
- vc4_gem_destroy(drm);
315
- drm_mode_config_cleanup(drm);
316
- vc4_bo_cache_destroy(drm);
317
-dev_put:
318
- drm_dev_put(drm);
334
+
319335 return ret;
320336 }
321337
322338 static void vc4_drm_unbind(struct device *dev)
323339 {
324340 struct drm_device *drm = dev_get_drvdata(dev);
325
- struct vc4_dev *vc4 = to_vc4_dev(drm);
326341
327342 drm_dev_unregister(drm);
328343
329
- drm_fb_cma_fbdev_fini(drm);
330
-
331
- drm_mode_config_cleanup(drm);
332
-
333
- drm_atomic_private_obj_fini(&vc4->ctm_manager);
334
-
335
- drm_dev_put(drm);
344
+ drm_atomic_helper_shutdown(drm);
336345 }
337346
338347 static const struct component_master_ops vc4_drm_ops = {
....@@ -345,8 +354,8 @@
345354 &vc4_vec_driver,
346355 &vc4_dpi_driver,
347356 &vc4_dsi_driver,
348
- &vc4_txp_driver,
349357 &vc4_hvs_driver,
358
+ &vc4_txp_driver,
350359 &vc4_crtc_driver,
351360 &vc4_v3d_driver,
352361 };
....@@ -370,6 +379,7 @@
370379 }
371380
372381 static const struct of_device_id vc4_of_match[] = {
382
+ { .compatible = "brcm,bcm2711-vc5", },
373383 { .compatible = "brcm,bcm2835-vc4", },
374384 { .compatible = "brcm,cygnus-vc4", },
375385 {},
....@@ -394,7 +404,12 @@
394404 if (ret)
395405 return ret;
396406
397
- return platform_driver_register(&vc4_platform_driver);
407
+ ret = platform_driver_register(&vc4_platform_driver);
408
+ if (ret)
409
+ platform_unregister_drivers(component_drivers,
410
+ ARRAY_SIZE(component_drivers));
411
+
412
+ return ret;
398413 }
399414
400415 static void __exit vc4_drm_unregister(void)