blob: 8de17f9e5fe13524408e68ca1523d32810682680 [file] [log] [blame]
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001/*
2 * Copyright (C) 2012 Avionic Design GmbH
Terje Bergstromd43f81c2013-03-22 16:34:09 +02003 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
Thierry Reding776dc382013-10-14 14:43:22 +020010#include <linux/host1x.h>
Thierry Redingdf06b752014-06-26 21:41:53 +020011#include <linux/iommu.h>
Thierry Reding776dc382013-10-14 14:43:22 +020012
Thierry Reding1503ca42014-11-24 17:41:23 +010013#include <drm/drm_atomic.h>
Thierry Reding07866962014-11-24 17:08:06 +010014#include <drm/drm_atomic_helper.h>
15
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000016#include "drm.h"
Arto Merilainende2ba662013-03-22 16:34:08 +020017#include "gem.h"
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000018
19#define DRIVER_NAME "tegra"
20#define DRIVER_DESC "NVIDIA Tegra graphics"
21#define DRIVER_DATE "20120330"
22#define DRIVER_MAJOR 0
23#define DRIVER_MINOR 0
24#define DRIVER_PATCHLEVEL 0
25
Thierry Reding08943e62013-09-26 16:08:18 +020026struct tegra_drm_file {
27 struct list_head contexts;
28};
29
Thierry Reding1503ca42014-11-24 17:41:23 +010030static void tegra_atomic_schedule(struct tegra_drm *tegra,
31 struct drm_atomic_state *state)
32{
33 tegra->commit.state = state;
34 schedule_work(&tegra->commit.work);
35}
36
37static void tegra_atomic_complete(struct tegra_drm *tegra,
38 struct drm_atomic_state *state)
39{
40 struct drm_device *drm = tegra->drm;
41
42 /*
43 * Everything below can be run asynchronously without the need to grab
44 * any modeset locks at all under one condition: It must be guaranteed
45 * that the asynchronous work has either been cancelled (if the driver
46 * supports it, which at least requires that the framebuffers get
47 * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
48 * before the new state gets committed on the software side with
49 * drm_atomic_helper_swap_state().
50 *
51 * This scheme allows new atomic state updates to be prepared and
52 * checked in parallel to the asynchronous completion of the previous
53 * update. Which is important since compositors need to figure out the
54 * composition of the next frame right after having submitted the
55 * current layout.
56 */
57
58 drm_atomic_helper_commit_pre_planes(drm, state);
59 drm_atomic_helper_commit_planes(drm, state);
60 drm_atomic_helper_commit_post_planes(drm, state);
61
62 drm_atomic_helper_wait_for_vblanks(drm, state);
63
64 drm_atomic_helper_cleanup_planes(drm, state);
65 drm_atomic_state_free(state);
66}
67
68static void tegra_atomic_work(struct work_struct *work)
69{
70 struct tegra_drm *tegra = container_of(work, struct tegra_drm,
71 commit.work);
72
73 tegra_atomic_complete(tegra, tegra->commit.state);
74}
75
76static int tegra_atomic_commit(struct drm_device *drm,
77 struct drm_atomic_state *state, bool async)
78{
79 struct tegra_drm *tegra = drm->dev_private;
80 int err;
81
82 err = drm_atomic_helper_prepare_planes(drm, state);
83 if (err)
84 return err;
85
86 /* serialize outstanding asynchronous commits */
87 mutex_lock(&tegra->commit.lock);
88 flush_work(&tegra->commit.work);
89
90 /*
91 * This is the point of no return - everything below never fails except
92 * when the hw goes bonghits. Which means we can commit the new state on
93 * the software side now.
94 */
95
96 drm_atomic_helper_swap_state(drm, state);
97
98 if (async)
99 tegra_atomic_schedule(tegra, state);
100 else
101 tegra_atomic_complete(tegra, state);
102
103 mutex_unlock(&tegra->commit.lock);
104 return 0;
105}
106
Thierry Redingf9914212014-11-26 13:03:57 +0100107static const struct drm_mode_config_funcs tegra_drm_mode_funcs = {
108 .fb_create = tegra_fb_create,
109#ifdef CONFIG_DRM_TEGRA_FBDEV
110 .output_poll_changed = tegra_fb_output_poll_changed,
111#endif
Thierry Reding07866962014-11-24 17:08:06 +0100112 .atomic_check = drm_atomic_helper_check,
Thierry Reding1503ca42014-11-24 17:41:23 +0100113 .atomic_commit = tegra_atomic_commit,
Thierry Redingf9914212014-11-26 13:03:57 +0100114};
115
Thierry Reding776dc382013-10-14 14:43:22 +0200116static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000117{
Thierry Reding776dc382013-10-14 14:43:22 +0200118 struct host1x_device *device = to_host1x_device(drm->dev);
Thierry Reding386a2a72013-09-24 13:22:17 +0200119 struct tegra_drm *tegra;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000120 int err;
121
Thierry Reding776dc382013-10-14 14:43:22 +0200122 tegra = kzalloc(sizeof(*tegra), GFP_KERNEL);
Thierry Reding386a2a72013-09-24 13:22:17 +0200123 if (!tegra)
Terje Bergstrom692e6d72013-03-22 16:34:07 +0200124 return -ENOMEM;
125
Thierry Redingdf06b752014-06-26 21:41:53 +0200126 if (iommu_present(&platform_bus_type)) {
127 tegra->domain = iommu_domain_alloc(&platform_bus_type);
Dan Carpenterbf19b882014-12-04 14:00:35 +0300128 if (!tegra->domain) {
129 err = -ENOMEM;
Thierry Redingdf06b752014-06-26 21:41:53 +0200130 goto free;
131 }
132
133 DRM_DEBUG("IOMMU context initialized\n");
134 drm_mm_init(&tegra->mm, 0, SZ_2G);
135 }
136
Thierry Reding386a2a72013-09-24 13:22:17 +0200137 mutex_init(&tegra->clients_lock);
138 INIT_LIST_HEAD(&tegra->clients);
Thierry Reding1503ca42014-11-24 17:41:23 +0100139
140 mutex_init(&tegra->commit.lock);
141 INIT_WORK(&tegra->commit.work, tegra_atomic_work);
142
Thierry Reding386a2a72013-09-24 13:22:17 +0200143 drm->dev_private = tegra;
144 tegra->drm = drm;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000145
146 drm_mode_config_init(drm);
147
Thierry Redingf9914212014-11-26 13:03:57 +0100148 drm->mode_config.min_width = 0;
149 drm->mode_config.min_height = 0;
150
151 drm->mode_config.max_width = 4096;
152 drm->mode_config.max_height = 4096;
153
154 drm->mode_config.funcs = &tegra_drm_mode_funcs;
155
Thierry Redinge2215322014-06-27 17:19:25 +0200156 err = tegra_drm_fb_prepare(drm);
157 if (err < 0)
Thierry Reding1d1e6fe2014-11-06 14:12:08 +0100158 goto config;
Thierry Redinge2215322014-06-27 17:19:25 +0200159
160 drm_kms_helper_poll_init(drm);
161
Thierry Reding776dc382013-10-14 14:43:22 +0200162 err = host1x_device_init(device);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000163 if (err < 0)
Thierry Reding1d1e6fe2014-11-06 14:12:08 +0100164 goto fbdev;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000165
Thierry Reding9d441892014-11-24 17:02:53 +0100166 drm_mode_config_reset(drm);
167
Thierry Reding603f0cc2013-04-22 21:22:14 +0200168 /*
169 * We don't use the drm_irq_install() helpers provided by the DRM
170 * core, so we need to set this manually in order to allow the
171 * DRM_IOCTL_WAIT_VBLANK to operate correctly.
172 */
Ville Syrjälä44238432013-10-04 14:53:37 +0300173 drm->irq_enabled = true;
Thierry Reding603f0cc2013-04-22 21:22:14 +0200174
Thierry Reding42e9ce02015-01-28 14:43:05 +0100175 /* syncpoints are used for full 32-bit hardware VBLANK counters */
176 drm->vblank_disable_immediate = true;
177 drm->max_vblank_count = 0xffffffff;
178
Thierry Reding6e5ff992012-11-28 11:45:47 +0100179 err = drm_vblank_init(drm, drm->mode_config.num_crtc);
180 if (err < 0)
Thierry Reding1d1e6fe2014-11-06 14:12:08 +0100181 goto device;
Thierry Reding6e5ff992012-11-28 11:45:47 +0100182
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000183 err = tegra_drm_fb_init(drm);
184 if (err < 0)
Thierry Reding1d1e6fe2014-11-06 14:12:08 +0100185 goto vblank;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000186
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000187 return 0;
Thierry Reding1d1e6fe2014-11-06 14:12:08 +0100188
189vblank:
190 drm_vblank_cleanup(drm);
191device:
192 host1x_device_exit(device);
193fbdev:
194 drm_kms_helper_poll_fini(drm);
195 tegra_drm_fb_free(drm);
196config:
197 drm_mode_config_cleanup(drm);
Thierry Redingdf06b752014-06-26 21:41:53 +0200198
199 if (tegra->domain) {
200 iommu_domain_free(tegra->domain);
201 drm_mm_takedown(&tegra->mm);
202 }
203free:
Thierry Reding1d1e6fe2014-11-06 14:12:08 +0100204 kfree(tegra);
205 return err;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000206}
207
208static int tegra_drm_unload(struct drm_device *drm)
209{
Thierry Reding776dc382013-10-14 14:43:22 +0200210 struct host1x_device *device = to_host1x_device(drm->dev);
Thierry Redingdf06b752014-06-26 21:41:53 +0200211 struct tegra_drm *tegra = drm->dev_private;
Thierry Reding776dc382013-10-14 14:43:22 +0200212 int err;
213
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000214 drm_kms_helper_poll_fini(drm);
215 tegra_drm_fb_exit(drm);
Thierry Redingf002abc2013-10-14 14:06:02 +0200216 drm_mode_config_cleanup(drm);
Thierry Reding4aa3df72014-11-24 16:27:13 +0100217 drm_vblank_cleanup(drm);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000218
Thierry Reding776dc382013-10-14 14:43:22 +0200219 err = host1x_device_exit(device);
220 if (err < 0)
221 return err;
222
Thierry Redingdf06b752014-06-26 21:41:53 +0200223 if (tegra->domain) {
224 iommu_domain_free(tegra->domain);
225 drm_mm_takedown(&tegra->mm);
226 }
227
Thierry Reding1053f4dd2014-11-04 16:17:55 +0100228 kfree(tegra);
229
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000230 return 0;
231}
232
233static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
234{
Thierry Reding08943e62013-09-26 16:08:18 +0200235 struct tegra_drm_file *fpriv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200236
237 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
238 if (!fpriv)
239 return -ENOMEM;
240
241 INIT_LIST_HEAD(&fpriv->contexts);
242 filp->driver_priv = fpriv;
243
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000244 return 0;
245}
246
Thierry Redingc88c3632013-09-26 16:08:22 +0200247static void tegra_drm_context_free(struct tegra_drm_context *context)
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200248{
249 context->client->ops->close_channel(context);
250 kfree(context);
251}
252
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000253static void tegra_drm_lastclose(struct drm_device *drm)
254{
Paul Bolle6e601632014-02-09 14:01:33 +0100255#ifdef CONFIG_DRM_TEGRA_FBDEV
Thierry Reding386a2a72013-09-24 13:22:17 +0200256 struct tegra_drm *tegra = drm->dev_private;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000257
Thierry Reding386a2a72013-09-24 13:22:17 +0200258 tegra_fbdev_restore_mode(tegra->fbdev);
Thierry Reding60c2f702013-10-31 13:28:50 +0100259#endif
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000260}
261
Thierry Redingc40f0f12013-10-10 11:00:33 +0200262static struct host1x_bo *
263host1x_bo_lookup(struct drm_device *drm, struct drm_file *file, u32 handle)
264{
265 struct drm_gem_object *gem;
266 struct tegra_bo *bo;
267
268 gem = drm_gem_object_lookup(drm, file, handle);
269 if (!gem)
270 return NULL;
271
272 mutex_lock(&drm->struct_mutex);
273 drm_gem_object_unreference(gem);
274 mutex_unlock(&drm->struct_mutex);
275
276 bo = to_tegra_bo(gem);
277 return &bo->base;
278}
279
Thierry Reding961e3be2014-06-10 10:25:00 +0200280static int host1x_reloc_copy_from_user(struct host1x_reloc *dest,
281 struct drm_tegra_reloc __user *src,
282 struct drm_device *drm,
283 struct drm_file *file)
284{
285 u32 cmdbuf, target;
286 int err;
287
288 err = get_user(cmdbuf, &src->cmdbuf.handle);
289 if (err < 0)
290 return err;
291
292 err = get_user(dest->cmdbuf.offset, &src->cmdbuf.offset);
293 if (err < 0)
294 return err;
295
296 err = get_user(target, &src->target.handle);
297 if (err < 0)
298 return err;
299
David Ung31f40f82015-01-20 18:37:35 -0800300 err = get_user(dest->target.offset, &src->target.offset);
Thierry Reding961e3be2014-06-10 10:25:00 +0200301 if (err < 0)
302 return err;
303
304 err = get_user(dest->shift, &src->shift);
305 if (err < 0)
306 return err;
307
308 dest->cmdbuf.bo = host1x_bo_lookup(drm, file, cmdbuf);
309 if (!dest->cmdbuf.bo)
310 return -ENOENT;
311
312 dest->target.bo = host1x_bo_lookup(drm, file, target);
313 if (!dest->target.bo)
314 return -ENOENT;
315
316 return 0;
317}
318
Thierry Redingc40f0f12013-10-10 11:00:33 +0200319int tegra_drm_submit(struct tegra_drm_context *context,
320 struct drm_tegra_submit *args, struct drm_device *drm,
321 struct drm_file *file)
322{
323 unsigned int num_cmdbufs = args->num_cmdbufs;
324 unsigned int num_relocs = args->num_relocs;
325 unsigned int num_waitchks = args->num_waitchks;
326 struct drm_tegra_cmdbuf __user *cmdbufs =
Thierry Redinga7ed68f2013-11-08 13:15:43 +0100327 (void __user *)(uintptr_t)args->cmdbufs;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200328 struct drm_tegra_reloc __user *relocs =
Thierry Redinga7ed68f2013-11-08 13:15:43 +0100329 (void __user *)(uintptr_t)args->relocs;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200330 struct drm_tegra_waitchk __user *waitchks =
Thierry Redinga7ed68f2013-11-08 13:15:43 +0100331 (void __user *)(uintptr_t)args->waitchks;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200332 struct drm_tegra_syncpt syncpt;
333 struct host1x_job *job;
334 int err;
335
336 /* We don't yet support other than one syncpt_incr struct per submit */
337 if (args->num_syncpts != 1)
338 return -EINVAL;
339
340 job = host1x_job_alloc(context->channel, args->num_cmdbufs,
341 args->num_relocs, args->num_waitchks);
342 if (!job)
343 return -ENOMEM;
344
345 job->num_relocs = args->num_relocs;
346 job->num_waitchk = args->num_waitchks;
347 job->client = (u32)args->context;
348 job->class = context->client->base.class;
349 job->serialize = true;
350
351 while (num_cmdbufs) {
352 struct drm_tegra_cmdbuf cmdbuf;
353 struct host1x_bo *bo;
354
Dan Carpenter9a991602013-11-08 13:07:37 +0300355 if (copy_from_user(&cmdbuf, cmdbufs, sizeof(cmdbuf))) {
356 err = -EFAULT;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200357 goto fail;
Dan Carpenter9a991602013-11-08 13:07:37 +0300358 }
Thierry Redingc40f0f12013-10-10 11:00:33 +0200359
360 bo = host1x_bo_lookup(drm, file, cmdbuf.handle);
361 if (!bo) {
362 err = -ENOENT;
363 goto fail;
364 }
365
366 host1x_job_add_gather(job, bo, cmdbuf.words, cmdbuf.offset);
367 num_cmdbufs--;
368 cmdbufs++;
369 }
370
Thierry Reding961e3be2014-06-10 10:25:00 +0200371 /* copy and resolve relocations from submit */
Thierry Redingc40f0f12013-10-10 11:00:33 +0200372 while (num_relocs--) {
Thierry Reding961e3be2014-06-10 10:25:00 +0200373 err = host1x_reloc_copy_from_user(&job->relocarray[num_relocs],
374 &relocs[num_relocs], drm,
375 file);
376 if (err < 0)
Thierry Redingc40f0f12013-10-10 11:00:33 +0200377 goto fail;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200378 }
379
Dan Carpenter9a991602013-11-08 13:07:37 +0300380 if (copy_from_user(job->waitchk, waitchks,
381 sizeof(*waitchks) * num_waitchks)) {
382 err = -EFAULT;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200383 goto fail;
Dan Carpenter9a991602013-11-08 13:07:37 +0300384 }
Thierry Redingc40f0f12013-10-10 11:00:33 +0200385
Dan Carpenter9a991602013-11-08 13:07:37 +0300386 if (copy_from_user(&syncpt, (void __user *)(uintptr_t)args->syncpts,
387 sizeof(syncpt))) {
388 err = -EFAULT;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200389 goto fail;
Dan Carpenter9a991602013-11-08 13:07:37 +0300390 }
Thierry Redingc40f0f12013-10-10 11:00:33 +0200391
392 job->is_addr_reg = context->client->ops->is_addr_reg;
393 job->syncpt_incrs = syncpt.incrs;
394 job->syncpt_id = syncpt.id;
395 job->timeout = 10000;
396
397 if (args->timeout && args->timeout < 10000)
398 job->timeout = args->timeout;
399
400 err = host1x_job_pin(job, context->client->base.dev);
401 if (err)
402 goto fail;
403
404 err = host1x_job_submit(job);
405 if (err)
406 goto fail_submit;
407
408 args->fence = job->syncpt_end;
409
410 host1x_job_put(job);
411 return 0;
412
413fail_submit:
414 host1x_job_unpin(job);
415fail:
416 host1x_job_put(job);
417 return err;
418}
419
420
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200421#ifdef CONFIG_DRM_TEGRA_STAGING
Thierry Redingc88c3632013-09-26 16:08:22 +0200422static struct tegra_drm_context *tegra_drm_get_context(__u64 context)
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200423{
Thierry Redingc88c3632013-09-26 16:08:22 +0200424 return (struct tegra_drm_context *)(uintptr_t)context;
425}
426
427static bool tegra_drm_file_owns_context(struct tegra_drm_file *file,
428 struct tegra_drm_context *context)
429{
430 struct tegra_drm_context *ctx;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200431
432 list_for_each_entry(ctx, &file->contexts, list)
433 if (ctx == context)
434 return true;
435
436 return false;
437}
438
439static int tegra_gem_create(struct drm_device *drm, void *data,
440 struct drm_file *file)
441{
442 struct drm_tegra_gem_create *args = data;
443 struct tegra_bo *bo;
444
Thierry Reding773af772013-10-04 22:34:01 +0200445 bo = tegra_bo_create_with_handle(file, drm, args->size, args->flags,
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200446 &args->handle);
447 if (IS_ERR(bo))
448 return PTR_ERR(bo);
449
450 return 0;
451}
452
453static int tegra_gem_mmap(struct drm_device *drm, void *data,
454 struct drm_file *file)
455{
456 struct drm_tegra_gem_mmap *args = data;
457 struct drm_gem_object *gem;
458 struct tegra_bo *bo;
459
460 gem = drm_gem_object_lookup(drm, file, args->handle);
461 if (!gem)
462 return -EINVAL;
463
464 bo = to_tegra_bo(gem);
465
David Herrmann2bc7b0c2013-08-13 14:19:58 +0200466 args->offset = drm_vma_node_offset_addr(&bo->gem.vma_node);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200467
468 drm_gem_object_unreference(gem);
469
470 return 0;
471}
472
473static int tegra_syncpt_read(struct drm_device *drm, void *data,
474 struct drm_file *file)
475{
Thierry Reding776dc382013-10-14 14:43:22 +0200476 struct host1x *host = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200477 struct drm_tegra_syncpt_read *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200478 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200479
Thierry Reding776dc382013-10-14 14:43:22 +0200480 sp = host1x_syncpt_get(host, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200481 if (!sp)
482 return -EINVAL;
483
484 args->value = host1x_syncpt_read_min(sp);
485 return 0;
486}
487
488static int tegra_syncpt_incr(struct drm_device *drm, void *data,
489 struct drm_file *file)
490{
Thierry Reding776dc382013-10-14 14:43:22 +0200491 struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200492 struct drm_tegra_syncpt_incr *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200493 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200494
Thierry Reding776dc382013-10-14 14:43:22 +0200495 sp = host1x_syncpt_get(host1x, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200496 if (!sp)
497 return -EINVAL;
498
Arto Merilainenebae30b2013-05-29 13:26:08 +0300499 return host1x_syncpt_incr(sp);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200500}
501
502static int tegra_syncpt_wait(struct drm_device *drm, void *data,
503 struct drm_file *file)
504{
Thierry Reding776dc382013-10-14 14:43:22 +0200505 struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200506 struct drm_tegra_syncpt_wait *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200507 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200508
Thierry Reding776dc382013-10-14 14:43:22 +0200509 sp = host1x_syncpt_get(host1x, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200510 if (!sp)
511 return -EINVAL;
512
513 return host1x_syncpt_wait(sp, args->thresh, args->timeout,
514 &args->value);
515}
516
517static int tegra_open_channel(struct drm_device *drm, void *data,
518 struct drm_file *file)
519{
Thierry Reding08943e62013-09-26 16:08:18 +0200520 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Reding386a2a72013-09-24 13:22:17 +0200521 struct tegra_drm *tegra = drm->dev_private;
522 struct drm_tegra_open_channel *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200523 struct tegra_drm_context *context;
Thierry Reding53fa7f72013-09-24 15:35:40 +0200524 struct tegra_drm_client *client;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200525 int err = -ENODEV;
526
527 context = kzalloc(sizeof(*context), GFP_KERNEL);
528 if (!context)
529 return -ENOMEM;
530
Thierry Reding776dc382013-10-14 14:43:22 +0200531 list_for_each_entry(client, &tegra->clients, list)
Thierry Reding53fa7f72013-09-24 15:35:40 +0200532 if (client->base.class == args->client) {
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200533 err = client->ops->open_channel(client, context);
534 if (err)
535 break;
536
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200537 list_add(&context->list, &fpriv->contexts);
538 args->context = (uintptr_t)context;
Thierry Reding53fa7f72013-09-24 15:35:40 +0200539 context->client = client;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200540 return 0;
541 }
542
543 kfree(context);
544 return err;
545}
546
547static int tegra_close_channel(struct drm_device *drm, void *data,
548 struct drm_file *file)
549{
Thierry Reding08943e62013-09-26 16:08:18 +0200550 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Reding776dc382013-10-14 14:43:22 +0200551 struct drm_tegra_close_channel *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200552 struct tegra_drm_context *context;
553
554 context = tegra_drm_get_context(args->context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200555
Thierry Reding08943e62013-09-26 16:08:18 +0200556 if (!tegra_drm_file_owns_context(fpriv, context))
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200557 return -EINVAL;
558
559 list_del(&context->list);
Thierry Redingc88c3632013-09-26 16:08:22 +0200560 tegra_drm_context_free(context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200561
562 return 0;
563}
564
565static int tegra_get_syncpt(struct drm_device *drm, void *data,
566 struct drm_file *file)
567{
Thierry Reding08943e62013-09-26 16:08:18 +0200568 struct tegra_drm_file *fpriv = file->driver_priv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200569 struct drm_tegra_get_syncpt *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200570 struct tegra_drm_context *context;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200571 struct host1x_syncpt *syncpt;
572
Thierry Redingc88c3632013-09-26 16:08:22 +0200573 context = tegra_drm_get_context(args->context);
574
Thierry Reding08943e62013-09-26 16:08:18 +0200575 if (!tegra_drm_file_owns_context(fpriv, context))
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200576 return -ENODEV;
577
Thierry Reding53fa7f72013-09-24 15:35:40 +0200578 if (args->index >= context->client->base.num_syncpts)
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200579 return -EINVAL;
580
Thierry Reding53fa7f72013-09-24 15:35:40 +0200581 syncpt = context->client->base.syncpts[args->index];
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200582 args->id = host1x_syncpt_id(syncpt);
583
584 return 0;
585}
586
587static int tegra_submit(struct drm_device *drm, void *data,
588 struct drm_file *file)
589{
Thierry Reding08943e62013-09-26 16:08:18 +0200590 struct tegra_drm_file *fpriv = file->driver_priv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200591 struct drm_tegra_submit *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200592 struct tegra_drm_context *context;
593
594 context = tegra_drm_get_context(args->context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200595
Thierry Reding08943e62013-09-26 16:08:18 +0200596 if (!tegra_drm_file_owns_context(fpriv, context))
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200597 return -ENODEV;
598
599 return context->client->ops->submit(context, args, drm, file);
600}
Arto Merilainenc54a1692013-10-14 15:21:54 +0300601
602static int tegra_get_syncpt_base(struct drm_device *drm, void *data,
603 struct drm_file *file)
604{
605 struct tegra_drm_file *fpriv = file->driver_priv;
606 struct drm_tegra_get_syncpt_base *args = data;
607 struct tegra_drm_context *context;
608 struct host1x_syncpt_base *base;
609 struct host1x_syncpt *syncpt;
610
611 context = tegra_drm_get_context(args->context);
612
613 if (!tegra_drm_file_owns_context(fpriv, context))
614 return -ENODEV;
615
616 if (args->syncpt >= context->client->base.num_syncpts)
617 return -EINVAL;
618
619 syncpt = context->client->base.syncpts[args->syncpt];
620
621 base = host1x_syncpt_get_base(syncpt);
622 if (!base)
623 return -ENXIO;
624
625 args->id = host1x_syncpt_base_id(base);
626
627 return 0;
628}
Thierry Reding7678d712014-06-03 14:56:57 +0200629
630static int tegra_gem_set_tiling(struct drm_device *drm, void *data,
631 struct drm_file *file)
632{
633 struct drm_tegra_gem_set_tiling *args = data;
634 enum tegra_bo_tiling_mode mode;
635 struct drm_gem_object *gem;
636 unsigned long value = 0;
637 struct tegra_bo *bo;
638
639 switch (args->mode) {
640 case DRM_TEGRA_GEM_TILING_MODE_PITCH:
641 mode = TEGRA_BO_TILING_MODE_PITCH;
642
643 if (args->value != 0)
644 return -EINVAL;
645
646 break;
647
648 case DRM_TEGRA_GEM_TILING_MODE_TILED:
649 mode = TEGRA_BO_TILING_MODE_TILED;
650
651 if (args->value != 0)
652 return -EINVAL;
653
654 break;
655
656 case DRM_TEGRA_GEM_TILING_MODE_BLOCK:
657 mode = TEGRA_BO_TILING_MODE_BLOCK;
658
659 if (args->value > 5)
660 return -EINVAL;
661
662 value = args->value;
663 break;
664
665 default:
666 return -EINVAL;
667 }
668
669 gem = drm_gem_object_lookup(drm, file, args->handle);
670 if (!gem)
671 return -ENOENT;
672
673 bo = to_tegra_bo(gem);
674
675 bo->tiling.mode = mode;
676 bo->tiling.value = value;
677
678 drm_gem_object_unreference(gem);
679
680 return 0;
681}
682
683static int tegra_gem_get_tiling(struct drm_device *drm, void *data,
684 struct drm_file *file)
685{
686 struct drm_tegra_gem_get_tiling *args = data;
687 struct drm_gem_object *gem;
688 struct tegra_bo *bo;
689 int err = 0;
690
691 gem = drm_gem_object_lookup(drm, file, args->handle);
692 if (!gem)
693 return -ENOENT;
694
695 bo = to_tegra_bo(gem);
696
697 switch (bo->tiling.mode) {
698 case TEGRA_BO_TILING_MODE_PITCH:
699 args->mode = DRM_TEGRA_GEM_TILING_MODE_PITCH;
700 args->value = 0;
701 break;
702
703 case TEGRA_BO_TILING_MODE_TILED:
704 args->mode = DRM_TEGRA_GEM_TILING_MODE_TILED;
705 args->value = 0;
706 break;
707
708 case TEGRA_BO_TILING_MODE_BLOCK:
709 args->mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
710 args->value = bo->tiling.value;
711 break;
712
713 default:
714 err = -EINVAL;
715 break;
716 }
717
718 drm_gem_object_unreference(gem);
719
720 return err;
721}
Thierry Reding7b129082014-06-10 12:04:03 +0200722
723static int tegra_gem_set_flags(struct drm_device *drm, void *data,
724 struct drm_file *file)
725{
726 struct drm_tegra_gem_set_flags *args = data;
727 struct drm_gem_object *gem;
728 struct tegra_bo *bo;
729
730 if (args->flags & ~DRM_TEGRA_GEM_FLAGS)
731 return -EINVAL;
732
733 gem = drm_gem_object_lookup(drm, file, args->handle);
734 if (!gem)
735 return -ENOENT;
736
737 bo = to_tegra_bo(gem);
738 bo->flags = 0;
739
740 if (args->flags & DRM_TEGRA_GEM_BOTTOM_UP)
741 bo->flags |= TEGRA_BO_BOTTOM_UP;
742
743 drm_gem_object_unreference(gem);
744
745 return 0;
746}
747
748static int tegra_gem_get_flags(struct drm_device *drm, void *data,
749 struct drm_file *file)
750{
751 struct drm_tegra_gem_get_flags *args = data;
752 struct drm_gem_object *gem;
753 struct tegra_bo *bo;
754
755 gem = drm_gem_object_lookup(drm, file, args->handle);
756 if (!gem)
757 return -ENOENT;
758
759 bo = to_tegra_bo(gem);
760 args->flags = 0;
761
762 if (bo->flags & TEGRA_BO_BOTTOM_UP)
763 args->flags |= DRM_TEGRA_GEM_BOTTOM_UP;
764
765 drm_gem_object_unreference(gem);
766
767 return 0;
768}
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200769#endif
770
Rob Clarkbaa70942013-08-02 13:27:49 -0400771static const struct drm_ioctl_desc tegra_drm_ioctls[] = {
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200772#ifdef CONFIG_DRM_TEGRA_STAGING
Thierry Redingbd4f2362014-06-03 14:59:29 +0200773 DRM_IOCTL_DEF_DRV(TEGRA_GEM_CREATE, tegra_gem_create, DRM_UNLOCKED),
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200774 DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_gem_mmap, DRM_UNLOCKED),
775 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_READ, tegra_syncpt_read, DRM_UNLOCKED),
776 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_INCR, tegra_syncpt_incr, DRM_UNLOCKED),
777 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_WAIT, tegra_syncpt_wait, DRM_UNLOCKED),
778 DRM_IOCTL_DEF_DRV(TEGRA_OPEN_CHANNEL, tegra_open_channel, DRM_UNLOCKED),
779 DRM_IOCTL_DEF_DRV(TEGRA_CLOSE_CHANNEL, tegra_close_channel, DRM_UNLOCKED),
780 DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT, tegra_get_syncpt, DRM_UNLOCKED),
781 DRM_IOCTL_DEF_DRV(TEGRA_SUBMIT, tegra_submit, DRM_UNLOCKED),
Arto Merilainenc54a1692013-10-14 15:21:54 +0300782 DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT_BASE, tegra_get_syncpt_base, DRM_UNLOCKED),
Thierry Reding7678d712014-06-03 14:56:57 +0200783 DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_TILING, tegra_gem_set_tiling, DRM_UNLOCKED),
784 DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_TILING, tegra_gem_get_tiling, DRM_UNLOCKED),
Thierry Reding7b129082014-06-10 12:04:03 +0200785 DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_FLAGS, tegra_gem_set_flags, DRM_UNLOCKED),
786 DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_FLAGS, tegra_gem_get_flags, DRM_UNLOCKED),
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200787#endif
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000788};
789
790static const struct file_operations tegra_drm_fops = {
791 .owner = THIS_MODULE,
792 .open = drm_open,
793 .release = drm_release,
794 .unlocked_ioctl = drm_ioctl,
Arto Merilainende2ba662013-03-22 16:34:08 +0200795 .mmap = tegra_drm_mmap,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000796 .poll = drm_poll,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000797 .read = drm_read,
798#ifdef CONFIG_COMPAT
799 .compat_ioctl = drm_compat_ioctl,
800#endif
801 .llseek = noop_llseek,
802};
803
Thierry Redinged7dae52014-12-16 16:03:13 +0100804static struct drm_crtc *tegra_crtc_from_pipe(struct drm_device *drm,
805 unsigned int pipe)
Thierry Reding6e5ff992012-11-28 11:45:47 +0100806{
807 struct drm_crtc *crtc;
808
809 list_for_each_entry(crtc, &drm->mode_config.crtc_list, head) {
Thierry Redinged7dae52014-12-16 16:03:13 +0100810 if (pipe == drm_crtc_index(crtc))
Thierry Reding6e5ff992012-11-28 11:45:47 +0100811 return crtc;
812 }
813
814 return NULL;
815}
816
Thierry Redinged7dae52014-12-16 16:03:13 +0100817static u32 tegra_drm_get_vblank_counter(struct drm_device *drm, int pipe)
Thierry Reding6e5ff992012-11-28 11:45:47 +0100818{
Thierry Redinged7dae52014-12-16 16:03:13 +0100819 struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe);
Thierry Reding42e9ce02015-01-28 14:43:05 +0100820 struct tegra_dc *dc = to_tegra_dc(crtc);
Thierry Redinged7dae52014-12-16 16:03:13 +0100821
822 if (!crtc)
823 return 0;
824
Thierry Reding42e9ce02015-01-28 14:43:05 +0100825 return tegra_dc_get_vblank_counter(dc);
Thierry Reding6e5ff992012-11-28 11:45:47 +0100826}
827
828static int tegra_drm_enable_vblank(struct drm_device *drm, int pipe)
829{
830 struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe);
831 struct tegra_dc *dc = to_tegra_dc(crtc);
832
833 if (!crtc)
834 return -ENODEV;
835
836 tegra_dc_enable_vblank(dc);
837
838 return 0;
839}
840
841static void tegra_drm_disable_vblank(struct drm_device *drm, int pipe)
842{
843 struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe);
844 struct tegra_dc *dc = to_tegra_dc(crtc);
845
846 if (crtc)
847 tegra_dc_disable_vblank(dc);
848}
849
Thierry Reding3c03c462012-11-28 12:00:18 +0100850static void tegra_drm_preclose(struct drm_device *drm, struct drm_file *file)
851{
Thierry Reding08943e62013-09-26 16:08:18 +0200852 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Redingc88c3632013-09-26 16:08:22 +0200853 struct tegra_drm_context *context, *tmp;
Thierry Reding3c03c462012-11-28 12:00:18 +0100854 struct drm_crtc *crtc;
855
856 list_for_each_entry(crtc, &drm->mode_config.crtc_list, head)
857 tegra_dc_cancel_page_flip(crtc, file);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200858
859 list_for_each_entry_safe(context, tmp, &fpriv->contexts, list)
Thierry Redingc88c3632013-09-26 16:08:22 +0200860 tegra_drm_context_free(context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200861
862 kfree(fpriv);
Thierry Reding3c03c462012-11-28 12:00:18 +0100863}
864
Thierry Redinge450fcc2013-02-13 16:13:16 +0100865#ifdef CONFIG_DEBUG_FS
866static int tegra_debugfs_framebuffers(struct seq_file *s, void *data)
867{
868 struct drm_info_node *node = (struct drm_info_node *)s->private;
869 struct drm_device *drm = node->minor->dev;
870 struct drm_framebuffer *fb;
871
872 mutex_lock(&drm->mode_config.fb_lock);
873
874 list_for_each_entry(fb, &drm->mode_config.fb_list, head) {
875 seq_printf(s, "%3d: user size: %d x %d, depth %d, %d bpp, refcount %d\n",
876 fb->base.id, fb->width, fb->height, fb->depth,
877 fb->bits_per_pixel,
878 atomic_read(&fb->refcount.refcount));
879 }
880
881 mutex_unlock(&drm->mode_config.fb_lock);
882
883 return 0;
884}
885
Thierry Reding28c23372015-01-23 09:16:03 +0100886static int tegra_debugfs_iova(struct seq_file *s, void *data)
887{
888 struct drm_info_node *node = (struct drm_info_node *)s->private;
889 struct drm_device *drm = node->minor->dev;
890 struct tegra_drm *tegra = drm->dev_private;
891
892 return drm_mm_dump_table(s, &tegra->mm);
893}
894
Thierry Redinge450fcc2013-02-13 16:13:16 +0100895static struct drm_info_list tegra_debugfs_list[] = {
896 { "framebuffers", tegra_debugfs_framebuffers, 0 },
Thierry Reding28c23372015-01-23 09:16:03 +0100897 { "iova", tegra_debugfs_iova, 0 },
Thierry Redinge450fcc2013-02-13 16:13:16 +0100898};
899
900static int tegra_debugfs_init(struct drm_minor *minor)
901{
902 return drm_debugfs_create_files(tegra_debugfs_list,
903 ARRAY_SIZE(tegra_debugfs_list),
904 minor->debugfs_root, minor);
905}
906
907static void tegra_debugfs_cleanup(struct drm_minor *minor)
908{
909 drm_debugfs_remove_files(tegra_debugfs_list,
910 ARRAY_SIZE(tegra_debugfs_list), minor);
911}
912#endif
913
Thierry Reding9b57f5f2013-11-08 13:17:14 +0100914static struct drm_driver tegra_drm_driver = {
Thierry Reding38003912013-12-12 10:00:43 +0100915 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000916 .load = tegra_drm_load,
917 .unload = tegra_drm_unload,
918 .open = tegra_drm_open,
Thierry Reding3c03c462012-11-28 12:00:18 +0100919 .preclose = tegra_drm_preclose,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000920 .lastclose = tegra_drm_lastclose,
921
Thierry Reding6e5ff992012-11-28 11:45:47 +0100922 .get_vblank_counter = tegra_drm_get_vblank_counter,
923 .enable_vblank = tegra_drm_enable_vblank,
924 .disable_vblank = tegra_drm_disable_vblank,
925
Thierry Redinge450fcc2013-02-13 16:13:16 +0100926#if defined(CONFIG_DEBUG_FS)
927 .debugfs_init = tegra_debugfs_init,
928 .debugfs_cleanup = tegra_debugfs_cleanup,
929#endif
930
Arto Merilainende2ba662013-03-22 16:34:08 +0200931 .gem_free_object = tegra_bo_free_object,
932 .gem_vm_ops = &tegra_bo_vm_ops,
Thierry Reding38003912013-12-12 10:00:43 +0100933
934 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
935 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
936 .gem_prime_export = tegra_gem_prime_export,
937 .gem_prime_import = tegra_gem_prime_import,
938
Arto Merilainende2ba662013-03-22 16:34:08 +0200939 .dumb_create = tegra_bo_dumb_create,
940 .dumb_map_offset = tegra_bo_dumb_map_offset,
Daniel Vetter43387b32013-07-16 09:12:04 +0200941 .dumb_destroy = drm_gem_dumb_destroy,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000942
943 .ioctls = tegra_drm_ioctls,
944 .num_ioctls = ARRAY_SIZE(tegra_drm_ioctls),
945 .fops = &tegra_drm_fops,
946
947 .name = DRIVER_NAME,
948 .desc = DRIVER_DESC,
949 .date = DRIVER_DATE,
950 .major = DRIVER_MAJOR,
951 .minor = DRIVER_MINOR,
952 .patchlevel = DRIVER_PATCHLEVEL,
953};
Thierry Reding776dc382013-10-14 14:43:22 +0200954
955int tegra_drm_register_client(struct tegra_drm *tegra,
956 struct tegra_drm_client *client)
957{
958 mutex_lock(&tegra->clients_lock);
959 list_add_tail(&client->list, &tegra->clients);
960 mutex_unlock(&tegra->clients_lock);
961
962 return 0;
963}
964
965int tegra_drm_unregister_client(struct tegra_drm *tegra,
966 struct tegra_drm_client *client)
967{
968 mutex_lock(&tegra->clients_lock);
969 list_del_init(&client->list);
970 mutex_unlock(&tegra->clients_lock);
971
972 return 0;
973}
974
Thierry Reding9910f5c2014-05-22 09:57:15 +0200975static int host1x_drm_probe(struct host1x_device *dev)
Thierry Reding776dc382013-10-14 14:43:22 +0200976{
Thierry Reding9910f5c2014-05-22 09:57:15 +0200977 struct drm_driver *driver = &tegra_drm_driver;
978 struct drm_device *drm;
979 int err;
980
981 drm = drm_dev_alloc(driver, &dev->dev);
982 if (!drm)
983 return -ENOMEM;
984
985 drm_dev_set_unique(drm, dev_name(&dev->dev));
986 dev_set_drvdata(&dev->dev, drm);
987
988 err = drm_dev_register(drm, 0);
989 if (err < 0)
990 goto unref;
991
992 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", driver->name,
993 driver->major, driver->minor, driver->patchlevel,
994 driver->date, drm->primary->index);
995
996 return 0;
997
998unref:
999 drm_dev_unref(drm);
1000 return err;
Thierry Reding776dc382013-10-14 14:43:22 +02001001}
1002
Thierry Reding9910f5c2014-05-22 09:57:15 +02001003static int host1x_drm_remove(struct host1x_device *dev)
Thierry Reding776dc382013-10-14 14:43:22 +02001004{
Thierry Reding9910f5c2014-05-22 09:57:15 +02001005 struct drm_device *drm = dev_get_drvdata(&dev->dev);
1006
1007 drm_dev_unregister(drm);
1008 drm_dev_unref(drm);
Thierry Reding776dc382013-10-14 14:43:22 +02001009
1010 return 0;
1011}
1012
Thierry Reding359ae682014-12-18 17:15:25 +01001013#ifdef CONFIG_PM_SLEEP
1014static int host1x_drm_suspend(struct device *dev)
1015{
1016 struct drm_device *drm = dev_get_drvdata(dev);
1017
1018 drm_kms_helper_poll_disable(drm);
1019
1020 return 0;
1021}
1022
1023static int host1x_drm_resume(struct device *dev)
1024{
1025 struct drm_device *drm = dev_get_drvdata(dev);
1026
1027 drm_kms_helper_poll_enable(drm);
1028
1029 return 0;
1030}
1031#endif
1032
1033static const struct dev_pm_ops host1x_drm_pm_ops = {
1034 SET_SYSTEM_SLEEP_PM_OPS(host1x_drm_suspend, host1x_drm_resume)
1035};
1036
Thierry Reding776dc382013-10-14 14:43:22 +02001037static const struct of_device_id host1x_drm_subdevs[] = {
1038 { .compatible = "nvidia,tegra20-dc", },
1039 { .compatible = "nvidia,tegra20-hdmi", },
1040 { .compatible = "nvidia,tegra20-gr2d", },
Thierry Reding5f60ed02013-02-28 08:08:01 +01001041 { .compatible = "nvidia,tegra20-gr3d", },
Thierry Reding776dc382013-10-14 14:43:22 +02001042 { .compatible = "nvidia,tegra30-dc", },
1043 { .compatible = "nvidia,tegra30-hdmi", },
1044 { .compatible = "nvidia,tegra30-gr2d", },
Thierry Reding5f60ed02013-02-28 08:08:01 +01001045 { .compatible = "nvidia,tegra30-gr3d", },
Thierry Redingdec72732013-09-03 08:45:46 +02001046 { .compatible = "nvidia,tegra114-dsi", },
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001047 { .compatible = "nvidia,tegra114-hdmi", },
Thierry Reding5f60ed02013-02-28 08:08:01 +01001048 { .compatible = "nvidia,tegra114-gr3d", },
Thierry Reding8620fc62013-12-12 11:03:59 +01001049 { .compatible = "nvidia,tegra124-dc", },
Thierry Reding6b6b6042013-11-15 16:06:05 +01001050 { .compatible = "nvidia,tegra124-sor", },
Thierry Redingfb7be702013-11-15 16:07:32 +01001051 { .compatible = "nvidia,tegra124-hdmi", },
Thierry Reding776dc382013-10-14 14:43:22 +02001052 { /* sentinel */ }
1053};
1054
1055static struct host1x_driver host1x_drm_driver = {
Thierry Redingf4c5cf82014-12-18 15:29:14 +01001056 .driver = {
1057 .name = "drm",
Thierry Reding359ae682014-12-18 17:15:25 +01001058 .pm = &host1x_drm_pm_ops,
Thierry Redingf4c5cf82014-12-18 15:29:14 +01001059 },
Thierry Reding776dc382013-10-14 14:43:22 +02001060 .probe = host1x_drm_probe,
1061 .remove = host1x_drm_remove,
1062 .subdevs = host1x_drm_subdevs,
1063};
1064
1065static int __init host1x_drm_init(void)
1066{
1067 int err;
1068
1069 err = host1x_driver_register(&host1x_drm_driver);
1070 if (err < 0)
1071 return err;
1072
1073 err = platform_driver_register(&tegra_dc_driver);
1074 if (err < 0)
1075 goto unregister_host1x;
1076
Thierry Redingdec72732013-09-03 08:45:46 +02001077 err = platform_driver_register(&tegra_dsi_driver);
Thierry Reding776dc382013-10-14 14:43:22 +02001078 if (err < 0)
1079 goto unregister_dc;
1080
Thierry Reding6b6b6042013-11-15 16:06:05 +01001081 err = platform_driver_register(&tegra_sor_driver);
Thierry Redingdec72732013-09-03 08:45:46 +02001082 if (err < 0)
1083 goto unregister_dsi;
1084
Thierry Reding6b6b6042013-11-15 16:06:05 +01001085 err = platform_driver_register(&tegra_hdmi_driver);
1086 if (err < 0)
1087 goto unregister_sor;
1088
1089 err = platform_driver_register(&tegra_dpaux_driver);
Thierry Reding776dc382013-10-14 14:43:22 +02001090 if (err < 0)
1091 goto unregister_hdmi;
1092
Thierry Reding6b6b6042013-11-15 16:06:05 +01001093 err = platform_driver_register(&tegra_gr2d_driver);
1094 if (err < 0)
1095 goto unregister_dpaux;
1096
Thierry Reding5f60ed02013-02-28 08:08:01 +01001097 err = platform_driver_register(&tegra_gr3d_driver);
1098 if (err < 0)
1099 goto unregister_gr2d;
1100
Thierry Reding776dc382013-10-14 14:43:22 +02001101 return 0;
1102
Thierry Reding5f60ed02013-02-28 08:08:01 +01001103unregister_gr2d:
1104 platform_driver_unregister(&tegra_gr2d_driver);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001105unregister_dpaux:
1106 platform_driver_unregister(&tegra_dpaux_driver);
Thierry Reding776dc382013-10-14 14:43:22 +02001107unregister_hdmi:
1108 platform_driver_unregister(&tegra_hdmi_driver);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001109unregister_sor:
1110 platform_driver_unregister(&tegra_sor_driver);
Thierry Redingdec72732013-09-03 08:45:46 +02001111unregister_dsi:
1112 platform_driver_unregister(&tegra_dsi_driver);
Thierry Reding776dc382013-10-14 14:43:22 +02001113unregister_dc:
1114 platform_driver_unregister(&tegra_dc_driver);
1115unregister_host1x:
1116 host1x_driver_unregister(&host1x_drm_driver);
1117 return err;
1118}
1119module_init(host1x_drm_init);
1120
1121static void __exit host1x_drm_exit(void)
1122{
Thierry Reding5f60ed02013-02-28 08:08:01 +01001123 platform_driver_unregister(&tegra_gr3d_driver);
Thierry Reding776dc382013-10-14 14:43:22 +02001124 platform_driver_unregister(&tegra_gr2d_driver);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001125 platform_driver_unregister(&tegra_dpaux_driver);
Thierry Reding776dc382013-10-14 14:43:22 +02001126 platform_driver_unregister(&tegra_hdmi_driver);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001127 platform_driver_unregister(&tegra_sor_driver);
Thierry Redingdec72732013-09-03 08:45:46 +02001128 platform_driver_unregister(&tegra_dsi_driver);
Thierry Reding776dc382013-10-14 14:43:22 +02001129 platform_driver_unregister(&tegra_dc_driver);
1130 host1x_driver_unregister(&host1x_drm_driver);
1131}
1132module_exit(host1x_drm_exit);
1133
1134MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
1135MODULE_DESCRIPTION("NVIDIA Tegra DRM driver");
1136MODULE_LICENSE("GPL v2");