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