]> Git Repo - linux.git/blob - drivers/gpu/drm/panfrost/panfrost_drv.c
Merge tag 'amd-drm-next-6.5-2023-06-09' of https://gitlab.freedesktop.org/agd5f/linux...
[linux.git] / drivers / gpu / drm / panfrost / panfrost_drv.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2018 Marty E. Plummer <[email protected]> */
3 /* Copyright 2019 Linaro, Ltd., Rob Herring <[email protected]> */
4 /* Copyright 2019 Collabora ltd. */
5
6 #include <linux/module.h>
7 #include <linux/of_platform.h>
8 #include <linux/pagemap.h>
9 #include <linux/pm_runtime.h>
10 #include <drm/panfrost_drm.h>
11 #include <drm/drm_drv.h>
12 #include <drm/drm_ioctl.h>
13 #include <drm/drm_syncobj.h>
14 #include <drm/drm_utils.h>
15
16 #include "panfrost_device.h"
17 #include "panfrost_gem.h"
18 #include "panfrost_mmu.h"
19 #include "panfrost_job.h"
20 #include "panfrost_gpu.h"
21 #include "panfrost_perfcnt.h"
22
23 static bool unstable_ioctls;
24 module_param_unsafe(unstable_ioctls, bool, 0600);
25
26 static int panfrost_ioctl_get_param(struct drm_device *ddev, void *data, struct drm_file *file)
27 {
28         struct drm_panfrost_get_param *param = data;
29         struct panfrost_device *pfdev = ddev->dev_private;
30
31         if (param->pad != 0)
32                 return -EINVAL;
33
34 #define PANFROST_FEATURE(name, member)                  \
35         case DRM_PANFROST_PARAM_ ## name:               \
36                 param->value = pfdev->features.member;  \
37                 break
38 #define PANFROST_FEATURE_ARRAY(name, member, max)                       \
39         case DRM_PANFROST_PARAM_ ## name ## 0 ...                       \
40                 DRM_PANFROST_PARAM_ ## name ## max:                     \
41                 param->value = pfdev->features.member[param->param -    \
42                         DRM_PANFROST_PARAM_ ## name ## 0];              \
43                 break
44
45         switch (param->param) {
46                 PANFROST_FEATURE(GPU_PROD_ID, id);
47                 PANFROST_FEATURE(GPU_REVISION, revision);
48                 PANFROST_FEATURE(SHADER_PRESENT, shader_present);
49                 PANFROST_FEATURE(TILER_PRESENT, tiler_present);
50                 PANFROST_FEATURE(L2_PRESENT, l2_present);
51                 PANFROST_FEATURE(STACK_PRESENT, stack_present);
52                 PANFROST_FEATURE(AS_PRESENT, as_present);
53                 PANFROST_FEATURE(JS_PRESENT, js_present);
54                 PANFROST_FEATURE(L2_FEATURES, l2_features);
55                 PANFROST_FEATURE(CORE_FEATURES, core_features);
56                 PANFROST_FEATURE(TILER_FEATURES, tiler_features);
57                 PANFROST_FEATURE(MEM_FEATURES, mem_features);
58                 PANFROST_FEATURE(MMU_FEATURES, mmu_features);
59                 PANFROST_FEATURE(THREAD_FEATURES, thread_features);
60                 PANFROST_FEATURE(MAX_THREADS, max_threads);
61                 PANFROST_FEATURE(THREAD_MAX_WORKGROUP_SZ,
62                                 thread_max_workgroup_sz);
63                 PANFROST_FEATURE(THREAD_MAX_BARRIER_SZ,
64                                 thread_max_barrier_sz);
65                 PANFROST_FEATURE(COHERENCY_FEATURES, coherency_features);
66                 PANFROST_FEATURE(AFBC_FEATURES, afbc_features);
67                 PANFROST_FEATURE_ARRAY(TEXTURE_FEATURES, texture_features, 3);
68                 PANFROST_FEATURE_ARRAY(JS_FEATURES, js_features, 15);
69                 PANFROST_FEATURE(NR_CORE_GROUPS, nr_core_groups);
70                 PANFROST_FEATURE(THREAD_TLS_ALLOC, thread_tls_alloc);
71         default:
72                 return -EINVAL;
73         }
74
75         return 0;
76 }
77
78 static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data,
79                 struct drm_file *file)
80 {
81         struct panfrost_file_priv *priv = file->driver_priv;
82         struct panfrost_gem_object *bo;
83         struct drm_panfrost_create_bo *args = data;
84         struct panfrost_gem_mapping *mapping;
85         int ret;
86
87         if (!args->size || args->pad ||
88             (args->flags & ~(PANFROST_BO_NOEXEC | PANFROST_BO_HEAP)))
89                 return -EINVAL;
90
91         /* Heaps should never be executable */
92         if ((args->flags & PANFROST_BO_HEAP) &&
93             !(args->flags & PANFROST_BO_NOEXEC))
94                 return -EINVAL;
95
96         bo = panfrost_gem_create(dev, args->size, args->flags);
97         if (IS_ERR(bo))
98                 return PTR_ERR(bo);
99
100         ret = drm_gem_handle_create(file, &bo->base.base, &args->handle);
101         if (ret)
102                 goto out;
103
104         mapping = panfrost_gem_mapping_get(bo, priv);
105         if (mapping) {
106                 args->offset = mapping->mmnode.start << PAGE_SHIFT;
107                 panfrost_gem_mapping_put(mapping);
108         } else {
109                 /* This can only happen if the handle from
110                  * drm_gem_handle_create() has already been guessed and freed
111                  * by user space
112                  */
113                 ret = -EINVAL;
114         }
115
116 out:
117         drm_gem_object_put(&bo->base.base);
118         return ret;
119 }
120
121 /**
122  * panfrost_lookup_bos() - Sets up job->bo[] with the GEM objects
123  * referenced by the job.
124  * @dev: DRM device
125  * @file_priv: DRM file for this fd
126  * @args: IOCTL args
127  * @job: job being set up
128  *
129  * Resolve handles from userspace to BOs and attach them to job.
130  *
131  * Note that this function doesn't need to unreference the BOs on
132  * failure, because that will happen at panfrost_job_cleanup() time.
133  */
134 static int
135 panfrost_lookup_bos(struct drm_device *dev,
136                   struct drm_file *file_priv,
137                   struct drm_panfrost_submit *args,
138                   struct panfrost_job *job)
139 {
140         struct panfrost_file_priv *priv = file_priv->driver_priv;
141         struct panfrost_gem_object *bo;
142         unsigned int i;
143         int ret;
144
145         job->bo_count = args->bo_handle_count;
146
147         if (!job->bo_count)
148                 return 0;
149
150         ret = drm_gem_objects_lookup(file_priv,
151                                      (void __user *)(uintptr_t)args->bo_handles,
152                                      job->bo_count, &job->bos);
153         if (ret)
154                 return ret;
155
156         job->mappings = kvmalloc_array(job->bo_count,
157                                        sizeof(struct panfrost_gem_mapping *),
158                                        GFP_KERNEL | __GFP_ZERO);
159         if (!job->mappings)
160                 return -ENOMEM;
161
162         for (i = 0; i < job->bo_count; i++) {
163                 struct panfrost_gem_mapping *mapping;
164
165                 bo = to_panfrost_bo(job->bos[i]);
166                 mapping = panfrost_gem_mapping_get(bo, priv);
167                 if (!mapping) {
168                         ret = -EINVAL;
169                         break;
170                 }
171
172                 atomic_inc(&bo->gpu_usecount);
173                 job->mappings[i] = mapping;
174         }
175
176         return ret;
177 }
178
179 /**
180  * panfrost_copy_in_sync() - Sets up job->deps with the sync objects
181  * referenced by the job.
182  * @dev: DRM device
183  * @file_priv: DRM file for this fd
184  * @args: IOCTL args
185  * @job: job being set up
186  *
187  * Resolve syncobjs from userspace to fences and attach them to job.
188  *
189  * Note that this function doesn't need to unreference the fences on
190  * failure, because that will happen at panfrost_job_cleanup() time.
191  */
192 static int
193 panfrost_copy_in_sync(struct drm_device *dev,
194                   struct drm_file *file_priv,
195                   struct drm_panfrost_submit *args,
196                   struct panfrost_job *job)
197 {
198         u32 *handles;
199         int ret = 0;
200         int i, in_fence_count;
201
202         in_fence_count = args->in_sync_count;
203
204         if (!in_fence_count)
205                 return 0;
206
207         handles = kvmalloc_array(in_fence_count, sizeof(u32), GFP_KERNEL);
208         if (!handles) {
209                 ret = -ENOMEM;
210                 DRM_DEBUG("Failed to allocate incoming syncobj handles\n");
211                 goto fail;
212         }
213
214         if (copy_from_user(handles,
215                            (void __user *)(uintptr_t)args->in_syncs,
216                            in_fence_count * sizeof(u32))) {
217                 ret = -EFAULT;
218                 DRM_DEBUG("Failed to copy in syncobj handles\n");
219                 goto fail;
220         }
221
222         for (i = 0; i < in_fence_count; i++) {
223                 ret = drm_sched_job_add_syncobj_dependency(&job->base, file_priv,
224                                                            handles[i], 0);
225                 if (ret)
226                         goto fail;
227         }
228
229 fail:
230         kvfree(handles);
231         return ret;
232 }
233
234 static int panfrost_ioctl_submit(struct drm_device *dev, void *data,
235                 struct drm_file *file)
236 {
237         struct panfrost_device *pfdev = dev->dev_private;
238         struct panfrost_file_priv *file_priv = file->driver_priv;
239         struct drm_panfrost_submit *args = data;
240         struct drm_syncobj *sync_out = NULL;
241         struct panfrost_job *job;
242         int ret = 0, slot;
243
244         if (!args->jc)
245                 return -EINVAL;
246
247         if (args->requirements && args->requirements != PANFROST_JD_REQ_FS)
248                 return -EINVAL;
249
250         if (args->out_sync > 0) {
251                 sync_out = drm_syncobj_find(file, args->out_sync);
252                 if (!sync_out)
253                         return -ENODEV;
254         }
255
256         job = kzalloc(sizeof(*job), GFP_KERNEL);
257         if (!job) {
258                 ret = -ENOMEM;
259                 goto out_put_syncout;
260         }
261
262         kref_init(&job->refcount);
263
264         job->pfdev = pfdev;
265         job->jc = args->jc;
266         job->requirements = args->requirements;
267         job->flush_id = panfrost_gpu_get_latest_flush_id(pfdev);
268         job->mmu = file_priv->mmu;
269
270         slot = panfrost_job_get_slot(job);
271
272         ret = drm_sched_job_init(&job->base,
273                                  &file_priv->sched_entity[slot],
274                                  NULL);
275         if (ret)
276                 goto out_put_job;
277
278         ret = panfrost_copy_in_sync(dev, file, args, job);
279         if (ret)
280                 goto out_cleanup_job;
281
282         ret = panfrost_lookup_bos(dev, file, args, job);
283         if (ret)
284                 goto out_cleanup_job;
285
286         ret = panfrost_job_push(job);
287         if (ret)
288                 goto out_cleanup_job;
289
290         /* Update the return sync object for the job */
291         if (sync_out)
292                 drm_syncobj_replace_fence(sync_out, job->render_done_fence);
293
294 out_cleanup_job:
295         if (ret)
296                 drm_sched_job_cleanup(&job->base);
297 out_put_job:
298         panfrost_job_put(job);
299 out_put_syncout:
300         if (sync_out)
301                 drm_syncobj_put(sync_out);
302
303         return ret;
304 }
305
306 static int
307 panfrost_ioctl_wait_bo(struct drm_device *dev, void *data,
308                        struct drm_file *file_priv)
309 {
310         long ret;
311         struct drm_panfrost_wait_bo *args = data;
312         struct drm_gem_object *gem_obj;
313         unsigned long timeout = drm_timeout_abs_to_jiffies(args->timeout_ns);
314
315         if (args->pad)
316                 return -EINVAL;
317
318         gem_obj = drm_gem_object_lookup(file_priv, args->handle);
319         if (!gem_obj)
320                 return -ENOENT;
321
322         ret = dma_resv_wait_timeout(gem_obj->resv, DMA_RESV_USAGE_READ,
323                                     true, timeout);
324         if (!ret)
325                 ret = timeout ? -ETIMEDOUT : -EBUSY;
326
327         drm_gem_object_put(gem_obj);
328
329         return ret;
330 }
331
332 static int panfrost_ioctl_mmap_bo(struct drm_device *dev, void *data,
333                       struct drm_file *file_priv)
334 {
335         struct drm_panfrost_mmap_bo *args = data;
336         struct drm_gem_object *gem_obj;
337         int ret;
338
339         if (args->flags != 0) {
340                 DRM_INFO("unknown mmap_bo flags: %d\n", args->flags);
341                 return -EINVAL;
342         }
343
344         gem_obj = drm_gem_object_lookup(file_priv, args->handle);
345         if (!gem_obj) {
346                 DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
347                 return -ENOENT;
348         }
349
350         /* Don't allow mmapping of heap objects as pages are not pinned. */
351         if (to_panfrost_bo(gem_obj)->is_heap) {
352                 ret = -EINVAL;
353                 goto out;
354         }
355
356         ret = drm_gem_create_mmap_offset(gem_obj);
357         if (ret == 0)
358                 args->offset = drm_vma_node_offset_addr(&gem_obj->vma_node);
359
360 out:
361         drm_gem_object_put(gem_obj);
362         return ret;
363 }
364
365 static int panfrost_ioctl_get_bo_offset(struct drm_device *dev, void *data,
366                             struct drm_file *file_priv)
367 {
368         struct panfrost_file_priv *priv = file_priv->driver_priv;
369         struct drm_panfrost_get_bo_offset *args = data;
370         struct panfrost_gem_mapping *mapping;
371         struct drm_gem_object *gem_obj;
372         struct panfrost_gem_object *bo;
373
374         gem_obj = drm_gem_object_lookup(file_priv, args->handle);
375         if (!gem_obj) {
376                 DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
377                 return -ENOENT;
378         }
379         bo = to_panfrost_bo(gem_obj);
380
381         mapping = panfrost_gem_mapping_get(bo, priv);
382         drm_gem_object_put(gem_obj);
383
384         if (!mapping)
385                 return -EINVAL;
386
387         args->offset = mapping->mmnode.start << PAGE_SHIFT;
388         panfrost_gem_mapping_put(mapping);
389         return 0;
390 }
391
392 static int panfrost_ioctl_madvise(struct drm_device *dev, void *data,
393                                   struct drm_file *file_priv)
394 {
395         struct panfrost_file_priv *priv = file_priv->driver_priv;
396         struct drm_panfrost_madvise *args = data;
397         struct panfrost_device *pfdev = dev->dev_private;
398         struct drm_gem_object *gem_obj;
399         struct panfrost_gem_object *bo;
400         int ret = 0;
401
402         gem_obj = drm_gem_object_lookup(file_priv, args->handle);
403         if (!gem_obj) {
404                 DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
405                 return -ENOENT;
406         }
407
408         bo = to_panfrost_bo(gem_obj);
409
410         mutex_lock(&pfdev->shrinker_lock);
411         mutex_lock(&bo->mappings.lock);
412         if (args->madv == PANFROST_MADV_DONTNEED) {
413                 struct panfrost_gem_mapping *first;
414
415                 first = list_first_entry(&bo->mappings.list,
416                                          struct panfrost_gem_mapping,
417                                          node);
418
419                 /*
420                  * If we want to mark the BO purgeable, there must be only one
421                  * user: the caller FD.
422                  * We could do something smarter and mark the BO purgeable only
423                  * when all its users have marked it purgeable, but globally
424                  * visible/shared BOs are likely to never be marked purgeable
425                  * anyway, so let's not bother.
426                  */
427                 if (!list_is_singular(&bo->mappings.list) ||
428                     WARN_ON_ONCE(first->mmu != priv->mmu)) {
429                         ret = -EINVAL;
430                         goto out_unlock_mappings;
431                 }
432         }
433
434         args->retained = drm_gem_shmem_madvise(&bo->base, args->madv);
435
436         if (args->retained) {
437                 if (args->madv == PANFROST_MADV_DONTNEED)
438                         list_move_tail(&bo->base.madv_list,
439                                        &pfdev->shrinker_list);
440                 else if (args->madv == PANFROST_MADV_WILLNEED)
441                         list_del_init(&bo->base.madv_list);
442         }
443
444 out_unlock_mappings:
445         mutex_unlock(&bo->mappings.lock);
446         mutex_unlock(&pfdev->shrinker_lock);
447
448         drm_gem_object_put(gem_obj);
449         return ret;
450 }
451
452 int panfrost_unstable_ioctl_check(void)
453 {
454         if (!unstable_ioctls)
455                 return -ENOSYS;
456
457         return 0;
458 }
459
460 static int
461 panfrost_open(struct drm_device *dev, struct drm_file *file)
462 {
463         int ret;
464         struct panfrost_device *pfdev = dev->dev_private;
465         struct panfrost_file_priv *panfrost_priv;
466
467         panfrost_priv = kzalloc(sizeof(*panfrost_priv), GFP_KERNEL);
468         if (!panfrost_priv)
469                 return -ENOMEM;
470
471         panfrost_priv->pfdev = pfdev;
472         file->driver_priv = panfrost_priv;
473
474         panfrost_priv->mmu = panfrost_mmu_ctx_create(pfdev);
475         if (IS_ERR(panfrost_priv->mmu)) {
476                 ret = PTR_ERR(panfrost_priv->mmu);
477                 goto err_free;
478         }
479
480         ret = panfrost_job_open(panfrost_priv);
481         if (ret)
482                 goto err_job;
483
484         return 0;
485
486 err_job:
487         panfrost_mmu_ctx_put(panfrost_priv->mmu);
488 err_free:
489         kfree(panfrost_priv);
490         return ret;
491 }
492
493 static void
494 panfrost_postclose(struct drm_device *dev, struct drm_file *file)
495 {
496         struct panfrost_file_priv *panfrost_priv = file->driver_priv;
497
498         panfrost_perfcnt_close(file);
499         panfrost_job_close(panfrost_priv);
500
501         panfrost_mmu_ctx_put(panfrost_priv->mmu);
502         kfree(panfrost_priv);
503 }
504
505 static const struct drm_ioctl_desc panfrost_drm_driver_ioctls[] = {
506 #define PANFROST_IOCTL(n, func, flags) \
507         DRM_IOCTL_DEF_DRV(PANFROST_##n, panfrost_ioctl_##func, flags)
508
509         PANFROST_IOCTL(SUBMIT,          submit,         DRM_RENDER_ALLOW),
510         PANFROST_IOCTL(WAIT_BO,         wait_bo,        DRM_RENDER_ALLOW),
511         PANFROST_IOCTL(CREATE_BO,       create_bo,      DRM_RENDER_ALLOW),
512         PANFROST_IOCTL(MMAP_BO,         mmap_bo,        DRM_RENDER_ALLOW),
513         PANFROST_IOCTL(GET_PARAM,       get_param,      DRM_RENDER_ALLOW),
514         PANFROST_IOCTL(GET_BO_OFFSET,   get_bo_offset,  DRM_RENDER_ALLOW),
515         PANFROST_IOCTL(PERFCNT_ENABLE,  perfcnt_enable, DRM_RENDER_ALLOW),
516         PANFROST_IOCTL(PERFCNT_DUMP,    perfcnt_dump,   DRM_RENDER_ALLOW),
517         PANFROST_IOCTL(MADVISE,         madvise,        DRM_RENDER_ALLOW),
518 };
519
520 DEFINE_DRM_GEM_FOPS(panfrost_drm_driver_fops);
521
522 /*
523  * Panfrost driver version:
524  * - 1.0 - initial interface
525  * - 1.1 - adds HEAP and NOEXEC flags for CREATE_BO
526  * - 1.2 - adds AFBC_FEATURES query
527  */
528 static const struct drm_driver panfrost_drm_driver = {
529         .driver_features        = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ,
530         .open                   = panfrost_open,
531         .postclose              = panfrost_postclose,
532         .ioctls                 = panfrost_drm_driver_ioctls,
533         .num_ioctls             = ARRAY_SIZE(panfrost_drm_driver_ioctls),
534         .fops                   = &panfrost_drm_driver_fops,
535         .name                   = "panfrost",
536         .desc                   = "panfrost DRM",
537         .date                   = "20180908",
538         .major                  = 1,
539         .minor                  = 2,
540
541         .gem_create_object      = panfrost_gem_create_object,
542         .prime_handle_to_fd     = drm_gem_prime_handle_to_fd,
543         .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
544         .gem_prime_import_sg_table = panfrost_gem_prime_import_sg_table,
545         .gem_prime_mmap         = drm_gem_prime_mmap,
546 };
547
548 static int panfrost_probe(struct platform_device *pdev)
549 {
550         struct panfrost_device *pfdev;
551         struct drm_device *ddev;
552         int err;
553
554         pfdev = devm_kzalloc(&pdev->dev, sizeof(*pfdev), GFP_KERNEL);
555         if (!pfdev)
556                 return -ENOMEM;
557
558         pfdev->pdev = pdev;
559         pfdev->dev = &pdev->dev;
560
561         platform_set_drvdata(pdev, pfdev);
562
563         pfdev->comp = of_device_get_match_data(&pdev->dev);
564         if (!pfdev->comp)
565                 return -ENODEV;
566
567         pfdev->coherent = device_get_dma_attr(&pdev->dev) == DEV_DMA_COHERENT;
568
569         /* Allocate and initialize the DRM device. */
570         ddev = drm_dev_alloc(&panfrost_drm_driver, &pdev->dev);
571         if (IS_ERR(ddev))
572                 return PTR_ERR(ddev);
573
574         ddev->dev_private = pfdev;
575         pfdev->ddev = ddev;
576
577         mutex_init(&pfdev->shrinker_lock);
578         INIT_LIST_HEAD(&pfdev->shrinker_list);
579
580         err = panfrost_device_init(pfdev);
581         if (err) {
582                 if (err != -EPROBE_DEFER)
583                         dev_err(&pdev->dev, "Fatal error during GPU init\n");
584                 goto err_out0;
585         }
586
587         pm_runtime_set_active(pfdev->dev);
588         pm_runtime_mark_last_busy(pfdev->dev);
589         pm_runtime_enable(pfdev->dev);
590         pm_runtime_set_autosuspend_delay(pfdev->dev, 50); /* ~3 frames */
591         pm_runtime_use_autosuspend(pfdev->dev);
592
593         /*
594          * Register the DRM device with the core and the connectors with
595          * sysfs
596          */
597         err = drm_dev_register(ddev, 0);
598         if (err < 0)
599                 goto err_out1;
600
601         panfrost_gem_shrinker_init(ddev);
602
603         return 0;
604
605 err_out1:
606         pm_runtime_disable(pfdev->dev);
607         panfrost_device_fini(pfdev);
608         pm_runtime_set_suspended(pfdev->dev);
609 err_out0:
610         drm_dev_put(ddev);
611         return err;
612 }
613
614 static int panfrost_remove(struct platform_device *pdev)
615 {
616         struct panfrost_device *pfdev = platform_get_drvdata(pdev);
617         struct drm_device *ddev = pfdev->ddev;
618
619         drm_dev_unregister(ddev);
620         panfrost_gem_shrinker_cleanup(ddev);
621
622         pm_runtime_get_sync(pfdev->dev);
623         pm_runtime_disable(pfdev->dev);
624         panfrost_device_fini(pfdev);
625         pm_runtime_set_suspended(pfdev->dev);
626
627         drm_dev_put(ddev);
628         return 0;
629 }
630
631 /*
632  * The OPP core wants the supply names to be NULL terminated, but we need the
633  * correct num_supplies value for regulator core. Hence, we NULL terminate here
634  * and then initialize num_supplies with ARRAY_SIZE - 1.
635  */
636 static const char * const default_supplies[] = { "mali", NULL };
637 static const struct panfrost_compatible default_data = {
638         .num_supplies = ARRAY_SIZE(default_supplies) - 1,
639         .supply_names = default_supplies,
640         .num_pm_domains = 1, /* optional */
641         .pm_domain_names = NULL,
642 };
643
644 static const struct panfrost_compatible amlogic_data = {
645         .num_supplies = ARRAY_SIZE(default_supplies) - 1,
646         .supply_names = default_supplies,
647         .vendor_quirk = panfrost_gpu_amlogic_quirk,
648 };
649
650 /*
651  * The old data with two power supplies for MT8183 is here only to
652  * keep retro-compatibility with older devicetrees, as DVFS will
653  * not work with this one.
654  *
655  * On new devicetrees please use the _b variant with a single and
656  * coupled regulators instead.
657  */
658 static const char * const mediatek_mt8183_supplies[] = { "mali", "sram", NULL };
659 static const char * const mediatek_mt8183_pm_domains[] = { "core0", "core1", "core2" };
660 static const struct panfrost_compatible mediatek_mt8183_data = {
661         .num_supplies = ARRAY_SIZE(mediatek_mt8183_supplies) - 1,
662         .supply_names = mediatek_mt8183_supplies,
663         .num_pm_domains = ARRAY_SIZE(mediatek_mt8183_pm_domains),
664         .pm_domain_names = mediatek_mt8183_pm_domains,
665 };
666
667 static const char * const mediatek_mt8183_b_supplies[] = { "mali", NULL };
668 static const struct panfrost_compatible mediatek_mt8183_b_data = {
669         .num_supplies = ARRAY_SIZE(mediatek_mt8183_b_supplies) - 1,
670         .supply_names = mediatek_mt8183_b_supplies,
671         .num_pm_domains = ARRAY_SIZE(mediatek_mt8183_pm_domains),
672         .pm_domain_names = mediatek_mt8183_pm_domains,
673 };
674
675 static const char * const mediatek_mt8186_pm_domains[] = { "core0", "core1" };
676 static const struct panfrost_compatible mediatek_mt8186_data = {
677         .num_supplies = ARRAY_SIZE(mediatek_mt8183_b_supplies) - 1,
678         .supply_names = mediatek_mt8183_b_supplies,
679         .num_pm_domains = ARRAY_SIZE(mediatek_mt8186_pm_domains),
680         .pm_domain_names = mediatek_mt8186_pm_domains,
681 };
682
683 static const char * const mediatek_mt8192_supplies[] = { "mali", NULL };
684 static const char * const mediatek_mt8192_pm_domains[] = { "core0", "core1", "core2",
685                                                            "core3", "core4" };
686 static const struct panfrost_compatible mediatek_mt8192_data = {
687         .num_supplies = ARRAY_SIZE(mediatek_mt8192_supplies) - 1,
688         .supply_names = mediatek_mt8192_supplies,
689         .num_pm_domains = ARRAY_SIZE(mediatek_mt8192_pm_domains),
690         .pm_domain_names = mediatek_mt8192_pm_domains,
691 };
692
693 static const struct of_device_id dt_match[] = {
694         /* Set first to probe before the generic compatibles */
695         { .compatible = "amlogic,meson-gxm-mali",
696           .data = &amlogic_data, },
697         { .compatible = "amlogic,meson-g12a-mali",
698           .data = &amlogic_data, },
699         { .compatible = "arm,mali-t604", .data = &default_data, },
700         { .compatible = "arm,mali-t624", .data = &default_data, },
701         { .compatible = "arm,mali-t628", .data = &default_data, },
702         { .compatible = "arm,mali-t720", .data = &default_data, },
703         { .compatible = "arm,mali-t760", .data = &default_data, },
704         { .compatible = "arm,mali-t820", .data = &default_data, },
705         { .compatible = "arm,mali-t830", .data = &default_data, },
706         { .compatible = "arm,mali-t860", .data = &default_data, },
707         { .compatible = "arm,mali-t880", .data = &default_data, },
708         { .compatible = "arm,mali-bifrost", .data = &default_data, },
709         { .compatible = "arm,mali-valhall-jm", .data = &default_data, },
710         { .compatible = "mediatek,mt8183-mali", .data = &mediatek_mt8183_data },
711         { .compatible = "mediatek,mt8183b-mali", .data = &mediatek_mt8183_b_data },
712         { .compatible = "mediatek,mt8186-mali", .data = &mediatek_mt8186_data },
713         { .compatible = "mediatek,mt8192-mali", .data = &mediatek_mt8192_data },
714         {}
715 };
716 MODULE_DEVICE_TABLE(of, dt_match);
717
718 static struct platform_driver panfrost_driver = {
719         .probe          = panfrost_probe,
720         .remove         = panfrost_remove,
721         .driver         = {
722                 .name   = "panfrost",
723                 .pm     = pm_ptr(&panfrost_pm_ops),
724                 .of_match_table = dt_match,
725         },
726 };
727 module_platform_driver(panfrost_driver);
728
729 MODULE_AUTHOR("Panfrost Project Developers");
730 MODULE_DESCRIPTION("Panfrost DRM Driver");
731 MODULE_LICENSE("GPL v2");
This page took 0.077855 seconds and 4 git commands to generate.