Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1 | /* |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 3 | * Copyright (C) 2013 Red Hat |
| 4 | * Author: Rob Clark <robdclark@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published by |
| 8 | * the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along with |
| 16 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 19 | #include <linux/kthread.h> |
| 20 | #include <uapi/linux/sched/types.h> |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 21 | #include <drm/drm_of.h> |
| 22 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 23 | #include "msm_drv.h" |
Rob Clark | edcd60c | 2016-03-16 12:56:12 -0400 | [diff] [blame] | 24 | #include "msm_debugfs.h" |
Rob Clark | fde5de6 | 2016-03-15 15:35:08 -0400 | [diff] [blame] | 25 | #include "msm_fence.h" |
Rob Clark | f05c83e | 2018-11-29 10:27:22 -0500 | [diff] [blame] | 26 | #include "msm_gem.h" |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 27 | #include "msm_gpu.h" |
Rob Clark | dd2da6e | 2013-11-30 16:12:10 -0500 | [diff] [blame] | 28 | #include "msm_kms.h" |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 29 | |
Rob Clark | a8d854c | 2016-06-01 14:02:02 -0400 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * MSM driver version: |
| 33 | * - 1.0.0 - initial interface |
| 34 | * - 1.1.0 - adds madvise, and support for submits with > 4 cmd buffers |
Rob Clark | 7a3bcc0 | 2016-09-16 18:37:44 -0400 | [diff] [blame] | 35 | * - 1.2.0 - adds explicit fence support for submit ioctl |
Jordan Crouse | f7de154 | 2017-10-20 11:06:55 -0600 | [diff] [blame] | 36 | * - 1.3.0 - adds GMEM_BASE + NR_RINGS params, SUBMITQUEUE_NEW + |
| 37 | * SUBMITQUEUE_CLOSE ioctls, and MSM_INFO_IOVA flag for |
| 38 | * MSM_GEM_INFO ioctl. |
Rob Clark | 1fed8df | 2018-11-29 10:30:04 -0500 | [diff] [blame] | 39 | * - 1.4.0 - softpin, MSM_RELOC_BO_DUMP, and GEM_INFO support to set/get |
| 40 | * GEM object's debug name |
Rob Clark | a8d854c | 2016-06-01 14:02:02 -0400 | [diff] [blame] | 41 | */ |
| 42 | #define MSM_VERSION_MAJOR 1 |
Rob Clark | 1fed8df | 2018-11-29 10:30:04 -0500 | [diff] [blame] | 43 | #define MSM_VERSION_MINOR 4 |
Rob Clark | a8d854c | 2016-06-01 14:02:02 -0400 | [diff] [blame] | 44 | #define MSM_VERSION_PATCHLEVEL 0 |
| 45 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 46 | static const struct drm_mode_config_funcs mode_config_funcs = { |
| 47 | .fb_create = msm_framebuffer_create, |
Noralf Trønnes | 4ccbc6e | 2017-12-05 19:24:59 +0100 | [diff] [blame] | 48 | .output_poll_changed = drm_fb_helper_output_poll_changed, |
Rob Clark | 1f92017 | 2017-10-25 12:30:51 -0400 | [diff] [blame] | 49 | .atomic_check = drm_atomic_helper_check, |
Sean Paul | d14659f | 2018-02-28 14:19:05 -0500 | [diff] [blame] | 50 | .atomic_commit = drm_atomic_helper_commit, |
| 51 | }; |
| 52 | |
| 53 | static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = { |
| 54 | .atomic_commit_tail = msm_atomic_commit_tail, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 55 | }; |
| 56 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 57 | #ifdef CONFIG_DRM_MSM_REGISTER_LOGGING |
| 58 | static bool reglog = false; |
| 59 | MODULE_PARM_DESC(reglog, "Enable register read/write logging"); |
| 60 | module_param(reglog, bool, 0600); |
| 61 | #else |
| 62 | #define reglog 0 |
| 63 | #endif |
| 64 | |
Archit Taneja | a9ee34b | 2015-07-13 12:12:07 +0530 | [diff] [blame] | 65 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Rob Clark | e90dfec | 2015-01-30 17:05:41 -0500 | [diff] [blame] | 66 | static bool fbdev = true; |
| 67 | MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer"); |
| 68 | module_param(fbdev, bool, 0600); |
| 69 | #endif |
| 70 | |
Rob Clark | 3a10ba8 | 2014-09-08 14:24:57 -0400 | [diff] [blame] | 71 | static char *vram = "16m"; |
Rob Clark | 4313c744 | 2016-02-03 14:02:04 -0500 | [diff] [blame] | 72 | MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)"); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 73 | module_param(vram, charp, 0); |
| 74 | |
Rob Clark | 06d9f56 | 2016-11-05 11:08:12 -0400 | [diff] [blame] | 75 | bool dumpstate = false; |
| 76 | MODULE_PARM_DESC(dumpstate, "Dump KMS state on errors"); |
| 77 | module_param(dumpstate, bool, 0600); |
| 78 | |
Rob Clark | ba4dd71 | 2017-07-06 16:33:44 -0400 | [diff] [blame] | 79 | static bool modeset = true; |
| 80 | MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disable)"); |
| 81 | module_param(modeset, bool, 0600); |
| 82 | |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 83 | /* |
| 84 | * Util/helpers: |
| 85 | */ |
| 86 | |
Jordan Crouse | 8e54eea | 2018-08-06 11:33:21 -0600 | [diff] [blame] | 87 | int msm_clk_bulk_get(struct device *dev, struct clk_bulk_data **bulk) |
| 88 | { |
| 89 | struct property *prop; |
| 90 | const char *name; |
| 91 | struct clk_bulk_data *local; |
| 92 | int i = 0, ret, count; |
| 93 | |
| 94 | count = of_property_count_strings(dev->of_node, "clock-names"); |
| 95 | if (count < 1) |
| 96 | return 0; |
| 97 | |
| 98 | local = devm_kcalloc(dev, sizeof(struct clk_bulk_data *), |
| 99 | count, GFP_KERNEL); |
| 100 | if (!local) |
| 101 | return -ENOMEM; |
| 102 | |
| 103 | of_property_for_each_string(dev->of_node, "clock-names", prop, name) { |
| 104 | local[i].id = devm_kstrdup(dev, name, GFP_KERNEL); |
| 105 | if (!local[i].id) { |
| 106 | devm_kfree(dev, local); |
| 107 | return -ENOMEM; |
| 108 | } |
| 109 | |
| 110 | i++; |
| 111 | } |
| 112 | |
| 113 | ret = devm_clk_bulk_get(dev, count, local); |
| 114 | |
| 115 | if (ret) { |
| 116 | for (i = 0; i < count; i++) |
| 117 | devm_kfree(dev, (void *) local[i].id); |
| 118 | devm_kfree(dev, local); |
| 119 | |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | *bulk = local; |
| 124 | return count; |
| 125 | } |
| 126 | |
| 127 | struct clk *msm_clk_bulk_get_clock(struct clk_bulk_data *bulk, int count, |
| 128 | const char *name) |
| 129 | { |
| 130 | int i; |
| 131 | char n[32]; |
| 132 | |
| 133 | snprintf(n, sizeof(n), "%s_clk", name); |
| 134 | |
| 135 | for (i = 0; bulk && i < count; i++) { |
| 136 | if (!strcmp(bulk[i].id, name) || !strcmp(bulk[i].id, n)) |
| 137 | return bulk[i].clk; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | return NULL; |
| 142 | } |
| 143 | |
Rob Clark | 720c3bb | 2017-01-30 11:30:58 -0500 | [diff] [blame] | 144 | struct clk *msm_clk_get(struct platform_device *pdev, const char *name) |
| 145 | { |
| 146 | struct clk *clk; |
| 147 | char name2[32]; |
| 148 | |
| 149 | clk = devm_clk_get(&pdev->dev, name); |
| 150 | if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER) |
| 151 | return clk; |
| 152 | |
| 153 | snprintf(name2, sizeof(name2), "%s_clk", name); |
| 154 | |
| 155 | clk = devm_clk_get(&pdev->dev, name2); |
| 156 | if (!IS_ERR(clk)) |
| 157 | dev_warn(&pdev->dev, "Using legacy clk name binding. Use " |
| 158 | "\"%s\" instead of \"%s\"\n", name, name2); |
| 159 | |
| 160 | return clk; |
| 161 | } |
| 162 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 163 | void __iomem *msm_ioremap(struct platform_device *pdev, const char *name, |
| 164 | const char *dbgname) |
| 165 | { |
| 166 | struct resource *res; |
| 167 | unsigned long size; |
| 168 | void __iomem *ptr; |
| 169 | |
| 170 | if (name) |
| 171 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); |
| 172 | else |
| 173 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 174 | |
| 175 | if (!res) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 176 | DRM_DEV_ERROR(&pdev->dev, "failed to get memory resource: %s\n", name); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 177 | return ERR_PTR(-EINVAL); |
| 178 | } |
| 179 | |
| 180 | size = resource_size(res); |
| 181 | |
| 182 | ptr = devm_ioremap_nocache(&pdev->dev, res->start, size); |
| 183 | if (!ptr) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 184 | DRM_DEV_ERROR(&pdev->dev, "failed to ioremap: %s\n", name); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 185 | return ERR_PTR(-ENOMEM); |
| 186 | } |
| 187 | |
| 188 | if (reglog) |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 189 | printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 190 | |
| 191 | return ptr; |
| 192 | } |
| 193 | |
| 194 | void msm_writel(u32 data, void __iomem *addr) |
| 195 | { |
| 196 | if (reglog) |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 197 | printk(KERN_DEBUG "IO:W %p %08x\n", addr, data); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 198 | writel(data, addr); |
| 199 | } |
| 200 | |
| 201 | u32 msm_readl(const void __iomem *addr) |
| 202 | { |
| 203 | u32 val = readl(addr); |
| 204 | if (reglog) |
Joe Perches | 8dfe162 | 2017-02-28 04:55:54 -0800 | [diff] [blame] | 205 | pr_err("IO:R %p %08x\n", addr, val); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 206 | return val; |
| 207 | } |
| 208 | |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 209 | struct vblank_event { |
| 210 | struct list_head node; |
| 211 | int crtc_id; |
| 212 | bool enable; |
| 213 | }; |
| 214 | |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 215 | static void vblank_ctrl_worker(struct kthread_work *work) |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 216 | { |
| 217 | struct msm_vblank_ctrl *vbl_ctrl = container_of(work, |
| 218 | struct msm_vblank_ctrl, work); |
| 219 | struct msm_drm_private *priv = container_of(vbl_ctrl, |
| 220 | struct msm_drm_private, vblank_ctrl); |
| 221 | struct msm_kms *kms = priv->kms; |
| 222 | struct vblank_event *vbl_ev, *tmp; |
| 223 | unsigned long flags; |
| 224 | |
| 225 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 226 | list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) { |
| 227 | list_del(&vbl_ev->node); |
| 228 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 229 | |
| 230 | if (vbl_ev->enable) |
| 231 | kms->funcs->enable_vblank(kms, |
| 232 | priv->crtcs[vbl_ev->crtc_id]); |
| 233 | else |
| 234 | kms->funcs->disable_vblank(kms, |
| 235 | priv->crtcs[vbl_ev->crtc_id]); |
| 236 | |
| 237 | kfree(vbl_ev); |
| 238 | |
| 239 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 240 | } |
| 241 | |
| 242 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 243 | } |
| 244 | |
| 245 | static int vblank_ctrl_queue_work(struct msm_drm_private *priv, |
| 246 | int crtc_id, bool enable) |
| 247 | { |
| 248 | struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl; |
| 249 | struct vblank_event *vbl_ev; |
| 250 | unsigned long flags; |
| 251 | |
| 252 | vbl_ev = kzalloc(sizeof(*vbl_ev), GFP_ATOMIC); |
| 253 | if (!vbl_ev) |
| 254 | return -ENOMEM; |
| 255 | |
| 256 | vbl_ev->crtc_id = crtc_id; |
| 257 | vbl_ev->enable = enable; |
| 258 | |
| 259 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 260 | list_add_tail(&vbl_ev->node, &vbl_ctrl->event_list); |
| 261 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 262 | |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 263 | kthread_queue_work(&priv->disp_thread[crtc_id].worker, |
| 264 | &vbl_ctrl->work); |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 269 | static int msm_drm_uninit(struct device *dev) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 270 | { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 271 | struct platform_device *pdev = to_platform_device(dev); |
| 272 | struct drm_device *ddev = platform_get_drvdata(pdev); |
| 273 | struct msm_drm_private *priv = ddev->dev_private; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 274 | struct msm_kms *kms = priv->kms; |
Rajesh Yadav | bc3220b | 2018-06-21 16:06:10 -0400 | [diff] [blame] | 275 | struct msm_mdss *mdss = priv->mdss; |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 276 | struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl; |
| 277 | struct vblank_event *vbl_ev, *tmp; |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 278 | int i; |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 279 | |
| 280 | /* We must cancel and cleanup any pending vblank enable/disable |
| 281 | * work before drm_irq_uninstall() to avoid work re-enabling an |
| 282 | * irq after uninstall has disabled it. |
| 283 | */ |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 284 | kthread_flush_work(&vbl_ctrl->work); |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 285 | list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) { |
| 286 | list_del(&vbl_ev->node); |
| 287 | kfree(vbl_ev); |
| 288 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 289 | |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 290 | /* clean up display commit/event worker threads */ |
| 291 | for (i = 0; i < priv->num_crtcs; i++) { |
| 292 | if (priv->disp_thread[i].thread) { |
| 293 | kthread_flush_worker(&priv->disp_thread[i].worker); |
| 294 | kthread_stop(priv->disp_thread[i].thread); |
| 295 | priv->disp_thread[i].thread = NULL; |
| 296 | } |
| 297 | |
| 298 | if (priv->event_thread[i].thread) { |
| 299 | kthread_flush_worker(&priv->event_thread[i].worker); |
| 300 | kthread_stop(priv->event_thread[i].thread); |
| 301 | priv->event_thread[i].thread = NULL; |
| 302 | } |
| 303 | } |
| 304 | |
Rob Clark | 6820939 | 2016-05-17 16:19:32 -0400 | [diff] [blame] | 305 | msm_gem_shrinker_cleanup(ddev); |
| 306 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 307 | drm_kms_helper_poll_fini(ddev); |
Archit Taneja | 1aaa57f | 2016-02-25 11:19:45 +0530 | [diff] [blame] | 308 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 309 | drm_dev_unregister(ddev); |
Archit Taneja | 8208ed9 | 2016-05-02 11:05:53 +0530 | [diff] [blame] | 310 | |
Noralf Trønnes | 85eac47 | 2017-03-07 21:49:22 +0100 | [diff] [blame] | 311 | msm_perf_debugfs_cleanup(priv); |
| 312 | msm_rd_debugfs_cleanup(priv); |
| 313 | |
Archit Taneja | 1aaa57f | 2016-02-25 11:19:45 +0530 | [diff] [blame] | 314 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
| 315 | if (fbdev && priv->fbdev) |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 316 | msm_fbdev_free(ddev); |
Archit Taneja | 1aaa57f | 2016-02-25 11:19:45 +0530 | [diff] [blame] | 317 | #endif |
Daniel Vetter | 3ea4b1e | 2018-10-04 22:24:36 +0200 | [diff] [blame] | 318 | drm_atomic_helper_shutdown(ddev); |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 319 | drm_mode_config_cleanup(ddev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 320 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 321 | pm_runtime_get_sync(dev); |
| 322 | drm_irq_uninstall(ddev); |
| 323 | pm_runtime_put_sync(dev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 324 | |
| 325 | flush_workqueue(priv->wq); |
| 326 | destroy_workqueue(priv->wq); |
| 327 | |
Archit Taneja | 1697608 | 2016-11-03 17:36:18 +0530 | [diff] [blame] | 328 | if (kms && kms->funcs) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 329 | kms->funcs->destroy(kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 330 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 331 | if (priv->vram.paddr) { |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 332 | unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING; |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 333 | drm_mm_takedown(&priv->vram.mm); |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 334 | dma_free_attrs(dev, priv->vram.size, NULL, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 335 | priv->vram.paddr, attrs); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 336 | } |
| 337 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 338 | component_unbind_all(dev, ddev); |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 339 | |
Rajesh Yadav | bc3220b | 2018-06-21 16:06:10 -0400 | [diff] [blame] | 340 | if (mdss && mdss->funcs) |
| 341 | mdss->funcs->destroy(ddev); |
Archit Taneja | 0a6030d | 2016-05-08 21:36:28 +0530 | [diff] [blame] | 342 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 343 | ddev->dev_private = NULL; |
Thomas Zimmermann | 4d8dc2d | 2018-09-26 13:48:59 +0200 | [diff] [blame] | 344 | drm_dev_put(ddev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 345 | |
| 346 | kfree(priv); |
| 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
Jeykumar Sankaran | aaded2e | 2018-06-27 14:26:24 -0400 | [diff] [blame] | 351 | #define KMS_MDP4 4 |
| 352 | #define KMS_MDP5 5 |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 353 | #define KMS_DPU 3 |
Jeykumar Sankaran | aaded2e | 2018-06-27 14:26:24 -0400 | [diff] [blame] | 354 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 355 | static int get_mdp_ver(struct platform_device *pdev) |
| 356 | { |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 357 | struct device *dev = &pdev->dev; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 358 | |
| 359 | return (int) (unsigned long) of_device_get_match_data(dev); |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 360 | } |
| 361 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 362 | #include <linux/of_address.h> |
| 363 | |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 364 | static int msm_init_vram(struct drm_device *dev) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 365 | { |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 366 | struct msm_drm_private *priv = dev->dev_private; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 367 | struct device_node *node; |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 368 | unsigned long size = 0; |
| 369 | int ret = 0; |
| 370 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 371 | /* In the device-tree world, we could have a 'memory-region' |
| 372 | * phandle, which gives us a link to our "vram". Allocating |
| 373 | * is all nicely abstracted behind the dma api, but we need |
| 374 | * to know the entire size to allocate it all in one go. There |
| 375 | * are two cases: |
| 376 | * 1) device with no IOMMU, in which case we need exclusive |
| 377 | * access to a VRAM carveout big enough for all gpu |
| 378 | * buffers |
| 379 | * 2) device with IOMMU, but where the bootloader puts up |
| 380 | * a splash screen. In this case, the VRAM carveout |
| 381 | * need only be large enough for fbdev fb. But we need |
| 382 | * exclusive access to the buffer to avoid the kernel |
| 383 | * using those pages for other purposes (which appears |
| 384 | * as corruption on screen before we have a chance to |
| 385 | * load and do initial modeset) |
| 386 | */ |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 387 | |
| 388 | node = of_parse_phandle(dev->dev->of_node, "memory-region", 0); |
| 389 | if (node) { |
| 390 | struct resource r; |
| 391 | ret = of_address_to_resource(node, 0, &r); |
Peter Chen | 2ca41c17 | 2016-07-04 16:49:50 +0800 | [diff] [blame] | 392 | of_node_put(node); |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 393 | if (ret) |
| 394 | return ret; |
| 395 | size = r.end - r.start; |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 396 | DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 397 | |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 398 | /* if we have no IOMMU, then we need to use carveout allocator. |
| 399 | * Grab the entire CMA chunk carved out in early startup in |
| 400 | * mach-msm: |
| 401 | */ |
| 402 | } else if (!iommu_present(&platform_bus_type)) { |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 403 | DRM_INFO("using %s VRAM carveout\n", vram); |
| 404 | size = memparse(vram, NULL); |
| 405 | } |
| 406 | |
| 407 | if (size) { |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 408 | unsigned long attrs = 0; |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 409 | void *p; |
| 410 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 411 | priv->vram.size = size; |
| 412 | |
| 413 | drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1); |
Sushmita Susheelendra | 0e08270 | 2017-06-13 16:52:54 -0600 | [diff] [blame] | 414 | spin_lock_init(&priv->vram.lock); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 415 | |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 416 | attrs |= DMA_ATTR_NO_KERNEL_MAPPING; |
| 417 | attrs |= DMA_ATTR_WRITE_COMBINE; |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 418 | |
| 419 | /* note that for no-kernel-mapping, the vaddr returned |
| 420 | * is bogus, but non-null if allocation succeeded: |
| 421 | */ |
| 422 | p = dma_alloc_attrs(dev->dev, size, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 423 | &priv->vram.paddr, GFP_KERNEL, attrs); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 424 | if (!p) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 425 | DRM_DEV_ERROR(dev->dev, "failed to allocate VRAM\n"); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 426 | priv->vram.paddr = 0; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 427 | return -ENOMEM; |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 428 | } |
| 429 | |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 430 | DRM_DEV_INFO(dev->dev, "VRAM: %08x->%08x\n", |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 431 | (uint32_t)priv->vram.paddr, |
| 432 | (uint32_t)(priv->vram.paddr + size)); |
| 433 | } |
| 434 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 435 | return ret; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 438 | static int msm_drm_init(struct device *dev, struct drm_driver *drv) |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 439 | { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 440 | struct platform_device *pdev = to_platform_device(dev); |
| 441 | struct drm_device *ddev; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 442 | struct msm_drm_private *priv; |
| 443 | struct msm_kms *kms; |
Rajesh Yadav | bc3220b | 2018-06-21 16:06:10 -0400 | [diff] [blame] | 444 | struct msm_mdss *mdss; |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 445 | int ret, i; |
| 446 | struct sched_param param; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 447 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 448 | ddev = drm_dev_alloc(drv, dev); |
Tom Gundersen | 0f28860 | 2016-09-21 16:59:19 +0200 | [diff] [blame] | 449 | if (IS_ERR(ddev)) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 450 | DRM_DEV_ERROR(dev, "failed to allocate drm_device\n"); |
Tom Gundersen | 0f28860 | 2016-09-21 16:59:19 +0200 | [diff] [blame] | 451 | return PTR_ERR(ddev); |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 452 | } |
| 453 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 454 | platform_set_drvdata(pdev, ddev); |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 455 | |
| 456 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 457 | if (!priv) { |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 458 | ret = -ENOMEM; |
Thomas Zimmermann | 4d8dc2d | 2018-09-26 13:48:59 +0200 | [diff] [blame] | 459 | goto err_put_drm_dev; |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | ddev->dev_private = priv; |
Rob Clark | 6820939 | 2016-05-17 16:19:32 -0400 | [diff] [blame] | 463 | priv->dev = ddev; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 464 | |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 465 | switch (get_mdp_ver(pdev)) { |
| 466 | case KMS_MDP5: |
| 467 | ret = mdp5_mdss_init(ddev); |
| 468 | break; |
| 469 | case KMS_DPU: |
| 470 | ret = dpu_mdss_init(ddev); |
| 471 | break; |
| 472 | default: |
| 473 | ret = 0; |
| 474 | break; |
| 475 | } |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 476 | if (ret) |
| 477 | goto err_free_priv; |
Archit Taneja | 0a6030d | 2016-05-08 21:36:28 +0530 | [diff] [blame] | 478 | |
Rajesh Yadav | bc3220b | 2018-06-21 16:06:10 -0400 | [diff] [blame] | 479 | mdss = priv->mdss; |
| 480 | |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 481 | priv->wq = alloc_ordered_workqueue("msm", 0); |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 482 | |
| 483 | INIT_LIST_HEAD(&priv->inactive_list); |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 484 | INIT_LIST_HEAD(&priv->vblank_ctrl.event_list); |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 485 | kthread_init_work(&priv->vblank_ctrl.work, vblank_ctrl_worker); |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 486 | spin_lock_init(&priv->vblank_ctrl.lock); |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 487 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 488 | drm_mode_config_init(ddev); |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 489 | |
| 490 | /* Bind all our sub-components: */ |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 491 | ret = component_bind_all(dev, ddev); |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 492 | if (ret) |
| 493 | goto err_destroy_mdss; |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 494 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 495 | ret = msm_init_vram(ddev); |
Rob Clark | 13f1556 | 2015-05-07 15:20:13 -0400 | [diff] [blame] | 496 | if (ret) |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 497 | goto err_msm_uninit; |
Rob Clark | 13f1556 | 2015-05-07 15:20:13 -0400 | [diff] [blame] | 498 | |
Rob Clark | 6820939 | 2016-05-17 16:19:32 -0400 | [diff] [blame] | 499 | msm_gem_shrinker_init(ddev); |
| 500 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 501 | switch (get_mdp_ver(pdev)) { |
Jeykumar Sankaran | aaded2e | 2018-06-27 14:26:24 -0400 | [diff] [blame] | 502 | case KMS_MDP4: |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 503 | kms = mdp4_kms_init(ddev); |
Archit Taneja | 0a6030d | 2016-05-08 21:36:28 +0530 | [diff] [blame] | 504 | priv->kms = kms; |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 505 | break; |
Jeykumar Sankaran | aaded2e | 2018-06-27 14:26:24 -0400 | [diff] [blame] | 506 | case KMS_MDP5: |
Archit Taneja | 392ae6e | 2016-06-14 18:24:54 +0530 | [diff] [blame] | 507 | kms = mdp5_kms_init(ddev); |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 508 | break; |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 509 | case KMS_DPU: |
| 510 | kms = dpu_kms_init(ddev); |
| 511 | priv->kms = kms; |
| 512 | break; |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 513 | default: |
| 514 | kms = ERR_PTR(-ENODEV); |
| 515 | break; |
| 516 | } |
| 517 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 518 | if (IS_ERR(kms)) { |
| 519 | /* |
| 520 | * NOTE: once we have GPU support, having no kms should not |
| 521 | * be considered fatal.. ideally we would still support gpu |
| 522 | * and (for example) use dmabuf/prime to share buffers with |
| 523 | * imx drm driver on iMX5 |
| 524 | */ |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 525 | DRM_DEV_ERROR(dev, "failed to load kms\n"); |
Thomas Meyer | e4826a9 | 2013-09-16 23:19:54 +0200 | [diff] [blame] | 526 | ret = PTR_ERR(kms); |
Jonathan Marek | b2ccfdf | 2018-11-21 20:52:35 -0500 | [diff] [blame^] | 527 | priv->kms = NULL; |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 528 | goto err_msm_uninit; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 529 | } |
| 530 | |
Jeykumar Sankaran | bb676df | 2018-06-11 14:13:20 -0700 | [diff] [blame] | 531 | /* Enable normalization of plane zpos */ |
| 532 | ddev->mode_config.normalize_zpos = true; |
| 533 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 534 | if (kms) { |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 535 | ret = kms->funcs->hw_init(kms); |
| 536 | if (ret) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 537 | DRM_DEV_ERROR(dev, "kms hw init failed: %d\n", ret); |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 538 | goto err_msm_uninit; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 542 | ddev->mode_config.funcs = &mode_config_funcs; |
Sean Paul | d14659f | 2018-02-28 14:19:05 -0500 | [diff] [blame] | 543 | ddev->mode_config.helper_private = &mode_config_helper_funcs; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 544 | |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 545 | /** |
| 546 | * this priority was found during empiric testing to have appropriate |
| 547 | * realtime scheduling to process display updates and interact with |
| 548 | * other real time and normal priority task |
| 549 | */ |
| 550 | param.sched_priority = 16; |
| 551 | for (i = 0; i < priv->num_crtcs; i++) { |
| 552 | |
| 553 | /* initialize display thread */ |
| 554 | priv->disp_thread[i].crtc_id = priv->crtcs[i]->base.id; |
| 555 | kthread_init_worker(&priv->disp_thread[i].worker); |
| 556 | priv->disp_thread[i].dev = ddev; |
| 557 | priv->disp_thread[i].thread = |
| 558 | kthread_run(kthread_worker_fn, |
| 559 | &priv->disp_thread[i].worker, |
| 560 | "crtc_commit:%d", priv->disp_thread[i].crtc_id); |
| 561 | ret = sched_setscheduler(priv->disp_thread[i].thread, |
| 562 | SCHED_FIFO, ¶m); |
| 563 | if (ret) |
| 564 | pr_warn("display thread priority update failed: %d\n", |
| 565 | ret); |
| 566 | |
| 567 | if (IS_ERR(priv->disp_thread[i].thread)) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 568 | DRM_DEV_ERROR(dev, "failed to create crtc_commit kthread\n"); |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 569 | priv->disp_thread[i].thread = NULL; |
| 570 | } |
| 571 | |
| 572 | /* initialize event thread */ |
| 573 | priv->event_thread[i].crtc_id = priv->crtcs[i]->base.id; |
| 574 | kthread_init_worker(&priv->event_thread[i].worker); |
| 575 | priv->event_thread[i].dev = ddev; |
| 576 | priv->event_thread[i].thread = |
| 577 | kthread_run(kthread_worker_fn, |
| 578 | &priv->event_thread[i].worker, |
| 579 | "crtc_event:%d", priv->event_thread[i].crtc_id); |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 580 | |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 581 | /** |
| 582 | * event thread should also run at same priority as disp_thread |
| 583 | * because it is handling frame_done events. A lower priority |
| 584 | * event thread and higher priority disp_thread can causes |
| 585 | * frame_pending counters beyond 2. This can lead to commit |
| 586 | * failure at crtc commit level. |
| 587 | */ |
| 588 | ret = sched_setscheduler(priv->event_thread[i].thread, |
| 589 | SCHED_FIFO, ¶m); |
| 590 | if (ret) |
| 591 | pr_warn("display event thread priority update failed: %d\n", |
| 592 | ret); |
| 593 | |
| 594 | if (IS_ERR(priv->event_thread[i].thread)) { |
| 595 | dev_err(dev, "failed to create crtc_event kthread\n"); |
| 596 | priv->event_thread[i].thread = NULL; |
| 597 | } |
| 598 | |
| 599 | if ((!priv->disp_thread[i].thread) || |
| 600 | !priv->event_thread[i].thread) { |
| 601 | /* clean up previously created threads if any */ |
| 602 | for ( ; i >= 0; i--) { |
| 603 | if (priv->disp_thread[i].thread) { |
| 604 | kthread_stop( |
| 605 | priv->disp_thread[i].thread); |
| 606 | priv->disp_thread[i].thread = NULL; |
| 607 | } |
| 608 | |
| 609 | if (priv->event_thread[i].thread) { |
| 610 | kthread_stop( |
| 611 | priv->event_thread[i].thread); |
| 612 | priv->event_thread[i].thread = NULL; |
| 613 | } |
| 614 | } |
| 615 | goto err_msm_uninit; |
| 616 | } |
| 617 | } |
| 618 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 619 | ret = drm_vblank_init(ddev, priv->num_crtcs); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 620 | if (ret < 0) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 621 | DRM_DEV_ERROR(dev, "failed to initialize vblank\n"); |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 622 | goto err_msm_uninit; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 623 | } |
| 624 | |
Archit Taneja | a2b3a55 | 2016-05-18 15:06:03 +0530 | [diff] [blame] | 625 | if (kms) { |
| 626 | pm_runtime_get_sync(dev); |
| 627 | ret = drm_irq_install(ddev, kms->irq); |
| 628 | pm_runtime_put_sync(dev); |
| 629 | if (ret < 0) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 630 | DRM_DEV_ERROR(dev, "failed to install IRQ handler\n"); |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 631 | goto err_msm_uninit; |
Archit Taneja | a2b3a55 | 2016-05-18 15:06:03 +0530 | [diff] [blame] | 632 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 633 | } |
| 634 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 635 | ret = drm_dev_register(ddev, 0); |
Rob Clark | a7d3c95 | 2014-05-30 14:47:38 -0400 | [diff] [blame] | 636 | if (ret) |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 637 | goto err_msm_uninit; |
Rob Clark | a7d3c95 | 2014-05-30 14:47:38 -0400 | [diff] [blame] | 638 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 639 | drm_mode_config_reset(ddev); |
| 640 | |
| 641 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
| 642 | if (fbdev) |
| 643 | priv->fbdev = msm_fbdev_init(ddev); |
| 644 | #endif |
| 645 | |
| 646 | ret = msm_debugfs_late_init(ddev); |
| 647 | if (ret) |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 648 | goto err_msm_uninit; |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 649 | |
| 650 | drm_kms_helper_poll_init(ddev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 651 | |
| 652 | return 0; |
| 653 | |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 654 | err_msm_uninit: |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 655 | msm_drm_uninit(dev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 656 | return ret; |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 657 | err_destroy_mdss: |
| 658 | if (mdss && mdss->funcs) |
| 659 | mdss->funcs->destroy(ddev); |
| 660 | err_free_priv: |
| 661 | kfree(priv); |
Thomas Zimmermann | 4d8dc2d | 2018-09-26 13:48:59 +0200 | [diff] [blame] | 662 | err_put_drm_dev: |
| 663 | drm_dev_put(ddev); |
Jeykumar Sankaran | 77050c3 | 2018-06-27 14:35:28 -0400 | [diff] [blame] | 664 | return ret; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 665 | } |
| 666 | |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 667 | /* |
| 668 | * DRM operations: |
| 669 | */ |
| 670 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 671 | static void load_gpu(struct drm_device *dev) |
| 672 | { |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 673 | static DEFINE_MUTEX(init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 674 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 675 | |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 676 | mutex_lock(&init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 677 | |
Rob Clark | e2550b7 | 2014-09-05 13:30:27 -0400 | [diff] [blame] | 678 | if (!priv->gpu) |
| 679 | priv->gpu = adreno_load_gpu(dev); |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 680 | |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 681 | mutex_unlock(&init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 682 | } |
| 683 | |
Jordan Crouse | f97deca | 2017-10-20 11:06:57 -0600 | [diff] [blame] | 684 | static int context_init(struct drm_device *dev, struct drm_file *file) |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 685 | { |
| 686 | struct msm_file_private *ctx; |
| 687 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 688 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
| 689 | if (!ctx) |
| 690 | return -ENOMEM; |
| 691 | |
Jordan Crouse | f97deca | 2017-10-20 11:06:57 -0600 | [diff] [blame] | 692 | msm_submitqueue_init(dev, ctx); |
Jordan Crouse | f7de154 | 2017-10-20 11:06:55 -0600 | [diff] [blame] | 693 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 694 | file->driver_priv = ctx; |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
Jordan Crouse | f7de154 | 2017-10-20 11:06:55 -0600 | [diff] [blame] | 699 | static int msm_open(struct drm_device *dev, struct drm_file *file) |
| 700 | { |
| 701 | /* For now, load gpu on open.. to avoid the requirement of having |
| 702 | * firmware in the initrd. |
| 703 | */ |
| 704 | load_gpu(dev); |
| 705 | |
Jordan Crouse | f97deca | 2017-10-20 11:06:57 -0600 | [diff] [blame] | 706 | return context_init(dev, file); |
Jordan Crouse | f7de154 | 2017-10-20 11:06:55 -0600 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | static void context_close(struct msm_file_private *ctx) |
| 710 | { |
| 711 | msm_submitqueue_close(ctx); |
| 712 | kfree(ctx); |
| 713 | } |
| 714 | |
Daniel Vetter | 94df145 | 2017-03-08 15:12:46 +0100 | [diff] [blame] | 715 | static void msm_postclose(struct drm_device *dev, struct drm_file *file) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 716 | { |
| 717 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 718 | struct msm_file_private *ctx = file->driver_priv; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 719 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 720 | mutex_lock(&dev->struct_mutex); |
| 721 | if (ctx == priv->lastctx) |
| 722 | priv->lastctx = NULL; |
| 723 | mutex_unlock(&dev->struct_mutex); |
| 724 | |
Jordan Crouse | f7de154 | 2017-10-20 11:06:55 -0600 | [diff] [blame] | 725 | context_close(ctx); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 726 | } |
| 727 | |
Daniel Vetter | e9f0d76 | 2013-12-11 11:34:42 +0100 | [diff] [blame] | 728 | static irqreturn_t msm_irq(int irq, void *arg) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 729 | { |
| 730 | struct drm_device *dev = arg; |
| 731 | struct msm_drm_private *priv = dev->dev_private; |
| 732 | struct msm_kms *kms = priv->kms; |
| 733 | BUG_ON(!kms); |
| 734 | return kms->funcs->irq(kms); |
| 735 | } |
| 736 | |
| 737 | static void msm_irq_preinstall(struct drm_device *dev) |
| 738 | { |
| 739 | struct msm_drm_private *priv = dev->dev_private; |
| 740 | struct msm_kms *kms = priv->kms; |
| 741 | BUG_ON(!kms); |
| 742 | kms->funcs->irq_preinstall(kms); |
| 743 | } |
| 744 | |
| 745 | static int msm_irq_postinstall(struct drm_device *dev) |
| 746 | { |
| 747 | struct msm_drm_private *priv = dev->dev_private; |
| 748 | struct msm_kms *kms = priv->kms; |
| 749 | BUG_ON(!kms); |
| 750 | return kms->funcs->irq_postinstall(kms); |
| 751 | } |
| 752 | |
| 753 | static void msm_irq_uninstall(struct drm_device *dev) |
| 754 | { |
| 755 | struct msm_drm_private *priv = dev->dev_private; |
| 756 | struct msm_kms *kms = priv->kms; |
| 757 | BUG_ON(!kms); |
| 758 | kms->funcs->irq_uninstall(kms); |
| 759 | } |
| 760 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 761 | static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 762 | { |
| 763 | struct msm_drm_private *priv = dev->dev_private; |
| 764 | struct msm_kms *kms = priv->kms; |
| 765 | if (!kms) |
| 766 | return -ENXIO; |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 767 | DBG("dev=%p, crtc=%u", dev, pipe); |
| 768 | return vblank_ctrl_queue_work(priv, pipe, true); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 769 | } |
| 770 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 771 | static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 772 | { |
| 773 | struct msm_drm_private *priv = dev->dev_private; |
| 774 | struct msm_kms *kms = priv->kms; |
| 775 | if (!kms) |
| 776 | return; |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 777 | DBG("dev=%p, crtc=%u", dev, pipe); |
| 778 | vblank_ctrl_queue_work(priv, pipe, false); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /* |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 782 | * DRM ioctls: |
| 783 | */ |
| 784 | |
| 785 | static int msm_ioctl_get_param(struct drm_device *dev, void *data, |
| 786 | struct drm_file *file) |
| 787 | { |
| 788 | struct msm_drm_private *priv = dev->dev_private; |
| 789 | struct drm_msm_param *args = data; |
| 790 | struct msm_gpu *gpu; |
| 791 | |
| 792 | /* for now, we just have 3d pipe.. eventually this would need to |
| 793 | * be more clever to dispatch to appropriate gpu module: |
| 794 | */ |
| 795 | if (args->pipe != MSM_PIPE_3D0) |
| 796 | return -EINVAL; |
| 797 | |
| 798 | gpu = priv->gpu; |
| 799 | |
| 800 | if (!gpu) |
| 801 | return -ENXIO; |
| 802 | |
| 803 | return gpu->funcs->get_param(gpu, args->param, &args->value); |
| 804 | } |
| 805 | |
| 806 | static int msm_ioctl_gem_new(struct drm_device *dev, void *data, |
| 807 | struct drm_file *file) |
| 808 | { |
| 809 | struct drm_msm_gem_new *args = data; |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 810 | |
| 811 | if (args->flags & ~MSM_BO_FLAGS) { |
| 812 | DRM_ERROR("invalid flags: %08x\n", args->flags); |
| 813 | return -EINVAL; |
| 814 | } |
| 815 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 816 | return msm_gem_new_handle(dev, file, args->size, |
Jordan Crouse | 0815d77 | 2018-11-07 15:35:52 -0700 | [diff] [blame] | 817 | args->flags, &args->handle, NULL); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 818 | } |
| 819 | |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 820 | static inline ktime_t to_ktime(struct drm_msm_timespec timeout) |
| 821 | { |
| 822 | return ktime_set(timeout.tv_sec, timeout.tv_nsec); |
| 823 | } |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 824 | |
| 825 | static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data, |
| 826 | struct drm_file *file) |
| 827 | { |
| 828 | struct drm_msm_gem_cpu_prep *args = data; |
| 829 | struct drm_gem_object *obj; |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 830 | ktime_t timeout = to_ktime(args->timeout); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 831 | int ret; |
| 832 | |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 833 | if (args->op & ~MSM_PREP_FLAGS) { |
| 834 | DRM_ERROR("invalid op: %08x\n", args->op); |
| 835 | return -EINVAL; |
| 836 | } |
| 837 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 838 | obj = drm_gem_object_lookup(file, args->handle); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 839 | if (!obj) |
| 840 | return -ENOENT; |
| 841 | |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 842 | ret = msm_gem_cpu_prep(obj, args->op, &timeout); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 843 | |
Steve Kowalik | dc9a9b3 | 2018-01-26 14:55:54 +1100 | [diff] [blame] | 844 | drm_gem_object_put_unlocked(obj); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 845 | |
| 846 | return ret; |
| 847 | } |
| 848 | |
| 849 | static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data, |
| 850 | struct drm_file *file) |
| 851 | { |
| 852 | struct drm_msm_gem_cpu_fini *args = data; |
| 853 | struct drm_gem_object *obj; |
| 854 | int ret; |
| 855 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 856 | obj = drm_gem_object_lookup(file, args->handle); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 857 | if (!obj) |
| 858 | return -ENOENT; |
| 859 | |
| 860 | ret = msm_gem_cpu_fini(obj); |
| 861 | |
Steve Kowalik | dc9a9b3 | 2018-01-26 14:55:54 +1100 | [diff] [blame] | 862 | drm_gem_object_put_unlocked(obj); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 863 | |
| 864 | return ret; |
| 865 | } |
| 866 | |
Jordan Crouse | 49fd08b | 2017-05-08 14:35:01 -0600 | [diff] [blame] | 867 | static int msm_ioctl_gem_info_iova(struct drm_device *dev, |
| 868 | struct drm_gem_object *obj, uint64_t *iova) |
| 869 | { |
| 870 | struct msm_drm_private *priv = dev->dev_private; |
| 871 | |
| 872 | if (!priv->gpu) |
| 873 | return -EINVAL; |
| 874 | |
Jordan Crouse | 9fe041f | 2018-11-07 15:35:50 -0700 | [diff] [blame] | 875 | /* |
| 876 | * Don't pin the memory here - just get an address so that userspace can |
| 877 | * be productive |
| 878 | */ |
Rob Clark | 8bdcd94 | 2017-06-13 11:07:08 -0400 | [diff] [blame] | 879 | return msm_gem_get_iova(obj, priv->gpu->aspace, iova); |
Jordan Crouse | 49fd08b | 2017-05-08 14:35:01 -0600 | [diff] [blame] | 880 | } |
| 881 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 882 | static int msm_ioctl_gem_info(struct drm_device *dev, void *data, |
| 883 | struct drm_file *file) |
| 884 | { |
| 885 | struct drm_msm_gem_info *args = data; |
| 886 | struct drm_gem_object *obj; |
Rob Clark | f05c83e | 2018-11-29 10:27:22 -0500 | [diff] [blame] | 887 | struct msm_gem_object *msm_obj; |
| 888 | int i, ret = 0; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 889 | |
Rob Clark | 789d2e5 | 2018-11-29 09:54:42 -0500 | [diff] [blame] | 890 | if (args->pad) |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 891 | return -EINVAL; |
| 892 | |
Rob Clark | 789d2e5 | 2018-11-29 09:54:42 -0500 | [diff] [blame] | 893 | switch (args->info) { |
| 894 | case MSM_INFO_GET_OFFSET: |
| 895 | case MSM_INFO_GET_IOVA: |
| 896 | /* value returned as immediate, not pointer, so len==0: */ |
| 897 | if (args->len) |
| 898 | return -EINVAL; |
| 899 | break; |
Rob Clark | f05c83e | 2018-11-29 10:27:22 -0500 | [diff] [blame] | 900 | case MSM_INFO_SET_NAME: |
| 901 | case MSM_INFO_GET_NAME: |
| 902 | break; |
Rob Clark | 789d2e5 | 2018-11-29 09:54:42 -0500 | [diff] [blame] | 903 | default: |
| 904 | return -EINVAL; |
| 905 | } |
| 906 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 907 | obj = drm_gem_object_lookup(file, args->handle); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 908 | if (!obj) |
| 909 | return -ENOENT; |
| 910 | |
Rob Clark | f05c83e | 2018-11-29 10:27:22 -0500 | [diff] [blame] | 911 | msm_obj = to_msm_bo(obj); |
| 912 | |
Rob Clark | 789d2e5 | 2018-11-29 09:54:42 -0500 | [diff] [blame] | 913 | switch (args->info) { |
| 914 | case MSM_INFO_GET_OFFSET: |
| 915 | args->value = msm_gem_mmap_offset(obj); |
| 916 | break; |
| 917 | case MSM_INFO_GET_IOVA: |
| 918 | ret = msm_ioctl_gem_info_iova(dev, obj, &args->value); |
| 919 | break; |
Rob Clark | f05c83e | 2018-11-29 10:27:22 -0500 | [diff] [blame] | 920 | case MSM_INFO_SET_NAME: |
| 921 | /* length check should leave room for terminating null: */ |
| 922 | if (args->len >= sizeof(msm_obj->name)) { |
| 923 | ret = -EINVAL; |
| 924 | break; |
| 925 | } |
| 926 | ret = copy_from_user(msm_obj->name, |
| 927 | u64_to_user_ptr(args->value), args->len); |
| 928 | msm_obj->name[args->len] = '\0'; |
| 929 | for (i = 0; i < args->len; i++) { |
| 930 | if (!isprint(msm_obj->name[i])) { |
| 931 | msm_obj->name[i] = '\0'; |
| 932 | break; |
| 933 | } |
| 934 | } |
| 935 | break; |
| 936 | case MSM_INFO_GET_NAME: |
| 937 | if (args->value && (args->len < strlen(msm_obj->name))) { |
| 938 | ret = -EINVAL; |
| 939 | break; |
| 940 | } |
| 941 | args->len = strlen(msm_obj->name); |
| 942 | if (args->value) { |
| 943 | ret = copy_to_user(u64_to_user_ptr(args->value), |
| 944 | msm_obj->name, args->len); |
| 945 | } |
| 946 | break; |
Jordan Crouse | 49fd08b | 2017-05-08 14:35:01 -0600 | [diff] [blame] | 947 | } |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 948 | |
Steve Kowalik | dc9a9b3 | 2018-01-26 14:55:54 +1100 | [diff] [blame] | 949 | drm_gem_object_put_unlocked(obj); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 950 | |
| 951 | return ret; |
| 952 | } |
| 953 | |
| 954 | static int msm_ioctl_wait_fence(struct drm_device *dev, void *data, |
| 955 | struct drm_file *file) |
| 956 | { |
Rob Clark | ca762a8 | 2016-03-15 17:22:13 -0400 | [diff] [blame] | 957 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 958 | struct drm_msm_wait_fence *args = data; |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 959 | ktime_t timeout = to_ktime(args->timeout); |
Jordan Crouse | f97deca | 2017-10-20 11:06:57 -0600 | [diff] [blame] | 960 | struct msm_gpu_submitqueue *queue; |
| 961 | struct msm_gpu *gpu = priv->gpu; |
| 962 | int ret; |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 963 | |
| 964 | if (args->pad) { |
| 965 | DRM_ERROR("invalid pad: %08x\n", args->pad); |
| 966 | return -EINVAL; |
| 967 | } |
| 968 | |
Jordan Crouse | f97deca | 2017-10-20 11:06:57 -0600 | [diff] [blame] | 969 | if (!gpu) |
Rob Clark | ca762a8 | 2016-03-15 17:22:13 -0400 | [diff] [blame] | 970 | return 0; |
| 971 | |
Jordan Crouse | f97deca | 2017-10-20 11:06:57 -0600 | [diff] [blame] | 972 | queue = msm_submitqueue_get(file->driver_priv, args->queueid); |
| 973 | if (!queue) |
| 974 | return -ENOENT; |
| 975 | |
| 976 | ret = msm_wait_fence(gpu->rb[queue->prio]->fctx, args->fence, &timeout, |
| 977 | true); |
| 978 | |
| 979 | msm_submitqueue_put(queue); |
| 980 | return ret; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 981 | } |
| 982 | |
Rob Clark | 4cd33c4 | 2016-05-17 15:44:49 -0400 | [diff] [blame] | 983 | static int msm_ioctl_gem_madvise(struct drm_device *dev, void *data, |
| 984 | struct drm_file *file) |
| 985 | { |
| 986 | struct drm_msm_gem_madvise *args = data; |
| 987 | struct drm_gem_object *obj; |
| 988 | int ret; |
| 989 | |
| 990 | switch (args->madv) { |
| 991 | case MSM_MADV_DONTNEED: |
| 992 | case MSM_MADV_WILLNEED: |
| 993 | break; |
| 994 | default: |
| 995 | return -EINVAL; |
| 996 | } |
| 997 | |
| 998 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
| 999 | if (ret) |
| 1000 | return ret; |
| 1001 | |
| 1002 | obj = drm_gem_object_lookup(file, args->handle); |
| 1003 | if (!obj) { |
| 1004 | ret = -ENOENT; |
| 1005 | goto unlock; |
| 1006 | } |
| 1007 | |
| 1008 | ret = msm_gem_madvise(obj, args->madv); |
| 1009 | if (ret >= 0) { |
| 1010 | args->retained = ret; |
| 1011 | ret = 0; |
| 1012 | } |
| 1013 | |
Steve Kowalik | dc9a9b3 | 2018-01-26 14:55:54 +1100 | [diff] [blame] | 1014 | drm_gem_object_put(obj); |
Rob Clark | 4cd33c4 | 2016-05-17 15:44:49 -0400 | [diff] [blame] | 1015 | |
| 1016 | unlock: |
| 1017 | mutex_unlock(&dev->struct_mutex); |
| 1018 | return ret; |
| 1019 | } |
| 1020 | |
Jordan Crouse | f7de154 | 2017-10-20 11:06:55 -0600 | [diff] [blame] | 1021 | |
| 1022 | static int msm_ioctl_submitqueue_new(struct drm_device *dev, void *data, |
| 1023 | struct drm_file *file) |
| 1024 | { |
| 1025 | struct drm_msm_submitqueue *args = data; |
| 1026 | |
| 1027 | if (args->flags & ~MSM_SUBMITQUEUE_FLAGS) |
| 1028 | return -EINVAL; |
| 1029 | |
Jordan Crouse | f97deca | 2017-10-20 11:06:57 -0600 | [diff] [blame] | 1030 | return msm_submitqueue_create(dev, file->driver_priv, args->prio, |
Jordan Crouse | f7de154 | 2017-10-20 11:06:55 -0600 | [diff] [blame] | 1031 | args->flags, &args->id); |
| 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | static int msm_ioctl_submitqueue_close(struct drm_device *dev, void *data, |
| 1036 | struct drm_file *file) |
| 1037 | { |
| 1038 | u32 id = *(u32 *) data; |
| 1039 | |
| 1040 | return msm_submitqueue_remove(file->driver_priv, id); |
| 1041 | } |
| 1042 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 1043 | static const struct drm_ioctl_desc msm_ioctls[] = { |
Daniel Vetter | f8c4714 | 2015-09-08 13:56:30 +0200 | [diff] [blame] | 1044 | DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_AUTH|DRM_RENDER_ALLOW), |
| 1045 | DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW), |
| 1046 | DRM_IOCTL_DEF_DRV(MSM_GEM_INFO, msm_ioctl_gem_info, DRM_AUTH|DRM_RENDER_ALLOW), |
| 1047 | DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW), |
| 1048 | DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW), |
| 1049 | DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_AUTH|DRM_RENDER_ALLOW), |
| 1050 | DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_AUTH|DRM_RENDER_ALLOW), |
Rob Clark | 4cd33c4 | 2016-05-17 15:44:49 -0400 | [diff] [blame] | 1051 | DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW), |
Jordan Crouse | f7de154 | 2017-10-20 11:06:55 -0600 | [diff] [blame] | 1052 | DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_NEW, msm_ioctl_submitqueue_new, DRM_AUTH|DRM_RENDER_ALLOW), |
| 1053 | DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_CLOSE, msm_ioctl_submitqueue_close, DRM_AUTH|DRM_RENDER_ALLOW), |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 1054 | }; |
| 1055 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1056 | static const struct vm_operations_struct vm_ops = { |
| 1057 | .fault = msm_gem_fault, |
| 1058 | .open = drm_gem_vm_open, |
| 1059 | .close = drm_gem_vm_close, |
| 1060 | }; |
| 1061 | |
| 1062 | static const struct file_operations fops = { |
| 1063 | .owner = THIS_MODULE, |
| 1064 | .open = drm_open, |
| 1065 | .release = drm_release, |
| 1066 | .unlocked_ioctl = drm_ioctl, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1067 | .compat_ioctl = drm_compat_ioctl, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1068 | .poll = drm_poll, |
| 1069 | .read = drm_read, |
| 1070 | .llseek = no_llseek, |
| 1071 | .mmap = msm_gem_mmap, |
| 1072 | }; |
| 1073 | |
| 1074 | static struct drm_driver msm_driver = { |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 1075 | .driver_features = DRIVER_HAVE_IRQ | |
| 1076 | DRIVER_GEM | |
| 1077 | DRIVER_PRIME | |
Rob Clark | b4b15c8 | 2013-09-28 12:01:25 -0400 | [diff] [blame] | 1078 | DRIVER_RENDER | |
Rob Clark | a5436e1 | 2015-06-04 10:12:22 -0400 | [diff] [blame] | 1079 | DRIVER_ATOMIC | |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 1080 | DRIVER_MODESET, |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 1081 | .open = msm_open, |
Daniel Vetter | 94df145 | 2017-03-08 15:12:46 +0100 | [diff] [blame] | 1082 | .postclose = msm_postclose, |
Noralf Trønnes | 4ccbc6e | 2017-12-05 19:24:59 +0100 | [diff] [blame] | 1083 | .lastclose = drm_fb_helper_lastclose, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1084 | .irq_handler = msm_irq, |
| 1085 | .irq_preinstall = msm_irq_preinstall, |
| 1086 | .irq_postinstall = msm_irq_postinstall, |
| 1087 | .irq_uninstall = msm_irq_uninstall, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1088 | .enable_vblank = msm_enable_vblank, |
| 1089 | .disable_vblank = msm_disable_vblank, |
| 1090 | .gem_free_object = msm_gem_free_object, |
| 1091 | .gem_vm_ops = &vm_ops, |
| 1092 | .dumb_create = msm_gem_dumb_create, |
| 1093 | .dumb_map_offset = msm_gem_dumb_map_offset, |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 1094 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 1095 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 1096 | .gem_prime_export = drm_gem_prime_export, |
| 1097 | .gem_prime_import = drm_gem_prime_import, |
Eric Anholt | 43523eb | 2017-04-12 12:11:58 -0700 | [diff] [blame] | 1098 | .gem_prime_res_obj = msm_gem_prime_res_obj, |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 1099 | .gem_prime_pin = msm_gem_prime_pin, |
| 1100 | .gem_prime_unpin = msm_gem_prime_unpin, |
| 1101 | .gem_prime_get_sg_table = msm_gem_prime_get_sg_table, |
| 1102 | .gem_prime_import_sg_table = msm_gem_prime_import_sg_table, |
| 1103 | .gem_prime_vmap = msm_gem_prime_vmap, |
| 1104 | .gem_prime_vunmap = msm_gem_prime_vunmap, |
Daniel Thompson | 77a147e | 2014-11-12 11:38:14 +0000 | [diff] [blame] | 1105 | .gem_prime_mmap = msm_gem_prime_mmap, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1106 | #ifdef CONFIG_DEBUG_FS |
| 1107 | .debugfs_init = msm_debugfs_init, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1108 | #endif |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 1109 | .ioctls = msm_ioctls, |
Jordan Crouse | 167b606 | 2017-05-08 14:34:59 -0600 | [diff] [blame] | 1110 | .num_ioctls = ARRAY_SIZE(msm_ioctls), |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1111 | .fops = &fops, |
| 1112 | .name = "msm", |
| 1113 | .desc = "MSM Snapdragon DRM", |
| 1114 | .date = "20130625", |
Rob Clark | a8d854c | 2016-06-01 14:02:02 -0400 | [diff] [blame] | 1115 | .major = MSM_VERSION_MAJOR, |
| 1116 | .minor = MSM_VERSION_MINOR, |
| 1117 | .patchlevel = MSM_VERSION_PATCHLEVEL, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1118 | }; |
| 1119 | |
| 1120 | #ifdef CONFIG_PM_SLEEP |
| 1121 | static int msm_pm_suspend(struct device *dev) |
| 1122 | { |
| 1123 | struct drm_device *ddev = dev_get_drvdata(dev); |
Daniel Mack | ec446d0 | 2018-05-28 21:53:38 +0200 | [diff] [blame] | 1124 | struct msm_drm_private *priv = ddev->dev_private; |
Jeykumar Sankaran | 036bfeb | 2018-06-27 15:24:17 -0400 | [diff] [blame] | 1125 | |
Bruce Wang | 3750e78 | 2018-10-05 17:04:01 -0400 | [diff] [blame] | 1126 | if (WARN_ON(priv->pm_state)) |
| 1127 | drm_atomic_state_put(priv->pm_state); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1128 | |
Daniel Mack | ec446d0 | 2018-05-28 21:53:38 +0200 | [diff] [blame] | 1129 | priv->pm_state = drm_atomic_helper_suspend(ddev); |
| 1130 | if (IS_ERR(priv->pm_state)) { |
Bruce Wang | 3750e78 | 2018-10-05 17:04:01 -0400 | [diff] [blame] | 1131 | int ret = PTR_ERR(priv->pm_state); |
| 1132 | DRM_ERROR("Failed to suspend dpu, %d\n", ret); |
| 1133 | return ret; |
Daniel Mack | ec446d0 | 2018-05-28 21:53:38 +0200 | [diff] [blame] | 1134 | } |
| 1135 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | static int msm_pm_resume(struct device *dev) |
| 1140 | { |
| 1141 | struct drm_device *ddev = dev_get_drvdata(dev); |
Daniel Mack | ec446d0 | 2018-05-28 21:53:38 +0200 | [diff] [blame] | 1142 | struct msm_drm_private *priv = ddev->dev_private; |
Bruce Wang | 3750e78 | 2018-10-05 17:04:01 -0400 | [diff] [blame] | 1143 | int ret; |
Jeykumar Sankaran | 036bfeb | 2018-06-27 15:24:17 -0400 | [diff] [blame] | 1144 | |
Bruce Wang | 3750e78 | 2018-10-05 17:04:01 -0400 | [diff] [blame] | 1145 | if (WARN_ON(!priv->pm_state)) |
| 1146 | return -ENOENT; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1147 | |
Bruce Wang | 3750e78 | 2018-10-05 17:04:01 -0400 | [diff] [blame] | 1148 | ret = drm_atomic_helper_resume(ddev, priv->pm_state); |
| 1149 | if (!ret) |
| 1150 | priv->pm_state = NULL; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1151 | |
Bruce Wang | 3750e78 | 2018-10-05 17:04:01 -0400 | [diff] [blame] | 1152 | return ret; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1153 | } |
| 1154 | #endif |
| 1155 | |
Archit Taneja | 774e39e | 2017-07-28 16:17:07 +0530 | [diff] [blame] | 1156 | #ifdef CONFIG_PM |
| 1157 | static int msm_runtime_suspend(struct device *dev) |
| 1158 | { |
| 1159 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 1160 | struct msm_drm_private *priv = ddev->dev_private; |
Rajesh Yadav | bc3220b | 2018-06-21 16:06:10 -0400 | [diff] [blame] | 1161 | struct msm_mdss *mdss = priv->mdss; |
Archit Taneja | 774e39e | 2017-07-28 16:17:07 +0530 | [diff] [blame] | 1162 | |
| 1163 | DBG(""); |
| 1164 | |
Rajesh Yadav | bc3220b | 2018-06-21 16:06:10 -0400 | [diff] [blame] | 1165 | if (mdss && mdss->funcs) |
| 1166 | return mdss->funcs->disable(mdss); |
Archit Taneja | 774e39e | 2017-07-28 16:17:07 +0530 | [diff] [blame] | 1167 | |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | static int msm_runtime_resume(struct device *dev) |
| 1172 | { |
| 1173 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 1174 | struct msm_drm_private *priv = ddev->dev_private; |
Rajesh Yadav | bc3220b | 2018-06-21 16:06:10 -0400 | [diff] [blame] | 1175 | struct msm_mdss *mdss = priv->mdss; |
Archit Taneja | 774e39e | 2017-07-28 16:17:07 +0530 | [diff] [blame] | 1176 | |
| 1177 | DBG(""); |
| 1178 | |
Rajesh Yadav | bc3220b | 2018-06-21 16:06:10 -0400 | [diff] [blame] | 1179 | if (mdss && mdss->funcs) |
| 1180 | return mdss->funcs->enable(mdss); |
Archit Taneja | 774e39e | 2017-07-28 16:17:07 +0530 | [diff] [blame] | 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | #endif |
| 1185 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1186 | static const struct dev_pm_ops msm_pm_ops = { |
| 1187 | SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume) |
Archit Taneja | 774e39e | 2017-07-28 16:17:07 +0530 | [diff] [blame] | 1188 | SET_RUNTIME_PM_OPS(msm_runtime_suspend, msm_runtime_resume, NULL) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1189 | }; |
| 1190 | |
| 1191 | /* |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 1192 | * Componentized driver support: |
| 1193 | */ |
| 1194 | |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 1195 | /* |
| 1196 | * NOTE: duplication of the same code as exynos or imx (or probably any other). |
| 1197 | * so probably some room for some helpers |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 1198 | */ |
| 1199 | static int compare_of(struct device *dev, void *data) |
| 1200 | { |
| 1201 | return dev->of_node == data; |
| 1202 | } |
Rob Clark | 41e6977 | 2013-12-15 16:23:05 -0500 | [diff] [blame] | 1203 | |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1204 | /* |
| 1205 | * Identify what components need to be added by parsing what remote-endpoints |
| 1206 | * our MDP output ports are connected to. In the case of LVDS on MDP4, there |
| 1207 | * is no external component that we need to add since LVDS is within MDP4 |
| 1208 | * itself. |
| 1209 | */ |
| 1210 | static int add_components_mdp(struct device *mdp_dev, |
| 1211 | struct component_match **matchptr) |
| 1212 | { |
| 1213 | struct device_node *np = mdp_dev->of_node; |
| 1214 | struct device_node *ep_node; |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1215 | struct device *master_dev; |
| 1216 | |
| 1217 | /* |
| 1218 | * on MDP4 based platforms, the MDP platform device is the component |
| 1219 | * master that adds other display interface components to itself. |
| 1220 | * |
| 1221 | * on MDP5 based platforms, the MDSS platform device is the component |
| 1222 | * master that adds MDP5 and other display interface components to |
| 1223 | * itself. |
| 1224 | */ |
| 1225 | if (of_device_is_compatible(np, "qcom,mdp4")) |
| 1226 | master_dev = mdp_dev; |
| 1227 | else |
| 1228 | master_dev = mdp_dev->parent; |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1229 | |
| 1230 | for_each_endpoint_of_node(np, ep_node) { |
| 1231 | struct device_node *intf; |
| 1232 | struct of_endpoint ep; |
| 1233 | int ret; |
| 1234 | |
| 1235 | ret = of_graph_parse_endpoint(ep_node, &ep); |
| 1236 | if (ret) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 1237 | DRM_DEV_ERROR(mdp_dev, "unable to parse port endpoint\n"); |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1238 | of_node_put(ep_node); |
| 1239 | return ret; |
| 1240 | } |
| 1241 | |
| 1242 | /* |
| 1243 | * The LCDC/LVDS port on MDP4 is a speacial case where the |
| 1244 | * remote-endpoint isn't a component that we need to add |
| 1245 | */ |
| 1246 | if (of_device_is_compatible(np, "qcom,mdp4") && |
Archit Taneja | d8dd805 | 2016-11-17 12:12:03 +0530 | [diff] [blame] | 1247 | ep.port == 0) |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1248 | continue; |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1249 | |
| 1250 | /* |
| 1251 | * It's okay if some of the ports don't have a remote endpoint |
| 1252 | * specified. It just means that the port isn't connected to |
| 1253 | * any external interface. |
| 1254 | */ |
| 1255 | intf = of_graph_get_remote_port_parent(ep_node); |
Archit Taneja | d8dd805 | 2016-11-17 12:12:03 +0530 | [diff] [blame] | 1256 | if (!intf) |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1257 | continue; |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1258 | |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 1259 | drm_of_component_match_add(master_dev, matchptr, compare_of, |
| 1260 | intf); |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1261 | of_node_put(intf); |
Archit Taneja | 812070e | 2016-05-19 10:38:39 +0530 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1267 | static int compare_name_mdp(struct device *dev, void *data) |
| 1268 | { |
| 1269 | return (strstr(dev_name(dev), "mdp") != NULL); |
| 1270 | } |
| 1271 | |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 1272 | static int add_display_components(struct device *dev, |
| 1273 | struct component_match **matchptr) |
| 1274 | { |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1275 | struct device *mdp_dev; |
| 1276 | int ret; |
| 1277 | |
| 1278 | /* |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 1279 | * MDP5/DPU based devices don't have a flat hierarchy. There is a top |
| 1280 | * level parent: MDSS, and children: MDP5/DPU, DSI, HDMI, eDP etc. |
| 1281 | * Populate the children devices, find the MDP5/DPU node, and then add |
| 1282 | * the interfaces to our components list. |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1283 | */ |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 1284 | if (of_device_is_compatible(dev->of_node, "qcom,mdss") || |
| 1285 | of_device_is_compatible(dev->of_node, "qcom,sdm845-mdss")) { |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1286 | ret = of_platform_populate(dev->of_node, NULL, NULL, dev); |
| 1287 | if (ret) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 1288 | DRM_DEV_ERROR(dev, "failed to populate children devices\n"); |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1289 | return ret; |
| 1290 | } |
| 1291 | |
| 1292 | mdp_dev = device_find_child(dev, NULL, compare_name_mdp); |
| 1293 | if (!mdp_dev) { |
Mamta Shukla | 6a41da1 | 2018-10-20 23:19:26 +0530 | [diff] [blame] | 1294 | DRM_DEV_ERROR(dev, "failed to find MDSS MDP node\n"); |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1295 | of_platform_depopulate(dev); |
| 1296 | return -ENODEV; |
| 1297 | } |
| 1298 | |
| 1299 | put_device(mdp_dev); |
| 1300 | |
| 1301 | /* add the MDP component itself */ |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 1302 | drm_of_component_match_add(dev, matchptr, compare_of, |
| 1303 | mdp_dev->of_node); |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1304 | } else { |
| 1305 | /* MDP4 */ |
| 1306 | mdp_dev = dev; |
| 1307 | } |
| 1308 | |
| 1309 | ret = add_components_mdp(mdp_dev, matchptr); |
| 1310 | if (ret) |
| 1311 | of_platform_depopulate(dev); |
| 1312 | |
| 1313 | return ret; |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 1314 | } |
| 1315 | |
Archit Taneja | dc3ea26 | 2016-05-19 13:33:52 +0530 | [diff] [blame] | 1316 | /* |
| 1317 | * We don't know what's the best binding to link the gpu with the drm device. |
| 1318 | * Fow now, we just hunt for all the possible gpus that we support, and add them |
| 1319 | * as components. |
| 1320 | */ |
| 1321 | static const struct of_device_id msm_gpu_match[] = { |
Rob Clark | 1db7afa | 2017-01-30 11:02:27 -0500 | [diff] [blame] | 1322 | { .compatible = "qcom,adreno" }, |
Archit Taneja | dc3ea26 | 2016-05-19 13:33:52 +0530 | [diff] [blame] | 1323 | { .compatible = "qcom,adreno-3xx" }, |
| 1324 | { .compatible = "qcom,kgsl-3d0" }, |
| 1325 | { }, |
| 1326 | }; |
| 1327 | |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 1328 | static int add_gpu_components(struct device *dev, |
| 1329 | struct component_match **matchptr) |
| 1330 | { |
Archit Taneja | dc3ea26 | 2016-05-19 13:33:52 +0530 | [diff] [blame] | 1331 | struct device_node *np; |
| 1332 | |
| 1333 | np = of_find_matching_node(NULL, msm_gpu_match); |
| 1334 | if (!np) |
| 1335 | return 0; |
| 1336 | |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 1337 | drm_of_component_match_add(dev, matchptr, compare_of, np); |
Archit Taneja | dc3ea26 | 2016-05-19 13:33:52 +0530 | [diff] [blame] | 1338 | |
| 1339 | of_node_put(np); |
| 1340 | |
| 1341 | return 0; |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 1342 | } |
| 1343 | |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 1344 | static int msm_drm_bind(struct device *dev) |
| 1345 | { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 1346 | return msm_drm_init(dev, &msm_driver); |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | static void msm_drm_unbind(struct device *dev) |
| 1350 | { |
Archit Taneja | 2b66987 | 2016-05-02 11:05:54 +0530 | [diff] [blame] | 1351 | msm_drm_uninit(dev); |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | static const struct component_master_ops msm_drm_ops = { |
| 1355 | .bind = msm_drm_bind, |
| 1356 | .unbind = msm_drm_unbind, |
| 1357 | }; |
| 1358 | |
| 1359 | /* |
| 1360 | * Platform driver: |
| 1361 | */ |
| 1362 | |
| 1363 | static int msm_pdev_probe(struct platform_device *pdev) |
| 1364 | { |
| 1365 | struct component_match *match = NULL; |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 1366 | int ret; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 1367 | |
Archit Taneja | 7d526fcf | 2016-05-19 10:33:57 +0530 | [diff] [blame] | 1368 | ret = add_display_components(&pdev->dev, &match); |
| 1369 | if (ret) |
| 1370 | return ret; |
| 1371 | |
| 1372 | ret = add_gpu_components(&pdev->dev, &match); |
| 1373 | if (ret) |
| 1374 | return ret; |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 1375 | |
Rob Clark | c83ea57 | 2016-11-07 13:31:30 -0500 | [diff] [blame] | 1376 | /* on all devices that I am aware of, iommu's which can map |
| 1377 | * any address the cpu can see are used: |
| 1378 | */ |
| 1379 | ret = dma_set_mask_and_coherent(&pdev->dev, ~0); |
| 1380 | if (ret) |
| 1381 | return ret; |
| 1382 | |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 1383 | return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | static int msm_pdev_remove(struct platform_device *pdev) |
| 1387 | { |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 1388 | component_master_del(&pdev->dev, &msm_drm_ops); |
Archit Taneja | 54011e2 | 2016-06-06 13:45:34 +0530 | [diff] [blame] | 1389 | of_platform_depopulate(&pdev->dev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 1394 | static const struct of_device_id dt_match[] = { |
Jeykumar Sankaran | aaded2e | 2018-06-27 14:26:24 -0400 | [diff] [blame] | 1395 | { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 }, |
| 1396 | { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 }, |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 1397 | { .compatible = "qcom,sdm845-mdss", .data = (void *)KMS_DPU }, |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 1398 | {} |
| 1399 | }; |
| 1400 | MODULE_DEVICE_TABLE(of, dt_match); |
| 1401 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1402 | static struct platform_driver msm_platform_driver = { |
| 1403 | .probe = msm_pdev_probe, |
| 1404 | .remove = msm_pdev_remove, |
| 1405 | .driver = { |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1406 | .name = "msm", |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 1407 | .of_match_table = dt_match, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1408 | .pm = &msm_pm_ops, |
| 1409 | }, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1410 | }; |
| 1411 | |
| 1412 | static int __init msm_drm_register(void) |
| 1413 | { |
Rob Clark | ba4dd71 | 2017-07-06 16:33:44 -0400 | [diff] [blame] | 1414 | if (!modeset) |
| 1415 | return -EINVAL; |
| 1416 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1417 | DBG("init"); |
Archit Taneja | 1dd0a0b | 2016-05-30 16:36:50 +0530 | [diff] [blame] | 1418 | msm_mdp_register(); |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 1419 | msm_dpu_register(); |
Hai Li | d5af49c | 2015-03-26 19:25:17 -0400 | [diff] [blame] | 1420 | msm_dsi_register(); |
Hai Li | 0045398 | 2014-12-12 14:41:17 -0500 | [diff] [blame] | 1421 | msm_edp_register(); |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 1422 | msm_hdmi_register(); |
Rob Clark | bfd28b1 | 2014-09-05 13:06:37 -0400 | [diff] [blame] | 1423 | adreno_register(); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1424 | return platform_driver_register(&msm_platform_driver); |
| 1425 | } |
| 1426 | |
| 1427 | static void __exit msm_drm_unregister(void) |
| 1428 | { |
| 1429 | DBG("fini"); |
| 1430 | platform_driver_unregister(&msm_platform_driver); |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 1431 | msm_hdmi_unregister(); |
Rob Clark | bfd28b1 | 2014-09-05 13:06:37 -0400 | [diff] [blame] | 1432 | adreno_unregister(); |
Hai Li | 0045398 | 2014-12-12 14:41:17 -0500 | [diff] [blame] | 1433 | msm_edp_unregister(); |
Hai Li | d5af49c | 2015-03-26 19:25:17 -0400 | [diff] [blame] | 1434 | msm_dsi_unregister(); |
Archit Taneja | 1dd0a0b | 2016-05-30 16:36:50 +0530 | [diff] [blame] | 1435 | msm_mdp_unregister(); |
Jeykumar Sankaran | 25fdd59 | 2018-06-27 15:26:09 -0400 | [diff] [blame] | 1436 | msm_dpu_unregister(); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | module_init(msm_drm_register); |
| 1440 | module_exit(msm_drm_unregister); |
| 1441 | |
| 1442 | MODULE_AUTHOR("Rob Clark <robdclark@gmail.com"); |
| 1443 | MODULE_DESCRIPTION("MSM DRM Driver"); |
| 1444 | MODULE_LICENSE("GPL"); |