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
= msm_atomic_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 #ifdef CONFIG_DRM_MSM_FBDEV
58 static bool fbdev
= true;
59 MODULE_PARM_DESC(fbdev
, "Enable fbdev compat layer");
60 module_param(fbdev
, bool, 0600);
63 static char *vram
= "16m";
64 MODULE_PARM_DESC(vram
, "Configure VRAM size (for devices without IOMMU/GPUMMU");
65 module_param(vram
, charp
, 0);
71 void __iomem
*msm_ioremap(struct platform_device
*pdev
, const char *name
,
79 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, name
);
81 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
84 dev_err(&pdev
->dev
, "failed to get memory resource: %s\n", name
);
85 return ERR_PTR(-EINVAL
);
88 size
= resource_size(res
);
90 ptr
= devm_ioremap_nocache(&pdev
->dev
, res
->start
, size
);
92 dev_err(&pdev
->dev
, "failed to ioremap: %s\n", name
);
93 return ERR_PTR(-ENOMEM
);
97 printk(KERN_DEBUG
"IO:region %s %08x %08lx\n", dbgname
, (u32
)ptr
, size
);
102 void msm_writel(u32 data
, void __iomem
*addr
)
105 printk(KERN_DEBUG
"IO:W %08x %08x\n", (u32
)addr
, data
);
109 u32
msm_readl(const void __iomem
*addr
)
111 u32 val
= readl(addr
);
113 printk(KERN_ERR
"IO:R %08x %08x\n", (u32
)addr
, val
);
121 static int msm_unload(struct drm_device
*dev
)
123 struct msm_drm_private
*priv
= dev
->dev_private
;
124 struct msm_kms
*kms
= priv
->kms
;
125 struct msm_gpu
*gpu
= priv
->gpu
;
127 drm_kms_helper_poll_fini(dev
);
128 drm_mode_config_cleanup(dev
);
129 drm_vblank_cleanup(dev
);
131 pm_runtime_get_sync(dev
->dev
);
132 drm_irq_uninstall(dev
);
133 pm_runtime_put_sync(dev
->dev
);
135 flush_workqueue(priv
->wq
);
136 destroy_workqueue(priv
->wq
);
139 pm_runtime_disable(dev
->dev
);
140 kms
->funcs
->destroy(kms
);
144 mutex_lock(&dev
->struct_mutex
);
145 gpu
->funcs
->pm_suspend(gpu
);
146 gpu
->funcs
->destroy(gpu
);
147 mutex_unlock(&dev
->struct_mutex
);
150 if (priv
->vram
.paddr
) {
151 DEFINE_DMA_ATTRS(attrs
);
152 dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING
, &attrs
);
153 drm_mm_takedown(&priv
->vram
.mm
);
154 dma_free_attrs(dev
->dev
, priv
->vram
.size
, NULL
,
155 priv
->vram
.paddr
, &attrs
);
158 component_unbind_all(dev
->dev
, dev
);
160 dev
->dev_private
= NULL
;
167 static int get_mdp_ver(struct platform_device
*pdev
)
170 static const struct of_device_id match_types
[] = { {
171 .compatible
= "qcom,mdss_mdp",
176 struct device
*dev
= &pdev
->dev
;
177 const struct of_device_id
*match
;
178 match
= of_match_node(match_types
, dev
->of_node
);
180 return (int)match
->data
;
185 #include <linux/of_address.h>
187 static int msm_init_vram(struct drm_device
*dev
)
189 struct msm_drm_private
*priv
= dev
->dev_private
;
190 unsigned long size
= 0;
194 /* In the device-tree world, we could have a 'memory-region'
195 * phandle, which gives us a link to our "vram". Allocating
196 * is all nicely abstracted behind the dma api, but we need
197 * to know the entire size to allocate it all in one go. There
199 * 1) device with no IOMMU, in which case we need exclusive
200 * access to a VRAM carveout big enough for all gpu
202 * 2) device with IOMMU, but where the bootloader puts up
203 * a splash screen. In this case, the VRAM carveout
204 * need only be large enough for fbdev fb. But we need
205 * exclusive access to the buffer to avoid the kernel
206 * using those pages for other purposes (which appears
207 * as corruption on screen before we have a chance to
208 * load and do initial modeset)
210 struct device_node
*node
;
212 node
= of_parse_phandle(dev
->dev
->of_node
, "memory-region", 0);
215 ret
= of_address_to_resource(node
, 0, &r
);
218 size
= r
.end
- r
.start
;
219 DRM_INFO("using VRAM carveout: %lx@%08x\n", size
, r
.start
);
223 /* if we have no IOMMU, then we need to use carveout allocator.
224 * Grab the entire CMA chunk carved out in early startup in
227 if (!iommu_present(&platform_bus_type
)) {
228 DRM_INFO("using %s VRAM carveout\n", vram
);
229 size
= memparse(vram
, NULL
);
233 DEFINE_DMA_ATTRS(attrs
);
236 priv
->vram
.size
= size
;
238 drm_mm_init(&priv
->vram
.mm
, 0, (size
>> PAGE_SHIFT
) - 1);
240 dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING
, &attrs
);
241 dma_set_attr(DMA_ATTR_WRITE_COMBINE
, &attrs
);
243 /* note that for no-kernel-mapping, the vaddr returned
244 * is bogus, but non-null if allocation succeeded:
246 p
= dma_alloc_attrs(dev
->dev
, size
,
247 &priv
->vram
.paddr
, GFP_KERNEL
, &attrs
);
249 dev_err(dev
->dev
, "failed to allocate VRAM\n");
250 priv
->vram
.paddr
= 0;
254 dev_info(dev
->dev
, "VRAM: %08x->%08x\n",
255 (uint32_t)priv
->vram
.paddr
,
256 (uint32_t)(priv
->vram
.paddr
+ size
));
262 static int msm_load(struct drm_device
*dev
, unsigned long flags
)
264 struct platform_device
*pdev
= dev
->platformdev
;
265 struct msm_drm_private
*priv
;
269 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
271 dev_err(dev
->dev
, "failed to allocate private data\n");
275 dev
->dev_private
= priv
;
277 priv
->wq
= alloc_ordered_workqueue("msm", 0);
278 init_waitqueue_head(&priv
->fence_event
);
279 init_waitqueue_head(&priv
->pending_crtcs_event
);
281 INIT_LIST_HEAD(&priv
->inactive_list
);
282 INIT_LIST_HEAD(&priv
->fence_cbs
);
284 drm_mode_config_init(dev
);
286 ret
= msm_init_vram(dev
);
290 platform_set_drvdata(pdev
, dev
);
292 /* Bind all our sub-components: */
293 ret
= component_bind_all(dev
->dev
, dev
);
297 switch (get_mdp_ver(pdev
)) {
299 kms
= mdp4_kms_init(dev
);
302 kms
= mdp5_kms_init(dev
);
305 kms
= ERR_PTR(-ENODEV
);
311 * NOTE: once we have GPU support, having no kms should not
312 * be considered fatal.. ideally we would still support gpu
313 * and (for example) use dmabuf/prime to share buffers with
314 * imx drm driver on iMX5
316 dev_err(dev
->dev
, "failed to load kms\n");
324 pm_runtime_enable(dev
->dev
);
325 ret
= kms
->funcs
->hw_init(kms
);
327 dev_err(dev
->dev
, "kms hw init failed: %d\n", ret
);
332 dev
->mode_config
.min_width
= 0;
333 dev
->mode_config
.min_height
= 0;
334 dev
->mode_config
.max_width
= 2048;
335 dev
->mode_config
.max_height
= 2048;
336 dev
->mode_config
.funcs
= &mode_config_funcs
;
338 ret
= drm_vblank_init(dev
, priv
->num_crtcs
);
340 dev_err(dev
->dev
, "failed to initialize vblank\n");
344 pm_runtime_get_sync(dev
->dev
);
345 ret
= drm_irq_install(dev
, platform_get_irq(dev
->platformdev
, 0));
346 pm_runtime_put_sync(dev
->dev
);
348 dev_err(dev
->dev
, "failed to install IRQ handler\n");
352 drm_mode_config_reset(dev
);
354 #ifdef CONFIG_DRM_MSM_FBDEV
356 priv
->fbdev
= msm_fbdev_init(dev
);
359 ret
= msm_debugfs_late_init(dev
);
363 drm_kms_helper_poll_init(dev
);
372 static void load_gpu(struct drm_device
*dev
)
374 static DEFINE_MUTEX(init_lock
);
375 struct msm_drm_private
*priv
= dev
->dev_private
;
377 mutex_lock(&init_lock
);
380 priv
->gpu
= adreno_load_gpu(dev
);
382 mutex_unlock(&init_lock
);
385 static int msm_open(struct drm_device
*dev
, struct drm_file
*file
)
387 struct msm_file_private
*ctx
;
389 /* For now, load gpu on open.. to avoid the requirement of having
390 * firmware in the initrd.
394 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
398 file
->driver_priv
= ctx
;
403 static void msm_preclose(struct drm_device
*dev
, struct drm_file
*file
)
405 struct msm_drm_private
*priv
= dev
->dev_private
;
406 struct msm_file_private
*ctx
= file
->driver_priv
;
407 struct msm_kms
*kms
= priv
->kms
;
410 kms
->funcs
->preclose(kms
, file
);
412 mutex_lock(&dev
->struct_mutex
);
413 if (ctx
== priv
->lastctx
)
414 priv
->lastctx
= NULL
;
415 mutex_unlock(&dev
->struct_mutex
);
420 static void msm_lastclose(struct drm_device
*dev
)
422 struct msm_drm_private
*priv
= dev
->dev_private
;
424 drm_fb_helper_restore_fbdev_mode_unlocked(priv
->fbdev
);
427 static irqreturn_t
msm_irq(int irq
, void *arg
)
429 struct drm_device
*dev
= arg
;
430 struct msm_drm_private
*priv
= dev
->dev_private
;
431 struct msm_kms
*kms
= priv
->kms
;
433 return kms
->funcs
->irq(kms
);
436 static void msm_irq_preinstall(struct drm_device
*dev
)
438 struct msm_drm_private
*priv
= dev
->dev_private
;
439 struct msm_kms
*kms
= priv
->kms
;
441 kms
->funcs
->irq_preinstall(kms
);
444 static int msm_irq_postinstall(struct drm_device
*dev
)
446 struct msm_drm_private
*priv
= dev
->dev_private
;
447 struct msm_kms
*kms
= priv
->kms
;
449 return kms
->funcs
->irq_postinstall(kms
);
452 static void msm_irq_uninstall(struct drm_device
*dev
)
454 struct msm_drm_private
*priv
= dev
->dev_private
;
455 struct msm_kms
*kms
= priv
->kms
;
457 kms
->funcs
->irq_uninstall(kms
);
460 static int msm_enable_vblank(struct drm_device
*dev
, int crtc_id
)
462 struct msm_drm_private
*priv
= dev
->dev_private
;
463 struct msm_kms
*kms
= priv
->kms
;
466 DBG("dev=%p, crtc=%d", dev
, crtc_id
);
467 return kms
->funcs
->enable_vblank(kms
, priv
->crtcs
[crtc_id
]);
470 static void msm_disable_vblank(struct drm_device
*dev
, int crtc_id
)
472 struct msm_drm_private
*priv
= dev
->dev_private
;
473 struct msm_kms
*kms
= priv
->kms
;
476 DBG("dev=%p, crtc=%d", dev
, crtc_id
);
477 kms
->funcs
->disable_vblank(kms
, priv
->crtcs
[crtc_id
]);
484 #ifdef CONFIG_DEBUG_FS
485 static int msm_gpu_show(struct drm_device
*dev
, struct seq_file
*m
)
487 struct msm_drm_private
*priv
= dev
->dev_private
;
488 struct msm_gpu
*gpu
= priv
->gpu
;
491 seq_printf(m
, "%s Status:\n", gpu
->name
);
492 gpu
->funcs
->show(gpu
, m
);
498 static int msm_gem_show(struct drm_device
*dev
, struct seq_file
*m
)
500 struct msm_drm_private
*priv
= dev
->dev_private
;
501 struct msm_gpu
*gpu
= priv
->gpu
;
504 seq_printf(m
, "Active Objects (%s):\n", gpu
->name
);
505 msm_gem_describe_objects(&gpu
->active_list
, m
);
508 seq_printf(m
, "Inactive Objects:\n");
509 msm_gem_describe_objects(&priv
->inactive_list
, m
);
514 static int msm_mm_show(struct drm_device
*dev
, struct seq_file
*m
)
516 return drm_mm_dump_table(m
, &dev
->vma_offset_manager
->vm_addr_space_mm
);
519 static int msm_fb_show(struct drm_device
*dev
, struct seq_file
*m
)
521 struct msm_drm_private
*priv
= dev
->dev_private
;
522 struct drm_framebuffer
*fb
, *fbdev_fb
= NULL
;
525 seq_printf(m
, "fbcon ");
526 fbdev_fb
= priv
->fbdev
->fb
;
527 msm_framebuffer_describe(fbdev_fb
, m
);
530 mutex_lock(&dev
->mode_config
.fb_lock
);
531 list_for_each_entry(fb
, &dev
->mode_config
.fb_list
, head
) {
535 seq_printf(m
, "user ");
536 msm_framebuffer_describe(fb
, m
);
538 mutex_unlock(&dev
->mode_config
.fb_lock
);
543 static int show_locked(struct seq_file
*m
, void *arg
)
545 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
546 struct drm_device
*dev
= node
->minor
->dev
;
547 int (*show
)(struct drm_device
*dev
, struct seq_file
*m
) =
548 node
->info_ent
->data
;
551 ret
= mutex_lock_interruptible(&dev
->struct_mutex
);
557 mutex_unlock(&dev
->struct_mutex
);
562 static struct drm_info_list msm_debugfs_list
[] = {
563 {"gpu", show_locked
, 0, msm_gpu_show
},
564 {"gem", show_locked
, 0, msm_gem_show
},
565 { "mm", show_locked
, 0, msm_mm_show
},
566 { "fb", show_locked
, 0, msm_fb_show
},
569 static int late_init_minor(struct drm_minor
*minor
)
576 ret
= msm_rd_debugfs_init(minor
);
578 dev_err(minor
->dev
->dev
, "could not install rd debugfs\n");
582 ret
= msm_perf_debugfs_init(minor
);
584 dev_err(minor
->dev
->dev
, "could not install perf debugfs\n");
591 int msm_debugfs_late_init(struct drm_device
*dev
)
594 ret
= late_init_minor(dev
->primary
);
597 ret
= late_init_minor(dev
->render
);
600 ret
= late_init_minor(dev
->control
);
604 static int msm_debugfs_init(struct drm_minor
*minor
)
606 struct drm_device
*dev
= minor
->dev
;
609 ret
= drm_debugfs_create_files(msm_debugfs_list
,
610 ARRAY_SIZE(msm_debugfs_list
),
611 minor
->debugfs_root
, minor
);
614 dev_err(dev
->dev
, "could not install msm_debugfs_list\n");
621 static void msm_debugfs_cleanup(struct drm_minor
*minor
)
623 drm_debugfs_remove_files(msm_debugfs_list
,
624 ARRAY_SIZE(msm_debugfs_list
), minor
);
625 if (!minor
->dev
->dev_private
)
627 msm_rd_debugfs_cleanup(minor
);
628 msm_perf_debugfs_cleanup(minor
);
636 int msm_wait_fence_interruptable(struct drm_device
*dev
, uint32_t fence
,
637 struct timespec
*timeout
)
639 struct msm_drm_private
*priv
= dev
->dev_private
;
645 if (fence
> priv
->gpu
->submitted_fence
) {
646 DRM_ERROR("waiting on invalid fence: %u (of %u)\n",
647 fence
, priv
->gpu
->submitted_fence
);
653 ret
= fence_completed(dev
, fence
) ? 0 : -EBUSY
;
655 unsigned long timeout_jiffies
= timespec_to_jiffies(timeout
);
656 unsigned long start_jiffies
= jiffies
;
657 unsigned long remaining_jiffies
;
659 if (time_after(start_jiffies
, timeout_jiffies
))
660 remaining_jiffies
= 0;
662 remaining_jiffies
= timeout_jiffies
- start_jiffies
;
664 ret
= wait_event_interruptible_timeout(priv
->fence_event
,
665 fence_completed(dev
, fence
),
669 DBG("timeout waiting for fence: %u (completed: %u)",
670 fence
, priv
->completed_fence
);
672 } else if (ret
!= -ERESTARTSYS
) {
680 int msm_queue_fence_cb(struct drm_device
*dev
,
681 struct msm_fence_cb
*cb
, uint32_t fence
)
683 struct msm_drm_private
*priv
= dev
->dev_private
;
686 mutex_lock(&dev
->struct_mutex
);
687 if (!list_empty(&cb
->work
.entry
)) {
689 } else if (fence
> priv
->completed_fence
) {
691 list_add_tail(&cb
->work
.entry
, &priv
->fence_cbs
);
693 queue_work(priv
->wq
, &cb
->work
);
695 mutex_unlock(&dev
->struct_mutex
);
700 /* called from workqueue */
701 void msm_update_fence(struct drm_device
*dev
, uint32_t fence
)
703 struct msm_drm_private
*priv
= dev
->dev_private
;
705 mutex_lock(&dev
->struct_mutex
);
706 priv
->completed_fence
= max(fence
, priv
->completed_fence
);
708 while (!list_empty(&priv
->fence_cbs
)) {
709 struct msm_fence_cb
*cb
;
711 cb
= list_first_entry(&priv
->fence_cbs
,
712 struct msm_fence_cb
, work
.entry
);
714 if (cb
->fence
> priv
->completed_fence
)
717 list_del_init(&cb
->work
.entry
);
718 queue_work(priv
->wq
, &cb
->work
);
721 mutex_unlock(&dev
->struct_mutex
);
723 wake_up_all(&priv
->fence_event
);
726 void __msm_fence_worker(struct work_struct
*work
)
728 struct msm_fence_cb
*cb
= container_of(work
, struct msm_fence_cb
, work
);
736 static int msm_ioctl_get_param(struct drm_device
*dev
, void *data
,
737 struct drm_file
*file
)
739 struct msm_drm_private
*priv
= dev
->dev_private
;
740 struct drm_msm_param
*args
= data
;
743 /* for now, we just have 3d pipe.. eventually this would need to
744 * be more clever to dispatch to appropriate gpu module:
746 if (args
->pipe
!= MSM_PIPE_3D0
)
754 return gpu
->funcs
->get_param(gpu
, args
->param
, &args
->value
);
757 static int msm_ioctl_gem_new(struct drm_device
*dev
, void *data
,
758 struct drm_file
*file
)
760 struct drm_msm_gem_new
*args
= data
;
762 if (args
->flags
& ~MSM_BO_FLAGS
) {
763 DRM_ERROR("invalid flags: %08x\n", args
->flags
);
767 return msm_gem_new_handle(dev
, file
, args
->size
,
768 args
->flags
, &args
->handle
);
771 #define TS(t) ((struct timespec){ .tv_sec = (t).tv_sec, .tv_nsec = (t).tv_nsec })
773 static int msm_ioctl_gem_cpu_prep(struct drm_device
*dev
, void *data
,
774 struct drm_file
*file
)
776 struct drm_msm_gem_cpu_prep
*args
= data
;
777 struct drm_gem_object
*obj
;
780 if (args
->op
& ~MSM_PREP_FLAGS
) {
781 DRM_ERROR("invalid op: %08x\n", args
->op
);
785 obj
= drm_gem_object_lookup(dev
, file
, args
->handle
);
789 ret
= msm_gem_cpu_prep(obj
, args
->op
, &TS(args
->timeout
));
791 drm_gem_object_unreference_unlocked(obj
);
796 static int msm_ioctl_gem_cpu_fini(struct drm_device
*dev
, void *data
,
797 struct drm_file
*file
)
799 struct drm_msm_gem_cpu_fini
*args
= data
;
800 struct drm_gem_object
*obj
;
803 obj
= drm_gem_object_lookup(dev
, file
, args
->handle
);
807 ret
= msm_gem_cpu_fini(obj
);
809 drm_gem_object_unreference_unlocked(obj
);
814 static int msm_ioctl_gem_info(struct drm_device
*dev
, void *data
,
815 struct drm_file
*file
)
817 struct drm_msm_gem_info
*args
= data
;
818 struct drm_gem_object
*obj
;
824 obj
= drm_gem_object_lookup(dev
, file
, args
->handle
);
828 args
->offset
= msm_gem_mmap_offset(obj
);
830 drm_gem_object_unreference_unlocked(obj
);
835 static int msm_ioctl_wait_fence(struct drm_device
*dev
, void *data
,
836 struct drm_file
*file
)
838 struct drm_msm_wait_fence
*args
= data
;
841 DRM_ERROR("invalid pad: %08x\n", args
->pad
);
845 return msm_wait_fence_interruptable(dev
, args
->fence
,
849 static const struct drm_ioctl_desc msm_ioctls
[] = {
850 DRM_IOCTL_DEF_DRV(MSM_GET_PARAM
, msm_ioctl_get_param
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
851 DRM_IOCTL_DEF_DRV(MSM_GEM_NEW
, msm_ioctl_gem_new
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
852 DRM_IOCTL_DEF_DRV(MSM_GEM_INFO
, msm_ioctl_gem_info
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
853 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP
, msm_ioctl_gem_cpu_prep
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
854 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI
, msm_ioctl_gem_cpu_fini
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
855 DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT
, msm_ioctl_gem_submit
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
856 DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE
, msm_ioctl_wait_fence
, DRM_UNLOCKED
|DRM_AUTH
|DRM_RENDER_ALLOW
),
859 static const struct vm_operations_struct vm_ops
= {
860 .fault
= msm_gem_fault
,
861 .open
= drm_gem_vm_open
,
862 .close
= drm_gem_vm_close
,
865 static const struct file_operations fops
= {
866 .owner
= THIS_MODULE
,
868 .release
= drm_release
,
869 .unlocked_ioctl
= drm_ioctl
,
871 .compat_ioctl
= drm_compat_ioctl
,
876 .mmap
= msm_gem_mmap
,
879 static struct drm_driver msm_driver
= {
880 .driver_features
= DRIVER_HAVE_IRQ
|
886 .unload
= msm_unload
,
888 .preclose
= msm_preclose
,
889 .lastclose
= msm_lastclose
,
890 .set_busid
= drm_platform_set_busid
,
891 .irq_handler
= msm_irq
,
892 .irq_preinstall
= msm_irq_preinstall
,
893 .irq_postinstall
= msm_irq_postinstall
,
894 .irq_uninstall
= msm_irq_uninstall
,
895 .get_vblank_counter
= drm_vblank_count
,
896 .enable_vblank
= msm_enable_vblank
,
897 .disable_vblank
= msm_disable_vblank
,
898 .gem_free_object
= msm_gem_free_object
,
899 .gem_vm_ops
= &vm_ops
,
900 .dumb_create
= msm_gem_dumb_create
,
901 .dumb_map_offset
= msm_gem_dumb_map_offset
,
902 .dumb_destroy
= drm_gem_dumb_destroy
,
903 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
904 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
905 .gem_prime_export
= drm_gem_prime_export
,
906 .gem_prime_import
= drm_gem_prime_import
,
907 .gem_prime_pin
= msm_gem_prime_pin
,
908 .gem_prime_unpin
= msm_gem_prime_unpin
,
909 .gem_prime_get_sg_table
= msm_gem_prime_get_sg_table
,
910 .gem_prime_import_sg_table
= msm_gem_prime_import_sg_table
,
911 .gem_prime_vmap
= msm_gem_prime_vmap
,
912 .gem_prime_vunmap
= msm_gem_prime_vunmap
,
913 .gem_prime_mmap
= msm_gem_prime_mmap
,
914 #ifdef CONFIG_DEBUG_FS
915 .debugfs_init
= msm_debugfs_init
,
916 .debugfs_cleanup
= msm_debugfs_cleanup
,
918 .ioctls
= msm_ioctls
,
919 .num_ioctls
= DRM_MSM_NUM_IOCTLS
,
922 .desc
= "MSM Snapdragon DRM",
928 #ifdef CONFIG_PM_SLEEP
929 static int msm_pm_suspend(struct device
*dev
)
931 struct drm_device
*ddev
= dev_get_drvdata(dev
);
933 drm_kms_helper_poll_disable(ddev
);
938 static int msm_pm_resume(struct device
*dev
)
940 struct drm_device
*ddev
= dev_get_drvdata(dev
);
942 drm_kms_helper_poll_enable(ddev
);
948 static const struct dev_pm_ops msm_pm_ops
= {
949 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend
, msm_pm_resume
)
953 * Componentized driver support:
957 /* NOTE: the CONFIG_OF case duplicates the same code as exynos or imx
958 * (or probably any other).. so probably some room for some helpers
960 static int compare_of(struct device
*dev
, void *data
)
962 return dev
->of_node
== data
;
965 static int add_components(struct device
*dev
, struct component_match
**matchptr
,
968 struct device_node
*np
= dev
->of_node
;
972 struct device_node
*node
;
974 node
= of_parse_phandle(np
, name
, i
);
978 component_match_add(dev
, matchptr
, compare_of
, node
);
984 static int compare_dev(struct device
*dev
, void *data
)
990 static int msm_drm_bind(struct device
*dev
)
992 return drm_platform_init(&msm_driver
, to_platform_device(dev
));
995 static void msm_drm_unbind(struct device
*dev
)
997 drm_put_dev(platform_get_drvdata(to_platform_device(dev
)));
1000 static const struct component_master_ops msm_drm_ops
= {
1001 .bind
= msm_drm_bind
,
1002 .unbind
= msm_drm_unbind
,
1009 static int msm_pdev_probe(struct platform_device
*pdev
)
1011 struct component_match
*match
= NULL
;
1013 add_components(&pdev
->dev
, &match
, "connectors");
1014 add_components(&pdev
->dev
, &match
, "gpus");
1016 /* For non-DT case, it kinda sucks. We don't actually have a way
1017 * to know whether or not we are waiting for certain devices (or if
1018 * they are simply not present). But for non-DT we only need to
1019 * care about apq8064/apq8060/etc (all mdp4/a3xx):
1021 static const char *devnames
[] = {
1022 "hdmi_msm.0", "kgsl-3d0.0",
1026 DBG("Adding components..");
1028 for (i
= 0; i
< ARRAY_SIZE(devnames
); i
++) {
1031 dev
= bus_find_device_by_name(&platform_bus_type
,
1034 dev_info(&pdev
->dev
, "still waiting for %s\n", devnames
[i
]);
1035 return -EPROBE_DEFER
;
1038 component_match_add(&pdev
->dev
, &match
, compare_dev
, dev
);
1042 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
1043 return component_master_add_with_match(&pdev
->dev
, &msm_drm_ops
, match
);
1046 static int msm_pdev_remove(struct platform_device
*pdev
)
1048 component_master_del(&pdev
->dev
, &msm_drm_ops
);
1053 static const struct platform_device_id msm_id
[] = {
1058 static const struct of_device_id dt_match
[] = {
1059 { .compatible
= "qcom,mdp" }, /* mdp4 */
1060 { .compatible
= "qcom,mdss_mdp" }, /* mdp5 */
1063 MODULE_DEVICE_TABLE(of
, dt_match
);
1065 static struct platform_driver msm_platform_driver
= {
1066 .probe
= msm_pdev_probe
,
1067 .remove
= msm_pdev_remove
,
1070 .of_match_table
= dt_match
,
1076 static int __init
msm_drm_register(void)
1083 return platform_driver_register(&msm_platform_driver
);
1086 static void __exit
msm_drm_unregister(void)
1089 platform_driver_unregister(&msm_platform_driver
);
1091 adreno_unregister();
1092 msm_edp_unregister();
1093 msm_dsi_unregister();
1096 module_init(msm_drm_register
);
1097 module_exit(msm_drm_unregister
);
1099 MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
1100 MODULE_DESCRIPTION("MSM DRM Driver");
1101 MODULE_LICENSE("GPL");