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