blob: c08f83c7ca5793c4126389b6aa15e96978d95f59 [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 Clarka8d854c2016-06-01 14:02:02 -040039 */
40#define MSM_VERSION_MAJOR 1
Jordan Crousef7de1542017-10-20 11:06:55 -060041#define MSM_VERSION_MINOR 3
Rob Clarka8d854c2016-06-01 14:02:02 -040042#define MSM_VERSION_PATCHLEVEL 0
43
Rob Clarkc8afe682013-06-26 12:44:06 -040044static const struct drm_mode_config_funcs mode_config_funcs = {
45 .fb_create = msm_framebuffer_create,
Noralf Trønnes4ccbc6e2017-12-05 19:24:59 +010046 .output_poll_changed = drm_fb_helper_output_poll_changed,
Rob Clark1f920172017-10-25 12:30:51 -040047 .atomic_check = drm_atomic_helper_check,
Sean Pauld14659f2018-02-28 14:19:05 -050048 .atomic_commit = drm_atomic_helper_commit,
49};
50
51static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = {
52 .atomic_commit_tail = msm_atomic_commit_tail,
Rob Clarkc8afe682013-06-26 12:44:06 -040053};
54
Rob Clarkc8afe682013-06-26 12:44:06 -040055#ifdef CONFIG_DRM_MSM_REGISTER_LOGGING
56static bool reglog = false;
57MODULE_PARM_DESC(reglog, "Enable register read/write logging");
58module_param(reglog, bool, 0600);
59#else
60#define reglog 0
61#endif
62
Archit Tanejaa9ee34b2015-07-13 12:12:07 +053063#ifdef CONFIG_DRM_FBDEV_EMULATION
Rob Clarke90dfec2015-01-30 17:05:41 -050064static bool fbdev = true;
65MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer");
66module_param(fbdev, bool, 0600);
67#endif
68
Rob Clark3a10ba82014-09-08 14:24:57 -040069static char *vram = "16m";
Rob Clark4313c7442016-02-03 14:02:04 -050070MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)");
Rob Clark871d8122013-11-16 12:56:06 -050071module_param(vram, charp, 0);
72
Rob Clark06d9f562016-11-05 11:08:12 -040073bool dumpstate = false;
74MODULE_PARM_DESC(dumpstate, "Dump KMS state on errors");
75module_param(dumpstate, bool, 0600);
76
Rob Clarkba4dd712017-07-06 16:33:44 -040077static bool modeset = true;
78MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disable)");
79module_param(modeset, bool, 0600);
80
Rob Clark060530f2014-03-03 14:19:12 -050081/*
82 * Util/helpers:
83 */
84
Jordan Crouse8e54eea2018-08-06 11:33:21 -060085int msm_clk_bulk_get(struct device *dev, struct clk_bulk_data **bulk)
86{
87 struct property *prop;
88 const char *name;
89 struct clk_bulk_data *local;
90 int i = 0, ret, count;
91
92 count = of_property_count_strings(dev->of_node, "clock-names");
93 if (count < 1)
94 return 0;
95
96 local = devm_kcalloc(dev, sizeof(struct clk_bulk_data *),
97 count, GFP_KERNEL);
98 if (!local)
99 return -ENOMEM;
100
101 of_property_for_each_string(dev->of_node, "clock-names", prop, name) {
102 local[i].id = devm_kstrdup(dev, name, GFP_KERNEL);
103 if (!local[i].id) {
104 devm_kfree(dev, local);
105 return -ENOMEM;
106 }
107
108 i++;
109 }
110
111 ret = devm_clk_bulk_get(dev, count, local);
112
113 if (ret) {
114 for (i = 0; i < count; i++)
115 devm_kfree(dev, (void *) local[i].id);
116 devm_kfree(dev, local);
117
118 return ret;
119 }
120
121 *bulk = local;
122 return count;
123}
124
125struct clk *msm_clk_bulk_get_clock(struct clk_bulk_data *bulk, int count,
126 const char *name)
127{
128 int i;
129 char n[32];
130
131 snprintf(n, sizeof(n), "%s_clk", name);
132
133 for (i = 0; bulk && i < count; i++) {
134 if (!strcmp(bulk[i].id, name) || !strcmp(bulk[i].id, n))
135 return bulk[i].clk;
136 }
137
138
139 return NULL;
140}
141
Rob Clark720c3bb2017-01-30 11:30:58 -0500142struct clk *msm_clk_get(struct platform_device *pdev, const char *name)
143{
144 struct clk *clk;
145 char name2[32];
146
147 clk = devm_clk_get(&pdev->dev, name);
148 if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
149 return clk;
150
151 snprintf(name2, sizeof(name2), "%s_clk", name);
152
153 clk = devm_clk_get(&pdev->dev, name2);
154 if (!IS_ERR(clk))
155 dev_warn(&pdev->dev, "Using legacy clk name binding. Use "
156 "\"%s\" instead of \"%s\"\n", name, name2);
157
158 return clk;
159}
160
Rob Clarkc8afe682013-06-26 12:44:06 -0400161void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
162 const char *dbgname)
163{
164 struct resource *res;
165 unsigned long size;
166 void __iomem *ptr;
167
168 if (name)
169 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
170 else
171 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
172
173 if (!res) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530174 DRM_DEV_ERROR(&pdev->dev, "failed to get memory resource: %s\n", name);
Rob Clarkc8afe682013-06-26 12:44:06 -0400175 return ERR_PTR(-EINVAL);
176 }
177
178 size = resource_size(res);
179
180 ptr = devm_ioremap_nocache(&pdev->dev, res->start, size);
181 if (!ptr) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530182 DRM_DEV_ERROR(&pdev->dev, "failed to ioremap: %s\n", name);
Rob Clarkc8afe682013-06-26 12:44:06 -0400183 return ERR_PTR(-ENOMEM);
184 }
185
186 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200187 printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size);
Rob Clarkc8afe682013-06-26 12:44:06 -0400188
189 return ptr;
190}
191
192void msm_writel(u32 data, void __iomem *addr)
193{
194 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200195 printk(KERN_DEBUG "IO:W %p %08x\n", addr, data);
Rob Clarkc8afe682013-06-26 12:44:06 -0400196 writel(data, addr);
197}
198
199u32 msm_readl(const void __iomem *addr)
200{
201 u32 val = readl(addr);
202 if (reglog)
Joe Perches8dfe1622017-02-28 04:55:54 -0800203 pr_err("IO:R %p %08x\n", addr, val);
Rob Clarkc8afe682013-06-26 12:44:06 -0400204 return val;
205}
206
Hai Li78b1d472015-07-27 13:49:45 -0400207struct vblank_event {
208 struct list_head node;
209 int crtc_id;
210 bool enable;
211};
212
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400213static void vblank_ctrl_worker(struct kthread_work *work)
Hai Li78b1d472015-07-27 13:49:45 -0400214{
215 struct msm_vblank_ctrl *vbl_ctrl = container_of(work,
216 struct msm_vblank_ctrl, work);
217 struct msm_drm_private *priv = container_of(vbl_ctrl,
218 struct msm_drm_private, vblank_ctrl);
219 struct msm_kms *kms = priv->kms;
220 struct vblank_event *vbl_ev, *tmp;
221 unsigned long flags;
222
223 spin_lock_irqsave(&vbl_ctrl->lock, flags);
224 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
225 list_del(&vbl_ev->node);
226 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
227
228 if (vbl_ev->enable)
229 kms->funcs->enable_vblank(kms,
230 priv->crtcs[vbl_ev->crtc_id]);
231 else
232 kms->funcs->disable_vblank(kms,
233 priv->crtcs[vbl_ev->crtc_id]);
234
235 kfree(vbl_ev);
236
237 spin_lock_irqsave(&vbl_ctrl->lock, flags);
238 }
239
240 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
241}
242
243static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
244 int crtc_id, bool enable)
245{
246 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
247 struct vblank_event *vbl_ev;
248 unsigned long flags;
249
250 vbl_ev = kzalloc(sizeof(*vbl_ev), GFP_ATOMIC);
251 if (!vbl_ev)
252 return -ENOMEM;
253
254 vbl_ev->crtc_id = crtc_id;
255 vbl_ev->enable = enable;
256
257 spin_lock_irqsave(&vbl_ctrl->lock, flags);
258 list_add_tail(&vbl_ev->node, &vbl_ctrl->event_list);
259 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
260
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400261 kthread_queue_work(&priv->disp_thread[crtc_id].worker,
262 &vbl_ctrl->work);
Hai Li78b1d472015-07-27 13:49:45 -0400263
264 return 0;
265}
266
Archit Taneja2b669872016-05-02 11:05:54 +0530267static int msm_drm_uninit(struct device *dev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400268{
Archit Taneja2b669872016-05-02 11:05:54 +0530269 struct platform_device *pdev = to_platform_device(dev);
270 struct drm_device *ddev = platform_get_drvdata(pdev);
271 struct msm_drm_private *priv = ddev->dev_private;
Rob Clarkc8afe682013-06-26 12:44:06 -0400272 struct msm_kms *kms = priv->kms;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400273 struct msm_mdss *mdss = priv->mdss;
Hai Li78b1d472015-07-27 13:49:45 -0400274 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
275 struct vblank_event *vbl_ev, *tmp;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400276 int i;
Hai Li78b1d472015-07-27 13:49:45 -0400277
278 /* We must cancel and cleanup any pending vblank enable/disable
279 * work before drm_irq_uninstall() to avoid work re-enabling an
280 * irq after uninstall has disabled it.
281 */
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400282 kthread_flush_work(&vbl_ctrl->work);
Hai Li78b1d472015-07-27 13:49:45 -0400283 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
284 list_del(&vbl_ev->node);
285 kfree(vbl_ev);
286 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400287
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400288 /* clean up display commit/event worker threads */
289 for (i = 0; i < priv->num_crtcs; i++) {
290 if (priv->disp_thread[i].thread) {
291 kthread_flush_worker(&priv->disp_thread[i].worker);
292 kthread_stop(priv->disp_thread[i].thread);
293 priv->disp_thread[i].thread = NULL;
294 }
295
296 if (priv->event_thread[i].thread) {
297 kthread_flush_worker(&priv->event_thread[i].worker);
298 kthread_stop(priv->event_thread[i].thread);
299 priv->event_thread[i].thread = NULL;
300 }
301 }
302
Rob Clark68209392016-05-17 16:19:32 -0400303 msm_gem_shrinker_cleanup(ddev);
304
Archit Taneja2b669872016-05-02 11:05:54 +0530305 drm_kms_helper_poll_fini(ddev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530306
Archit Taneja2b669872016-05-02 11:05:54 +0530307 drm_dev_unregister(ddev);
Archit Taneja8208ed92016-05-02 11:05:53 +0530308
Noralf Trønnes85eac472017-03-07 21:49:22 +0100309 msm_perf_debugfs_cleanup(priv);
310 msm_rd_debugfs_cleanup(priv);
311
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530312#ifdef CONFIG_DRM_FBDEV_EMULATION
313 if (fbdev && priv->fbdev)
Archit Taneja2b669872016-05-02 11:05:54 +0530314 msm_fbdev_free(ddev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530315#endif
Daniel Vetter3ea4b1e2018-10-04 22:24:36 +0200316 drm_atomic_helper_shutdown(ddev);
Archit Taneja2b669872016-05-02 11:05:54 +0530317 drm_mode_config_cleanup(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400318
Archit Taneja2b669872016-05-02 11:05:54 +0530319 pm_runtime_get_sync(dev);
320 drm_irq_uninstall(ddev);
321 pm_runtime_put_sync(dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400322
323 flush_workqueue(priv->wq);
324 destroy_workqueue(priv->wq);
325
Archit Taneja16976082016-11-03 17:36:18 +0530326 if (kms && kms->funcs)
Rob Clarkc8afe682013-06-26 12:44:06 -0400327 kms->funcs->destroy(kms);
Rob Clarkc8afe682013-06-26 12:44:06 -0400328
Rob Clark871d8122013-11-16 12:56:06 -0500329 if (priv->vram.paddr) {
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700330 unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
Rob Clark871d8122013-11-16 12:56:06 -0500331 drm_mm_takedown(&priv->vram.mm);
Archit Taneja2b669872016-05-02 11:05:54 +0530332 dma_free_attrs(dev, priv->vram.size, NULL,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700333 priv->vram.paddr, attrs);
Rob Clark871d8122013-11-16 12:56:06 -0500334 }
335
Archit Taneja2b669872016-05-02 11:05:54 +0530336 component_unbind_all(dev, ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500337
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400338 if (mdss && mdss->funcs)
339 mdss->funcs->destroy(ddev);
Archit Taneja0a6030d2016-05-08 21:36:28 +0530340
Archit Taneja2b669872016-05-02 11:05:54 +0530341 ddev->dev_private = NULL;
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200342 drm_dev_put(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400343
344 kfree(priv);
345
346 return 0;
347}
348
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400349#define KMS_MDP4 4
350#define KMS_MDP5 5
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400351#define KMS_DPU 3
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400352
Rob Clark06c0dd92013-11-30 17:51:47 -0500353static int get_mdp_ver(struct platform_device *pdev)
354{
Rob Clark06c0dd92013-11-30 17:51:47 -0500355 struct device *dev = &pdev->dev;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530356
357 return (int) (unsigned long) of_device_get_match_data(dev);
Rob Clark06c0dd92013-11-30 17:51:47 -0500358}
359
Rob Clark072f1f92015-03-03 15:04:25 -0500360#include <linux/of_address.h>
361
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500362static int msm_init_vram(struct drm_device *dev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400363{
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500364 struct msm_drm_private *priv = dev->dev_private;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530365 struct device_node *node;
Rob Clark072f1f92015-03-03 15:04:25 -0500366 unsigned long size = 0;
367 int ret = 0;
368
Rob Clark072f1f92015-03-03 15:04:25 -0500369 /* In the device-tree world, we could have a 'memory-region'
370 * phandle, which gives us a link to our "vram". Allocating
371 * is all nicely abstracted behind the dma api, but we need
372 * to know the entire size to allocate it all in one go. There
373 * are two cases:
374 * 1) device with no IOMMU, in which case we need exclusive
375 * access to a VRAM carveout big enough for all gpu
376 * buffers
377 * 2) device with IOMMU, but where the bootloader puts up
378 * a splash screen. In this case, the VRAM carveout
379 * need only be large enough for fbdev fb. But we need
380 * exclusive access to the buffer to avoid the kernel
381 * using those pages for other purposes (which appears
382 * as corruption on screen before we have a chance to
383 * load and do initial modeset)
384 */
Rob Clark072f1f92015-03-03 15:04:25 -0500385
386 node = of_parse_phandle(dev->dev->of_node, "memory-region", 0);
387 if (node) {
388 struct resource r;
389 ret = of_address_to_resource(node, 0, &r);
Peter Chen2ca41c172016-07-04 16:49:50 +0800390 of_node_put(node);
Rob Clark072f1f92015-03-03 15:04:25 -0500391 if (ret)
392 return ret;
393 size = r.end - r.start;
Thierry Redingfc99f972015-04-09 16:39:51 +0200394 DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
Rob Clarkc8afe682013-06-26 12:44:06 -0400395
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530396 /* if we have no IOMMU, then we need to use carveout allocator.
397 * Grab the entire CMA chunk carved out in early startup in
398 * mach-msm:
399 */
400 } else if (!iommu_present(&platform_bus_type)) {
Rob Clark072f1f92015-03-03 15:04:25 -0500401 DRM_INFO("using %s VRAM carveout\n", vram);
402 size = memparse(vram, NULL);
403 }
404
405 if (size) {
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700406 unsigned long attrs = 0;
Rob Clark871d8122013-11-16 12:56:06 -0500407 void *p;
408
Rob Clark871d8122013-11-16 12:56:06 -0500409 priv->vram.size = size;
410
411 drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);
Sushmita Susheelendra0e082702017-06-13 16:52:54 -0600412 spin_lock_init(&priv->vram.lock);
Rob Clark871d8122013-11-16 12:56:06 -0500413
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700414 attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
415 attrs |= DMA_ATTR_WRITE_COMBINE;
Rob Clark871d8122013-11-16 12:56:06 -0500416
417 /* note that for no-kernel-mapping, the vaddr returned
418 * is bogus, but non-null if allocation succeeded:
419 */
420 p = dma_alloc_attrs(dev->dev, size,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700421 &priv->vram.paddr, GFP_KERNEL, attrs);
Rob Clark871d8122013-11-16 12:56:06 -0500422 if (!p) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530423 DRM_DEV_ERROR(dev->dev, "failed to allocate VRAM\n");
Rob Clark871d8122013-11-16 12:56:06 -0500424 priv->vram.paddr = 0;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500425 return -ENOMEM;
Rob Clark871d8122013-11-16 12:56:06 -0500426 }
427
Mamta Shukla6a41da12018-10-20 23:19:26 +0530428 DRM_DEV_INFO(dev->dev, "VRAM: %08x->%08x\n",
Rob Clark871d8122013-11-16 12:56:06 -0500429 (uint32_t)priv->vram.paddr,
430 (uint32_t)(priv->vram.paddr + size));
431 }
432
Rob Clark072f1f92015-03-03 15:04:25 -0500433 return ret;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500434}
435
Archit Taneja2b669872016-05-02 11:05:54 +0530436static int msm_drm_init(struct device *dev, struct drm_driver *drv)
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500437{
Archit Taneja2b669872016-05-02 11:05:54 +0530438 struct platform_device *pdev = to_platform_device(dev);
439 struct drm_device *ddev;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500440 struct msm_drm_private *priv;
441 struct msm_kms *kms;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400442 struct msm_mdss *mdss;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400443 int ret, i;
444 struct sched_param param;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500445
Archit Taneja2b669872016-05-02 11:05:54 +0530446 ddev = drm_dev_alloc(drv, dev);
Tom Gundersen0f288602016-09-21 16:59:19 +0200447 if (IS_ERR(ddev)) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530448 DRM_DEV_ERROR(dev, "failed to allocate drm_device\n");
Tom Gundersen0f288602016-09-21 16:59:19 +0200449 return PTR_ERR(ddev);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500450 }
451
Archit Taneja2b669872016-05-02 11:05:54 +0530452 platform_set_drvdata(pdev, ddev);
Archit Taneja2b669872016-05-02 11:05:54 +0530453
454 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
455 if (!priv) {
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400456 ret = -ENOMEM;
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200457 goto err_put_drm_dev;
Archit Taneja2b669872016-05-02 11:05:54 +0530458 }
459
460 ddev->dev_private = priv;
Rob Clark68209392016-05-17 16:19:32 -0400461 priv->dev = ddev;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500462
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400463 switch (get_mdp_ver(pdev)) {
464 case KMS_MDP5:
465 ret = mdp5_mdss_init(ddev);
466 break;
467 case KMS_DPU:
468 ret = dpu_mdss_init(ddev);
469 break;
470 default:
471 ret = 0;
472 break;
473 }
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400474 if (ret)
475 goto err_free_priv;
Archit Taneja0a6030d2016-05-08 21:36:28 +0530476
Rajesh Yadavbc3220b2018-06-21 16:06:10 -0400477 mdss = priv->mdss;
478
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500479 priv->wq = alloc_ordered_workqueue("msm", 0);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500480
481 INIT_LIST_HEAD(&priv->inactive_list);
Hai Li78b1d472015-07-27 13:49:45 -0400482 INIT_LIST_HEAD(&priv->vblank_ctrl.event_list);
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400483 kthread_init_work(&priv->vblank_ctrl.work, vblank_ctrl_worker);
Hai Li78b1d472015-07-27 13:49:45 -0400484 spin_lock_init(&priv->vblank_ctrl.lock);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500485
Archit Taneja2b669872016-05-02 11:05:54 +0530486 drm_mode_config_init(ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500487
488 /* Bind all our sub-components: */
Archit Taneja2b669872016-05-02 11:05:54 +0530489 ret = component_bind_all(dev, ddev);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400490 if (ret)
491 goto err_destroy_mdss;
Rob Clark060530f2014-03-03 14:19:12 -0500492
Archit Taneja2b669872016-05-02 11:05:54 +0530493 ret = msm_init_vram(ddev);
Rob Clark13f15562015-05-07 15:20:13 -0400494 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400495 goto err_msm_uninit;
Rob Clark13f15562015-05-07 15:20:13 -0400496
Rob Clark68209392016-05-17 16:19:32 -0400497 msm_gem_shrinker_init(ddev);
498
Rob Clark06c0dd92013-11-30 17:51:47 -0500499 switch (get_mdp_ver(pdev)) {
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400500 case KMS_MDP4:
Archit Taneja2b669872016-05-02 11:05:54 +0530501 kms = mdp4_kms_init(ddev);
Archit Taneja0a6030d2016-05-08 21:36:28 +0530502 priv->kms = kms;
Rob Clark06c0dd92013-11-30 17:51:47 -0500503 break;
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -0400504 case KMS_MDP5:
Archit Taneja392ae6e2016-06-14 18:24:54 +0530505 kms = mdp5_kms_init(ddev);
Rob Clark06c0dd92013-11-30 17:51:47 -0500506 break;
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400507 case KMS_DPU:
508 kms = dpu_kms_init(ddev);
509 priv->kms = kms;
510 break;
Rob Clark06c0dd92013-11-30 17:51:47 -0500511 default:
512 kms = ERR_PTR(-ENODEV);
513 break;
514 }
515
Rob Clarkc8afe682013-06-26 12:44:06 -0400516 if (IS_ERR(kms)) {
517 /*
518 * NOTE: once we have GPU support, having no kms should not
519 * be considered fatal.. ideally we would still support gpu
520 * and (for example) use dmabuf/prime to share buffers with
521 * imx drm driver on iMX5
522 */
Mamta Shukla6a41da12018-10-20 23:19:26 +0530523 DRM_DEV_ERROR(dev, "failed to load kms\n");
Thomas Meyere4826a92013-09-16 23:19:54 +0200524 ret = PTR_ERR(kms);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400525 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400526 }
527
Jeykumar Sankaranbb676df2018-06-11 14:13:20 -0700528 /* Enable normalization of plane zpos */
529 ddev->mode_config.normalize_zpos = true;
530
Rob Clarkc8afe682013-06-26 12:44:06 -0400531 if (kms) {
Rob Clarkc8afe682013-06-26 12:44:06 -0400532 ret = kms->funcs->hw_init(kms);
533 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530534 DRM_DEV_ERROR(dev, "kms hw init failed: %d\n", ret);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400535 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400536 }
537 }
538
Archit Taneja2b669872016-05-02 11:05:54 +0530539 ddev->mode_config.funcs = &mode_config_funcs;
Sean Pauld14659f2018-02-28 14:19:05 -0500540 ddev->mode_config.helper_private = &mode_config_helper_funcs;
Rob Clarkc8afe682013-06-26 12:44:06 -0400541
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400542 /**
543 * this priority was found during empiric testing to have appropriate
544 * realtime scheduling to process display updates and interact with
545 * other real time and normal priority task
546 */
547 param.sched_priority = 16;
548 for (i = 0; i < priv->num_crtcs; i++) {
549
550 /* initialize display thread */
551 priv->disp_thread[i].crtc_id = priv->crtcs[i]->base.id;
552 kthread_init_worker(&priv->disp_thread[i].worker);
553 priv->disp_thread[i].dev = ddev;
554 priv->disp_thread[i].thread =
555 kthread_run(kthread_worker_fn,
556 &priv->disp_thread[i].worker,
557 "crtc_commit:%d", priv->disp_thread[i].crtc_id);
558 ret = sched_setscheduler(priv->disp_thread[i].thread,
559 SCHED_FIFO, &param);
560 if (ret)
561 pr_warn("display thread priority update failed: %d\n",
562 ret);
563
564 if (IS_ERR(priv->disp_thread[i].thread)) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530565 DRM_DEV_ERROR(dev, "failed to create crtc_commit kthread\n");
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400566 priv->disp_thread[i].thread = NULL;
567 }
568
569 /* initialize event thread */
570 priv->event_thread[i].crtc_id = priv->crtcs[i]->base.id;
571 kthread_init_worker(&priv->event_thread[i].worker);
572 priv->event_thread[i].dev = ddev;
573 priv->event_thread[i].thread =
574 kthread_run(kthread_worker_fn,
575 &priv->event_thread[i].worker,
576 "crtc_event:%d", priv->event_thread[i].crtc_id);
Mamta Shukla6a41da12018-10-20 23:19:26 +0530577
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -0400578 /**
579 * event thread should also run at same priority as disp_thread
580 * because it is handling frame_done events. A lower priority
581 * event thread and higher priority disp_thread can causes
582 * frame_pending counters beyond 2. This can lead to commit
583 * failure at crtc commit level.
584 */
585 ret = sched_setscheduler(priv->event_thread[i].thread,
586 SCHED_FIFO, &param);
587 if (ret)
588 pr_warn("display event thread priority update failed: %d\n",
589 ret);
590
591 if (IS_ERR(priv->event_thread[i].thread)) {
592 dev_err(dev, "failed to create crtc_event kthread\n");
593 priv->event_thread[i].thread = NULL;
594 }
595
596 if ((!priv->disp_thread[i].thread) ||
597 !priv->event_thread[i].thread) {
598 /* clean up previously created threads if any */
599 for ( ; i >= 0; i--) {
600 if (priv->disp_thread[i].thread) {
601 kthread_stop(
602 priv->disp_thread[i].thread);
603 priv->disp_thread[i].thread = NULL;
604 }
605
606 if (priv->event_thread[i].thread) {
607 kthread_stop(
608 priv->event_thread[i].thread);
609 priv->event_thread[i].thread = NULL;
610 }
611 }
612 goto err_msm_uninit;
613 }
614 }
615
Archit Taneja2b669872016-05-02 11:05:54 +0530616 ret = drm_vblank_init(ddev, priv->num_crtcs);
Rob Clarkc8afe682013-06-26 12:44:06 -0400617 if (ret < 0) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530618 DRM_DEV_ERROR(dev, "failed to initialize vblank\n");
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400619 goto err_msm_uninit;
Rob Clarkc8afe682013-06-26 12:44:06 -0400620 }
621
Archit Tanejaa2b3a552016-05-18 15:06:03 +0530622 if (kms) {
623 pm_runtime_get_sync(dev);
624 ret = drm_irq_install(ddev, kms->irq);
625 pm_runtime_put_sync(dev);
626 if (ret < 0) {
Mamta Shukla6a41da12018-10-20 23:19:26 +0530627 DRM_DEV_ERROR(dev, "failed to install IRQ handler\n");
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400628 goto err_msm_uninit;
Archit Tanejaa2b3a552016-05-18 15:06:03 +0530629 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400630 }
631
Archit Taneja2b669872016-05-02 11:05:54 +0530632 ret = drm_dev_register(ddev, 0);
Rob Clarka7d3c952014-05-30 14:47:38 -0400633 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400634 goto err_msm_uninit;
Rob Clarka7d3c952014-05-30 14:47:38 -0400635
Archit Taneja2b669872016-05-02 11:05:54 +0530636 drm_mode_config_reset(ddev);
637
638#ifdef CONFIG_DRM_FBDEV_EMULATION
639 if (fbdev)
640 priv->fbdev = msm_fbdev_init(ddev);
641#endif
642
643 ret = msm_debugfs_late_init(ddev);
644 if (ret)
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400645 goto err_msm_uninit;
Archit Taneja2b669872016-05-02 11:05:54 +0530646
647 drm_kms_helper_poll_init(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400648
649 return 0;
650
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400651err_msm_uninit:
Archit Taneja2b669872016-05-02 11:05:54 +0530652 msm_drm_uninit(dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400653 return ret;
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400654err_destroy_mdss:
655 if (mdss && mdss->funcs)
656 mdss->funcs->destroy(ddev);
657err_free_priv:
658 kfree(priv);
Thomas Zimmermann4d8dc2d2018-09-26 13:48:59 +0200659err_put_drm_dev:
660 drm_dev_put(ddev);
Jeykumar Sankaran77050c32018-06-27 14:35:28 -0400661 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -0400662}
663
Archit Taneja2b669872016-05-02 11:05:54 +0530664/*
665 * DRM operations:
666 */
667
Rob Clark7198e6b2013-07-19 12:59:32 -0400668static void load_gpu(struct drm_device *dev)
669{
Rob Clarka1ad3522014-07-11 11:59:22 -0400670 static DEFINE_MUTEX(init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400671 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400672
Rob Clarka1ad3522014-07-11 11:59:22 -0400673 mutex_lock(&init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400674
Rob Clarke2550b72014-09-05 13:30:27 -0400675 if (!priv->gpu)
676 priv->gpu = adreno_load_gpu(dev);
Rob Clarka1ad3522014-07-11 11:59:22 -0400677
Rob Clarka1ad3522014-07-11 11:59:22 -0400678 mutex_unlock(&init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400679}
680
Jordan Crousef97deca2017-10-20 11:06:57 -0600681static int context_init(struct drm_device *dev, struct drm_file *file)
Rob Clark7198e6b2013-07-19 12:59:32 -0400682{
683 struct msm_file_private *ctx;
684
Rob Clark7198e6b2013-07-19 12:59:32 -0400685 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
686 if (!ctx)
687 return -ENOMEM;
688
Jordan Crousef97deca2017-10-20 11:06:57 -0600689 msm_submitqueue_init(dev, ctx);
Jordan Crousef7de1542017-10-20 11:06:55 -0600690
Rob Clark7198e6b2013-07-19 12:59:32 -0400691 file->driver_priv = ctx;
692
693 return 0;
694}
695
Jordan Crousef7de1542017-10-20 11:06:55 -0600696static int msm_open(struct drm_device *dev, struct drm_file *file)
697{
698 /* For now, load gpu on open.. to avoid the requirement of having
699 * firmware in the initrd.
700 */
701 load_gpu(dev);
702
Jordan Crousef97deca2017-10-20 11:06:57 -0600703 return context_init(dev, file);
Jordan Crousef7de1542017-10-20 11:06:55 -0600704}
705
706static void context_close(struct msm_file_private *ctx)
707{
708 msm_submitqueue_close(ctx);
709 kfree(ctx);
710}
711
Daniel Vetter94df1452017-03-08 15:12:46 +0100712static void msm_postclose(struct drm_device *dev, struct drm_file *file)
Rob Clarkc8afe682013-06-26 12:44:06 -0400713{
714 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400715 struct msm_file_private *ctx = file->driver_priv;
Rob Clark7198e6b2013-07-19 12:59:32 -0400716
Rob Clark7198e6b2013-07-19 12:59:32 -0400717 mutex_lock(&dev->struct_mutex);
718 if (ctx == priv->lastctx)
719 priv->lastctx = NULL;
720 mutex_unlock(&dev->struct_mutex);
721
Jordan Crousef7de1542017-10-20 11:06:55 -0600722 context_close(ctx);
Rob Clarkc8afe682013-06-26 12:44:06 -0400723}
724
Daniel Vettere9f0d762013-12-11 11:34:42 +0100725static irqreturn_t msm_irq(int irq, void *arg)
Rob Clarkc8afe682013-06-26 12:44:06 -0400726{
727 struct drm_device *dev = arg;
728 struct msm_drm_private *priv = dev->dev_private;
729 struct msm_kms *kms = priv->kms;
730 BUG_ON(!kms);
731 return kms->funcs->irq(kms);
732}
733
734static void msm_irq_preinstall(struct drm_device *dev)
735{
736 struct msm_drm_private *priv = dev->dev_private;
737 struct msm_kms *kms = priv->kms;
738 BUG_ON(!kms);
739 kms->funcs->irq_preinstall(kms);
740}
741
742static int msm_irq_postinstall(struct drm_device *dev)
743{
744 struct msm_drm_private *priv = dev->dev_private;
745 struct msm_kms *kms = priv->kms;
746 BUG_ON(!kms);
747 return kms->funcs->irq_postinstall(kms);
748}
749
750static void msm_irq_uninstall(struct drm_device *dev)
751{
752 struct msm_drm_private *priv = dev->dev_private;
753 struct msm_kms *kms = priv->kms;
754 BUG_ON(!kms);
755 kms->funcs->irq_uninstall(kms);
756}
757
Thierry Reding88e72712015-09-24 18:35:31 +0200758static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
Rob Clarkc8afe682013-06-26 12:44:06 -0400759{
760 struct msm_drm_private *priv = dev->dev_private;
761 struct msm_kms *kms = priv->kms;
762 if (!kms)
763 return -ENXIO;
Thierry Reding88e72712015-09-24 18:35:31 +0200764 DBG("dev=%p, crtc=%u", dev, pipe);
765 return vblank_ctrl_queue_work(priv, pipe, true);
Rob Clarkc8afe682013-06-26 12:44:06 -0400766}
767
Thierry Reding88e72712015-09-24 18:35:31 +0200768static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
Rob Clarkc8afe682013-06-26 12:44:06 -0400769{
770 struct msm_drm_private *priv = dev->dev_private;
771 struct msm_kms *kms = priv->kms;
772 if (!kms)
773 return;
Thierry Reding88e72712015-09-24 18:35:31 +0200774 DBG("dev=%p, crtc=%u", dev, pipe);
775 vblank_ctrl_queue_work(priv, pipe, false);
Rob Clarkc8afe682013-06-26 12:44:06 -0400776}
777
778/*
Rob Clark7198e6b2013-07-19 12:59:32 -0400779 * DRM ioctls:
780 */
781
782static int msm_ioctl_get_param(struct drm_device *dev, void *data,
783 struct drm_file *file)
784{
785 struct msm_drm_private *priv = dev->dev_private;
786 struct drm_msm_param *args = data;
787 struct msm_gpu *gpu;
788
789 /* for now, we just have 3d pipe.. eventually this would need to
790 * be more clever to dispatch to appropriate gpu module:
791 */
792 if (args->pipe != MSM_PIPE_3D0)
793 return -EINVAL;
794
795 gpu = priv->gpu;
796
797 if (!gpu)
798 return -ENXIO;
799
800 return gpu->funcs->get_param(gpu, args->param, &args->value);
801}
802
803static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
804 struct drm_file *file)
805{
806 struct drm_msm_gem_new *args = data;
Rob Clark93ddb0d2014-03-03 09:42:33 -0500807
808 if (args->flags & ~MSM_BO_FLAGS) {
809 DRM_ERROR("invalid flags: %08x\n", args->flags);
810 return -EINVAL;
811 }
812
Rob Clark7198e6b2013-07-19 12:59:32 -0400813 return msm_gem_new_handle(dev, file, args->size,
Jordan Crouse0815d772018-11-07 15:35:52 -0700814 args->flags, &args->handle, NULL);
Rob Clark7198e6b2013-07-19 12:59:32 -0400815}
816
Rob Clark56c2da82015-05-11 11:50:03 -0400817static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
818{
819 return ktime_set(timeout.tv_sec, timeout.tv_nsec);
820}
Rob Clark7198e6b2013-07-19 12:59:32 -0400821
822static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
823 struct drm_file *file)
824{
825 struct drm_msm_gem_cpu_prep *args = data;
826 struct drm_gem_object *obj;
Rob Clark56c2da82015-05-11 11:50:03 -0400827 ktime_t timeout = to_ktime(args->timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400828 int ret;
829
Rob Clark93ddb0d2014-03-03 09:42:33 -0500830 if (args->op & ~MSM_PREP_FLAGS) {
831 DRM_ERROR("invalid op: %08x\n", args->op);
832 return -EINVAL;
833 }
834
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100835 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400836 if (!obj)
837 return -ENOENT;
838
Rob Clark56c2da82015-05-11 11:50:03 -0400839 ret = msm_gem_cpu_prep(obj, args->op, &timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400840
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100841 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400842
843 return ret;
844}
845
846static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
847 struct drm_file *file)
848{
849 struct drm_msm_gem_cpu_fini *args = data;
850 struct drm_gem_object *obj;
851 int ret;
852
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100853 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400854 if (!obj)
855 return -ENOENT;
856
857 ret = msm_gem_cpu_fini(obj);
858
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100859 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400860
861 return ret;
862}
863
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600864static int msm_ioctl_gem_info_iova(struct drm_device *dev,
865 struct drm_gem_object *obj, uint64_t *iova)
866{
867 struct msm_drm_private *priv = dev->dev_private;
868
869 if (!priv->gpu)
870 return -EINVAL;
871
Jordan Crouse9fe041f2018-11-07 15:35:50 -0700872 /*
873 * Don't pin the memory here - just get an address so that userspace can
874 * be productive
875 */
Rob Clark8bdcd942017-06-13 11:07:08 -0400876 return msm_gem_get_iova(obj, priv->gpu->aspace, iova);
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600877}
878
Rob Clark7198e6b2013-07-19 12:59:32 -0400879static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
880 struct drm_file *file)
881{
882 struct drm_msm_gem_info *args = data;
883 struct drm_gem_object *obj;
Rob Clarkf05c83e2018-11-29 10:27:22 -0500884 struct msm_gem_object *msm_obj;
885 int i, ret = 0;
Rob Clark7198e6b2013-07-19 12:59:32 -0400886
Rob Clark789d2e52018-11-29 09:54:42 -0500887 if (args->pad)
Rob Clark7198e6b2013-07-19 12:59:32 -0400888 return -EINVAL;
889
Rob Clark789d2e52018-11-29 09:54:42 -0500890 switch (args->info) {
891 case MSM_INFO_GET_OFFSET:
892 case MSM_INFO_GET_IOVA:
893 /* value returned as immediate, not pointer, so len==0: */
894 if (args->len)
895 return -EINVAL;
896 break;
Rob Clarkf05c83e2018-11-29 10:27:22 -0500897 case MSM_INFO_SET_NAME:
898 case MSM_INFO_GET_NAME:
899 break;
Rob Clark789d2e52018-11-29 09:54:42 -0500900 default:
901 return -EINVAL;
902 }
903
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100904 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400905 if (!obj)
906 return -ENOENT;
907
Rob Clarkf05c83e2018-11-29 10:27:22 -0500908 msm_obj = to_msm_bo(obj);
909
Rob Clark789d2e52018-11-29 09:54:42 -0500910 switch (args->info) {
911 case MSM_INFO_GET_OFFSET:
912 args->value = msm_gem_mmap_offset(obj);
913 break;
914 case MSM_INFO_GET_IOVA:
915 ret = msm_ioctl_gem_info_iova(dev, obj, &args->value);
916 break;
Rob Clarkf05c83e2018-11-29 10:27:22 -0500917 case MSM_INFO_SET_NAME:
918 /* length check should leave room for terminating null: */
919 if (args->len >= sizeof(msm_obj->name)) {
920 ret = -EINVAL;
921 break;
922 }
923 ret = copy_from_user(msm_obj->name,
924 u64_to_user_ptr(args->value), args->len);
925 msm_obj->name[args->len] = '\0';
926 for (i = 0; i < args->len; i++) {
927 if (!isprint(msm_obj->name[i])) {
928 msm_obj->name[i] = '\0';
929 break;
930 }
931 }
932 break;
933 case MSM_INFO_GET_NAME:
934 if (args->value && (args->len < strlen(msm_obj->name))) {
935 ret = -EINVAL;
936 break;
937 }
938 args->len = strlen(msm_obj->name);
939 if (args->value) {
940 ret = copy_to_user(u64_to_user_ptr(args->value),
941 msm_obj->name, args->len);
942 }
943 break;
Jordan Crouse49fd08b2017-05-08 14:35:01 -0600944 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400945
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100946 drm_gem_object_put_unlocked(obj);
Rob Clark7198e6b2013-07-19 12:59:32 -0400947
948 return ret;
949}
950
951static int msm_ioctl_wait_fence(struct drm_device *dev, void *data,
952 struct drm_file *file)
953{
Rob Clarkca762a82016-03-15 17:22:13 -0400954 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400955 struct drm_msm_wait_fence *args = data;
Rob Clark56c2da82015-05-11 11:50:03 -0400956 ktime_t timeout = to_ktime(args->timeout);
Jordan Crousef97deca2017-10-20 11:06:57 -0600957 struct msm_gpu_submitqueue *queue;
958 struct msm_gpu *gpu = priv->gpu;
959 int ret;
Rob Clark93ddb0d2014-03-03 09:42:33 -0500960
961 if (args->pad) {
962 DRM_ERROR("invalid pad: %08x\n", args->pad);
963 return -EINVAL;
964 }
965
Jordan Crousef97deca2017-10-20 11:06:57 -0600966 if (!gpu)
Rob Clarkca762a82016-03-15 17:22:13 -0400967 return 0;
968
Jordan Crousef97deca2017-10-20 11:06:57 -0600969 queue = msm_submitqueue_get(file->driver_priv, args->queueid);
970 if (!queue)
971 return -ENOENT;
972
973 ret = msm_wait_fence(gpu->rb[queue->prio]->fctx, args->fence, &timeout,
974 true);
975
976 msm_submitqueue_put(queue);
977 return ret;
Rob Clark7198e6b2013-07-19 12:59:32 -0400978}
979
Rob Clark4cd33c42016-05-17 15:44:49 -0400980static int msm_ioctl_gem_madvise(struct drm_device *dev, void *data,
981 struct drm_file *file)
982{
983 struct drm_msm_gem_madvise *args = data;
984 struct drm_gem_object *obj;
985 int ret;
986
987 switch (args->madv) {
988 case MSM_MADV_DONTNEED:
989 case MSM_MADV_WILLNEED:
990 break;
991 default:
992 return -EINVAL;
993 }
994
995 ret = mutex_lock_interruptible(&dev->struct_mutex);
996 if (ret)
997 return ret;
998
999 obj = drm_gem_object_lookup(file, args->handle);
1000 if (!obj) {
1001 ret = -ENOENT;
1002 goto unlock;
1003 }
1004
1005 ret = msm_gem_madvise(obj, args->madv);
1006 if (ret >= 0) {
1007 args->retained = ret;
1008 ret = 0;
1009 }
1010
Steve Kowalikdc9a9b32018-01-26 14:55:54 +11001011 drm_gem_object_put(obj);
Rob Clark4cd33c42016-05-17 15:44:49 -04001012
1013unlock:
1014 mutex_unlock(&dev->struct_mutex);
1015 return ret;
1016}
1017
Jordan Crousef7de1542017-10-20 11:06:55 -06001018
1019static int msm_ioctl_submitqueue_new(struct drm_device *dev, void *data,
1020 struct drm_file *file)
1021{
1022 struct drm_msm_submitqueue *args = data;
1023
1024 if (args->flags & ~MSM_SUBMITQUEUE_FLAGS)
1025 return -EINVAL;
1026
Jordan Crousef97deca2017-10-20 11:06:57 -06001027 return msm_submitqueue_create(dev, file->driver_priv, args->prio,
Jordan Crousef7de1542017-10-20 11:06:55 -06001028 args->flags, &args->id);
1029}
1030
1031
1032static int msm_ioctl_submitqueue_close(struct drm_device *dev, void *data,
1033 struct drm_file *file)
1034{
1035 u32 id = *(u32 *) data;
1036
1037 return msm_submitqueue_remove(file->driver_priv, id);
1038}
1039
Rob Clark7198e6b2013-07-19 12:59:32 -04001040static const struct drm_ioctl_desc msm_ioctls[] = {
Daniel Vetterf8c47142015-09-08 13:56:30 +02001041 DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_AUTH|DRM_RENDER_ALLOW),
1042 DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW),
1043 DRM_IOCTL_DEF_DRV(MSM_GEM_INFO, msm_ioctl_gem_info, DRM_AUTH|DRM_RENDER_ALLOW),
1044 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
1045 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
1046 DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_AUTH|DRM_RENDER_ALLOW),
1047 DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_AUTH|DRM_RENDER_ALLOW),
Rob Clark4cd33c42016-05-17 15:44:49 -04001048 DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW),
Jordan Crousef7de1542017-10-20 11:06:55 -06001049 DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_NEW, msm_ioctl_submitqueue_new, DRM_AUTH|DRM_RENDER_ALLOW),
1050 DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_CLOSE, msm_ioctl_submitqueue_close, DRM_AUTH|DRM_RENDER_ALLOW),
Rob Clark7198e6b2013-07-19 12:59:32 -04001051};
1052
Rob Clarkc8afe682013-06-26 12:44:06 -04001053static const struct vm_operations_struct vm_ops = {
1054 .fault = msm_gem_fault,
1055 .open = drm_gem_vm_open,
1056 .close = drm_gem_vm_close,
1057};
1058
1059static const struct file_operations fops = {
1060 .owner = THIS_MODULE,
1061 .open = drm_open,
1062 .release = drm_release,
1063 .unlocked_ioctl = drm_ioctl,
Rob Clarkc8afe682013-06-26 12:44:06 -04001064 .compat_ioctl = drm_compat_ioctl,
Rob Clarkc8afe682013-06-26 12:44:06 -04001065 .poll = drm_poll,
1066 .read = drm_read,
1067 .llseek = no_llseek,
1068 .mmap = msm_gem_mmap,
1069};
1070
1071static struct drm_driver msm_driver = {
Rob Clark05b84912013-09-28 11:28:35 -04001072 .driver_features = DRIVER_HAVE_IRQ |
1073 DRIVER_GEM |
1074 DRIVER_PRIME |
Rob Clarkb4b15c82013-09-28 12:01:25 -04001075 DRIVER_RENDER |
Rob Clarka5436e12015-06-04 10:12:22 -04001076 DRIVER_ATOMIC |
Rob Clark05b84912013-09-28 11:28:35 -04001077 DRIVER_MODESET,
Rob Clark7198e6b2013-07-19 12:59:32 -04001078 .open = msm_open,
Daniel Vetter94df1452017-03-08 15:12:46 +01001079 .postclose = msm_postclose,
Noralf Trønnes4ccbc6e2017-12-05 19:24:59 +01001080 .lastclose = drm_fb_helper_lastclose,
Rob Clarkc8afe682013-06-26 12:44:06 -04001081 .irq_handler = msm_irq,
1082 .irq_preinstall = msm_irq_preinstall,
1083 .irq_postinstall = msm_irq_postinstall,
1084 .irq_uninstall = msm_irq_uninstall,
Rob Clarkc8afe682013-06-26 12:44:06 -04001085 .enable_vblank = msm_enable_vblank,
1086 .disable_vblank = msm_disable_vblank,
1087 .gem_free_object = msm_gem_free_object,
1088 .gem_vm_ops = &vm_ops,
1089 .dumb_create = msm_gem_dumb_create,
1090 .dumb_map_offset = msm_gem_dumb_map_offset,
Rob Clark05b84912013-09-28 11:28:35 -04001091 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
1092 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
1093 .gem_prime_export = drm_gem_prime_export,
1094 .gem_prime_import = drm_gem_prime_import,
Eric Anholt43523eb2017-04-12 12:11:58 -07001095 .gem_prime_res_obj = msm_gem_prime_res_obj,
Rob Clark05b84912013-09-28 11:28:35 -04001096 .gem_prime_pin = msm_gem_prime_pin,
1097 .gem_prime_unpin = msm_gem_prime_unpin,
1098 .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
1099 .gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
1100 .gem_prime_vmap = msm_gem_prime_vmap,
1101 .gem_prime_vunmap = msm_gem_prime_vunmap,
Daniel Thompson77a147e2014-11-12 11:38:14 +00001102 .gem_prime_mmap = msm_gem_prime_mmap,
Rob Clarkc8afe682013-06-26 12:44:06 -04001103#ifdef CONFIG_DEBUG_FS
1104 .debugfs_init = msm_debugfs_init,
Rob Clarkc8afe682013-06-26 12:44:06 -04001105#endif
Rob Clark7198e6b2013-07-19 12:59:32 -04001106 .ioctls = msm_ioctls,
Jordan Crouse167b6062017-05-08 14:34:59 -06001107 .num_ioctls = ARRAY_SIZE(msm_ioctls),
Rob Clarkc8afe682013-06-26 12:44:06 -04001108 .fops = &fops,
1109 .name = "msm",
1110 .desc = "MSM Snapdragon DRM",
1111 .date = "20130625",
Rob Clarka8d854c2016-06-01 14:02:02 -04001112 .major = MSM_VERSION_MAJOR,
1113 .minor = MSM_VERSION_MINOR,
1114 .patchlevel = MSM_VERSION_PATCHLEVEL,
Rob Clarkc8afe682013-06-26 12:44:06 -04001115};
1116
1117#ifdef CONFIG_PM_SLEEP
1118static int msm_pm_suspend(struct device *dev)
1119{
1120 struct drm_device *ddev = dev_get_drvdata(dev);
Daniel Mackec446d02018-05-28 21:53:38 +02001121 struct msm_drm_private *priv = ddev->dev_private;
Jeykumar Sankaran036bfeb2018-06-27 15:24:17 -04001122
Bruce Wang3750e782018-10-05 17:04:01 -04001123 if (WARN_ON(priv->pm_state))
1124 drm_atomic_state_put(priv->pm_state);
Rob Clarkc8afe682013-06-26 12:44:06 -04001125
Daniel Mackec446d02018-05-28 21:53:38 +02001126 priv->pm_state = drm_atomic_helper_suspend(ddev);
1127 if (IS_ERR(priv->pm_state)) {
Bruce Wang3750e782018-10-05 17:04:01 -04001128 int ret = PTR_ERR(priv->pm_state);
1129 DRM_ERROR("Failed to suspend dpu, %d\n", ret);
1130 return ret;
Daniel Mackec446d02018-05-28 21:53:38 +02001131 }
1132
Rob Clarkc8afe682013-06-26 12:44:06 -04001133 return 0;
1134}
1135
1136static int msm_pm_resume(struct device *dev)
1137{
1138 struct drm_device *ddev = dev_get_drvdata(dev);
Daniel Mackec446d02018-05-28 21:53:38 +02001139 struct msm_drm_private *priv = ddev->dev_private;
Bruce Wang3750e782018-10-05 17:04:01 -04001140 int ret;
Jeykumar Sankaran036bfeb2018-06-27 15:24:17 -04001141
Bruce Wang3750e782018-10-05 17:04:01 -04001142 if (WARN_ON(!priv->pm_state))
1143 return -ENOENT;
Rob Clarkc8afe682013-06-26 12:44:06 -04001144
Bruce Wang3750e782018-10-05 17:04:01 -04001145 ret = drm_atomic_helper_resume(ddev, priv->pm_state);
1146 if (!ret)
1147 priv->pm_state = NULL;
Rob Clarkc8afe682013-06-26 12:44:06 -04001148
Bruce Wang3750e782018-10-05 17:04:01 -04001149 return ret;
Rob Clarkc8afe682013-06-26 12:44:06 -04001150}
1151#endif
1152
Archit Taneja774e39e2017-07-28 16:17:07 +05301153#ifdef CONFIG_PM
1154static int msm_runtime_suspend(struct device *dev)
1155{
1156 struct drm_device *ddev = dev_get_drvdata(dev);
1157 struct msm_drm_private *priv = ddev->dev_private;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001158 struct msm_mdss *mdss = priv->mdss;
Archit Taneja774e39e2017-07-28 16:17:07 +05301159
1160 DBG("");
1161
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001162 if (mdss && mdss->funcs)
1163 return mdss->funcs->disable(mdss);
Archit Taneja774e39e2017-07-28 16:17:07 +05301164
1165 return 0;
1166}
1167
1168static int msm_runtime_resume(struct device *dev)
1169{
1170 struct drm_device *ddev = dev_get_drvdata(dev);
1171 struct msm_drm_private *priv = ddev->dev_private;
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001172 struct msm_mdss *mdss = priv->mdss;
Archit Taneja774e39e2017-07-28 16:17:07 +05301173
1174 DBG("");
1175
Rajesh Yadavbc3220b2018-06-21 16:06:10 -04001176 if (mdss && mdss->funcs)
1177 return mdss->funcs->enable(mdss);
Archit Taneja774e39e2017-07-28 16:17:07 +05301178
1179 return 0;
1180}
1181#endif
1182
Rob Clarkc8afe682013-06-26 12:44:06 -04001183static const struct dev_pm_ops msm_pm_ops = {
1184 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
Archit Taneja774e39e2017-07-28 16:17:07 +05301185 SET_RUNTIME_PM_OPS(msm_runtime_suspend, msm_runtime_resume, NULL)
Rob Clarkc8afe682013-06-26 12:44:06 -04001186};
1187
1188/*
Rob Clark060530f2014-03-03 14:19:12 -05001189 * Componentized driver support:
1190 */
1191
Archit Tanejae9fbdaf2015-11-18 12:15:14 +05301192/*
1193 * NOTE: duplication of the same code as exynos or imx (or probably any other).
1194 * so probably some room for some helpers
Rob Clark060530f2014-03-03 14:19:12 -05001195 */
1196static int compare_of(struct device *dev, void *data)
1197{
1198 return dev->of_node == data;
1199}
Rob Clark41e69772013-12-15 16:23:05 -05001200
Archit Taneja812070e2016-05-19 10:38:39 +05301201/*
1202 * Identify what components need to be added by parsing what remote-endpoints
1203 * our MDP output ports are connected to. In the case of LVDS on MDP4, there
1204 * is no external component that we need to add since LVDS is within MDP4
1205 * itself.
1206 */
1207static int add_components_mdp(struct device *mdp_dev,
1208 struct component_match **matchptr)
1209{
1210 struct device_node *np = mdp_dev->of_node;
1211 struct device_node *ep_node;
Archit Taneja54011e22016-06-06 13:45:34 +05301212 struct device *master_dev;
1213
1214 /*
1215 * on MDP4 based platforms, the MDP platform device is the component
1216 * master that adds other display interface components to itself.
1217 *
1218 * on MDP5 based platforms, the MDSS platform device is the component
1219 * master that adds MDP5 and other display interface components to
1220 * itself.
1221 */
1222 if (of_device_is_compatible(np, "qcom,mdp4"))
1223 master_dev = mdp_dev;
1224 else
1225 master_dev = mdp_dev->parent;
Archit Taneja812070e2016-05-19 10:38:39 +05301226
1227 for_each_endpoint_of_node(np, ep_node) {
1228 struct device_node *intf;
1229 struct of_endpoint ep;
1230 int ret;
1231
1232 ret = of_graph_parse_endpoint(ep_node, &ep);
1233 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +05301234 DRM_DEV_ERROR(mdp_dev, "unable to parse port endpoint\n");
Archit Taneja812070e2016-05-19 10:38:39 +05301235 of_node_put(ep_node);
1236 return ret;
1237 }
1238
1239 /*
1240 * The LCDC/LVDS port on MDP4 is a speacial case where the
1241 * remote-endpoint isn't a component that we need to add
1242 */
1243 if (of_device_is_compatible(np, "qcom,mdp4") &&
Archit Tanejad8dd8052016-11-17 12:12:03 +05301244 ep.port == 0)
Archit Taneja812070e2016-05-19 10:38:39 +05301245 continue;
Archit Taneja812070e2016-05-19 10:38:39 +05301246
1247 /*
1248 * It's okay if some of the ports don't have a remote endpoint
1249 * specified. It just means that the port isn't connected to
1250 * any external interface.
1251 */
1252 intf = of_graph_get_remote_port_parent(ep_node);
Archit Tanejad8dd8052016-11-17 12:12:03 +05301253 if (!intf)
Archit Taneja812070e2016-05-19 10:38:39 +05301254 continue;
Archit Taneja812070e2016-05-19 10:38:39 +05301255
Russell King97ac0e42016-10-19 11:28:27 +01001256 drm_of_component_match_add(master_dev, matchptr, compare_of,
1257 intf);
Archit Taneja812070e2016-05-19 10:38:39 +05301258 of_node_put(intf);
Archit Taneja812070e2016-05-19 10:38:39 +05301259 }
1260
1261 return 0;
1262}
1263
Archit Taneja54011e22016-06-06 13:45:34 +05301264static int compare_name_mdp(struct device *dev, void *data)
1265{
1266 return (strstr(dev_name(dev), "mdp") != NULL);
1267}
1268
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301269static int add_display_components(struct device *dev,
1270 struct component_match **matchptr)
1271{
Archit Taneja54011e22016-06-06 13:45:34 +05301272 struct device *mdp_dev;
1273 int ret;
1274
1275 /*
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001276 * MDP5/DPU based devices don't have a flat hierarchy. There is a top
1277 * level parent: MDSS, and children: MDP5/DPU, DSI, HDMI, eDP etc.
1278 * Populate the children devices, find the MDP5/DPU node, and then add
1279 * the interfaces to our components list.
Archit Taneja54011e22016-06-06 13:45:34 +05301280 */
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001281 if (of_device_is_compatible(dev->of_node, "qcom,mdss") ||
1282 of_device_is_compatible(dev->of_node, "qcom,sdm845-mdss")) {
Archit Taneja54011e22016-06-06 13:45:34 +05301283 ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
1284 if (ret) {
Mamta Shukla6a41da12018-10-20 23:19:26 +05301285 DRM_DEV_ERROR(dev, "failed to populate children devices\n");
Archit Taneja54011e22016-06-06 13:45:34 +05301286 return ret;
1287 }
1288
1289 mdp_dev = device_find_child(dev, NULL, compare_name_mdp);
1290 if (!mdp_dev) {
Mamta Shukla6a41da12018-10-20 23:19:26 +05301291 DRM_DEV_ERROR(dev, "failed to find MDSS MDP node\n");
Archit Taneja54011e22016-06-06 13:45:34 +05301292 of_platform_depopulate(dev);
1293 return -ENODEV;
1294 }
1295
1296 put_device(mdp_dev);
1297
1298 /* add the MDP component itself */
Russell King97ac0e42016-10-19 11:28:27 +01001299 drm_of_component_match_add(dev, matchptr, compare_of,
1300 mdp_dev->of_node);
Archit Taneja54011e22016-06-06 13:45:34 +05301301 } else {
1302 /* MDP4 */
1303 mdp_dev = dev;
1304 }
1305
1306 ret = add_components_mdp(mdp_dev, matchptr);
1307 if (ret)
1308 of_platform_depopulate(dev);
1309
1310 return ret;
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301311}
1312
Archit Tanejadc3ea262016-05-19 13:33:52 +05301313/*
1314 * We don't know what's the best binding to link the gpu with the drm device.
1315 * Fow now, we just hunt for all the possible gpus that we support, and add them
1316 * as components.
1317 */
1318static const struct of_device_id msm_gpu_match[] = {
Rob Clark1db7afa2017-01-30 11:02:27 -05001319 { .compatible = "qcom,adreno" },
Archit Tanejadc3ea262016-05-19 13:33:52 +05301320 { .compatible = "qcom,adreno-3xx" },
1321 { .compatible = "qcom,kgsl-3d0" },
1322 { },
1323};
1324
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301325static int add_gpu_components(struct device *dev,
1326 struct component_match **matchptr)
1327{
Archit Tanejadc3ea262016-05-19 13:33:52 +05301328 struct device_node *np;
1329
1330 np = of_find_matching_node(NULL, msm_gpu_match);
1331 if (!np)
1332 return 0;
1333
Russell King97ac0e42016-10-19 11:28:27 +01001334 drm_of_component_match_add(dev, matchptr, compare_of, np);
Archit Tanejadc3ea262016-05-19 13:33:52 +05301335
1336 of_node_put(np);
1337
1338 return 0;
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301339}
1340
Russell King84448282014-04-19 11:20:42 +01001341static int msm_drm_bind(struct device *dev)
1342{
Archit Taneja2b669872016-05-02 11:05:54 +05301343 return msm_drm_init(dev, &msm_driver);
Russell King84448282014-04-19 11:20:42 +01001344}
1345
1346static void msm_drm_unbind(struct device *dev)
1347{
Archit Taneja2b669872016-05-02 11:05:54 +05301348 msm_drm_uninit(dev);
Russell King84448282014-04-19 11:20:42 +01001349}
1350
1351static const struct component_master_ops msm_drm_ops = {
1352 .bind = msm_drm_bind,
1353 .unbind = msm_drm_unbind,
1354};
1355
1356/*
1357 * Platform driver:
1358 */
1359
1360static int msm_pdev_probe(struct platform_device *pdev)
1361{
1362 struct component_match *match = NULL;
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301363 int ret;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +05301364
Archit Taneja7d526fcf2016-05-19 10:33:57 +05301365 ret = add_display_components(&pdev->dev, &match);
1366 if (ret)
1367 return ret;
1368
1369 ret = add_gpu_components(&pdev->dev, &match);
1370 if (ret)
1371 return ret;
Rob Clark060530f2014-03-03 14:19:12 -05001372
Rob Clarkc83ea572016-11-07 13:31:30 -05001373 /* on all devices that I am aware of, iommu's which can map
1374 * any address the cpu can see are used:
1375 */
1376 ret = dma_set_mask_and_coherent(&pdev->dev, ~0);
1377 if (ret)
1378 return ret;
1379
Russell King84448282014-04-19 11:20:42 +01001380 return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
Rob Clarkc8afe682013-06-26 12:44:06 -04001381}
1382
1383static int msm_pdev_remove(struct platform_device *pdev)
1384{
Rob Clark060530f2014-03-03 14:19:12 -05001385 component_master_del(&pdev->dev, &msm_drm_ops);
Archit Taneja54011e22016-06-06 13:45:34 +05301386 of_platform_depopulate(&pdev->dev);
Rob Clarkc8afe682013-06-26 12:44:06 -04001387
1388 return 0;
1389}
1390
Rob Clark06c0dd92013-11-30 17:51:47 -05001391static const struct of_device_id dt_match[] = {
Jeykumar Sankaranaaded2e2018-06-27 14:26:24 -04001392 { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 },
1393 { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 },
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001394 { .compatible = "qcom,sdm845-mdss", .data = (void *)KMS_DPU },
Rob Clark06c0dd92013-11-30 17:51:47 -05001395 {}
1396};
1397MODULE_DEVICE_TABLE(of, dt_match);
1398
Rob Clarkc8afe682013-06-26 12:44:06 -04001399static struct platform_driver msm_platform_driver = {
1400 .probe = msm_pdev_probe,
1401 .remove = msm_pdev_remove,
1402 .driver = {
Rob Clarkc8afe682013-06-26 12:44:06 -04001403 .name = "msm",
Rob Clark06c0dd92013-11-30 17:51:47 -05001404 .of_match_table = dt_match,
Rob Clarkc8afe682013-06-26 12:44:06 -04001405 .pm = &msm_pm_ops,
1406 },
Rob Clarkc8afe682013-06-26 12:44:06 -04001407};
1408
1409static int __init msm_drm_register(void)
1410{
Rob Clarkba4dd712017-07-06 16:33:44 -04001411 if (!modeset)
1412 return -EINVAL;
1413
Rob Clarkc8afe682013-06-26 12:44:06 -04001414 DBG("init");
Archit Taneja1dd0a0b2016-05-30 16:36:50 +05301415 msm_mdp_register();
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001416 msm_dpu_register();
Hai Lid5af49c2015-03-26 19:25:17 -04001417 msm_dsi_register();
Hai Li00453982014-12-12 14:41:17 -05001418 msm_edp_register();
Arnd Bergmannfcda50c2016-02-22 22:08:35 +01001419 msm_hdmi_register();
Rob Clarkbfd28b12014-09-05 13:06:37 -04001420 adreno_register();
Rob Clarkc8afe682013-06-26 12:44:06 -04001421 return platform_driver_register(&msm_platform_driver);
1422}
1423
1424static void __exit msm_drm_unregister(void)
1425{
1426 DBG("fini");
1427 platform_driver_unregister(&msm_platform_driver);
Arnd Bergmannfcda50c2016-02-22 22:08:35 +01001428 msm_hdmi_unregister();
Rob Clarkbfd28b12014-09-05 13:06:37 -04001429 adreno_unregister();
Hai Li00453982014-12-12 14:41:17 -05001430 msm_edp_unregister();
Hai Lid5af49c2015-03-26 19:25:17 -04001431 msm_dsi_unregister();
Archit Taneja1dd0a0b2016-05-30 16:36:50 +05301432 msm_mdp_unregister();
Jeykumar Sankaran25fdd592018-06-27 15:26:09 -04001433 msm_dpu_unregister();
Rob Clarkc8afe682013-06-26 12:44:06 -04001434}
1435
1436module_init(msm_drm_register);
1437module_exit(msm_drm_unregister);
1438
1439MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
1440MODULE_DESCRIPTION("MSM DRM Driver");
1441MODULE_LICENSE("GPL");