Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Avionic Design GmbH |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 3 | * Copyright (C) 2012-2016 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 | |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 10 | #include <linux/bitops.h> |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 11 | #include <linux/host1x.h> |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 12 | #include <linux/idr.h> |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 13 | #include <linux/iommu.h> |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 14 | |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 15 | #include <drm/drm_atomic.h> |
Thierry Reding | 0786696 | 2014-11-24 17:08:06 +0100 | [diff] [blame] | 16 | #include <drm/drm_atomic_helper.h> |
| 17 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 18 | #include "drm.h" |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 19 | #include "gem.h" |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 20 | |
| 21 | #define DRIVER_NAME "tegra" |
| 22 | #define DRIVER_DESC "NVIDIA Tegra graphics" |
| 23 | #define DRIVER_DATE "20120330" |
| 24 | #define DRIVER_MAJOR 0 |
| 25 | #define DRIVER_MINOR 0 |
| 26 | #define DRIVER_PATCHLEVEL 0 |
| 27 | |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 28 | #define CARVEOUT_SZ SZ_64M |
| 29 | |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 30 | struct tegra_drm_file { |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 31 | struct idr contexts; |
| 32 | struct mutex lock; |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 33 | }; |
| 34 | |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 35 | static void tegra_atomic_schedule(struct tegra_drm *tegra, |
| 36 | struct drm_atomic_state *state) |
| 37 | { |
| 38 | tegra->commit.state = state; |
| 39 | schedule_work(&tegra->commit.work); |
| 40 | } |
| 41 | |
| 42 | static void tegra_atomic_complete(struct tegra_drm *tegra, |
| 43 | struct drm_atomic_state *state) |
| 44 | { |
| 45 | struct drm_device *drm = tegra->drm; |
| 46 | |
| 47 | /* |
| 48 | * Everything below can be run asynchronously without the need to grab |
| 49 | * any modeset locks at all under one condition: It must be guaranteed |
| 50 | * that the asynchronous work has either been cancelled (if the driver |
| 51 | * supports it, which at least requires that the framebuffers get |
| 52 | * cleaned up with drm_atomic_helper_cleanup_planes()) or completed |
| 53 | * before the new state gets committed on the software side with |
| 54 | * drm_atomic_helper_swap_state(). |
| 55 | * |
| 56 | * This scheme allows new atomic state updates to be prepared and |
| 57 | * checked in parallel to the asynchronous completion of the previous |
| 58 | * update. Which is important since compositors need to figure out the |
| 59 | * composition of the next frame right after having submitted the |
| 60 | * current layout. |
| 61 | */ |
| 62 | |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 63 | drm_atomic_helper_commit_modeset_disables(drm, state); |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 64 | drm_atomic_helper_commit_modeset_enables(drm, state); |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 65 | drm_atomic_helper_commit_planes(drm, state, |
| 66 | DRM_PLANE_COMMIT_ACTIVE_ONLY); |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 67 | |
| 68 | drm_atomic_helper_wait_for_vblanks(drm, state); |
| 69 | |
| 70 | drm_atomic_helper_cleanup_planes(drm, state); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 71 | drm_atomic_state_put(state); |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static void tegra_atomic_work(struct work_struct *work) |
| 75 | { |
| 76 | struct tegra_drm *tegra = container_of(work, struct tegra_drm, |
| 77 | commit.work); |
| 78 | |
| 79 | tegra_atomic_complete(tegra, tegra->commit.state); |
| 80 | } |
| 81 | |
| 82 | static int tegra_atomic_commit(struct drm_device *drm, |
Maarten Lankhorst | 2dacdd7 | 2016-04-26 16:11:42 +0200 | [diff] [blame] | 83 | struct drm_atomic_state *state, bool nonblock) |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 84 | { |
| 85 | struct tegra_drm *tegra = drm->dev_private; |
| 86 | int err; |
| 87 | |
| 88 | err = drm_atomic_helper_prepare_planes(drm, state); |
| 89 | if (err) |
| 90 | return err; |
| 91 | |
Maarten Lankhorst | 2dacdd7 | 2016-04-26 16:11:42 +0200 | [diff] [blame] | 92 | /* serialize outstanding nonblocking commits */ |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 93 | mutex_lock(&tegra->commit.lock); |
| 94 | flush_work(&tegra->commit.work); |
| 95 | |
| 96 | /* |
| 97 | * This is the point of no return - everything below never fails except |
| 98 | * when the hw goes bonghits. Which means we can commit the new state on |
| 99 | * the software side now. |
| 100 | */ |
| 101 | |
Daniel Vetter | 5e84c26 | 2016-06-10 00:06:32 +0200 | [diff] [blame] | 102 | drm_atomic_helper_swap_state(state, true); |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 103 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 104 | drm_atomic_state_get(state); |
Maarten Lankhorst | 2dacdd7 | 2016-04-26 16:11:42 +0200 | [diff] [blame] | 105 | if (nonblock) |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 106 | tegra_atomic_schedule(tegra, state); |
| 107 | else |
| 108 | tegra_atomic_complete(tegra, state); |
| 109 | |
| 110 | mutex_unlock(&tegra->commit.lock); |
| 111 | return 0; |
| 112 | } |
| 113 | |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 114 | static const struct drm_mode_config_funcs tegra_drm_mode_funcs = { |
| 115 | .fb_create = tegra_fb_create, |
Archit Taneja | b110ef3 | 2015-10-27 13:40:59 +0530 | [diff] [blame] | 116 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 117 | .output_poll_changed = tegra_fb_output_poll_changed, |
| 118 | #endif |
Thierry Reding | 0786696 | 2014-11-24 17:08:06 +0100 | [diff] [blame] | 119 | .atomic_check = drm_atomic_helper_check, |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 120 | .atomic_commit = tegra_atomic_commit, |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 121 | }; |
| 122 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 123 | static int tegra_drm_load(struct drm_device *drm, unsigned long flags) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 124 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 125 | struct host1x_device *device = to_host1x_device(drm->dev); |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 126 | struct tegra_drm *tegra; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 127 | int err; |
| 128 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 129 | tegra = kzalloc(sizeof(*tegra), GFP_KERNEL); |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 130 | if (!tegra) |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 131 | return -ENOMEM; |
| 132 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 133 | if (iommu_present(&platform_bus_type)) { |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 134 | u64 carveout_start, carveout_end, gem_start, gem_end; |
Thierry Reding | 4553f73 | 2015-01-19 16:15:04 +0100 | [diff] [blame] | 135 | struct iommu_domain_geometry *geometry; |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 136 | unsigned long order; |
Thierry Reding | 4553f73 | 2015-01-19 16:15:04 +0100 | [diff] [blame] | 137 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 138 | tegra->domain = iommu_domain_alloc(&platform_bus_type); |
Dan Carpenter | bf19b88 | 2014-12-04 14:00:35 +0300 | [diff] [blame] | 139 | if (!tegra->domain) { |
| 140 | err = -ENOMEM; |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 141 | goto free; |
| 142 | } |
| 143 | |
Thierry Reding | 4553f73 | 2015-01-19 16:15:04 +0100 | [diff] [blame] | 144 | geometry = &tegra->domain->geometry; |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 145 | gem_start = geometry->aperture_start; |
| 146 | gem_end = geometry->aperture_end - CARVEOUT_SZ; |
| 147 | carveout_start = gem_end + 1; |
| 148 | carveout_end = geometry->aperture_end; |
Thierry Reding | 4553f73 | 2015-01-19 16:15:04 +0100 | [diff] [blame] | 149 | |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 150 | order = __ffs(tegra->domain->pgsize_bitmap); |
| 151 | init_iova_domain(&tegra->carveout.domain, 1UL << order, |
| 152 | carveout_start >> order, |
| 153 | carveout_end >> order); |
| 154 | |
| 155 | tegra->carveout.shift = iova_shift(&tegra->carveout.domain); |
| 156 | tegra->carveout.limit = carveout_end >> tegra->carveout.shift; |
| 157 | |
| 158 | drm_mm_init(&tegra->mm, gem_start, gem_end - gem_start + 1); |
Thierry Reding | 347ad49d | 2017-03-09 20:04:56 +0100 | [diff] [blame] | 159 | mutex_init(&tegra->mm_lock); |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 160 | |
| 161 | DRM_DEBUG("IOMMU apertures:\n"); |
| 162 | DRM_DEBUG(" GEM: %#llx-%#llx\n", gem_start, gem_end); |
| 163 | DRM_DEBUG(" Carveout: %#llx-%#llx\n", carveout_start, |
| 164 | carveout_end); |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 167 | mutex_init(&tegra->clients_lock); |
| 168 | INIT_LIST_HEAD(&tegra->clients); |
Thierry Reding | 1503ca4 | 2014-11-24 17:41:23 +0100 | [diff] [blame] | 169 | |
| 170 | mutex_init(&tegra->commit.lock); |
| 171 | INIT_WORK(&tegra->commit.work, tegra_atomic_work); |
| 172 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 173 | drm->dev_private = tegra; |
| 174 | tegra->drm = drm; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 175 | |
| 176 | drm_mode_config_init(drm); |
| 177 | |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 178 | drm->mode_config.min_width = 0; |
| 179 | drm->mode_config.min_height = 0; |
| 180 | |
| 181 | drm->mode_config.max_width = 4096; |
| 182 | drm->mode_config.max_height = 4096; |
| 183 | |
Alexandre Courbot | 5e91144 | 2016-11-08 16:50:42 +0900 | [diff] [blame] | 184 | drm->mode_config.allow_fb_modifiers = true; |
| 185 | |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 186 | drm->mode_config.funcs = &tegra_drm_mode_funcs; |
| 187 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 188 | err = tegra_drm_fb_prepare(drm); |
| 189 | if (err < 0) |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 190 | goto config; |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 191 | |
| 192 | drm_kms_helper_poll_init(drm); |
| 193 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 194 | err = host1x_device_init(device); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 195 | if (err < 0) |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 196 | goto fbdev; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 197 | |
Thierry Reding | 603f0cc | 2013-04-22 21:22:14 +0200 | [diff] [blame] | 198 | /* |
| 199 | * We don't use the drm_irq_install() helpers provided by the DRM |
| 200 | * core, so we need to set this manually in order to allow the |
| 201 | * DRM_IOCTL_WAIT_VBLANK to operate correctly. |
| 202 | */ |
Ville Syrjälä | 4423843 | 2013-10-04 14:53:37 +0300 | [diff] [blame] | 203 | drm->irq_enabled = true; |
Thierry Reding | 603f0cc | 2013-04-22 21:22:14 +0200 | [diff] [blame] | 204 | |
Thierry Reding | 42e9ce0 | 2015-01-28 14:43:05 +0100 | [diff] [blame] | 205 | /* syncpoints are used for full 32-bit hardware VBLANK counters */ |
Thierry Reding | 42e9ce0 | 2015-01-28 14:43:05 +0100 | [diff] [blame] | 206 | drm->max_vblank_count = 0xffffffff; |
| 207 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 208 | err = drm_vblank_init(drm, drm->mode_config.num_crtc); |
| 209 | if (err < 0) |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 210 | goto device; |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 211 | |
Thierry Reding | 31930d4 | 2015-07-02 17:04:06 +0200 | [diff] [blame] | 212 | drm_mode_config_reset(drm); |
| 213 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 214 | err = tegra_drm_fb_init(drm); |
| 215 | if (err < 0) |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 216 | goto vblank; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 217 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 218 | return 0; |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 219 | |
| 220 | vblank: |
| 221 | drm_vblank_cleanup(drm); |
| 222 | device: |
| 223 | host1x_device_exit(device); |
| 224 | fbdev: |
| 225 | drm_kms_helper_poll_fini(drm); |
| 226 | tegra_drm_fb_free(drm); |
| 227 | config: |
| 228 | drm_mode_config_cleanup(drm); |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 229 | |
| 230 | if (tegra->domain) { |
| 231 | iommu_domain_free(tegra->domain); |
| 232 | drm_mm_takedown(&tegra->mm); |
Thierry Reding | 347ad49d | 2017-03-09 20:04:56 +0100 | [diff] [blame] | 233 | mutex_destroy(&tegra->mm_lock); |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 234 | put_iova_domain(&tegra->carveout.domain); |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 235 | } |
| 236 | free: |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 237 | kfree(tegra); |
| 238 | return err; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Gabriel Krisman Bertazi | 11b3c20 | 2017-01-06 15:57:31 -0200 | [diff] [blame] | 241 | static void tegra_drm_unload(struct drm_device *drm) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 242 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 243 | struct host1x_device *device = to_host1x_device(drm->dev); |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 244 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 245 | int err; |
| 246 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 247 | drm_kms_helper_poll_fini(drm); |
| 248 | tegra_drm_fb_exit(drm); |
Thierry Reding | f002abc | 2013-10-14 14:06:02 +0200 | [diff] [blame] | 249 | drm_mode_config_cleanup(drm); |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame] | 250 | drm_vblank_cleanup(drm); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 251 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 252 | err = host1x_device_exit(device); |
| 253 | if (err < 0) |
Gabriel Krisman Bertazi | 11b3c20 | 2017-01-06 15:57:31 -0200 | [diff] [blame] | 254 | return; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 255 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 256 | if (tegra->domain) { |
| 257 | iommu_domain_free(tegra->domain); |
| 258 | drm_mm_takedown(&tegra->mm); |
Thierry Reding | 347ad49d | 2017-03-09 20:04:56 +0100 | [diff] [blame] | 259 | mutex_destroy(&tegra->mm_lock); |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 260 | put_iova_domain(&tegra->carveout.domain); |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Thierry Reding | 1053f4dd | 2014-11-04 16:17:55 +0100 | [diff] [blame] | 263 | kfree(tegra); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) |
| 267 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 268 | struct tegra_drm_file *fpriv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 269 | |
| 270 | fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); |
| 271 | if (!fpriv) |
| 272 | return -ENOMEM; |
| 273 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 274 | idr_init(&fpriv->contexts); |
| 275 | mutex_init(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 276 | filp->driver_priv = fpriv; |
| 277 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 281 | static void tegra_drm_context_free(struct tegra_drm_context *context) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 282 | { |
| 283 | context->client->ops->close_channel(context); |
| 284 | kfree(context); |
| 285 | } |
| 286 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 287 | static void tegra_drm_lastclose(struct drm_device *drm) |
| 288 | { |
Archit Taneja | b110ef3 | 2015-10-27 13:40:59 +0530 | [diff] [blame] | 289 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 290 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 291 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 292 | tegra_fbdev_restore_mode(tegra->fbdev); |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 293 | #endif |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 296 | static struct host1x_bo * |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 297 | host1x_bo_lookup(struct drm_file *file, u32 handle) |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 298 | { |
| 299 | struct drm_gem_object *gem; |
| 300 | struct tegra_bo *bo; |
| 301 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 302 | gem = drm_gem_object_lookup(file, handle); |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 303 | if (!gem) |
| 304 | return NULL; |
| 305 | |
Daniel Vetter | a07cdfe | 2015-11-23 10:32:48 +0100 | [diff] [blame] | 306 | drm_gem_object_unreference_unlocked(gem); |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 307 | |
| 308 | bo = to_tegra_bo(gem); |
| 309 | return &bo->base; |
| 310 | } |
| 311 | |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 312 | static int host1x_reloc_copy_from_user(struct host1x_reloc *dest, |
| 313 | struct drm_tegra_reloc __user *src, |
| 314 | struct drm_device *drm, |
| 315 | struct drm_file *file) |
| 316 | { |
| 317 | u32 cmdbuf, target; |
| 318 | int err; |
| 319 | |
| 320 | err = get_user(cmdbuf, &src->cmdbuf.handle); |
| 321 | if (err < 0) |
| 322 | return err; |
| 323 | |
| 324 | err = get_user(dest->cmdbuf.offset, &src->cmdbuf.offset); |
| 325 | if (err < 0) |
| 326 | return err; |
| 327 | |
| 328 | err = get_user(target, &src->target.handle); |
| 329 | if (err < 0) |
| 330 | return err; |
| 331 | |
David Ung | 31f40f8 | 2015-01-20 18:37:35 -0800 | [diff] [blame] | 332 | err = get_user(dest->target.offset, &src->target.offset); |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 333 | if (err < 0) |
| 334 | return err; |
| 335 | |
| 336 | err = get_user(dest->shift, &src->shift); |
| 337 | if (err < 0) |
| 338 | return err; |
| 339 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 340 | dest->cmdbuf.bo = host1x_bo_lookup(file, cmdbuf); |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 341 | if (!dest->cmdbuf.bo) |
| 342 | return -ENOENT; |
| 343 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 344 | dest->target.bo = host1x_bo_lookup(file, target); |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 345 | if (!dest->target.bo) |
| 346 | return -ENOENT; |
| 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 351 | int tegra_drm_submit(struct tegra_drm_context *context, |
| 352 | struct drm_tegra_submit *args, struct drm_device *drm, |
| 353 | struct drm_file *file) |
| 354 | { |
| 355 | unsigned int num_cmdbufs = args->num_cmdbufs; |
| 356 | unsigned int num_relocs = args->num_relocs; |
| 357 | unsigned int num_waitchks = args->num_waitchks; |
| 358 | struct drm_tegra_cmdbuf __user *cmdbufs = |
Thierry Reding | a7ed68f | 2013-11-08 13:15:43 +0100 | [diff] [blame] | 359 | (void __user *)(uintptr_t)args->cmdbufs; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 360 | struct drm_tegra_reloc __user *relocs = |
Thierry Reding | a7ed68f | 2013-11-08 13:15:43 +0100 | [diff] [blame] | 361 | (void __user *)(uintptr_t)args->relocs; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 362 | struct drm_tegra_waitchk __user *waitchks = |
Thierry Reding | a7ed68f | 2013-11-08 13:15:43 +0100 | [diff] [blame] | 363 | (void __user *)(uintptr_t)args->waitchks; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 364 | struct drm_tegra_syncpt syncpt; |
| 365 | struct host1x_job *job; |
| 366 | int err; |
| 367 | |
| 368 | /* We don't yet support other than one syncpt_incr struct per submit */ |
| 369 | if (args->num_syncpts != 1) |
| 370 | return -EINVAL; |
| 371 | |
| 372 | job = host1x_job_alloc(context->channel, args->num_cmdbufs, |
| 373 | args->num_relocs, args->num_waitchks); |
| 374 | if (!job) |
| 375 | return -ENOMEM; |
| 376 | |
| 377 | job->num_relocs = args->num_relocs; |
| 378 | job->num_waitchk = args->num_waitchks; |
| 379 | job->client = (u32)args->context; |
| 380 | job->class = context->client->base.class; |
| 381 | job->serialize = true; |
| 382 | |
| 383 | while (num_cmdbufs) { |
| 384 | struct drm_tegra_cmdbuf cmdbuf; |
| 385 | struct host1x_bo *bo; |
| 386 | |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 387 | if (copy_from_user(&cmdbuf, cmdbufs, sizeof(cmdbuf))) { |
| 388 | err = -EFAULT; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 389 | goto fail; |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 390 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 391 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 392 | bo = host1x_bo_lookup(file, cmdbuf.handle); |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 393 | if (!bo) { |
| 394 | err = -ENOENT; |
| 395 | goto fail; |
| 396 | } |
| 397 | |
| 398 | host1x_job_add_gather(job, bo, cmdbuf.words, cmdbuf.offset); |
| 399 | num_cmdbufs--; |
| 400 | cmdbufs++; |
| 401 | } |
| 402 | |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 403 | /* copy and resolve relocations from submit */ |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 404 | while (num_relocs--) { |
Thierry Reding | 961e3be | 2014-06-10 10:25:00 +0200 | [diff] [blame] | 405 | err = host1x_reloc_copy_from_user(&job->relocarray[num_relocs], |
| 406 | &relocs[num_relocs], drm, |
| 407 | file); |
| 408 | if (err < 0) |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 409 | goto fail; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 412 | if (copy_from_user(job->waitchk, waitchks, |
| 413 | sizeof(*waitchks) * num_waitchks)) { |
| 414 | err = -EFAULT; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 415 | goto fail; |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 416 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 417 | |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 418 | if (copy_from_user(&syncpt, (void __user *)(uintptr_t)args->syncpts, |
| 419 | sizeof(syncpt))) { |
| 420 | err = -EFAULT; |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 421 | goto fail; |
Dan Carpenter | 9a99160 | 2013-11-08 13:07:37 +0300 | [diff] [blame] | 422 | } |
Thierry Reding | c40f0f1 | 2013-10-10 11:00:33 +0200 | [diff] [blame] | 423 | |
| 424 | job->is_addr_reg = context->client->ops->is_addr_reg; |
| 425 | job->syncpt_incrs = syncpt.incrs; |
| 426 | job->syncpt_id = syncpt.id; |
| 427 | job->timeout = 10000; |
| 428 | |
| 429 | if (args->timeout && args->timeout < 10000) |
| 430 | job->timeout = args->timeout; |
| 431 | |
| 432 | err = host1x_job_pin(job, context->client->base.dev); |
| 433 | if (err) |
| 434 | goto fail; |
| 435 | |
| 436 | err = host1x_job_submit(job); |
| 437 | if (err) |
| 438 | goto fail_submit; |
| 439 | |
| 440 | args->fence = job->syncpt_end; |
| 441 | |
| 442 | host1x_job_put(job); |
| 443 | return 0; |
| 444 | |
| 445 | fail_submit: |
| 446 | host1x_job_unpin(job); |
| 447 | fail: |
| 448 | host1x_job_put(job); |
| 449 | return err; |
| 450 | } |
| 451 | |
| 452 | |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 453 | #ifdef CONFIG_DRM_TEGRA_STAGING |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 454 | static struct tegra_drm_context * |
| 455 | tegra_drm_file_get_context(struct tegra_drm_file *file, u32 id) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 456 | { |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 457 | struct tegra_drm_context *context; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 458 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 459 | mutex_lock(&file->lock); |
| 460 | context = idr_find(&file->contexts, id); |
| 461 | mutex_unlock(&file->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 462 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 463 | return context; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static int tegra_gem_create(struct drm_device *drm, void *data, |
| 467 | struct drm_file *file) |
| 468 | { |
| 469 | struct drm_tegra_gem_create *args = data; |
| 470 | struct tegra_bo *bo; |
| 471 | |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 472 | bo = tegra_bo_create_with_handle(file, drm, args->size, args->flags, |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 473 | &args->handle); |
| 474 | if (IS_ERR(bo)) |
| 475 | return PTR_ERR(bo); |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static int tegra_gem_mmap(struct drm_device *drm, void *data, |
| 481 | struct drm_file *file) |
| 482 | { |
| 483 | struct drm_tegra_gem_mmap *args = data; |
| 484 | struct drm_gem_object *gem; |
| 485 | struct tegra_bo *bo; |
| 486 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 487 | gem = drm_gem_object_lookup(file, args->handle); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 488 | if (!gem) |
| 489 | return -EINVAL; |
| 490 | |
| 491 | bo = to_tegra_bo(gem); |
| 492 | |
David Herrmann | 2bc7b0c | 2013-08-13 14:19:58 +0200 | [diff] [blame] | 493 | args->offset = drm_vma_node_offset_addr(&bo->gem.vma_node); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 494 | |
Daniel Vetter | 1153330 | 2015-11-23 10:32:40 +0100 | [diff] [blame] | 495 | drm_gem_object_unreference_unlocked(gem); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int tegra_syncpt_read(struct drm_device *drm, void *data, |
| 501 | struct drm_file *file) |
| 502 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 503 | struct host1x *host = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 504 | struct drm_tegra_syncpt_read *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 505 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 506 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 507 | sp = host1x_syncpt_get(host, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 508 | if (!sp) |
| 509 | return -EINVAL; |
| 510 | |
| 511 | args->value = host1x_syncpt_read_min(sp); |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | static int tegra_syncpt_incr(struct drm_device *drm, void *data, |
| 516 | struct drm_file *file) |
| 517 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 518 | struct host1x *host1x = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 519 | struct drm_tegra_syncpt_incr *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 520 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 521 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 522 | sp = host1x_syncpt_get(host1x, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 523 | if (!sp) |
| 524 | return -EINVAL; |
| 525 | |
Arto Merilainen | ebae30b | 2013-05-29 13:26:08 +0300 | [diff] [blame] | 526 | return host1x_syncpt_incr(sp); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static int tegra_syncpt_wait(struct drm_device *drm, void *data, |
| 530 | struct drm_file *file) |
| 531 | { |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 532 | struct host1x *host1x = dev_get_drvdata(drm->dev->parent); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 533 | struct drm_tegra_syncpt_wait *args = data; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 534 | struct host1x_syncpt *sp; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 535 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 536 | sp = host1x_syncpt_get(host1x, args->id); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 537 | if (!sp) |
| 538 | return -EINVAL; |
| 539 | |
| 540 | return host1x_syncpt_wait(sp, args->thresh, args->timeout, |
| 541 | &args->value); |
| 542 | } |
| 543 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 544 | static int tegra_client_open(struct tegra_drm_file *fpriv, |
| 545 | struct tegra_drm_client *client, |
| 546 | struct tegra_drm_context *context) |
| 547 | { |
| 548 | int err; |
| 549 | |
| 550 | err = client->ops->open_channel(client, context); |
| 551 | if (err < 0) |
| 552 | return err; |
| 553 | |
| 554 | err = idr_alloc(&fpriv->contexts, context, 0, 0, GFP_KERNEL); |
| 555 | if (err < 0) { |
| 556 | client->ops->close_channel(context); |
| 557 | return err; |
| 558 | } |
| 559 | |
| 560 | context->client = client; |
| 561 | context->id = err; |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 566 | static int tegra_open_channel(struct drm_device *drm, void *data, |
| 567 | struct drm_file *file) |
| 568 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 569 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 570 | struct tegra_drm *tegra = drm->dev_private; |
| 571 | struct drm_tegra_open_channel *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 572 | struct tegra_drm_context *context; |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 573 | struct tegra_drm_client *client; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 574 | int err = -ENODEV; |
| 575 | |
| 576 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 577 | if (!context) |
| 578 | return -ENOMEM; |
| 579 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 580 | mutex_lock(&fpriv->lock); |
| 581 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 582 | list_for_each_entry(client, &tegra->clients, list) |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 583 | if (client->base.class == args->client) { |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 584 | err = tegra_client_open(fpriv, client, context); |
| 585 | if (err < 0) |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 586 | break; |
| 587 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 588 | args->context = context->id; |
| 589 | break; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 590 | } |
| 591 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 592 | if (err < 0) |
| 593 | kfree(context); |
| 594 | |
| 595 | mutex_unlock(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 596 | return err; |
| 597 | } |
| 598 | |
| 599 | static int tegra_close_channel(struct drm_device *drm, void *data, |
| 600 | struct drm_file *file) |
| 601 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 602 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 603 | struct drm_tegra_close_channel *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 604 | struct tegra_drm_context *context; |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 605 | int err = 0; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 606 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 607 | mutex_lock(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 608 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 609 | context = tegra_drm_file_get_context(fpriv, args->context); |
| 610 | if (!context) { |
| 611 | err = -EINVAL; |
| 612 | goto unlock; |
| 613 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 614 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 615 | idr_remove(&fpriv->contexts, context->id); |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 616 | tegra_drm_context_free(context); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 617 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 618 | unlock: |
| 619 | mutex_unlock(&fpriv->lock); |
| 620 | return err; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static int tegra_get_syncpt(struct drm_device *drm, void *data, |
| 624 | struct drm_file *file) |
| 625 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 626 | struct tegra_drm_file *fpriv = file->driver_priv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 627 | struct drm_tegra_get_syncpt *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 628 | struct tegra_drm_context *context; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 629 | struct host1x_syncpt *syncpt; |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 630 | int err = 0; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 631 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 632 | mutex_lock(&fpriv->lock); |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 633 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 634 | context = tegra_drm_file_get_context(fpriv, args->context); |
| 635 | if (!context) { |
| 636 | err = -ENODEV; |
| 637 | goto unlock; |
| 638 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 639 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 640 | if (args->index >= context->client->base.num_syncpts) { |
| 641 | err = -EINVAL; |
| 642 | goto unlock; |
| 643 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 644 | |
Thierry Reding | 53fa7f7 | 2013-09-24 15:35:40 +0200 | [diff] [blame] | 645 | syncpt = context->client->base.syncpts[args->index]; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 646 | args->id = host1x_syncpt_id(syncpt); |
| 647 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 648 | unlock: |
| 649 | mutex_unlock(&fpriv->lock); |
| 650 | return err; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static int tegra_submit(struct drm_device *drm, void *data, |
| 654 | struct drm_file *file) |
| 655 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 656 | struct tegra_drm_file *fpriv = file->driver_priv; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 657 | struct drm_tegra_submit *args = data; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 658 | struct tegra_drm_context *context; |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 659 | int err; |
Thierry Reding | c88c363 | 2013-09-26 16:08:22 +0200 | [diff] [blame] | 660 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 661 | mutex_lock(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 662 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 663 | context = tegra_drm_file_get_context(fpriv, args->context); |
| 664 | if (!context) { |
| 665 | err = -ENODEV; |
| 666 | goto unlock; |
| 667 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 668 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 669 | err = context->client->ops->submit(context, args, drm, file); |
| 670 | |
| 671 | unlock: |
| 672 | mutex_unlock(&fpriv->lock); |
| 673 | return err; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 674 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 675 | |
| 676 | static int tegra_get_syncpt_base(struct drm_device *drm, void *data, |
| 677 | struct drm_file *file) |
| 678 | { |
| 679 | struct tegra_drm_file *fpriv = file->driver_priv; |
| 680 | struct drm_tegra_get_syncpt_base *args = data; |
| 681 | struct tegra_drm_context *context; |
| 682 | struct host1x_syncpt_base *base; |
| 683 | struct host1x_syncpt *syncpt; |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 684 | int err = 0; |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 685 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 686 | mutex_lock(&fpriv->lock); |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 687 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 688 | context = tegra_drm_file_get_context(fpriv, args->context); |
| 689 | if (!context) { |
| 690 | err = -ENODEV; |
| 691 | goto unlock; |
| 692 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 693 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 694 | if (args->syncpt >= context->client->base.num_syncpts) { |
| 695 | err = -EINVAL; |
| 696 | goto unlock; |
| 697 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 698 | |
| 699 | syncpt = context->client->base.syncpts[args->syncpt]; |
| 700 | |
| 701 | base = host1x_syncpt_get_base(syncpt); |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 702 | if (!base) { |
| 703 | err = -ENXIO; |
| 704 | goto unlock; |
| 705 | } |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 706 | |
| 707 | args->id = host1x_syncpt_base_id(base); |
| 708 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 709 | unlock: |
| 710 | mutex_unlock(&fpriv->lock); |
| 711 | return err; |
Arto Merilainen | c54a169 | 2013-10-14 15:21:54 +0300 | [diff] [blame] | 712 | } |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 713 | |
| 714 | static int tegra_gem_set_tiling(struct drm_device *drm, void *data, |
| 715 | struct drm_file *file) |
| 716 | { |
| 717 | struct drm_tegra_gem_set_tiling *args = data; |
| 718 | enum tegra_bo_tiling_mode mode; |
| 719 | struct drm_gem_object *gem; |
| 720 | unsigned long value = 0; |
| 721 | struct tegra_bo *bo; |
| 722 | |
| 723 | switch (args->mode) { |
| 724 | case DRM_TEGRA_GEM_TILING_MODE_PITCH: |
| 725 | mode = TEGRA_BO_TILING_MODE_PITCH; |
| 726 | |
| 727 | if (args->value != 0) |
| 728 | return -EINVAL; |
| 729 | |
| 730 | break; |
| 731 | |
| 732 | case DRM_TEGRA_GEM_TILING_MODE_TILED: |
| 733 | mode = TEGRA_BO_TILING_MODE_TILED; |
| 734 | |
| 735 | if (args->value != 0) |
| 736 | return -EINVAL; |
| 737 | |
| 738 | break; |
| 739 | |
| 740 | case DRM_TEGRA_GEM_TILING_MODE_BLOCK: |
| 741 | mode = TEGRA_BO_TILING_MODE_BLOCK; |
| 742 | |
| 743 | if (args->value > 5) |
| 744 | return -EINVAL; |
| 745 | |
| 746 | value = args->value; |
| 747 | break; |
| 748 | |
| 749 | default: |
| 750 | return -EINVAL; |
| 751 | } |
| 752 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 753 | gem = drm_gem_object_lookup(file, args->handle); |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 754 | if (!gem) |
| 755 | return -ENOENT; |
| 756 | |
| 757 | bo = to_tegra_bo(gem); |
| 758 | |
| 759 | bo->tiling.mode = mode; |
| 760 | bo->tiling.value = value; |
| 761 | |
Daniel Vetter | 1153330 | 2015-11-23 10:32:40 +0100 | [diff] [blame] | 762 | drm_gem_object_unreference_unlocked(gem); |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | static int tegra_gem_get_tiling(struct drm_device *drm, void *data, |
| 768 | struct drm_file *file) |
| 769 | { |
| 770 | struct drm_tegra_gem_get_tiling *args = data; |
| 771 | struct drm_gem_object *gem; |
| 772 | struct tegra_bo *bo; |
| 773 | int err = 0; |
| 774 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 775 | gem = drm_gem_object_lookup(file, args->handle); |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 776 | if (!gem) |
| 777 | return -ENOENT; |
| 778 | |
| 779 | bo = to_tegra_bo(gem); |
| 780 | |
| 781 | switch (bo->tiling.mode) { |
| 782 | case TEGRA_BO_TILING_MODE_PITCH: |
| 783 | args->mode = DRM_TEGRA_GEM_TILING_MODE_PITCH; |
| 784 | args->value = 0; |
| 785 | break; |
| 786 | |
| 787 | case TEGRA_BO_TILING_MODE_TILED: |
| 788 | args->mode = DRM_TEGRA_GEM_TILING_MODE_TILED; |
| 789 | args->value = 0; |
| 790 | break; |
| 791 | |
| 792 | case TEGRA_BO_TILING_MODE_BLOCK: |
| 793 | args->mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK; |
| 794 | args->value = bo->tiling.value; |
| 795 | break; |
| 796 | |
| 797 | default: |
| 798 | err = -EINVAL; |
| 799 | break; |
| 800 | } |
| 801 | |
Daniel Vetter | 1153330 | 2015-11-23 10:32:40 +0100 | [diff] [blame] | 802 | drm_gem_object_unreference_unlocked(gem); |
Thierry Reding | 7678d71 | 2014-06-03 14:56:57 +0200 | [diff] [blame] | 803 | |
| 804 | return err; |
| 805 | } |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 806 | |
| 807 | static int tegra_gem_set_flags(struct drm_device *drm, void *data, |
| 808 | struct drm_file *file) |
| 809 | { |
| 810 | struct drm_tegra_gem_set_flags *args = data; |
| 811 | struct drm_gem_object *gem; |
| 812 | struct tegra_bo *bo; |
| 813 | |
| 814 | if (args->flags & ~DRM_TEGRA_GEM_FLAGS) |
| 815 | return -EINVAL; |
| 816 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 817 | gem = drm_gem_object_lookup(file, args->handle); |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 818 | if (!gem) |
| 819 | return -ENOENT; |
| 820 | |
| 821 | bo = to_tegra_bo(gem); |
| 822 | bo->flags = 0; |
| 823 | |
| 824 | if (args->flags & DRM_TEGRA_GEM_BOTTOM_UP) |
| 825 | bo->flags |= TEGRA_BO_BOTTOM_UP; |
| 826 | |
Daniel Vetter | 1153330 | 2015-11-23 10:32:40 +0100 | [diff] [blame] | 827 | drm_gem_object_unreference_unlocked(gem); |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 828 | |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | static int tegra_gem_get_flags(struct drm_device *drm, void *data, |
| 833 | struct drm_file *file) |
| 834 | { |
| 835 | struct drm_tegra_gem_get_flags *args = data; |
| 836 | struct drm_gem_object *gem; |
| 837 | struct tegra_bo *bo; |
| 838 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 839 | gem = drm_gem_object_lookup(file, args->handle); |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 840 | if (!gem) |
| 841 | return -ENOENT; |
| 842 | |
| 843 | bo = to_tegra_bo(gem); |
| 844 | args->flags = 0; |
| 845 | |
| 846 | if (bo->flags & TEGRA_BO_BOTTOM_UP) |
| 847 | args->flags |= DRM_TEGRA_GEM_BOTTOM_UP; |
| 848 | |
Daniel Vetter | 1153330 | 2015-11-23 10:32:40 +0100 | [diff] [blame] | 849 | drm_gem_object_unreference_unlocked(gem); |
Thierry Reding | 7b12908 | 2014-06-10 12:04:03 +0200 | [diff] [blame] | 850 | |
| 851 | return 0; |
| 852 | } |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 853 | #endif |
| 854 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 855 | static const struct drm_ioctl_desc tegra_drm_ioctls[] = { |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 856 | #ifdef CONFIG_DRM_TEGRA_STAGING |
Daniel Vetter | f8c4714 | 2015-09-08 13:56:30 +0200 | [diff] [blame] | 857 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_CREATE, tegra_gem_create, 0), |
| 858 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_gem_mmap, 0), |
| 859 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_READ, tegra_syncpt_read, 0), |
| 860 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_INCR, tegra_syncpt_incr, 0), |
| 861 | DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_WAIT, tegra_syncpt_wait, 0), |
| 862 | DRM_IOCTL_DEF_DRV(TEGRA_OPEN_CHANNEL, tegra_open_channel, 0), |
| 863 | DRM_IOCTL_DEF_DRV(TEGRA_CLOSE_CHANNEL, tegra_close_channel, 0), |
| 864 | DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT, tegra_get_syncpt, 0), |
| 865 | DRM_IOCTL_DEF_DRV(TEGRA_SUBMIT, tegra_submit, 0), |
| 866 | DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT_BASE, tegra_get_syncpt_base, 0), |
| 867 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_TILING, tegra_gem_set_tiling, 0), |
| 868 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_TILING, tegra_gem_get_tiling, 0), |
| 869 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_FLAGS, tegra_gem_set_flags, 0), |
| 870 | DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_FLAGS, tegra_gem_get_flags, 0), |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 871 | #endif |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 872 | }; |
| 873 | |
| 874 | static const struct file_operations tegra_drm_fops = { |
| 875 | .owner = THIS_MODULE, |
| 876 | .open = drm_open, |
| 877 | .release = drm_release, |
| 878 | .unlocked_ioctl = drm_ioctl, |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 879 | .mmap = tegra_drm_mmap, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 880 | .poll = drm_poll, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 881 | .read = drm_read, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 882 | .compat_ioctl = drm_compat_ioctl, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 883 | .llseek = noop_llseek, |
| 884 | }; |
| 885 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 886 | static u32 tegra_drm_get_vblank_counter(struct drm_device *drm, |
| 887 | unsigned int pipe) |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 888 | { |
Shawn Guo | 75bcb05 | 2017-01-09 19:25:44 +0800 | [diff] [blame] | 889 | struct drm_crtc *crtc = drm_crtc_from_index(drm, pipe); |
Thierry Reding | 42e9ce0 | 2015-01-28 14:43:05 +0100 | [diff] [blame] | 890 | struct tegra_dc *dc = to_tegra_dc(crtc); |
Thierry Reding | ed7dae5 | 2014-12-16 16:03:13 +0100 | [diff] [blame] | 891 | |
| 892 | if (!crtc) |
| 893 | return 0; |
| 894 | |
Thierry Reding | 42e9ce0 | 2015-01-28 14:43:05 +0100 | [diff] [blame] | 895 | return tegra_dc_get_vblank_counter(dc); |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 896 | } |
| 897 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 898 | static int tegra_drm_enable_vblank(struct drm_device *drm, unsigned int pipe) |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 899 | { |
Shawn Guo | 75bcb05 | 2017-01-09 19:25:44 +0800 | [diff] [blame] | 900 | struct drm_crtc *crtc = drm_crtc_from_index(drm, pipe); |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 901 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 902 | |
| 903 | if (!crtc) |
| 904 | return -ENODEV; |
| 905 | |
| 906 | tegra_dc_enable_vblank(dc); |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 911 | static void tegra_drm_disable_vblank(struct drm_device *drm, unsigned int pipe) |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 912 | { |
Shawn Guo | 75bcb05 | 2017-01-09 19:25:44 +0800 | [diff] [blame] | 913 | struct drm_crtc *crtc = drm_crtc_from_index(drm, pipe); |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 914 | struct tegra_dc *dc = to_tegra_dc(crtc); |
| 915 | |
| 916 | if (crtc) |
| 917 | tegra_dc_disable_vblank(dc); |
| 918 | } |
| 919 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 920 | static int tegra_drm_context_cleanup(int id, void *p, void *data) |
| 921 | { |
| 922 | struct tegra_drm_context *context = p; |
| 923 | |
| 924 | tegra_drm_context_free(context); |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 929 | static void tegra_drm_preclose(struct drm_device *drm, struct drm_file *file) |
| 930 | { |
Thierry Reding | 08943e6 | 2013-09-26 16:08:18 +0200 | [diff] [blame] | 931 | struct tegra_drm_file *fpriv = file->driver_priv; |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 932 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 933 | mutex_lock(&fpriv->lock); |
| 934 | idr_for_each(&fpriv->contexts, tegra_drm_context_cleanup, NULL); |
| 935 | mutex_unlock(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 936 | |
Thierry Reding | bdd2f9c | 2017-03-09 20:04:55 +0100 | [diff] [blame] | 937 | idr_destroy(&fpriv->contexts); |
| 938 | mutex_destroy(&fpriv->lock); |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 939 | kfree(fpriv); |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 940 | } |
| 941 | |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 942 | #ifdef CONFIG_DEBUG_FS |
| 943 | static int tegra_debugfs_framebuffers(struct seq_file *s, void *data) |
| 944 | { |
| 945 | struct drm_info_node *node = (struct drm_info_node *)s->private; |
| 946 | struct drm_device *drm = node->minor->dev; |
| 947 | struct drm_framebuffer *fb; |
| 948 | |
| 949 | mutex_lock(&drm->mode_config.fb_lock); |
| 950 | |
| 951 | list_for_each_entry(fb, &drm->mode_config.fb_list, head) { |
| 952 | 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] | 953 | fb->base.id, fb->width, fb->height, |
| 954 | fb->format->depth, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 955 | fb->format->cpp[0] * 8, |
Dave Airlie | 747a598 | 2016-04-15 15:10:35 +1000 | [diff] [blame] | 956 | drm_framebuffer_read_refcount(fb)); |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | mutex_unlock(&drm->mode_config.fb_lock); |
| 960 | |
| 961 | return 0; |
| 962 | } |
| 963 | |
Thierry Reding | 28c2337 | 2015-01-23 09:16:03 +0100 | [diff] [blame] | 964 | static int tegra_debugfs_iova(struct seq_file *s, void *data) |
| 965 | { |
| 966 | struct drm_info_node *node = (struct drm_info_node *)s->private; |
| 967 | struct drm_device *drm = node->minor->dev; |
| 968 | struct tegra_drm *tegra = drm->dev_private; |
Daniel Vetter | b5c3714 | 2016-12-29 12:09:24 +0100 | [diff] [blame] | 969 | struct drm_printer p = drm_seq_file_printer(s); |
Thierry Reding | 28c2337 | 2015-01-23 09:16:03 +0100 | [diff] [blame] | 970 | |
Thierry Reding | 347ad49d | 2017-03-09 20:04:56 +0100 | [diff] [blame] | 971 | mutex_lock(&tegra->mm_lock); |
Daniel Vetter | b5c3714 | 2016-12-29 12:09:24 +0100 | [diff] [blame] | 972 | drm_mm_print(&tegra->mm, &p); |
Thierry Reding | 347ad49d | 2017-03-09 20:04:56 +0100 | [diff] [blame] | 973 | mutex_unlock(&tegra->mm_lock); |
Daniel Vetter | b5c3714 | 2016-12-29 12:09:24 +0100 | [diff] [blame] | 974 | |
| 975 | return 0; |
Thierry Reding | 28c2337 | 2015-01-23 09:16:03 +0100 | [diff] [blame] | 976 | } |
| 977 | |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 978 | static struct drm_info_list tegra_debugfs_list[] = { |
| 979 | { "framebuffers", tegra_debugfs_framebuffers, 0 }, |
Thierry Reding | 28c2337 | 2015-01-23 09:16:03 +0100 | [diff] [blame] | 980 | { "iova", tegra_debugfs_iova, 0 }, |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 981 | }; |
| 982 | |
| 983 | static int tegra_debugfs_init(struct drm_minor *minor) |
| 984 | { |
| 985 | return drm_debugfs_create_files(tegra_debugfs_list, |
| 986 | ARRAY_SIZE(tegra_debugfs_list), |
| 987 | minor->debugfs_root, minor); |
| 988 | } |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 989 | #endif |
| 990 | |
Thierry Reding | 9b57f5f | 2013-11-08 13:17:14 +0100 | [diff] [blame] | 991 | static struct drm_driver tegra_drm_driver = { |
Thierry Reding | ad90659 | 2015-09-24 18:38:09 +0200 | [diff] [blame] | 992 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | |
| 993 | DRIVER_ATOMIC, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 994 | .load = tegra_drm_load, |
| 995 | .unload = tegra_drm_unload, |
| 996 | .open = tegra_drm_open, |
Thierry Reding | 3c03c46 | 2012-11-28 12:00:18 +0100 | [diff] [blame] | 997 | .preclose = tegra_drm_preclose, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 998 | .lastclose = tegra_drm_lastclose, |
| 999 | |
Thierry Reding | 6e5ff99 | 2012-11-28 11:45:47 +0100 | [diff] [blame] | 1000 | .get_vblank_counter = tegra_drm_get_vblank_counter, |
| 1001 | .enable_vblank = tegra_drm_enable_vblank, |
| 1002 | .disable_vblank = tegra_drm_disable_vblank, |
| 1003 | |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 1004 | #if defined(CONFIG_DEBUG_FS) |
| 1005 | .debugfs_init = tegra_debugfs_init, |
Thierry Reding | e450fcc | 2013-02-13 16:13:16 +0100 | [diff] [blame] | 1006 | #endif |
| 1007 | |
Daniel Vetter | 1ddbdbd | 2016-04-26 19:30:00 +0200 | [diff] [blame] | 1008 | .gem_free_object_unlocked = tegra_bo_free_object, |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 1009 | .gem_vm_ops = &tegra_bo_vm_ops, |
Thierry Reding | 3800391 | 2013-12-12 10:00:43 +0100 | [diff] [blame] | 1010 | |
| 1011 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 1012 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 1013 | .gem_prime_export = tegra_gem_prime_export, |
| 1014 | .gem_prime_import = tegra_gem_prime_import, |
| 1015 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 1016 | .dumb_create = tegra_bo_dumb_create, |
| 1017 | .dumb_map_offset = tegra_bo_dumb_map_offset, |
Daniel Vetter | 43387b3 | 2013-07-16 09:12:04 +0200 | [diff] [blame] | 1018 | .dumb_destroy = drm_gem_dumb_destroy, |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1019 | |
| 1020 | .ioctls = tegra_drm_ioctls, |
| 1021 | .num_ioctls = ARRAY_SIZE(tegra_drm_ioctls), |
| 1022 | .fops = &tegra_drm_fops, |
| 1023 | |
| 1024 | .name = DRIVER_NAME, |
| 1025 | .desc = DRIVER_DESC, |
| 1026 | .date = DRIVER_DATE, |
| 1027 | .major = DRIVER_MAJOR, |
| 1028 | .minor = DRIVER_MINOR, |
| 1029 | .patchlevel = DRIVER_PATCHLEVEL, |
| 1030 | }; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1031 | |
| 1032 | int tegra_drm_register_client(struct tegra_drm *tegra, |
| 1033 | struct tegra_drm_client *client) |
| 1034 | { |
| 1035 | mutex_lock(&tegra->clients_lock); |
| 1036 | list_add_tail(&client->list, &tegra->clients); |
| 1037 | mutex_unlock(&tegra->clients_lock); |
| 1038 | |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | int tegra_drm_unregister_client(struct tegra_drm *tegra, |
| 1043 | struct tegra_drm_client *client) |
| 1044 | { |
| 1045 | mutex_lock(&tegra->clients_lock); |
| 1046 | list_del_init(&client->list); |
| 1047 | mutex_unlock(&tegra->clients_lock); |
| 1048 | |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
Mikko Perttunen | ad92601 | 2016-12-14 13:16:11 +0200 | [diff] [blame] | 1052 | void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, |
| 1053 | dma_addr_t *dma) |
| 1054 | { |
| 1055 | struct iova *alloc; |
| 1056 | void *virt; |
| 1057 | gfp_t gfp; |
| 1058 | int err; |
| 1059 | |
| 1060 | if (tegra->domain) |
| 1061 | size = iova_align(&tegra->carveout.domain, size); |
| 1062 | else |
| 1063 | size = PAGE_ALIGN(size); |
| 1064 | |
| 1065 | gfp = GFP_KERNEL | __GFP_ZERO; |
| 1066 | if (!tegra->domain) { |
| 1067 | /* |
| 1068 | * Many units only support 32-bit addresses, even on 64-bit |
| 1069 | * SoCs. If there is no IOMMU to translate into a 32-bit IO |
| 1070 | * virtual address space, force allocations to be in the |
| 1071 | * lower 32-bit range. |
| 1072 | */ |
| 1073 | gfp |= GFP_DMA; |
| 1074 | } |
| 1075 | |
| 1076 | virt = (void *)__get_free_pages(gfp, get_order(size)); |
| 1077 | if (!virt) |
| 1078 | return ERR_PTR(-ENOMEM); |
| 1079 | |
| 1080 | if (!tegra->domain) { |
| 1081 | /* |
| 1082 | * If IOMMU is disabled, devices address physical memory |
| 1083 | * directly. |
| 1084 | */ |
| 1085 | *dma = virt_to_phys(virt); |
| 1086 | return virt; |
| 1087 | } |
| 1088 | |
| 1089 | alloc = alloc_iova(&tegra->carveout.domain, |
| 1090 | size >> tegra->carveout.shift, |
| 1091 | tegra->carveout.limit, true); |
| 1092 | if (!alloc) { |
| 1093 | err = -EBUSY; |
| 1094 | goto free_pages; |
| 1095 | } |
| 1096 | |
| 1097 | *dma = iova_dma_addr(&tegra->carveout.domain, alloc); |
| 1098 | err = iommu_map(tegra->domain, *dma, virt_to_phys(virt), |
| 1099 | size, IOMMU_READ | IOMMU_WRITE); |
| 1100 | if (err < 0) |
| 1101 | goto free_iova; |
| 1102 | |
| 1103 | return virt; |
| 1104 | |
| 1105 | free_iova: |
| 1106 | __free_iova(&tegra->carveout.domain, alloc); |
| 1107 | free_pages: |
| 1108 | free_pages((unsigned long)virt, get_order(size)); |
| 1109 | |
| 1110 | return ERR_PTR(err); |
| 1111 | } |
| 1112 | |
| 1113 | void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt, |
| 1114 | dma_addr_t dma) |
| 1115 | { |
| 1116 | if (tegra->domain) |
| 1117 | size = iova_align(&tegra->carveout.domain, size); |
| 1118 | else |
| 1119 | size = PAGE_ALIGN(size); |
| 1120 | |
| 1121 | if (tegra->domain) { |
| 1122 | iommu_unmap(tegra->domain, dma, size); |
| 1123 | free_iova(&tegra->carveout.domain, |
| 1124 | iova_pfn(&tegra->carveout.domain, dma)); |
| 1125 | } |
| 1126 | |
| 1127 | free_pages((unsigned long)virt, get_order(size)); |
| 1128 | } |
| 1129 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1130 | static int host1x_drm_probe(struct host1x_device *dev) |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1131 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1132 | struct drm_driver *driver = &tegra_drm_driver; |
| 1133 | struct drm_device *drm; |
| 1134 | int err; |
| 1135 | |
| 1136 | drm = drm_dev_alloc(driver, &dev->dev); |
Tom Gundersen | 0f28860 | 2016-09-21 16:59:19 +0200 | [diff] [blame] | 1137 | if (IS_ERR(drm)) |
| 1138 | return PTR_ERR(drm); |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1139 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1140 | dev_set_drvdata(&dev->dev, drm); |
| 1141 | |
| 1142 | err = drm_dev_register(drm, 0); |
| 1143 | if (err < 0) |
| 1144 | goto unref; |
| 1145 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1146 | return 0; |
| 1147 | |
| 1148 | unref: |
| 1149 | drm_dev_unref(drm); |
| 1150 | return err; |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1153 | static int host1x_drm_remove(struct host1x_device *dev) |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1154 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 1155 | struct drm_device *drm = dev_get_drvdata(&dev->dev); |
| 1156 | |
| 1157 | drm_dev_unregister(drm); |
| 1158 | drm_dev_unref(drm); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1159 | |
| 1160 | return 0; |
| 1161 | } |
| 1162 | |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1163 | #ifdef CONFIG_PM_SLEEP |
| 1164 | static int host1x_drm_suspend(struct device *dev) |
| 1165 | { |
| 1166 | struct drm_device *drm = dev_get_drvdata(dev); |
Thierry Reding | 986c58d | 2015-08-11 13:11:49 +0200 | [diff] [blame] | 1167 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1168 | |
| 1169 | drm_kms_helper_poll_disable(drm); |
Thierry Reding | 986c58d | 2015-08-11 13:11:49 +0200 | [diff] [blame] | 1170 | tegra_drm_fb_suspend(drm); |
| 1171 | |
| 1172 | tegra->state = drm_atomic_helper_suspend(drm); |
| 1173 | if (IS_ERR(tegra->state)) { |
| 1174 | tegra_drm_fb_resume(drm); |
| 1175 | drm_kms_helper_poll_enable(drm); |
| 1176 | return PTR_ERR(tegra->state); |
| 1177 | } |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1178 | |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | static int host1x_drm_resume(struct device *dev) |
| 1183 | { |
| 1184 | struct drm_device *drm = dev_get_drvdata(dev); |
Thierry Reding | 986c58d | 2015-08-11 13:11:49 +0200 | [diff] [blame] | 1185 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1186 | |
Thierry Reding | 986c58d | 2015-08-11 13:11:49 +0200 | [diff] [blame] | 1187 | drm_atomic_helper_resume(drm, tegra->state); |
| 1188 | tegra_drm_fb_resume(drm); |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1189 | drm_kms_helper_poll_enable(drm); |
| 1190 | |
| 1191 | return 0; |
| 1192 | } |
| 1193 | #endif |
| 1194 | |
Thierry Reding | a13f1dc | 2015-08-11 13:22:44 +0200 | [diff] [blame] | 1195 | static SIMPLE_DEV_PM_OPS(host1x_drm_pm_ops, host1x_drm_suspend, |
| 1196 | host1x_drm_resume); |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1197 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1198 | static const struct of_device_id host1x_drm_subdevs[] = { |
| 1199 | { .compatible = "nvidia,tegra20-dc", }, |
| 1200 | { .compatible = "nvidia,tegra20-hdmi", }, |
| 1201 | { .compatible = "nvidia,tegra20-gr2d", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 1202 | { .compatible = "nvidia,tegra20-gr3d", }, |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1203 | { .compatible = "nvidia,tegra30-dc", }, |
| 1204 | { .compatible = "nvidia,tegra30-hdmi", }, |
| 1205 | { .compatible = "nvidia,tegra30-gr2d", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 1206 | { .compatible = "nvidia,tegra30-gr3d", }, |
Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 1207 | { .compatible = "nvidia,tegra114-dsi", }, |
Mikko Perttunen | 7d1d28a | 2013-09-30 16:54:47 +0200 | [diff] [blame] | 1208 | { .compatible = "nvidia,tegra114-hdmi", }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 1209 | { .compatible = "nvidia,tegra114-gr3d", }, |
Thierry Reding | 8620fc6 | 2013-12-12 11:03:59 +0100 | [diff] [blame] | 1210 | { .compatible = "nvidia,tegra124-dc", }, |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1211 | { .compatible = "nvidia,tegra124-sor", }, |
Thierry Reding | fb7be70 | 2013-11-15 16:07:32 +0100 | [diff] [blame] | 1212 | { .compatible = "nvidia,tegra124-hdmi", }, |
Thierry Reding | 7d33858 | 2015-04-10 11:35:21 +0200 | [diff] [blame] | 1213 | { .compatible = "nvidia,tegra124-dsi", }, |
Arto Merilainen | 0ae797a | 2016-12-14 13:16:13 +0200 | [diff] [blame^] | 1214 | { .compatible = "nvidia,tegra124-vic", }, |
Thierry Reding | c06c793 | 2015-04-10 11:35:21 +0200 | [diff] [blame] | 1215 | { .compatible = "nvidia,tegra132-dsi", }, |
Thierry Reding | 5b4f516 | 2015-03-27 10:31:58 +0100 | [diff] [blame] | 1216 | { .compatible = "nvidia,tegra210-dc", }, |
Thierry Reding | ddfb406 | 2015-04-08 16:56:22 +0200 | [diff] [blame] | 1217 | { .compatible = "nvidia,tegra210-dsi", }, |
Thierry Reding | 3309ac8 | 2015-07-30 10:32:46 +0200 | [diff] [blame] | 1218 | { .compatible = "nvidia,tegra210-sor", }, |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1219 | { .compatible = "nvidia,tegra210-sor1", }, |
Arto Merilainen | 0ae797a | 2016-12-14 13:16:13 +0200 | [diff] [blame^] | 1220 | { .compatible = "nvidia,tegra210-vic", }, |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1221 | { /* sentinel */ } |
| 1222 | }; |
| 1223 | |
| 1224 | static struct host1x_driver host1x_drm_driver = { |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 1225 | .driver = { |
| 1226 | .name = "drm", |
Thierry Reding | 359ae68 | 2014-12-18 17:15:25 +0100 | [diff] [blame] | 1227 | .pm = &host1x_drm_pm_ops, |
Thierry Reding | f4c5cf8 | 2014-12-18 15:29:14 +0100 | [diff] [blame] | 1228 | }, |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1229 | .probe = host1x_drm_probe, |
| 1230 | .remove = host1x_drm_remove, |
| 1231 | .subdevs = host1x_drm_subdevs, |
| 1232 | }; |
| 1233 | |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1234 | static struct platform_driver * const drivers[] = { |
| 1235 | &tegra_dc_driver, |
| 1236 | &tegra_hdmi_driver, |
| 1237 | &tegra_dsi_driver, |
| 1238 | &tegra_dpaux_driver, |
| 1239 | &tegra_sor_driver, |
| 1240 | &tegra_gr2d_driver, |
| 1241 | &tegra_gr3d_driver, |
Arto Merilainen | 0ae797a | 2016-12-14 13:16:13 +0200 | [diff] [blame^] | 1242 | &tegra_vic_driver, |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1243 | }; |
| 1244 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1245 | static int __init host1x_drm_init(void) |
| 1246 | { |
| 1247 | int err; |
| 1248 | |
| 1249 | err = host1x_driver_register(&host1x_drm_driver); |
| 1250 | if (err < 0) |
| 1251 | return err; |
| 1252 | |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1253 | err = platform_register_drivers(drivers, ARRAY_SIZE(drivers)); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1254 | if (err < 0) |
| 1255 | goto unregister_host1x; |
| 1256 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1257 | return 0; |
| 1258 | |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1259 | unregister_host1x: |
| 1260 | host1x_driver_unregister(&host1x_drm_driver); |
| 1261 | return err; |
| 1262 | } |
| 1263 | module_init(host1x_drm_init); |
| 1264 | |
| 1265 | static void __exit host1x_drm_exit(void) |
| 1266 | { |
Thierry Reding | 473112e | 2015-09-10 16:07:14 +0200 | [diff] [blame] | 1267 | platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); |
Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 1268 | host1x_driver_unregister(&host1x_drm_driver); |
| 1269 | } |
| 1270 | module_exit(host1x_drm_exit); |
| 1271 | |
| 1272 | MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); |
| 1273 | MODULE_DESCRIPTION("NVIDIA Tegra DRM driver"); |
| 1274 | MODULE_LICENSE("GPL v2"); |