Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Avionic Design GmbH |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 4 | * Copyright (C) 2012-2016 NVIDIA CORPORATION. All rights reserved. |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 7 | #include <linux/bitops.h> |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 8 | #include <linux/host1x.h> |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 9 | #include <linux/idr.h> |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 10 | #include <linux/iommu.h> |
Sam Ravnborg | eb1df69 | 2019-08-04 11:41:30 +0200 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/platform_device.h> |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 13 | |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 14 | #include <drm/drm_atomic.h> |
Thierry Reding | 0786696 | 2014-11-24 17:08:06 +0100 | [diff] [blame] | 15 | #include <drm/drm_atomic_helper.h> |
Sam Ravnborg | eb1df69 | 2019-08-04 11:41:30 +0200 | [diff] [blame] | 16 | #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 Reding | 0786696 | 2014-11-24 17:08:06 +0100 | [diff] [blame] | 22 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 23 | #include "drm.h" |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 24 | #include "gem.h" |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 25 | |
| 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 Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 33 | #define CARVEOUT_SZ SZ_64M |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 34 | #define CDMA_GATHER_FETCHES_MAX_NB 16383 |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 35 | |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 36 | struct tegra_drm_file { |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 37 | struct idr contexts; |
| 38 | struct mutex lock; |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
Thierry Reding | ab7d3f5 | 2017-12-14 13:46:20 +0100 | [diff] [blame] | 41 | static int tegra_atomic_check(struct drm_device *drm, |
| 42 | struct drm_atomic_state *state) |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 43 | { |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 44 | int err; |
| 45 | |
Peter Ujfalusi | a18301b | 2018-03-21 12:20:26 +0200 | [diff] [blame] | 46 | err = drm_atomic_helper_check(drm, state); |
Thierry Reding | ab7d3f5 | 2017-12-14 13:46:20 +0100 | [diff] [blame] | 47 | if (err < 0) |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 48 | return err; |
| 49 | |
Peter Ujfalusi | a18301b | 2018-03-21 12:20:26 +0200 | [diff] [blame] | 50 | return tegra_display_hub_atomic_check(drm, state); |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Thierry Reding | 31b02ca | 2017-10-12 17:40:46 +0200 | [diff] [blame] | 53 | static const struct drm_mode_config_funcs tegra_drm_mode_config_funcs = { |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 54 | .fb_create = tegra_fb_create, |
Archit Taneja | b110ef3 | 2015-10-27 13:40:59 +0530 | [diff] [blame] | 55 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Noralf Trønnes | c94beda | 2017-12-05 19:25:04 +0100 | [diff] [blame] | 56 | .output_poll_changed = drm_fb_helper_output_poll_changed, |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 57 | #endif |
Thierry Reding | ab7d3f5 | 2017-12-14 13:46:20 +0100 | [diff] [blame] | 58 | .atomic_check = tegra_atomic_check, |
Thierry Reding | 31b02ca | 2017-10-12 17:40:46 +0200 | [diff] [blame] | 59 | .atomic_commit = drm_atomic_helper_commit, |
| 60 | }; |
| 61 | |
Thierry Reding | c4755fb | 2017-11-13 11:08:13 +0100 | [diff] [blame] | 62 | static 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 Reding | 31b02ca | 2017-10-12 17:40:46 +0200 | [diff] [blame] | 80 | static const struct drm_mode_config_helper_funcs |
| 81 | tegra_drm_mode_config_helpers = { |
Thierry Reding | c4755fb | 2017-11-13 11:08:13 +0100 | [diff] [blame] | 82 | .atomic_commit_tail = tegra_atomic_commit_tail, |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 83 | }; |
| 84 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 85 | static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) |
| 86 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 87 | struct tegra_drm_file *fpriv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 88 | |
| 89 | fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); |
| 90 | if (!fpriv) |
| 91 | return -ENOMEM; |
| 92 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 93 | idr_init(&fpriv->contexts); |
| 94 | mutex_init(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 95 | filp->driver_priv = fpriv; |
| 96 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 100 | static void tegra_drm_context_free(struct tegra_drm_context *context) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 101 | { |
| 102 | context->client->ops->close_channel(context); |
| 103 | kfree(context); |
| 104 | } |
| 105 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 106 | static struct host1x_bo * |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 107 | host1x_bo_lookup(struct drm_file *file, u32 handle) |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 108 | { |
| 109 | struct drm_gem_object *gem; |
| 110 | struct tegra_bo *bo; |
| 111 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 112 | gem = drm_gem_object_lookup(file, handle); |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 113 | if (!gem) |
| 114 | return NULL; |
| 115 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 116 | bo = to_tegra_bo(gem); |
| 117 | return &bo->base; |
| 118 | } |
| 119 | |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 120 | static 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 Ung | 31f40f8 | 2015-01-20 18:37:35 -0800 | [diff] [blame] | 140 | err = get_user(dest->target.offset, &src->target.offset); |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 141 | if (err < 0) |
| 142 | return err; |
| 143 | |
| 144 | err = get_user(dest->shift, &src->shift); |
| 145 | if (err < 0) |
| 146 | return err; |
| 147 | |
Thierry Reding | ab4f81b | 2019-10-28 13:37:11 +0100 | [diff] [blame] | 148 | dest->flags = HOST1X_RELOC_READ | HOST1X_RELOC_WRITE; |
| 149 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 150 | dest->cmdbuf.bo = host1x_bo_lookup(file, cmdbuf); |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 151 | if (!dest->cmdbuf.bo) |
| 152 | return -ENOENT; |
| 153 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 154 | dest->target.bo = host1x_bo_lookup(file, target); |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 155 | if (!dest->target.bo) |
| 156 | return -ENOENT; |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 161 | int 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 Reding | bf3d41c | 2018-05-16 14:12:33 +0200 | [diff] [blame] | 165 | struct host1x_client *client = &context->client->base; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 166 | unsigned int num_cmdbufs = args->num_cmdbufs; |
| 167 | unsigned int num_relocs = args->num_relocs; |
Mikko Perttunen | a176c67 | 2017-09-28 15:50:44 +0300 | [diff] [blame] | 168 | struct drm_tegra_cmdbuf __user *user_cmdbufs; |
| 169 | struct drm_tegra_reloc __user *user_relocs; |
Mikko Perttunen | a176c67 | 2017-09-28 15:50:44 +0300 | [diff] [blame] | 170 | struct drm_tegra_syncpt __user *user_syncpt; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 171 | struct drm_tegra_syncpt syncpt; |
Dmitry Osipenko | e0b2ce0 | 2017-06-15 02:18:28 +0300 | [diff] [blame] | 172 | struct host1x *host1x = dev_get_drvdata(drm->dev->parent); |
Dmitry Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 173 | struct drm_gem_object **refs; |
Dmitry Osipenko | e0b2ce0 | 2017-06-15 02:18:28 +0300 | [diff] [blame] | 174 | struct host1x_syncpt *sp; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 175 | struct host1x_job *job; |
Dmitry Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 176 | unsigned int num_refs; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 177 | int err; |
| 178 | |
Mikko Perttunen | a176c67 | 2017-09-28 15:50:44 +0300 | [diff] [blame] | 179 | user_cmdbufs = u64_to_user_ptr(args->cmdbufs); |
| 180 | user_relocs = u64_to_user_ptr(args->relocs); |
Mikko Perttunen | a176c67 | 2017-09-28 15:50:44 +0300 | [diff] [blame] | 181 | user_syncpt = u64_to_user_ptr(args->syncpts); |
| 182 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 183 | /* We don't yet support other than one syncpt_incr struct per submit */ |
| 184 | if (args->num_syncpts != 1) |
| 185 | return -EINVAL; |
| 186 | |
Dmitry Osipenko | d0fbbdf | 2017-06-15 02:18:27 +0300 | [diff] [blame] | 187 | /* We don't yet support waitchks */ |
| 188 | if (args->num_waitchks != 0) |
| 189 | return -EINVAL; |
| 190 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 191 | job = host1x_job_alloc(context->channel, args->num_cmdbufs, |
Thierry Reding | 24c94e1 | 2018-05-05 08:45:47 +0200 | [diff] [blame] | 192 | args->num_relocs); |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 193 | if (!job) |
| 194 | return -ENOMEM; |
| 195 | |
| 196 | job->num_relocs = args->num_relocs; |
Thierry Reding | bf3d41c | 2018-05-16 14:12:33 +0200 | [diff] [blame] | 197 | job->client = client; |
| 198 | job->class = client->class; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 199 | job->serialize = true; |
| 200 | |
Dmitry Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 201 | /* |
| 202 | * Track referenced BOs so that they can be unreferenced after the |
| 203 | * submission is complete. |
| 204 | */ |
Thierry Reding | 24c94e1 | 2018-05-05 08:45:47 +0200 | [diff] [blame] | 205 | num_refs = num_cmdbufs + num_relocs * 2; |
Dmitry Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 206 | |
| 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 Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 216 | while (num_cmdbufs) { |
| 217 | struct drm_tegra_cmdbuf cmdbuf; |
| 218 | struct host1x_bo *bo; |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 219 | struct tegra_bo *obj; |
| 220 | u64 offset; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 221 | |
Mikko Perttunen | a176c67 | 2017-09-28 15:50:44 +0300 | [diff] [blame] | 222 | if (copy_from_user(&cmdbuf, user_cmdbufs, sizeof(cmdbuf))) { |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 223 | err = -EFAULT; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 224 | goto fail; |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 225 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 226 | |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 227 | /* |
| 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 Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 236 | bo = host1x_bo_lookup(file, cmdbuf.handle); |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 237 | if (!bo) { |
| 238 | err = -ENOENT; |
| 239 | goto fail; |
| 240 | } |
| 241 | |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 242 | offset = (u64)cmdbuf.offset + (u64)cmdbuf.words * sizeof(u32); |
| 243 | obj = host1x_to_tegra_bo(bo); |
Dmitry Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 244 | refs[num_refs++] = &obj->gem; |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 245 | |
| 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 Perttunen | 5265f03 | 2018-06-20 16:03:58 +0300 | [diff] [blame] | 251 | if (offset & 3 || offset > obj->gem.size) { |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 252 | err = -EINVAL; |
| 253 | goto fail; |
| 254 | } |
| 255 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 256 | host1x_job_add_gather(job, bo, cmdbuf.words, cmdbuf.offset); |
| 257 | num_cmdbufs--; |
Mikko Perttunen | a176c67 | 2017-09-28 15:50:44 +0300 | [diff] [blame] | 258 | user_cmdbufs++; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 261 | /* copy and resolve relocations from submit */ |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 262 | while (num_relocs--) { |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 263 | struct host1x_reloc *reloc; |
| 264 | struct tegra_bo *obj; |
| 265 | |
Thierry Reding | 06490bb | 2018-05-16 16:58:44 +0200 | [diff] [blame] | 266 | err = host1x_reloc_copy_from_user(&job->relocs[num_relocs], |
Mikko Perttunen | a176c67 | 2017-09-28 15:50:44 +0300 | [diff] [blame] | 267 | &user_relocs[num_relocs], drm, |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 268 | file); |
| 269 | if (err < 0) |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 270 | goto fail; |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 271 | |
Thierry Reding | 06490bb | 2018-05-16 16:58:44 +0200 | [diff] [blame] | 272 | reloc = &job->relocs[num_relocs]; |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 273 | obj = host1x_to_tegra_bo(reloc->cmdbuf.bo); |
Dmitry Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 274 | refs[num_refs++] = &obj->gem; |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 275 | |
| 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 Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 288 | refs[num_refs++] = &obj->gem; |
Dmitry Osipenko | 368f622 | 2017-06-15 02:18:26 +0300 | [diff] [blame] | 289 | |
| 290 | if (reloc->target.offset >= obj->gem.size) { |
| 291 | err = -EINVAL; |
| 292 | goto fail; |
| 293 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 294 | } |
| 295 | |
Mikko Perttunen | a176c67 | 2017-09-28 15:50:44 +0300 | [diff] [blame] | 296 | if (copy_from_user(&syncpt, user_syncpt, sizeof(syncpt))) { |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 297 | err = -EFAULT; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 298 | goto fail; |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 299 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 300 | |
Dmitry Osipenko | e0b2ce0 | 2017-06-15 02:18:28 +0300 | [diff] [blame] | 301 | /* 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 Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 308 | job->is_addr_reg = context->client->ops->is_addr_reg; |
Dmitry Osipenko | 0f563a4 | 2017-06-15 02:18:37 +0300 | [diff] [blame] | 309 | job->is_valid_class = context->client->ops->is_valid_class; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 310 | 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 Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 322 | if (err) { |
| 323 | host1x_job_unpin(job); |
| 324 | goto fail; |
| 325 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 326 | |
| 327 | args->fence = job->syncpt_end; |
| 328 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 329 | fail: |
Dmitry Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 330 | while (num_refs--) |
Emil Velikov | b8912e2 | 2020-05-15 10:51:11 +0100 | [diff] [blame] | 331 | drm_gem_object_put(refs[num_refs]); |
Dmitry Osipenko | ec73c4c | 2017-08-11 19:54:56 +0200 | [diff] [blame] | 332 | |
| 333 | kfree(refs); |
| 334 | |
| 335 | put: |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 336 | host1x_job_put(job); |
| 337 | return err; |
| 338 | } |
| 339 | |
| 340 | |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 341 | #ifdef CONFIG_DRM_TEGRA_STAGING |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 342 | static 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 Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 348 | bo = tegra_bo_create_with_handle(file, drm, args->size, args->flags, |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 349 | &args->handle); |
| 350 | if (IS_ERR(bo)) |
| 351 | return PTR_ERR(bo); |
| 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | static 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 Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 363 | gem = drm_gem_object_lookup(file, args->handle); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 364 | if (!gem) |
| 365 | return -EINVAL; |
| 366 | |
| 367 | bo = to_tegra_bo(gem); |
| 368 | |
David Herrmann | 2bc7b0c | 2013-08-13 14:19:58 +0200 | [diff] [blame] | 369 | args->offset = drm_vma_node_offset_addr(&bo->gem.vma_node); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 370 | |
Emil Velikov | b8912e2 | 2020-05-15 10:51:11 +0100 | [diff] [blame] | 371 | drm_gem_object_put(gem); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static int tegra_syncpt_read(struct drm_device *drm, void *data, |
| 377 | struct drm_file *file) |
| 378 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 379 | struct host1x *host = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 380 | struct drm_tegra_syncpt_read *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 381 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 382 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 383 | sp = host1x_syncpt_get(host, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 384 | if (!sp) |
| 385 | return -EINVAL; |
| 386 | |
| 387 | args->value = host1x_syncpt_read_min(sp); |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static int tegra_syncpt_incr(struct drm_device *drm, void *data, |
| 392 | struct drm_file *file) |
| 393 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 394 | struct host1x *host1x = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 395 | struct drm_tegra_syncpt_incr *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 396 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 397 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 398 | sp = host1x_syncpt_get(host1x, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 399 | if (!sp) |
| 400 | return -EINVAL; |
| 401 | |
Arto Merilainen | ebae30b | 2013-05-29 13:26:08 +0300 | [diff] [blame] | 402 | return host1x_syncpt_incr(sp); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static int tegra_syncpt_wait(struct drm_device *drm, void *data, |
| 406 | struct drm_file *file) |
| 407 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 408 | struct host1x *host1x = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 409 | struct drm_tegra_syncpt_wait *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 410 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 411 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 412 | sp = host1x_syncpt_get(host1x, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 413 | if (!sp) |
| 414 | return -EINVAL; |
| 415 | |
Dmitry Osipenko | 4c69ac12 | 2017-12-20 18:46:14 +0300 | [diff] [blame] | 416 | return host1x_syncpt_wait(sp, args->thresh, |
| 417 | msecs_to_jiffies(args->timeout), |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 418 | &args->value); |
| 419 | } |
| 420 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 421 | static 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 Osipenko | d6c153e | 2017-06-15 02:18:25 +0300 | [diff] [blame] | 431 | err = idr_alloc(&fpriv->contexts, context, 1, 0, GFP_KERNEL); |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 432 | 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 Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 443 | static int tegra_open_channel(struct drm_device *drm, void *data, |
| 444 | struct drm_file *file) |
| 445 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 446 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 447 | struct tegra_drm *tegra = drm->dev_private; |
| 448 | struct drm_tegra_open_channel *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 449 | struct tegra_drm_context *context; |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 450 | struct tegra_drm_client *client; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 451 | int err = -ENODEV; |
| 452 | |
| 453 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 454 | if (!context) |
| 455 | return -ENOMEM; |
| 456 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 457 | mutex_lock(&fpriv->lock); |
| 458 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 459 | list_for_each_entry(client, &tegra->clients, list) |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 460 | if (client->base.class == args->client) { |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 461 | err = tegra_client_open(fpriv, client, context); |
| 462 | if (err < 0) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 463 | break; |
| 464 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 465 | args->context = context->id; |
| 466 | break; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 467 | } |
| 468 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 469 | if (err < 0) |
| 470 | kfree(context); |
| 471 | |
| 472 | mutex_unlock(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 473 | return err; |
| 474 | } |
| 475 | |
| 476 | static int tegra_close_channel(struct drm_device *drm, void *data, |
| 477 | struct drm_file *file) |
| 478 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 479 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 480 | struct drm_tegra_close_channel *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 481 | struct tegra_drm_context *context; |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 482 | int err = 0; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 483 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 484 | mutex_lock(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 485 | |
Dmitry Osipenko | 1066a89 | 2017-06-15 02:18:24 +0300 | [diff] [blame] | 486 | context = idr_find(&fpriv->contexts, args->context); |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 487 | if (!context) { |
| 488 | err = -EINVAL; |
| 489 | goto unlock; |
| 490 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 491 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 492 | idr_remove(&fpriv->contexts, context->id); |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 493 | tegra_drm_context_free(context); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 494 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 495 | unlock: |
| 496 | mutex_unlock(&fpriv->lock); |
| 497 | return err; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static int tegra_get_syncpt(struct drm_device *drm, void *data, |
| 501 | struct drm_file *file) |
| 502 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 503 | struct tegra_drm_file *fpriv = file->driver_priv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 504 | struct drm_tegra_get_syncpt *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 505 | struct tegra_drm_context *context; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 506 | struct host1x_syncpt *syncpt; |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 507 | int err = 0; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 508 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 509 | mutex_lock(&fpriv->lock); |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 510 | |
Dmitry Osipenko | 1066a89 | 2017-06-15 02:18:24 +0300 | [diff] [blame] | 511 | context = idr_find(&fpriv->contexts, args->context); |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 512 | if (!context) { |
| 513 | err = -ENODEV; |
| 514 | goto unlock; |
| 515 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 516 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 517 | if (args->index >= context->client->base.num_syncpts) { |
| 518 | err = -EINVAL; |
| 519 | goto unlock; |
| 520 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 521 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 522 | syncpt = context->client->base.syncpts[args->index]; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 523 | args->id = host1x_syncpt_id(syncpt); |
| 524 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 525 | unlock: |
| 526 | mutex_unlock(&fpriv->lock); |
| 527 | return err; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static int tegra_submit(struct drm_device *drm, void *data, |
| 531 | struct drm_file *file) |
| 532 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 533 | struct tegra_drm_file *fpriv = file->driver_priv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 534 | struct drm_tegra_submit *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 535 | struct tegra_drm_context *context; |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 536 | int err; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 537 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 538 | mutex_lock(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 539 | |
Dmitry Osipenko | 1066a89 | 2017-06-15 02:18:24 +0300 | [diff] [blame] | 540 | context = idr_find(&fpriv->contexts, args->context); |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 541 | if (!context) { |
| 542 | err = -ENODEV; |
| 543 | goto unlock; |
| 544 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 545 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 546 | err = context->client->ops->submit(context, args, drm, file); |
| 547 | |
| 548 | unlock: |
| 549 | mutex_unlock(&fpriv->lock); |
| 550 | return err; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 551 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 552 | |
| 553 | static 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 Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 561 | int err = 0; |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 562 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 563 | mutex_lock(&fpriv->lock); |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 564 | |
Dmitry Osipenko | 1066a89 | 2017-06-15 02:18:24 +0300 | [diff] [blame] | 565 | context = idr_find(&fpriv->contexts, args->context); |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 566 | if (!context) { |
| 567 | err = -ENODEV; |
| 568 | goto unlock; |
| 569 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 570 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 571 | if (args->syncpt >= context->client->base.num_syncpts) { |
| 572 | err = -EINVAL; |
| 573 | goto unlock; |
| 574 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 575 | |
| 576 | syncpt = context->client->base.syncpts[args->syncpt]; |
| 577 | |
| 578 | base = host1x_syncpt_get_base(syncpt); |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 579 | if (!base) { |
| 580 | err = -ENXIO; |
| 581 | goto unlock; |
| 582 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 583 | |
| 584 | args->id = host1x_syncpt_base_id(base); |
| 585 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 586 | unlock: |
| 587 | mutex_unlock(&fpriv->lock); |
| 588 | return err; |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 589 | } |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 590 | |
| 591 | static 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 Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 630 | gem = drm_gem_object_lookup(file, args->handle); |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 631 | if (!gem) |
| 632 | return -ENOENT; |
| 633 | |
| 634 | bo = to_tegra_bo(gem); |
| 635 | |
| 636 | bo->tiling.mode = mode; |
| 637 | bo->tiling.value = value; |
| 638 | |
Emil Velikov | b8912e2 | 2020-05-15 10:51:11 +0100 | [diff] [blame] | 639 | drm_gem_object_put(gem); |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | static 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 Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 652 | gem = drm_gem_object_lookup(file, args->handle); |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 653 | 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 | |
Emil Velikov | b8912e2 | 2020-05-15 10:51:11 +0100 | [diff] [blame] | 679 | drm_gem_object_put(gem); |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 680 | |
| 681 | return err; |
| 682 | } |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 683 | |
| 684 | static 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 Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 694 | gem = drm_gem_object_lookup(file, args->handle); |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 695 | 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 | |
Emil Velikov | b8912e2 | 2020-05-15 10:51:11 +0100 | [diff] [blame] | 704 | drm_gem_object_put(gem); |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 705 | |
| 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | static 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 Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 716 | gem = drm_gem_object_lookup(file, args->handle); |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 717 | 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 | |
Emil Velikov | b8912e2 | 2020-05-15 10:51:11 +0100 | [diff] [blame] | 726 | drm_gem_object_put(gem); |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 727 | |
| 728 | return 0; |
| 729 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 730 | #endif |
| 731 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 732 | static const struct drm_ioctl_desc tegra_drm_ioctls[] = { |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 733 | #ifdef CONFIG_DRM_TEGRA_STAGING |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 734 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_CREATE, tegra_gem_create, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 735 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 736 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_gem_mmap, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 737 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 738 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_READ, tegra_syncpt_read, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 739 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 740 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_INCR, tegra_syncpt_incr, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 741 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 742 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_WAIT, tegra_syncpt_wait, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 743 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 744 | DRM_IOCTL_DEF_DRV(TEGRA_OPEN_CHANNEL, tegra_open_channel, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 745 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 746 | DRM_IOCTL_DEF_DRV(TEGRA_CLOSE_CHANNEL, tegra_close_channel, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 747 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 748 | DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT, tegra_get_syncpt, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 749 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 750 | DRM_IOCTL_DEF_DRV(TEGRA_SUBMIT, tegra_submit, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 751 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 752 | DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT_BASE, tegra_get_syncpt_base, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 753 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 754 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_TILING, tegra_gem_set_tiling, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 755 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 756 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_TILING, tegra_gem_get_tiling, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 757 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 758 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_FLAGS, tegra_gem_set_flags, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 759 | DRM_RENDER_ALLOW), |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 760 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_FLAGS, tegra_gem_get_flags, |
Emil Velikov | d6891db | 2019-05-22 16:46:59 +0100 | [diff] [blame] | 761 | DRM_RENDER_ALLOW), |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 762 | #endif |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 763 | }; |
| 764 | |
| 765 | static 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 Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 770 | .mmap = tegra_drm_mmap, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 771 | .poll = drm_poll, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 772 | .read = drm_read, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 773 | .compat_ioctl = drm_compat_ioctl, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 774 | .llseek = noop_llseek, |
| 775 | }; |
| 776 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 777 | static 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 Vetter | bda0ecc | 2017-05-08 10:26:31 +0200 | [diff] [blame] | 786 | static void tegra_drm_postclose(struct drm_device *drm, struct drm_file *file) |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 787 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 788 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 789 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 790 | mutex_lock(&fpriv->lock); |
| 791 | idr_for_each(&fpriv->contexts, tegra_drm_context_cleanup, NULL); |
| 792 | mutex_unlock(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 793 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 794 | idr_destroy(&fpriv->contexts); |
| 795 | mutex_destroy(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 796 | kfree(fpriv); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 797 | } |
| 798 | |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 799 | #ifdef CONFIG_DEBUG_FS |
| 800 | static 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ä | b00c600 | 2016-12-14 23:31:35 +0200 | [diff] [blame] | 810 | fb->base.id, fb->width, fb->height, |
| 811 | fb->format->depth, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 812 | fb->format->cpp[0] * 8, |
Dave Airlie | 747a598 | 2016-04-15 15:10:35 +1000 | [diff] [blame] | 813 | drm_framebuffer_read_refcount(fb)); |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | mutex_unlock(&drm->mode_config.fb_lock); |
| 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
Thierry Reding | 28c2337 | 2015-01-23 09:16:03 +0100 | [diff] [blame] | 821 | static 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 Vetter | b5c3714 | 2016-12-29 12:09:24 +0100 | [diff] [blame] | 826 | struct drm_printer p = drm_seq_file_printer(s); |
Thierry Reding | 28c2337 | 2015-01-23 09:16:03 +0100 | [diff] [blame] | 827 | |
Michał Mirosław | 68d890a | 2017-08-14 23:53:45 +0200 | [diff] [blame] | 828 | if (tegra->domain) { |
| 829 | mutex_lock(&tegra->mm_lock); |
| 830 | drm_mm_print(&tegra->mm, &p); |
| 831 | mutex_unlock(&tegra->mm_lock); |
| 832 | } |
Daniel Vetter | b5c3714 | 2016-12-29 12:09:24 +0100 | [diff] [blame] | 833 | |
| 834 | return 0; |
Thierry Reding | 28c2337 | 2015-01-23 09:16:03 +0100 | [diff] [blame] | 835 | } |
| 836 | |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 837 | static struct drm_info_list tegra_debugfs_list[] = { |
| 838 | { "framebuffers", tegra_debugfs_framebuffers, 0 }, |
Thierry Reding | 28c2337 | 2015-01-23 09:16:03 +0100 | [diff] [blame] | 839 | { "iova", tegra_debugfs_iova, 0 }, |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 840 | }; |
| 841 | |
Wambui Karuga | 7ce84471 | 2020-03-10 16:31:21 +0300 | [diff] [blame] | 842 | static void tegra_debugfs_init(struct drm_minor *minor) |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 843 | { |
Wambui Karuga | ad6d94f | 2020-03-10 16:31:05 +0300 | [diff] [blame] | 844 | drm_debugfs_create_files(tegra_debugfs_list, |
| 845 | ARRAY_SIZE(tegra_debugfs_list), |
| 846 | minor->debugfs_root, minor); |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 847 | } |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 848 | #endif |
| 849 | |
Thierry Reding | 9b57f5f | 2013-11-08 13:17:14 +0100 | [diff] [blame] | 850 | static struct drm_driver tegra_drm_driver = { |
Daniel Vetter | 0424fda | 2019-06-17 17:39:24 +0200 | [diff] [blame] | 851 | .driver_features = DRIVER_MODESET | DRIVER_GEM | |
Thierry Reding | 6c68b71 | 2017-08-15 15:42:39 +0200 | [diff] [blame] | 852 | DRIVER_ATOMIC | DRIVER_RENDER, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 853 | .open = tegra_drm_open, |
Daniel Vetter | bda0ecc | 2017-05-08 10:26:31 +0200 | [diff] [blame] | 854 | .postclose = tegra_drm_postclose, |
Noralf Trønnes | c94beda | 2017-12-05 19:25:04 +0100 | [diff] [blame] | 855 | .lastclose = drm_fb_helper_lastclose, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 856 | |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 857 | #if defined(CONFIG_DEBUG_FS) |
| 858 | .debugfs_init = tegra_debugfs_init, |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 859 | #endif |
| 860 | |
Thierry Reding | 3800391 | 2013-12-12 10:00:43 +0100 | [diff] [blame] | 861 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 862 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
Thierry Reding | 3800391 | 2013-12-12 10:00:43 +0100 | [diff] [blame] | 863 | .gem_prime_import = tegra_gem_prime_import, |
| 864 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 865 | .dumb_create = tegra_bo_dumb_create, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 866 | |
| 867 | .ioctls = tegra_drm_ioctls, |
| 868 | .num_ioctls = ARRAY_SIZE(tegra_drm_ioctls), |
| 869 | .fops = &tegra_drm_fops, |
| 870 | |
| 871 | .name = DRIVER_NAME, |
| 872 | .desc = DRIVER_DESC, |
| 873 | .date = DRIVER_DATE, |
| 874 | .major = DRIVER_MAJOR, |
| 875 | .minor = DRIVER_MINOR, |
| 876 | .patchlevel = DRIVER_PATCHLEVEL, |
| 877 | }; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 878 | |
| 879 | int tegra_drm_register_client(struct tegra_drm *tegra, |
| 880 | struct tegra_drm_client *client) |
| 881 | { |
| 882 | mutex_lock(&tegra->clients_lock); |
| 883 | list_add_tail(&client->list, &tegra->clients); |
Thierry Reding | 8e5d19c | 2019-02-01 14:28:31 +0100 | [diff] [blame] | 884 | client->drm = tegra; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 885 | mutex_unlock(&tegra->clients_lock); |
| 886 | |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | int tegra_drm_unregister_client(struct tegra_drm *tegra, |
| 891 | struct tegra_drm_client *client) |
| 892 | { |
| 893 | mutex_lock(&tegra->clients_lock); |
| 894 | list_del_init(&client->list); |
Thierry Reding | 8e5d19c | 2019-02-01 14:28:31 +0100 | [diff] [blame] | 895 | client->drm = NULL; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 896 | mutex_unlock(&tegra->clients_lock); |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
Thierry Reding | 7edd796 | 2019-10-28 13:37:08 +0100 | [diff] [blame] | 901 | int host1x_client_iommu_attach(struct host1x_client *client) |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 902 | { |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 903 | struct iommu_domain *domain = iommu_get_domain_for_dev(client->dev); |
Thierry Reding | 608f43a | 2019-12-02 10:51:58 +0100 | [diff] [blame] | 904 | struct drm_device *drm = dev_get_drvdata(client->host); |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 905 | struct tegra_drm *tegra = drm->dev_private; |
| 906 | struct iommu_group *group = NULL; |
| 907 | int err; |
| 908 | |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 909 | /* |
| 910 | * If the host1x client is already attached to an IOMMU domain that is |
| 911 | * not the shared IOMMU domain, don't try to attach it to a different |
| 912 | * domain. This allows using the IOMMU-backed DMA API. |
| 913 | */ |
| 914 | if (domain && domain != tegra->domain) |
| 915 | return 0; |
Thierry Reding | 7edd796 | 2019-10-28 13:37:08 +0100 | [diff] [blame] | 916 | |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 917 | if (tegra->domain) { |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 918 | group = iommu_group_get(client->dev); |
Thierry Reding | a881748 | 2019-12-03 17:19:12 +0100 | [diff] [blame] | 919 | if (!group) |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 920 | return -ENODEV; |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 921 | |
Thierry Reding | 7edd796 | 2019-10-28 13:37:08 +0100 | [diff] [blame] | 922 | if (domain != tegra->domain) { |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 923 | err = iommu_attach_group(tegra->domain, group); |
| 924 | if (err < 0) { |
| 925 | iommu_group_put(group); |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 926 | return err; |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 927 | } |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 928 | } |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 929 | |
| 930 | tegra->use_explicit_iommu = true; |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 931 | } |
| 932 | |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 933 | client->group = group; |
| 934 | |
| 935 | return 0; |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 936 | } |
| 937 | |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 938 | void host1x_client_iommu_detach(struct host1x_client *client) |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 939 | { |
Thierry Reding | 608f43a | 2019-12-02 10:51:58 +0100 | [diff] [blame] | 940 | struct drm_device *drm = dev_get_drvdata(client->host); |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 941 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | 7edd796 | 2019-10-28 13:37:08 +0100 | [diff] [blame] | 942 | struct iommu_domain *domain; |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 943 | |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 944 | if (client->group) { |
Thierry Reding | 7edd796 | 2019-10-28 13:37:08 +0100 | [diff] [blame] | 945 | /* |
| 946 | * Devices that are part of the same group may no longer be |
| 947 | * attached to a domain at this point because their group may |
| 948 | * have been detached by an earlier client. |
| 949 | */ |
| 950 | domain = iommu_get_domain_for_dev(client->dev); |
| 951 | if (domain) |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 952 | iommu_detach_group(tegra->domain, client->group); |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 953 | |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 954 | iommu_group_put(client->group); |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 955 | client->group = NULL; |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
Thierry Reding | 67485fb | 2017-11-09 13:17:11 +0100 | [diff] [blame] | 959 | void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *dma) |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 960 | { |
| 961 | struct iova *alloc; |
| 962 | void *virt; |
| 963 | gfp_t gfp; |
| 964 | int err; |
| 965 | |
| 966 | if (tegra->domain) |
| 967 | size = iova_align(&tegra->carveout.domain, size); |
| 968 | else |
| 969 | size = PAGE_ALIGN(size); |
| 970 | |
| 971 | gfp = GFP_KERNEL | __GFP_ZERO; |
| 972 | if (!tegra->domain) { |
| 973 | /* |
| 974 | * Many units only support 32-bit addresses, even on 64-bit |
| 975 | * SoCs. If there is no IOMMU to translate into a 32-bit IO |
| 976 | * virtual address space, force allocations to be in the |
| 977 | * lower 32-bit range. |
| 978 | */ |
| 979 | gfp |= GFP_DMA; |
| 980 | } |
| 981 | |
| 982 | virt = (void *)__get_free_pages(gfp, get_order(size)); |
| 983 | if (!virt) |
| 984 | return ERR_PTR(-ENOMEM); |
| 985 | |
| 986 | if (!tegra->domain) { |
| 987 | /* |
| 988 | * If IOMMU is disabled, devices address physical memory |
| 989 | * directly. |
| 990 | */ |
| 991 | *dma = virt_to_phys(virt); |
| 992 | return virt; |
| 993 | } |
| 994 | |
| 995 | alloc = alloc_iova(&tegra->carveout.domain, |
| 996 | size >> tegra->carveout.shift, |
| 997 | tegra->carveout.limit, true); |
| 998 | if (!alloc) { |
| 999 | err = -EBUSY; |
| 1000 | goto free_pages; |
| 1001 | } |
| 1002 | |
| 1003 | *dma = iova_dma_addr(&tegra->carveout.domain, alloc); |
| 1004 | err = iommu_map(tegra->domain, *dma, virt_to_phys(virt), |
| 1005 | size, IOMMU_READ | IOMMU_WRITE); |
| 1006 | if (err < 0) |
| 1007 | goto free_iova; |
| 1008 | |
| 1009 | return virt; |
| 1010 | |
| 1011 | free_iova: |
| 1012 | __free_iova(&tegra->carveout.domain, alloc); |
| 1013 | free_pages: |
| 1014 | free_pages((unsigned long)virt, get_order(size)); |
| 1015 | |
| 1016 | return ERR_PTR(err); |
| 1017 | } |
| 1018 | |
| 1019 | void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt, |
| 1020 | dma_addr_t dma) |
| 1021 | { |
| 1022 | if (tegra->domain) |
| 1023 | size = iova_align(&tegra->carveout.domain, size); |
| 1024 | else |
| 1025 | size = PAGE_ALIGN(size); |
| 1026 | |
| 1027 | if (tegra->domain) { |
| 1028 | iommu_unmap(tegra->domain, dma, size); |
| 1029 | free_iova(&tegra->carveout.domain, |
| 1030 | iova_pfn(&tegra->carveout.domain, dma)); |
| 1031 | } |
| 1032 | |
| 1033 | free_pages((unsigned long)virt, get_order(size)); |
| 1034 | } |
| 1035 | |
Thierry Reding | 2d9384f | 2020-02-04 14:59:24 +0100 | [diff] [blame] | 1036 | static bool host1x_drm_wants_iommu(struct host1x_device *dev) |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1037 | { |
Thierry Reding | 501be6c | 2020-03-25 21:16:03 +0100 | [diff] [blame] | 1038 | struct host1x *host1x = dev_get_drvdata(dev->dev.parent); |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 1039 | struct iommu_domain *domain; |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1040 | |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 1041 | /* |
| 1042 | * If the Tegra DRM clients are backed by an IOMMU, push buffers are |
| 1043 | * likely to be allocated beyond the 32-bit boundary if sufficient |
| 1044 | * system memory is available. This is problematic on earlier Tegra |
| 1045 | * generations where host1x supports a maximum of 32 address bits in |
| 1046 | * the GATHER opcode. In this case, unless host1x is behind an IOMMU |
| 1047 | * as well it won't be able to process buffers allocated beyond the |
| 1048 | * 32-bit boundary. |
| 1049 | * |
| 1050 | * The DMA API will use bounce buffers in this case, so that could |
| 1051 | * perhaps still be made to work, even if less efficient, but there |
| 1052 | * is another catch: in order to perform cache maintenance on pages |
| 1053 | * allocated for discontiguous buffers we need to map and unmap the |
| 1054 | * SG table representing these buffers. This is fine for something |
| 1055 | * small like a push buffer, but it exhausts the bounce buffer pool |
| 1056 | * (typically on the order of a few MiB) for framebuffers (many MiB |
| 1057 | * for any modern resolution). |
| 1058 | * |
| 1059 | * Work around this by making sure that Tegra DRM clients only use |
| 1060 | * an IOMMU if the parent host1x also uses an IOMMU. |
| 1061 | * |
| 1062 | * Note that there's still a small gap here that we don't cover: if |
| 1063 | * the DMA API is backed by an IOMMU there's no way to control which |
| 1064 | * device is attached to an IOMMU and which isn't, except via wiring |
| 1065 | * up the device tree appropriately. This is considered an problem |
| 1066 | * of integration, so care must be taken for the DT to be consistent. |
| 1067 | */ |
Thierry Reding | 2d9384f | 2020-02-04 14:59:24 +0100 | [diff] [blame] | 1068 | domain = iommu_get_domain_for_dev(dev->dev.parent); |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 1069 | |
Thierry Reding | 2d9384f | 2020-02-04 14:59:24 +0100 | [diff] [blame] | 1070 | /* |
| 1071 | * Tegra20 and Tegra30 don't support addressing memory beyond the |
| 1072 | * 32-bit boundary, so the regular GATHER opcodes will always be |
| 1073 | * sufficient and whether or not the host1x is attached to an IOMMU |
| 1074 | * doesn't matter. |
| 1075 | */ |
Thierry Reding | 501be6c | 2020-03-25 21:16:03 +0100 | [diff] [blame] | 1076 | if (!domain && host1x_get_dma_mask(host1x) <= DMA_BIT_MASK(32)) |
Thierry Reding | 2d9384f | 2020-02-04 14:59:24 +0100 | [diff] [blame] | 1077 | return true; |
| 1078 | |
| 1079 | return domain != NULL; |
| 1080 | } |
| 1081 | |
| 1082 | static int host1x_drm_probe(struct host1x_device *dev) |
| 1083 | { |
| 1084 | struct drm_driver *driver = &tegra_drm_driver; |
| 1085 | struct tegra_drm *tegra; |
| 1086 | struct drm_device *drm; |
| 1087 | int err; |
| 1088 | |
| 1089 | drm = drm_dev_alloc(driver, &dev->dev); |
| 1090 | if (IS_ERR(drm)) |
| 1091 | return PTR_ERR(drm); |
| 1092 | |
| 1093 | tegra = kzalloc(sizeof(*tegra), GFP_KERNEL); |
| 1094 | if (!tegra) { |
| 1095 | err = -ENOMEM; |
| 1096 | goto put; |
| 1097 | } |
| 1098 | |
| 1099 | if (host1x_drm_wants_iommu(dev) && iommu_present(&platform_bus_type)) { |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1100 | tegra->domain = iommu_domain_alloc(&platform_bus_type); |
| 1101 | if (!tegra->domain) { |
| 1102 | err = -ENOMEM; |
| 1103 | goto free; |
| 1104 | } |
| 1105 | |
| 1106 | err = iova_cache_get(); |
| 1107 | if (err < 0) |
| 1108 | goto domain; |
| 1109 | } |
| 1110 | |
| 1111 | mutex_init(&tegra->clients_lock); |
| 1112 | INIT_LIST_HEAD(&tegra->clients); |
| 1113 | |
| 1114 | dev_set_drvdata(&dev->dev, drm); |
| 1115 | drm->dev_private = tegra; |
| 1116 | tegra->drm = drm; |
| 1117 | |
| 1118 | drm_mode_config_init(drm); |
| 1119 | |
| 1120 | drm->mode_config.min_width = 0; |
| 1121 | drm->mode_config.min_height = 0; |
| 1122 | |
| 1123 | drm->mode_config.max_width = 4096; |
| 1124 | drm->mode_config.max_height = 4096; |
| 1125 | |
| 1126 | drm->mode_config.allow_fb_modifiers = true; |
| 1127 | |
| 1128 | drm->mode_config.normalize_zpos = true; |
| 1129 | |
| 1130 | drm->mode_config.funcs = &tegra_drm_mode_config_funcs; |
| 1131 | drm->mode_config.helper_private = &tegra_drm_mode_config_helpers; |
| 1132 | |
| 1133 | err = tegra_drm_fb_prepare(drm); |
| 1134 | if (err < 0) |
| 1135 | goto config; |
| 1136 | |
| 1137 | drm_kms_helper_poll_init(drm); |
| 1138 | |
| 1139 | err = host1x_device_init(dev); |
| 1140 | if (err < 0) |
| 1141 | goto fbdev; |
| 1142 | |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 1143 | if (tegra->use_explicit_iommu) { |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1144 | u64 carveout_start, carveout_end, gem_start, gem_end; |
| 1145 | u64 dma_mask = dma_get_mask(&dev->dev); |
| 1146 | dma_addr_t start, end; |
| 1147 | unsigned long order; |
| 1148 | |
| 1149 | start = tegra->domain->geometry.aperture_start & dma_mask; |
| 1150 | end = tegra->domain->geometry.aperture_end & dma_mask; |
| 1151 | |
| 1152 | gem_start = start; |
| 1153 | gem_end = end - CARVEOUT_SZ; |
| 1154 | carveout_start = gem_end + 1; |
| 1155 | carveout_end = end; |
| 1156 | |
| 1157 | order = __ffs(tegra->domain->pgsize_bitmap); |
| 1158 | init_iova_domain(&tegra->carveout.domain, 1UL << order, |
| 1159 | carveout_start >> order); |
| 1160 | |
| 1161 | tegra->carveout.shift = iova_shift(&tegra->carveout.domain); |
| 1162 | tegra->carveout.limit = carveout_end >> tegra->carveout.shift; |
| 1163 | |
| 1164 | drm_mm_init(&tegra->mm, gem_start, gem_end - gem_start + 1); |
| 1165 | mutex_init(&tegra->mm_lock); |
| 1166 | |
| 1167 | DRM_DEBUG_DRIVER("IOMMU apertures:\n"); |
| 1168 | DRM_DEBUG_DRIVER(" GEM: %#llx-%#llx\n", gem_start, gem_end); |
| 1169 | DRM_DEBUG_DRIVER(" Carveout: %#llx-%#llx\n", carveout_start, |
| 1170 | carveout_end); |
Thierry Reding | fa6661b | 2019-10-28 13:37:18 +0100 | [diff] [blame] | 1171 | } else if (tegra->domain) { |
| 1172 | iommu_domain_free(tegra->domain); |
| 1173 | tegra->domain = NULL; |
| 1174 | iova_cache_put(); |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | if (tegra->hub) { |
| 1178 | err = tegra_display_hub_prepare(tegra->hub); |
| 1179 | if (err < 0) |
| 1180 | goto device; |
| 1181 | } |
| 1182 | |
| 1183 | /* |
| 1184 | * We don't use the drm_irq_install() helpers provided by the DRM |
| 1185 | * core, so we need to set this manually in order to allow the |
| 1186 | * DRM_IOCTL_WAIT_VBLANK to operate correctly. |
| 1187 | */ |
| 1188 | drm->irq_enabled = true; |
| 1189 | |
| 1190 | /* syncpoints are used for full 32-bit hardware VBLANK counters */ |
| 1191 | drm->max_vblank_count = 0xffffffff; |
| 1192 | |
| 1193 | err = drm_vblank_init(drm, drm->mode_config.num_crtc); |
| 1194 | if (err < 0) |
| 1195 | goto hub; |
| 1196 | |
| 1197 | drm_mode_config_reset(drm); |
| 1198 | |
| 1199 | err = drm_fb_helper_remove_conflicting_framebuffers(NULL, "tegradrmfb", |
| 1200 | false); |
| 1201 | if (err < 0) |
| 1202 | goto hub; |
| 1203 | |
| 1204 | err = tegra_drm_fb_init(drm); |
| 1205 | if (err < 0) |
| 1206 | goto hub; |
Michał Mirosław | 6e4228f | 2018-09-01 16:08:51 +0200 | [diff] [blame] | 1207 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1208 | err = drm_dev_register(drm, 0); |
| 1209 | if (err < 0) |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1210 | goto fb; |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1211 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1212 | return 0; |
| 1213 | |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1214 | fb: |
| 1215 | tegra_drm_fb_exit(drm); |
| 1216 | hub: |
| 1217 | if (tegra->hub) |
| 1218 | tegra_display_hub_cleanup(tegra->hub); |
| 1219 | device: |
| 1220 | if (tegra->domain) { |
| 1221 | mutex_destroy(&tegra->mm_lock); |
| 1222 | drm_mm_takedown(&tegra->mm); |
| 1223 | put_iova_domain(&tegra->carveout.domain); |
| 1224 | iova_cache_put(); |
| 1225 | } |
| 1226 | |
| 1227 | host1x_device_exit(dev); |
| 1228 | fbdev: |
| 1229 | drm_kms_helper_poll_fini(drm); |
| 1230 | tegra_drm_fb_free(drm); |
| 1231 | config: |
| 1232 | drm_mode_config_cleanup(drm); |
| 1233 | domain: |
| 1234 | if (tegra->domain) |
| 1235 | iommu_domain_free(tegra->domain); |
| 1236 | free: |
| 1237 | kfree(tegra); |
Thomas Zimmermann | 9c94209 | 2018-09-26 13:56:40 +0200 | [diff] [blame] | 1238 | put: |
| 1239 | drm_dev_put(drm); |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1240 | return err; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1241 | } |
| 1242 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1243 | static int host1x_drm_remove(struct host1x_device *dev) |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1244 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1245 | struct drm_device *drm = dev_get_drvdata(&dev->dev); |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1246 | struct tegra_drm *tegra = drm->dev_private; |
| 1247 | int err; |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1248 | |
| 1249 | drm_dev_unregister(drm); |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1250 | |
| 1251 | drm_kms_helper_poll_fini(drm); |
| 1252 | tegra_drm_fb_exit(drm); |
| 1253 | drm_atomic_helper_shutdown(drm); |
| 1254 | drm_mode_config_cleanup(drm); |
| 1255 | |
Thierry Reding | d66dfcf8 | 2019-12-03 17:19:14 +0100 | [diff] [blame] | 1256 | if (tegra->hub) |
| 1257 | tegra_display_hub_cleanup(tegra->hub); |
| 1258 | |
Thierry Reding | a7303f7 | 2019-10-28 13:16:10 +0100 | [diff] [blame] | 1259 | err = host1x_device_exit(dev); |
| 1260 | if (err < 0) |
| 1261 | dev_err(&dev->dev, "host1x device cleanup failed: %d\n", err); |
| 1262 | |
| 1263 | if (tegra->domain) { |
| 1264 | mutex_destroy(&tegra->mm_lock); |
| 1265 | drm_mm_takedown(&tegra->mm); |
| 1266 | put_iova_domain(&tegra->carveout.domain); |
| 1267 | iova_cache_put(); |
| 1268 | iommu_domain_free(tegra->domain); |
| 1269 | } |
| 1270 | |
| 1271 | kfree(tegra); |
Thomas Zimmermann | 9c94209 | 2018-09-26 13:56:40 +0200 | [diff] [blame] | 1272 | drm_dev_put(drm); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1277 | #ifdef CONFIG_PM_SLEEP |
| 1278 | static int host1x_drm_suspend(struct device *dev) |
| 1279 | { |
| 1280 | struct drm_device *drm = dev_get_drvdata(dev); |
| 1281 | |
Souptick Joarder | 53f1e06 | 2018-08-01 01:37:05 +0530 | [diff] [blame] | 1282 | return drm_mode_config_helper_suspend(drm); |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | static int host1x_drm_resume(struct device *dev) |
| 1286 | { |
| 1287 | struct drm_device *drm = dev_get_drvdata(dev); |
| 1288 | |
Souptick Joarder | 53f1e06 | 2018-08-01 01:37:05 +0530 | [diff] [blame] | 1289 | return drm_mode_config_helper_resume(drm); |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1290 | } |
| 1291 | #endif |
| 1292 | |
Thierry Reding | a13f1dc | 2015-08-11 13:22:44 +0200 | [diff] [blame] | 1293 | static SIMPLE_DEV_PM_OPS(host1x_drm_pm_ops, host1x_drm_suspend, |
| 1294 | host1x_drm_resume); |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1295 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1296 | static const struct of_device_id host1x_drm_subdevs[] = { |
| 1297 | { .compatible = "nvidia,tegra20-dc", }, |
| 1298 | { .compatible = "nvidia,tegra20-hdmi", }, |
| 1299 | { .compatible = "nvidia,tegra20-gr2d", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 1300 | { .compatible = "nvidia,tegra20-gr3d", }, |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1301 | { .compatible = "nvidia,tegra30-dc", }, |
| 1302 | { .compatible = "nvidia,tegra30-hdmi", }, |
| 1303 | { .compatible = "nvidia,tegra30-gr2d", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 1304 | { .compatible = "nvidia,tegra30-gr3d", }, |
Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 1305 | { .compatible = "nvidia,tegra114-dsi", }, |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 1306 | { .compatible = "nvidia,tegra114-hdmi", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 1307 | { .compatible = "nvidia,tegra114-gr3d", }, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1308 | { .compatible = "nvidia,tegra124-dc", }, |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1309 | { .compatible = "nvidia,tegra124-sor", }, |
Thierry Reding | fb7be70 | 2013-11-15 16:07:32 +0100 | [diff] [blame] | 1310 | { .compatible = "nvidia,tegra124-hdmi", }, |
Thierry Reding | 7d33858 | 2015-04-10 11:35:21 +0200 | [diff] [blame] | 1311 | { .compatible = "nvidia,tegra124-dsi", }, |
Arto Merilainen | 0ae797a | 2016-12-14 13:16:13 +0200 | [diff] [blame] | 1312 | { .compatible = "nvidia,tegra124-vic", }, |
Thierry Reding | c06c793 | 2015-04-10 11:35:21 +0200 | [diff] [blame] | 1313 | { .compatible = "nvidia,tegra132-dsi", }, |
Thierry Reding | 5b4f516 | 2015-03-27 10:31:58 +0100 | [diff] [blame] | 1314 | { .compatible = "nvidia,tegra210-dc", }, |
Thierry Reding | ddfb406 | 2015-04-08 16:56:22 +0200 | [diff] [blame] | 1315 | { .compatible = "nvidia,tegra210-dsi", }, |
Thierry Reding | 3309ac8 | 2015-07-30 10:32:46 +0200 | [diff] [blame] | 1316 | { .compatible = "nvidia,tegra210-sor", }, |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1317 | { .compatible = "nvidia,tegra210-sor1", }, |
Arto Merilainen | 0ae797a | 2016-12-14 13:16:13 +0200 | [diff] [blame] | 1318 | { .compatible = "nvidia,tegra210-vic", }, |
Thierry Reding | c4755fb | 2017-11-13 11:08:13 +0100 | [diff] [blame] | 1319 | { .compatible = "nvidia,tegra186-display", }, |
Thierry Reding | 4730795 | 2017-08-30 17:42:54 +0200 | [diff] [blame] | 1320 | { .compatible = "nvidia,tegra186-dc", }, |
Thierry Reding | c57997b | 2017-10-12 19:12:57 +0200 | [diff] [blame] | 1321 | { .compatible = "nvidia,tegra186-sor", }, |
| 1322 | { .compatible = "nvidia,tegra186-sor1", }, |
Mikko Perttunen | 6e44b9a | 2017-09-05 11:43:06 +0300 | [diff] [blame] | 1323 | { .compatible = "nvidia,tegra186-vic", }, |
Thierry Reding | 5725daa | 2018-09-21 12:27:43 +0200 | [diff] [blame] | 1324 | { .compatible = "nvidia,tegra194-display", }, |
Thierry Reding | 4744319 | 2018-09-21 12:27:44 +0200 | [diff] [blame] | 1325 | { .compatible = "nvidia,tegra194-dc", }, |
Thierry Reding | 9b6c14b | 2018-09-21 12:27:46 +0200 | [diff] [blame] | 1326 | { .compatible = "nvidia,tegra194-sor", }, |
Thierry Reding | d6b9bc0 | 2018-10-26 10:59:38 +0200 | [diff] [blame] | 1327 | { .compatible = "nvidia,tegra194-vic", }, |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1328 | { /* sentinel */ } |
| 1329 | }; |
| 1330 | |
| 1331 | static struct host1x_driver host1x_drm_driver = { |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 1332 | .driver = { |
| 1333 | .name = "drm", |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1334 | .pm = &host1x_drm_pm_ops, |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 1335 | }, |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1336 | .probe = host1x_drm_probe, |
| 1337 | .remove = host1x_drm_remove, |
| 1338 | .subdevs = host1x_drm_subdevs, |
| 1339 | }; |
| 1340 | |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1341 | static struct platform_driver * const drivers[] = { |
Thierry Reding | c4755fb | 2017-11-13 11:08:13 +0100 | [diff] [blame] | 1342 | &tegra_display_hub_driver, |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1343 | &tegra_dc_driver, |
| 1344 | &tegra_hdmi_driver, |
| 1345 | &tegra_dsi_driver, |
| 1346 | &tegra_dpaux_driver, |
| 1347 | &tegra_sor_driver, |
| 1348 | &tegra_gr2d_driver, |
| 1349 | &tegra_gr3d_driver, |
Arto Merilainen | 0ae797a | 2016-12-14 13:16:13 +0200 | [diff] [blame] | 1350 | &tegra_vic_driver, |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1351 | }; |
| 1352 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1353 | static int __init host1x_drm_init(void) |
| 1354 | { |
| 1355 | int err; |
| 1356 | |
| 1357 | err = host1x_driver_register(&host1x_drm_driver); |
| 1358 | if (err < 0) |
| 1359 | return err; |
| 1360 | |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1361 | err = platform_register_drivers(drivers, ARRAY_SIZE(drivers)); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1362 | if (err < 0) |
| 1363 | goto unregister_host1x; |
| 1364 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1365 | return 0; |
| 1366 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1367 | unregister_host1x: |
| 1368 | host1x_driver_unregister(&host1x_drm_driver); |
| 1369 | return err; |
| 1370 | } |
| 1371 | module_init(host1x_drm_init); |
| 1372 | |
| 1373 | static void __exit host1x_drm_exit(void) |
| 1374 | { |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1375 | platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1376 | host1x_driver_unregister(&host1x_drm_driver); |
| 1377 | } |
| 1378 | module_exit(host1x_drm_exit); |
| 1379 | |
| 1380 | MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); |
| 1381 | MODULE_DESCRIPTION("NVIDIA Tegra DRM driver"); |
| 1382 | MODULE_LICENSE("GPL v2"); |