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/>.
22 static void msm_fb_output_poll_changed(struct drm_device
*dev
)
24 struct msm_drm_private
*priv
= dev
->dev_private
;
26 drm_fb_helper_hotplug_event(priv
->fbdev
);
29 static const struct drm_mode_config_funcs mode_config_funcs
= {
30 .fb_create
= msm_framebuffer_create
,
31 .output_poll_changed
= msm_fb_output_poll_changed
,
32 .atomic_check
= drm_atomic_helper_check
,
33 .atomic_commit
= msm_atomic_commit
,
36 int msm_register_mmu(struct drm_device
*dev
, struct msm_mmu
*mmu
)
38 struct msm_drm_private
*priv
= dev
->dev_private
;
39 int idx
= priv
->num_mmus
++;
41 if (WARN_ON(idx
>= ARRAY_SIZE(priv
->mmus
)))
44 priv
->mmus
[idx
] = mmu
;
49 #ifdef CONFIG_DRM_MSM_REGISTER_LOGGING
50 static bool reglog
= false;
51 MODULE_PARM_DESC(reglog
, "Enable register read/write logging");
52 module_param(reglog
, bool, 0600);
57 static char *vram
= "16m";
58 MODULE_PARM_DESC(vram
, "Configure VRAM size (for devices without IOMMU/GPUMMU");
59 module_param(vram
, charp
, 0);
65 void __iomem
*msm_ioremap(struct platform_device
*pdev
, const char *name
,
73 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, name
);
75 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
78 dev_err(&pdev
->dev
, "failed to get memory resource: %s\n", name
);
79 return ERR_PTR(-EINVAL
);
82 size
= resource_size(res
);
84 ptr
= devm_ioremap_nocache(&pdev
->dev
, res
->start
, size
);
86 dev_err(&pdev
->dev
, "failed to ioremap: %s\n", name
);
87 return ERR_PTR(-ENOMEM
);
91 printk(KERN_DEBUG
"IO:region %s %08x %08lx\n", dbgname
, (u32
)ptr
, size
);
96 void msm_writel(u32 data
, void __iomem
*addr
)
99 printk(KERN_DEBUG
"IO:W %08x %08x\n", (u32
)addr
, data
);
103 u32
msm_readl(const void __iomem
*addr
)
105 u32 val
= readl(addr
);
107 printk(KERN_ERR
"IO:R %08x %08x\n", (u32
)addr
, val
);
115 static int msm_unload(struct drm_device
*dev
)
117 struct msm_drm_private
*priv
= dev
->dev_private
;
118 struct msm_kms
*kms
= priv
->kms
;
119 struct msm_gpu
*gpu
= priv
->gpu
;
121 drm_kms_helper_poll_fini(dev
);
122 drm_mode_config_cleanup(dev
);
123 drm_vblank_cleanup(dev
);
125 pm_runtime_get_sync(dev
->dev
);
126 drm_irq_uninstall(dev
);
127 pm_runtime_put_sync(dev
->dev
);
129 flush_workqueue(priv
->wq
);
130 destroy_workqueue(priv
->wq
);
133 pm_runtime_disable(dev
->dev
);
134 kms
->funcs
->destroy(kms
);
138 mutex_lock(&dev
->struct_mutex
);
139 gpu
->funcs
->pm_suspend(gpu
);
140 gpu
->funcs
->destroy(gpu
);
141 mutex_unlock(&dev
->struct_mutex
);
144 if (priv
->vram
.paddr
) {
145 DEFINE_DMA_ATTRS(attrs
);
146 dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING
, &attrs
);
147 drm_mm_takedown(&priv
->vram
.mm
);
148 dma_free_attrs(dev
->dev
, priv
->vram
.size
, NULL
,
149 priv
->vram
.paddr
, &attrs
);
152 component_unbind_all(dev
->dev
, dev
);
154 dev
->dev_private
= NULL
;
161 static int get_mdp_ver(struct platform_device
*pdev
)
164 static const struct of_device_id match_types
[] = { {
165 .compatible
= "qcom,mdss_mdp",
170 struct device
*dev
= &pdev
->dev
;
171 const struct of_device_id
*match
;
172 match
= of_match_node(match_types
, dev
->of_node
);
174 return (int)match
->data
;
179 static int msm_load(struct drm_device
*dev
, unsigned long flags
)
181 struct platform_device
*pdev
= dev
->platformdev
;
182 struct msm_drm_private
*priv
;
186 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
188 dev_err(dev
->dev
, "failed to allocate private data\n");
192 dev
->dev_private
= priv
;
194 priv
->wq
= alloc_ordered_workqueue("msm", 0);
195 init_waitqueue_head(&priv
->fence_event
);
197 INIT_LIST_HEAD(&priv
->inactive_list
);
198 INIT_LIST_HEAD(&priv
->fence_cbs
);
200 drm_mode_config_init(dev
);
202 /* if we have no IOMMU, then we need to use carveout allocator.
203 * Grab the entire CMA chunk carved out in early startup in
206 if (!iommu_present(&platform_bus_type
)) {
207 DEFINE_DMA_ATTRS(attrs
);
211 DBG("using %s VRAM carveout", vram
);
212 size
= memparse(vram
, NULL
);
213 priv
->vram
.size
= size
;
215 drm_mm_init(&priv
->vram
.mm
, 0, (size
>> PAGE_SHIFT
) - 1);
217 dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING
, &attrs
);
218 dma_set_attr(DMA_ATTR_WRITE_COMBINE
, &attrs
);
220 /* note that for no-kernel-mapping, the vaddr returned
221 * is bogus, but non-null if allocation succeeded:
223 p
= dma_alloc_attrs(dev
->dev
, size
,
224 &priv
->vram
.paddr
, GFP_KERNEL
, &attrs
);
226 dev_err(dev
->dev
, "failed to allocate VRAM\n");
227 priv
->vram
.paddr
= 0;
232 dev_info(dev
->dev
, "VRAM: %08x->%08x\n",
233 (uint32_t)priv
->vram
.paddr
,
234 (uint32_t)(priv
->vram
.paddr
+ size
));
237 platform_set_drvdata(pdev
, dev
);
239 /* Bind all our sub-components: */
240 ret
= component_bind_all(dev
->dev
, dev
);
244 switch (get_mdp_ver(pdev
)) {
246 kms
= mdp4_kms_init(dev
);
249 kms
= mdp5_kms_init(dev
);
252 kms
= ERR_PTR(-ENODEV
);
258 * NOTE: once we have GPU support, having no kms should not
259 * be considered fatal.. ideally we would still support gpu
260 * and (for example) use dmabuf/prime to share buffers with
261 * imx drm driver on iMX5
263 dev_err(dev
->dev
, "failed to load kms\n");
271 pm_runtime_enable(dev
->dev
);
272 ret
= kms
->funcs
->hw_init(kms
);
274 dev_err(dev
->dev
, "kms hw init failed: %d\n", ret
);
279 dev
->mode_config
.min_width
= 0;
280 dev
->mode_config
.min_height
= 0;
281 dev
->mode_config
.max_width
= 2048;
282 dev
->mode_config
.max_height
= 2048;
283 dev
->mode_config
.funcs
= &mode_config_funcs
;
285 ret
= drm_vblank_init(dev
, priv
->num_crtcs
);
287 dev_err(dev
->dev
, "failed to initialize vblank\n");
291 pm_runtime_get_sync(dev
->dev
);
292 ret
= drm_irq_install(dev
, platform_get_irq(dev
->platformdev
, 0));
293 pm_runtime_put_sync(dev
->dev
);
295 dev_err(dev
->dev
, "failed to install IRQ handler\n");
299 drm_mode_config_reset(dev
);
301 #ifdef CONFIG_DRM_MSM_FBDEV
302 priv
->fbdev
= msm_fbdev_init(dev
);
305 ret
= msm_debugfs_late_init(dev
);
309 drm_kms_helper_poll_init(dev
);
318 static void load_gpu(struct drm_device
*dev
)
320 static DEFINE_MUTEX(init_lock
);
321 struct msm_drm_private
*priv
= dev
->dev_private
;
323 mutex_lock(&init_lock
);
326 priv
->gpu
= adreno_load_gpu(dev
);
328 mutex_unlock(&init_lock
);
331 static int msm_open(struct drm_device
*dev
, struct drm_file
*file
)
333 struct msm_file_private
*ctx
;
335 /* For now, load gpu on open.. to avoid the requirement of having
336 * firmware in the initrd.
340 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
344 file
->driver_priv
= ctx
;
349 static void msm_preclose(struct drm_device
*dev
, struct drm_file
*file
)
351 struct msm_drm_private
*priv
= dev
->dev_private
;
352 struct msm_file_private
*ctx
= file
->driver_priv
;
353 struct msm_kms
*kms
= priv
->kms
;
356 kms
->funcs
->preclose(kms
, file
);
358 mutex_lock(&dev
->struct_mutex
);
359 if (ctx
== priv
->lastctx
)
360 priv
->lastctx
= NULL
;
361 mutex_unlock(&dev
->struct_mutex
);
366 static void msm_lastclose(struct drm_device
*dev
)
368 struct msm_drm_private
*priv
= dev
->dev_private
;
370 drm_fb_helper_restore_fbdev_mode_unlocked(priv
->fbdev
);
373 static irqreturn_t
msm_irq(int irq
, void *arg
)
375 struct drm_device
*dev
= arg
;
376 struct msm_drm_private
*priv
= dev
->dev_private
;
377 struct msm_kms
*kms
= priv
->kms
;
379 return kms
->funcs
->irq(kms
);
382 static void msm_irq_preinstall(struct drm_device
*dev
)
384 struct msm_drm_private
*priv
= dev
->dev_private
;
385 struct msm_kms
*kms
= priv
->kms
;
387 kms
->funcs
->irq_preinstall(kms
);
390 static int msm_irq_postinstall(struct drm_device
*dev
)
392 struct msm_drm_private
*priv
= dev
->dev_private
;
393 struct msm_kms
*kms
= priv
->kms
;
395 return kms
->funcs
->irq_postinstall(kms
);
398 static void msm_irq_uninstall(struct drm_device
*dev
)
400 struct msm_drm_private
*priv
= dev
->dev_private
;
401 struct msm_kms
*kms
= priv
->kms
;
403 kms
->funcs
->irq_uninstall(kms
);
406 static int msm_enable_vblank(struct drm_device
*dev
, int crtc_id
)
408 struct msm_drm_private
*priv
= dev
->dev_private
;
409 struct msm_kms
*kms
= priv
->kms
;
412 DBG("dev=%p, crtc=%d", dev
, crtc_id
);
413 return kms
->funcs
->enable_vblank(kms
, priv
->crtcs
[crtc_id
]);
416 static void msm_disable_vblank(struct drm_device
*dev
, int crtc_id
)
418 struct msm_drm_private
*priv
= dev
->dev_private
;
419 struct msm_kms
*kms
= priv
->kms
;
422 DBG("dev=%p, crtc=%d", dev
, crtc_id
);
423 kms
->funcs
->disable_vblank(kms
, priv
->crtcs
[crtc_id
]);
430 #ifdef CONFIG_DEBUG_FS
431 static int msm_gpu_show(struct drm_device
*dev
, struct seq_file
*m
)
433 struct msm_drm_private
*priv
= dev
->dev_private
;
434 struct msm_gpu
*gpu
= priv
->gpu
;
437 seq_printf(m
, "%s Status:\n", gpu
->name
);
438 gpu
->funcs
->show(gpu
, m
);
444 static int msm_gem_show(struct drm_device
*dev
, struct seq_file
*m
)
446 struct msm_drm_private
*priv
= dev
->dev_private
;
447 struct msm_gpu
*gpu
= priv
->gpu
;
450 seq_printf(m
, "Active Objects (%s):\n", gpu
->name
);
451 msm_gem_describe_objects(&gpu
->active_list
, m
);
454 seq_printf(m
, "Inactive Objects:\n");
455 msm_gem_describe_objects(&priv
->inactive_list
, m
);
460 static int msm_mm_show(struct drm_device
*dev
, struct seq_file
*m
)
462 return drm_mm_dump_table(m
, &dev
->vma_offset_manager
->vm_addr_space_mm
);
465 static int msm_fb_show(struct drm_device
*dev
, struct seq_file
*m
)
467 struct msm_drm_private
*priv
= dev
->dev_private
;
468 struct drm_framebuffer
*fb
, *fbdev_fb
= NULL
;
471 seq_printf(m
, "fbcon ");
472 fbdev_fb
= priv
->fbdev
->fb
;
473 msm_framebuffer_describe(fbdev_fb
, m
);
476 mutex_lock(&dev
->mode_config
.fb_lock
);
477 list_for_each_entry(fb
, &dev
->mode_config
.fb_list
, head
) {
481 seq_printf(m
, "user ");
482 msm_framebuffer_describe(fb
, m
);
484 mutex_unlock(&dev
->mode_config
.fb_lock
);
489 static int show_locked(struct seq_file
*m
, void *arg
)
491 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
492 struct drm_device
*dev
= node
->minor
->dev
;
493 int (*show
)(struct drm_device
*dev
, struct seq_file
*m
) =
494 node
->info_ent
->data
;
497 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
503 mutex_unlock(&dev
->struct_mutex
);
508 static struct drm_info_list msm_debugfs_list
[] = {
509 {"gpu", show_locked
, 0, msm_gpu_show
},
510 {"gem", show_locked
, 0, msm_gem_show
},
511 { "mm", show_locked
, 0, msm_mm_show
},
512 { "fb", show_locked
, 0, msm_fb_show
},
515 static int late_init_minor(struct drm_minor
*minor
)
522 ret
= msm_rd_debugfs_init(minor
);
524 dev_err(minor
->dev
->dev
, "could not install rd debugfs\n");
528 ret
= msm_perf_debugfs_init(minor
);
530 dev_err(minor
->dev
->dev
, "could not install perf debugfs\n");
537 int msm_debugfs_late_init(struct drm_device
*dev
)
540 ret
= late_init_minor(dev
->primary
);
543 ret
= late_init_minor(dev
->render
);
546 ret
= late_init_minor(dev
->control
);
550 static int msm_debugfs_init(struct drm_minor
*minor
)
552 struct drm_device
*dev
= minor
->dev
;
555 ret
= drm_debugfs_create_files(msm_debugfs_list
,
556 ARRAY_SIZE(msm_debugfs_list
),
557 minor
->debugfs_root
, minor
);
560 dev_err(dev
->dev
, "could not install msm_debugfs_list\n");
567 static void msm_debugfs_cleanup(struct drm_minor
*minor
)
569 drm_debugfs_remove_files(msm_debugfs_list
,
570 ARRAY_SIZE(msm_debugfs_list
), minor
);
571 if (!minor
->dev
->dev_private
)
573 msm_rd_debugfs_cleanup(minor
);
574 msm_perf_debugfs_cleanup(minor
);
582 int msm_wait_fence_interruptable(struct drm_device
*dev
, uint32_t fence
,
583 struct timespec
*timeout
)
585 struct msm_drm_private
*priv
= dev
->dev_private
;
591 if (fence
> priv
->gpu
->submitted_fence
) {
592 DRM_ERROR("waiting on invalid fence: %u (of %u)\n",
593 fence
, priv
->gpu
->submitted_fence
);
599 ret
= fence_completed(dev
, fence
) ? 0 : -EBUSY
;
601 unsigned long timeout_jiffies
= timespec_to_jiffies(timeout
);
602 unsigned long start_jiffies
= jiffies
;
603 unsigned long remaining_jiffies
;
605 if (time_after(start_jiffies
, timeout_jiffies
))
606 remaining_jiffies
= 0;
608 remaining_jiffies
= timeout_jiffies
- start_jiffies
;
610 ret
= wait_event_interruptible_timeout(priv
->fence_event
,
611 fence_completed(dev
, fence
),
615 DBG("timeout waiting for fence: %u (completed: %u)",
616 fence
, priv
->completed_fence
);
618 } else if (ret
!= -ERESTARTSYS
) {
626 int msm_queue_fence_cb(struct drm_device
*dev
,
627 struct msm_fence_cb
*cb
, uint32_t fence
)
629 struct msm_drm_private
*priv
= dev
->dev_private
;
632 mutex_lock(&dev
->struct_mutex
);
633 if (!list_empty(&cb
->work
.entry
)) {
635 } else if (fence
> priv
->completed_fence
) {
637 list_add_tail(&cb
->work
.entry
, &priv
->fence_cbs
);
639 queue_work(priv
->wq
, &cb
->work
);
641 mutex_unlock(&dev
->struct_mutex
);
646 /* called from workqueue */
647 void msm_update_fence(struct drm_device
*dev
, uint32_t fence
)
649 struct msm_drm_private
*priv
= dev
->dev_private
;
651 mutex_lock(&dev
->struct_mutex
);
652 priv
->completed_fence
= max(fence
, priv
->completed_fence
);
654 while (!list_empty(&priv
->fence_cbs
)) {
655 struct msm_fence_cb
*cb
;
657 cb
= list_first_entry(&priv
->fence_cbs
,
658 struct msm_fence_cb
, work
.entry
);
660 if (cb
->fence
> priv
->completed_fence
)
663 list_del_init(&cb
->work
.entry
);
664 queue_work(priv
->wq
, &cb
->work
);
667 mutex_unlock(&dev
->struct_mutex
);
669 wake_up_all(&priv
->fence_event
);
672 void __msm_fence_worker(struct work_struct
*work
)
674 struct msm_fence_cb
*cb
= container_of(work
, struct msm_fence_cb
, work
);
682 static int msm_ioctl_get_param(struct drm_device
*dev
, void *data
,
683 struct drm_file
*file
)
685 struct msm_drm_private
*priv
= dev
->dev_private
;
686 struct drm_msm_param
*args
= data
;
689 /* for now, we just have 3d pipe.. eventually this would need to
690 * be more clever to dispatch to appropriate gpu module:
692 if (args
->pipe
!= MSM_PIPE_3D0
)
700 return gpu
->funcs
->get_param(gpu
, args
->param
, &args
->value
);
703 static int msm_ioctl_gem_new(struct drm_device
*dev
, void *data
,
704 struct drm_file
*file
)
706 struct drm_msm_gem_new
*args
= data
;
708 if (args
->flags
& ~MSM_BO_FLAGS
) {
709 DRM_ERROR("invalid flags: %08x\n", args
->flags
);
713 return msm_gem_new_handle(dev
, file
, args
->size
,
714 args
->flags
, &args
->handle
);
717 #define TS(t) ((struct timespec){ .tv_sec = (t).tv_sec, .tv_nsec = (t).tv_nsec })
719 static int msm_ioctl_gem_cpu_prep(struct drm_device
*dev
, void *data
,
720 struct drm_file
*file
)
722 struct drm_msm_gem_cpu_prep
*args
= data
;
723 struct drm_gem_object
*obj
;
726 if (args
->op
& ~MSM_PREP_FLAGS
) {
727 DRM_ERROR("invalid op: %08x\n", args
->op
);
731 obj
= drm_gem_object_lookup(dev
, file
, args
->handle
);
735 ret
= msm_gem_cpu_prep(obj
, args
->op
, &TS(args
->timeout
));
737 drm_gem_object_unreference_unlocked(obj
);
742 static int msm_ioctl_gem_cpu_fini(struct drm_device
*dev
, void *data
,
743 struct drm_file
*file
)
745 struct drm_msm_gem_cpu_fini
*args
= data
;
746 struct drm_gem_object
*obj
;
749 obj
= drm_gem_object_lookup(dev
, file
, args
->handle
);
753 ret
= msm_gem_cpu_fini(obj
);
755 drm_gem_object_unreference_unlocked(obj
);
760 static int msm_ioctl_gem_info(struct drm_device
*dev
, void *data
,
761 struct drm_file
*file
)
763 struct drm_msm_gem_info
*args
= data
;
764 struct drm_gem_object
*obj
;
770 obj
= drm_gem_object_lookup(dev
, file
, args
->handle
);
774 args
->offset
= msm_gem_mmap_offset(obj
);
776 drm_gem_object_unreference_unlocked(obj
);
781 static int msm_ioctl_wait_fence(struct drm_device
*dev
, void *data
,
782 struct drm_file
*file
)
784 struct drm_msm_wait_fence
*args
= data
;
787 DRM_ERROR("invalid pad: %08x\n", args
->pad
);
791 return msm_wait_fence_interruptable(dev
, args
->fence
,
795 static const struct drm_ioctl_desc msm_ioctls
[] = {
796 DRM_IOCTL_DEF_DRV(MSM_GET_PARAM
, msm_ioctl_get_param
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
797 DRM_IOCTL_DEF_DRV(MSM_GEM_NEW
, msm_ioctl_gem_new
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
798 DRM_IOCTL_DEF_DRV(MSM_GEM_INFO
, msm_ioctl_gem_info
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
799 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP
, msm_ioctl_gem_cpu_prep
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
800 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI
, msm_ioctl_gem_cpu_fini
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
801 DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT
, msm_ioctl_gem_submit
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
802 DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE
, msm_ioctl_wait_fence
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
805 static const struct vm_operations_struct vm_ops
= {
806 .fault
= msm_gem_fault
,
807 .open
= drm_gem_vm_open
,
808 .close
= drm_gem_vm_close
,
811 static const struct file_operations fops
= {
812 .owner
= THIS_MODULE
,
814 .release
= drm_release
,
815 .unlocked_ioctl
= drm_ioctl
,
817 .compat_ioctl
= drm_compat_ioctl
,
822 .mmap
= msm_gem_mmap
,
825 static struct drm_driver msm_driver
= {
826 .driver_features
= DRIVER_HAVE_IRQ
|
832 .unload
= msm_unload
,
834 .preclose
= msm_preclose
,
835 .lastclose
= msm_lastclose
,
836 .set_busid
= drm_platform_set_busid
,
837 .irq_handler
= msm_irq
,
838 .irq_preinstall
= msm_irq_preinstall
,
839 .irq_postinstall
= msm_irq_postinstall
,
840 .irq_uninstall
= msm_irq_uninstall
,
841 .get_vblank_counter
= drm_vblank_count
,
842 .enable_vblank
= msm_enable_vblank
,
843 .disable_vblank
= msm_disable_vblank
,
844 .gem_free_object
= msm_gem_free_object
,
845 .gem_vm_ops
= &vm_ops
,
846 .dumb_create
= msm_gem_dumb_create
,
847 .dumb_map_offset
= msm_gem_dumb_map_offset
,
848 .dumb_destroy
= drm_gem_dumb_destroy
,
849 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
850 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
851 .gem_prime_export
= drm_gem_prime_export
,
852 .gem_prime_import
= drm_gem_prime_import
,
853 .gem_prime_pin
= msm_gem_prime_pin
,
854 .gem_prime_unpin
= msm_gem_prime_unpin
,
855 .gem_prime_get_sg_table
= msm_gem_prime_get_sg_table
,
856 .gem_prime_import_sg_table
= msm_gem_prime_import_sg_table
,
857 .gem_prime_vmap
= msm_gem_prime_vmap
,
858 .gem_prime_vunmap
= msm_gem_prime_vunmap
,
859 .gem_prime_mmap
= msm_gem_prime_mmap
,
860 #ifdef CONFIG_DEBUG_FS
861 .debugfs_init
= msm_debugfs_init
,
862 .debugfs_cleanup
= msm_debugfs_cleanup
,
864 .ioctls
= msm_ioctls
,
865 .num_ioctls
= DRM_MSM_NUM_IOCTLS
,
868 .desc
= "MSM Snapdragon DRM",
874 #ifdef CONFIG_PM_SLEEP
875 static int msm_pm_suspend(struct device
*dev
)
877 struct drm_device
*ddev
= dev_get_drvdata(dev
);
879 drm_kms_helper_poll_disable(ddev
);
884 static int msm_pm_resume(struct device
*dev
)
886 struct drm_device
*ddev
= dev_get_drvdata(dev
);
888 drm_kms_helper_poll_enable(ddev
);
894 static const struct dev_pm_ops msm_pm_ops
= {
895 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend
, msm_pm_resume
)
899 * Componentized driver support:
903 /* NOTE: the CONFIG_OF case duplicates the same code as exynos or imx
904 * (or probably any other).. so probably some room for some helpers
906 static int compare_of(struct device
*dev
, void *data
)
908 return dev
->of_node
== data
;
911 static int add_components(struct device
*dev
, struct component_match
**matchptr
,
914 struct device_node
*np
= dev
->of_node
;
918 struct device_node
*node
;
920 node
= of_parse_phandle(np
, name
, i
);
924 component_match_add(dev
, matchptr
, compare_of
, node
);
930 static int compare_dev(struct device
*dev
, void *data
)
936 static int msm_drm_bind(struct device
*dev
)
938 return drm_platform_init(&msm_driver
, to_platform_device(dev
));
941 static void msm_drm_unbind(struct device
*dev
)
943 drm_put_dev(platform_get_drvdata(to_platform_device(dev
)));
946 static const struct component_master_ops msm_drm_ops
= {
947 .bind
= msm_drm_bind
,
948 .unbind
= msm_drm_unbind
,
955 static int msm_pdev_probe(struct platform_device
*pdev
)
957 struct component_match
*match
= NULL
;
959 add_components(&pdev
->dev
, &match
, "connectors");
960 add_components(&pdev
->dev
, &match
, "gpus");
962 /* For non-DT case, it kinda sucks. We don't actually have a way
963 * to know whether or not we are waiting for certain devices (or if
964 * they are simply not present). But for non-DT we only need to
965 * care about apq8064/apq8060/etc (all mdp4/a3xx):
967 static const char *devnames
[] = {
968 "hdmi_msm.0", "kgsl-3d0.0",
972 DBG("Adding components..");
974 for (i
= 0; i
< ARRAY_SIZE(devnames
); i
++) {
977 dev
= bus_find_device_by_name(&platform_bus_type
,
980 dev_info(&pdev
->dev
, "still waiting for %s\n", devnames
[i
]);
981 return -EPROBE_DEFER
;
984 component_match_add(&pdev
->dev
, &match
, compare_dev
, dev
);
988 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
989 return component_master_add_with_match(&pdev
->dev
, &msm_drm_ops
, match
);
992 static int msm_pdev_remove(struct platform_device
*pdev
)
994 component_master_del(&pdev
->dev
, &msm_drm_ops
);
999 static const struct platform_device_id msm_id
[] = {
1004 static const struct of_device_id dt_match
[] = {
1005 { .compatible
= "qcom,mdp" }, /* mdp4 */
1006 { .compatible
= "qcom,mdss_mdp" }, /* mdp5 */
1009 MODULE_DEVICE_TABLE(of
, dt_match
);
1011 static struct platform_driver msm_platform_driver
= {
1012 .probe
= msm_pdev_probe
,
1013 .remove
= msm_pdev_remove
,
1016 .of_match_table
= dt_match
,
1022 static int __init
msm_drm_register(void)
1027 return platform_driver_register(&msm_platform_driver
);
1030 static void __exit
msm_drm_unregister(void)
1033 platform_driver_unregister(&msm_platform_driver
);
1035 adreno_unregister();
1038 module_init(msm_drm_register
);
1039 module_exit(msm_drm_unregister
);
1041 MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
1042 MODULE_DESCRIPTION("MSM DRM Driver");
1043 MODULE_LICENSE("GPL");