Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Avionic Design GmbH |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 3 | * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved. |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 10 | #include <linux/host1x.h> |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 11 | #include <linux/iommu.h> |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 12 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 13 | #include "drm.h" |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 14 | #include "gem.h" |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 15 | |
| 16 | #define DRIVER_NAME "tegra" |
| 17 | #define DRIVER_DESC "NVIDIA Tegra graphics" |
| 18 | #define DRIVER_DATE "20120330" |
| 19 | #define DRIVER_MAJOR 0 |
| 20 | #define DRIVER_MINOR 0 |
| 21 | #define DRIVER_PATCHLEVEL 0 |
| 22 | |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 23 | struct tegra_drm_file { |
| 24 | struct list_head contexts; |
| 25 | }; |
| 26 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 27 | static int tegra_drm_load(struct drm_device *drm, unsigned long flags) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 28 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 29 | struct host1x_device *device = to_host1x_device(drm->dev); |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 30 | struct tegra_drm *tegra; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 31 | int err; |
| 32 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 33 | tegra = kzalloc(sizeof(*tegra), GFP_KERNEL); |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 34 | if (!tegra) |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 35 | return -ENOMEM; |
| 36 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 37 | if (iommu_present(&platform_bus_type)) { |
| 38 | tegra->domain = iommu_domain_alloc(&platform_bus_type); |
| 39 | if (IS_ERR(tegra->domain)) { |
| 40 | err = PTR_ERR(tegra->domain); |
| 41 | goto free; |
| 42 | } |
| 43 | |
| 44 | DRM_DEBUG("IOMMU context initialized\n"); |
| 45 | drm_mm_init(&tegra->mm, 0, SZ_2G); |
| 46 | } |
| 47 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 48 | mutex_init(&tegra->clients_lock); |
| 49 | INIT_LIST_HEAD(&tegra->clients); |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 50 | drm->dev_private = tegra; |
| 51 | tegra->drm = drm; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 52 | |
| 53 | drm_mode_config_init(drm); |
| 54 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 55 | err = tegra_drm_fb_prepare(drm); |
| 56 | if (err < 0) |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 57 | goto config; |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 58 | |
| 59 | drm_kms_helper_poll_init(drm); |
| 60 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 61 | err = host1x_device_init(device); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 62 | if (err < 0) |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 63 | goto fbdev; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 64 | |
Thierry Reding | 603f0cc | 2013-04-22 21:22:14 +0200 | [diff] [blame] | 65 | /* |
| 66 | * We don't use the drm_irq_install() helpers provided by the DRM |
| 67 | * core, so we need to set this manually in order to allow the |
| 68 | * DRM_IOCTL_WAIT_VBLANK to operate correctly. |
| 69 | */ |
Ville Syrjälä | 4423843 | 2013-10-04 14:53:37 +0300 | [diff] [blame] | 70 | drm->irq_enabled = true; |
Thierry Reding | 603f0cc | 2013-04-22 21:22:14 +0200 | [diff] [blame] | 71 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 72 | err = drm_vblank_init(drm, drm->mode_config.num_crtc); |
| 73 | if (err < 0) |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 74 | goto device; |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 75 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 76 | err = tegra_drm_fb_init(drm); |
| 77 | if (err < 0) |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 78 | goto vblank; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 79 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 80 | return 0; |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 81 | |
| 82 | vblank: |
| 83 | drm_vblank_cleanup(drm); |
| 84 | device: |
| 85 | host1x_device_exit(device); |
| 86 | fbdev: |
| 87 | drm_kms_helper_poll_fini(drm); |
| 88 | tegra_drm_fb_free(drm); |
| 89 | config: |
| 90 | drm_mode_config_cleanup(drm); |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 91 | |
| 92 | if (tegra->domain) { |
| 93 | iommu_domain_free(tegra->domain); |
| 94 | drm_mm_takedown(&tegra->mm); |
| 95 | } |
| 96 | free: |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 97 | kfree(tegra); |
| 98 | return err; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static int tegra_drm_unload(struct drm_device *drm) |
| 102 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 103 | struct host1x_device *device = to_host1x_device(drm->dev); |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 104 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 105 | int err; |
| 106 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 107 | drm_kms_helper_poll_fini(drm); |
| 108 | tegra_drm_fb_exit(drm); |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 109 | drm_vblank_cleanup(drm); |
| 110 | drm_mode_config_cleanup(drm); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 111 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 112 | err = host1x_device_exit(device); |
| 113 | if (err < 0) |
| 114 | return err; |
| 115 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 116 | if (tegra->domain) { |
| 117 | iommu_domain_free(tegra->domain); |
| 118 | drm_mm_takedown(&tegra->mm); |
| 119 | } |
| 120 | |
Thierry Reding | 1053f4dd | 2014-11-04 16:17:55 +0100 | [diff] [blame] | 121 | kfree(tegra); |
| 122 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) |
| 127 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 128 | struct tegra_drm_file *fpriv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 129 | |
| 130 | fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); |
| 131 | if (!fpriv) |
| 132 | return -ENOMEM; |
| 133 | |
| 134 | INIT_LIST_HEAD(&fpriv->contexts); |
| 135 | filp->driver_priv = fpriv; |
| 136 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 140 | static void tegra_drm_context_free(struct tegra_drm_context *context) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 141 | { |
| 142 | context->client->ops->close_channel(context); |
| 143 | kfree(context); |
| 144 | } |
| 145 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 146 | static void tegra_drm_lastclose(struct drm_device *drm) |
| 147 | { |
Paul Bolle | 6e60163 | 2014-02-09 14:01:33 +0100 | [diff] [blame] | 148 | #ifdef CONFIG_DRM_TEGRA_FBDEV |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 149 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 150 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 151 | tegra_fbdev_restore_mode(tegra->fbdev); |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 152 | #endif |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 155 | static struct host1x_bo * |
| 156 | host1x_bo_lookup(struct drm_device *drm, struct drm_file *file, u32 handle) |
| 157 | { |
| 158 | struct drm_gem_object *gem; |
| 159 | struct tegra_bo *bo; |
| 160 | |
| 161 | gem = drm_gem_object_lookup(drm, file, handle); |
| 162 | if (!gem) |
| 163 | return NULL; |
| 164 | |
| 165 | mutex_lock(&drm->struct_mutex); |
| 166 | drm_gem_object_unreference(gem); |
| 167 | mutex_unlock(&drm->struct_mutex); |
| 168 | |
| 169 | bo = to_tegra_bo(gem); |
| 170 | return &bo->base; |
| 171 | } |
| 172 | |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 173 | static int host1x_reloc_copy_from_user(struct host1x_reloc *dest, |
| 174 | struct drm_tegra_reloc __user *src, |
| 175 | struct drm_device *drm, |
| 176 | struct drm_file *file) |
| 177 | { |
| 178 | u32 cmdbuf, target; |
| 179 | int err; |
| 180 | |
| 181 | err = get_user(cmdbuf, &src->cmdbuf.handle); |
| 182 | if (err < 0) |
| 183 | return err; |
| 184 | |
| 185 | err = get_user(dest->cmdbuf.offset, &src->cmdbuf.offset); |
| 186 | if (err < 0) |
| 187 | return err; |
| 188 | |
| 189 | err = get_user(target, &src->target.handle); |
| 190 | if (err < 0) |
| 191 | return err; |
| 192 | |
| 193 | err = get_user(dest->target.offset, &src->cmdbuf.offset); |
| 194 | if (err < 0) |
| 195 | return err; |
| 196 | |
| 197 | err = get_user(dest->shift, &src->shift); |
| 198 | if (err < 0) |
| 199 | return err; |
| 200 | |
| 201 | dest->cmdbuf.bo = host1x_bo_lookup(drm, file, cmdbuf); |
| 202 | if (!dest->cmdbuf.bo) |
| 203 | return -ENOENT; |
| 204 | |
| 205 | dest->target.bo = host1x_bo_lookup(drm, file, target); |
| 206 | if (!dest->target.bo) |
| 207 | return -ENOENT; |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 212 | int tegra_drm_submit(struct tegra_drm_context *context, |
| 213 | struct drm_tegra_submit *args, struct drm_device *drm, |
| 214 | struct drm_file *file) |
| 215 | { |
| 216 | unsigned int num_cmdbufs = args->num_cmdbufs; |
| 217 | unsigned int num_relocs = args->num_relocs; |
| 218 | unsigned int num_waitchks = args->num_waitchks; |
| 219 | struct drm_tegra_cmdbuf __user *cmdbufs = |
Thierry Reding | a7ed68f | 2013-11-08 13:15:43 +0100 | [diff] [blame] | 220 | (void __user *)(uintptr_t)args->cmdbufs; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 221 | struct drm_tegra_reloc __user *relocs = |
Thierry Reding | a7ed68f | 2013-11-08 13:15:43 +0100 | [diff] [blame] | 222 | (void __user *)(uintptr_t)args->relocs; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 223 | struct drm_tegra_waitchk __user *waitchks = |
Thierry Reding | a7ed68f | 2013-11-08 13:15:43 +0100 | [diff] [blame] | 224 | (void __user *)(uintptr_t)args->waitchks; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 225 | struct drm_tegra_syncpt syncpt; |
| 226 | struct host1x_job *job; |
| 227 | int err; |
| 228 | |
| 229 | /* We don't yet support other than one syncpt_incr struct per submit */ |
| 230 | if (args->num_syncpts != 1) |
| 231 | return -EINVAL; |
| 232 | |
| 233 | job = host1x_job_alloc(context->channel, args->num_cmdbufs, |
| 234 | args->num_relocs, args->num_waitchks); |
| 235 | if (!job) |
| 236 | return -ENOMEM; |
| 237 | |
| 238 | job->num_relocs = args->num_relocs; |
| 239 | job->num_waitchk = args->num_waitchks; |
| 240 | job->client = (u32)args->context; |
| 241 | job->class = context->client->base.class; |
| 242 | job->serialize = true; |
| 243 | |
| 244 | while (num_cmdbufs) { |
| 245 | struct drm_tegra_cmdbuf cmdbuf; |
| 246 | struct host1x_bo *bo; |
| 247 | |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 248 | if (copy_from_user(&cmdbuf, cmdbufs, sizeof(cmdbuf))) { |
| 249 | err = -EFAULT; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 250 | goto fail; |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 251 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 252 | |
| 253 | bo = host1x_bo_lookup(drm, file, cmdbuf.handle); |
| 254 | if (!bo) { |
| 255 | err = -ENOENT; |
| 256 | goto fail; |
| 257 | } |
| 258 | |
| 259 | host1x_job_add_gather(job, bo, cmdbuf.words, cmdbuf.offset); |
| 260 | num_cmdbufs--; |
| 261 | cmdbufs++; |
| 262 | } |
| 263 | |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 264 | /* copy and resolve relocations from submit */ |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 265 | while (num_relocs--) { |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 266 | err = host1x_reloc_copy_from_user(&job->relocarray[num_relocs], |
| 267 | &relocs[num_relocs], drm, |
| 268 | file); |
| 269 | if (err < 0) |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 270 | goto fail; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 273 | if (copy_from_user(job->waitchk, waitchks, |
| 274 | sizeof(*waitchks) * num_waitchks)) { |
| 275 | err = -EFAULT; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 276 | goto fail; |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 277 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 278 | |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 279 | if (copy_from_user(&syncpt, (void __user *)(uintptr_t)args->syncpts, |
| 280 | sizeof(syncpt))) { |
| 281 | err = -EFAULT; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 282 | goto fail; |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 283 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 284 | |
| 285 | job->is_addr_reg = context->client->ops->is_addr_reg; |
| 286 | job->syncpt_incrs = syncpt.incrs; |
| 287 | job->syncpt_id = syncpt.id; |
| 288 | job->timeout = 10000; |
| 289 | |
| 290 | if (args->timeout && args->timeout < 10000) |
| 291 | job->timeout = args->timeout; |
| 292 | |
| 293 | err = host1x_job_pin(job, context->client->base.dev); |
| 294 | if (err) |
| 295 | goto fail; |
| 296 | |
| 297 | err = host1x_job_submit(job); |
| 298 | if (err) |
| 299 | goto fail_submit; |
| 300 | |
| 301 | args->fence = job->syncpt_end; |
| 302 | |
| 303 | host1x_job_put(job); |
| 304 | return 0; |
| 305 | |
| 306 | fail_submit: |
| 307 | host1x_job_unpin(job); |
| 308 | fail: |
| 309 | host1x_job_put(job); |
| 310 | return err; |
| 311 | } |
| 312 | |
| 313 | |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 314 | #ifdef CONFIG_DRM_TEGRA_STAGING |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 315 | static struct tegra_drm_context *tegra_drm_get_context(__u64 context) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 316 | { |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 317 | return (struct tegra_drm_context *)(uintptr_t)context; |
| 318 | } |
| 319 | |
| 320 | static bool tegra_drm_file_owns_context(struct tegra_drm_file *file, |
| 321 | struct tegra_drm_context *context) |
| 322 | { |
| 323 | struct tegra_drm_context *ctx; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 324 | |
| 325 | list_for_each_entry(ctx, &file->contexts, list) |
| 326 | if (ctx == context) |
| 327 | return true; |
| 328 | |
| 329 | return false; |
| 330 | } |
| 331 | |
| 332 | static int tegra_gem_create(struct drm_device *drm, void *data, |
| 333 | struct drm_file *file) |
| 334 | { |
| 335 | struct drm_tegra_gem_create *args = data; |
| 336 | struct tegra_bo *bo; |
| 337 | |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 338 | bo = tegra_bo_create_with_handle(file, drm, args->size, args->flags, |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 339 | &args->handle); |
| 340 | if (IS_ERR(bo)) |
| 341 | return PTR_ERR(bo); |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static int tegra_gem_mmap(struct drm_device *drm, void *data, |
| 347 | struct drm_file *file) |
| 348 | { |
| 349 | struct drm_tegra_gem_mmap *args = data; |
| 350 | struct drm_gem_object *gem; |
| 351 | struct tegra_bo *bo; |
| 352 | |
| 353 | gem = drm_gem_object_lookup(drm, file, args->handle); |
| 354 | if (!gem) |
| 355 | return -EINVAL; |
| 356 | |
| 357 | bo = to_tegra_bo(gem); |
| 358 | |
David Herrmann | 2bc7b0c | 2013-08-13 14:19:58 +0200 | [diff] [blame] | 359 | args->offset = drm_vma_node_offset_addr(&bo->gem.vma_node); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 360 | |
| 361 | drm_gem_object_unreference(gem); |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static int tegra_syncpt_read(struct drm_device *drm, void *data, |
| 367 | struct drm_file *file) |
| 368 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 369 | struct host1x *host = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 370 | struct drm_tegra_syncpt_read *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 371 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 372 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 373 | sp = host1x_syncpt_get(host, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 374 | if (!sp) |
| 375 | return -EINVAL; |
| 376 | |
| 377 | args->value = host1x_syncpt_read_min(sp); |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | static int tegra_syncpt_incr(struct drm_device *drm, void *data, |
| 382 | struct drm_file *file) |
| 383 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 384 | struct host1x *host1x = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 385 | struct drm_tegra_syncpt_incr *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 386 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 387 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 388 | sp = host1x_syncpt_get(host1x, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 389 | if (!sp) |
| 390 | return -EINVAL; |
| 391 | |
Arto Merilainen | ebae30b | 2013-05-29 13:26:08 +0300 | [diff] [blame] | 392 | return host1x_syncpt_incr(sp); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static int tegra_syncpt_wait(struct drm_device *drm, void *data, |
| 396 | struct drm_file *file) |
| 397 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 398 | struct host1x *host1x = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 399 | struct drm_tegra_syncpt_wait *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 400 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 401 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 402 | sp = host1x_syncpt_get(host1x, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 403 | if (!sp) |
| 404 | return -EINVAL; |
| 405 | |
| 406 | return host1x_syncpt_wait(sp, args->thresh, args->timeout, |
| 407 | &args->value); |
| 408 | } |
| 409 | |
| 410 | static int tegra_open_channel(struct drm_device *drm, void *data, |
| 411 | struct drm_file *file) |
| 412 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 413 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 414 | struct tegra_drm *tegra = drm->dev_private; |
| 415 | struct drm_tegra_open_channel *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 416 | struct tegra_drm_context *context; |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 417 | struct tegra_drm_client *client; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 418 | int err = -ENODEV; |
| 419 | |
| 420 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 421 | if (!context) |
| 422 | return -ENOMEM; |
| 423 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 424 | list_for_each_entry(client, &tegra->clients, list) |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 425 | if (client->base.class == args->client) { |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 426 | err = client->ops->open_channel(client, context); |
| 427 | if (err) |
| 428 | break; |
| 429 | |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 430 | list_add(&context->list, &fpriv->contexts); |
| 431 | args->context = (uintptr_t)context; |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 432 | context->client = client; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | kfree(context); |
| 437 | return err; |
| 438 | } |
| 439 | |
| 440 | static int tegra_close_channel(struct drm_device *drm, void *data, |
| 441 | struct drm_file *file) |
| 442 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 443 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 444 | struct drm_tegra_close_channel *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 445 | struct tegra_drm_context *context; |
| 446 | |
| 447 | context = tegra_drm_get_context(args->context); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 448 | |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 449 | if (!tegra_drm_file_owns_context(fpriv, context)) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 450 | return -EINVAL; |
| 451 | |
| 452 | list_del(&context->list); |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 453 | tegra_drm_context_free(context); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int tegra_get_syncpt(struct drm_device *drm, void *data, |
| 459 | struct drm_file *file) |
| 460 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 461 | struct tegra_drm_file *fpriv = file->driver_priv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 462 | struct drm_tegra_get_syncpt *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 463 | struct tegra_drm_context *context; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 464 | struct host1x_syncpt *syncpt; |
| 465 | |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 466 | context = tegra_drm_get_context(args->context); |
| 467 | |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 468 | if (!tegra_drm_file_owns_context(fpriv, context)) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 469 | return -ENODEV; |
| 470 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 471 | if (args->index >= context->client->base.num_syncpts) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 472 | return -EINVAL; |
| 473 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 474 | syncpt = context->client->base.syncpts[args->index]; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 475 | args->id = host1x_syncpt_id(syncpt); |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static int tegra_submit(struct drm_device *drm, void *data, |
| 481 | struct drm_file *file) |
| 482 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 483 | struct tegra_drm_file *fpriv = file->driver_priv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 484 | struct drm_tegra_submit *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 485 | struct tegra_drm_context *context; |
| 486 | |
| 487 | context = tegra_drm_get_context(args->context); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 488 | |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 489 | if (!tegra_drm_file_owns_context(fpriv, context)) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 490 | return -ENODEV; |
| 491 | |
| 492 | return context->client->ops->submit(context, args, drm, file); |
| 493 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 494 | |
| 495 | static int tegra_get_syncpt_base(struct drm_device *drm, void *data, |
| 496 | struct drm_file *file) |
| 497 | { |
| 498 | struct tegra_drm_file *fpriv = file->driver_priv; |
| 499 | struct drm_tegra_get_syncpt_base *args = data; |
| 500 | struct tegra_drm_context *context; |
| 501 | struct host1x_syncpt_base *base; |
| 502 | struct host1x_syncpt *syncpt; |
| 503 | |
| 504 | context = tegra_drm_get_context(args->context); |
| 505 | |
| 506 | if (!tegra_drm_file_owns_context(fpriv, context)) |
| 507 | return -ENODEV; |
| 508 | |
| 509 | if (args->syncpt >= context->client->base.num_syncpts) |
| 510 | return -EINVAL; |
| 511 | |
| 512 | syncpt = context->client->base.syncpts[args->syncpt]; |
| 513 | |
| 514 | base = host1x_syncpt_get_base(syncpt); |
| 515 | if (!base) |
| 516 | return -ENXIO; |
| 517 | |
| 518 | args->id = host1x_syncpt_base_id(base); |
| 519 | |
| 520 | return 0; |
| 521 | } |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 522 | |
| 523 | static int tegra_gem_set_tiling(struct drm_device *drm, void *data, |
| 524 | struct drm_file *file) |
| 525 | { |
| 526 | struct drm_tegra_gem_set_tiling *args = data; |
| 527 | enum tegra_bo_tiling_mode mode; |
| 528 | struct drm_gem_object *gem; |
| 529 | unsigned long value = 0; |
| 530 | struct tegra_bo *bo; |
| 531 | |
| 532 | switch (args->mode) { |
| 533 | case DRM_TEGRA_GEM_TILING_MODE_PITCH: |
| 534 | mode = TEGRA_BO_TILING_MODE_PITCH; |
| 535 | |
| 536 | if (args->value != 0) |
| 537 | return -EINVAL; |
| 538 | |
| 539 | break; |
| 540 | |
| 541 | case DRM_TEGRA_GEM_TILING_MODE_TILED: |
| 542 | mode = TEGRA_BO_TILING_MODE_TILED; |
| 543 | |
| 544 | if (args->value != 0) |
| 545 | return -EINVAL; |
| 546 | |
| 547 | break; |
| 548 | |
| 549 | case DRM_TEGRA_GEM_TILING_MODE_BLOCK: |
| 550 | mode = TEGRA_BO_TILING_MODE_BLOCK; |
| 551 | |
| 552 | if (args->value > 5) |
| 553 | return -EINVAL; |
| 554 | |
| 555 | value = args->value; |
| 556 | break; |
| 557 | |
| 558 | default: |
| 559 | return -EINVAL; |
| 560 | } |
| 561 | |
| 562 | gem = drm_gem_object_lookup(drm, file, args->handle); |
| 563 | if (!gem) |
| 564 | return -ENOENT; |
| 565 | |
| 566 | bo = to_tegra_bo(gem); |
| 567 | |
| 568 | bo->tiling.mode = mode; |
| 569 | bo->tiling.value = value; |
| 570 | |
| 571 | drm_gem_object_unreference(gem); |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | static int tegra_gem_get_tiling(struct drm_device *drm, void *data, |
| 577 | struct drm_file *file) |
| 578 | { |
| 579 | struct drm_tegra_gem_get_tiling *args = data; |
| 580 | struct drm_gem_object *gem; |
| 581 | struct tegra_bo *bo; |
| 582 | int err = 0; |
| 583 | |
| 584 | gem = drm_gem_object_lookup(drm, file, args->handle); |
| 585 | if (!gem) |
| 586 | return -ENOENT; |
| 587 | |
| 588 | bo = to_tegra_bo(gem); |
| 589 | |
| 590 | switch (bo->tiling.mode) { |
| 591 | case TEGRA_BO_TILING_MODE_PITCH: |
| 592 | args->mode = DRM_TEGRA_GEM_TILING_MODE_PITCH; |
| 593 | args->value = 0; |
| 594 | break; |
| 595 | |
| 596 | case TEGRA_BO_TILING_MODE_TILED: |
| 597 | args->mode = DRM_TEGRA_GEM_TILING_MODE_TILED; |
| 598 | args->value = 0; |
| 599 | break; |
| 600 | |
| 601 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 602 | args->mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK; |
| 603 | args->value = bo->tiling.value; |
| 604 | break; |
| 605 | |
| 606 | default: |
| 607 | err = -EINVAL; |
| 608 | break; |
| 609 | } |
| 610 | |
| 611 | drm_gem_object_unreference(gem); |
| 612 | |
| 613 | return err; |
| 614 | } |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 615 | |
| 616 | static int tegra_gem_set_flags(struct drm_device *drm, void *data, |
| 617 | struct drm_file *file) |
| 618 | { |
| 619 | struct drm_tegra_gem_set_flags *args = data; |
| 620 | struct drm_gem_object *gem; |
| 621 | struct tegra_bo *bo; |
| 622 | |
| 623 | if (args->flags & ~DRM_TEGRA_GEM_FLAGS) |
| 624 | return -EINVAL; |
| 625 | |
| 626 | gem = drm_gem_object_lookup(drm, file, args->handle); |
| 627 | if (!gem) |
| 628 | return -ENOENT; |
| 629 | |
| 630 | bo = to_tegra_bo(gem); |
| 631 | bo->flags = 0; |
| 632 | |
| 633 | if (args->flags & DRM_TEGRA_GEM_BOTTOM_UP) |
| 634 | bo->flags |= TEGRA_BO_BOTTOM_UP; |
| 635 | |
| 636 | drm_gem_object_unreference(gem); |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | static int tegra_gem_get_flags(struct drm_device *drm, void *data, |
| 642 | struct drm_file *file) |
| 643 | { |
| 644 | struct drm_tegra_gem_get_flags *args = data; |
| 645 | struct drm_gem_object *gem; |
| 646 | struct tegra_bo *bo; |
| 647 | |
| 648 | gem = drm_gem_object_lookup(drm, file, args->handle); |
| 649 | if (!gem) |
| 650 | return -ENOENT; |
| 651 | |
| 652 | bo = to_tegra_bo(gem); |
| 653 | args->flags = 0; |
| 654 | |
| 655 | if (bo->flags & TEGRA_BO_BOTTOM_UP) |
| 656 | args->flags |= DRM_TEGRA_GEM_BOTTOM_UP; |
| 657 | |
| 658 | drm_gem_object_unreference(gem); |
| 659 | |
| 660 | return 0; |
| 661 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 662 | #endif |
| 663 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 664 | static const struct drm_ioctl_desc tegra_drm_ioctls[] = { |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 665 | #ifdef CONFIG_DRM_TEGRA_STAGING |
Thierry Reding | bd4f236 | 2014-06-03 14:59:29 +0200 | [diff] [blame] | 666 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_CREATE, tegra_gem_create, DRM_UNLOCKED), |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 667 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_gem_mmap, DRM_UNLOCKED), |
| 668 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_READ, tegra_syncpt_read, DRM_UNLOCKED), |
| 669 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_INCR, tegra_syncpt_incr, DRM_UNLOCKED), |
| 670 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_WAIT, tegra_syncpt_wait, DRM_UNLOCKED), |
| 671 | DRM_IOCTL_DEF_DRV(TEGRA_OPEN_CHANNEL, tegra_open_channel, DRM_UNLOCKED), |
| 672 | DRM_IOCTL_DEF_DRV(TEGRA_CLOSE_CHANNEL, tegra_close_channel, DRM_UNLOCKED), |
| 673 | DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT, tegra_get_syncpt, DRM_UNLOCKED), |
| 674 | DRM_IOCTL_DEF_DRV(TEGRA_SUBMIT, tegra_submit, DRM_UNLOCKED), |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 675 | DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT_BASE, tegra_get_syncpt_base, DRM_UNLOCKED), |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 676 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_TILING, tegra_gem_set_tiling, DRM_UNLOCKED), |
| 677 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_TILING, tegra_gem_get_tiling, DRM_UNLOCKED), |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 678 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_FLAGS, tegra_gem_set_flags, DRM_UNLOCKED), |
| 679 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_FLAGS, tegra_gem_get_flags, DRM_UNLOCKED), |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 680 | #endif |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 681 | }; |
| 682 | |
| 683 | static const struct file_operations tegra_drm_fops = { |
| 684 | .owner = THIS_MODULE, |
| 685 | .open = drm_open, |
| 686 | .release = drm_release, |
| 687 | .unlocked_ioctl = drm_ioctl, |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 688 | .mmap = tegra_drm_mmap, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 689 | .poll = drm_poll, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 690 | .read = drm_read, |
| 691 | #ifdef CONFIG_COMPAT |
| 692 | .compat_ioctl = drm_compat_ioctl, |
| 693 | #endif |
| 694 | .llseek = noop_llseek, |
| 695 | }; |
| 696 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 697 | static struct drm_crtc *tegra_crtc_from_pipe(struct drm_device *drm, int pipe) |
| 698 | { |
| 699 | struct drm_crtc *crtc; |
| 700 | |
| 701 | list_for_each_entry(crtc, &drm->mode_config.crtc_list, head) { |
| 702 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 703 | |
| 704 | if (dc->pipe == pipe) |
| 705 | return crtc; |
| 706 | } |
| 707 | |
| 708 | return NULL; |
| 709 | } |
| 710 | |
| 711 | static u32 tegra_drm_get_vblank_counter(struct drm_device *dev, int crtc) |
| 712 | { |
| 713 | /* TODO: implement real hardware counter using syncpoints */ |
| 714 | return drm_vblank_count(dev, crtc); |
| 715 | } |
| 716 | |
| 717 | static int tegra_drm_enable_vblank(struct drm_device *drm, int pipe) |
| 718 | { |
| 719 | struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe); |
| 720 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 721 | |
| 722 | if (!crtc) |
| 723 | return -ENODEV; |
| 724 | |
| 725 | tegra_dc_enable_vblank(dc); |
| 726 | |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | static void tegra_drm_disable_vblank(struct drm_device *drm, int pipe) |
| 731 | { |
| 732 | struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe); |
| 733 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 734 | |
| 735 | if (crtc) |
| 736 | tegra_dc_disable_vblank(dc); |
| 737 | } |
| 738 | |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 739 | static void tegra_drm_preclose(struct drm_device *drm, struct drm_file *file) |
| 740 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 741 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 742 | struct tegra_drm_context *context, *tmp; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 743 | struct drm_crtc *crtc; |
| 744 | |
| 745 | list_for_each_entry(crtc, &drm->mode_config.crtc_list, head) |
| 746 | tegra_dc_cancel_page_flip(crtc, file); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 747 | |
| 748 | list_for_each_entry_safe(context, tmp, &fpriv->contexts, list) |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 749 | tegra_drm_context_free(context); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 750 | |
| 751 | kfree(fpriv); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 752 | } |
| 753 | |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 754 | #ifdef CONFIG_DEBUG_FS |
| 755 | static int tegra_debugfs_framebuffers(struct seq_file *s, void *data) |
| 756 | { |
| 757 | struct drm_info_node *node = (struct drm_info_node *)s->private; |
| 758 | struct drm_device *drm = node->minor->dev; |
| 759 | struct drm_framebuffer *fb; |
| 760 | |
| 761 | mutex_lock(&drm->mode_config.fb_lock); |
| 762 | |
| 763 | list_for_each_entry(fb, &drm->mode_config.fb_list, head) { |
| 764 | seq_printf(s, "%3d: user size: %d x %d, depth %d, %d bpp, refcount %d\n", |
| 765 | fb->base.id, fb->width, fb->height, fb->depth, |
| 766 | fb->bits_per_pixel, |
| 767 | atomic_read(&fb->refcount.refcount)); |
| 768 | } |
| 769 | |
| 770 | mutex_unlock(&drm->mode_config.fb_lock); |
| 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static struct drm_info_list tegra_debugfs_list[] = { |
| 776 | { "framebuffers", tegra_debugfs_framebuffers, 0 }, |
| 777 | }; |
| 778 | |
| 779 | static int tegra_debugfs_init(struct drm_minor *minor) |
| 780 | { |
| 781 | return drm_debugfs_create_files(tegra_debugfs_list, |
| 782 | ARRAY_SIZE(tegra_debugfs_list), |
| 783 | minor->debugfs_root, minor); |
| 784 | } |
| 785 | |
| 786 | static void tegra_debugfs_cleanup(struct drm_minor *minor) |
| 787 | { |
| 788 | drm_debugfs_remove_files(tegra_debugfs_list, |
| 789 | ARRAY_SIZE(tegra_debugfs_list), minor); |
| 790 | } |
| 791 | #endif |
| 792 | |
Thierry Reding | 9b57f5f | 2013-11-08 13:17:14 +0100 | [diff] [blame] | 793 | static struct drm_driver tegra_drm_driver = { |
Thierry Reding | 3800391 | 2013-12-12 10:00:43 +0100 | [diff] [blame] | 794 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 795 | .load = tegra_drm_load, |
| 796 | .unload = tegra_drm_unload, |
| 797 | .open = tegra_drm_open, |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 798 | .preclose = tegra_drm_preclose, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 799 | .lastclose = tegra_drm_lastclose, |
| 800 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 801 | .get_vblank_counter = tegra_drm_get_vblank_counter, |
| 802 | .enable_vblank = tegra_drm_enable_vblank, |
| 803 | .disable_vblank = tegra_drm_disable_vblank, |
| 804 | |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 805 | #if defined(CONFIG_DEBUG_FS) |
| 806 | .debugfs_init = tegra_debugfs_init, |
| 807 | .debugfs_cleanup = tegra_debugfs_cleanup, |
| 808 | #endif |
| 809 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 810 | .gem_free_object = tegra_bo_free_object, |
| 811 | .gem_vm_ops = &tegra_bo_vm_ops, |
Thierry Reding | 3800391 | 2013-12-12 10:00:43 +0100 | [diff] [blame] | 812 | |
| 813 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 814 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 815 | .gem_prime_export = tegra_gem_prime_export, |
| 816 | .gem_prime_import = tegra_gem_prime_import, |
| 817 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 818 | .dumb_create = tegra_bo_dumb_create, |
| 819 | .dumb_map_offset = tegra_bo_dumb_map_offset, |
Daniel Vetter | 43387b3 | 2013-07-16 09:12:04 +0200 | [diff] [blame] | 820 | .dumb_destroy = drm_gem_dumb_destroy, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 821 | |
| 822 | .ioctls = tegra_drm_ioctls, |
| 823 | .num_ioctls = ARRAY_SIZE(tegra_drm_ioctls), |
| 824 | .fops = &tegra_drm_fops, |
| 825 | |
| 826 | .name = DRIVER_NAME, |
| 827 | .desc = DRIVER_DESC, |
| 828 | .date = DRIVER_DATE, |
| 829 | .major = DRIVER_MAJOR, |
| 830 | .minor = DRIVER_MINOR, |
| 831 | .patchlevel = DRIVER_PATCHLEVEL, |
| 832 | }; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 833 | |
| 834 | int tegra_drm_register_client(struct tegra_drm *tegra, |
| 835 | struct tegra_drm_client *client) |
| 836 | { |
| 837 | mutex_lock(&tegra->clients_lock); |
| 838 | list_add_tail(&client->list, &tegra->clients); |
| 839 | mutex_unlock(&tegra->clients_lock); |
| 840 | |
| 841 | return 0; |
| 842 | } |
| 843 | |
| 844 | int tegra_drm_unregister_client(struct tegra_drm *tegra, |
| 845 | struct tegra_drm_client *client) |
| 846 | { |
| 847 | mutex_lock(&tegra->clients_lock); |
| 848 | list_del_init(&client->list); |
| 849 | mutex_unlock(&tegra->clients_lock); |
| 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 854 | static int host1x_drm_probe(struct host1x_device *dev) |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 855 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 856 | struct drm_driver *driver = &tegra_drm_driver; |
| 857 | struct drm_device *drm; |
| 858 | int err; |
| 859 | |
| 860 | drm = drm_dev_alloc(driver, &dev->dev); |
| 861 | if (!drm) |
| 862 | return -ENOMEM; |
| 863 | |
| 864 | drm_dev_set_unique(drm, dev_name(&dev->dev)); |
| 865 | dev_set_drvdata(&dev->dev, drm); |
| 866 | |
| 867 | err = drm_dev_register(drm, 0); |
| 868 | if (err < 0) |
| 869 | goto unref; |
| 870 | |
| 871 | DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", driver->name, |
| 872 | driver->major, driver->minor, driver->patchlevel, |
| 873 | driver->date, drm->primary->index); |
| 874 | |
| 875 | return 0; |
| 876 | |
| 877 | unref: |
| 878 | drm_dev_unref(drm); |
| 879 | return err; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 880 | } |
| 881 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 882 | static int host1x_drm_remove(struct host1x_device *dev) |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 883 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 884 | struct drm_device *drm = dev_get_drvdata(&dev->dev); |
| 885 | |
| 886 | drm_dev_unregister(drm); |
| 887 | drm_dev_unref(drm); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | static const struct of_device_id host1x_drm_subdevs[] = { |
| 893 | { .compatible = "nvidia,tegra20-dc", }, |
| 894 | { .compatible = "nvidia,tegra20-hdmi", }, |
| 895 | { .compatible = "nvidia,tegra20-gr2d", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 896 | { .compatible = "nvidia,tegra20-gr3d", }, |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 897 | { .compatible = "nvidia,tegra30-dc", }, |
| 898 | { .compatible = "nvidia,tegra30-hdmi", }, |
| 899 | { .compatible = "nvidia,tegra30-gr2d", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 900 | { .compatible = "nvidia,tegra30-gr3d", }, |
Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 901 | { .compatible = "nvidia,tegra114-dsi", }, |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 902 | { .compatible = "nvidia,tegra114-hdmi", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 903 | { .compatible = "nvidia,tegra114-gr3d", }, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 904 | { .compatible = "nvidia,tegra124-dc", }, |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 905 | { .compatible = "nvidia,tegra124-sor", }, |
Thierry Reding | fb7be70 | 2013-11-15 16:07:32 +0100 | [diff] [blame] | 906 | { .compatible = "nvidia,tegra124-hdmi", }, |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 907 | { /* sentinel */ } |
| 908 | }; |
| 909 | |
| 910 | static struct host1x_driver host1x_drm_driver = { |
| 911 | .name = "drm", |
| 912 | .probe = host1x_drm_probe, |
| 913 | .remove = host1x_drm_remove, |
| 914 | .subdevs = host1x_drm_subdevs, |
| 915 | }; |
| 916 | |
| 917 | static int __init host1x_drm_init(void) |
| 918 | { |
| 919 | int err; |
| 920 | |
| 921 | err = host1x_driver_register(&host1x_drm_driver); |
| 922 | if (err < 0) |
| 923 | return err; |
| 924 | |
| 925 | err = platform_driver_register(&tegra_dc_driver); |
| 926 | if (err < 0) |
| 927 | goto unregister_host1x; |
| 928 | |
Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 929 | err = platform_driver_register(&tegra_dsi_driver); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 930 | if (err < 0) |
| 931 | goto unregister_dc; |
| 932 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 933 | err = platform_driver_register(&tegra_sor_driver); |
Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 934 | if (err < 0) |
| 935 | goto unregister_dsi; |
| 936 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 937 | err = platform_driver_register(&tegra_hdmi_driver); |
| 938 | if (err < 0) |
| 939 | goto unregister_sor; |
| 940 | |
| 941 | err = platform_driver_register(&tegra_dpaux_driver); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 942 | if (err < 0) |
| 943 | goto unregister_hdmi; |
| 944 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 945 | err = platform_driver_register(&tegra_gr2d_driver); |
| 946 | if (err < 0) |
| 947 | goto unregister_dpaux; |
| 948 | |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 949 | err = platform_driver_register(&tegra_gr3d_driver); |
| 950 | if (err < 0) |
| 951 | goto unregister_gr2d; |
| 952 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 953 | return 0; |
| 954 | |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 955 | unregister_gr2d: |
| 956 | platform_driver_unregister(&tegra_gr2d_driver); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 957 | unregister_dpaux: |
| 958 | platform_driver_unregister(&tegra_dpaux_driver); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 959 | unregister_hdmi: |
| 960 | platform_driver_unregister(&tegra_hdmi_driver); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 961 | unregister_sor: |
| 962 | platform_driver_unregister(&tegra_sor_driver); |
Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 963 | unregister_dsi: |
| 964 | platform_driver_unregister(&tegra_dsi_driver); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 965 | unregister_dc: |
| 966 | platform_driver_unregister(&tegra_dc_driver); |
| 967 | unregister_host1x: |
| 968 | host1x_driver_unregister(&host1x_drm_driver); |
| 969 | return err; |
| 970 | } |
| 971 | module_init(host1x_drm_init); |
| 972 | |
| 973 | static void __exit host1x_drm_exit(void) |
| 974 | { |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 975 | platform_driver_unregister(&tegra_gr3d_driver); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 976 | platform_driver_unregister(&tegra_gr2d_driver); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 977 | platform_driver_unregister(&tegra_dpaux_driver); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 978 | platform_driver_unregister(&tegra_hdmi_driver); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 979 | platform_driver_unregister(&tegra_sor_driver); |
Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 980 | platform_driver_unregister(&tegra_dsi_driver); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 981 | platform_driver_unregister(&tegra_dc_driver); |
| 982 | host1x_driver_unregister(&host1x_drm_driver); |
| 983 | } |
| 984 | module_exit(host1x_drm_exit); |
| 985 | |
| 986 | MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); |
| 987 | MODULE_DESCRIPTION("NVIDIA Tegra DRM driver"); |
| 988 | MODULE_LICENSE("GPL v2"); |