blob: 37f18b55d11f8bacd1a2a358623231cb2a3ec1e4 [file] [log] [blame]
Rob Clarkc8afe682013-06-26 12:44:06 -04001/*
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04002 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
Rob Clarkc8afe682013-06-26 12:44:06 -04003 * 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 Sankaran25fdd592018-06-27 15:26:09 -040019#include <linux/kthread.h>
20#include <uapi/linux/sched/types.h>
Russell King97ac0e42016-10-19 11:28:27 +010021#include <drm/drm_of.h>
22
Rob Clarkc8afe682013-06-26 12:44:06 -040023#include "msm_drv.h"
Rob Clarkedcd60c2016-03-16 12:56:12 -040024#include "msm_debugfs.h"
Rob Clarkfde5de62016-03-15 15:35:08 -040025#include "msm_fence.h"
Rob Clarkf05c83e2018-11-29 10:27:22 -050026#include "msm_gem.h"
Rob Clark7198e6b2013-07-19 12:59:32 -040027#include "msm_gpu.h"
Rob Clarkdd2da6e2013-11-30 16:12:10 -050028#include "msm_kms.h"
Jonathan Marekc2052a42018-11-14 17:08:04 -050029#include "adreno/adreno_gpu.h"
Rob Clarkc8afe682013-06-26 12:44:06 -040030
Rob Clarka8d854c2016-06-01 14:02:02 -040031
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 Clark7a3bcc02016-09-16 18:37:44 -040036 * - 1.2.0 - adds explicit fence support for submit ioctl
Jordan Crousef7de1542017-10-20 11:06:55 -060037 * - 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 Clark1fed8df2018-11-29 10:30:04 -050040 * - 1.4.0 - softpin, MSM_RELOC_BO_DUMP, and GEM_INFO support to set/get
41 * GEM object's debug name
Jordan Crouseb0fb6602019-03-22 14:21:22 -060042 * - 1.5.0 - Add SUBMITQUERY_QUERY ioctl
Rob Clarka8d854c2016-06-01 14:02:02 -040043 */
44#define MSM_VERSION_MAJOR 1
Jordan Crouseb0fb6602019-03-22 14:21:22 -060045#define MSM_VERSION_MINOR 5
Rob Clarka8d854c2016-06-01 14:02:02 -040046#define MSM_VERSION_PATCHLEVEL 0
47
Rob Clarkc8afe682013-06-26 12:44:06 -040048static const struct drm_mode_config_funcs mode_config_funcs = {
49 .fb_create = msm_framebuffer_create,
Noralf Trønnes4ccbc6e2017-12-05 19:24:59 +010050 .output_poll_changed = drm_fb_helper_output_poll_changed,
Rob Clark1f920172017-10-25 12:30:51 -040051 .atomic_check = drm_atomic_helper_check,
Sean Pauld14659f2018-02-28 14:19:05 -050052 .atomic_commit = drm_atomic_helper_commit,
53};
54
55static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = {
56 .atomic_commit_tail = msm_atomic_commit_tail,
Rob Clarkc8afe682013-06-26 12:44:06 -040057};
58
Rob Clarkc8afe682013-06-26 12:44:06 -040059#ifdef CONFIG_DRM_MSM_REGISTER_LOGGING
60static bool reglog = false;
61MODULE_PARM_DESC(reglog, "Enable register read/write logging");
62module_param(reglog, bool, 0600);
63#else
64#define reglog 0
65#endif
66
Archit Tanejaa9ee34b2015-07-13 12:12:07 +053067#ifdef CONFIG_DRM_FBDEV_EMULATION
Rob Clarke90dfec2015-01-30 17:05:41 -050068static bool fbdev = true;
69MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer");
70module_param(fbdev, bool, 0600);
71#endif
72
Rob Clark3a10ba82014-09-08 14:24:57 -040073static char *vram = "16m";
Rob Clark4313c7442016-02-03 14:02:04 -050074MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)");
Rob Clark871d8122013-11-16 12:56:06 -050075module_param(vram, charp, 0);
76
Rob Clark06d9f562016-11-05 11:08:12 -040077bool dumpstate = false;
78MODULE_PARM_DESC(dumpstate, "Dump KMS state on errors");
79module_param(dumpstate, bool, 0600);
80
Rob Clarkba4dd712017-07-06 16:33:44 -040081static bool modeset = true;
82MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disable)");
83module_param(modeset, bool, 0600);
84
Rob Clark060530f2014-03-03 14:19:12 -050085/*
86 * Util/helpers:
87 */
88
Jordan Crouse8e54eea2018-08-06 11:33:21 -060089int 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
129struct 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 Clark720c3bb2017-01-30 11:30:58 -0500146struct 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 Clarkc8afe682013-06-26 12:44:06 -0400165void __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 Shukla6a41da12018-10-20 23:19:26 +0530178 DRM_DEV_ERROR(&pdev->dev, "failed to get memory resource: %s\n", name);
Rob Clarkc8afe682013-06-26 12:44:06 -0400179 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 Shukla6a41da12018-10-20 23:19:26 +0530186 DRM_DEV_ERROR(&pdev->dev, "failed to ioremap: %s\n", name);
Rob Clarkc8afe682013-06-26 12:44:06 -0400187 return ERR_PTR(-ENOMEM);
188 }
189
190 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200191 printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size);
Rob Clarkc8afe682013-06-26 12:44:06 -0400192
193 return ptr;
194}
195
196void msm_writel(u32 data, void __iomem *addr)
197{
198 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200199 printk(KERN_DEBUG "IO:W %p %08x\n", addr, data);
Rob Clarkc8afe682013-06-26 12:44:06 -0400200 writel(data, addr);
201}
202
203u32 msm_readl(const void __iomem *addr)
204{
205 u32 val = readl(addr);
206 if (reglog)
Joe Perches8dfe1622017-02-28 04:55:54 -0800207 pr_err("IO:R %p %08x\n", addr, val);
Rob Clarkc8afe682013-06-26 12:44:06 -0400208 return val;
209}
210
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800211struct msm_vblank_work {
212 struct work_struct work;
Hai Li78b1d472015-07-27 13:49:45 -0400213 int crtc_id;
214 bool enable;
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800215 struct msm_drm_private *priv;
Hai Li78b1d472015-07-27 13:49:45 -0400216};
217
Jeykumar Sankaran5aeb6652018-12-14 15:57:52 -0800218static void vblank_ctrl_worker(struct work_struct *work)
Hai Li78b1d472015-07-27 13:49:45 -0400219{
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800220 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 Li78b1d472015-07-27 13:49:45 -0400223 struct msm_kms *kms = priv->kms;
Hai Li78b1d472015-07-27 13:49:45 -0400224
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800225 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 Li78b1d472015-07-27 13:49:45 -0400229
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800230 kfree(vbl_work);
Hai Li78b1d472015-07-27 13:49:45 -0400231}
232
233static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
234 int crtc_id, bool enable)
235{
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800236 struct msm_vblank_work *vbl_work;
Hai Li78b1d472015-07-27 13:49:45 -0400237
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800238 vbl_work = kzalloc(sizeof(*vbl_work), GFP_ATOMIC);
239 if (!vbl_work)
Hai Li78b1d472015-07-27 13:49:45 -0400240 return -ENOMEM;
241
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800242 INIT_WORK(&vbl_work->work, vblank_ctrl_worker);
Hai Li78b1d472015-07-27 13:49:45 -0400243
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800244 vbl_work->crtc_id = crtc_id;
245 vbl_work->enable = enable;
246 vbl_work->priv = priv;
Hai Li78b1d472015-07-27 13:49:45 -0400247
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800248 queue_work(priv->wq, &vbl_work->work);
Hai Li78b1d472015-07-27 13:49:45 -0400249
250 return 0;
251}
252
Archit Taneja2b669872016-05-02 11:05:54 +0530253static int msm_drm_uninit(struct device *dev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400254{
Archit Taneja2b669872016-05-02 11:05:54 +0530255 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 Clarkc8afe682013-06-26 12:44:06 -0400258 struct msm_kms *kms = priv->kms;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400259 struct msm_mdss *mdss = priv->mdss;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400260 int i;
Hai Li78b1d472015-07-27 13:49:45 -0400261
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 Clarkc8afe682013-06-26 12:44:06 -0400266
Jeykumar Sankaran48d1d282018-12-14 15:57:55 -0800267 flush_workqueue(priv->wq);
268 destroy_workqueue(priv->wq);
Rob Clarkc8afe682013-06-26 12:44:06 -0400269
Jeykumar Sankarand9db30c2018-12-14 15:57:54 -0800270 /* clean up event worker threads */
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400271 for (i = 0; i < priv->num_crtcs; i++) {
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400272 if (priv->event_thread[i].thread) {
Jeykumar Sankaran3c125682018-12-14 15:57:51 -0800273 kthread_destroy_worker(&priv->event_thread[i].worker);
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400274 priv->event_thread[i].thread = NULL;
275 }
276 }
277
Rob Clark68209392016-05-17 16:19:32 -0400278 msm_gem_shrinker_cleanup(ddev);
279
Archit Taneja2b669872016-05-02 11:05:54 +0530280 drm_kms_helper_poll_fini(ddev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530281
Archit Taneja2b669872016-05-02 11:05:54 +0530282 drm_dev_unregister(ddev);
Archit Taneja8208ed92016-05-02 11:05:53 +0530283
Noralf Trønnes85eac472017-03-07 21:49:22 +0100284 msm_perf_debugfs_cleanup(priv);
285 msm_rd_debugfs_cleanup(priv);
286
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530287#ifdef CONFIG_DRM_FBDEV_EMULATION
288 if (fbdev && priv->fbdev)
Archit Taneja2b669872016-05-02 11:05:54 +0530289 msm_fbdev_free(ddev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530290#endif
Daniel Vetter3ea4b1e2018-10-04 22:24:36 +0200291 drm_atomic_helper_shutdown(ddev);
Archit Taneja2b669872016-05-02 11:05:54 +0530292 drm_mode_config_cleanup(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400293
Archit Taneja2b669872016-05-02 11:05:54 +0530294 pm_runtime_get_sync(dev);
295 drm_irq_uninstall(ddev);
296 pm_runtime_put_sync(dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400297
Archit Taneja16976082016-11-03 17:36:18 +0530298 if (kms && kms->funcs)
Rob Clarkc8afe682013-06-26 12:44:06 -0400299 kms->funcs->destroy(kms);
Rob Clarkc8afe682013-06-26 12:44:06 -0400300
Rob Clark871d8122013-11-16 12:56:06 -0500301 if (priv->vram.paddr) {
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700302 unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
Rob Clark871d8122013-11-16 12:56:06 -0500303 drm_mm_takedown(&priv->vram.mm);
Archit Taneja2b669872016-05-02 11:05:54 +0530304 dma_free_attrs(dev, priv->vram.size, NULL,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700305 priv->vram.paddr, attrs);
Rob Clark871d8122013-11-16 12:56:06 -0500306 }
307
Archit Taneja2b669872016-05-02 11:05:54 +0530308 component_unbind_all(dev, ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500309
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400310 if (mdss && mdss->funcs)
311 mdss->funcs->destroy(ddev);
Archit Taneja0a6030d2016-05-08 21:36:28 +0530312
Archit Taneja2b669872016-05-02 11:05:54 +0530313 ddev->dev_private = NULL;
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200314 drm_dev_put(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400315
316 kfree(priv);
317
318 return 0;
319}
320
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400321#define KMS_MDP4 4
322#define KMS_MDP5 5
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400323#define KMS_DPU 3
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400324
Rob Clark06c0dd92013-11-30 17:51:47 -0500325static int get_mdp_ver(struct platform_device *pdev)
326{
Rob Clark06c0dd92013-11-30 17:51:47 -0500327 struct device *dev = &pdev->dev;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530328
329 return (int) (unsigned long) of_device_get_match_data(dev);
Rob Clark06c0dd92013-11-30 17:51:47 -0500330}
331
Rob Clark072f1f92015-03-03 15:04:25 -0500332#include <linux/of_address.h>
333
Jonathan Marekc2052a42018-11-14 17:08:04 -0500334bool 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 Clark5bf9c0b2015-03-03 15:04:24 -0500342static int msm_init_vram(struct drm_device *dev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400343{
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500344 struct msm_drm_private *priv = dev->dev_private;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530345 struct device_node *node;
Rob Clark072f1f92015-03-03 15:04:25 -0500346 unsigned long size = 0;
347 int ret = 0;
348
Rob Clark072f1f92015-03-03 15:04:25 -0500349 /* 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 Clark072f1f92015-03-03 15:04:25 -0500365
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 Chen2ca41c172016-07-04 16:49:50 +0800370 of_node_put(node);
Rob Clark072f1f92015-03-03 15:04:25 -0500371 if (ret)
372 return ret;
373 size = r.end - r.start;
Thierry Redingfc99f972015-04-09 16:39:51 +0200374 DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
Rob Clarkc8afe682013-06-26 12:44:06 -0400375
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530376 /* 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 Marekc2052a42018-11-14 17:08:04 -0500380 } else if (!msm_use_mmu(dev)) {
Rob Clark072f1f92015-03-03 15:04:25 -0500381 DRM_INFO("using %s VRAM carveout\n", vram);
382 size = memparse(vram, NULL);
383 }
384
385 if (size) {
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700386 unsigned long attrs = 0;
Rob Clark871d8122013-11-16 12:56:06 -0500387 void *p;
388
Rob Clark871d8122013-11-16 12:56:06 -0500389 priv->vram.size = size;
390
391 drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);
Sushmita Susheelendra0e082702017-06-13 16:52:54 -0600392 spin_lock_init(&priv->vram.lock);
Rob Clark871d8122013-11-16 12:56:06 -0500393
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700394 attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
395 attrs |= DMA_ATTR_WRITE_COMBINE;
Rob Clark871d8122013-11-16 12:56:06 -0500396
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 Kozlowski00085f12016-08-03 13:46:00 -0700401 &priv->vram.paddr, GFP_KERNEL, attrs);
Rob Clark871d8122013-11-16 12:56:06 -0500402 if (!p) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530403 DRM_DEV_ERROR(dev->dev, "failed to allocate VRAM\n");
Rob Clark871d8122013-11-16 12:56:06 -0500404 priv->vram.paddr = 0;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500405 return -ENOMEM;
Rob Clark871d8122013-11-16 12:56:06 -0500406 }
407
Mamta Shukla6a41da12018-10-20 23:19:26 +0530408 DRM_DEV_INFO(dev->dev, "VRAM: %08x->%08x\n",
Rob Clark871d8122013-11-16 12:56:06 -0500409 (uint32_t)priv->vram.paddr,
410 (uint32_t)(priv->vram.paddr + size));
411 }
412
Rob Clark072f1f92015-03-03 15:04:25 -0500413 return ret;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500414}
415
Archit Taneja2b669872016-05-02 11:05:54 +0530416static int msm_drm_init(struct device *dev, struct drm_driver *drv)
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500417{
Archit Taneja2b669872016-05-02 11:05:54 +0530418 struct platform_device *pdev = to_platform_device(dev);
419 struct drm_device *ddev;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500420 struct msm_drm_private *priv;
421 struct msm_kms *kms;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400422 struct msm_mdss *mdss;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400423 int ret, i;
424 struct sched_param param;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500425
Archit Taneja2b669872016-05-02 11:05:54 +0530426 ddev = drm_dev_alloc(drv, dev);
Tom Gundersen0f288602016-09-21 16:59:19 +0200427 if (IS_ERR(ddev)) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530428 DRM_DEV_ERROR(dev, "failed to allocate drm_device\n");
Tom Gundersen0f288602016-09-21 16:59:19 +0200429 return PTR_ERR(ddev);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500430 }
431
Archit Taneja2b669872016-05-02 11:05:54 +0530432 platform_set_drvdata(pdev, ddev);
Archit Taneja2b669872016-05-02 11:05:54 +0530433
434 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
435 if (!priv) {
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400436 ret = -ENOMEM;
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200437 goto err_put_drm_dev;
Archit Taneja2b669872016-05-02 11:05:54 +0530438 }
439
440 ddev->dev_private = priv;
Rob Clark68209392016-05-17 16:19:32 -0400441 priv->dev = ddev;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500442
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400443 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 Sankaran77050c32018-06-27 14:35:28 -0400454 if (ret)
455 goto err_free_priv;
Archit Taneja0a6030d2016-05-08 21:36:28 +0530456
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400457 mdss = priv->mdss;
458
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500459 priv->wq = alloc_ordered_workqueue("msm", 0);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500460
461 INIT_LIST_HEAD(&priv->inactive_list);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500462
Archit Taneja2b669872016-05-02 11:05:54 +0530463 drm_mode_config_init(ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500464
465 /* Bind all our sub-components: */
Archit Taneja2b669872016-05-02 11:05:54 +0530466 ret = component_bind_all(dev, ddev);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400467 if (ret)
468 goto err_destroy_mdss;
Rob Clark060530f2014-03-03 14:19:12 -0500469
Archit Taneja2b669872016-05-02 11:05:54 +0530470 ret = msm_init_vram(ddev);
Rob Clark13f15562015-05-07 15:20:13 -0400471 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400472 goto err_msm_uninit;
Rob Clark13f15562015-05-07 15:20:13 -0400473
Rob Clark68209392016-05-17 16:19:32 -0400474 msm_gem_shrinker_init(ddev);
475
Rob Clark06c0dd92013-11-30 17:51:47 -0500476 switch (get_mdp_ver(pdev)) {
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400477 case KMS_MDP4:
Archit Taneja2b669872016-05-02 11:05:54 +0530478 kms = mdp4_kms_init(ddev);
Archit Taneja0a6030d2016-05-08 21:36:28 +0530479 priv->kms = kms;
Rob Clark06c0dd92013-11-30 17:51:47 -0500480 break;
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400481 case KMS_MDP5:
Archit Taneja392ae6e2016-06-14 18:24:54 +0530482 kms = mdp5_kms_init(ddev);
Rob Clark06c0dd92013-11-30 17:51:47 -0500483 break;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400484 case KMS_DPU:
485 kms = dpu_kms_init(ddev);
486 priv->kms = kms;
487 break;
Rob Clark06c0dd92013-11-30 17:51:47 -0500488 default:
Jonathan Mareke6f6d632018-12-04 10:16:58 -0500489 /* valid only for the dummy headless case, where of_node=NULL */
490 WARN_ON(dev->of_node);
491 kms = NULL;
Rob Clark06c0dd92013-11-30 17:51:47 -0500492 break;
493 }
494
Rob Clarkc8afe682013-06-26 12:44:06 -0400495 if (IS_ERR(kms)) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530496 DRM_DEV_ERROR(dev, "failed to load kms\n");
Thomas Meyere4826a92013-09-16 23:19:54 +0200497 ret = PTR_ERR(kms);
Jonathan Marekb2ccfdf2018-11-21 20:52:35 -0500498 priv->kms = NULL;
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400499 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400500 }
501
Jeykumar Sankaranbb676df2018-06-11 14:13:20 -0700502 /* Enable normalization of plane zpos */
503 ddev->mode_config.normalize_zpos = true;
504
Rob Clarkc8afe682013-06-26 12:44:06 -0400505 if (kms) {
Rob Clarkc8afe682013-06-26 12:44:06 -0400506 ret = kms->funcs->hw_init(kms);
507 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530508 DRM_DEV_ERROR(dev, "kms hw init failed: %d\n", ret);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400509 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400510 }
511 }
512
Archit Taneja2b669872016-05-02 11:05:54 +0530513 ddev->mode_config.funcs = &mode_config_funcs;
Sean Pauld14659f2018-02-28 14:19:05 -0500514 ddev->mode_config.helper_private = &mode_config_helper_funcs;
Rob Clarkc8afe682013-06-26 12:44:06 -0400515
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400516 /**
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 Sankaran25fdd592018-06-27 15:26:09 -0400523 /* 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 Sankaran7f9743a2018-10-10 14:11:16 -0700531 if (IS_ERR(priv->event_thread[i].thread)) {
Linus Torvalds4971f092018-12-25 11:48:26 -0800532 DRM_DEV_ERROR(dev, "failed to create crtc_event kthread\n");
Jeykumar Sankaran7f9743a2018-10-10 14:11:16 -0700533 priv->event_thread[i].thread = NULL;
534 goto err_msm_uninit;
535 }
536
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400537 ret = sched_setscheduler(priv->event_thread[i].thread,
Jeykumar Sankaran7f9743a2018-10-10 14:11:16 -0700538 SCHED_FIFO, &param);
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400539 if (ret)
Jeykumar Sankaran7f9743a2018-10-10 14:11:16 -0700540 dev_warn(dev, "event_thread set priority failed:%d\n",
541 ret);
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400542 }
543
Archit Taneja2b669872016-05-02 11:05:54 +0530544 ret = drm_vblank_init(ddev, priv->num_crtcs);
Rob Clarkc8afe682013-06-26 12:44:06 -0400545 if (ret < 0) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530546 DRM_DEV_ERROR(dev, "failed to initialize vblank\n");
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400547 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400548 }
549
Archit Tanejaa2b3a552016-05-18 15:06:03 +0530550 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 Shukla6a41da12018-10-20 23:19:26 +0530555 DRM_DEV_ERROR(dev, "failed to install IRQ handler\n");
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400556 goto err_msm_uninit;
Archit Tanejaa2b3a552016-05-18 15:06:03 +0530557 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400558 }
559
Archit Taneja2b669872016-05-02 11:05:54 +0530560 ret = drm_dev_register(ddev, 0);
Rob Clarka7d3c952014-05-30 14:47:38 -0400561 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400562 goto err_msm_uninit;
Rob Clarka7d3c952014-05-30 14:47:38 -0400563
Archit Taneja2b669872016-05-02 11:05:54 +0530564 drm_mode_config_reset(ddev);
565
566#ifdef CONFIG_DRM_FBDEV_EMULATION
Jonathan Mareke6f6d632018-12-04 10:16:58 -0500567 if (kms && fbdev)
Archit Taneja2b669872016-05-02 11:05:54 +0530568 priv->fbdev = msm_fbdev_init(ddev);
569#endif
570
571 ret = msm_debugfs_late_init(ddev);
572 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400573 goto err_msm_uninit;
Archit Taneja2b669872016-05-02 11:05:54 +0530574
575 drm_kms_helper_poll_init(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400576
577 return 0;
578
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400579err_msm_uninit:
Archit Taneja2b669872016-05-02 11:05:54 +0530580 msm_drm_uninit(dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400581 return ret;
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400582err_destroy_mdss:
583 if (mdss && mdss->funcs)
584 mdss->funcs->destroy(ddev);
585err_free_priv:
586 kfree(priv);
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200587err_put_drm_dev:
588 drm_dev_put(ddev);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400589 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -0400590}
591
Archit Taneja2b669872016-05-02 11:05:54 +0530592/*
593 * DRM operations:
594 */
595
Rob Clark7198e6b2013-07-19 12:59:32 -0400596static void load_gpu(struct drm_device *dev)
597{
Rob Clarka1ad3522014-07-11 11:59:22 -0400598 static DEFINE_MUTEX(init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400599 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400600
Rob Clarka1ad3522014-07-11 11:59:22 -0400601 mutex_lock(&init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400602
Rob Clarke2550b72014-09-05 13:30:27 -0400603 if (!priv->gpu)
604 priv->gpu = adreno_load_gpu(dev);
Rob Clarka1ad3522014-07-11 11:59:22 -0400605
Rob Clarka1ad3522014-07-11 11:59:22 -0400606 mutex_unlock(&init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400607}
608
Jordan Crousef97deca2017-10-20 11:06:57 -0600609static int context_init(struct drm_device *dev, struct drm_file *file)
Rob Clark7198e6b2013-07-19 12:59:32 -0400610{
611 struct msm_file_private *ctx;
612
Rob Clark7198e6b2013-07-19 12:59:32 -0400613 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
614 if (!ctx)
615 return -ENOMEM;
616
Jordan Crousef97deca2017-10-20 11:06:57 -0600617 msm_submitqueue_init(dev, ctx);
Jordan Crousef7de1542017-10-20 11:06:55 -0600618
Rob Clark7198e6b2013-07-19 12:59:32 -0400619 file->driver_priv = ctx;
620
621 return 0;
622}
623
Jordan Crousef7de1542017-10-20 11:06:55 -0600624static 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 Crousef97deca2017-10-20 11:06:57 -0600631 return context_init(dev, file);
Jordan Crousef7de1542017-10-20 11:06:55 -0600632}
633
634static void context_close(struct msm_file_private *ctx)
635{
636 msm_submitqueue_close(ctx);
637 kfree(ctx);
638}
639
Daniel Vetter94df1452017-03-08 15:12:46 +0100640static void msm_postclose(struct drm_device *dev, struct drm_file *file)
Rob Clarkc8afe682013-06-26 12:44:06 -0400641{
642 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400643 struct msm_file_private *ctx = file->driver_priv;
Rob Clark7198e6b2013-07-19 12:59:32 -0400644
Rob Clark7198e6b2013-07-19 12:59:32 -0400645 mutex_lock(&dev->struct_mutex);
646 if (ctx == priv->lastctx)
647 priv->lastctx = NULL;
648 mutex_unlock(&dev->struct_mutex);
649
Jordan Crousef7de1542017-10-20 11:06:55 -0600650 context_close(ctx);
Rob Clarkc8afe682013-06-26 12:44:06 -0400651}
652
Daniel Vettere9f0d762013-12-11 11:34:42 +0100653static irqreturn_t msm_irq(int irq, void *arg)
Rob Clarkc8afe682013-06-26 12:44:06 -0400654{
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
662static 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
670static 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 Crouseab07e0c2018-12-03 15:47:19 -0700675
676 if (kms->funcs->irq_postinstall)
677 return kms->funcs->irq_postinstall(kms);
678
679 return 0;
Rob Clarkc8afe682013-06-26 12:44:06 -0400680}
681
682static 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 Reding88e72712015-09-24 18:35:31 +0200690static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
Rob Clarkc8afe682013-06-26 12:44:06 -0400691{
692 struct msm_drm_private *priv = dev->dev_private;
693 struct msm_kms *kms = priv->kms;
694 if (!kms)
695 return -ENXIO;
Thierry Reding88e72712015-09-24 18:35:31 +0200696 DBG("dev=%p, crtc=%u", dev, pipe);
697 return vblank_ctrl_queue_work(priv, pipe, true);
Rob Clarkc8afe682013-06-26 12:44:06 -0400698}
699
Thierry Reding88e72712015-09-24 18:35:31 +0200700static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
Rob Clarkc8afe682013-06-26 12:44:06 -0400701{
702 struct msm_drm_private *priv = dev->dev_private;
703 struct msm_kms *kms = priv->kms;
704 if (!kms)
705 return;
Thierry Reding88e72712015-09-24 18:35:31 +0200706 DBG("dev=%p, crtc=%u", dev, pipe);
707 vblank_ctrl_queue_work(priv, pipe, false);
Rob Clarkc8afe682013-06-26 12:44:06 -0400708}
709
710/*
Rob Clark7198e6b2013-07-19 12:59:32 -0400711 * DRM ioctls:
712 */
713
714static 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
735static 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 Clark93ddb0d2014-03-03 09:42:33 -0500739
740 if (args->flags & ~MSM_BO_FLAGS) {
741 DRM_ERROR("invalid flags: %08x\n", args->flags);
742 return -EINVAL;
743 }
744
Rob Clark7198e6b2013-07-19 12:59:32 -0400745 return msm_gem_new_handle(dev, file, args->size,
Jordan Crouse0815d772018-11-07 15:35:52 -0700746 args->flags, &args->handle, NULL);
Rob Clark7198e6b2013-07-19 12:59:32 -0400747}
748
Rob Clark56c2da82015-05-11 11:50:03 -0400749static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
750{
751 return ktime_set(timeout.tv_sec, timeout.tv_nsec);
752}
Rob Clark7198e6b2013-07-19 12:59:32 -0400753
754static 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 Clark56c2da82015-05-11 11:50:03 -0400759 ktime_t timeout = to_ktime(args->timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400760 int ret;
761
Rob Clark93ddb0d2014-03-03 09:42:33 -0500762 if (args->op & ~MSM_PREP_FLAGS) {
763 DRM_ERROR("invalid op: %08x\n", args->op);
764 return -EINVAL;
765 }
766
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100767 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400768 if (!obj)
769 return -ENOENT;
770
Rob Clark56c2da82015-05-11 11:50:03 -0400771 ret = msm_gem_cpu_prep(obj, args->op, &timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400772
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100773 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400774
775 return ret;
776}
777
778static 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 Wilsona8ad0bd2016-05-09 11:04:54 +0100785 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400786 if (!obj)
787 return -ENOENT;
788
789 ret = msm_gem_cpu_fini(obj);
790
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100791 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400792
793 return ret;
794}
795
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600796static 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 Crouse9fe041f2018-11-07 15:35:50 -0700804 /*
805 * Don't pin the memory here - just get an address so that userspace can
806 * be productive
807 */
Rob Clark8bdcd942017-06-13 11:07:08 -0400808 return msm_gem_get_iova(obj, priv->gpu->aspace, iova);
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600809}
810
Rob Clark7198e6b2013-07-19 12:59:32 -0400811static 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 Clarkf05c83e2018-11-29 10:27:22 -0500816 struct msm_gem_object *msm_obj;
817 int i, ret = 0;
Rob Clark7198e6b2013-07-19 12:59:32 -0400818
Rob Clark789d2e52018-11-29 09:54:42 -0500819 if (args->pad)
Rob Clark7198e6b2013-07-19 12:59:32 -0400820 return -EINVAL;
821
Rob Clark789d2e52018-11-29 09:54:42 -0500822 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 Clarkf05c83e2018-11-29 10:27:22 -0500829 case MSM_INFO_SET_NAME:
830 case MSM_INFO_GET_NAME:
831 break;
Rob Clark789d2e52018-11-29 09:54:42 -0500832 default:
833 return -EINVAL;
834 }
835
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100836 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400837 if (!obj)
838 return -ENOENT;
839
Rob Clarkf05c83e2018-11-29 10:27:22 -0500840 msm_obj = to_msm_bo(obj);
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600841
Rob Clark789d2e52018-11-29 09:54:42 -0500842 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 Clarkf05c83e2018-11-29 10:27:22 -0500849 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 Carpenter7cce8e42019-02-14 10:19:27 +0300855 if (copy_from_user(msm_obj->name, u64_to_user_ptr(args->value),
Jordan Crouse860433e2019-02-19 11:40:19 -0700856 args->len)) {
857 msm_obj->name[0] = '\0';
Dan Carpenter7cce8e42019-02-14 10:19:27 +0300858 ret = -EFAULT;
Jordan Crouse860433e2019-02-19 11:40:19 -0700859 break;
860 }
Rob Clarkf05c83e2018-11-29 10:27:22 -0500861 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 Carpenter7cce8e42019-02-14 10:19:27 +0300876 if (copy_to_user(u64_to_user_ptr(args->value),
877 msm_obj->name, args->len))
878 ret = -EFAULT;
Rob Clarkf05c83e2018-11-29 10:27:22 -0500879 }
880 break;
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600881 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400882
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100883 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400884
885 return ret;
886}
887
888static int msm_ioctl_wait_fence(struct drm_device *dev, void *data,
889 struct drm_file *file)
890{
Rob Clarkca762a82016-03-15 17:22:13 -0400891 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400892 struct drm_msm_wait_fence *args = data;
Rob Clark56c2da82015-05-11 11:50:03 -0400893 ktime_t timeout = to_ktime(args->timeout);
Jordan Crousef97deca2017-10-20 11:06:57 -0600894 struct msm_gpu_submitqueue *queue;
895 struct msm_gpu *gpu = priv->gpu;
896 int ret;
Rob Clark93ddb0d2014-03-03 09:42:33 -0500897
898 if (args->pad) {
899 DRM_ERROR("invalid pad: %08x\n", args->pad);
900 return -EINVAL;
901 }
902
Jordan Crousef97deca2017-10-20 11:06:57 -0600903 if (!gpu)
Rob Clarkca762a82016-03-15 17:22:13 -0400904 return 0;
905
Jordan Crousef97deca2017-10-20 11:06:57 -0600906 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 Clark7198e6b2013-07-19 12:59:32 -0400915}
916
Rob Clark4cd33c42016-05-17 15:44:49 -0400917static 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 Kowalikdc9a9b32018-01-26 14:55:54 +1100948 drm_gem_object_put(obj);
Rob Clark4cd33c42016-05-17 15:44:49 -0400949
950unlock:
951 mutex_unlock(&dev->struct_mutex);
952 return ret;
953}
954
Jordan Crousef7de1542017-10-20 11:06:55 -0600955
956static 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 Crousef97deca2017-10-20 11:06:57 -0600964 return msm_submitqueue_create(dev, file->driver_priv, args->prio,
Jordan Crousef7de1542017-10-20 11:06:55 -0600965 args->flags, &args->id);
966}
967
Jordan Crouseb0fb6602019-03-22 14:21:22 -0600968static 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 Crousef7de1542017-10-20 11:06:55 -0600973
974static 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 Clark7198e6b2013-07-19 12:59:32 -0400982static const struct drm_ioctl_desc msm_ioctls[] = {
Daniel Vetterf8c47142015-09-08 13:56:30 +0200983 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 Clark4cd33c42016-05-17 15:44:49 -0400990 DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW),
Jordan Crousef7de1542017-10-20 11:06:55 -0600991 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 Crouseb0fb6602019-03-22 14:21:22 -0600993 DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, DRM_AUTH|DRM_RENDER_ALLOW),
Rob Clark7198e6b2013-07-19 12:59:32 -0400994};
995
Rob Clarkc8afe682013-06-26 12:44:06 -0400996static 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
1002static const struct file_operations fops = {
1003 .owner = THIS_MODULE,
1004 .open = drm_open,
1005 .release = drm_release,
1006 .unlocked_ioctl = drm_ioctl,
Rob Clarkc8afe682013-06-26 12:44:06 -04001007 .compat_ioctl = drm_compat_ioctl,
Rob Clarkc8afe682013-06-26 12:44:06 -04001008 .poll = drm_poll,
1009 .read = drm_read,
1010 .llseek = no_llseek,
1011 .mmap = msm_gem_mmap,
1012};
1013
1014static struct drm_driver msm_driver = {
Daniel Vetter5b38e742019-01-29 11:42:46 +01001015 .driver_features = DRIVER_GEM |
Rob Clark05b84912013-09-28 11:28:35 -04001016 DRIVER_PRIME |
Rob Clarkb4b15c82013-09-28 12:01:25 -04001017 DRIVER_RENDER |
Rob Clarka5436e12015-06-04 10:12:22 -04001018 DRIVER_ATOMIC |
Rob Clark05b84912013-09-28 11:28:35 -04001019 DRIVER_MODESET,
Rob Clark7198e6b2013-07-19 12:59:32 -04001020 .open = msm_open,
Daniel Vetter94df1452017-03-08 15:12:46 +01001021 .postclose = msm_postclose,
Noralf Trønnes4ccbc6e2017-12-05 19:24:59 +01001022 .lastclose = drm_fb_helper_lastclose,
Rob Clarkc8afe682013-06-26 12:44:06 -04001023 .irq_handler = msm_irq,
1024 .irq_preinstall = msm_irq_preinstall,
1025 .irq_postinstall = msm_irq_postinstall,
1026 .irq_uninstall = msm_irq_uninstall,
Rob Clarkc8afe682013-06-26 12:44:06 -04001027 .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 Clark05b84912013-09-28 11:28:35 -04001033 .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 Anholt43523eb2017-04-12 12:11:58 -07001037 .gem_prime_res_obj = msm_gem_prime_res_obj,
Rob Clark05b84912013-09-28 11:28:35 -04001038 .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 Thompson77a147e2014-11-12 11:38:14 +00001044 .gem_prime_mmap = msm_gem_prime_mmap,
Rob Clarkc8afe682013-06-26 12:44:06 -04001045#ifdef CONFIG_DEBUG_FS
1046 .debugfs_init = msm_debugfs_init,
Rob Clarkc8afe682013-06-26 12:44:06 -04001047#endif
Rob Clark7198e6b2013-07-19 12:59:32 -04001048 .ioctls = msm_ioctls,
Jordan Crouse167b6062017-05-08 14:34:59 -06001049 .num_ioctls = ARRAY_SIZE(msm_ioctls),
Rob Clarkc8afe682013-06-26 12:44:06 -04001050 .fops = &fops,
1051 .name = "msm",
1052 .desc = "MSM Snapdragon DRM",
1053 .date = "20130625",
Rob Clarka8d854c2016-06-01 14:02:02 -04001054 .major = MSM_VERSION_MAJOR,
1055 .minor = MSM_VERSION_MINOR,
1056 .patchlevel = MSM_VERSION_PATCHLEVEL,
Rob Clarkc8afe682013-06-26 12:44:06 -04001057};
1058
1059#ifdef CONFIG_PM_SLEEP
1060static int msm_pm_suspend(struct device *dev)
1061{
1062 struct drm_device *ddev = dev_get_drvdata(dev);
Daniel Mackec446d02018-05-28 21:53:38 +02001063 struct msm_drm_private *priv = ddev->dev_private;
Jeykumar Sankaran036bfeb2018-06-27 15:24:17 -04001064
Bruce Wang3750e782018-10-05 17:04:01 -04001065 if (WARN_ON(priv->pm_state))
1066 drm_atomic_state_put(priv->pm_state);
Rob Clarkc8afe682013-06-26 12:44:06 -04001067
Daniel Mackec446d02018-05-28 21:53:38 +02001068 priv->pm_state = drm_atomic_helper_suspend(ddev);
1069 if (IS_ERR(priv->pm_state)) {
Bruce Wang3750e782018-10-05 17:04:01 -04001070 int ret = PTR_ERR(priv->pm_state);
1071 DRM_ERROR("Failed to suspend dpu, %d\n", ret);
1072 return ret;
Daniel Mackec446d02018-05-28 21:53:38 +02001073 }
1074
Rob Clarkc8afe682013-06-26 12:44:06 -04001075 return 0;
1076}
1077
1078static int msm_pm_resume(struct device *dev)
1079{
1080 struct drm_device *ddev = dev_get_drvdata(dev);
Daniel Mackec446d02018-05-28 21:53:38 +02001081 struct msm_drm_private *priv = ddev->dev_private;
Bruce Wang3750e782018-10-05 17:04:01 -04001082 int ret;
Jeykumar Sankaran036bfeb2018-06-27 15:24:17 -04001083
Bruce Wang3750e782018-10-05 17:04:01 -04001084 if (WARN_ON(!priv->pm_state))
1085 return -ENOENT;
Rob Clarkc8afe682013-06-26 12:44:06 -04001086
Bruce Wang3750e782018-10-05 17:04:01 -04001087 ret = drm_atomic_helper_resume(ddev, priv->pm_state);
1088 if (!ret)
1089 priv->pm_state = NULL;
Rob Clarkc8afe682013-06-26 12:44:06 -04001090
Bruce Wang3750e782018-10-05 17:04:01 -04001091 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -04001092}
1093#endif
1094
Archit Taneja774e39e2017-07-28 16:17:07 +05301095#ifdef CONFIG_PM
1096static 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 Yadavbc3220b2018-06-21 16:06:10 -04001100 struct msm_mdss *mdss = priv->mdss;
Archit Taneja774e39e2017-07-28 16:17:07 +05301101
1102 DBG("");
1103
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001104 if (mdss && mdss->funcs)
1105 return mdss->funcs->disable(mdss);
Archit Taneja774e39e2017-07-28 16:17:07 +05301106
1107 return 0;
1108}
1109
1110static 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 Yadavbc3220b2018-06-21 16:06:10 -04001114 struct msm_mdss *mdss = priv->mdss;
Archit Taneja774e39e2017-07-28 16:17:07 +05301115
1116 DBG("");
1117
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001118 if (mdss && mdss->funcs)
1119 return mdss->funcs->enable(mdss);
Archit Taneja774e39e2017-07-28 16:17:07 +05301120
1121 return 0;
1122}
1123#endif
1124
Rob Clarkc8afe682013-06-26 12:44:06 -04001125static const struct dev_pm_ops msm_pm_ops = {
1126 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
Archit Taneja774e39e2017-07-28 16:17:07 +05301127 SET_RUNTIME_PM_OPS(msm_runtime_suspend, msm_runtime_resume, NULL)
Rob Clarkc8afe682013-06-26 12:44:06 -04001128};
1129
1130/*
Rob Clark060530f2014-03-03 14:19:12 -05001131 * Componentized driver support:
1132 */
1133
Archit Tanejae9fbdaf2015-11-18 12:15:14 +05301134/*
1135 * NOTE: duplication of the same code as exynos or imx (or probably any other).
1136 * so probably some room for some helpers
Rob Clark060530f2014-03-03 14:19:12 -05001137 */
1138static int compare_of(struct device *dev, void *data)
1139{
1140 return dev->of_node == data;
1141}
Rob Clark41e69772013-12-15 16:23:05 -05001142
Archit Taneja812070e2016-05-19 10:38:39 +05301143/*
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 */
1149static 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 Taneja54011e22016-06-06 13:45:34 +05301154 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 Taneja812070e2016-05-19 10:38:39 +05301168
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 Shukla6a41da12018-10-20 23:19:26 +05301176 DRM_DEV_ERROR(mdp_dev, "unable to parse port endpoint\n");
Archit Taneja812070e2016-05-19 10:38:39 +05301177 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 Tanejad8dd8052016-11-17 12:12:03 +05301186 ep.port == 0)
Archit Taneja812070e2016-05-19 10:38:39 +05301187 continue;
Archit Taneja812070e2016-05-19 10:38:39 +05301188
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 Tanejad8dd8052016-11-17 12:12:03 +05301195 if (!intf)
Archit Taneja812070e2016-05-19 10:38:39 +05301196 continue;
Archit Taneja812070e2016-05-19 10:38:39 +05301197
Douglas Andersond1d9d0e2018-12-04 10:04:41 -08001198 if (of_device_is_available(intf))
1199 drm_of_component_match_add(master_dev, matchptr,
1200 compare_of, intf);
1201
Archit Taneja812070e2016-05-19 10:38:39 +05301202 of_node_put(intf);
Archit Taneja812070e2016-05-19 10:38:39 +05301203 }
1204
1205 return 0;
1206}
1207
Archit Taneja54011e22016-06-06 13:45:34 +05301208static int compare_name_mdp(struct device *dev, void *data)
1209{
1210 return (strstr(dev_name(dev), "mdp") != NULL);
1211}
1212
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301213static int add_display_components(struct device *dev,
1214 struct component_match **matchptr)
1215{
Archit Taneja54011e22016-06-06 13:45:34 +05301216 struct device *mdp_dev;
1217 int ret;
1218
1219 /*
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001220 * 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 Taneja54011e22016-06-06 13:45:34 +05301224 */
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001225 if (of_device_is_compatible(dev->of_node, "qcom,mdss") ||
1226 of_device_is_compatible(dev->of_node, "qcom,sdm845-mdss")) {
Archit Taneja54011e22016-06-06 13:45:34 +05301227 ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
1228 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +05301229 DRM_DEV_ERROR(dev, "failed to populate children devices\n");
Archit Taneja54011e22016-06-06 13:45:34 +05301230 return ret;
1231 }
1232
1233 mdp_dev = device_find_child(dev, NULL, compare_name_mdp);
1234 if (!mdp_dev) {
Mamta Shukla6a41da12018-10-20 23:19:26 +05301235 DRM_DEV_ERROR(dev, "failed to find MDSS MDP node\n");
Archit Taneja54011e22016-06-06 13:45:34 +05301236 of_platform_depopulate(dev);
1237 return -ENODEV;
1238 }
1239
1240 put_device(mdp_dev);
1241
1242 /* add the MDP component itself */
Russell King97ac0e42016-10-19 11:28:27 +01001243 drm_of_component_match_add(dev, matchptr, compare_of,
1244 mdp_dev->of_node);
Archit Taneja54011e22016-06-06 13:45:34 +05301245 } 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 Taneja7d526fcf2016-05-19 10:33:57 +05301255}
1256
Archit Tanejadc3ea262016-05-19 13:33:52 +05301257/*
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 */
1262static const struct of_device_id msm_gpu_match[] = {
Rob Clark1db7afa2017-01-30 11:02:27 -05001263 { .compatible = "qcom,adreno" },
Archit Tanejadc3ea262016-05-19 13:33:52 +05301264 { .compatible = "qcom,adreno-3xx" },
Jonathan Mareke6f6d632018-12-04 10:16:58 -05001265 { .compatible = "amd,imageon" },
Archit Tanejadc3ea262016-05-19 13:33:52 +05301266 { .compatible = "qcom,kgsl-3d0" },
1267 { },
1268};
1269
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301270static int add_gpu_components(struct device *dev,
1271 struct component_match **matchptr)
1272{
Archit Tanejadc3ea262016-05-19 13:33:52 +05301273 struct device_node *np;
1274
1275 np = of_find_matching_node(NULL, msm_gpu_match);
1276 if (!np)
1277 return 0;
1278
Russell King97ac0e42016-10-19 11:28:27 +01001279 drm_of_component_match_add(dev, matchptr, compare_of, np);
Archit Tanejadc3ea262016-05-19 13:33:52 +05301280
1281 of_node_put(np);
1282
1283 return 0;
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301284}
1285
Russell King84448282014-04-19 11:20:42 +01001286static int msm_drm_bind(struct device *dev)
1287{
Archit Taneja2b669872016-05-02 11:05:54 +05301288 return msm_drm_init(dev, &msm_driver);
Russell King84448282014-04-19 11:20:42 +01001289}
1290
1291static void msm_drm_unbind(struct device *dev)
1292{
Archit Taneja2b669872016-05-02 11:05:54 +05301293 msm_drm_uninit(dev);
Russell King84448282014-04-19 11:20:42 +01001294}
1295
1296static 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
1305static int msm_pdev_probe(struct platform_device *pdev)
1306{
1307 struct component_match *match = NULL;
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301308 int ret;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +05301309
Jonathan Mareke6f6d632018-12-04 10:16:58 -05001310 if (get_mdp_ver(pdev)) {
1311 ret = add_display_components(&pdev->dev, &match);
1312 if (ret)
1313 return ret;
1314 }
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301315
1316 ret = add_gpu_components(&pdev->dev, &match);
1317 if (ret)
1318 return ret;
Rob Clark060530f2014-03-03 14:19:12 -05001319
Rob Clarkc83ea572016-11-07 13:31:30 -05001320 /* 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 King84448282014-04-19 11:20:42 +01001327 return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
Rob Clarkc8afe682013-06-26 12:44:06 -04001328}
1329
1330static int msm_pdev_remove(struct platform_device *pdev)
1331{
Rob Clark060530f2014-03-03 14:19:12 -05001332 component_master_del(&pdev->dev, &msm_drm_ops);
Archit Taneja54011e22016-06-06 13:45:34 +05301333 of_platform_depopulate(&pdev->dev);
Rob Clarkc8afe682013-06-26 12:44:06 -04001334
1335 return 0;
1336}
1337
Rob Clark06c0dd92013-11-30 17:51:47 -05001338static const struct of_device_id dt_match[] = {
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -04001339 { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 },
1340 { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 },
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001341 { .compatible = "qcom,sdm845-mdss", .data = (void *)KMS_DPU },
Rob Clark06c0dd92013-11-30 17:51:47 -05001342 {}
1343};
1344MODULE_DEVICE_TABLE(of, dt_match);
1345
Rob Clarkc8afe682013-06-26 12:44:06 -04001346static struct platform_driver msm_platform_driver = {
1347 .probe = msm_pdev_probe,
1348 .remove = msm_pdev_remove,
1349 .driver = {
Rob Clarkc8afe682013-06-26 12:44:06 -04001350 .name = "msm",
Rob Clark06c0dd92013-11-30 17:51:47 -05001351 .of_match_table = dt_match,
Rob Clarkc8afe682013-06-26 12:44:06 -04001352 .pm = &msm_pm_ops,
1353 },
Rob Clarkc8afe682013-06-26 12:44:06 -04001354};
1355
1356static int __init msm_drm_register(void)
1357{
Rob Clarkba4dd712017-07-06 16:33:44 -04001358 if (!modeset)
1359 return -EINVAL;
1360
Rob Clarkc8afe682013-06-26 12:44:06 -04001361 DBG("init");
Archit Taneja1dd0a0b2016-05-30 16:36:50 +05301362 msm_mdp_register();
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001363 msm_dpu_register();
Hai Lid5af49c2015-03-26 19:25:17 -04001364 msm_dsi_register();
Hai Li00453982014-12-12 14:41:17 -05001365 msm_edp_register();
Arnd Bergmannfcda50c2016-02-22 22:08:35 +01001366 msm_hdmi_register();
Rob Clarkbfd28b12014-09-05 13:06:37 -04001367 adreno_register();
Rob Clarkc8afe682013-06-26 12:44:06 -04001368 return platform_driver_register(&msm_platform_driver);
1369}
1370
1371static void __exit msm_drm_unregister(void)
1372{
1373 DBG("fini");
1374 platform_driver_unregister(&msm_platform_driver);
Arnd Bergmannfcda50c2016-02-22 22:08:35 +01001375 msm_hdmi_unregister();
Rob Clarkbfd28b12014-09-05 13:06:37 -04001376 adreno_unregister();
Hai Li00453982014-12-12 14:41:17 -05001377 msm_edp_unregister();
Hai Lid5af49c2015-03-26 19:25:17 -04001378 msm_dsi_unregister();
Archit Taneja1dd0a0b2016-05-30 16:36:50 +05301379 msm_mdp_unregister();
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001380 msm_dpu_unregister();
Rob Clarkc8afe682013-06-26 12:44:06 -04001381}
1382
1383module_init(msm_drm_register);
1384module_exit(msm_drm_unregister);
1385
1386MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
1387MODULE_DESCRIPTION("MSM DRM Driver");
1388MODULE_LICENSE("GPL");