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_FBDEV_EMULATION
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 %p %08lx\n", dbgname, ptr, size);
102 void msm_writel(u32 data, void __iomem *addr)
105 printk(KERN_DEBUG "IO:W %p %08x\n", addr, data);
109 u32 msm_readl(const void __iomem *addr)
111 u32 val = readl(addr);
113 printk(KERN_ERR "IO:R %p %08x\n", addr, val);
117 struct vblank_event {
118 struct list_head node;
123 static void vblank_ctrl_worker(struct work_struct *work)
125 struct msm_vblank_ctrl *vbl_ctrl = container_of(work,
126 struct msm_vblank_ctrl, work);
127 struct msm_drm_private *priv = container_of(vbl_ctrl,
128 struct msm_drm_private, vblank_ctrl);
129 struct msm_kms *kms = priv->kms;
130 struct vblank_event *vbl_ev, *tmp;
133 spin_lock_irqsave(&vbl_ctrl->lock, flags);
134 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
135 list_del(&vbl_ev->node);
136 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
139 kms->funcs->enable_vblank(kms,
140 priv->crtcs[vbl_ev->crtc_id]);
142 kms->funcs->disable_vblank(kms,
143 priv->crtcs[vbl_ev->crtc_id]);
147 spin_lock_irqsave(&vbl_ctrl->lock, flags);
150 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
153 static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
154 int crtc_id, bool enable)
156 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
157 struct vblank_event *vbl_ev;
160 vbl_ev = kzalloc(sizeof(*vbl_ev), GFP_ATOMIC);
164 vbl_ev->crtc_id = crtc_id;
165 vbl_ev->enable = enable;
167 spin_lock_irqsave(&vbl_ctrl->lock, flags);
168 list_add_tail(&vbl_ev->node, &vbl_ctrl->event_list);
169 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
171 queue_work(priv->wq, &vbl_ctrl->work);
180 static int msm_unload(struct drm_device *dev)
182 struct msm_drm_private *priv = dev->dev_private;
183 struct msm_kms *kms = priv->kms;
184 struct msm_gpu *gpu = priv->gpu;
185 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
186 struct vblank_event *vbl_ev, *tmp;
188 /* We must cancel and cleanup any pending vblank enable/disable
189 * work before drm_irq_uninstall() to avoid work re-enabling an
190 * irq after uninstall has disabled it.
192 cancel_work_sync(&vbl_ctrl->work);
193 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
194 list_del(&vbl_ev->node);
198 drm_kms_helper_poll_fini(dev);
200 #ifdef CONFIG_DRM_FBDEV_EMULATION
201 if (fbdev && priv->fbdev)
204 drm_mode_config_cleanup(dev);
205 drm_vblank_cleanup(dev);
207 pm_runtime_get_sync(dev->dev);
208 drm_irq_uninstall(dev);
209 pm_runtime_put_sync(dev->dev);
211 flush_workqueue(priv->wq);
212 destroy_workqueue(priv->wq);
215 pm_runtime_disable(dev->dev);
216 kms->funcs->destroy(kms);
220 mutex_lock(&dev->struct_mutex);
221 gpu->funcs->pm_suspend(gpu);
222 mutex_unlock(&dev->struct_mutex);
223 gpu->funcs->destroy(gpu);
226 if (priv->vram.paddr) {
227 DEFINE_DMA_ATTRS(attrs);
228 dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs);
229 drm_mm_takedown(&priv->vram.mm);
230 dma_free_attrs(dev->dev, priv->vram.size, NULL,
231 priv->vram.paddr, &attrs);
234 component_unbind_all(dev->dev, dev);
236 dev->dev_private = NULL;
243 static int get_mdp_ver(struct platform_device *pdev)
245 struct device *dev = &pdev->dev;
247 return (int) (unsigned long) of_device_get_match_data(dev);
250 #include <linux/of_address.h>
252 static int msm_init_vram(struct drm_device *dev)
254 struct msm_drm_private *priv = dev->dev_private;
255 struct device_node *node;
256 unsigned long size = 0;
259 /* In the device-tree world, we could have a 'memory-region'
260 * phandle, which gives us a link to our "vram". Allocating
261 * is all nicely abstracted behind the dma api, but we need
262 * to know the entire size to allocate it all in one go. There
264 * 1) device with no IOMMU, in which case we need exclusive
265 * access to a VRAM carveout big enough for all gpu
267 * 2) device with IOMMU, but where the bootloader puts up
268 * a splash screen. In this case, the VRAM carveout
269 * need only be large enough for fbdev fb. But we need
270 * exclusive access to the buffer to avoid the kernel
271 * using those pages for other purposes (which appears
272 * as corruption on screen before we have a chance to
273 * load and do initial modeset)
276 node = of_parse_phandle(dev->dev->of_node, "memory-region", 0);
279 ret = of_address_to_resource(node, 0, &r);
282 size = r.end - r.start;
283 DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
285 /* if we have no IOMMU, then we need to use carveout allocator.
286 * Grab the entire CMA chunk carved out in early startup in
289 } else if (!iommu_present(&platform_bus_type)) {
290 DRM_INFO("using %s VRAM carveout\n", vram);
291 size = memparse(vram, NULL);
295 DEFINE_DMA_ATTRS(attrs);
298 priv->vram.size = size;
300 drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);
302 dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs);
303 dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
305 /* note that for no-kernel-mapping, the vaddr returned
306 * is bogus, but non-null if allocation succeeded:
308 p = dma_alloc_attrs(dev->dev, size,
309 &priv->vram.paddr, GFP_KERNEL, &attrs);
311 dev_err(dev->dev, "failed to allocate VRAM\n");
312 priv->vram.paddr = 0;
316 dev_info(dev->dev, "VRAM: %08x->%08x\n",
317 (uint32_t)priv->vram.paddr,
318 (uint32_t)(priv->vram.paddr + size));
324 static int msm_load(struct drm_device *dev, unsigned long flags)
326 struct platform_device *pdev = dev->platformdev;
327 struct msm_drm_private *priv;
331 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
333 dev_err(dev->dev, "failed to allocate private data\n");
337 dev->dev_private = priv;
339 priv->wq = alloc_ordered_workqueue("msm", 0);
340 init_waitqueue_head(&priv->fence_event);
341 init_waitqueue_head(&priv->pending_crtcs_event);
343 INIT_LIST_HEAD(&priv->inactive_list);
344 INIT_LIST_HEAD(&priv->fence_cbs);
345 INIT_LIST_HEAD(&priv->vblank_ctrl.event_list);
346 INIT_WORK(&priv->vblank_ctrl.work, vblank_ctrl_worker);
347 spin_lock_init(&priv->vblank_ctrl.lock);
349 drm_mode_config_init(dev);
351 platform_set_drvdata(pdev, dev);
353 /* Bind all our sub-components: */
354 ret = component_bind_all(dev->dev, dev);
358 ret = msm_init_vram(dev);
362 switch (get_mdp_ver(pdev)) {
364 kms = mdp4_kms_init(dev);
367 kms = mdp5_kms_init(dev);
370 kms = ERR_PTR(-ENODEV);
376 * NOTE: once we have GPU support, having no kms should not
377 * be considered fatal.. ideally we would still support gpu
378 * and (for example) use dmabuf/prime to share buffers with
379 * imx drm driver on iMX5
381 dev_err(dev->dev, "failed to load kms\n");
389 pm_runtime_enable(dev->dev);
390 ret = kms->funcs->hw_init(kms);
392 dev_err(dev->dev, "kms hw init failed: %d\n", ret);
397 dev->mode_config.funcs = &mode_config_funcs;
399 ret = drm_vblank_init(dev, priv->num_crtcs);
401 dev_err(dev->dev, "failed to initialize vblank\n");
405 pm_runtime_get_sync(dev->dev);
406 ret = drm_irq_install(dev, platform_get_irq(dev->platformdev, 0));
407 pm_runtime_put_sync(dev->dev);
409 dev_err(dev->dev, "failed to install IRQ handler\n");
413 drm_mode_config_reset(dev);
415 #ifdef CONFIG_DRM_FBDEV_EMULATION
417 priv->fbdev = msm_fbdev_init(dev);
420 ret = msm_debugfs_late_init(dev);
424 drm_kms_helper_poll_init(dev);
433 static void load_gpu(struct drm_device *dev)
435 static DEFINE_MUTEX(init_lock);
436 struct msm_drm_private *priv = dev->dev_private;
438 mutex_lock(&init_lock);
441 priv->gpu = adreno_load_gpu(dev);
443 mutex_unlock(&init_lock);
446 static int msm_open(struct drm_device *dev, struct drm_file *file)
448 struct msm_file_private *ctx;
450 /* For now, load gpu on open.. to avoid the requirement of having
451 * firmware in the initrd.
455 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
459 file->driver_priv = ctx;
464 static void msm_preclose(struct drm_device *dev, struct drm_file *file)
466 struct msm_drm_private *priv = dev->dev_private;
467 struct msm_file_private *ctx = file->driver_priv;
468 struct msm_kms *kms = priv->kms;
471 kms->funcs->preclose(kms, file);
473 mutex_lock(&dev->struct_mutex);
474 if (ctx == priv->lastctx)
475 priv->lastctx = NULL;
476 mutex_unlock(&dev->struct_mutex);
481 static void msm_lastclose(struct drm_device *dev)
483 struct msm_drm_private *priv = dev->dev_private;
485 drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev);
488 static irqreturn_t msm_irq(int irq, void *arg)
490 struct drm_device *dev = arg;
491 struct msm_drm_private *priv = dev->dev_private;
492 struct msm_kms *kms = priv->kms;
494 return kms->funcs->irq(kms);
497 static void msm_irq_preinstall(struct drm_device *dev)
499 struct msm_drm_private *priv = dev->dev_private;
500 struct msm_kms *kms = priv->kms;
502 kms->funcs->irq_preinstall(kms);
505 static int msm_irq_postinstall(struct drm_device *dev)
507 struct msm_drm_private *priv = dev->dev_private;
508 struct msm_kms *kms = priv->kms;
510 return kms->funcs->irq_postinstall(kms);
513 static void msm_irq_uninstall(struct drm_device *dev)
515 struct msm_drm_private *priv = dev->dev_private;
516 struct msm_kms *kms = priv->kms;
518 kms->funcs->irq_uninstall(kms);
521 static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
523 struct msm_drm_private *priv = dev->dev_private;
524 struct msm_kms *kms = priv->kms;
527 DBG("dev=%p, crtc=%u", dev, pipe);
528 return vblank_ctrl_queue_work(priv, pipe, true);
531 static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
533 struct msm_drm_private *priv = dev->dev_private;
534 struct msm_kms *kms = priv->kms;
537 DBG("dev=%p, crtc=%u", dev, pipe);
538 vblank_ctrl_queue_work(priv, pipe, false);
545 #ifdef CONFIG_DEBUG_FS
546 static int msm_gpu_show(struct drm_device *dev, struct seq_file *m)
548 struct msm_drm_private *priv = dev->dev_private;
549 struct msm_gpu *gpu = priv->gpu;
552 seq_printf(m, "%s Status:\n", gpu->name);
553 gpu->funcs->show(gpu, m);
559 static int msm_gem_show(struct drm_device *dev, struct seq_file *m)
561 struct msm_drm_private *priv = dev->dev_private;
562 struct msm_gpu *gpu = priv->gpu;
565 seq_printf(m, "Active Objects (%s):\n", gpu->name);
566 msm_gem_describe_objects(&gpu->active_list, m);
569 seq_printf(m, "Inactive Objects:\n");
570 msm_gem_describe_objects(&priv->inactive_list, m);
575 static int msm_mm_show(struct drm_device *dev, struct seq_file *m)
577 return drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm);
580 static int msm_fb_show(struct drm_device *dev, struct seq_file *m)
582 struct msm_drm_private *priv = dev->dev_private;
583 struct drm_framebuffer *fb, *fbdev_fb = NULL;
586 seq_printf(m, "fbcon ");
587 fbdev_fb = priv->fbdev->fb;
588 msm_framebuffer_describe(fbdev_fb, m);
591 mutex_lock(&dev->mode_config.fb_lock);
592 list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
596 seq_printf(m, "user ");
597 msm_framebuffer_describe(fb, m);
599 mutex_unlock(&dev->mode_config.fb_lock);
604 static int show_locked(struct seq_file *m, void *arg)
606 struct drm_info_node *node = (struct drm_info_node *) m->private;
607 struct drm_device *dev = node->minor->dev;
608 int (*show)(struct drm_device *dev, struct seq_file *m) =
609 node->info_ent->data;
612 ret = mutex_lock_interruptible(&dev->struct_mutex);
618 mutex_unlock(&dev->struct_mutex);
623 static struct drm_info_list msm_debugfs_list[] = {
624 {"gpu", show_locked, 0, msm_gpu_show},
625 {"gem", show_locked, 0, msm_gem_show},
626 { "mm", show_locked, 0, msm_mm_show },
627 { "fb", show_locked, 0, msm_fb_show },
630 static int late_init_minor(struct drm_minor *minor)
637 ret = msm_rd_debugfs_init(minor);
639 dev_err(minor->dev->dev, "could not install rd debugfs\n");
643 ret = msm_perf_debugfs_init(minor);
645 dev_err(minor->dev->dev, "could not install perf debugfs\n");
652 int msm_debugfs_late_init(struct drm_device *dev)
655 ret = late_init_minor(dev->primary);
658 ret = late_init_minor(dev->render);
661 ret = late_init_minor(dev->control);
665 static int msm_debugfs_init(struct drm_minor *minor)
667 struct drm_device *dev = minor->dev;
670 ret = drm_debugfs_create_files(msm_debugfs_list,
671 ARRAY_SIZE(msm_debugfs_list),
672 minor->debugfs_root, minor);
675 dev_err(dev->dev, "could not install msm_debugfs_list\n");
682 static void msm_debugfs_cleanup(struct drm_minor *minor)
684 drm_debugfs_remove_files(msm_debugfs_list,
685 ARRAY_SIZE(msm_debugfs_list), minor);
686 if (!minor->dev->dev_private)
688 msm_rd_debugfs_cleanup(minor);
689 msm_perf_debugfs_cleanup(minor);
697 int msm_wait_fence(struct drm_device *dev, uint32_t fence,
698 ktime_t *timeout , bool interruptible)
700 struct msm_drm_private *priv = dev->dev_private;
706 if (fence > priv->gpu->submitted_fence) {
707 DRM_ERROR("waiting on invalid fence: %u (of %u)\n",
708 fence, priv->gpu->submitted_fence);
714 ret = fence_completed(dev, fence) ? 0 : -EBUSY;
716 ktime_t now = ktime_get();
717 unsigned long remaining_jiffies;
719 if (ktime_compare(*timeout, now) < 0) {
720 remaining_jiffies = 0;
722 ktime_t rem = ktime_sub(*timeout, now);
723 struct timespec ts = ktime_to_timespec(rem);
724 remaining_jiffies = timespec_to_jiffies(&ts);
728 ret = wait_event_interruptible_timeout(priv->fence_event,
729 fence_completed(dev, fence),
732 ret = wait_event_timeout(priv->fence_event,
733 fence_completed(dev, fence),
737 DBG("timeout waiting for fence: %u (completed: %u)",
738 fence, priv->completed_fence);
740 } else if (ret != -ERESTARTSYS) {
748 int msm_queue_fence_cb(struct drm_device *dev,
749 struct msm_fence_cb *cb, uint32_t fence)
751 struct msm_drm_private *priv = dev->dev_private;
754 mutex_lock(&dev->struct_mutex);
755 if (!list_empty(&cb->work.entry)) {
757 } else if (fence > priv->completed_fence) {
759 list_add_tail(&cb->work.entry, &priv->fence_cbs);
761 queue_work(priv->wq, &cb->work);
763 mutex_unlock(&dev->struct_mutex);
768 /* called from workqueue */
769 void msm_update_fence(struct drm_device *dev, uint32_t fence)
771 struct msm_drm_private *priv = dev->dev_private;
773 mutex_lock(&dev->struct_mutex);
774 priv->completed_fence = max(fence, priv->completed_fence);
776 while (!list_empty(&priv->fence_cbs)) {
777 struct msm_fence_cb *cb;
779 cb = list_first_entry(&priv->fence_cbs,
780 struct msm_fence_cb, work.entry);
782 if (cb->fence > priv->completed_fence)
785 list_del_init(&cb->work.entry);
786 queue_work(priv->wq, &cb->work);
789 mutex_unlock(&dev->struct_mutex);
791 wake_up_all(&priv->fence_event);
794 void __msm_fence_worker(struct work_struct *work)
796 struct msm_fence_cb *cb = container_of(work, struct msm_fence_cb, work);
804 static int msm_ioctl_get_param(struct drm_device *dev, void *data,
805 struct drm_file *file)
807 struct msm_drm_private *priv = dev->dev_private;
808 struct drm_msm_param *args = data;
811 /* for now, we just have 3d pipe.. eventually this would need to
812 * be more clever to dispatch to appropriate gpu module:
814 if (args->pipe != MSM_PIPE_3D0)
822 return gpu->funcs->get_param(gpu, args->param, &args->value);
825 static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
826 struct drm_file *file)
828 struct drm_msm_gem_new *args = data;
830 if (args->flags & ~MSM_BO_FLAGS) {
831 DRM_ERROR("invalid flags: %08x\n", args->flags);
835 return msm_gem_new_handle(dev, file, args->size,
836 args->flags, &args->handle);
839 static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
841 return ktime_set(timeout.tv_sec, timeout.tv_nsec);
844 static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
845 struct drm_file *file)
847 struct drm_msm_gem_cpu_prep *args = data;
848 struct drm_gem_object *obj;
849 ktime_t timeout = to_ktime(args->timeout);
852 if (args->op & ~MSM_PREP_FLAGS) {
853 DRM_ERROR("invalid op: %08x\n", args->op);
857 obj = drm_gem_object_lookup(dev, file, args->handle);
861 ret = msm_gem_cpu_prep(obj, args->op, &timeout);
863 drm_gem_object_unreference_unlocked(obj);
868 static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
869 struct drm_file *file)
871 struct drm_msm_gem_cpu_fini *args = data;
872 struct drm_gem_object *obj;
875 obj = drm_gem_object_lookup(dev, file, args->handle);
879 ret = msm_gem_cpu_fini(obj);
881 drm_gem_object_unreference_unlocked(obj);
886 static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
887 struct drm_file *file)
889 struct drm_msm_gem_info *args = data;
890 struct drm_gem_object *obj;
896 obj = drm_gem_object_lookup(dev, file, args->handle);
900 args->offset = msm_gem_mmap_offset(obj);
902 drm_gem_object_unreference_unlocked(obj);
907 static int msm_ioctl_wait_fence(struct drm_device *dev, void *data,
908 struct drm_file *file)
910 struct drm_msm_wait_fence *args = data;
911 ktime_t timeout = to_ktime(args->timeout);
914 DRM_ERROR("invalid pad: %08x\n", args->pad);
918 return msm_wait_fence(dev, args->fence, &timeout, true);
921 static const struct drm_ioctl_desc msm_ioctls[] = {
922 DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_AUTH|DRM_RENDER_ALLOW),
923 DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW),
924 DRM_IOCTL_DEF_DRV(MSM_GEM_INFO, msm_ioctl_gem_info, DRM_AUTH|DRM_RENDER_ALLOW),
925 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
926 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
927 DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_AUTH|DRM_RENDER_ALLOW),
928 DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_AUTH|DRM_RENDER_ALLOW),
931 static const struct vm_operations_struct vm_ops = {
932 .fault = msm_gem_fault,
933 .open = drm_gem_vm_open,
934 .close = drm_gem_vm_close,
937 static const struct file_operations fops = {
938 .owner = THIS_MODULE,
940 .release = drm_release,
941 .unlocked_ioctl = drm_ioctl,
943 .compat_ioctl = drm_compat_ioctl,
948 .mmap = msm_gem_mmap,
951 static struct drm_driver msm_driver = {
952 .driver_features = DRIVER_HAVE_IRQ |
959 .unload = msm_unload,
961 .preclose = msm_preclose,
962 .lastclose = msm_lastclose,
963 .set_busid = drm_platform_set_busid,
964 .irq_handler = msm_irq,
965 .irq_preinstall = msm_irq_preinstall,
966 .irq_postinstall = msm_irq_postinstall,
967 .irq_uninstall = msm_irq_uninstall,
968 .get_vblank_counter = drm_vblank_no_hw_counter,
969 .enable_vblank = msm_enable_vblank,
970 .disable_vblank = msm_disable_vblank,
971 .gem_free_object = msm_gem_free_object,
972 .gem_vm_ops = &vm_ops,
973 .dumb_create = msm_gem_dumb_create,
974 .dumb_map_offset = msm_gem_dumb_map_offset,
975 .dumb_destroy = drm_gem_dumb_destroy,
976 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
977 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
978 .gem_prime_export = drm_gem_prime_export,
979 .gem_prime_import = drm_gem_prime_import,
980 .gem_prime_pin = msm_gem_prime_pin,
981 .gem_prime_unpin = msm_gem_prime_unpin,
982 .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
983 .gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
984 .gem_prime_vmap = msm_gem_prime_vmap,
985 .gem_prime_vunmap = msm_gem_prime_vunmap,
986 .gem_prime_mmap = msm_gem_prime_mmap,
987 #ifdef CONFIG_DEBUG_FS
988 .debugfs_init = msm_debugfs_init,
989 .debugfs_cleanup = msm_debugfs_cleanup,
991 .ioctls = msm_ioctls,
992 .num_ioctls = DRM_MSM_NUM_IOCTLS,
995 .desc = "MSM Snapdragon DRM",
1001 #ifdef CONFIG_PM_SLEEP
1002 static int msm_pm_suspend(struct device *dev)
1004 struct drm_device *ddev = dev_get_drvdata(dev);
1006 drm_kms_helper_poll_disable(ddev);
1011 static int msm_pm_resume(struct device *dev)
1013 struct drm_device *ddev = dev_get_drvdata(dev);
1015 drm_kms_helper_poll_enable(ddev);
1021 static const struct dev_pm_ops msm_pm_ops = {
1022 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
1026 * Componentized driver support:
1030 * NOTE: duplication of the same code as exynos or imx (or probably any other).
1031 * so probably some room for some helpers
1033 static int compare_of(struct device *dev, void *data)
1035 return dev->of_node == data;
1038 static int add_components(struct device *dev, struct component_match **matchptr,
1041 struct device_node *np = dev->of_node;
1044 for (i = 0; ; i++) {
1045 struct device_node *node;
1047 node = of_parse_phandle(np, name, i);
1051 component_match_add(dev, matchptr, compare_of, node);
1057 static int msm_drm_bind(struct device *dev)
1059 return drm_platform_init(&msm_driver, to_platform_device(dev));
1062 static void msm_drm_unbind(struct device *dev)
1064 drm_put_dev(platform_get_drvdata(to_platform_device(dev)));
1067 static const struct component_master_ops msm_drm_ops = {
1068 .bind = msm_drm_bind,
1069 .unbind = msm_drm_unbind,
1076 static int msm_pdev_probe(struct platform_device *pdev)
1078 struct component_match *match = NULL;
1080 add_components(&pdev->dev, &match, "connectors");
1081 add_components(&pdev->dev, &match, "gpus");
1083 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
1084 return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
1087 static int msm_pdev_remove(struct platform_device *pdev)
1089 component_master_del(&pdev->dev, &msm_drm_ops);
1094 static const struct platform_device_id msm_id[] = {
1099 static const struct of_device_id dt_match[] = {
1100 { .compatible = "qcom,mdp4", .data = (void *) 4 }, /* mdp4 */
1101 { .compatible = "qcom,mdp5", .data = (void *) 5 }, /* mdp5 */
1102 /* to support downstream DT files */
1103 { .compatible = "qcom,mdss_mdp", .data = (void *) 5 }, /* mdp5 */
1106 MODULE_DEVICE_TABLE(of, dt_match);
1108 static struct platform_driver msm_platform_driver = {
1109 .probe = msm_pdev_probe,
1110 .remove = msm_pdev_remove,
1113 .of_match_table = dt_match,
1119 static int __init msm_drm_register(void)
1126 return platform_driver_register(&msm_platform_driver);
1129 static void __exit msm_drm_unregister(void)
1132 platform_driver_unregister(&msm_platform_driver);
1134 adreno_unregister();
1135 msm_edp_unregister();
1136 msm_dsi_unregister();
1139 module_init(msm_drm_register);
1140 module_exit(msm_drm_unregister);
1142 MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
1143 MODULE_DESCRIPTION("MSM DRM Driver");
1144 MODULE_LICENSE("GPL");