Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Red Hat |
| 3 | * Author: Rob Clark <robdclark@gmail.com> |
| 4 | * |
| 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. |
| 8 | * |
| 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 |
| 12 | * more details. |
| 13 | * |
| 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/>. |
| 16 | */ |
| 17 | |
| 18 | #include "msm_drv.h" |
Rob Clark | edcd60c | 2016-03-16 12:56:12 -0400 | [diff] [blame] | 19 | #include "msm_debugfs.h" |
Rob Clark | fde5de6 | 2016-03-15 15:35:08 -0400 | [diff] [blame] | 20 | #include "msm_fence.h" |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 21 | #include "msm_gpu.h" |
Rob Clark | dd2da6e | 2013-11-30 16:12:10 -0500 | [diff] [blame] | 22 | #include "msm_kms.h" |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 23 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 24 | static void msm_fb_output_poll_changed(struct drm_device *dev) |
| 25 | { |
| 26 | struct msm_drm_private *priv = dev->dev_private; |
| 27 | if (priv->fbdev) |
| 28 | drm_fb_helper_hotplug_event(priv->fbdev); |
| 29 | } |
| 30 | |
| 31 | static const struct drm_mode_config_funcs mode_config_funcs = { |
| 32 | .fb_create = msm_framebuffer_create, |
| 33 | .output_poll_changed = msm_fb_output_poll_changed, |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 34 | .atomic_check = msm_atomic_check, |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 35 | .atomic_commit = msm_atomic_commit, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 36 | }; |
| 37 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 38 | int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 39 | { |
| 40 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 41 | int idx = priv->num_mmus++; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 42 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 43 | if (WARN_ON(idx >= ARRAY_SIZE(priv->mmus))) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 44 | return -EINVAL; |
| 45 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 46 | priv->mmus[idx] = mmu; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 47 | |
| 48 | return idx; |
| 49 | } |
| 50 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 51 | #ifdef CONFIG_DRM_MSM_REGISTER_LOGGING |
| 52 | static bool reglog = false; |
| 53 | MODULE_PARM_DESC(reglog, "Enable register read/write logging"); |
| 54 | module_param(reglog, bool, 0600); |
| 55 | #else |
| 56 | #define reglog 0 |
| 57 | #endif |
| 58 | |
Archit Taneja | a9ee34b | 2015-07-13 12:12:07 +0530 | [diff] [blame] | 59 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Rob Clark | e90dfec | 2015-01-30 17:05:41 -0500 | [diff] [blame] | 60 | static bool fbdev = true; |
| 61 | MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer"); |
| 62 | module_param(fbdev, bool, 0600); |
| 63 | #endif |
| 64 | |
Rob Clark | 3a10ba8 | 2014-09-08 14:24:57 -0400 | [diff] [blame] | 65 | static char *vram = "16m"; |
Rob Clark | 4313c744 | 2016-02-03 14:02:04 -0500 | [diff] [blame] | 66 | MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)"); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 67 | module_param(vram, charp, 0); |
| 68 | |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 69 | /* |
| 70 | * Util/helpers: |
| 71 | */ |
| 72 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 73 | void __iomem *msm_ioremap(struct platform_device *pdev, const char *name, |
| 74 | const char *dbgname) |
| 75 | { |
| 76 | struct resource *res; |
| 77 | unsigned long size; |
| 78 | void __iomem *ptr; |
| 79 | |
| 80 | if (name) |
| 81 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); |
| 82 | else |
| 83 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 84 | |
| 85 | if (!res) { |
| 86 | dev_err(&pdev->dev, "failed to get memory resource: %s\n", name); |
| 87 | return ERR_PTR(-EINVAL); |
| 88 | } |
| 89 | |
| 90 | size = resource_size(res); |
| 91 | |
| 92 | ptr = devm_ioremap_nocache(&pdev->dev, res->start, size); |
| 93 | if (!ptr) { |
| 94 | dev_err(&pdev->dev, "failed to ioremap: %s\n", name); |
| 95 | return ERR_PTR(-ENOMEM); |
| 96 | } |
| 97 | |
| 98 | if (reglog) |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 99 | printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 100 | |
| 101 | return ptr; |
| 102 | } |
| 103 | |
| 104 | void msm_writel(u32 data, void __iomem *addr) |
| 105 | { |
| 106 | if (reglog) |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 107 | printk(KERN_DEBUG "IO:W %p %08x\n", addr, data); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 108 | writel(data, addr); |
| 109 | } |
| 110 | |
| 111 | u32 msm_readl(const void __iomem *addr) |
| 112 | { |
| 113 | u32 val = readl(addr); |
| 114 | if (reglog) |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 115 | printk(KERN_ERR "IO:R %p %08x\n", addr, val); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 116 | return val; |
| 117 | } |
| 118 | |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 119 | struct vblank_event { |
| 120 | struct list_head node; |
| 121 | int crtc_id; |
| 122 | bool enable; |
| 123 | }; |
| 124 | |
| 125 | static void vblank_ctrl_worker(struct work_struct *work) |
| 126 | { |
| 127 | struct msm_vblank_ctrl *vbl_ctrl = container_of(work, |
| 128 | struct msm_vblank_ctrl, work); |
| 129 | struct msm_drm_private *priv = container_of(vbl_ctrl, |
| 130 | struct msm_drm_private, vblank_ctrl); |
| 131 | struct msm_kms *kms = priv->kms; |
| 132 | struct vblank_event *vbl_ev, *tmp; |
| 133 | unsigned long flags; |
| 134 | |
| 135 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 136 | list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) { |
| 137 | list_del(&vbl_ev->node); |
| 138 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 139 | |
| 140 | if (vbl_ev->enable) |
| 141 | kms->funcs->enable_vblank(kms, |
| 142 | priv->crtcs[vbl_ev->crtc_id]); |
| 143 | else |
| 144 | kms->funcs->disable_vblank(kms, |
| 145 | priv->crtcs[vbl_ev->crtc_id]); |
| 146 | |
| 147 | kfree(vbl_ev); |
| 148 | |
| 149 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 150 | } |
| 151 | |
| 152 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 153 | } |
| 154 | |
| 155 | static int vblank_ctrl_queue_work(struct msm_drm_private *priv, |
| 156 | int crtc_id, bool enable) |
| 157 | { |
| 158 | struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl; |
| 159 | struct vblank_event *vbl_ev; |
| 160 | unsigned long flags; |
| 161 | |
| 162 | vbl_ev = kzalloc(sizeof(*vbl_ev), GFP_ATOMIC); |
| 163 | if (!vbl_ev) |
| 164 | return -ENOMEM; |
| 165 | |
| 166 | vbl_ev->crtc_id = crtc_id; |
| 167 | vbl_ev->enable = enable; |
| 168 | |
| 169 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 170 | list_add_tail(&vbl_ev->node, &vbl_ctrl->event_list); |
| 171 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 172 | |
| 173 | queue_work(priv->wq, &vbl_ctrl->work); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 178 | static int msm_drm_uninit(struct device *dev) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 179 | { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 180 | struct platform_device *pdev = to_platform_device(dev); |
| 181 | struct drm_device *ddev = platform_get_drvdata(pdev); |
| 182 | struct msm_drm_private *priv = ddev->dev_private; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 183 | struct msm_kms *kms = priv->kms; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 184 | struct msm_gpu *gpu = priv->gpu; |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 185 | struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl; |
| 186 | struct vblank_event *vbl_ev, *tmp; |
| 187 | |
| 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. |
| 191 | */ |
| 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); |
| 195 | kfree(vbl_ev); |
| 196 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 197 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 198 | drm_kms_helper_poll_fini(ddev); |
Archit Taneja | 1aaa57f | 2016-02-25 11:19:45 +0530 | [diff] [blame] | 199 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 200 | drm_dev_unregister(ddev); |
Archit Taneja | 8208ed9 | 2016-05-02 11:05:53 +0530 | [diff] [blame] | 201 | |
Archit Taneja | 1aaa57f | 2016-02-25 11:19:45 +0530 | [diff] [blame] | 202 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
| 203 | if (fbdev && priv->fbdev) |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 204 | msm_fbdev_free(ddev); |
Archit Taneja | 1aaa57f | 2016-02-25 11:19:45 +0530 | [diff] [blame] | 205 | #endif |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 206 | drm_mode_config_cleanup(ddev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 207 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 208 | pm_runtime_get_sync(dev); |
| 209 | drm_irq_uninstall(ddev); |
| 210 | pm_runtime_put_sync(dev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 211 | |
| 212 | flush_workqueue(priv->wq); |
| 213 | destroy_workqueue(priv->wq); |
| 214 | |
Rob Clark | ba00c3f | 2016-03-16 18:18:17 -0400 | [diff] [blame] | 215 | flush_workqueue(priv->atomic_wq); |
| 216 | destroy_workqueue(priv->atomic_wq); |
| 217 | |
Archit Taneja | cd79272 | 2016-06-15 18:04:31 +0530 | [diff] [blame] | 218 | if (kms) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 219 | kms->funcs->destroy(kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 220 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 221 | if (gpu) { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 222 | mutex_lock(&ddev->struct_mutex); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 223 | gpu->funcs->pm_suspend(gpu); |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 224 | mutex_unlock(&ddev->struct_mutex); |
Rob Clark | 774449e | 2015-05-15 09:19:36 -0400 | [diff] [blame] | 225 | gpu->funcs->destroy(gpu); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 226 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 227 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 228 | if (priv->vram.paddr) { |
| 229 | DEFINE_DMA_ATTRS(attrs); |
| 230 | dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs); |
| 231 | drm_mm_takedown(&priv->vram.mm); |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 232 | dma_free_attrs(dev, priv->vram.size, NULL, |
| 233 | priv->vram.paddr, &attrs); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 234 | } |
| 235 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 236 | component_unbind_all(dev, ddev); |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 237 | |
Archit Taneja | 0a6030d | 2016-05-08 21:36:28 +0530 | [diff] [blame] | 238 | msm_mdss_destroy(ddev); |
| 239 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 240 | ddev->dev_private = NULL; |
| 241 | drm_dev_unref(ddev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 242 | |
| 243 | kfree(priv); |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 248 | static int get_mdp_ver(struct platform_device *pdev) |
| 249 | { |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 250 | struct device *dev = &pdev->dev; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 251 | |
| 252 | return (int) (unsigned long) of_device_get_match_data(dev); |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 253 | } |
| 254 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 255 | #include <linux/of_address.h> |
| 256 | |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 257 | static int msm_init_vram(struct drm_device *dev) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 258 | { |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 259 | struct msm_drm_private *priv = dev->dev_private; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 260 | struct device_node *node; |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 261 | unsigned long size = 0; |
| 262 | int ret = 0; |
| 263 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 264 | /* In the device-tree world, we could have a 'memory-region' |
| 265 | * phandle, which gives us a link to our "vram". Allocating |
| 266 | * is all nicely abstracted behind the dma api, but we need |
| 267 | * to know the entire size to allocate it all in one go. There |
| 268 | * are two cases: |
| 269 | * 1) device with no IOMMU, in which case we need exclusive |
| 270 | * access to a VRAM carveout big enough for all gpu |
| 271 | * buffers |
| 272 | * 2) device with IOMMU, but where the bootloader puts up |
| 273 | * a splash screen. In this case, the VRAM carveout |
| 274 | * need only be large enough for fbdev fb. But we need |
| 275 | * exclusive access to the buffer to avoid the kernel |
| 276 | * using those pages for other purposes (which appears |
| 277 | * as corruption on screen before we have a chance to |
| 278 | * load and do initial modeset) |
| 279 | */ |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 280 | |
| 281 | node = of_parse_phandle(dev->dev->of_node, "memory-region", 0); |
| 282 | if (node) { |
| 283 | struct resource r; |
| 284 | ret = of_address_to_resource(node, 0, &r); |
| 285 | if (ret) |
| 286 | return ret; |
| 287 | size = r.end - r.start; |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 288 | DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 289 | |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 290 | /* if we have no IOMMU, then we need to use carveout allocator. |
| 291 | * Grab the entire CMA chunk carved out in early startup in |
| 292 | * mach-msm: |
| 293 | */ |
| 294 | } else if (!iommu_present(&platform_bus_type)) { |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 295 | DRM_INFO("using %s VRAM carveout\n", vram); |
| 296 | size = memparse(vram, NULL); |
| 297 | } |
| 298 | |
| 299 | if (size) { |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 300 | DEFINE_DMA_ATTRS(attrs); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 301 | void *p; |
| 302 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 303 | priv->vram.size = size; |
| 304 | |
| 305 | drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1); |
| 306 | |
| 307 | dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs); |
| 308 | dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); |
| 309 | |
| 310 | /* note that for no-kernel-mapping, the vaddr returned |
| 311 | * is bogus, but non-null if allocation succeeded: |
| 312 | */ |
| 313 | p = dma_alloc_attrs(dev->dev, size, |
Rob Clark | 543d301 | 2014-06-02 07:25:56 -0400 | [diff] [blame] | 314 | &priv->vram.paddr, GFP_KERNEL, &attrs); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 315 | if (!p) { |
| 316 | dev_err(dev->dev, "failed to allocate VRAM\n"); |
| 317 | priv->vram.paddr = 0; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 318 | return -ENOMEM; |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | dev_info(dev->dev, "VRAM: %08x->%08x\n", |
| 322 | (uint32_t)priv->vram.paddr, |
| 323 | (uint32_t)(priv->vram.paddr + size)); |
| 324 | } |
| 325 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 326 | return ret; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 329 | static int msm_drm_init(struct device *dev, struct drm_driver *drv) |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 330 | { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 331 | struct platform_device *pdev = to_platform_device(dev); |
| 332 | struct drm_device *ddev; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 333 | struct msm_drm_private *priv; |
| 334 | struct msm_kms *kms; |
| 335 | int ret; |
| 336 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 337 | ddev = drm_dev_alloc(drv, dev); |
| 338 | if (!ddev) { |
| 339 | dev_err(dev, "failed to allocate drm_device\n"); |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 340 | return -ENOMEM; |
| 341 | } |
| 342 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 343 | platform_set_drvdata(pdev, ddev); |
| 344 | ddev->platformdev = pdev; |
| 345 | |
| 346 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 347 | if (!priv) { |
| 348 | drm_dev_unref(ddev); |
| 349 | return -ENOMEM; |
| 350 | } |
| 351 | |
| 352 | ddev->dev_private = priv; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 353 | |
Archit Taneja | 0a6030d | 2016-05-08 21:36:28 +0530 | [diff] [blame] | 354 | ret = msm_mdss_init(ddev); |
| 355 | if (ret) { |
| 356 | kfree(priv); |
| 357 | drm_dev_unref(ddev); |
| 358 | return ret; |
| 359 | } |
| 360 | |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 361 | priv->wq = alloc_ordered_workqueue("msm", 0); |
Rob Clark | ba00c3f | 2016-03-16 18:18:17 -0400 | [diff] [blame] | 362 | priv->atomic_wq = alloc_ordered_workqueue("msm:atomic", 0); |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 363 | init_waitqueue_head(&priv->pending_crtcs_event); |
| 364 | |
| 365 | INIT_LIST_HEAD(&priv->inactive_list); |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 366 | INIT_LIST_HEAD(&priv->vblank_ctrl.event_list); |
| 367 | INIT_WORK(&priv->vblank_ctrl.work, vblank_ctrl_worker); |
| 368 | spin_lock_init(&priv->vblank_ctrl.lock); |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 369 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 370 | drm_mode_config_init(ddev); |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 371 | |
| 372 | /* Bind all our sub-components: */ |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 373 | ret = component_bind_all(dev, ddev); |
| 374 | if (ret) { |
Archit Taneja | 0a6030d | 2016-05-08 21:36:28 +0530 | [diff] [blame] | 375 | msm_mdss_destroy(ddev); |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 376 | kfree(priv); |
| 377 | drm_dev_unref(ddev); |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 378 | return ret; |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 379 | } |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 380 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 381 | ret = msm_init_vram(ddev); |
Rob Clark | 13f1556 | 2015-05-07 15:20:13 -0400 | [diff] [blame] | 382 | if (ret) |
| 383 | goto fail; |
| 384 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 385 | switch (get_mdp_ver(pdev)) { |
| 386 | case 4: |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 387 | kms = mdp4_kms_init(ddev); |
Archit Taneja | 0a6030d | 2016-05-08 21:36:28 +0530 | [diff] [blame] | 388 | priv->kms = kms; |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 389 | break; |
| 390 | case 5: |
Archit Taneja | 392ae6e | 2016-06-14 18:24:54 +0530 | [diff] [blame] | 391 | kms = mdp5_kms_init(ddev); |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 392 | break; |
| 393 | default: |
| 394 | kms = ERR_PTR(-ENODEV); |
| 395 | break; |
| 396 | } |
| 397 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 398 | if (IS_ERR(kms)) { |
| 399 | /* |
| 400 | * NOTE: once we have GPU support, having no kms should not |
| 401 | * be considered fatal.. ideally we would still support gpu |
| 402 | * and (for example) use dmabuf/prime to share buffers with |
| 403 | * imx drm driver on iMX5 |
| 404 | */ |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 405 | dev_err(dev, "failed to load kms\n"); |
Thomas Meyer | e4826a9 | 2013-09-16 23:19:54 +0200 | [diff] [blame] | 406 | ret = PTR_ERR(kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 407 | goto fail; |
| 408 | } |
| 409 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 410 | if (kms) { |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 411 | ret = kms->funcs->hw_init(kms); |
| 412 | if (ret) { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 413 | dev_err(dev, "kms hw init failed: %d\n", ret); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 414 | goto fail; |
| 415 | } |
| 416 | } |
| 417 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 418 | ddev->mode_config.funcs = &mode_config_funcs; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 419 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 420 | ret = drm_vblank_init(ddev, priv->num_crtcs); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 421 | if (ret < 0) { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 422 | dev_err(dev, "failed to initialize vblank\n"); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 423 | goto fail; |
| 424 | } |
| 425 | |
Archit Taneja | a2b3a55 | 2016-05-18 15:06:03 +0530 | [diff] [blame] | 426 | if (kms) { |
| 427 | pm_runtime_get_sync(dev); |
| 428 | ret = drm_irq_install(ddev, kms->irq); |
| 429 | pm_runtime_put_sync(dev); |
| 430 | if (ret < 0) { |
| 431 | dev_err(dev, "failed to install IRQ handler\n"); |
| 432 | goto fail; |
| 433 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 434 | } |
| 435 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 436 | ret = drm_dev_register(ddev, 0); |
Rob Clark | a7d3c95 | 2014-05-30 14:47:38 -0400 | [diff] [blame] | 437 | if (ret) |
| 438 | goto fail; |
| 439 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 440 | drm_mode_config_reset(ddev); |
| 441 | |
| 442 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
| 443 | if (fbdev) |
| 444 | priv->fbdev = msm_fbdev_init(ddev); |
| 445 | #endif |
| 446 | |
| 447 | ret = msm_debugfs_late_init(ddev); |
| 448 | if (ret) |
| 449 | goto fail; |
| 450 | |
| 451 | drm_kms_helper_poll_init(ddev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 452 | |
| 453 | return 0; |
| 454 | |
| 455 | fail: |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 456 | msm_drm_uninit(dev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 457 | return ret; |
| 458 | } |
| 459 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 460 | /* |
| 461 | * DRM operations: |
| 462 | */ |
| 463 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 464 | static void load_gpu(struct drm_device *dev) |
| 465 | { |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 466 | static DEFINE_MUTEX(init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 467 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 468 | |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 469 | mutex_lock(&init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 470 | |
Rob Clark | e2550b7 | 2014-09-05 13:30:27 -0400 | [diff] [blame] | 471 | if (!priv->gpu) |
| 472 | priv->gpu = adreno_load_gpu(dev); |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 473 | |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 474 | mutex_unlock(&init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static int msm_open(struct drm_device *dev, struct drm_file *file) |
| 478 | { |
| 479 | struct msm_file_private *ctx; |
| 480 | |
| 481 | /* For now, load gpu on open.. to avoid the requirement of having |
| 482 | * firmware in the initrd. |
| 483 | */ |
| 484 | load_gpu(dev); |
| 485 | |
| 486 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
| 487 | if (!ctx) |
| 488 | return -ENOMEM; |
| 489 | |
| 490 | file->driver_priv = ctx; |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 495 | static void msm_preclose(struct drm_device *dev, struct drm_file *file) |
| 496 | { |
| 497 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 498 | struct msm_file_private *ctx = file->driver_priv; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 499 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 500 | mutex_lock(&dev->struct_mutex); |
| 501 | if (ctx == priv->lastctx) |
| 502 | priv->lastctx = NULL; |
| 503 | mutex_unlock(&dev->struct_mutex); |
| 504 | |
| 505 | kfree(ctx); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | static void msm_lastclose(struct drm_device *dev) |
| 509 | { |
| 510 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 511 | if (priv->fbdev) |
| 512 | drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 513 | } |
| 514 | |
Daniel Vetter | e9f0d76 | 2013-12-11 11:34:42 +0100 | [diff] [blame] | 515 | static irqreturn_t msm_irq(int irq, void *arg) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 516 | { |
| 517 | struct drm_device *dev = arg; |
| 518 | struct msm_drm_private *priv = dev->dev_private; |
| 519 | struct msm_kms *kms = priv->kms; |
| 520 | BUG_ON(!kms); |
| 521 | return kms->funcs->irq(kms); |
| 522 | } |
| 523 | |
| 524 | static void msm_irq_preinstall(struct drm_device *dev) |
| 525 | { |
| 526 | struct msm_drm_private *priv = dev->dev_private; |
| 527 | struct msm_kms *kms = priv->kms; |
| 528 | BUG_ON(!kms); |
| 529 | kms->funcs->irq_preinstall(kms); |
| 530 | } |
| 531 | |
| 532 | static int msm_irq_postinstall(struct drm_device *dev) |
| 533 | { |
| 534 | struct msm_drm_private *priv = dev->dev_private; |
| 535 | struct msm_kms *kms = priv->kms; |
| 536 | BUG_ON(!kms); |
| 537 | return kms->funcs->irq_postinstall(kms); |
| 538 | } |
| 539 | |
| 540 | static void msm_irq_uninstall(struct drm_device *dev) |
| 541 | { |
| 542 | struct msm_drm_private *priv = dev->dev_private; |
| 543 | struct msm_kms *kms = priv->kms; |
| 544 | BUG_ON(!kms); |
| 545 | kms->funcs->irq_uninstall(kms); |
| 546 | } |
| 547 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 548 | static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 549 | { |
| 550 | struct msm_drm_private *priv = dev->dev_private; |
| 551 | struct msm_kms *kms = priv->kms; |
| 552 | if (!kms) |
| 553 | return -ENXIO; |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 554 | DBG("dev=%p, crtc=%u", dev, pipe); |
| 555 | return vblank_ctrl_queue_work(priv, pipe, true); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 556 | } |
| 557 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 558 | static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 559 | { |
| 560 | struct msm_drm_private *priv = dev->dev_private; |
| 561 | struct msm_kms *kms = priv->kms; |
| 562 | if (!kms) |
| 563 | return; |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 564 | DBG("dev=%p, crtc=%u", dev, pipe); |
| 565 | vblank_ctrl_queue_work(priv, pipe, false); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 569 | * DRM ioctls: |
| 570 | */ |
| 571 | |
| 572 | static int msm_ioctl_get_param(struct drm_device *dev, void *data, |
| 573 | struct drm_file *file) |
| 574 | { |
| 575 | struct msm_drm_private *priv = dev->dev_private; |
| 576 | struct drm_msm_param *args = data; |
| 577 | struct msm_gpu *gpu; |
| 578 | |
| 579 | /* for now, we just have 3d pipe.. eventually this would need to |
| 580 | * be more clever to dispatch to appropriate gpu module: |
| 581 | */ |
| 582 | if (args->pipe != MSM_PIPE_3D0) |
| 583 | return -EINVAL; |
| 584 | |
| 585 | gpu = priv->gpu; |
| 586 | |
| 587 | if (!gpu) |
| 588 | return -ENXIO; |
| 589 | |
| 590 | return gpu->funcs->get_param(gpu, args->param, &args->value); |
| 591 | } |
| 592 | |
| 593 | static int msm_ioctl_gem_new(struct drm_device *dev, void *data, |
| 594 | struct drm_file *file) |
| 595 | { |
| 596 | struct drm_msm_gem_new *args = data; |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 597 | |
| 598 | if (args->flags & ~MSM_BO_FLAGS) { |
| 599 | DRM_ERROR("invalid flags: %08x\n", args->flags); |
| 600 | return -EINVAL; |
| 601 | } |
| 602 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 603 | return msm_gem_new_handle(dev, file, args->size, |
| 604 | args->flags, &args->handle); |
| 605 | } |
| 606 | |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 607 | static inline ktime_t to_ktime(struct drm_msm_timespec timeout) |
| 608 | { |
| 609 | return ktime_set(timeout.tv_sec, timeout.tv_nsec); |
| 610 | } |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 611 | |
| 612 | static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data, |
| 613 | struct drm_file *file) |
| 614 | { |
| 615 | struct drm_msm_gem_cpu_prep *args = data; |
| 616 | struct drm_gem_object *obj; |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 617 | ktime_t timeout = to_ktime(args->timeout); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 618 | int ret; |
| 619 | |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 620 | if (args->op & ~MSM_PREP_FLAGS) { |
| 621 | DRM_ERROR("invalid op: %08x\n", args->op); |
| 622 | return -EINVAL; |
| 623 | } |
| 624 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 625 | obj = drm_gem_object_lookup(file, args->handle); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 626 | if (!obj) |
| 627 | return -ENOENT; |
| 628 | |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 629 | ret = msm_gem_cpu_prep(obj, args->op, &timeout); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 630 | |
| 631 | drm_gem_object_unreference_unlocked(obj); |
| 632 | |
| 633 | return ret; |
| 634 | } |
| 635 | |
| 636 | static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data, |
| 637 | struct drm_file *file) |
| 638 | { |
| 639 | struct drm_msm_gem_cpu_fini *args = data; |
| 640 | struct drm_gem_object *obj; |
| 641 | int ret; |
| 642 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 643 | obj = drm_gem_object_lookup(file, args->handle); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 644 | if (!obj) |
| 645 | return -ENOENT; |
| 646 | |
| 647 | ret = msm_gem_cpu_fini(obj); |
| 648 | |
| 649 | drm_gem_object_unreference_unlocked(obj); |
| 650 | |
| 651 | return ret; |
| 652 | } |
| 653 | |
| 654 | static int msm_ioctl_gem_info(struct drm_device *dev, void *data, |
| 655 | struct drm_file *file) |
| 656 | { |
| 657 | struct drm_msm_gem_info *args = data; |
| 658 | struct drm_gem_object *obj; |
| 659 | int ret = 0; |
| 660 | |
| 661 | if (args->pad) |
| 662 | return -EINVAL; |
| 663 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 664 | obj = drm_gem_object_lookup(file, args->handle); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 665 | if (!obj) |
| 666 | return -ENOENT; |
| 667 | |
| 668 | args->offset = msm_gem_mmap_offset(obj); |
| 669 | |
| 670 | drm_gem_object_unreference_unlocked(obj); |
| 671 | |
| 672 | return ret; |
| 673 | } |
| 674 | |
| 675 | static int msm_ioctl_wait_fence(struct drm_device *dev, void *data, |
| 676 | struct drm_file *file) |
| 677 | { |
Rob Clark | ca762a8 | 2016-03-15 17:22:13 -0400 | [diff] [blame] | 678 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 679 | struct drm_msm_wait_fence *args = data; |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 680 | ktime_t timeout = to_ktime(args->timeout); |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 681 | |
| 682 | if (args->pad) { |
| 683 | DRM_ERROR("invalid pad: %08x\n", args->pad); |
| 684 | return -EINVAL; |
| 685 | } |
| 686 | |
Rob Clark | ca762a8 | 2016-03-15 17:22:13 -0400 | [diff] [blame] | 687 | if (!priv->gpu) |
| 688 | return 0; |
| 689 | |
| 690 | return msm_wait_fence(priv->gpu->fctx, args->fence, &timeout, true); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | static const struct drm_ioctl_desc msm_ioctls[] = { |
Daniel Vetter | f8c4714 | 2015-09-08 13:56:30 +0200 | [diff] [blame] | 694 | DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_AUTH|DRM_RENDER_ALLOW), |
| 695 | DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW), |
| 696 | DRM_IOCTL_DEF_DRV(MSM_GEM_INFO, msm_ioctl_gem_info, DRM_AUTH|DRM_RENDER_ALLOW), |
| 697 | DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW), |
| 698 | DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW), |
| 699 | DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_AUTH|DRM_RENDER_ALLOW), |
| 700 | DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_AUTH|DRM_RENDER_ALLOW), |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 701 | }; |
| 702 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 703 | static const struct vm_operations_struct vm_ops = { |
| 704 | .fault = msm_gem_fault, |
| 705 | .open = drm_gem_vm_open, |
| 706 | .close = drm_gem_vm_close, |
| 707 | }; |
| 708 | |
| 709 | static const struct file_operations fops = { |
| 710 | .owner = THIS_MODULE, |
| 711 | .open = drm_open, |
| 712 | .release = drm_release, |
| 713 | .unlocked_ioctl = drm_ioctl, |
| 714 | #ifdef CONFIG_COMPAT |
| 715 | .compat_ioctl = drm_compat_ioctl, |
| 716 | #endif |
| 717 | .poll = drm_poll, |
| 718 | .read = drm_read, |
| 719 | .llseek = no_llseek, |
| 720 | .mmap = msm_gem_mmap, |
| 721 | }; |
| 722 | |
| 723 | static struct drm_driver msm_driver = { |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 724 | .driver_features = DRIVER_HAVE_IRQ | |
| 725 | DRIVER_GEM | |
| 726 | DRIVER_PRIME | |
Rob Clark | b4b15c8 | 2013-09-28 12:01:25 -0400 | [diff] [blame] | 727 | DRIVER_RENDER | |
Rob Clark | a5436e1 | 2015-06-04 10:12:22 -0400 | [diff] [blame] | 728 | DRIVER_ATOMIC | |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 729 | DRIVER_MODESET, |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 730 | .open = msm_open, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 731 | .preclose = msm_preclose, |
| 732 | .lastclose = msm_lastclose, |
| 733 | .irq_handler = msm_irq, |
| 734 | .irq_preinstall = msm_irq_preinstall, |
| 735 | .irq_postinstall = msm_irq_postinstall, |
| 736 | .irq_uninstall = msm_irq_uninstall, |
Ville Syrjälä | b44f840 | 2015-09-30 16:46:48 +0300 | [diff] [blame] | 737 | .get_vblank_counter = drm_vblank_no_hw_counter, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 738 | .enable_vblank = msm_enable_vblank, |
| 739 | .disable_vblank = msm_disable_vblank, |
| 740 | .gem_free_object = msm_gem_free_object, |
| 741 | .gem_vm_ops = &vm_ops, |
| 742 | .dumb_create = msm_gem_dumb_create, |
| 743 | .dumb_map_offset = msm_gem_dumb_map_offset, |
Rob Clark | 30600a9 | 2013-09-28 10:13:04 -0400 | [diff] [blame] | 744 | .dumb_destroy = drm_gem_dumb_destroy, |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 745 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 746 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 747 | .gem_prime_export = drm_gem_prime_export, |
| 748 | .gem_prime_import = drm_gem_prime_import, |
| 749 | .gem_prime_pin = msm_gem_prime_pin, |
| 750 | .gem_prime_unpin = msm_gem_prime_unpin, |
| 751 | .gem_prime_get_sg_table = msm_gem_prime_get_sg_table, |
| 752 | .gem_prime_import_sg_table = msm_gem_prime_import_sg_table, |
| 753 | .gem_prime_vmap = msm_gem_prime_vmap, |
| 754 | .gem_prime_vunmap = msm_gem_prime_vunmap, |
Daniel Thompson | 77a147e | 2014-11-12 11:38:14 +0000 | [diff] [blame] | 755 | .gem_prime_mmap = msm_gem_prime_mmap, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 756 | #ifdef CONFIG_DEBUG_FS |
| 757 | .debugfs_init = msm_debugfs_init, |
| 758 | .debugfs_cleanup = msm_debugfs_cleanup, |
| 759 | #endif |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 760 | .ioctls = msm_ioctls, |
| 761 | .num_ioctls = DRM_MSM_NUM_IOCTLS, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 762 | .fops = &fops, |
| 763 | .name = "msm", |
| 764 | .desc = "MSM Snapdragon DRM", |
| 765 | .date = "20130625", |
| 766 | .major = 1, |
| 767 | .minor = 0, |
| 768 | }; |
| 769 | |
| 770 | #ifdef CONFIG_PM_SLEEP |
| 771 | static int msm_pm_suspend(struct device *dev) |
| 772 | { |
| 773 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 774 | |
| 775 | drm_kms_helper_poll_disable(ddev); |
| 776 | |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | static int msm_pm_resume(struct device *dev) |
| 781 | { |
| 782 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 783 | |
| 784 | drm_kms_helper_poll_enable(ddev); |
| 785 | |
| 786 | return 0; |
| 787 | } |
| 788 | #endif |
| 789 | |
| 790 | static const struct dev_pm_ops msm_pm_ops = { |
| 791 | SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume) |
| 792 | }; |
| 793 | |
| 794 | /* |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 795 | * Componentized driver support: |
| 796 | */ |
| 797 | |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 798 | /* |
| 799 | * NOTE: duplication of the same code as exynos or imx (or probably any other). |
| 800 | * so probably some room for some helpers |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 801 | */ |
| 802 | static int compare_of(struct device *dev, void *data) |
| 803 | { |
| 804 | return dev->of_node == data; |
| 805 | } |
Rob Clark | 41e6977 | 2013-12-15 16:23:05 -0500 | [diff] [blame] | 806 | |
| 807 | static int add_components(struct device *dev, struct component_match **matchptr, |
| 808 | const char *name) |
| 809 | { |
| 810 | struct device_node *np = dev->of_node; |
| 811 | unsigned i; |
| 812 | |
| 813 | for (i = 0; ; i++) { |
| 814 | struct device_node *node; |
| 815 | |
| 816 | node = of_parse_phandle(np, name, i); |
| 817 | if (!node) |
| 818 | break; |
| 819 | |
| 820 | component_match_add(dev, matchptr, compare_of, node); |
| 821 | } |
| 822 | |
| 823 | return 0; |
| 824 | } |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 825 | |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame^] | 826 | /* |
| 827 | * Identify what components need to be added by parsing what remote-endpoints |
| 828 | * our MDP output ports are connected to. In the case of LVDS on MDP4, there |
| 829 | * is no external component that we need to add since LVDS is within MDP4 |
| 830 | * itself. |
| 831 | */ |
| 832 | static int add_components_mdp(struct device *mdp_dev, |
| 833 | struct component_match **matchptr) |
| 834 | { |
| 835 | struct device_node *np = mdp_dev->of_node; |
| 836 | struct device_node *ep_node; |
| 837 | |
| 838 | for_each_endpoint_of_node(np, ep_node) { |
| 839 | struct device_node *intf; |
| 840 | struct of_endpoint ep; |
| 841 | int ret; |
| 842 | |
| 843 | ret = of_graph_parse_endpoint(ep_node, &ep); |
| 844 | if (ret) { |
| 845 | dev_err(mdp_dev, "unable to parse port endpoint\n"); |
| 846 | of_node_put(ep_node); |
| 847 | return ret; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * The LCDC/LVDS port on MDP4 is a speacial case where the |
| 852 | * remote-endpoint isn't a component that we need to add |
| 853 | */ |
| 854 | if (of_device_is_compatible(np, "qcom,mdp4") && |
| 855 | ep.port == 0) { |
| 856 | of_node_put(ep_node); |
| 857 | continue; |
| 858 | } |
| 859 | |
| 860 | /* |
| 861 | * It's okay if some of the ports don't have a remote endpoint |
| 862 | * specified. It just means that the port isn't connected to |
| 863 | * any external interface. |
| 864 | */ |
| 865 | intf = of_graph_get_remote_port_parent(ep_node); |
| 866 | if (!intf) { |
| 867 | of_node_put(ep_node); |
| 868 | continue; |
| 869 | } |
| 870 | |
| 871 | component_match_add(mdp_dev, matchptr, compare_of, intf); |
| 872 | |
| 873 | of_node_put(intf); |
| 874 | of_node_put(ep_node); |
| 875 | } |
| 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 880 | static int add_display_components(struct device *dev, |
| 881 | struct component_match **matchptr) |
| 882 | { |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame^] | 883 | return add_components_mdp(dev, matchptr); |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static int add_gpu_components(struct device *dev, |
| 887 | struct component_match **matchptr) |
| 888 | { |
| 889 | return add_components(dev, matchptr, "gpus"); |
| 890 | } |
| 891 | |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 892 | static int msm_drm_bind(struct device *dev) |
| 893 | { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 894 | return msm_drm_init(dev, &msm_driver); |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | static void msm_drm_unbind(struct device *dev) |
| 898 | { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 899 | msm_drm_uninit(dev); |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | static const struct component_master_ops msm_drm_ops = { |
| 903 | .bind = msm_drm_bind, |
| 904 | .unbind = msm_drm_unbind, |
| 905 | }; |
| 906 | |
| 907 | /* |
| 908 | * Platform driver: |
| 909 | */ |
| 910 | |
| 911 | static int msm_pdev_probe(struct platform_device *pdev) |
| 912 | { |
| 913 | struct component_match *match = NULL; |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 914 | int ret; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 915 | |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 916 | ret = add_display_components(&pdev->dev, &match); |
| 917 | if (ret) |
| 918 | return ret; |
| 919 | |
| 920 | ret = add_gpu_components(&pdev->dev, &match); |
| 921 | if (ret) |
| 922 | return ret; |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 923 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 924 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 925 | return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static int msm_pdev_remove(struct platform_device *pdev) |
| 929 | { |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 930 | component_master_del(&pdev->dev, &msm_drm_ops); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 935 | static const struct of_device_id dt_match[] = { |
Archit Taneja | d4fc72e | 2015-11-18 12:28:39 +0530 | [diff] [blame] | 936 | { .compatible = "qcom,mdp4", .data = (void *) 4 }, /* mdp4 */ |
| 937 | { .compatible = "qcom,mdp5", .data = (void *) 5 }, /* mdp5 */ |
| 938 | /* to support downstream DT files */ |
| 939 | { .compatible = "qcom,mdss_mdp", .data = (void *) 5 }, /* mdp5 */ |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 940 | {} |
| 941 | }; |
| 942 | MODULE_DEVICE_TABLE(of, dt_match); |
| 943 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 944 | static struct platform_driver msm_platform_driver = { |
| 945 | .probe = msm_pdev_probe, |
| 946 | .remove = msm_pdev_remove, |
| 947 | .driver = { |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 948 | .name = "msm", |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 949 | .of_match_table = dt_match, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 950 | .pm = &msm_pm_ops, |
| 951 | }, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 952 | }; |
| 953 | |
| 954 | static int __init msm_drm_register(void) |
| 955 | { |
| 956 | DBG("init"); |
Archit Taneja | 1dd0a0b | 2016-05-30 16:36:50 +0530 | [diff] [blame] | 957 | msm_mdp_register(); |
Hai Li | d5af49c | 2015-03-26 19:25:17 -0400 | [diff] [blame] | 958 | msm_dsi_register(); |
Hai Li | 0045398 | 2014-12-12 14:41:17 -0500 | [diff] [blame] | 959 | msm_edp_register(); |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 960 | msm_hdmi_register(); |
Rob Clark | bfd28b1 | 2014-09-05 13:06:37 -0400 | [diff] [blame] | 961 | adreno_register(); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 962 | return platform_driver_register(&msm_platform_driver); |
| 963 | } |
| 964 | |
| 965 | static void __exit msm_drm_unregister(void) |
| 966 | { |
| 967 | DBG("fini"); |
| 968 | platform_driver_unregister(&msm_platform_driver); |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 969 | msm_hdmi_unregister(); |
Rob Clark | bfd28b1 | 2014-09-05 13:06:37 -0400 | [diff] [blame] | 970 | adreno_unregister(); |
Hai Li | 0045398 | 2014-12-12 14:41:17 -0500 | [diff] [blame] | 971 | msm_edp_unregister(); |
Hai Li | d5af49c | 2015-03-26 19:25:17 -0400 | [diff] [blame] | 972 | msm_dsi_unregister(); |
Archit Taneja | 1dd0a0b | 2016-05-30 16:36:50 +0530 | [diff] [blame] | 973 | msm_mdp_unregister(); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | module_init(msm_drm_register); |
| 977 | module_exit(msm_drm_unregister); |
| 978 | |
| 979 | MODULE_AUTHOR("Rob Clark <robdclark@gmail.com"); |
| 980 | MODULE_DESCRIPTION("MSM DRM Driver"); |
| 981 | MODULE_LICENSE("GPL"); |