forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/gpu/drm/exynos/exynos_drm_drv.c
....@@ -1,36 +1,37 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
34 * Authors:
45 * Inki Dae <inki.dae@samsung.com>
56 * Joonyoung Shim <jy0922.shim@samsung.com>
67 * Seung-Woo Kim <sw0312.kim@samsung.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify it
9
- * under the terms of the GNU General Public License as published by the
10
- * Free Software Foundation; either version 2 of the License, or (at your
11
- * option) any later version.
128 */
139
10
+#include <linux/component.h>
11
+#include <linux/dma-mapping.h>
12
+#include <linux/platform_device.h>
1413 #include <linux/pm_runtime.h>
15
-#include <drm/drmP.h>
14
+#include <linux/uaccess.h>
15
+
1616 #include <drm/drm_atomic.h>
1717 #include <drm/drm_atomic_helper.h>
18
-#include <drm/drm_crtc_helper.h>
18
+#include <drm/drm_drv.h>
1919 #include <drm/drm_fb_helper.h>
20
-
21
-#include <linux/component.h>
22
-
20
+#include <drm/drm_file.h>
21
+#include <drm/drm_fourcc.h>
22
+#include <drm/drm_ioctl.h>
23
+#include <drm/drm_probe_helper.h>
24
+#include <drm/drm_vblank.h>
2325 #include <drm/exynos_drm.h>
2426
2527 #include "exynos_drm_drv.h"
26
-#include "exynos_drm_fbdev.h"
2728 #include "exynos_drm_fb.h"
28
-#include "exynos_drm_gem.h"
29
-#include "exynos_drm_plane.h"
30
-#include "exynos_drm_ipp.h"
31
-#include "exynos_drm_vidi.h"
29
+#include "exynos_drm_fbdev.h"
3230 #include "exynos_drm_g2d.h"
33
-#include "exynos_drm_iommu.h"
31
+#include "exynos_drm_gem.h"
32
+#include "exynos_drm_ipp.h"
33
+#include "exynos_drm_plane.h"
34
+#include "exynos_drm_vidi.h"
3435
3536 #define DRIVER_NAME "exynos"
3637 #define DRIVER_DESC "Samsung SoC DRM"
....@@ -75,36 +76,35 @@
7576 }
7677
7778 static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
78
- .fault = exynos_drm_gem_fault,
7979 .open = drm_gem_vm_open,
8080 .close = drm_gem_vm_close,
8181 };
8282
8383 static const struct drm_ioctl_desc exynos_ioctls[] = {
8484 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
85
- DRM_AUTH | DRM_RENDER_ALLOW),
85
+ DRM_RENDER_ALLOW),
8686 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP, exynos_drm_gem_map_ioctl,
87
- DRM_AUTH | DRM_RENDER_ALLOW),
87
+ DRM_RENDER_ALLOW),
8888 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET, exynos_drm_gem_get_ioctl,
8989 DRM_RENDER_ALLOW),
9090 DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION, vidi_connection_ioctl,
9191 DRM_AUTH),
9292 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER, exynos_g2d_get_ver_ioctl,
93
- DRM_AUTH | DRM_RENDER_ALLOW),
93
+ DRM_RENDER_ALLOW),
9494 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST, exynos_g2d_set_cmdlist_ioctl,
95
- DRM_AUTH | DRM_RENDER_ALLOW),
95
+ DRM_RENDER_ALLOW),
9696 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC, exynos_g2d_exec_ioctl,
97
- DRM_AUTH | DRM_RENDER_ALLOW),
97
+ DRM_RENDER_ALLOW),
9898 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_RESOURCES,
9999 exynos_drm_ipp_get_res_ioctl,
100
- DRM_AUTH | DRM_RENDER_ALLOW),
100
+ DRM_RENDER_ALLOW),
101101 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_CAPS, exynos_drm_ipp_get_caps_ioctl,
102
- DRM_AUTH | DRM_RENDER_ALLOW),
102
+ DRM_RENDER_ALLOW),
103103 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_LIMITS,
104104 exynos_drm_ipp_get_limits_ioctl,
105
- DRM_AUTH | DRM_RENDER_ALLOW),
105
+ DRM_RENDER_ALLOW),
106106 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_COMMIT, exynos_drm_ipp_commit_ioctl,
107
- DRM_AUTH | DRM_RENDER_ALLOW),
107
+ DRM_RENDER_ALLOW),
108108 };
109109
110110 static const struct file_operations exynos_drm_driver_fops = {
....@@ -119,7 +119,7 @@
119119 };
120120
121121 static struct drm_driver exynos_drm_driver = {
122
- .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME
122
+ .driver_features = DRIVER_MODESET | DRIVER_GEM
123123 | DRIVER_ATOMIC | DRIVER_RENDER,
124124 .open = exynos_drm_open,
125125 .lastclose = drm_fb_helper_lastclose,
....@@ -129,7 +129,6 @@
129129 .dumb_create = exynos_drm_gem_dumb_create,
130130 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
131131 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
132
- .gem_prime_export = drm_gem_prime_export,
133132 .gem_prime_import = exynos_drm_gem_prime_import,
134133 .gem_prime_get_sg_table = exynos_drm_gem_prime_get_sg_table,
135134 .gem_prime_import_sg_table = exynos_drm_gem_prime_import_sg_table,
....@@ -149,37 +148,15 @@
149148 static int exynos_drm_suspend(struct device *dev)
150149 {
151150 struct drm_device *drm_dev = dev_get_drvdata(dev);
152
- struct exynos_drm_private *private;
153151
154
- if (!drm_dev)
155
- return 0;
156
-
157
- private = drm_dev->dev_private;
158
-
159
- drm_kms_helper_poll_disable(drm_dev);
160
- exynos_drm_fbdev_suspend(drm_dev);
161
- private->suspend_state = drm_atomic_helper_suspend(drm_dev);
162
- if (IS_ERR(private->suspend_state)) {
163
- exynos_drm_fbdev_resume(drm_dev);
164
- drm_kms_helper_poll_enable(drm_dev);
165
- return PTR_ERR(private->suspend_state);
166
- }
167
-
168
- return 0;
152
+ return drm_mode_config_helper_suspend(drm_dev);
169153 }
170154
171155 static void exynos_drm_resume(struct device *dev)
172156 {
173157 struct drm_device *drm_dev = dev_get_drvdata(dev);
174
- struct exynos_drm_private *private;
175158
176
- if (!drm_dev)
177
- return;
178
-
179
- private = drm_dev->dev_private;
180
- drm_atomic_helper_resume(drm_dev, private->suspend_state);
181
- exynos_drm_fbdev_resume(drm_dev);
182
- drm_kms_helper_poll_enable(drm_dev);
159
+ drm_mode_config_helper_resume(drm_dev);
183160 }
184161
185162 static const struct dev_pm_ops exynos_drm_pm_ops = {
....@@ -197,8 +174,7 @@
197174
198175 #define DRM_COMPONENT_DRIVER BIT(0) /* supports component framework */
199176 #define DRM_VIRTUAL_DEVICE BIT(1) /* create virtual platform device */
200
-#define DRM_DMA_DEVICE BIT(2) /* can be used for dma allocations */
201
-#define DRM_FIMC_DEVICE BIT(3) /* devices shared with V4L2 subsystem */
177
+#define DRM_FIMC_DEVICE BIT(2) /* devices shared with V4L2 subsystem */
202178
203179 #define DRV_PTR(drv, cond) (IS_ENABLED(cond) ? &drv : NULL)
204180
....@@ -209,16 +185,16 @@
209185 static struct exynos_drm_driver_info exynos_drm_drivers[] = {
210186 {
211187 DRV_PTR(fimd_driver, CONFIG_DRM_EXYNOS_FIMD),
212
- DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
188
+ DRM_COMPONENT_DRIVER
213189 }, {
214190 DRV_PTR(exynos5433_decon_driver, CONFIG_DRM_EXYNOS5433_DECON),
215
- DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
191
+ DRM_COMPONENT_DRIVER
216192 }, {
217193 DRV_PTR(decon_driver, CONFIG_DRM_EXYNOS7_DECON),
218
- DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
194
+ DRM_COMPONENT_DRIVER
219195 }, {
220196 DRV_PTR(mixer_driver, CONFIG_DRM_EXYNOS_MIXER),
221
- DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
197
+ DRM_COMPONENT_DRIVER
222198 }, {
223199 DRV_PTR(mic_driver, CONFIG_DRM_EXYNOS_MIC),
224200 DRM_COMPONENT_DRIVER
....@@ -272,9 +248,7 @@
272248 if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
273249 continue;
274250
275
- while ((d = bus_find_device(&platform_bus_type, p,
276
- &info->driver->driver,
277
- (void *)platform_bus_type.match))) {
251
+ while ((d = platform_find_device_by_driver(p, &info->driver->driver))) {
278252 put_device(p);
279253
280254 if (!(info->flags & DRM_FIMC_DEVICE) ||
....@@ -289,34 +263,13 @@
289263 return match ?: ERR_PTR(-ENODEV);
290264 }
291265
292
-static struct device *exynos_drm_get_dma_device(void)
293
-{
294
- int i;
295
-
296
- for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
297
- struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
298
- struct device *dev;
299
-
300
- if (!info->driver || !(info->flags & DRM_DMA_DEVICE))
301
- continue;
302
-
303
- while ((dev = bus_find_device(&platform_bus_type, NULL,
304
- &info->driver->driver,
305
- (void *)platform_bus_type.match))) {
306
- put_device(dev);
307
- return dev;
308
- }
309
- }
310
- return NULL;
311
-}
312
-
313266 static int exynos_drm_bind(struct device *dev)
314267 {
315268 struct exynos_drm_private *private;
316269 struct drm_encoder *encoder;
317270 struct drm_device *drm;
318271 unsigned int clone_mask;
319
- int cnt, ret;
272
+ int ret;
320273
321274 drm = drm_dev_alloc(&exynos_drm_driver, dev);
322275 if (IS_ERR(drm))
....@@ -334,32 +287,14 @@
334287 dev_set_drvdata(dev, drm);
335288 drm->dev_private = (void *)private;
336289
337
- /* the first real CRTC device is used for all dma mapping operations */
338
- private->dma_dev = exynos_drm_get_dma_device();
339
- if (!private->dma_dev) {
340
- DRM_ERROR("no device found for DMA mapping operations.\n");
341
- ret = -ENODEV;
342
- goto err_free_private;
343
- }
344
- DRM_INFO("Exynos DRM: using %s device for DMA mapping operations\n",
345
- dev_name(private->dma_dev));
346
-
347
- /* create common IOMMU mapping for all devices attached to Exynos DRM */
348
- ret = drm_create_iommu_mapping(drm);
349
- if (ret < 0) {
350
- DRM_ERROR("failed to create iommu mapping.\n");
351
- goto err_free_private;
352
- }
353
-
354290 drm_mode_config_init(drm);
355291
356292 exynos_drm_mode_config_init(drm);
357293
358294 /* setup possible_clones. */
359
- cnt = 0;
360295 clone_mask = 0;
361296 list_for_each_entry(encoder, &drm->mode_config.encoder_list, head)
362
- clone_mask |= (1 << (cnt++));
297
+ clone_mask |= drm_encoder_mask(encoder);
363298
364299 list_for_each_entry(encoder, &drm->mode_config.encoder_list, head)
365300 encoder->possible_clones = clone_mask;
....@@ -407,8 +342,7 @@
407342 component_unbind_all(drm->dev, drm);
408343 err_mode_config_cleanup:
409344 drm_mode_config_cleanup(drm);
410
- drm_release_iommu_mapping(drm);
411
-err_free_private:
345
+ exynos_drm_cleanup_dma(drm);
412346 kfree(private);
413347 err_free_drm:
414348 drm_dev_put(drm);
....@@ -427,7 +361,7 @@
427361
428362 component_unbind_all(drm->dev, drm);
429363 drm_mode_config_cleanup(drm);
430
- drm_release_iommu_mapping(drm);
364
+ exynos_drm_cleanup_dma(drm);
431365
432366 kfree(drm->dev_private);
433367 drm->dev_private = NULL;
....@@ -481,9 +415,8 @@
481415 if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
482416 continue;
483417
484
- while ((dev = bus_find_device(&platform_bus_type, NULL,
485
- &info->driver->driver,
486
- (void *)platform_bus_type.match))) {
418
+ while ((dev = platform_find_device_by_driver(NULL,
419
+ &info->driver->driver))) {
487420 put_device(dev);
488421 platform_device_unregister(to_platform_device(dev));
489422 }