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