blob: 1a3b80d317265053630ed3f372373d0422d1d3c4 [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"
Rob Clarkc8afe682013-06-26 12:44:06 -040029
Rob Clarka8d854c2016-06-01 14:02:02 -040030
31/*
32 * MSM driver version:
33 * - 1.0.0 - initial interface
34 * - 1.1.0 - adds madvise, and support for submits with > 4 cmd buffers
Rob Clark7a3bcc02016-09-16 18:37:44 -040035 * - 1.2.0 - adds explicit fence support for submit ioctl
Jordan Crousef7de1542017-10-20 11:06:55 -060036 * - 1.3.0 - adds GMEM_BASE + NR_RINGS params, SUBMITQUEUE_NEW +
37 * SUBMITQUEUE_CLOSE ioctls, and MSM_INFO_IOVA flag for
38 * MSM_GEM_INFO ioctl.
Rob Clark1fed8df2018-11-29 10:30:04 -050039 * - 1.4.0 - softpin, MSM_RELOC_BO_DUMP, and GEM_INFO support to set/get
40 * GEM object's debug name
Rob Clarka8d854c2016-06-01 14:02:02 -040041 */
42#define MSM_VERSION_MAJOR 1
Rob Clark1fed8df2018-11-29 10:30:04 -050043#define MSM_VERSION_MINOR 4
Rob Clarka8d854c2016-06-01 14:02:02 -040044#define MSM_VERSION_PATCHLEVEL 0
45
Rob Clarkc8afe682013-06-26 12:44:06 -040046static const struct drm_mode_config_funcs mode_config_funcs = {
47 .fb_create = msm_framebuffer_create,
Noralf Trønnes4ccbc6e2017-12-05 19:24:59 +010048 .output_poll_changed = drm_fb_helper_output_poll_changed,
Rob Clark1f920172017-10-25 12:30:51 -040049 .atomic_check = drm_atomic_helper_check,
Sean Pauld14659f2018-02-28 14:19:05 -050050 .atomic_commit = drm_atomic_helper_commit,
51};
52
53static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = {
54 .atomic_commit_tail = msm_atomic_commit_tail,
Rob Clarkc8afe682013-06-26 12:44:06 -040055};
56
Rob Clarkc8afe682013-06-26 12:44:06 -040057#ifdef CONFIG_DRM_MSM_REGISTER_LOGGING
58static bool reglog = false;
59MODULE_PARM_DESC(reglog, "Enable register read/write logging");
60module_param(reglog, bool, 0600);
61#else
62#define reglog 0
63#endif
64
Archit Tanejaa9ee34b2015-07-13 12:12:07 +053065#ifdef CONFIG_DRM_FBDEV_EMULATION
Rob Clarke90dfec2015-01-30 17:05:41 -050066static bool fbdev = true;
67MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer");
68module_param(fbdev, bool, 0600);
69#endif
70
Rob Clark3a10ba82014-09-08 14:24:57 -040071static char *vram = "16m";
Rob Clark4313c7442016-02-03 14:02:04 -050072MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)");
Rob Clark871d8122013-11-16 12:56:06 -050073module_param(vram, charp, 0);
74
Rob Clark06d9f562016-11-05 11:08:12 -040075bool dumpstate = false;
76MODULE_PARM_DESC(dumpstate, "Dump KMS state on errors");
77module_param(dumpstate, bool, 0600);
78
Rob Clarkba4dd712017-07-06 16:33:44 -040079static bool modeset = true;
80MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disable)");
81module_param(modeset, bool, 0600);
82
Rob Clark060530f2014-03-03 14:19:12 -050083/*
84 * Util/helpers:
85 */
86
Jordan Crouse8e54eea2018-08-06 11:33:21 -060087int msm_clk_bulk_get(struct device *dev, struct clk_bulk_data **bulk)
88{
89 struct property *prop;
90 const char *name;
91 struct clk_bulk_data *local;
92 int i = 0, ret, count;
93
94 count = of_property_count_strings(dev->of_node, "clock-names");
95 if (count < 1)
96 return 0;
97
98 local = devm_kcalloc(dev, sizeof(struct clk_bulk_data *),
99 count, GFP_KERNEL);
100 if (!local)
101 return -ENOMEM;
102
103 of_property_for_each_string(dev->of_node, "clock-names", prop, name) {
104 local[i].id = devm_kstrdup(dev, name, GFP_KERNEL);
105 if (!local[i].id) {
106 devm_kfree(dev, local);
107 return -ENOMEM;
108 }
109
110 i++;
111 }
112
113 ret = devm_clk_bulk_get(dev, count, local);
114
115 if (ret) {
116 for (i = 0; i < count; i++)
117 devm_kfree(dev, (void *) local[i].id);
118 devm_kfree(dev, local);
119
120 return ret;
121 }
122
123 *bulk = local;
124 return count;
125}
126
127struct clk *msm_clk_bulk_get_clock(struct clk_bulk_data *bulk, int count,
128 const char *name)
129{
130 int i;
131 char n[32];
132
133 snprintf(n, sizeof(n), "%s_clk", name);
134
135 for (i = 0; bulk && i < count; i++) {
136 if (!strcmp(bulk[i].id, name) || !strcmp(bulk[i].id, n))
137 return bulk[i].clk;
138 }
139
140
141 return NULL;
142}
143
Rob Clark720c3bb2017-01-30 11:30:58 -0500144struct clk *msm_clk_get(struct platform_device *pdev, const char *name)
145{
146 struct clk *clk;
147 char name2[32];
148
149 clk = devm_clk_get(&pdev->dev, name);
150 if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
151 return clk;
152
153 snprintf(name2, sizeof(name2), "%s_clk", name);
154
155 clk = devm_clk_get(&pdev->dev, name2);
156 if (!IS_ERR(clk))
157 dev_warn(&pdev->dev, "Using legacy clk name binding. Use "
158 "\"%s\" instead of \"%s\"\n", name, name2);
159
160 return clk;
161}
162
Rob Clarkc8afe682013-06-26 12:44:06 -0400163void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
164 const char *dbgname)
165{
166 struct resource *res;
167 unsigned long size;
168 void __iomem *ptr;
169
170 if (name)
171 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
172 else
173 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
174
175 if (!res) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530176 DRM_DEV_ERROR(&pdev->dev, "failed to get memory resource: %s\n", name);
Rob Clarkc8afe682013-06-26 12:44:06 -0400177 return ERR_PTR(-EINVAL);
178 }
179
180 size = resource_size(res);
181
182 ptr = devm_ioremap_nocache(&pdev->dev, res->start, size);
183 if (!ptr) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530184 DRM_DEV_ERROR(&pdev->dev, "failed to ioremap: %s\n", name);
Rob Clarkc8afe682013-06-26 12:44:06 -0400185 return ERR_PTR(-ENOMEM);
186 }
187
188 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200189 printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size);
Rob Clarkc8afe682013-06-26 12:44:06 -0400190
191 return ptr;
192}
193
194void msm_writel(u32 data, void __iomem *addr)
195{
196 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200197 printk(KERN_DEBUG "IO:W %p %08x\n", addr, data);
Rob Clarkc8afe682013-06-26 12:44:06 -0400198 writel(data, addr);
199}
200
201u32 msm_readl(const void __iomem *addr)
202{
203 u32 val = readl(addr);
204 if (reglog)
Joe Perches8dfe1622017-02-28 04:55:54 -0800205 pr_err("IO:R %p %08x\n", addr, val);
Rob Clarkc8afe682013-06-26 12:44:06 -0400206 return val;
207}
208
Hai Li78b1d472015-07-27 13:49:45 -0400209struct vblank_event {
210 struct list_head node;
211 int crtc_id;
212 bool enable;
213};
214
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400215static void vblank_ctrl_worker(struct kthread_work *work)
Hai Li78b1d472015-07-27 13:49:45 -0400216{
217 struct msm_vblank_ctrl *vbl_ctrl = container_of(work,
218 struct msm_vblank_ctrl, work);
219 struct msm_drm_private *priv = container_of(vbl_ctrl,
220 struct msm_drm_private, vblank_ctrl);
221 struct msm_kms *kms = priv->kms;
222 struct vblank_event *vbl_ev, *tmp;
223 unsigned long flags;
224
225 spin_lock_irqsave(&vbl_ctrl->lock, flags);
226 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
227 list_del(&vbl_ev->node);
228 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
229
230 if (vbl_ev->enable)
231 kms->funcs->enable_vblank(kms,
232 priv->crtcs[vbl_ev->crtc_id]);
233 else
234 kms->funcs->disable_vblank(kms,
235 priv->crtcs[vbl_ev->crtc_id]);
236
237 kfree(vbl_ev);
238
239 spin_lock_irqsave(&vbl_ctrl->lock, flags);
240 }
241
242 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
243}
244
245static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
246 int crtc_id, bool enable)
247{
248 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
249 struct vblank_event *vbl_ev;
250 unsigned long flags;
251
252 vbl_ev = kzalloc(sizeof(*vbl_ev), GFP_ATOMIC);
253 if (!vbl_ev)
254 return -ENOMEM;
255
256 vbl_ev->crtc_id = crtc_id;
257 vbl_ev->enable = enable;
258
259 spin_lock_irqsave(&vbl_ctrl->lock, flags);
260 list_add_tail(&vbl_ev->node, &vbl_ctrl->event_list);
261 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
262
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400263 kthread_queue_work(&priv->disp_thread[crtc_id].worker,
264 &vbl_ctrl->work);
Hai Li78b1d472015-07-27 13:49:45 -0400265
266 return 0;
267}
268
Archit Taneja2b669872016-05-02 11:05:54 +0530269static int msm_drm_uninit(struct device *dev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400270{
Archit Taneja2b669872016-05-02 11:05:54 +0530271 struct platform_device *pdev = to_platform_device(dev);
272 struct drm_device *ddev = platform_get_drvdata(pdev);
273 struct msm_drm_private *priv = ddev->dev_private;
Rob Clarkc8afe682013-06-26 12:44:06 -0400274 struct msm_kms *kms = priv->kms;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400275 struct msm_mdss *mdss = priv->mdss;
Hai Li78b1d472015-07-27 13:49:45 -0400276 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
277 struct vblank_event *vbl_ev, *tmp;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400278 int i;
Hai Li78b1d472015-07-27 13:49:45 -0400279
280 /* We must cancel and cleanup any pending vblank enable/disable
281 * work before drm_irq_uninstall() to avoid work re-enabling an
282 * irq after uninstall has disabled it.
283 */
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400284 kthread_flush_work(&vbl_ctrl->work);
Hai Li78b1d472015-07-27 13:49:45 -0400285 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
286 list_del(&vbl_ev->node);
287 kfree(vbl_ev);
288 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400289
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400290 /* clean up display commit/event worker threads */
291 for (i = 0; i < priv->num_crtcs; i++) {
292 if (priv->disp_thread[i].thread) {
293 kthread_flush_worker(&priv->disp_thread[i].worker);
294 kthread_stop(priv->disp_thread[i].thread);
295 priv->disp_thread[i].thread = NULL;
296 }
297
298 if (priv->event_thread[i].thread) {
299 kthread_flush_worker(&priv->event_thread[i].worker);
300 kthread_stop(priv->event_thread[i].thread);
301 priv->event_thread[i].thread = NULL;
302 }
303 }
304
Rob Clark68209392016-05-17 16:19:32 -0400305 msm_gem_shrinker_cleanup(ddev);
306
Archit Taneja2b669872016-05-02 11:05:54 +0530307 drm_kms_helper_poll_fini(ddev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530308
Archit Taneja2b669872016-05-02 11:05:54 +0530309 drm_dev_unregister(ddev);
Archit Taneja8208ed92016-05-02 11:05:53 +0530310
Noralf Trønnes85eac472017-03-07 21:49:22 +0100311 msm_perf_debugfs_cleanup(priv);
312 msm_rd_debugfs_cleanup(priv);
313
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530314#ifdef CONFIG_DRM_FBDEV_EMULATION
315 if (fbdev && priv->fbdev)
Archit Taneja2b669872016-05-02 11:05:54 +0530316 msm_fbdev_free(ddev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530317#endif
Daniel Vetter3ea4b1e2018-10-04 22:24:36 +0200318 drm_atomic_helper_shutdown(ddev);
Archit Taneja2b669872016-05-02 11:05:54 +0530319 drm_mode_config_cleanup(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400320
Archit Taneja2b669872016-05-02 11:05:54 +0530321 pm_runtime_get_sync(dev);
322 drm_irq_uninstall(ddev);
323 pm_runtime_put_sync(dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400324
325 flush_workqueue(priv->wq);
326 destroy_workqueue(priv->wq);
327
Archit Taneja16976082016-11-03 17:36:18 +0530328 if (kms && kms->funcs)
Rob Clarkc8afe682013-06-26 12:44:06 -0400329 kms->funcs->destroy(kms);
Rob Clarkc8afe682013-06-26 12:44:06 -0400330
Rob Clark871d8122013-11-16 12:56:06 -0500331 if (priv->vram.paddr) {
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700332 unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
Rob Clark871d8122013-11-16 12:56:06 -0500333 drm_mm_takedown(&priv->vram.mm);
Archit Taneja2b669872016-05-02 11:05:54 +0530334 dma_free_attrs(dev, priv->vram.size, NULL,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700335 priv->vram.paddr, attrs);
Rob Clark871d8122013-11-16 12:56:06 -0500336 }
337
Archit Taneja2b669872016-05-02 11:05:54 +0530338 component_unbind_all(dev, ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500339
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400340 if (mdss && mdss->funcs)
341 mdss->funcs->destroy(ddev);
Archit Taneja0a6030d2016-05-08 21:36:28 +0530342
Archit Taneja2b669872016-05-02 11:05:54 +0530343 ddev->dev_private = NULL;
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200344 drm_dev_put(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400345
346 kfree(priv);
347
348 return 0;
349}
350
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400351#define KMS_MDP4 4
352#define KMS_MDP5 5
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400353#define KMS_DPU 3
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400354
Rob Clark06c0dd92013-11-30 17:51:47 -0500355static int get_mdp_ver(struct platform_device *pdev)
356{
Rob Clark06c0dd92013-11-30 17:51:47 -0500357 struct device *dev = &pdev->dev;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530358
359 return (int) (unsigned long) of_device_get_match_data(dev);
Rob Clark06c0dd92013-11-30 17:51:47 -0500360}
361
Rob Clark072f1f92015-03-03 15:04:25 -0500362#include <linux/of_address.h>
363
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500364static int msm_init_vram(struct drm_device *dev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400365{
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500366 struct msm_drm_private *priv = dev->dev_private;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530367 struct device_node *node;
Rob Clark072f1f92015-03-03 15:04:25 -0500368 unsigned long size = 0;
369 int ret = 0;
370
Rob Clark072f1f92015-03-03 15:04:25 -0500371 /* In the device-tree world, we could have a 'memory-region'
372 * phandle, which gives us a link to our "vram". Allocating
373 * is all nicely abstracted behind the dma api, but we need
374 * to know the entire size to allocate it all in one go. There
375 * are two cases:
376 * 1) device with no IOMMU, in which case we need exclusive
377 * access to a VRAM carveout big enough for all gpu
378 * buffers
379 * 2) device with IOMMU, but where the bootloader puts up
380 * a splash screen. In this case, the VRAM carveout
381 * need only be large enough for fbdev fb. But we need
382 * exclusive access to the buffer to avoid the kernel
383 * using those pages for other purposes (which appears
384 * as corruption on screen before we have a chance to
385 * load and do initial modeset)
386 */
Rob Clark072f1f92015-03-03 15:04:25 -0500387
388 node = of_parse_phandle(dev->dev->of_node, "memory-region", 0);
389 if (node) {
390 struct resource r;
391 ret = of_address_to_resource(node, 0, &r);
Peter Chen2ca41c172016-07-04 16:49:50 +0800392 of_node_put(node);
Rob Clark072f1f92015-03-03 15:04:25 -0500393 if (ret)
394 return ret;
395 size = r.end - r.start;
Thierry Redingfc99f972015-04-09 16:39:51 +0200396 DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
Rob Clarkc8afe682013-06-26 12:44:06 -0400397
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530398 /* if we have no IOMMU, then we need to use carveout allocator.
399 * Grab the entire CMA chunk carved out in early startup in
400 * mach-msm:
401 */
402 } else if (!iommu_present(&platform_bus_type)) {
Rob Clark072f1f92015-03-03 15:04:25 -0500403 DRM_INFO("using %s VRAM carveout\n", vram);
404 size = memparse(vram, NULL);
405 }
406
407 if (size) {
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700408 unsigned long attrs = 0;
Rob Clark871d8122013-11-16 12:56:06 -0500409 void *p;
410
Rob Clark871d8122013-11-16 12:56:06 -0500411 priv->vram.size = size;
412
413 drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);
Sushmita Susheelendra0e082702017-06-13 16:52:54 -0600414 spin_lock_init(&priv->vram.lock);
Rob Clark871d8122013-11-16 12:56:06 -0500415
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700416 attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
417 attrs |= DMA_ATTR_WRITE_COMBINE;
Rob Clark871d8122013-11-16 12:56:06 -0500418
419 /* note that for no-kernel-mapping, the vaddr returned
420 * is bogus, but non-null if allocation succeeded:
421 */
422 p = dma_alloc_attrs(dev->dev, size,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700423 &priv->vram.paddr, GFP_KERNEL, attrs);
Rob Clark871d8122013-11-16 12:56:06 -0500424 if (!p) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530425 DRM_DEV_ERROR(dev->dev, "failed to allocate VRAM\n");
Rob Clark871d8122013-11-16 12:56:06 -0500426 priv->vram.paddr = 0;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500427 return -ENOMEM;
Rob Clark871d8122013-11-16 12:56:06 -0500428 }
429
Mamta Shukla6a41da12018-10-20 23:19:26 +0530430 DRM_DEV_INFO(dev->dev, "VRAM: %08x->%08x\n",
Rob Clark871d8122013-11-16 12:56:06 -0500431 (uint32_t)priv->vram.paddr,
432 (uint32_t)(priv->vram.paddr + size));
433 }
434
Rob Clark072f1f92015-03-03 15:04:25 -0500435 return ret;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500436}
437
Archit Taneja2b669872016-05-02 11:05:54 +0530438static int msm_drm_init(struct device *dev, struct drm_driver *drv)
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500439{
Archit Taneja2b669872016-05-02 11:05:54 +0530440 struct platform_device *pdev = to_platform_device(dev);
441 struct drm_device *ddev;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500442 struct msm_drm_private *priv;
443 struct msm_kms *kms;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400444 struct msm_mdss *mdss;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400445 int ret, i;
446 struct sched_param param;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500447
Archit Taneja2b669872016-05-02 11:05:54 +0530448 ddev = drm_dev_alloc(drv, dev);
Tom Gundersen0f288602016-09-21 16:59:19 +0200449 if (IS_ERR(ddev)) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530450 DRM_DEV_ERROR(dev, "failed to allocate drm_device\n");
Tom Gundersen0f288602016-09-21 16:59:19 +0200451 return PTR_ERR(ddev);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500452 }
453
Archit Taneja2b669872016-05-02 11:05:54 +0530454 platform_set_drvdata(pdev, ddev);
Archit Taneja2b669872016-05-02 11:05:54 +0530455
456 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
457 if (!priv) {
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400458 ret = -ENOMEM;
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200459 goto err_put_drm_dev;
Archit Taneja2b669872016-05-02 11:05:54 +0530460 }
461
462 ddev->dev_private = priv;
Rob Clark68209392016-05-17 16:19:32 -0400463 priv->dev = ddev;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500464
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400465 switch (get_mdp_ver(pdev)) {
466 case KMS_MDP5:
467 ret = mdp5_mdss_init(ddev);
468 break;
469 case KMS_DPU:
470 ret = dpu_mdss_init(ddev);
471 break;
472 default:
473 ret = 0;
474 break;
475 }
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400476 if (ret)
477 goto err_free_priv;
Archit Taneja0a6030d2016-05-08 21:36:28 +0530478
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400479 mdss = priv->mdss;
480
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500481 priv->wq = alloc_ordered_workqueue("msm", 0);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500482
483 INIT_LIST_HEAD(&priv->inactive_list);
Hai Li78b1d472015-07-27 13:49:45 -0400484 INIT_LIST_HEAD(&priv->vblank_ctrl.event_list);
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400485 kthread_init_work(&priv->vblank_ctrl.work, vblank_ctrl_worker);
Hai Li78b1d472015-07-27 13:49:45 -0400486 spin_lock_init(&priv->vblank_ctrl.lock);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500487
Archit Taneja2b669872016-05-02 11:05:54 +0530488 drm_mode_config_init(ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500489
490 /* Bind all our sub-components: */
Archit Taneja2b669872016-05-02 11:05:54 +0530491 ret = component_bind_all(dev, ddev);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400492 if (ret)
493 goto err_destroy_mdss;
Rob Clark060530f2014-03-03 14:19:12 -0500494
Archit Taneja2b669872016-05-02 11:05:54 +0530495 ret = msm_init_vram(ddev);
Rob Clark13f15562015-05-07 15:20:13 -0400496 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400497 goto err_msm_uninit;
Rob Clark13f15562015-05-07 15:20:13 -0400498
Rob Clark68209392016-05-17 16:19:32 -0400499 msm_gem_shrinker_init(ddev);
500
Rob Clark06c0dd92013-11-30 17:51:47 -0500501 switch (get_mdp_ver(pdev)) {
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400502 case KMS_MDP4:
Archit Taneja2b669872016-05-02 11:05:54 +0530503 kms = mdp4_kms_init(ddev);
Archit Taneja0a6030d2016-05-08 21:36:28 +0530504 priv->kms = kms;
Rob Clark06c0dd92013-11-30 17:51:47 -0500505 break;
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400506 case KMS_MDP5:
Archit Taneja392ae6e2016-06-14 18:24:54 +0530507 kms = mdp5_kms_init(ddev);
Rob Clark06c0dd92013-11-30 17:51:47 -0500508 break;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400509 case KMS_DPU:
510 kms = dpu_kms_init(ddev);
511 priv->kms = kms;
512 break;
Rob Clark06c0dd92013-11-30 17:51:47 -0500513 default:
514 kms = ERR_PTR(-ENODEV);
515 break;
516 }
517
Rob Clarkc8afe682013-06-26 12:44:06 -0400518 if (IS_ERR(kms)) {
519 /*
520 * NOTE: once we have GPU support, having no kms should not
521 * be considered fatal.. ideally we would still support gpu
522 * and (for example) use dmabuf/prime to share buffers with
523 * imx drm driver on iMX5
524 */
Mamta Shukla6a41da12018-10-20 23:19:26 +0530525 DRM_DEV_ERROR(dev, "failed to load kms\n");
Thomas Meyere4826a92013-09-16 23:19:54 +0200526 ret = PTR_ERR(kms);
Jonathan Marekb2ccfdf2018-11-21 20:52:35 -0500527 priv->kms = NULL;
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400528 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400529 }
530
Jeykumar Sankaranbb676df2018-06-11 14:13:20 -0700531 /* Enable normalization of plane zpos */
532 ddev->mode_config.normalize_zpos = true;
533
Rob Clarkc8afe682013-06-26 12:44:06 -0400534 if (kms) {
Rob Clarkc8afe682013-06-26 12:44:06 -0400535 ret = kms->funcs->hw_init(kms);
536 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530537 DRM_DEV_ERROR(dev, "kms hw init failed: %d\n", ret);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400538 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400539 }
540 }
541
Archit Taneja2b669872016-05-02 11:05:54 +0530542 ddev->mode_config.funcs = &mode_config_funcs;
Sean Pauld14659f2018-02-28 14:19:05 -0500543 ddev->mode_config.helper_private = &mode_config_helper_funcs;
Rob Clarkc8afe682013-06-26 12:44:06 -0400544
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400545 /**
546 * this priority was found during empiric testing to have appropriate
547 * realtime scheduling to process display updates and interact with
548 * other real time and normal priority task
549 */
550 param.sched_priority = 16;
551 for (i = 0; i < priv->num_crtcs; i++) {
552
553 /* initialize display thread */
554 priv->disp_thread[i].crtc_id = priv->crtcs[i]->base.id;
555 kthread_init_worker(&priv->disp_thread[i].worker);
556 priv->disp_thread[i].dev = ddev;
557 priv->disp_thread[i].thread =
558 kthread_run(kthread_worker_fn,
559 &priv->disp_thread[i].worker,
560 "crtc_commit:%d", priv->disp_thread[i].crtc_id);
561 ret = sched_setscheduler(priv->disp_thread[i].thread,
562 SCHED_FIFO, &param);
563 if (ret)
564 pr_warn("display thread priority update failed: %d\n",
565 ret);
566
567 if (IS_ERR(priv->disp_thread[i].thread)) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530568 DRM_DEV_ERROR(dev, "failed to create crtc_commit kthread\n");
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400569 priv->disp_thread[i].thread = NULL;
570 }
571
572 /* initialize event thread */
573 priv->event_thread[i].crtc_id = priv->crtcs[i]->base.id;
574 kthread_init_worker(&priv->event_thread[i].worker);
575 priv->event_thread[i].dev = ddev;
576 priv->event_thread[i].thread =
577 kthread_run(kthread_worker_fn,
578 &priv->event_thread[i].worker,
579 "crtc_event:%d", priv->event_thread[i].crtc_id);
Mamta Shukla6a41da12018-10-20 23:19:26 +0530580
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400581 /**
582 * event thread should also run at same priority as disp_thread
583 * because it is handling frame_done events. A lower priority
584 * event thread and higher priority disp_thread can causes
585 * frame_pending counters beyond 2. This can lead to commit
586 * failure at crtc commit level.
587 */
588 ret = sched_setscheduler(priv->event_thread[i].thread,
589 SCHED_FIFO, &param);
590 if (ret)
591 pr_warn("display event thread priority update failed: %d\n",
592 ret);
593
594 if (IS_ERR(priv->event_thread[i].thread)) {
595 dev_err(dev, "failed to create crtc_event kthread\n");
596 priv->event_thread[i].thread = NULL;
597 }
598
599 if ((!priv->disp_thread[i].thread) ||
600 !priv->event_thread[i].thread) {
601 /* clean up previously created threads if any */
602 for ( ; i >= 0; i--) {
603 if (priv->disp_thread[i].thread) {
604 kthread_stop(
605 priv->disp_thread[i].thread);
606 priv->disp_thread[i].thread = NULL;
607 }
608
609 if (priv->event_thread[i].thread) {
610 kthread_stop(
611 priv->event_thread[i].thread);
612 priv->event_thread[i].thread = NULL;
613 }
614 }
615 goto err_msm_uninit;
616 }
617 }
618
Archit Taneja2b669872016-05-02 11:05:54 +0530619 ret = drm_vblank_init(ddev, priv->num_crtcs);
Rob Clarkc8afe682013-06-26 12:44:06 -0400620 if (ret < 0) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530621 DRM_DEV_ERROR(dev, "failed to initialize vblank\n");
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400622 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400623 }
624
Archit Tanejaa2b3a552016-05-18 15:06:03 +0530625 if (kms) {
626 pm_runtime_get_sync(dev);
627 ret = drm_irq_install(ddev, kms->irq);
628 pm_runtime_put_sync(dev);
629 if (ret < 0) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530630 DRM_DEV_ERROR(dev, "failed to install IRQ handler\n");
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400631 goto err_msm_uninit;
Archit Tanejaa2b3a552016-05-18 15:06:03 +0530632 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400633 }
634
Archit Taneja2b669872016-05-02 11:05:54 +0530635 ret = drm_dev_register(ddev, 0);
Rob Clarka7d3c952014-05-30 14:47:38 -0400636 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400637 goto err_msm_uninit;
Rob Clarka7d3c952014-05-30 14:47:38 -0400638
Archit Taneja2b669872016-05-02 11:05:54 +0530639 drm_mode_config_reset(ddev);
640
641#ifdef CONFIG_DRM_FBDEV_EMULATION
642 if (fbdev)
643 priv->fbdev = msm_fbdev_init(ddev);
644#endif
645
646 ret = msm_debugfs_late_init(ddev);
647 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400648 goto err_msm_uninit;
Archit Taneja2b669872016-05-02 11:05:54 +0530649
650 drm_kms_helper_poll_init(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400651
652 return 0;
653
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400654err_msm_uninit:
Archit Taneja2b669872016-05-02 11:05:54 +0530655 msm_drm_uninit(dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400656 return ret;
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400657err_destroy_mdss:
658 if (mdss && mdss->funcs)
659 mdss->funcs->destroy(ddev);
660err_free_priv:
661 kfree(priv);
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200662err_put_drm_dev:
663 drm_dev_put(ddev);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400664 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -0400665}
666
Archit Taneja2b669872016-05-02 11:05:54 +0530667/*
668 * DRM operations:
669 */
670
Rob Clark7198e6b2013-07-19 12:59:32 -0400671static void load_gpu(struct drm_device *dev)
672{
Rob Clarka1ad3522014-07-11 11:59:22 -0400673 static DEFINE_MUTEX(init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400674 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400675
Rob Clarka1ad3522014-07-11 11:59:22 -0400676 mutex_lock(&init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400677
Rob Clarke2550b72014-09-05 13:30:27 -0400678 if (!priv->gpu)
679 priv->gpu = adreno_load_gpu(dev);
Rob Clarka1ad3522014-07-11 11:59:22 -0400680
Rob Clarka1ad3522014-07-11 11:59:22 -0400681 mutex_unlock(&init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400682}
683
Jordan Crousef97deca2017-10-20 11:06:57 -0600684static int context_init(struct drm_device *dev, struct drm_file *file)
Rob Clark7198e6b2013-07-19 12:59:32 -0400685{
686 struct msm_file_private *ctx;
687
Rob Clark7198e6b2013-07-19 12:59:32 -0400688 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
689 if (!ctx)
690 return -ENOMEM;
691
Jordan Crousef97deca2017-10-20 11:06:57 -0600692 msm_submitqueue_init(dev, ctx);
Jordan Crousef7de1542017-10-20 11:06:55 -0600693
Rob Clark7198e6b2013-07-19 12:59:32 -0400694 file->driver_priv = ctx;
695
696 return 0;
697}
698
Jordan Crousef7de1542017-10-20 11:06:55 -0600699static int msm_open(struct drm_device *dev, struct drm_file *file)
700{
701 /* For now, load gpu on open.. to avoid the requirement of having
702 * firmware in the initrd.
703 */
704 load_gpu(dev);
705
Jordan Crousef97deca2017-10-20 11:06:57 -0600706 return context_init(dev, file);
Jordan Crousef7de1542017-10-20 11:06:55 -0600707}
708
709static void context_close(struct msm_file_private *ctx)
710{
711 msm_submitqueue_close(ctx);
712 kfree(ctx);
713}
714
Daniel Vetter94df1452017-03-08 15:12:46 +0100715static void msm_postclose(struct drm_device *dev, struct drm_file *file)
Rob Clarkc8afe682013-06-26 12:44:06 -0400716{
717 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400718 struct msm_file_private *ctx = file->driver_priv;
Rob Clark7198e6b2013-07-19 12:59:32 -0400719
Rob Clark7198e6b2013-07-19 12:59:32 -0400720 mutex_lock(&dev->struct_mutex);
721 if (ctx == priv->lastctx)
722 priv->lastctx = NULL;
723 mutex_unlock(&dev->struct_mutex);
724
Jordan Crousef7de1542017-10-20 11:06:55 -0600725 context_close(ctx);
Rob Clarkc8afe682013-06-26 12:44:06 -0400726}
727
Daniel Vettere9f0d762013-12-11 11:34:42 +0100728static irqreturn_t msm_irq(int irq, void *arg)
Rob Clarkc8afe682013-06-26 12:44:06 -0400729{
730 struct drm_device *dev = arg;
731 struct msm_drm_private *priv = dev->dev_private;
732 struct msm_kms *kms = priv->kms;
733 BUG_ON(!kms);
734 return kms->funcs->irq(kms);
735}
736
737static void msm_irq_preinstall(struct drm_device *dev)
738{
739 struct msm_drm_private *priv = dev->dev_private;
740 struct msm_kms *kms = priv->kms;
741 BUG_ON(!kms);
742 kms->funcs->irq_preinstall(kms);
743}
744
745static int msm_irq_postinstall(struct drm_device *dev)
746{
747 struct msm_drm_private *priv = dev->dev_private;
748 struct msm_kms *kms = priv->kms;
749 BUG_ON(!kms);
750 return kms->funcs->irq_postinstall(kms);
751}
752
753static void msm_irq_uninstall(struct drm_device *dev)
754{
755 struct msm_drm_private *priv = dev->dev_private;
756 struct msm_kms *kms = priv->kms;
757 BUG_ON(!kms);
758 kms->funcs->irq_uninstall(kms);
759}
760
Thierry Reding88e72712015-09-24 18:35:31 +0200761static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
Rob Clarkc8afe682013-06-26 12:44:06 -0400762{
763 struct msm_drm_private *priv = dev->dev_private;
764 struct msm_kms *kms = priv->kms;
765 if (!kms)
766 return -ENXIO;
Thierry Reding88e72712015-09-24 18:35:31 +0200767 DBG("dev=%p, crtc=%u", dev, pipe);
768 return vblank_ctrl_queue_work(priv, pipe, true);
Rob Clarkc8afe682013-06-26 12:44:06 -0400769}
770
Thierry Reding88e72712015-09-24 18:35:31 +0200771static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
Rob Clarkc8afe682013-06-26 12:44:06 -0400772{
773 struct msm_drm_private *priv = dev->dev_private;
774 struct msm_kms *kms = priv->kms;
775 if (!kms)
776 return;
Thierry Reding88e72712015-09-24 18:35:31 +0200777 DBG("dev=%p, crtc=%u", dev, pipe);
778 vblank_ctrl_queue_work(priv, pipe, false);
Rob Clarkc8afe682013-06-26 12:44:06 -0400779}
780
781/*
Rob Clark7198e6b2013-07-19 12:59:32 -0400782 * DRM ioctls:
783 */
784
785static int msm_ioctl_get_param(struct drm_device *dev, void *data,
786 struct drm_file *file)
787{
788 struct msm_drm_private *priv = dev->dev_private;
789 struct drm_msm_param *args = data;
790 struct msm_gpu *gpu;
791
792 /* for now, we just have 3d pipe.. eventually this would need to
793 * be more clever to dispatch to appropriate gpu module:
794 */
795 if (args->pipe != MSM_PIPE_3D0)
796 return -EINVAL;
797
798 gpu = priv->gpu;
799
800 if (!gpu)
801 return -ENXIO;
802
803 return gpu->funcs->get_param(gpu, args->param, &args->value);
804}
805
806static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
807 struct drm_file *file)
808{
809 struct drm_msm_gem_new *args = data;
Rob Clark93ddb0d2014-03-03 09:42:33 -0500810
811 if (args->flags & ~MSM_BO_FLAGS) {
812 DRM_ERROR("invalid flags: %08x\n", args->flags);
813 return -EINVAL;
814 }
815
Rob Clark7198e6b2013-07-19 12:59:32 -0400816 return msm_gem_new_handle(dev, file, args->size,
Jordan Crouse0815d772018-11-07 15:35:52 -0700817 args->flags, &args->handle, NULL);
Rob Clark7198e6b2013-07-19 12:59:32 -0400818}
819
Rob Clark56c2da82015-05-11 11:50:03 -0400820static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
821{
822 return ktime_set(timeout.tv_sec, timeout.tv_nsec);
823}
Rob Clark7198e6b2013-07-19 12:59:32 -0400824
825static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
826 struct drm_file *file)
827{
828 struct drm_msm_gem_cpu_prep *args = data;
829 struct drm_gem_object *obj;
Rob Clark56c2da82015-05-11 11:50:03 -0400830 ktime_t timeout = to_ktime(args->timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400831 int ret;
832
Rob Clark93ddb0d2014-03-03 09:42:33 -0500833 if (args->op & ~MSM_PREP_FLAGS) {
834 DRM_ERROR("invalid op: %08x\n", args->op);
835 return -EINVAL;
836 }
837
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100838 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400839 if (!obj)
840 return -ENOENT;
841
Rob Clark56c2da82015-05-11 11:50:03 -0400842 ret = msm_gem_cpu_prep(obj, args->op, &timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400843
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100844 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400845
846 return ret;
847}
848
849static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
850 struct drm_file *file)
851{
852 struct drm_msm_gem_cpu_fini *args = data;
853 struct drm_gem_object *obj;
854 int ret;
855
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100856 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400857 if (!obj)
858 return -ENOENT;
859
860 ret = msm_gem_cpu_fini(obj);
861
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100862 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400863
864 return ret;
865}
866
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600867static int msm_ioctl_gem_info_iova(struct drm_device *dev,
868 struct drm_gem_object *obj, uint64_t *iova)
869{
870 struct msm_drm_private *priv = dev->dev_private;
871
872 if (!priv->gpu)
873 return -EINVAL;
874
Jordan Crouse9fe041f2018-11-07 15:35:50 -0700875 /*
876 * Don't pin the memory here - just get an address so that userspace can
877 * be productive
878 */
Rob Clark8bdcd942017-06-13 11:07:08 -0400879 return msm_gem_get_iova(obj, priv->gpu->aspace, iova);
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600880}
881
Rob Clark7198e6b2013-07-19 12:59:32 -0400882static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
883 struct drm_file *file)
884{
885 struct drm_msm_gem_info *args = data;
886 struct drm_gem_object *obj;
Rob Clarkf05c83e2018-11-29 10:27:22 -0500887 struct msm_gem_object *msm_obj;
888 int i, ret = 0;
Rob Clark7198e6b2013-07-19 12:59:32 -0400889
Rob Clark789d2e52018-11-29 09:54:42 -0500890 if (args->pad)
Rob Clark7198e6b2013-07-19 12:59:32 -0400891 return -EINVAL;
892
Rob Clark789d2e52018-11-29 09:54:42 -0500893 switch (args->info) {
894 case MSM_INFO_GET_OFFSET:
895 case MSM_INFO_GET_IOVA:
896 /* value returned as immediate, not pointer, so len==0: */
897 if (args->len)
898 return -EINVAL;
899 break;
Rob Clarkf05c83e2018-11-29 10:27:22 -0500900 case MSM_INFO_SET_NAME:
901 case MSM_INFO_GET_NAME:
902 break;
Rob Clark789d2e52018-11-29 09:54:42 -0500903 default:
904 return -EINVAL;
905 }
906
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100907 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400908 if (!obj)
909 return -ENOENT;
910
Rob Clarkf05c83e2018-11-29 10:27:22 -0500911 msm_obj = to_msm_bo(obj);
912
Rob Clark789d2e52018-11-29 09:54:42 -0500913 switch (args->info) {
914 case MSM_INFO_GET_OFFSET:
915 args->value = msm_gem_mmap_offset(obj);
916 break;
917 case MSM_INFO_GET_IOVA:
918 ret = msm_ioctl_gem_info_iova(dev, obj, &args->value);
919 break;
Rob Clarkf05c83e2018-11-29 10:27:22 -0500920 case MSM_INFO_SET_NAME:
921 /* length check should leave room for terminating null: */
922 if (args->len >= sizeof(msm_obj->name)) {
923 ret = -EINVAL;
924 break;
925 }
926 ret = copy_from_user(msm_obj->name,
927 u64_to_user_ptr(args->value), args->len);
928 msm_obj->name[args->len] = '\0';
929 for (i = 0; i < args->len; i++) {
930 if (!isprint(msm_obj->name[i])) {
931 msm_obj->name[i] = '\0';
932 break;
933 }
934 }
935 break;
936 case MSM_INFO_GET_NAME:
937 if (args->value && (args->len < strlen(msm_obj->name))) {
938 ret = -EINVAL;
939 break;
940 }
941 args->len = strlen(msm_obj->name);
942 if (args->value) {
943 ret = copy_to_user(u64_to_user_ptr(args->value),
944 msm_obj->name, args->len);
945 }
946 break;
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600947 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400948
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100949 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400950
951 return ret;
952}
953
954static int msm_ioctl_wait_fence(struct drm_device *dev, void *data,
955 struct drm_file *file)
956{
Rob Clarkca762a82016-03-15 17:22:13 -0400957 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400958 struct drm_msm_wait_fence *args = data;
Rob Clark56c2da82015-05-11 11:50:03 -0400959 ktime_t timeout = to_ktime(args->timeout);
Jordan Crousef97deca2017-10-20 11:06:57 -0600960 struct msm_gpu_submitqueue *queue;
961 struct msm_gpu *gpu = priv->gpu;
962 int ret;
Rob Clark93ddb0d2014-03-03 09:42:33 -0500963
964 if (args->pad) {
965 DRM_ERROR("invalid pad: %08x\n", args->pad);
966 return -EINVAL;
967 }
968
Jordan Crousef97deca2017-10-20 11:06:57 -0600969 if (!gpu)
Rob Clarkca762a82016-03-15 17:22:13 -0400970 return 0;
971
Jordan Crousef97deca2017-10-20 11:06:57 -0600972 queue = msm_submitqueue_get(file->driver_priv, args->queueid);
973 if (!queue)
974 return -ENOENT;
975
976 ret = msm_wait_fence(gpu->rb[queue->prio]->fctx, args->fence, &timeout,
977 true);
978
979 msm_submitqueue_put(queue);
980 return ret;
Rob Clark7198e6b2013-07-19 12:59:32 -0400981}
982
Rob Clark4cd33c42016-05-17 15:44:49 -0400983static int msm_ioctl_gem_madvise(struct drm_device *dev, void *data,
984 struct drm_file *file)
985{
986 struct drm_msm_gem_madvise *args = data;
987 struct drm_gem_object *obj;
988 int ret;
989
990 switch (args->madv) {
991 case MSM_MADV_DONTNEED:
992 case MSM_MADV_WILLNEED:
993 break;
994 default:
995 return -EINVAL;
996 }
997
998 ret = mutex_lock_interruptible(&dev->struct_mutex);
999 if (ret)
1000 return ret;
1001
1002 obj = drm_gem_object_lookup(file, args->handle);
1003 if (!obj) {
1004 ret = -ENOENT;
1005 goto unlock;
1006 }
1007
1008 ret = msm_gem_madvise(obj, args->madv);
1009 if (ret >= 0) {
1010 args->retained = ret;
1011 ret = 0;
1012 }
1013
Steve Kowalikdc9a9b32018-01-26 14:55:54 +11001014 drm_gem_object_put(obj);
Rob Clark4cd33c42016-05-17 15:44:49 -04001015
1016unlock:
1017 mutex_unlock(&dev->struct_mutex);
1018 return ret;
1019}
1020
Jordan Crousef7de1542017-10-20 11:06:55 -06001021
1022static int msm_ioctl_submitqueue_new(struct drm_device *dev, void *data,
1023 struct drm_file *file)
1024{
1025 struct drm_msm_submitqueue *args = data;
1026
1027 if (args->flags & ~MSM_SUBMITQUEUE_FLAGS)
1028 return -EINVAL;
1029
Jordan Crousef97deca2017-10-20 11:06:57 -06001030 return msm_submitqueue_create(dev, file->driver_priv, args->prio,
Jordan Crousef7de1542017-10-20 11:06:55 -06001031 args->flags, &args->id);
1032}
1033
1034
1035static int msm_ioctl_submitqueue_close(struct drm_device *dev, void *data,
1036 struct drm_file *file)
1037{
1038 u32 id = *(u32 *) data;
1039
1040 return msm_submitqueue_remove(file->driver_priv, id);
1041}
1042
Rob Clark7198e6b2013-07-19 12:59:32 -04001043static const struct drm_ioctl_desc msm_ioctls[] = {
Daniel Vetterf8c47142015-09-08 13:56:30 +02001044 DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_AUTH|DRM_RENDER_ALLOW),
1045 DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW),
1046 DRM_IOCTL_DEF_DRV(MSM_GEM_INFO, msm_ioctl_gem_info, DRM_AUTH|DRM_RENDER_ALLOW),
1047 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
1048 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
1049 DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_AUTH|DRM_RENDER_ALLOW),
1050 DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_AUTH|DRM_RENDER_ALLOW),
Rob Clark4cd33c42016-05-17 15:44:49 -04001051 DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW),
Jordan Crousef7de1542017-10-20 11:06:55 -06001052 DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_NEW, msm_ioctl_submitqueue_new, DRM_AUTH|DRM_RENDER_ALLOW),
1053 DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_CLOSE, msm_ioctl_submitqueue_close, DRM_AUTH|DRM_RENDER_ALLOW),
Rob Clark7198e6b2013-07-19 12:59:32 -04001054};
1055
Rob Clarkc8afe682013-06-26 12:44:06 -04001056static const struct vm_operations_struct vm_ops = {
1057 .fault = msm_gem_fault,
1058 .open = drm_gem_vm_open,
1059 .close = drm_gem_vm_close,
1060};
1061
1062static const struct file_operations fops = {
1063 .owner = THIS_MODULE,
1064 .open = drm_open,
1065 .release = drm_release,
1066 .unlocked_ioctl = drm_ioctl,
Rob Clarkc8afe682013-06-26 12:44:06 -04001067 .compat_ioctl = drm_compat_ioctl,
Rob Clarkc8afe682013-06-26 12:44:06 -04001068 .poll = drm_poll,
1069 .read = drm_read,
1070 .llseek = no_llseek,
1071 .mmap = msm_gem_mmap,
1072};
1073
1074static struct drm_driver msm_driver = {
Rob Clark05b84912013-09-28 11:28:35 -04001075 .driver_features = DRIVER_HAVE_IRQ |
1076 DRIVER_GEM |
1077 DRIVER_PRIME |
Rob Clarkb4b15c82013-09-28 12:01:25 -04001078 DRIVER_RENDER |
Rob Clarka5436e12015-06-04 10:12:22 -04001079 DRIVER_ATOMIC |
Rob Clark05b84912013-09-28 11:28:35 -04001080 DRIVER_MODESET,
Rob Clark7198e6b2013-07-19 12:59:32 -04001081 .open = msm_open,
Daniel Vetter94df1452017-03-08 15:12:46 +01001082 .postclose = msm_postclose,
Noralf Trønnes4ccbc6e2017-12-05 19:24:59 +01001083 .lastclose = drm_fb_helper_lastclose,
Rob Clarkc8afe682013-06-26 12:44:06 -04001084 .irq_handler = msm_irq,
1085 .irq_preinstall = msm_irq_preinstall,
1086 .irq_postinstall = msm_irq_postinstall,
1087 .irq_uninstall = msm_irq_uninstall,
Rob Clarkc8afe682013-06-26 12:44:06 -04001088 .enable_vblank = msm_enable_vblank,
1089 .disable_vblank = msm_disable_vblank,
1090 .gem_free_object = msm_gem_free_object,
1091 .gem_vm_ops = &vm_ops,
1092 .dumb_create = msm_gem_dumb_create,
1093 .dumb_map_offset = msm_gem_dumb_map_offset,
Rob Clark05b84912013-09-28 11:28:35 -04001094 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
1095 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
1096 .gem_prime_export = drm_gem_prime_export,
1097 .gem_prime_import = drm_gem_prime_import,
Eric Anholt43523eb2017-04-12 12:11:58 -07001098 .gem_prime_res_obj = msm_gem_prime_res_obj,
Rob Clark05b84912013-09-28 11:28:35 -04001099 .gem_prime_pin = msm_gem_prime_pin,
1100 .gem_prime_unpin = msm_gem_prime_unpin,
1101 .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
1102 .gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
1103 .gem_prime_vmap = msm_gem_prime_vmap,
1104 .gem_prime_vunmap = msm_gem_prime_vunmap,
Daniel Thompson77a147e2014-11-12 11:38:14 +00001105 .gem_prime_mmap = msm_gem_prime_mmap,
Rob Clarkc8afe682013-06-26 12:44:06 -04001106#ifdef CONFIG_DEBUG_FS
1107 .debugfs_init = msm_debugfs_init,
Rob Clarkc8afe682013-06-26 12:44:06 -04001108#endif
Rob Clark7198e6b2013-07-19 12:59:32 -04001109 .ioctls = msm_ioctls,
Jordan Crouse167b6062017-05-08 14:34:59 -06001110 .num_ioctls = ARRAY_SIZE(msm_ioctls),
Rob Clarkc8afe682013-06-26 12:44:06 -04001111 .fops = &fops,
1112 .name = "msm",
1113 .desc = "MSM Snapdragon DRM",
1114 .date = "20130625",
Rob Clarka8d854c2016-06-01 14:02:02 -04001115 .major = MSM_VERSION_MAJOR,
1116 .minor = MSM_VERSION_MINOR,
1117 .patchlevel = MSM_VERSION_PATCHLEVEL,
Rob Clarkc8afe682013-06-26 12:44:06 -04001118};
1119
1120#ifdef CONFIG_PM_SLEEP
1121static int msm_pm_suspend(struct device *dev)
1122{
1123 struct drm_device *ddev = dev_get_drvdata(dev);
Daniel Mackec446d02018-05-28 21:53:38 +02001124 struct msm_drm_private *priv = ddev->dev_private;
Jeykumar Sankaran036bfeb2018-06-27 15:24:17 -04001125
Bruce Wang3750e782018-10-05 17:04:01 -04001126 if (WARN_ON(priv->pm_state))
1127 drm_atomic_state_put(priv->pm_state);
Rob Clarkc8afe682013-06-26 12:44:06 -04001128
Daniel Mackec446d02018-05-28 21:53:38 +02001129 priv->pm_state = drm_atomic_helper_suspend(ddev);
1130 if (IS_ERR(priv->pm_state)) {
Bruce Wang3750e782018-10-05 17:04:01 -04001131 int ret = PTR_ERR(priv->pm_state);
1132 DRM_ERROR("Failed to suspend dpu, %d\n", ret);
1133 return ret;
Daniel Mackec446d02018-05-28 21:53:38 +02001134 }
1135
Rob Clarkc8afe682013-06-26 12:44:06 -04001136 return 0;
1137}
1138
1139static int msm_pm_resume(struct device *dev)
1140{
1141 struct drm_device *ddev = dev_get_drvdata(dev);
Daniel Mackec446d02018-05-28 21:53:38 +02001142 struct msm_drm_private *priv = ddev->dev_private;
Bruce Wang3750e782018-10-05 17:04:01 -04001143 int ret;
Jeykumar Sankaran036bfeb2018-06-27 15:24:17 -04001144
Bruce Wang3750e782018-10-05 17:04:01 -04001145 if (WARN_ON(!priv->pm_state))
1146 return -ENOENT;
Rob Clarkc8afe682013-06-26 12:44:06 -04001147
Bruce Wang3750e782018-10-05 17:04:01 -04001148 ret = drm_atomic_helper_resume(ddev, priv->pm_state);
1149 if (!ret)
1150 priv->pm_state = NULL;
Rob Clarkc8afe682013-06-26 12:44:06 -04001151
Bruce Wang3750e782018-10-05 17:04:01 -04001152 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -04001153}
1154#endif
1155
Archit Taneja774e39e2017-07-28 16:17:07 +05301156#ifdef CONFIG_PM
1157static int msm_runtime_suspend(struct device *dev)
1158{
1159 struct drm_device *ddev = dev_get_drvdata(dev);
1160 struct msm_drm_private *priv = ddev->dev_private;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001161 struct msm_mdss *mdss = priv->mdss;
Archit Taneja774e39e2017-07-28 16:17:07 +05301162
1163 DBG("");
1164
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001165 if (mdss && mdss->funcs)
1166 return mdss->funcs->disable(mdss);
Archit Taneja774e39e2017-07-28 16:17:07 +05301167
1168 return 0;
1169}
1170
1171static int msm_runtime_resume(struct device *dev)
1172{
1173 struct drm_device *ddev = dev_get_drvdata(dev);
1174 struct msm_drm_private *priv = ddev->dev_private;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001175 struct msm_mdss *mdss = priv->mdss;
Archit Taneja774e39e2017-07-28 16:17:07 +05301176
1177 DBG("");
1178
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001179 if (mdss && mdss->funcs)
1180 return mdss->funcs->enable(mdss);
Archit Taneja774e39e2017-07-28 16:17:07 +05301181
1182 return 0;
1183}
1184#endif
1185
Rob Clarkc8afe682013-06-26 12:44:06 -04001186static const struct dev_pm_ops msm_pm_ops = {
1187 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
Archit Taneja774e39e2017-07-28 16:17:07 +05301188 SET_RUNTIME_PM_OPS(msm_runtime_suspend, msm_runtime_resume, NULL)
Rob Clarkc8afe682013-06-26 12:44:06 -04001189};
1190
1191/*
Rob Clark060530f2014-03-03 14:19:12 -05001192 * Componentized driver support:
1193 */
1194
Archit Tanejae9fbdaf2015-11-18 12:15:14 +05301195/*
1196 * NOTE: duplication of the same code as exynos or imx (or probably any other).
1197 * so probably some room for some helpers
Rob Clark060530f2014-03-03 14:19:12 -05001198 */
1199static int compare_of(struct device *dev, void *data)
1200{
1201 return dev->of_node == data;
1202}
Rob Clark41e69772013-12-15 16:23:05 -05001203
Archit Taneja812070e2016-05-19 10:38:39 +05301204/*
1205 * Identify what components need to be added by parsing what remote-endpoints
1206 * our MDP output ports are connected to. In the case of LVDS on MDP4, there
1207 * is no external component that we need to add since LVDS is within MDP4
1208 * itself.
1209 */
1210static int add_components_mdp(struct device *mdp_dev,
1211 struct component_match **matchptr)
1212{
1213 struct device_node *np = mdp_dev->of_node;
1214 struct device_node *ep_node;
Archit Taneja54011e22016-06-06 13:45:34 +05301215 struct device *master_dev;
1216
1217 /*
1218 * on MDP4 based platforms, the MDP platform device is the component
1219 * master that adds other display interface components to itself.
1220 *
1221 * on MDP5 based platforms, the MDSS platform device is the component
1222 * master that adds MDP5 and other display interface components to
1223 * itself.
1224 */
1225 if (of_device_is_compatible(np, "qcom,mdp4"))
1226 master_dev = mdp_dev;
1227 else
1228 master_dev = mdp_dev->parent;
Archit Taneja812070e2016-05-19 10:38:39 +05301229
1230 for_each_endpoint_of_node(np, ep_node) {
1231 struct device_node *intf;
1232 struct of_endpoint ep;
1233 int ret;
1234
1235 ret = of_graph_parse_endpoint(ep_node, &ep);
1236 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +05301237 DRM_DEV_ERROR(mdp_dev, "unable to parse port endpoint\n");
Archit Taneja812070e2016-05-19 10:38:39 +05301238 of_node_put(ep_node);
1239 return ret;
1240 }
1241
1242 /*
1243 * The LCDC/LVDS port on MDP4 is a speacial case where the
1244 * remote-endpoint isn't a component that we need to add
1245 */
1246 if (of_device_is_compatible(np, "qcom,mdp4") &&
Archit Tanejad8dd8052016-11-17 12:12:03 +05301247 ep.port == 0)
Archit Taneja812070e2016-05-19 10:38:39 +05301248 continue;
Archit Taneja812070e2016-05-19 10:38:39 +05301249
1250 /*
1251 * It's okay if some of the ports don't have a remote endpoint
1252 * specified. It just means that the port isn't connected to
1253 * any external interface.
1254 */
1255 intf = of_graph_get_remote_port_parent(ep_node);
Archit Tanejad8dd8052016-11-17 12:12:03 +05301256 if (!intf)
Archit Taneja812070e2016-05-19 10:38:39 +05301257 continue;
Archit Taneja812070e2016-05-19 10:38:39 +05301258
Russell King97ac0e42016-10-19 11:28:27 +01001259 drm_of_component_match_add(master_dev, matchptr, compare_of,
1260 intf);
Archit Taneja812070e2016-05-19 10:38:39 +05301261 of_node_put(intf);
Archit Taneja812070e2016-05-19 10:38:39 +05301262 }
1263
1264 return 0;
1265}
1266
Archit Taneja54011e22016-06-06 13:45:34 +05301267static int compare_name_mdp(struct device *dev, void *data)
1268{
1269 return (strstr(dev_name(dev), "mdp") != NULL);
1270}
1271
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301272static int add_display_components(struct device *dev,
1273 struct component_match **matchptr)
1274{
Archit Taneja54011e22016-06-06 13:45:34 +05301275 struct device *mdp_dev;
1276 int ret;
1277
1278 /*
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001279 * MDP5/DPU based devices don't have a flat hierarchy. There is a top
1280 * level parent: MDSS, and children: MDP5/DPU, DSI, HDMI, eDP etc.
1281 * Populate the children devices, find the MDP5/DPU node, and then add
1282 * the interfaces to our components list.
Archit Taneja54011e22016-06-06 13:45:34 +05301283 */
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001284 if (of_device_is_compatible(dev->of_node, "qcom,mdss") ||
1285 of_device_is_compatible(dev->of_node, "qcom,sdm845-mdss")) {
Archit Taneja54011e22016-06-06 13:45:34 +05301286 ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
1287 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +05301288 DRM_DEV_ERROR(dev, "failed to populate children devices\n");
Archit Taneja54011e22016-06-06 13:45:34 +05301289 return ret;
1290 }
1291
1292 mdp_dev = device_find_child(dev, NULL, compare_name_mdp);
1293 if (!mdp_dev) {
Mamta Shukla6a41da12018-10-20 23:19:26 +05301294 DRM_DEV_ERROR(dev, "failed to find MDSS MDP node\n");
Archit Taneja54011e22016-06-06 13:45:34 +05301295 of_platform_depopulate(dev);
1296 return -ENODEV;
1297 }
1298
1299 put_device(mdp_dev);
1300
1301 /* add the MDP component itself */
Russell King97ac0e42016-10-19 11:28:27 +01001302 drm_of_component_match_add(dev, matchptr, compare_of,
1303 mdp_dev->of_node);
Archit Taneja54011e22016-06-06 13:45:34 +05301304 } else {
1305 /* MDP4 */
1306 mdp_dev = dev;
1307 }
1308
1309 ret = add_components_mdp(mdp_dev, matchptr);
1310 if (ret)
1311 of_platform_depopulate(dev);
1312
1313 return ret;
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301314}
1315
Archit Tanejadc3ea262016-05-19 13:33:52 +05301316/*
1317 * We don't know what's the best binding to link the gpu with the drm device.
1318 * Fow now, we just hunt for all the possible gpus that we support, and add them
1319 * as components.
1320 */
1321static const struct of_device_id msm_gpu_match[] = {
Rob Clark1db7afa2017-01-30 11:02:27 -05001322 { .compatible = "qcom,adreno" },
Archit Tanejadc3ea262016-05-19 13:33:52 +05301323 { .compatible = "qcom,adreno-3xx" },
1324 { .compatible = "qcom,kgsl-3d0" },
1325 { },
1326};
1327
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301328static int add_gpu_components(struct device *dev,
1329 struct component_match **matchptr)
1330{
Archit Tanejadc3ea262016-05-19 13:33:52 +05301331 struct device_node *np;
1332
1333 np = of_find_matching_node(NULL, msm_gpu_match);
1334 if (!np)
1335 return 0;
1336
Russell King97ac0e42016-10-19 11:28:27 +01001337 drm_of_component_match_add(dev, matchptr, compare_of, np);
Archit Tanejadc3ea262016-05-19 13:33:52 +05301338
1339 of_node_put(np);
1340
1341 return 0;
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301342}
1343
Russell King84448282014-04-19 11:20:42 +01001344static int msm_drm_bind(struct device *dev)
1345{
Archit Taneja2b669872016-05-02 11:05:54 +05301346 return msm_drm_init(dev, &msm_driver);
Russell King84448282014-04-19 11:20:42 +01001347}
1348
1349static void msm_drm_unbind(struct device *dev)
1350{
Archit Taneja2b669872016-05-02 11:05:54 +05301351 msm_drm_uninit(dev);
Russell King84448282014-04-19 11:20:42 +01001352}
1353
1354static const struct component_master_ops msm_drm_ops = {
1355 .bind = msm_drm_bind,
1356 .unbind = msm_drm_unbind,
1357};
1358
1359/*
1360 * Platform driver:
1361 */
1362
1363static int msm_pdev_probe(struct platform_device *pdev)
1364{
1365 struct component_match *match = NULL;
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301366 int ret;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +05301367
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301368 ret = add_display_components(&pdev->dev, &match);
1369 if (ret)
1370 return ret;
1371
1372 ret = add_gpu_components(&pdev->dev, &match);
1373 if (ret)
1374 return ret;
Rob Clark060530f2014-03-03 14:19:12 -05001375
Rob Clarkc83ea572016-11-07 13:31:30 -05001376 /* on all devices that I am aware of, iommu's which can map
1377 * any address the cpu can see are used:
1378 */
1379 ret = dma_set_mask_and_coherent(&pdev->dev, ~0);
1380 if (ret)
1381 return ret;
1382
Russell King84448282014-04-19 11:20:42 +01001383 return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
Rob Clarkc8afe682013-06-26 12:44:06 -04001384}
1385
1386static int msm_pdev_remove(struct platform_device *pdev)
1387{
Rob Clark060530f2014-03-03 14:19:12 -05001388 component_master_del(&pdev->dev, &msm_drm_ops);
Archit Taneja54011e22016-06-06 13:45:34 +05301389 of_platform_depopulate(&pdev->dev);
Rob Clarkc8afe682013-06-26 12:44:06 -04001390
1391 return 0;
1392}
1393
Rob Clark06c0dd92013-11-30 17:51:47 -05001394static const struct of_device_id dt_match[] = {
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -04001395 { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 },
1396 { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 },
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001397 { .compatible = "qcom,sdm845-mdss", .data = (void *)KMS_DPU },
Rob Clark06c0dd92013-11-30 17:51:47 -05001398 {}
1399};
1400MODULE_DEVICE_TABLE(of, dt_match);
1401
Rob Clarkc8afe682013-06-26 12:44:06 -04001402static struct platform_driver msm_platform_driver = {
1403 .probe = msm_pdev_probe,
1404 .remove = msm_pdev_remove,
1405 .driver = {
Rob Clarkc8afe682013-06-26 12:44:06 -04001406 .name = "msm",
Rob Clark06c0dd92013-11-30 17:51:47 -05001407 .of_match_table = dt_match,
Rob Clarkc8afe682013-06-26 12:44:06 -04001408 .pm = &msm_pm_ops,
1409 },
Rob Clarkc8afe682013-06-26 12:44:06 -04001410};
1411
1412static int __init msm_drm_register(void)
1413{
Rob Clarkba4dd712017-07-06 16:33:44 -04001414 if (!modeset)
1415 return -EINVAL;
1416
Rob Clarkc8afe682013-06-26 12:44:06 -04001417 DBG("init");
Archit Taneja1dd0a0b2016-05-30 16:36:50 +05301418 msm_mdp_register();
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001419 msm_dpu_register();
Hai Lid5af49c2015-03-26 19:25:17 -04001420 msm_dsi_register();
Hai Li00453982014-12-12 14:41:17 -05001421 msm_edp_register();
Arnd Bergmannfcda50c2016-02-22 22:08:35 +01001422 msm_hdmi_register();
Rob Clarkbfd28b12014-09-05 13:06:37 -04001423 adreno_register();
Rob Clarkc8afe682013-06-26 12:44:06 -04001424 return platform_driver_register(&msm_platform_driver);
1425}
1426
1427static void __exit msm_drm_unregister(void)
1428{
1429 DBG("fini");
1430 platform_driver_unregister(&msm_platform_driver);
Arnd Bergmannfcda50c2016-02-22 22:08:35 +01001431 msm_hdmi_unregister();
Rob Clarkbfd28b12014-09-05 13:06:37 -04001432 adreno_unregister();
Hai Li00453982014-12-12 14:41:17 -05001433 msm_edp_unregister();
Hai Lid5af49c2015-03-26 19:25:17 -04001434 msm_dsi_unregister();
Archit Taneja1dd0a0b2016-05-30 16:36:50 +05301435 msm_mdp_unregister();
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001436 msm_dpu_unregister();
Rob Clarkc8afe682013-06-26 12:44:06 -04001437}
1438
1439module_init(msm_drm_register);
1440module_exit(msm_drm_unregister);
1441
1442MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
1443MODULE_DESCRIPTION("MSM DRM Driver");
1444MODULE_LICENSE("GPL");