blob: f455ce71e85d9c6bff84388815caa87f9a22409b [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00002/*
3 * Copyright (C) 2012 Avionic Design GmbH
Mikko Perttunenad926012016-12-14 13:16:11 +02004 * Copyright (C) 2012-2016 NVIDIA CORPORATION. All rights reserved.
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00005 */
6
Mikko Perttunenad926012016-12-14 13:16:11 +02007#include <linux/bitops.h>
Thierry Reding776dc382013-10-14 14:43:22 +02008#include <linux/host1x.h>
Thierry Redingbdd2f9c2017-03-09 20:04:55 +01009#include <linux/idr.h>
Thierry Redingdf06b752014-06-26 21:41:53 +020010#include <linux/iommu.h>
Sam Ravnborgeb1df692019-08-04 11:41:30 +020011#include <linux/module.h>
12#include <linux/platform_device.h>
Thierry Reding776dc382013-10-14 14:43:22 +020013
Thierry Reding1503ca42014-11-24 17:41:23 +010014#include <drm/drm_atomic.h>
Thierry Reding07866962014-11-24 17:08:06 +010015#include <drm/drm_atomic_helper.h>
Sam Ravnborgeb1df692019-08-04 11:41:30 +020016#include <drm/drm_debugfs.h>
17#include <drm/drm_drv.h>
18#include <drm/drm_fourcc.h>
19#include <drm/drm_ioctl.h>
20#include <drm/drm_prime.h>
21#include <drm/drm_vblank.h>
Thierry Reding07866962014-11-24 17:08:06 +010022
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000023#include "drm.h"
Arto Merilainende2ba662013-03-22 16:34:08 +020024#include "gem.h"
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000025
26#define DRIVER_NAME "tegra"
27#define DRIVER_DESC "NVIDIA Tegra graphics"
28#define DRIVER_DATE "20120330"
29#define DRIVER_MAJOR 0
30#define DRIVER_MINOR 0
31#define DRIVER_PATCHLEVEL 0
32
Mikko Perttunenad926012016-12-14 13:16:11 +020033#define CARVEOUT_SZ SZ_64M
Dmitry Osipenko368f6222017-06-15 02:18:26 +030034#define CDMA_GATHER_FETCHES_MAX_NB 16383
Mikko Perttunenad926012016-12-14 13:16:11 +020035
Thierry Reding08943e62013-09-26 16:08:18 +020036struct tegra_drm_file {
Thierry Redingbdd2f9c2017-03-09 20:04:55 +010037 struct idr contexts;
38 struct mutex lock;
Thierry Reding08943e62013-09-26 16:08:18 +020039};
40
Thierry Redingab7d3f52017-12-14 13:46:20 +010041static int tegra_atomic_check(struct drm_device *drm,
42 struct drm_atomic_state *state)
Thierry Reding1503ca42014-11-24 17:41:23 +010043{
Thierry Reding1503ca42014-11-24 17:41:23 +010044 int err;
45
Peter Ujfalusia18301b2018-03-21 12:20:26 +020046 err = drm_atomic_helper_check(drm, state);
Thierry Redingab7d3f52017-12-14 13:46:20 +010047 if (err < 0)
Thierry Reding1503ca42014-11-24 17:41:23 +010048 return err;
49
Peter Ujfalusia18301b2018-03-21 12:20:26 +020050 return tegra_display_hub_atomic_check(drm, state);
Thierry Reding1503ca42014-11-24 17:41:23 +010051}
52
Thierry Reding31b02ca2017-10-12 17:40:46 +020053static const struct drm_mode_config_funcs tegra_drm_mode_config_funcs = {
Thierry Redingf9914212014-11-26 13:03:57 +010054 .fb_create = tegra_fb_create,
Archit Tanejab110ef32015-10-27 13:40:59 +053055#ifdef CONFIG_DRM_FBDEV_EMULATION
Noralf Trønnesc94beda2017-12-05 19:25:04 +010056 .output_poll_changed = drm_fb_helper_output_poll_changed,
Thierry Redingf9914212014-11-26 13:03:57 +010057#endif
Thierry Redingab7d3f52017-12-14 13:46:20 +010058 .atomic_check = tegra_atomic_check,
Thierry Reding31b02ca2017-10-12 17:40:46 +020059 .atomic_commit = drm_atomic_helper_commit,
60};
61
Thierry Redingc4755fb2017-11-13 11:08:13 +010062static void tegra_atomic_commit_tail(struct drm_atomic_state *old_state)
63{
64 struct drm_device *drm = old_state->dev;
65 struct tegra_drm *tegra = drm->dev_private;
66
67 if (tegra->hub) {
68 drm_atomic_helper_commit_modeset_disables(drm, old_state);
69 tegra_display_hub_atomic_commit(drm, old_state);
70 drm_atomic_helper_commit_planes(drm, old_state, 0);
71 drm_atomic_helper_commit_modeset_enables(drm, old_state);
72 drm_atomic_helper_commit_hw_done(old_state);
73 drm_atomic_helper_wait_for_vblanks(drm, old_state);
74 drm_atomic_helper_cleanup_planes(drm, old_state);
75 } else {
76 drm_atomic_helper_commit_tail_rpm(old_state);
77 }
78}
79
Thierry Reding31b02ca2017-10-12 17:40:46 +020080static const struct drm_mode_config_helper_funcs
81tegra_drm_mode_config_helpers = {
Thierry Redingc4755fb2017-11-13 11:08:13 +010082 .atomic_commit_tail = tegra_atomic_commit_tail,
Thierry Redingf9914212014-11-26 13:03:57 +010083};
84
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000085static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
86{
Thierry Reding08943e62013-09-26 16:08:18 +020087 struct tegra_drm_file *fpriv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +020088
89 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
90 if (!fpriv)
91 return -ENOMEM;
92
Thierry Redingbdd2f9c2017-03-09 20:04:55 +010093 idr_init(&fpriv->contexts);
94 mutex_init(&fpriv->lock);
Terje Bergstromd43f81c2013-03-22 16:34:09 +020095 filp->driver_priv = fpriv;
96
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000097 return 0;
98}
99
Thierry Redingc88c3632013-09-26 16:08:22 +0200100static void tegra_drm_context_free(struct tegra_drm_context *context)
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200101{
102 context->client->ops->close_channel(context);
103 kfree(context);
104}
105
Thierry Redingc40f0f12013-10-10 11:00:33 +0200106static struct host1x_bo *
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100107host1x_bo_lookup(struct drm_file *file, u32 handle)
Thierry Redingc40f0f12013-10-10 11:00:33 +0200108{
109 struct drm_gem_object *gem;
110 struct tegra_bo *bo;
111
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100112 gem = drm_gem_object_lookup(file, handle);
Thierry Redingc40f0f12013-10-10 11:00:33 +0200113 if (!gem)
114 return NULL;
115
Thierry Redingc40f0f12013-10-10 11:00:33 +0200116 bo = to_tegra_bo(gem);
117 return &bo->base;
118}
119
Thierry Reding961e3be2014-06-10 10:25:00 +0200120static int host1x_reloc_copy_from_user(struct host1x_reloc *dest,
121 struct drm_tegra_reloc __user *src,
122 struct drm_device *drm,
123 struct drm_file *file)
124{
125 u32 cmdbuf, target;
126 int err;
127
128 err = get_user(cmdbuf, &src->cmdbuf.handle);
129 if (err < 0)
130 return err;
131
132 err = get_user(dest->cmdbuf.offset, &src->cmdbuf.offset);
133 if (err < 0)
134 return err;
135
136 err = get_user(target, &src->target.handle);
137 if (err < 0)
138 return err;
139
David Ung31f40f82015-01-20 18:37:35 -0800140 err = get_user(dest->target.offset, &src->target.offset);
Thierry Reding961e3be2014-06-10 10:25:00 +0200141 if (err < 0)
142 return err;
143
144 err = get_user(dest->shift, &src->shift);
145 if (err < 0)
146 return err;
147
Thierry Redingab4f81b2019-10-28 13:37:11 +0100148 dest->flags = HOST1X_RELOC_READ | HOST1X_RELOC_WRITE;
149
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100150 dest->cmdbuf.bo = host1x_bo_lookup(file, cmdbuf);
Thierry Reding961e3be2014-06-10 10:25:00 +0200151 if (!dest->cmdbuf.bo)
152 return -ENOENT;
153
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100154 dest->target.bo = host1x_bo_lookup(file, target);
Thierry Reding961e3be2014-06-10 10:25:00 +0200155 if (!dest->target.bo)
156 return -ENOENT;
157
158 return 0;
159}
160
Thierry Redingc40f0f12013-10-10 11:00:33 +0200161int tegra_drm_submit(struct tegra_drm_context *context,
162 struct drm_tegra_submit *args, struct drm_device *drm,
163 struct drm_file *file)
164{
Thierry Redingbf3d41c2018-05-16 14:12:33 +0200165 struct host1x_client *client = &context->client->base;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200166 unsigned int num_cmdbufs = args->num_cmdbufs;
167 unsigned int num_relocs = args->num_relocs;
Mikko Perttunena176c672017-09-28 15:50:44 +0300168 struct drm_tegra_cmdbuf __user *user_cmdbufs;
169 struct drm_tegra_reloc __user *user_relocs;
Mikko Perttunena176c672017-09-28 15:50:44 +0300170 struct drm_tegra_syncpt __user *user_syncpt;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200171 struct drm_tegra_syncpt syncpt;
Dmitry Osipenkoe0b2ce02017-06-15 02:18:28 +0300172 struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200173 struct drm_gem_object **refs;
Dmitry Osipenkoe0b2ce02017-06-15 02:18:28 +0300174 struct host1x_syncpt *sp;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200175 struct host1x_job *job;
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200176 unsigned int num_refs;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200177 int err;
178
Mikko Perttunena176c672017-09-28 15:50:44 +0300179 user_cmdbufs = u64_to_user_ptr(args->cmdbufs);
180 user_relocs = u64_to_user_ptr(args->relocs);
Mikko Perttunena176c672017-09-28 15:50:44 +0300181 user_syncpt = u64_to_user_ptr(args->syncpts);
182
Thierry Redingc40f0f12013-10-10 11:00:33 +0200183 /* We don't yet support other than one syncpt_incr struct per submit */
184 if (args->num_syncpts != 1)
185 return -EINVAL;
186
Dmitry Osipenkod0fbbdf2017-06-15 02:18:27 +0300187 /* We don't yet support waitchks */
188 if (args->num_waitchks != 0)
189 return -EINVAL;
190
Thierry Redingc40f0f12013-10-10 11:00:33 +0200191 job = host1x_job_alloc(context->channel, args->num_cmdbufs,
Thierry Reding24c94e12018-05-05 08:45:47 +0200192 args->num_relocs);
Thierry Redingc40f0f12013-10-10 11:00:33 +0200193 if (!job)
194 return -ENOMEM;
195
196 job->num_relocs = args->num_relocs;
Thierry Redingbf3d41c2018-05-16 14:12:33 +0200197 job->client = client;
198 job->class = client->class;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200199 job->serialize = true;
200
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200201 /*
202 * Track referenced BOs so that they can be unreferenced after the
203 * submission is complete.
204 */
Thierry Reding24c94e12018-05-05 08:45:47 +0200205 num_refs = num_cmdbufs + num_relocs * 2;
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200206
207 refs = kmalloc_array(num_refs, sizeof(*refs), GFP_KERNEL);
208 if (!refs) {
209 err = -ENOMEM;
210 goto put;
211 }
212
213 /* reuse as an iterator later */
214 num_refs = 0;
215
Thierry Redingc40f0f12013-10-10 11:00:33 +0200216 while (num_cmdbufs) {
217 struct drm_tegra_cmdbuf cmdbuf;
218 struct host1x_bo *bo;
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300219 struct tegra_bo *obj;
220 u64 offset;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200221
Mikko Perttunena176c672017-09-28 15:50:44 +0300222 if (copy_from_user(&cmdbuf, user_cmdbufs, sizeof(cmdbuf))) {
Dan Carpenter9a991602013-11-08 13:07:37 +0300223 err = -EFAULT;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200224 goto fail;
Dan Carpenter9a991602013-11-08 13:07:37 +0300225 }
Thierry Redingc40f0f12013-10-10 11:00:33 +0200226
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300227 /*
228 * The maximum number of CDMA gather fetches is 16383, a higher
229 * value means the words count is malformed.
230 */
231 if (cmdbuf.words > CDMA_GATHER_FETCHES_MAX_NB) {
232 err = -EINVAL;
233 goto fail;
234 }
235
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100236 bo = host1x_bo_lookup(file, cmdbuf.handle);
Thierry Redingc40f0f12013-10-10 11:00:33 +0200237 if (!bo) {
238 err = -ENOENT;
239 goto fail;
240 }
241
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300242 offset = (u64)cmdbuf.offset + (u64)cmdbuf.words * sizeof(u32);
243 obj = host1x_to_tegra_bo(bo);
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200244 refs[num_refs++] = &obj->gem;
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300245
246 /*
247 * Gather buffer base address must be 4-bytes aligned,
248 * unaligned offset is malformed and cause commands stream
249 * corruption on the buffer address relocation.
250 */
Mikko Perttunen5265f032018-06-20 16:03:58 +0300251 if (offset & 3 || offset > obj->gem.size) {
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300252 err = -EINVAL;
253 goto fail;
254 }
255
Thierry Redingc40f0f12013-10-10 11:00:33 +0200256 host1x_job_add_gather(job, bo, cmdbuf.words, cmdbuf.offset);
257 num_cmdbufs--;
Mikko Perttunena176c672017-09-28 15:50:44 +0300258 user_cmdbufs++;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200259 }
260
Thierry Reding961e3be2014-06-10 10:25:00 +0200261 /* copy and resolve relocations from submit */
Thierry Redingc40f0f12013-10-10 11:00:33 +0200262 while (num_relocs--) {
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300263 struct host1x_reloc *reloc;
264 struct tegra_bo *obj;
265
Thierry Reding06490bb2018-05-16 16:58:44 +0200266 err = host1x_reloc_copy_from_user(&job->relocs[num_relocs],
Mikko Perttunena176c672017-09-28 15:50:44 +0300267 &user_relocs[num_relocs], drm,
Thierry Reding961e3be2014-06-10 10:25:00 +0200268 file);
269 if (err < 0)
Thierry Redingc40f0f12013-10-10 11:00:33 +0200270 goto fail;
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300271
Thierry Reding06490bb2018-05-16 16:58:44 +0200272 reloc = &job->relocs[num_relocs];
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300273 obj = host1x_to_tegra_bo(reloc->cmdbuf.bo);
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200274 refs[num_refs++] = &obj->gem;
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300275
276 /*
277 * The unaligned cmdbuf offset will cause an unaligned write
278 * during of the relocations patching, corrupting the commands
279 * stream.
280 */
281 if (reloc->cmdbuf.offset & 3 ||
282 reloc->cmdbuf.offset >= obj->gem.size) {
283 err = -EINVAL;
284 goto fail;
285 }
286
287 obj = host1x_to_tegra_bo(reloc->target.bo);
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200288 refs[num_refs++] = &obj->gem;
Dmitry Osipenko368f6222017-06-15 02:18:26 +0300289
290 if (reloc->target.offset >= obj->gem.size) {
291 err = -EINVAL;
292 goto fail;
293 }
Thierry Redingc40f0f12013-10-10 11:00:33 +0200294 }
295
Mikko Perttunena176c672017-09-28 15:50:44 +0300296 if (copy_from_user(&syncpt, user_syncpt, sizeof(syncpt))) {
Dan Carpenter9a991602013-11-08 13:07:37 +0300297 err = -EFAULT;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200298 goto fail;
Dan Carpenter9a991602013-11-08 13:07:37 +0300299 }
Thierry Redingc40f0f12013-10-10 11:00:33 +0200300
Dmitry Osipenkoe0b2ce02017-06-15 02:18:28 +0300301 /* check whether syncpoint ID is valid */
302 sp = host1x_syncpt_get(host1x, syncpt.id);
303 if (!sp) {
304 err = -ENOENT;
305 goto fail;
306 }
307
Thierry Redingc40f0f12013-10-10 11:00:33 +0200308 job->is_addr_reg = context->client->ops->is_addr_reg;
Dmitry Osipenko0f563a42017-06-15 02:18:37 +0300309 job->is_valid_class = context->client->ops->is_valid_class;
Thierry Redingc40f0f12013-10-10 11:00:33 +0200310 job->syncpt_incrs = syncpt.incrs;
311 job->syncpt_id = syncpt.id;
312 job->timeout = 10000;
313
314 if (args->timeout && args->timeout < 10000)
315 job->timeout = args->timeout;
316
317 err = host1x_job_pin(job, context->client->base.dev);
318 if (err)
319 goto fail;
320
321 err = host1x_job_submit(job);
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200322 if (err) {
323 host1x_job_unpin(job);
324 goto fail;
325 }
Thierry Redingc40f0f12013-10-10 11:00:33 +0200326
327 args->fence = job->syncpt_end;
328
Thierry Redingc40f0f12013-10-10 11:00:33 +0200329fail:
Dmitry Osipenkoec73c4c2017-08-11 19:54:56 +0200330 while (num_refs--)
331 drm_gem_object_put_unlocked(refs[num_refs]);
332
333 kfree(refs);
334
335put:
Thierry Redingc40f0f12013-10-10 11:00:33 +0200336 host1x_job_put(job);
337 return err;
338}
339
340
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200341#ifdef CONFIG_DRM_TEGRA_STAGING
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200342static int tegra_gem_create(struct drm_device *drm, void *data,
343 struct drm_file *file)
344{
345 struct drm_tegra_gem_create *args = data;
346 struct tegra_bo *bo;
347
Thierry Reding773af772013-10-04 22:34:01 +0200348 bo = tegra_bo_create_with_handle(file, drm, args->size, args->flags,
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200349 &args->handle);
350 if (IS_ERR(bo))
351 return PTR_ERR(bo);
352
353 return 0;
354}
355
356static int tegra_gem_mmap(struct drm_device *drm, void *data,
357 struct drm_file *file)
358{
359 struct drm_tegra_gem_mmap *args = data;
360 struct drm_gem_object *gem;
361 struct tegra_bo *bo;
362
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100363 gem = drm_gem_object_lookup(file, args->handle);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200364 if (!gem)
365 return -EINVAL;
366
367 bo = to_tegra_bo(gem);
368
David Herrmann2bc7b0c2013-08-13 14:19:58 +0200369 args->offset = drm_vma_node_offset_addr(&bo->gem.vma_node);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200370
Cihangir Akturk7664b2f2017-08-11 15:33:07 +0300371 drm_gem_object_put_unlocked(gem);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200372
373 return 0;
374}
375
376static int tegra_syncpt_read(struct drm_device *drm, void *data,
377 struct drm_file *file)
378{
Thierry Reding776dc382013-10-14 14:43:22 +0200379 struct host1x *host = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200380 struct drm_tegra_syncpt_read *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200381 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200382
Thierry Reding776dc382013-10-14 14:43:22 +0200383 sp = host1x_syncpt_get(host, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200384 if (!sp)
385 return -EINVAL;
386
387 args->value = host1x_syncpt_read_min(sp);
388 return 0;
389}
390
391static int tegra_syncpt_incr(struct drm_device *drm, void *data,
392 struct drm_file *file)
393{
Thierry Reding776dc382013-10-14 14:43:22 +0200394 struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200395 struct drm_tegra_syncpt_incr *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200396 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200397
Thierry Reding776dc382013-10-14 14:43:22 +0200398 sp = host1x_syncpt_get(host1x, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200399 if (!sp)
400 return -EINVAL;
401
Arto Merilainenebae30b2013-05-29 13:26:08 +0300402 return host1x_syncpt_incr(sp);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200403}
404
405static int tegra_syncpt_wait(struct drm_device *drm, void *data,
406 struct drm_file *file)
407{
Thierry Reding776dc382013-10-14 14:43:22 +0200408 struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200409 struct drm_tegra_syncpt_wait *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200410 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200411
Thierry Reding776dc382013-10-14 14:43:22 +0200412 sp = host1x_syncpt_get(host1x, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200413 if (!sp)
414 return -EINVAL;
415
Dmitry Osipenko4c69ac122017-12-20 18:46:14 +0300416 return host1x_syncpt_wait(sp, args->thresh,
417 msecs_to_jiffies(args->timeout),
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200418 &args->value);
419}
420
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100421static int tegra_client_open(struct tegra_drm_file *fpriv,
422 struct tegra_drm_client *client,
423 struct tegra_drm_context *context)
424{
425 int err;
426
427 err = client->ops->open_channel(client, context);
428 if (err < 0)
429 return err;
430
Dmitry Osipenkod6c153e2017-06-15 02:18:25 +0300431 err = idr_alloc(&fpriv->contexts, context, 1, 0, GFP_KERNEL);
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100432 if (err < 0) {
433 client->ops->close_channel(context);
434 return err;
435 }
436
437 context->client = client;
438 context->id = err;
439
440 return 0;
441}
442
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200443static int tegra_open_channel(struct drm_device *drm, void *data,
444 struct drm_file *file)
445{
Thierry Reding08943e62013-09-26 16:08:18 +0200446 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Reding386a2a72013-09-24 13:22:17 +0200447 struct tegra_drm *tegra = drm->dev_private;
448 struct drm_tegra_open_channel *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200449 struct tegra_drm_context *context;
Thierry Reding53fa7f72013-09-24 15:35:40 +0200450 struct tegra_drm_client *client;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200451 int err = -ENODEV;
452
453 context = kzalloc(sizeof(*context), GFP_KERNEL);
454 if (!context)
455 return -ENOMEM;
456
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100457 mutex_lock(&fpriv->lock);
458
Thierry Reding776dc382013-10-14 14:43:22 +0200459 list_for_each_entry(client, &tegra->clients, list)
Thierry Reding53fa7f72013-09-24 15:35:40 +0200460 if (client->base.class == args->client) {
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100461 err = tegra_client_open(fpriv, client, context);
462 if (err < 0)
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200463 break;
464
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100465 args->context = context->id;
466 break;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200467 }
468
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100469 if (err < 0)
470 kfree(context);
471
472 mutex_unlock(&fpriv->lock);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200473 return err;
474}
475
476static int tegra_close_channel(struct drm_device *drm, void *data,
477 struct drm_file *file)
478{
Thierry Reding08943e62013-09-26 16:08:18 +0200479 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Reding776dc382013-10-14 14:43:22 +0200480 struct drm_tegra_close_channel *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200481 struct tegra_drm_context *context;
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100482 int err = 0;
Thierry Redingc88c3632013-09-26 16:08:22 +0200483
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100484 mutex_lock(&fpriv->lock);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200485
Dmitry Osipenko1066a892017-06-15 02:18:24 +0300486 context = idr_find(&fpriv->contexts, args->context);
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100487 if (!context) {
488 err = -EINVAL;
489 goto unlock;
490 }
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200491
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100492 idr_remove(&fpriv->contexts, context->id);
Thierry Redingc88c3632013-09-26 16:08:22 +0200493 tegra_drm_context_free(context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200494
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100495unlock:
496 mutex_unlock(&fpriv->lock);
497 return err;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200498}
499
500static int tegra_get_syncpt(struct drm_device *drm, void *data,
501 struct drm_file *file)
502{
Thierry Reding08943e62013-09-26 16:08:18 +0200503 struct tegra_drm_file *fpriv = file->driver_priv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200504 struct drm_tegra_get_syncpt *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200505 struct tegra_drm_context *context;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200506 struct host1x_syncpt *syncpt;
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100507 int err = 0;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200508
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100509 mutex_lock(&fpriv->lock);
Thierry Redingc88c3632013-09-26 16:08:22 +0200510
Dmitry Osipenko1066a892017-06-15 02:18:24 +0300511 context = idr_find(&fpriv->contexts, args->context);
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100512 if (!context) {
513 err = -ENODEV;
514 goto unlock;
515 }
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200516
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100517 if (args->index >= context->client->base.num_syncpts) {
518 err = -EINVAL;
519 goto unlock;
520 }
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200521
Thierry Reding53fa7f72013-09-24 15:35:40 +0200522 syncpt = context->client->base.syncpts[args->index];
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200523 args->id = host1x_syncpt_id(syncpt);
524
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100525unlock:
526 mutex_unlock(&fpriv->lock);
527 return err;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200528}
529
530static int tegra_submit(struct drm_device *drm, void *data,
531 struct drm_file *file)
532{
Thierry Reding08943e62013-09-26 16:08:18 +0200533 struct tegra_drm_file *fpriv = file->driver_priv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200534 struct drm_tegra_submit *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200535 struct tegra_drm_context *context;
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100536 int err;
Thierry Redingc88c3632013-09-26 16:08:22 +0200537
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100538 mutex_lock(&fpriv->lock);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200539
Dmitry Osipenko1066a892017-06-15 02:18:24 +0300540 context = idr_find(&fpriv->contexts, args->context);
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100541 if (!context) {
542 err = -ENODEV;
543 goto unlock;
544 }
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200545
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100546 err = context->client->ops->submit(context, args, drm, file);
547
548unlock:
549 mutex_unlock(&fpriv->lock);
550 return err;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200551}
Arto Merilainenc54a1692013-10-14 15:21:54 +0300552
553static int tegra_get_syncpt_base(struct drm_device *drm, void *data,
554 struct drm_file *file)
555{
556 struct tegra_drm_file *fpriv = file->driver_priv;
557 struct drm_tegra_get_syncpt_base *args = data;
558 struct tegra_drm_context *context;
559 struct host1x_syncpt_base *base;
560 struct host1x_syncpt *syncpt;
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100561 int err = 0;
Arto Merilainenc54a1692013-10-14 15:21:54 +0300562
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100563 mutex_lock(&fpriv->lock);
Arto Merilainenc54a1692013-10-14 15:21:54 +0300564
Dmitry Osipenko1066a892017-06-15 02:18:24 +0300565 context = idr_find(&fpriv->contexts, args->context);
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100566 if (!context) {
567 err = -ENODEV;
568 goto unlock;
569 }
Arto Merilainenc54a1692013-10-14 15:21:54 +0300570
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100571 if (args->syncpt >= context->client->base.num_syncpts) {
572 err = -EINVAL;
573 goto unlock;
574 }
Arto Merilainenc54a1692013-10-14 15:21:54 +0300575
576 syncpt = context->client->base.syncpts[args->syncpt];
577
578 base = host1x_syncpt_get_base(syncpt);
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100579 if (!base) {
580 err = -ENXIO;
581 goto unlock;
582 }
Arto Merilainenc54a1692013-10-14 15:21:54 +0300583
584 args->id = host1x_syncpt_base_id(base);
585
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100586unlock:
587 mutex_unlock(&fpriv->lock);
588 return err;
Arto Merilainenc54a1692013-10-14 15:21:54 +0300589}
Thierry Reding7678d712014-06-03 14:56:57 +0200590
591static int tegra_gem_set_tiling(struct drm_device *drm, void *data,
592 struct drm_file *file)
593{
594 struct drm_tegra_gem_set_tiling *args = data;
595 enum tegra_bo_tiling_mode mode;
596 struct drm_gem_object *gem;
597 unsigned long value = 0;
598 struct tegra_bo *bo;
599
600 switch (args->mode) {
601 case DRM_TEGRA_GEM_TILING_MODE_PITCH:
602 mode = TEGRA_BO_TILING_MODE_PITCH;
603
604 if (args->value != 0)
605 return -EINVAL;
606
607 break;
608
609 case DRM_TEGRA_GEM_TILING_MODE_TILED:
610 mode = TEGRA_BO_TILING_MODE_TILED;
611
612 if (args->value != 0)
613 return -EINVAL;
614
615 break;
616
617 case DRM_TEGRA_GEM_TILING_MODE_BLOCK:
618 mode = TEGRA_BO_TILING_MODE_BLOCK;
619
620 if (args->value > 5)
621 return -EINVAL;
622
623 value = args->value;
624 break;
625
626 default:
627 return -EINVAL;
628 }
629
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100630 gem = drm_gem_object_lookup(file, args->handle);
Thierry Reding7678d712014-06-03 14:56:57 +0200631 if (!gem)
632 return -ENOENT;
633
634 bo = to_tegra_bo(gem);
635
636 bo->tiling.mode = mode;
637 bo->tiling.value = value;
638
Cihangir Akturk7664b2f2017-08-11 15:33:07 +0300639 drm_gem_object_put_unlocked(gem);
Thierry Reding7678d712014-06-03 14:56:57 +0200640
641 return 0;
642}
643
644static int tegra_gem_get_tiling(struct drm_device *drm, void *data,
645 struct drm_file *file)
646{
647 struct drm_tegra_gem_get_tiling *args = data;
648 struct drm_gem_object *gem;
649 struct tegra_bo *bo;
650 int err = 0;
651
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100652 gem = drm_gem_object_lookup(file, args->handle);
Thierry Reding7678d712014-06-03 14:56:57 +0200653 if (!gem)
654 return -ENOENT;
655
656 bo = to_tegra_bo(gem);
657
658 switch (bo->tiling.mode) {
659 case TEGRA_BO_TILING_MODE_PITCH:
660 args->mode = DRM_TEGRA_GEM_TILING_MODE_PITCH;
661 args->value = 0;
662 break;
663
664 case TEGRA_BO_TILING_MODE_TILED:
665 args->mode = DRM_TEGRA_GEM_TILING_MODE_TILED;
666 args->value = 0;
667 break;
668
669 case TEGRA_BO_TILING_MODE_BLOCK:
670 args->mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
671 args->value = bo->tiling.value;
672 break;
673
674 default:
675 err = -EINVAL;
676 break;
677 }
678
Cihangir Akturk7664b2f2017-08-11 15:33:07 +0300679 drm_gem_object_put_unlocked(gem);
Thierry Reding7678d712014-06-03 14:56:57 +0200680
681 return err;
682}
Thierry Reding7b129082014-06-10 12:04:03 +0200683
684static int tegra_gem_set_flags(struct drm_device *drm, void *data,
685 struct drm_file *file)
686{
687 struct drm_tegra_gem_set_flags *args = data;
688 struct drm_gem_object *gem;
689 struct tegra_bo *bo;
690
691 if (args->flags & ~DRM_TEGRA_GEM_FLAGS)
692 return -EINVAL;
693
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100694 gem = drm_gem_object_lookup(file, args->handle);
Thierry Reding7b129082014-06-10 12:04:03 +0200695 if (!gem)
696 return -ENOENT;
697
698 bo = to_tegra_bo(gem);
699 bo->flags = 0;
700
701 if (args->flags & DRM_TEGRA_GEM_BOTTOM_UP)
702 bo->flags |= TEGRA_BO_BOTTOM_UP;
703
Cihangir Akturk7664b2f2017-08-11 15:33:07 +0300704 drm_gem_object_put_unlocked(gem);
Thierry Reding7b129082014-06-10 12:04:03 +0200705
706 return 0;
707}
708
709static int tegra_gem_get_flags(struct drm_device *drm, void *data,
710 struct drm_file *file)
711{
712 struct drm_tegra_gem_get_flags *args = data;
713 struct drm_gem_object *gem;
714 struct tegra_bo *bo;
715
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100716 gem = drm_gem_object_lookup(file, args->handle);
Thierry Reding7b129082014-06-10 12:04:03 +0200717 if (!gem)
718 return -ENOENT;
719
720 bo = to_tegra_bo(gem);
721 args->flags = 0;
722
723 if (bo->flags & TEGRA_BO_BOTTOM_UP)
724 args->flags |= DRM_TEGRA_GEM_BOTTOM_UP;
725
Cihangir Akturk7664b2f2017-08-11 15:33:07 +0300726 drm_gem_object_put_unlocked(gem);
Thierry Reding7b129082014-06-10 12:04:03 +0200727
728 return 0;
729}
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200730#endif
731
Rob Clarkbaa70942013-08-02 13:27:49 -0400732static const struct drm_ioctl_desc tegra_drm_ioctls[] = {
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200733#ifdef CONFIG_DRM_TEGRA_STAGING
Thierry Reding6c68b712017-08-15 15:42:39 +0200734 DRM_IOCTL_DEF_DRV(TEGRA_GEM_CREATE, tegra_gem_create,
Emil Velikovd6891db2019-05-22 16:46:59 +0100735 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200736 DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_gem_mmap,
Emil Velikovd6891db2019-05-22 16:46:59 +0100737 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200738 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_READ, tegra_syncpt_read,
Emil Velikovd6891db2019-05-22 16:46:59 +0100739 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200740 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_INCR, tegra_syncpt_incr,
Emil Velikovd6891db2019-05-22 16:46:59 +0100741 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200742 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_WAIT, tegra_syncpt_wait,
Emil Velikovd6891db2019-05-22 16:46:59 +0100743 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200744 DRM_IOCTL_DEF_DRV(TEGRA_OPEN_CHANNEL, tegra_open_channel,
Emil Velikovd6891db2019-05-22 16:46:59 +0100745 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200746 DRM_IOCTL_DEF_DRV(TEGRA_CLOSE_CHANNEL, tegra_close_channel,
Emil Velikovd6891db2019-05-22 16:46:59 +0100747 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200748 DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT, tegra_get_syncpt,
Emil Velikovd6891db2019-05-22 16:46:59 +0100749 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200750 DRM_IOCTL_DEF_DRV(TEGRA_SUBMIT, tegra_submit,
Emil Velikovd6891db2019-05-22 16:46:59 +0100751 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200752 DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT_BASE, tegra_get_syncpt_base,
Emil Velikovd6891db2019-05-22 16:46:59 +0100753 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200754 DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_TILING, tegra_gem_set_tiling,
Emil Velikovd6891db2019-05-22 16:46:59 +0100755 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200756 DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_TILING, tegra_gem_get_tiling,
Emil Velikovd6891db2019-05-22 16:46:59 +0100757 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200758 DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_FLAGS, tegra_gem_set_flags,
Emil Velikovd6891db2019-05-22 16:46:59 +0100759 DRM_RENDER_ALLOW),
Thierry Reding6c68b712017-08-15 15:42:39 +0200760 DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_FLAGS, tegra_gem_get_flags,
Emil Velikovd6891db2019-05-22 16:46:59 +0100761 DRM_RENDER_ALLOW),
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200762#endif
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000763};
764
765static const struct file_operations tegra_drm_fops = {
766 .owner = THIS_MODULE,
767 .open = drm_open,
768 .release = drm_release,
769 .unlocked_ioctl = drm_ioctl,
Arto Merilainende2ba662013-03-22 16:34:08 +0200770 .mmap = tegra_drm_mmap,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000771 .poll = drm_poll,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000772 .read = drm_read,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000773 .compat_ioctl = drm_compat_ioctl,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000774 .llseek = noop_llseek,
775};
776
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100777static int tegra_drm_context_cleanup(int id, void *p, void *data)
778{
779 struct tegra_drm_context *context = p;
780
781 tegra_drm_context_free(context);
782
783 return 0;
784}
785
Daniel Vetterbda0ecc2017-05-08 10:26:31 +0200786static void tegra_drm_postclose(struct drm_device *drm, struct drm_file *file)
Thierry Reding3c03c462012-11-28 12:00:18 +0100787{
Thierry Reding08943e62013-09-26 16:08:18 +0200788 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Reding3c03c462012-11-28 12:00:18 +0100789
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100790 mutex_lock(&fpriv->lock);
791 idr_for_each(&fpriv->contexts, tegra_drm_context_cleanup, NULL);
792 mutex_unlock(&fpriv->lock);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200793
Thierry Redingbdd2f9c2017-03-09 20:04:55 +0100794 idr_destroy(&fpriv->contexts);
795 mutex_destroy(&fpriv->lock);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200796 kfree(fpriv);
Thierry Reding3c03c462012-11-28 12:00:18 +0100797}
798
Thierry Redinge450fcc2013-02-13 16:13:16 +0100799#ifdef CONFIG_DEBUG_FS
800static int tegra_debugfs_framebuffers(struct seq_file *s, void *data)
801{
802 struct drm_info_node *node = (struct drm_info_node *)s->private;
803 struct drm_device *drm = node->minor->dev;
804 struct drm_framebuffer *fb;
805
806 mutex_lock(&drm->mode_config.fb_lock);
807
808 list_for_each_entry(fb, &drm->mode_config.fb_list, head) {
809 seq_printf(s, "%3d: user size: %d x %d, depth %d, %d bpp, refcount %d\n",
Ville Syrjäläb00c6002016-12-14 23:31:35 +0200810 fb->base.id, fb->width, fb->height,
811 fb->format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +0200812 fb->format->cpp[0] * 8,
Dave Airlie747a5982016-04-15 15:10:35 +1000813 drm_framebuffer_read_refcount(fb));
Thierry Redinge450fcc2013-02-13 16:13:16 +0100814 }
815
816 mutex_unlock(&drm->mode_config.fb_lock);
817
818 return 0;
819}
820
Thierry Reding28c23372015-01-23 09:16:03 +0100821static int tegra_debugfs_iova(struct seq_file *s, void *data)
822{
823 struct drm_info_node *node = (struct drm_info_node *)s->private;
824 struct drm_device *drm = node->minor->dev;
825 struct tegra_drm *tegra = drm->dev_private;
Daniel Vetterb5c37142016-12-29 12:09:24 +0100826 struct drm_printer p = drm_seq_file_printer(s);
Thierry Reding28c23372015-01-23 09:16:03 +0100827
Michał Mirosław68d890a2017-08-14 23:53:45 +0200828 if (tegra->domain) {
829 mutex_lock(&tegra->mm_lock);
830 drm_mm_print(&tegra->mm, &p);
831 mutex_unlock(&tegra->mm_lock);
832 }
Daniel Vetterb5c37142016-12-29 12:09:24 +0100833
834 return 0;
Thierry Reding28c23372015-01-23 09:16:03 +0100835}
836
Thierry Redinge450fcc2013-02-13 16:13:16 +0100837static struct drm_info_list tegra_debugfs_list[] = {
838 { "framebuffers", tegra_debugfs_framebuffers, 0 },
Thierry Reding28c23372015-01-23 09:16:03 +0100839 { "iova", tegra_debugfs_iova, 0 },
Thierry Redinge450fcc2013-02-13 16:13:16 +0100840};
841
842static int tegra_debugfs_init(struct drm_minor *minor)
843{
844 return drm_debugfs_create_files(tegra_debugfs_list,
845 ARRAY_SIZE(tegra_debugfs_list),
846 minor->debugfs_root, minor);
847}
Thierry Redinge450fcc2013-02-13 16:13:16 +0100848#endif
849
Thierry Reding9b57f5f2013-11-08 13:17:14 +0100850static struct drm_driver tegra_drm_driver = {
Daniel Vetter0424fda2019-06-17 17:39:24 +0200851 .driver_features = DRIVER_MODESET | DRIVER_GEM |
Thierry Reding6c68b712017-08-15 15:42:39 +0200852 DRIVER_ATOMIC | DRIVER_RENDER,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000853 .open = tegra_drm_open,
Daniel Vetterbda0ecc2017-05-08 10:26:31 +0200854 .postclose = tegra_drm_postclose,
Noralf Trønnesc94beda2017-12-05 19:25:04 +0100855 .lastclose = drm_fb_helper_lastclose,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000856
Thierry Redinge450fcc2013-02-13 16:13:16 +0100857#if defined(CONFIG_DEBUG_FS)
858 .debugfs_init = tegra_debugfs_init,
Thierry Redinge450fcc2013-02-13 16:13:16 +0100859#endif
860
Daniel Vetter1ddbdbd2016-04-26 19:30:00 +0200861 .gem_free_object_unlocked = tegra_bo_free_object,
Arto Merilainende2ba662013-03-22 16:34:08 +0200862 .gem_vm_ops = &tegra_bo_vm_ops,
Thierry Reding38003912013-12-12 10:00:43 +0100863
864 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
865 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
866 .gem_prime_export = tegra_gem_prime_export,
867 .gem_prime_import = tegra_gem_prime_import,
868
Arto Merilainende2ba662013-03-22 16:34:08 +0200869 .dumb_create = tegra_bo_dumb_create,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000870
871 .ioctls = tegra_drm_ioctls,
872 .num_ioctls = ARRAY_SIZE(tegra_drm_ioctls),
873 .fops = &tegra_drm_fops,
874
875 .name = DRIVER_NAME,
876 .desc = DRIVER_DESC,
877 .date = DRIVER_DATE,
878 .major = DRIVER_MAJOR,
879 .minor = DRIVER_MINOR,
880 .patchlevel = DRIVER_PATCHLEVEL,
881};
Thierry Reding776dc382013-10-14 14:43:22 +0200882
883int tegra_drm_register_client(struct tegra_drm *tegra,
884 struct tegra_drm_client *client)
885{
886 mutex_lock(&tegra->clients_lock);
887 list_add_tail(&client->list, &tegra->clients);
Thierry Reding8e5d19c2019-02-01 14:28:31 +0100888 client->drm = tegra;
Thierry Reding776dc382013-10-14 14:43:22 +0200889 mutex_unlock(&tegra->clients_lock);
890
891 return 0;
892}
893
894int tegra_drm_unregister_client(struct tegra_drm *tegra,
895 struct tegra_drm_client *client)
896{
897 mutex_lock(&tegra->clients_lock);
898 list_del_init(&client->list);
Thierry Reding8e5d19c2019-02-01 14:28:31 +0100899 client->drm = NULL;
Thierry Reding776dc382013-10-14 14:43:22 +0200900 mutex_unlock(&tegra->clients_lock);
901
902 return 0;
903}
904
Thierry Reding7edd7962019-10-28 13:37:08 +0100905int host1x_client_iommu_attach(struct host1x_client *client)
Thierry Reding0c407de2018-05-04 15:02:24 +0200906{
Thierry Redingfa6661b2019-10-28 13:37:18 +0100907 struct iommu_domain *domain = iommu_get_domain_for_dev(client->dev);
Thierry Reding0c407de2018-05-04 15:02:24 +0200908 struct drm_device *drm = dev_get_drvdata(client->parent);
909 struct tegra_drm *tegra = drm->dev_private;
910 struct iommu_group *group = NULL;
911 int err;
912
Thierry Redingfa6661b2019-10-28 13:37:18 +0100913 /*
914 * If the host1x client is already attached to an IOMMU domain that is
915 * not the shared IOMMU domain, don't try to attach it to a different
916 * domain. This allows using the IOMMU-backed DMA API.
917 */
918 if (domain && domain != tegra->domain)
919 return 0;
Thierry Reding7edd7962019-10-28 13:37:08 +0100920
Thierry Redingfa6661b2019-10-28 13:37:18 +0100921 if (tegra->domain) {
Thierry Reding0c407de2018-05-04 15:02:24 +0200922 group = iommu_group_get(client->dev);
Thierry Redinga8817482019-12-03 17:19:12 +0100923 if (!group)
Thierry Redingaacdf192019-02-08 14:35:13 +0100924 return -ENODEV;
Thierry Reding0c407de2018-05-04 15:02:24 +0200925
Thierry Reding7edd7962019-10-28 13:37:08 +0100926 if (domain != tegra->domain) {
Thierry Reding0c407de2018-05-04 15:02:24 +0200927 err = iommu_attach_group(tegra->domain, group);
928 if (err < 0) {
929 iommu_group_put(group);
Thierry Redingaacdf192019-02-08 14:35:13 +0100930 return err;
Thierry Reding0c407de2018-05-04 15:02:24 +0200931 }
Thierry Reding0c407de2018-05-04 15:02:24 +0200932 }
Thierry Redingfa6661b2019-10-28 13:37:18 +0100933
934 tegra->use_explicit_iommu = true;
Thierry Reding0c407de2018-05-04 15:02:24 +0200935 }
936
Thierry Redingaacdf192019-02-08 14:35:13 +0100937 client->group = group;
938
939 return 0;
Thierry Reding0c407de2018-05-04 15:02:24 +0200940}
941
Thierry Redingaacdf192019-02-08 14:35:13 +0100942void host1x_client_iommu_detach(struct host1x_client *client)
Thierry Reding0c407de2018-05-04 15:02:24 +0200943{
944 struct drm_device *drm = dev_get_drvdata(client->parent);
945 struct tegra_drm *tegra = drm->dev_private;
Thierry Reding7edd7962019-10-28 13:37:08 +0100946 struct iommu_domain *domain;
Thierry Reding0c407de2018-05-04 15:02:24 +0200947
Thierry Redingaacdf192019-02-08 14:35:13 +0100948 if (client->group) {
Thierry Reding7edd7962019-10-28 13:37:08 +0100949 /*
950 * Devices that are part of the same group may no longer be
951 * attached to a domain at this point because their group may
952 * have been detached by an earlier client.
953 */
954 domain = iommu_get_domain_for_dev(client->dev);
955 if (domain)
Thierry Redingaacdf192019-02-08 14:35:13 +0100956 iommu_detach_group(tegra->domain, client->group);
Thierry Reding0c407de2018-05-04 15:02:24 +0200957
Thierry Redingaacdf192019-02-08 14:35:13 +0100958 iommu_group_put(client->group);
Thierry Redingfa6661b2019-10-28 13:37:18 +0100959 client->group = NULL;
Thierry Reding0c407de2018-05-04 15:02:24 +0200960 }
961}
962
Thierry Reding67485fb2017-11-09 13:17:11 +0100963void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *dma)
Mikko Perttunenad926012016-12-14 13:16:11 +0200964{
965 struct iova *alloc;
966 void *virt;
967 gfp_t gfp;
968 int err;
969
970 if (tegra->domain)
971 size = iova_align(&tegra->carveout.domain, size);
972 else
973 size = PAGE_ALIGN(size);
974
975 gfp = GFP_KERNEL | __GFP_ZERO;
976 if (!tegra->domain) {
977 /*
978 * Many units only support 32-bit addresses, even on 64-bit
979 * SoCs. If there is no IOMMU to translate into a 32-bit IO
980 * virtual address space, force allocations to be in the
981 * lower 32-bit range.
982 */
983 gfp |= GFP_DMA;
984 }
985
986 virt = (void *)__get_free_pages(gfp, get_order(size));
987 if (!virt)
988 return ERR_PTR(-ENOMEM);
989
990 if (!tegra->domain) {
991 /*
992 * If IOMMU is disabled, devices address physical memory
993 * directly.
994 */
995 *dma = virt_to_phys(virt);
996 return virt;
997 }
998
999 alloc = alloc_iova(&tegra->carveout.domain,
1000 size >> tegra->carveout.shift,
1001 tegra->carveout.limit, true);
1002 if (!alloc) {
1003 err = -EBUSY;
1004 goto free_pages;
1005 }
1006
1007 *dma = iova_dma_addr(&tegra->carveout.domain, alloc);
1008 err = iommu_map(tegra->domain, *dma, virt_to_phys(virt),
1009 size, IOMMU_READ | IOMMU_WRITE);
1010 if (err < 0)
1011 goto free_iova;
1012
1013 return virt;
1014
1015free_iova:
1016 __free_iova(&tegra->carveout.domain, alloc);
1017free_pages:
1018 free_pages((unsigned long)virt, get_order(size));
1019
1020 return ERR_PTR(err);
1021}
1022
1023void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
1024 dma_addr_t dma)
1025{
1026 if (tegra->domain)
1027 size = iova_align(&tegra->carveout.domain, size);
1028 else
1029 size = PAGE_ALIGN(size);
1030
1031 if (tegra->domain) {
1032 iommu_unmap(tegra->domain, dma, size);
1033 free_iova(&tegra->carveout.domain,
1034 iova_pfn(&tegra->carveout.domain, dma));
1035 }
1036
1037 free_pages((unsigned long)virt, get_order(size));
1038}
1039
Thierry Reding9910f5c2014-05-22 09:57:15 +02001040static int host1x_drm_probe(struct host1x_device *dev)
Thierry Reding776dc382013-10-14 14:43:22 +02001041{
Thierry Reding9910f5c2014-05-22 09:57:15 +02001042 struct drm_driver *driver = &tegra_drm_driver;
Thierry Redingfa6661b2019-10-28 13:37:18 +01001043 struct iommu_domain *domain;
Thierry Redinga7303f72019-10-28 13:16:10 +01001044 struct tegra_drm *tegra;
Thierry Reding9910f5c2014-05-22 09:57:15 +02001045 struct drm_device *drm;
1046 int err;
1047
1048 drm = drm_dev_alloc(driver, &dev->dev);
Tom Gundersen0f288602016-09-21 16:59:19 +02001049 if (IS_ERR(drm))
1050 return PTR_ERR(drm);
Thierry Reding9910f5c2014-05-22 09:57:15 +02001051
Thierry Redinga7303f72019-10-28 13:16:10 +01001052 tegra = kzalloc(sizeof(*tegra), GFP_KERNEL);
1053 if (!tegra) {
1054 err = -ENOMEM;
Thomas Zimmermann9c942092018-09-26 13:56:40 +02001055 goto put;
Thierry Redinga7303f72019-10-28 13:16:10 +01001056 }
1057
Thierry Redingfa6661b2019-10-28 13:37:18 +01001058 /*
1059 * If the Tegra DRM clients are backed by an IOMMU, push buffers are
1060 * likely to be allocated beyond the 32-bit boundary if sufficient
1061 * system memory is available. This is problematic on earlier Tegra
1062 * generations where host1x supports a maximum of 32 address bits in
1063 * the GATHER opcode. In this case, unless host1x is behind an IOMMU
1064 * as well it won't be able to process buffers allocated beyond the
1065 * 32-bit boundary.
1066 *
1067 * The DMA API will use bounce buffers in this case, so that could
1068 * perhaps still be made to work, even if less efficient, but there
1069 * is another catch: in order to perform cache maintenance on pages
1070 * allocated for discontiguous buffers we need to map and unmap the
1071 * SG table representing these buffers. This is fine for something
1072 * small like a push buffer, but it exhausts the bounce buffer pool
1073 * (typically on the order of a few MiB) for framebuffers (many MiB
1074 * for any modern resolution).
1075 *
1076 * Work around this by making sure that Tegra DRM clients only use
1077 * an IOMMU if the parent host1x also uses an IOMMU.
1078 *
1079 * Note that there's still a small gap here that we don't cover: if
1080 * the DMA API is backed by an IOMMU there's no way to control which
1081 * device is attached to an IOMMU and which isn't, except via wiring
1082 * up the device tree appropriately. This is considered an problem
1083 * of integration, so care must be taken for the DT to be consistent.
1084 */
1085 domain = iommu_get_domain_for_dev(drm->dev->parent);
1086
1087 if (domain && iommu_present(&platform_bus_type)) {
Thierry Redinga7303f72019-10-28 13:16:10 +01001088 tegra->domain = iommu_domain_alloc(&platform_bus_type);
1089 if (!tegra->domain) {
1090 err = -ENOMEM;
1091 goto free;
1092 }
1093
1094 err = iova_cache_get();
1095 if (err < 0)
1096 goto domain;
1097 }
1098
1099 mutex_init(&tegra->clients_lock);
1100 INIT_LIST_HEAD(&tegra->clients);
1101
1102 dev_set_drvdata(&dev->dev, drm);
1103 drm->dev_private = tegra;
1104 tegra->drm = drm;
1105
1106 drm_mode_config_init(drm);
1107
1108 drm->mode_config.min_width = 0;
1109 drm->mode_config.min_height = 0;
1110
1111 drm->mode_config.max_width = 4096;
1112 drm->mode_config.max_height = 4096;
1113
1114 drm->mode_config.allow_fb_modifiers = true;
1115
1116 drm->mode_config.normalize_zpos = true;
1117
1118 drm->mode_config.funcs = &tegra_drm_mode_config_funcs;
1119 drm->mode_config.helper_private = &tegra_drm_mode_config_helpers;
1120
1121 err = tegra_drm_fb_prepare(drm);
1122 if (err < 0)
1123 goto config;
1124
1125 drm_kms_helper_poll_init(drm);
1126
1127 err = host1x_device_init(dev);
1128 if (err < 0)
1129 goto fbdev;
1130
Thierry Redingfa6661b2019-10-28 13:37:18 +01001131 if (tegra->use_explicit_iommu) {
Thierry Redinga7303f72019-10-28 13:16:10 +01001132 u64 carveout_start, carveout_end, gem_start, gem_end;
1133 u64 dma_mask = dma_get_mask(&dev->dev);
1134 dma_addr_t start, end;
1135 unsigned long order;
1136
1137 start = tegra->domain->geometry.aperture_start & dma_mask;
1138 end = tegra->domain->geometry.aperture_end & dma_mask;
1139
1140 gem_start = start;
1141 gem_end = end - CARVEOUT_SZ;
1142 carveout_start = gem_end + 1;
1143 carveout_end = end;
1144
1145 order = __ffs(tegra->domain->pgsize_bitmap);
1146 init_iova_domain(&tegra->carveout.domain, 1UL << order,
1147 carveout_start >> order);
1148
1149 tegra->carveout.shift = iova_shift(&tegra->carveout.domain);
1150 tegra->carveout.limit = carveout_end >> tegra->carveout.shift;
1151
1152 drm_mm_init(&tegra->mm, gem_start, gem_end - gem_start + 1);
1153 mutex_init(&tegra->mm_lock);
1154
1155 DRM_DEBUG_DRIVER("IOMMU apertures:\n");
1156 DRM_DEBUG_DRIVER(" GEM: %#llx-%#llx\n", gem_start, gem_end);
1157 DRM_DEBUG_DRIVER(" Carveout: %#llx-%#llx\n", carveout_start,
1158 carveout_end);
Thierry Redingfa6661b2019-10-28 13:37:18 +01001159 } else if (tegra->domain) {
1160 iommu_domain_free(tegra->domain);
1161 tegra->domain = NULL;
1162 iova_cache_put();
Thierry Redinga7303f72019-10-28 13:16:10 +01001163 }
1164
1165 if (tegra->hub) {
1166 err = tegra_display_hub_prepare(tegra->hub);
1167 if (err < 0)
1168 goto device;
1169 }
1170
1171 /*
1172 * We don't use the drm_irq_install() helpers provided by the DRM
1173 * core, so we need to set this manually in order to allow the
1174 * DRM_IOCTL_WAIT_VBLANK to operate correctly.
1175 */
1176 drm->irq_enabled = true;
1177
1178 /* syncpoints are used for full 32-bit hardware VBLANK counters */
1179 drm->max_vblank_count = 0xffffffff;
1180
1181 err = drm_vblank_init(drm, drm->mode_config.num_crtc);
1182 if (err < 0)
1183 goto hub;
1184
1185 drm_mode_config_reset(drm);
1186
1187 err = drm_fb_helper_remove_conflicting_framebuffers(NULL, "tegradrmfb",
1188 false);
1189 if (err < 0)
1190 goto hub;
1191
1192 err = tegra_drm_fb_init(drm);
1193 if (err < 0)
1194 goto hub;
Michał Mirosław6e4228f2018-09-01 16:08:51 +02001195
Thierry Reding9910f5c2014-05-22 09:57:15 +02001196 err = drm_dev_register(drm, 0);
1197 if (err < 0)
Thierry Redinga7303f72019-10-28 13:16:10 +01001198 goto fb;
Thierry Reding9910f5c2014-05-22 09:57:15 +02001199
Thierry Reding9910f5c2014-05-22 09:57:15 +02001200 return 0;
1201
Thierry Redinga7303f72019-10-28 13:16:10 +01001202fb:
1203 tegra_drm_fb_exit(drm);
1204hub:
1205 if (tegra->hub)
1206 tegra_display_hub_cleanup(tegra->hub);
1207device:
1208 if (tegra->domain) {
1209 mutex_destroy(&tegra->mm_lock);
1210 drm_mm_takedown(&tegra->mm);
1211 put_iova_domain(&tegra->carveout.domain);
1212 iova_cache_put();
1213 }
1214
1215 host1x_device_exit(dev);
1216fbdev:
1217 drm_kms_helper_poll_fini(drm);
1218 tegra_drm_fb_free(drm);
1219config:
1220 drm_mode_config_cleanup(drm);
1221domain:
1222 if (tegra->domain)
1223 iommu_domain_free(tegra->domain);
1224free:
1225 kfree(tegra);
Thomas Zimmermann9c942092018-09-26 13:56:40 +02001226put:
1227 drm_dev_put(drm);
Thierry Reding9910f5c2014-05-22 09:57:15 +02001228 return err;
Thierry Reding776dc382013-10-14 14:43:22 +02001229}
1230
Thierry Reding9910f5c2014-05-22 09:57:15 +02001231static int host1x_drm_remove(struct host1x_device *dev)
Thierry Reding776dc382013-10-14 14:43:22 +02001232{
Thierry Reding9910f5c2014-05-22 09:57:15 +02001233 struct drm_device *drm = dev_get_drvdata(&dev->dev);
Thierry Redinga7303f72019-10-28 13:16:10 +01001234 struct tegra_drm *tegra = drm->dev_private;
1235 int err;
Thierry Reding9910f5c2014-05-22 09:57:15 +02001236
1237 drm_dev_unregister(drm);
Thierry Redinga7303f72019-10-28 13:16:10 +01001238
1239 drm_kms_helper_poll_fini(drm);
1240 tegra_drm_fb_exit(drm);
1241 drm_atomic_helper_shutdown(drm);
1242 drm_mode_config_cleanup(drm);
1243
Thierry Redingd66dfcf82019-12-03 17:19:14 +01001244 if (tegra->hub)
1245 tegra_display_hub_cleanup(tegra->hub);
1246
Thierry Redinga7303f72019-10-28 13:16:10 +01001247 err = host1x_device_exit(dev);
1248 if (err < 0)
1249 dev_err(&dev->dev, "host1x device cleanup failed: %d\n", err);
1250
1251 if (tegra->domain) {
1252 mutex_destroy(&tegra->mm_lock);
1253 drm_mm_takedown(&tegra->mm);
1254 put_iova_domain(&tegra->carveout.domain);
1255 iova_cache_put();
1256 iommu_domain_free(tegra->domain);
1257 }
1258
1259 kfree(tegra);
Thomas Zimmermann9c942092018-09-26 13:56:40 +02001260 drm_dev_put(drm);
Thierry Reding776dc382013-10-14 14:43:22 +02001261
1262 return 0;
1263}
1264
Thierry Reding359ae682014-12-18 17:15:25 +01001265#ifdef CONFIG_PM_SLEEP
1266static int host1x_drm_suspend(struct device *dev)
1267{
1268 struct drm_device *drm = dev_get_drvdata(dev);
1269
Souptick Joarder53f1e062018-08-01 01:37:05 +05301270 return drm_mode_config_helper_suspend(drm);
Thierry Reding359ae682014-12-18 17:15:25 +01001271}
1272
1273static int host1x_drm_resume(struct device *dev)
1274{
1275 struct drm_device *drm = dev_get_drvdata(dev);
1276
Souptick Joarder53f1e062018-08-01 01:37:05 +05301277 return drm_mode_config_helper_resume(drm);
Thierry Reding359ae682014-12-18 17:15:25 +01001278}
1279#endif
1280
Thierry Redinga13f1dc2015-08-11 13:22:44 +02001281static SIMPLE_DEV_PM_OPS(host1x_drm_pm_ops, host1x_drm_suspend,
1282 host1x_drm_resume);
Thierry Reding359ae682014-12-18 17:15:25 +01001283
Thierry Reding776dc382013-10-14 14:43:22 +02001284static const struct of_device_id host1x_drm_subdevs[] = {
1285 { .compatible = "nvidia,tegra20-dc", },
1286 { .compatible = "nvidia,tegra20-hdmi", },
1287 { .compatible = "nvidia,tegra20-gr2d", },
Thierry Reding5f60ed02013-02-28 08:08:01 +01001288 { .compatible = "nvidia,tegra20-gr3d", },
Thierry Reding776dc382013-10-14 14:43:22 +02001289 { .compatible = "nvidia,tegra30-dc", },
1290 { .compatible = "nvidia,tegra30-hdmi", },
1291 { .compatible = "nvidia,tegra30-gr2d", },
Thierry Reding5f60ed02013-02-28 08:08:01 +01001292 { .compatible = "nvidia,tegra30-gr3d", },
Thierry Redingdec72732013-09-03 08:45:46 +02001293 { .compatible = "nvidia,tegra114-dsi", },
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001294 { .compatible = "nvidia,tegra114-hdmi", },
Thierry Reding5f60ed02013-02-28 08:08:01 +01001295 { .compatible = "nvidia,tegra114-gr3d", },
Thierry Reding8620fc62013-12-12 11:03:59 +01001296 { .compatible = "nvidia,tegra124-dc", },
Thierry Reding6b6b6042013-11-15 16:06:05 +01001297 { .compatible = "nvidia,tegra124-sor", },
Thierry Redingfb7be702013-11-15 16:07:32 +01001298 { .compatible = "nvidia,tegra124-hdmi", },
Thierry Reding7d338582015-04-10 11:35:21 +02001299 { .compatible = "nvidia,tegra124-dsi", },
Arto Merilainen0ae797a2016-12-14 13:16:13 +02001300 { .compatible = "nvidia,tegra124-vic", },
Thierry Redingc06c7932015-04-10 11:35:21 +02001301 { .compatible = "nvidia,tegra132-dsi", },
Thierry Reding5b4f5162015-03-27 10:31:58 +01001302 { .compatible = "nvidia,tegra210-dc", },
Thierry Redingddfb4062015-04-08 16:56:22 +02001303 { .compatible = "nvidia,tegra210-dsi", },
Thierry Reding3309ac82015-07-30 10:32:46 +02001304 { .compatible = "nvidia,tegra210-sor", },
Thierry Reding459cc2c2015-07-30 10:34:24 +02001305 { .compatible = "nvidia,tegra210-sor1", },
Arto Merilainen0ae797a2016-12-14 13:16:13 +02001306 { .compatible = "nvidia,tegra210-vic", },
Thierry Redingc4755fb2017-11-13 11:08:13 +01001307 { .compatible = "nvidia,tegra186-display", },
Thierry Reding47307952017-08-30 17:42:54 +02001308 { .compatible = "nvidia,tegra186-dc", },
Thierry Redingc57997b2017-10-12 19:12:57 +02001309 { .compatible = "nvidia,tegra186-sor", },
1310 { .compatible = "nvidia,tegra186-sor1", },
Mikko Perttunen6e44b9a2017-09-05 11:43:06 +03001311 { .compatible = "nvidia,tegra186-vic", },
Thierry Reding5725daa2018-09-21 12:27:43 +02001312 { .compatible = "nvidia,tegra194-display", },
Thierry Reding47443192018-09-21 12:27:44 +02001313 { .compatible = "nvidia,tegra194-dc", },
Thierry Reding9b6c14b2018-09-21 12:27:46 +02001314 { .compatible = "nvidia,tegra194-sor", },
Thierry Redingd6b9bc02018-10-26 10:59:38 +02001315 { .compatible = "nvidia,tegra194-vic", },
Thierry Reding776dc382013-10-14 14:43:22 +02001316 { /* sentinel */ }
1317};
1318
1319static struct host1x_driver host1x_drm_driver = {
Thierry Redingf4c5cf82014-12-18 15:29:14 +01001320 .driver = {
1321 .name = "drm",
Thierry Reding359ae682014-12-18 17:15:25 +01001322 .pm = &host1x_drm_pm_ops,
Thierry Redingf4c5cf82014-12-18 15:29:14 +01001323 },
Thierry Reding776dc382013-10-14 14:43:22 +02001324 .probe = host1x_drm_probe,
1325 .remove = host1x_drm_remove,
1326 .subdevs = host1x_drm_subdevs,
1327};
1328
Thierry Reding473112e2015-09-10 16:07:14 +02001329static struct platform_driver * const drivers[] = {
Thierry Redingc4755fb2017-11-13 11:08:13 +01001330 &tegra_display_hub_driver,
Thierry Reding473112e2015-09-10 16:07:14 +02001331 &tegra_dc_driver,
1332 &tegra_hdmi_driver,
1333 &tegra_dsi_driver,
1334 &tegra_dpaux_driver,
1335 &tegra_sor_driver,
1336 &tegra_gr2d_driver,
1337 &tegra_gr3d_driver,
Arto Merilainen0ae797a2016-12-14 13:16:13 +02001338 &tegra_vic_driver,
Thierry Reding473112e2015-09-10 16:07:14 +02001339};
1340
Thierry Reding776dc382013-10-14 14:43:22 +02001341static int __init host1x_drm_init(void)
1342{
1343 int err;
1344
1345 err = host1x_driver_register(&host1x_drm_driver);
1346 if (err < 0)
1347 return err;
1348
Thierry Reding473112e2015-09-10 16:07:14 +02001349 err = platform_register_drivers(drivers, ARRAY_SIZE(drivers));
Thierry Reding776dc382013-10-14 14:43:22 +02001350 if (err < 0)
1351 goto unregister_host1x;
1352
Thierry Reding776dc382013-10-14 14:43:22 +02001353 return 0;
1354
Thierry Reding776dc382013-10-14 14:43:22 +02001355unregister_host1x:
1356 host1x_driver_unregister(&host1x_drm_driver);
1357 return err;
1358}
1359module_init(host1x_drm_init);
1360
1361static void __exit host1x_drm_exit(void)
1362{
Thierry Reding473112e2015-09-10 16:07:14 +02001363 platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
Thierry Reding776dc382013-10-14 14:43:22 +02001364 host1x_driver_unregister(&host1x_drm_driver);
1365}
1366module_exit(host1x_drm_exit);
1367
1368MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
1369MODULE_DESCRIPTION("NVIDIA Tegra DRM driver");
1370MODULE_LICENSE("GPL v2");