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