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