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