2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <drm/drm_of.h>
21 #include "msm_debugfs.h"
22 #include "msm_fence.h"
29 * - 1.0.0 - initial interface
30 * - 1.1.0 - adds madvise, and support for submits with > 4 cmd buffers
31 * - 1.2.0 - adds explicit fence support for submit ioctl
33 #define MSM_VERSION_MAJOR 1
34 #define MSM_VERSION_MINOR 2
35 #define MSM_VERSION_PATCHLEVEL 0
37 static void msm_fb_output_poll_changed(struct drm_device
*dev
)
39 struct msm_drm_private
*priv
= dev
->dev_private
;
41 drm_fb_helper_hotplug_event(priv
->fbdev
);
44 static const struct drm_mode_config_funcs mode_config_funcs
= {
45 .fb_create
= msm_framebuffer_create
,
46 .output_poll_changed
= msm_fb_output_poll_changed
,
47 .atomic_check
= msm_atomic_check
,
48 .atomic_commit
= msm_atomic_commit
,
49 .atomic_state_alloc
= msm_atomic_state_alloc
,
50 .atomic_state_clear
= msm_atomic_state_clear
,
51 .atomic_state_free
= msm_atomic_state_free
,
54 int msm_register_address_space(struct drm_device
*dev
,
55 struct msm_gem_address_space
*aspace
)
57 struct msm_drm_private
*priv
= dev
->dev_private
;
59 if (WARN_ON(priv
->num_aspaces
>= ARRAY_SIZE(priv
->aspace
)))
62 priv
->aspace
[priv
->num_aspaces
] = aspace
;
64 return priv
->num_aspaces
++;
67 #ifdef CONFIG_DRM_MSM_REGISTER_LOGGING
68 static bool reglog
= false;
69 MODULE_PARM_DESC(reglog
, "Enable register read/write logging");
70 module_param(reglog
, bool, 0600);
75 #ifdef CONFIG_DRM_FBDEV_EMULATION
76 static bool fbdev
= true;
77 MODULE_PARM_DESC(fbdev
, "Enable fbdev compat layer");
78 module_param(fbdev
, bool, 0600);
81 static char *vram
= "16m";
82 MODULE_PARM_DESC(vram
, "Configure VRAM size (for devices without IOMMU/GPUMMU)");
83 module_param(vram
, charp
, 0);
85 bool dumpstate
= false;
86 MODULE_PARM_DESC(dumpstate
, "Dump KMS state on errors");
87 module_param(dumpstate
, bool, 0600);
93 struct clk
*msm_clk_get(struct platform_device
*pdev
, const char *name
)
98 clk
= devm_clk_get(&pdev
->dev
, name
);
99 if (!IS_ERR(clk
) || PTR_ERR(clk
) == -EPROBE_DEFER
)
102 snprintf(name2
, sizeof(name2
), "%s_clk", name
);
104 clk
= devm_clk_get(&pdev
->dev
, name2
);
106 dev_warn(&pdev
->dev
, "Using legacy clk name binding. Use "
107 "\"%s\" instead of \"%s\"\n", name
, name2
);
112 void __iomem
*msm_ioremap(struct platform_device
*pdev
, const char *name
,
115 struct resource
*res
;
120 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, name
);
122 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
125 dev_err(&pdev
->dev
, "failed to get memory resource: %s\n", name
);
126 return ERR_PTR(-EINVAL
);
129 size
= resource_size(res
);
131 ptr
= devm_ioremap_nocache(&pdev
->dev
, res
->start
, size
);
133 dev_err(&pdev
->dev
, "failed to ioremap: %s\n", name
);
134 return ERR_PTR(-ENOMEM
);
138 printk(KERN_DEBUG
"IO:region %s %p %08lx\n", dbgname
, ptr
, size
);
143 void msm_writel(u32 data
, void __iomem
*addr
)
146 printk(KERN_DEBUG
"IO:W %p %08x\n", addr
, data
);
150 u32
msm_readl(const void __iomem
*addr
)
152 u32 val
= readl(addr
);
154 pr_err("IO:R %p %08x\n", addr
, val
);
158 struct vblank_event
{
159 struct list_head node
;
164 static void vblank_ctrl_worker(struct work_struct
*work
)
166 struct msm_vblank_ctrl
*vbl_ctrl
= container_of(work
,
167 struct msm_vblank_ctrl
, work
);
168 struct msm_drm_private
*priv
= container_of(vbl_ctrl
,
169 struct msm_drm_private
, vblank_ctrl
);
170 struct msm_kms
*kms
= priv
->kms
;
171 struct vblank_event
*vbl_ev
, *tmp
;
174 spin_lock_irqsave(&vbl_ctrl
->lock
, flags
);
175 list_for_each_entry_safe(vbl_ev
, tmp
, &vbl_ctrl
->event_list
, node
) {
176 list_del(&vbl_ev
->node
);
177 spin_unlock_irqrestore(&vbl_ctrl
->lock
, flags
);
180 kms
->funcs
->enable_vblank(kms
,
181 priv
->crtcs
[vbl_ev
->crtc_id
]);
183 kms
->funcs
->disable_vblank(kms
,
184 priv
->crtcs
[vbl_ev
->crtc_id
]);
188 spin_lock_irqsave(&vbl_ctrl
->lock
, flags
);
191 spin_unlock_irqrestore(&vbl_ctrl
->lock
, flags
);
194 static int vblank_ctrl_queue_work(struct msm_drm_private
*priv
,
195 int crtc_id
, bool enable
)
197 struct msm_vblank_ctrl
*vbl_ctrl
= &priv
->vblank_ctrl
;
198 struct vblank_event
*vbl_ev
;
201 vbl_ev
= kzalloc(sizeof(*vbl_ev
), GFP_ATOMIC
);
205 vbl_ev
->crtc_id
= crtc_id
;
206 vbl_ev
->enable
= enable
;
208 spin_lock_irqsave(&vbl_ctrl
->lock
, flags
);
209 list_add_tail(&vbl_ev
->node
, &vbl_ctrl
->event_list
);
210 spin_unlock_irqrestore(&vbl_ctrl
->lock
, flags
);
212 queue_work(priv
->wq
, &vbl_ctrl
->work
);
217 static int msm_drm_uninit(struct device
*dev
)
219 struct platform_device
*pdev
= to_platform_device(dev
);
220 struct drm_device
*ddev
= platform_get_drvdata(pdev
);
221 struct msm_drm_private
*priv
= ddev
->dev_private
;
222 struct msm_kms
*kms
= priv
->kms
;
223 struct msm_gpu
*gpu
= priv
->gpu
;
224 struct msm_vblank_ctrl
*vbl_ctrl
= &priv
->vblank_ctrl
;
225 struct vblank_event
*vbl_ev
, *tmp
;
227 /* We must cancel and cleanup any pending vblank enable/disable
228 * work before drm_irq_uninstall() to avoid work re-enabling an
229 * irq after uninstall has disabled it.
231 cancel_work_sync(&vbl_ctrl
->work
);
232 list_for_each_entry_safe(vbl_ev
, tmp
, &vbl_ctrl
->event_list
, node
) {
233 list_del(&vbl_ev
->node
);
237 msm_gem_shrinker_cleanup(ddev
);
239 drm_kms_helper_poll_fini(ddev
);
241 drm_dev_unregister(ddev
);
243 msm_perf_debugfs_cleanup(priv
);
244 msm_rd_debugfs_cleanup(priv
);
246 #ifdef CONFIG_DRM_FBDEV_EMULATION
247 if (fbdev
&& priv
->fbdev
)
248 msm_fbdev_free(ddev
);
250 drm_mode_config_cleanup(ddev
);
252 pm_runtime_get_sync(dev
);
253 drm_irq_uninstall(ddev
);
254 pm_runtime_put_sync(dev
);
256 flush_workqueue(priv
->wq
);
257 destroy_workqueue(priv
->wq
);
259 flush_workqueue(priv
->atomic_wq
);
260 destroy_workqueue(priv
->atomic_wq
);
262 if (kms
&& kms
->funcs
)
263 kms
->funcs
->destroy(kms
);
266 mutex_lock(&ddev
->struct_mutex
);
267 // XXX what do we do here?
268 //pm_runtime_enable(&pdev->dev);
269 gpu
->funcs
->pm_suspend(gpu
);
270 mutex_unlock(&ddev
->struct_mutex
);
271 gpu
->funcs
->destroy(gpu
);
274 if (priv
->vram
.paddr
) {
275 unsigned long attrs
= DMA_ATTR_NO_KERNEL_MAPPING
;
276 drm_mm_takedown(&priv
->vram
.mm
);
277 dma_free_attrs(dev
, priv
->vram
.size
, NULL
,
278 priv
->vram
.paddr
, attrs
);
281 component_unbind_all(dev
, ddev
);
283 msm_mdss_destroy(ddev
);
285 ddev
->dev_private
= NULL
;
293 static int get_mdp_ver(struct platform_device
*pdev
)
295 struct device
*dev
= &pdev
->dev
;
297 return (int) (unsigned long) of_device_get_match_data(dev
);
300 #include <linux/of_address.h>
302 static int msm_init_vram(struct drm_device
*dev
)
304 struct msm_drm_private
*priv
= dev
->dev_private
;
305 struct device_node
*node
;
306 unsigned long size
= 0;
309 /* In the device-tree world, we could have a 'memory-region'
310 * phandle, which gives us a link to our "vram". Allocating
311 * is all nicely abstracted behind the dma api, but we need
312 * to know the entire size to allocate it all in one go. There
314 * 1) device with no IOMMU, in which case we need exclusive
315 * access to a VRAM carveout big enough for all gpu
317 * 2) device with IOMMU, but where the bootloader puts up
318 * a splash screen. In this case, the VRAM carveout
319 * need only be large enough for fbdev fb. But we need
320 * exclusive access to the buffer to avoid the kernel
321 * using those pages for other purposes (which appears
322 * as corruption on screen before we have a chance to
323 * load and do initial modeset)
326 node
= of_parse_phandle(dev
->dev
->of_node
, "memory-region", 0);
329 ret
= of_address_to_resource(node
, 0, &r
);
333 size
= r
.end
- r
.start
;
334 DRM_INFO("using VRAM carveout: %lx@%pa\n", size
, &r
.start
);
336 /* if we have no IOMMU, then we need to use carveout allocator.
337 * Grab the entire CMA chunk carved out in early startup in
340 } else if (!iommu_present(&platform_bus_type
)) {
341 DRM_INFO("using %s VRAM carveout\n", vram
);
342 size
= memparse(vram
, NULL
);
346 unsigned long attrs
= 0;
349 priv
->vram
.size
= size
;
351 drm_mm_init(&priv
->vram
.mm
, 0, (size
>> PAGE_SHIFT
) - 1);
353 attrs
|= DMA_ATTR_NO_KERNEL_MAPPING
;
354 attrs
|= DMA_ATTR_WRITE_COMBINE
;
356 /* note that for no-kernel-mapping, the vaddr returned
357 * is bogus, but non-null if allocation succeeded:
359 p
= dma_alloc_attrs(dev
->dev
, size
,
360 &priv
->vram
.paddr
, GFP_KERNEL
, attrs
);
362 dev_err(dev
->dev
, "failed to allocate VRAM\n");
363 priv
->vram
.paddr
= 0;
367 dev_info(dev
->dev
, "VRAM: %08x->%08x\n",
368 (uint32_t)priv
->vram
.paddr
,
369 (uint32_t)(priv
->vram
.paddr
+ size
));
375 static int msm_drm_init(struct device
*dev
, struct drm_driver
*drv
)
377 struct platform_device
*pdev
= to_platform_device(dev
);
378 struct drm_device
*ddev
;
379 struct msm_drm_private
*priv
;
383 ddev
= drm_dev_alloc(drv
, dev
);
385 dev_err(dev
, "failed to allocate drm_device\n");
386 return PTR_ERR(ddev
);
389 platform_set_drvdata(pdev
, ddev
);
391 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
397 ddev
->dev_private
= priv
;
400 ret
= msm_mdss_init(ddev
);
407 priv
->wq
= alloc_ordered_workqueue("msm", 0);
408 priv
->atomic_wq
= alloc_ordered_workqueue("msm:atomic", 0);
409 init_waitqueue_head(&priv
->pending_crtcs_event
);
411 INIT_LIST_HEAD(&priv
->inactive_list
);
412 INIT_LIST_HEAD(&priv
->vblank_ctrl
.event_list
);
413 INIT_WORK(&priv
->vblank_ctrl
.work
, vblank_ctrl_worker
);
414 spin_lock_init(&priv
->vblank_ctrl
.lock
);
416 drm_mode_config_init(ddev
);
418 /* Bind all our sub-components: */
419 ret
= component_bind_all(dev
, ddev
);
421 msm_mdss_destroy(ddev
);
427 ret
= msm_init_vram(ddev
);
431 msm_gem_shrinker_init(ddev
);
433 switch (get_mdp_ver(pdev
)) {
435 kms
= mdp4_kms_init(ddev
);
439 kms
= mdp5_kms_init(ddev
);
442 kms
= ERR_PTR(-ENODEV
);
448 * NOTE: once we have GPU support, having no kms should not
449 * be considered fatal.. ideally we would still support gpu
450 * and (for example) use dmabuf/prime to share buffers with
451 * imx drm driver on iMX5
453 dev_err(dev
, "failed to load kms\n");
459 ret
= kms
->funcs
->hw_init(kms
);
461 dev_err(dev
, "kms hw init failed: %d\n", ret
);
466 ddev
->mode_config
.funcs
= &mode_config_funcs
;
468 ret
= drm_vblank_init(ddev
, priv
->num_crtcs
);
470 dev_err(dev
, "failed to initialize vblank\n");
475 pm_runtime_get_sync(dev
);
476 ret
= drm_irq_install(ddev
, kms
->irq
);
477 pm_runtime_put_sync(dev
);
479 dev_err(dev
, "failed to install IRQ handler\n");
484 ret
= drm_dev_register(ddev
, 0);
488 drm_mode_config_reset(ddev
);
490 #ifdef CONFIG_DRM_FBDEV_EMULATION
492 priv
->fbdev
= msm_fbdev_init(ddev
);
495 ret
= msm_debugfs_late_init(ddev
);
499 drm_kms_helper_poll_init(ddev
);
512 static void load_gpu(struct drm_device
*dev
)
514 static DEFINE_MUTEX(init_lock
);
515 struct msm_drm_private
*priv
= dev
->dev_private
;
517 mutex_lock(&init_lock
);
520 priv
->gpu
= adreno_load_gpu(dev
);
522 mutex_unlock(&init_lock
);
525 static int msm_open(struct drm_device
*dev
, struct drm_file
*file
)
527 struct msm_file_private
*ctx
;
529 /* For now, load gpu on open.. to avoid the requirement of having
530 * firmware in the initrd.
534 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
538 file
->driver_priv
= ctx
;
543 static void msm_postclose(struct drm_device
*dev
, struct drm_file
*file
)
545 struct msm_drm_private
*priv
= dev
->dev_private
;
546 struct msm_file_private
*ctx
= file
->driver_priv
;
548 mutex_lock(&dev
->struct_mutex
);
549 if (ctx
== priv
->lastctx
)
550 priv
->lastctx
= NULL
;
551 mutex_unlock(&dev
->struct_mutex
);
556 static void msm_lastclose(struct drm_device
*dev
)
558 struct msm_drm_private
*priv
= dev
->dev_private
;
560 drm_fb_helper_restore_fbdev_mode_unlocked(priv
->fbdev
);
563 static irqreturn_t
msm_irq(int irq
, void *arg
)
565 struct drm_device
*dev
= arg
;
566 struct msm_drm_private
*priv
= dev
->dev_private
;
567 struct msm_kms
*kms
= priv
->kms
;
569 return kms
->funcs
->irq(kms
);
572 static void msm_irq_preinstall(struct drm_device
*dev
)
574 struct msm_drm_private
*priv
= dev
->dev_private
;
575 struct msm_kms
*kms
= priv
->kms
;
577 kms
->funcs
->irq_preinstall(kms
);
580 static int msm_irq_postinstall(struct drm_device
*dev
)
582 struct msm_drm_private
*priv
= dev
->dev_private
;
583 struct msm_kms
*kms
= priv
->kms
;
585 return kms
->funcs
->irq_postinstall(kms
);
588 static void msm_irq_uninstall(struct drm_device
*dev
)
590 struct msm_drm_private
*priv
= dev
->dev_private
;
591 struct msm_kms
*kms
= priv
->kms
;
593 kms
->funcs
->irq_uninstall(kms
);
596 static int msm_enable_vblank(struct drm_device
*dev
, unsigned int pipe
)
598 struct msm_drm_private
*priv
= dev
->dev_private
;
599 struct msm_kms
*kms
= priv
->kms
;
602 DBG("dev=%p, crtc=%u", dev
, pipe
);
603 return vblank_ctrl_queue_work(priv
, pipe
, true);
606 static void msm_disable_vblank(struct drm_device
*dev
, unsigned int pipe
)
608 struct msm_drm_private
*priv
= dev
->dev_private
;
609 struct msm_kms
*kms
= priv
->kms
;
612 DBG("dev=%p, crtc=%u", dev
, pipe
);
613 vblank_ctrl_queue_work(priv
, pipe
, false);
620 static int msm_ioctl_get_param(struct drm_device
*dev
, void *data
,
621 struct drm_file
*file
)
623 struct msm_drm_private
*priv
= dev
->dev_private
;
624 struct drm_msm_param
*args
= data
;
627 /* for now, we just have 3d pipe.. eventually this would need to
628 * be more clever to dispatch to appropriate gpu module:
630 if (args
->pipe
!= MSM_PIPE_3D0
)
638 return gpu
->funcs
->get_param(gpu
, args
->param
, &args
->value
);
641 static int msm_ioctl_gem_new(struct drm_device
*dev
, void *data
,
642 struct drm_file
*file
)
644 struct drm_msm_gem_new
*args
= data
;
646 if (args
->flags
& ~MSM_BO_FLAGS
) {
647 DRM_ERROR("invalid flags: %08x\n", args
->flags
);
651 return msm_gem_new_handle(dev
, file
, args
->size
,
652 args
->flags
, &args
->handle
);
655 static inline ktime_t
to_ktime(struct drm_msm_timespec timeout
)
657 return ktime_set(timeout
.tv_sec
, timeout
.tv_nsec
);
660 static int msm_ioctl_gem_cpu_prep(struct drm_device
*dev
, void *data
,
661 struct drm_file
*file
)
663 struct drm_msm_gem_cpu_prep
*args
= data
;
664 struct drm_gem_object
*obj
;
665 ktime_t timeout
= to_ktime(args
->timeout
);
668 if (args
->op
& ~MSM_PREP_FLAGS
) {
669 DRM_ERROR("invalid op: %08x\n", args
->op
);
673 obj
= drm_gem_object_lookup(file
, args
->handle
);
677 ret
= msm_gem_cpu_prep(obj
, args
->op
, &timeout
);
679 drm_gem_object_unreference_unlocked(obj
);
684 static int msm_ioctl_gem_cpu_fini(struct drm_device
*dev
, void *data
,
685 struct drm_file
*file
)
687 struct drm_msm_gem_cpu_fini
*args
= data
;
688 struct drm_gem_object
*obj
;
691 obj
= drm_gem_object_lookup(file
, args
->handle
);
695 ret
= msm_gem_cpu_fini(obj
);
697 drm_gem_object_unreference_unlocked(obj
);
702 static int msm_ioctl_gem_info(struct drm_device
*dev
, void *data
,
703 struct drm_file
*file
)
705 struct drm_msm_gem_info
*args
= data
;
706 struct drm_gem_object
*obj
;
712 obj
= drm_gem_object_lookup(file
, args
->handle
);
716 args
->offset
= msm_gem_mmap_offset(obj
);
718 drm_gem_object_unreference_unlocked(obj
);
723 static int msm_ioctl_wait_fence(struct drm_device
*dev
, void *data
,
724 struct drm_file
*file
)
726 struct msm_drm_private
*priv
= dev
->dev_private
;
727 struct drm_msm_wait_fence
*args
= data
;
728 ktime_t timeout
= to_ktime(args
->timeout
);
731 DRM_ERROR("invalid pad: %08x\n", args
->pad
);
738 return msm_wait_fence(priv
->gpu
->fctx
, args
->fence
, &timeout
, true);
741 static int msm_ioctl_gem_madvise(struct drm_device
*dev
, void *data
,
742 struct drm_file
*file
)
744 struct drm_msm_gem_madvise
*args
= data
;
745 struct drm_gem_object
*obj
;
748 switch (args
->madv
) {
749 case MSM_MADV_DONTNEED
:
750 case MSM_MADV_WILLNEED
:
756 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
760 obj
= drm_gem_object_lookup(file
, args
->handle
);
766 ret
= msm_gem_madvise(obj
, args
->madv
);
768 args
->retained
= ret
;
772 drm_gem_object_unreference(obj
);
775 mutex_unlock(&dev
->struct_mutex
);
779 static const struct drm_ioctl_desc msm_ioctls
[] = {
780 DRM_IOCTL_DEF_DRV(MSM_GET_PARAM
, msm_ioctl_get_param
, DRM_AUTH
|DRM_RENDER_ALLOW
),
781 DRM_IOCTL_DEF_DRV(MSM_GEM_NEW
, msm_ioctl_gem_new
, DRM_AUTH
|DRM_RENDER_ALLOW
),
782 DRM_IOCTL_DEF_DRV(MSM_GEM_INFO
, msm_ioctl_gem_info
, DRM_AUTH
|DRM_RENDER_ALLOW
),
783 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP
, msm_ioctl_gem_cpu_prep
, DRM_AUTH
|DRM_RENDER_ALLOW
),
784 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI
, msm_ioctl_gem_cpu_fini
, DRM_AUTH
|DRM_RENDER_ALLOW
),
785 DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT
, msm_ioctl_gem_submit
, DRM_AUTH
|DRM_RENDER_ALLOW
),
786 DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE
, msm_ioctl_wait_fence
, DRM_AUTH
|DRM_RENDER_ALLOW
),
787 DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE
, msm_ioctl_gem_madvise
, DRM_AUTH
|DRM_RENDER_ALLOW
),
790 static const struct vm_operations_struct vm_ops
= {
791 .fault
= msm_gem_fault
,
792 .open
= drm_gem_vm_open
,
793 .close
= drm_gem_vm_close
,
796 static const struct file_operations fops
= {
797 .owner
= THIS_MODULE
,
799 .release
= drm_release
,
800 .unlocked_ioctl
= drm_ioctl
,
801 .compat_ioctl
= drm_compat_ioctl
,
805 .mmap
= msm_gem_mmap
,
808 static struct drm_driver msm_driver
= {
809 .driver_features
= DRIVER_HAVE_IRQ
|
816 .postclose
= msm_postclose
,
817 .lastclose
= msm_lastclose
,
818 .irq_handler
= msm_irq
,
819 .irq_preinstall
= msm_irq_preinstall
,
820 .irq_postinstall
= msm_irq_postinstall
,
821 .irq_uninstall
= msm_irq_uninstall
,
822 .enable_vblank
= msm_enable_vblank
,
823 .disable_vblank
= msm_disable_vblank
,
824 .gem_free_object
= msm_gem_free_object
,
825 .gem_vm_ops
= &vm_ops
,
826 .dumb_create
= msm_gem_dumb_create
,
827 .dumb_map_offset
= msm_gem_dumb_map_offset
,
828 .dumb_destroy
= drm_gem_dumb_destroy
,
829 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
830 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
831 .gem_prime_export
= drm_gem_prime_export
,
832 .gem_prime_import
= drm_gem_prime_import
,
833 .gem_prime_pin
= msm_gem_prime_pin
,
834 .gem_prime_unpin
= msm_gem_prime_unpin
,
835 .gem_prime_get_sg_table
= msm_gem_prime_get_sg_table
,
836 .gem_prime_import_sg_table
= msm_gem_prime_import_sg_table
,
837 .gem_prime_vmap
= msm_gem_prime_vmap
,
838 .gem_prime_vunmap
= msm_gem_prime_vunmap
,
839 .gem_prime_mmap
= msm_gem_prime_mmap
,
840 #ifdef CONFIG_DEBUG_FS
841 .debugfs_init
= msm_debugfs_init
,
843 .ioctls
= msm_ioctls
,
844 .num_ioctls
= DRM_MSM_NUM_IOCTLS
,
847 .desc
= "MSM Snapdragon DRM",
849 .major
= MSM_VERSION_MAJOR
,
850 .minor
= MSM_VERSION_MINOR
,
851 .patchlevel
= MSM_VERSION_PATCHLEVEL
,
854 #ifdef CONFIG_PM_SLEEP
855 static int msm_pm_suspend(struct device
*dev
)
857 struct drm_device
*ddev
= dev_get_drvdata(dev
);
859 drm_kms_helper_poll_disable(ddev
);
864 static int msm_pm_resume(struct device
*dev
)
866 struct drm_device
*ddev
= dev_get_drvdata(dev
);
868 drm_kms_helper_poll_enable(ddev
);
874 static const struct dev_pm_ops msm_pm_ops
= {
875 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend
, msm_pm_resume
)
879 * Componentized driver support:
883 * NOTE: duplication of the same code as exynos or imx (or probably any other).
884 * so probably some room for some helpers
886 static int compare_of(struct device
*dev
, void *data
)
888 return dev
->of_node
== data
;
892 * Identify what components need to be added by parsing what remote-endpoints
893 * our MDP output ports are connected to. In the case of LVDS on MDP4, there
894 * is no external component that we need to add since LVDS is within MDP4
897 static int add_components_mdp(struct device
*mdp_dev
,
898 struct component_match
**matchptr
)
900 struct device_node
*np
= mdp_dev
->of_node
;
901 struct device_node
*ep_node
;
902 struct device
*master_dev
;
905 * on MDP4 based platforms, the MDP platform device is the component
906 * master that adds other display interface components to itself.
908 * on MDP5 based platforms, the MDSS platform device is the component
909 * master that adds MDP5 and other display interface components to
912 if (of_device_is_compatible(np
, "qcom,mdp4"))
913 master_dev
= mdp_dev
;
915 master_dev
= mdp_dev
->parent
;
917 for_each_endpoint_of_node(np
, ep_node
) {
918 struct device_node
*intf
;
919 struct of_endpoint ep
;
922 ret
= of_graph_parse_endpoint(ep_node
, &ep
);
924 dev_err(mdp_dev
, "unable to parse port endpoint\n");
925 of_node_put(ep_node
);
930 * The LCDC/LVDS port on MDP4 is a speacial case where the
931 * remote-endpoint isn't a component that we need to add
933 if (of_device_is_compatible(np
, "qcom,mdp4") &&
938 * It's okay if some of the ports don't have a remote endpoint
939 * specified. It just means that the port isn't connected to
940 * any external interface.
942 intf
= of_graph_get_remote_port_parent(ep_node
);
946 drm_of_component_match_add(master_dev
, matchptr
, compare_of
,
954 static int compare_name_mdp(struct device
*dev
, void *data
)
956 return (strstr(dev_name(dev
), "mdp") != NULL
);
959 static int add_display_components(struct device
*dev
,
960 struct component_match
**matchptr
)
962 struct device
*mdp_dev
;
966 * MDP5 based devices don't have a flat hierarchy. There is a top level
967 * parent: MDSS, and children: MDP5, DSI, HDMI, eDP etc. Populate the
968 * children devices, find the MDP5 node, and then add the interfaces
969 * to our components list.
971 if (of_device_is_compatible(dev
->of_node
, "qcom,mdss")) {
972 ret
= of_platform_populate(dev
->of_node
, NULL
, NULL
, dev
);
974 dev_err(dev
, "failed to populate children devices\n");
978 mdp_dev
= device_find_child(dev
, NULL
, compare_name_mdp
);
980 dev_err(dev
, "failed to find MDSS MDP node\n");
981 of_platform_depopulate(dev
);
987 /* add the MDP component itself */
988 drm_of_component_match_add(dev
, matchptr
, compare_of
,
995 ret
= add_components_mdp(mdp_dev
, matchptr
);
997 of_platform_depopulate(dev
);
1003 * We don't know what's the best binding to link the gpu with the drm device.
1004 * Fow now, we just hunt for all the possible gpus that we support, and add them
1007 static const struct of_device_id msm_gpu_match
[] = {
1008 { .compatible
= "qcom,adreno" },
1009 { .compatible
= "qcom,adreno-3xx" },
1010 { .compatible
= "qcom,kgsl-3d0" },
1014 static int add_gpu_components(struct device
*dev
,
1015 struct component_match
**matchptr
)
1017 struct device_node
*np
;
1019 np
= of_find_matching_node(NULL
, msm_gpu_match
);
1023 drm_of_component_match_add(dev
, matchptr
, compare_of
, np
);
1030 static int msm_drm_bind(struct device
*dev
)
1032 return msm_drm_init(dev
, &msm_driver
);
1035 static void msm_drm_unbind(struct device
*dev
)
1037 msm_drm_uninit(dev
);
1040 static const struct component_master_ops msm_drm_ops
= {
1041 .bind
= msm_drm_bind
,
1042 .unbind
= msm_drm_unbind
,
1049 static int msm_pdev_probe(struct platform_device
*pdev
)
1051 struct component_match
*match
= NULL
;
1054 ret
= add_display_components(&pdev
->dev
, &match
);
1058 ret
= add_gpu_components(&pdev
->dev
, &match
);
1062 /* on all devices that I am aware of, iommu's which can map
1063 * any address the cpu can see are used:
1065 ret
= dma_set_mask_and_coherent(&pdev
->dev
, ~0);
1069 return component_master_add_with_match(&pdev
->dev
, &msm_drm_ops
, match
);
1072 static int msm_pdev_remove(struct platform_device
*pdev
)
1074 component_master_del(&pdev
->dev
, &msm_drm_ops
);
1075 of_platform_depopulate(&pdev
->dev
);
1080 static const struct of_device_id dt_match
[] = {
1081 { .compatible
= "qcom,mdp4", .data
= (void *)4 }, /* MDP4 */
1082 { .compatible
= "qcom,mdss", .data
= (void *)5 }, /* MDP5 MDSS */
1085 MODULE_DEVICE_TABLE(of
, dt_match
);
1087 static struct platform_driver msm_platform_driver
= {
1088 .probe
= msm_pdev_probe
,
1089 .remove
= msm_pdev_remove
,
1092 .of_match_table
= dt_match
,
1097 static int __init
msm_drm_register(void)
1103 msm_hdmi_register();
1105 return platform_driver_register(&msm_platform_driver
);
1108 static void __exit
msm_drm_unregister(void)
1111 platform_driver_unregister(&msm_platform_driver
);
1112 msm_hdmi_unregister();
1113 adreno_unregister();
1114 msm_edp_unregister();
1115 msm_dsi_unregister();
1116 msm_mdp_unregister();
1119 module_init(msm_drm_register
);
1120 module_exit(msm_drm_unregister
);
1122 MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
1123 MODULE_DESCRIPTION("MSM DRM Driver");
1124 MODULE_LICENSE("GPL");