Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 2 | * Legacy: Generic DRM Contexts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas. |
| 5 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 6 | * All Rights Reserved. |
| 7 | * |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 8 | * Author: Rickard E. (Rik) Faith <faith@valinux.com> |
| 9 | * Author: Gareth Hughes <gareth@valinux.com> |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 12 | * copy of this software and associated documentation files (the "Software"), |
| 13 | * to deal in the Software without restriction, including without limitation |
| 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 15 | * and/or sell copies of the Software, and to permit persons to whom the |
| 16 | * Software is furnished to do so, subject to the following conditions: |
| 17 | * |
| 18 | * The above copyright notice and this permission notice (including the next |
| 19 | * paragraph) shall be included in all copies or substantial portions of the |
| 20 | * Software. |
| 21 | * |
| 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 23 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 24 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 25 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 26 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 27 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 28 | * OTHER DEALINGS IN THE SOFTWARE. |
| 29 | */ |
| 30 | |
Sam Ravnborg | 0500c04 | 2019-05-26 19:35:35 +0200 | [diff] [blame] | 31 | #include <linux/slab.h> |
| 32 | #include <linux/uaccess.h> |
| 33 | |
| 34 | #include <drm/drm_drv.h> |
| 35 | #include <drm/drm_file.h> |
| 36 | #include <drm/drm_print.h> |
| 37 | |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 38 | #include "drm_legacy.h" |
| 39 | |
| 40 | struct drm_ctx_list { |
| 41 | struct list_head head; |
| 42 | drm_context_t handle; |
| 43 | struct drm_file *tag; |
| 44 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Dave Airlie | c21eb21 | 2013-09-20 08:32:59 +1000 | [diff] [blame] | 46 | /******************************************************************/ |
| 47 | /** \name Context bitmap support */ |
| 48 | /*@{*/ |
| 49 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 50 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | * Free a handle from the context bitmap. |
| 52 | * |
| 53 | * \param dev DRM device. |
| 54 | * \param ctx_handle context handle. |
| 55 | * |
| 56 | * Clears the bit specified by \p ctx_handle in drm_device::ctx_bitmap and the entry |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 57 | * in drm_device::ctx_idr, while holding the drm_device::struct_mutex |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | * lock. |
| 59 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 60 | void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 62 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 63 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 64 | return; |
| 65 | |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 66 | mutex_lock(&dev->struct_mutex); |
| 67 | idr_remove(&dev->ctx_idr, ctx_handle); |
| 68 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 71 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | * Context bitmap allocation. |
| 73 | * |
| 74 | * \param dev DRM device. |
| 75 | * \return (non-negative) context handle on success or a negative number on failure. |
| 76 | * |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 77 | * Allocate a new idr from drm_device::ctx_idr while holding the |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 78 | * drm_device::struct_mutex lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 80 | static int drm_legacy_ctxbitmap_next(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 82 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 84 | mutex_lock(&dev->struct_mutex); |
Tejun Heo | 2e92881 | 2013-02-27 17:04:08 -0800 | [diff] [blame] | 85 | ret = idr_alloc(&dev->ctx_idr, NULL, DRM_RESERVED_CONTEXTS, 0, |
| 86 | GFP_KERNEL); |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 87 | mutex_unlock(&dev->struct_mutex); |
Tejun Heo | 2e92881 | 2013-02-27 17:04:08 -0800 | [diff] [blame] | 88 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 91 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | * Context bitmap initialization. |
| 93 | * |
| 94 | * \param dev DRM device. |
| 95 | * |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 96 | * Initialise the drm_device::ctx_idr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | */ |
Daniel Vetter | ba6976c | 2015-06-23 11:22:36 +0200 | [diff] [blame] | 98 | void drm_legacy_ctxbitmap_init(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 100 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 101 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Daniel Vetter | ba6976c | 2015-06-23 11:22:36 +0200 | [diff] [blame] | 102 | return; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 103 | |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 104 | idr_init(&dev->ctx_idr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 107 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * Context bitmap cleanup. |
| 109 | * |
| 110 | * \param dev DRM device. |
| 111 | * |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 112 | * Free all idr members using drm_ctx_sarea_free helper function |
| 113 | * while holding the drm_device::struct_mutex lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 115 | void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 117 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 118 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 119 | return; |
| 120 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 121 | mutex_lock(&dev->struct_mutex); |
Tejun Heo | 4d53233 | 2013-02-27 17:03:39 -0800 | [diff] [blame] | 122 | idr_destroy(&dev->ctx_idr); |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 123 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
David Herrmann | 9f8d21e | 2014-07-23 09:01:12 +0200 | [diff] [blame] | 126 | /** |
Yang Yingliang | 76fb351 | 2021-05-13 15:19:18 +0800 | [diff] [blame] | 127 | * drm_legacy_ctxbitmap_flush() - Flush all contexts owned by a file |
David Herrmann | 9f8d21e | 2014-07-23 09:01:12 +0200 | [diff] [blame] | 128 | * @dev: DRM device to operate on |
| 129 | * @file: Open file to flush contexts for |
| 130 | * |
| 131 | * This iterates over all contexts on @dev and drops them if they're owned by |
| 132 | * @file. Note that after this call returns, new contexts might be added if |
| 133 | * the file is still alive. |
| 134 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 135 | void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) |
David Herrmann | 9f8d21e | 2014-07-23 09:01:12 +0200 | [diff] [blame] | 136 | { |
| 137 | struct drm_ctx_list *pos, *tmp; |
| 138 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 139 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 140 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 141 | return; |
| 142 | |
David Herrmann | 9f8d21e | 2014-07-23 09:01:12 +0200 | [diff] [blame] | 143 | mutex_lock(&dev->ctxlist_mutex); |
| 144 | |
| 145 | list_for_each_entry_safe(pos, tmp, &dev->ctxlist, head) { |
| 146 | if (pos->tag == file && |
| 147 | pos->handle != DRM_KERNEL_CONTEXT) { |
| 148 | if (dev->driver->context_dtor) |
| 149 | dev->driver->context_dtor(dev, pos->handle); |
| 150 | |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 151 | drm_legacy_ctxbitmap_free(dev, pos->handle); |
David Herrmann | 9f8d21e | 2014-07-23 09:01:12 +0200 | [diff] [blame] | 152 | list_del(&pos->head); |
| 153 | kfree(pos); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | mutex_unlock(&dev->ctxlist_mutex); |
| 158 | } |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /*@}*/ |
| 161 | |
| 162 | /******************************************************************/ |
| 163 | /** \name Per Context SAREA Support */ |
| 164 | /*@{*/ |
| 165 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 166 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | * Get per-context SAREA. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 168 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 170 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | * \param cmd command. |
| 172 | * \param arg user argument pointing to a drm_ctx_priv_map structure. |
| 173 | * \return zero on success or a negative number on failure. |
| 174 | * |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 175 | * Gets the map from drm_device::ctx_idr with the handle specified and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | * returns its handle. |
| 177 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 178 | int drm_legacy_getsareactx(struct drm_device *dev, void *data, |
| 179 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 181 | struct drm_ctx_priv_map *request = data; |
Benjamin Herrenschmidt | f77d390 | 2009-02-02 16:55:46 +1100 | [diff] [blame] | 182 | struct drm_local_map *map; |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 183 | struct drm_map_list *_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 185 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 186 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Chris Wilson | 69fdf42 | 2018-09-13 20:20:50 +0100 | [diff] [blame] | 187 | return -EOPNOTSUPP; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 188 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 189 | mutex_lock(&dev->struct_mutex); |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 190 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 191 | map = idr_find(&dev->ctx_idr, request->ctx_id); |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 192 | if (!map) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 193 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | return -EINVAL; |
| 195 | } |
| 196 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 197 | request->handle = NULL; |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 198 | list_for_each_entry(_entry, &dev->maplist, head) { |
Dave Airlie | d1f2b55 | 2005-08-05 22:11:22 +1000 | [diff] [blame] | 199 | if (_entry->map == map) { |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 200 | request->handle = |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 201 | (void *)(unsigned long)_entry->user_token; |
Dave Airlie | d1f2b55 | 2005-08-05 22:11:22 +1000 | [diff] [blame] | 202 | break; |
| 203 | } |
| 204 | } |
Ilija Hadzic | 09b4ea4 | 2011-10-28 17:43:28 -0400 | [diff] [blame] | 205 | |
| 206 | mutex_unlock(&dev->struct_mutex); |
| 207 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 208 | if (request->handle == NULL) |
Dave Airlie | d1f2b55 | 2005-08-05 22:11:22 +1000 | [diff] [blame] | 209 | return -EINVAL; |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | return 0; |
| 212 | } |
| 213 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 214 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | * Set per-context SAREA. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 216 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 218 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | * \param cmd command. |
| 220 | * \param arg user argument pointing to a drm_ctx_priv_map structure. |
| 221 | * \return zero on success or a negative number on failure. |
| 222 | * |
| 223 | * Searches the mapping specified in \p arg and update the entry in |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 224 | * drm_device::ctx_idr with it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 226 | int drm_legacy_setsareactx(struct drm_device *dev, void *data, |
| 227 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 229 | struct drm_ctx_priv_map *request = data; |
Benjamin Herrenschmidt | f77d390 | 2009-02-02 16:55:46 +1100 | [diff] [blame] | 230 | struct drm_local_map *map = NULL; |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 231 | struct drm_map_list *r_list = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 233 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 234 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Chris Wilson | 69fdf42 | 2018-09-13 20:20:50 +0100 | [diff] [blame] | 235 | return -EOPNOTSUPP; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 236 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 237 | mutex_lock(&dev->struct_mutex); |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 238 | list_for_each_entry(r_list, &dev->maplist, head) { |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 239 | if (r_list->map |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 240 | && r_list->user_token == (unsigned long) request->handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | goto found; |
| 242 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 243 | bad: |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 244 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return -EINVAL; |
| 246 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 247 | found: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | map = r_list->map; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 249 | if (!map) |
| 250 | goto bad; |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 251 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 252 | if (IS_ERR(idr_replace(&dev->ctx_idr, map, request->ctx_id))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | goto bad; |
Dave Airlie | 6296814 | 2007-07-17 10:46:52 +1000 | [diff] [blame] | 254 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 255 | mutex_unlock(&dev->struct_mutex); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | /*@}*/ |
| 261 | |
| 262 | /******************************************************************/ |
| 263 | /** \name The actual DRM context handling routines */ |
| 264 | /*@{*/ |
| 265 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 266 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | * Switch context. |
| 268 | * |
| 269 | * \param dev DRM device. |
| 270 | * \param old old context handle. |
| 271 | * \param new new context handle. |
| 272 | * \return zero on success or a negative number on failure. |
| 273 | * |
| 274 | * Attempt to set drm_device::context_flag. |
| 275 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 276 | static int drm_context_switch(struct drm_device * dev, int old, int new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 278 | if (test_and_set_bit(0, &dev->context_flag)) { |
| 279 | DRM_ERROR("Reentering -- FIXME\n"); |
| 280 | return -EBUSY; |
| 281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 283 | DRM_DEBUG("Context switch from %d to %d\n", old, new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 285 | if (new == dev->last_context) { |
| 286 | clear_bit(0, &dev->context_flag); |
| 287 | return 0; |
| 288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 290 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 293 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | * Complete context switch. |
| 295 | * |
| 296 | * \param dev DRM device. |
| 297 | * \param new new context handle. |
| 298 | * \return zero on success or a negative number on failure. |
| 299 | * |
| 300 | * Updates drm_device::last_context and drm_device::last_switch. Verifies the |
| 301 | * hardware lock is held, clears the drm_device::context_flag and wakes up |
| 302 | * drm_device::context_wait. |
| 303 | */ |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 304 | static int drm_context_switch_complete(struct drm_device *dev, |
| 305 | struct drm_file *file_priv, int new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 307 | dev->last_context = new; /* PRE/POST: This is the _only_ writer. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 309 | if (!_DRM_LOCK_IS_HELD(file_priv->master->lock.hw_lock->lock)) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 310 | DRM_ERROR("Lock isn't held after context switch\n"); |
| 311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 313 | /* If a context switch is ever initiated |
| 314 | when the kernel holds the lock, release |
Beatriz Martins de Carvalho | f0ce78e | 2021-04-18 15:48:25 +0100 | [diff] [blame] | 315 | that lock here. |
| 316 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 317 | clear_bit(0, &dev->context_flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 319 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 322 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | * Reserve contexts. |
| 324 | * |
| 325 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 326 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | * \param cmd command. |
| 328 | * \param arg user argument pointing to a drm_ctx_res structure. |
| 329 | * \return zero on success or a negative number on failure. |
| 330 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 331 | int drm_legacy_resctx(struct drm_device *dev, void *data, |
| 332 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 334 | struct drm_ctx_res *res = data; |
Dave Airlie | c60ce62 | 2007-07-11 15:27:12 +1000 | [diff] [blame] | 335 | struct drm_ctx ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | int i; |
| 337 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 338 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 339 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Chris Wilson | 69fdf42 | 2018-09-13 20:20:50 +0100 | [diff] [blame] | 340 | return -EOPNOTSUPP; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 341 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 342 | if (res->count >= DRM_RESERVED_CONTEXTS) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 343 | memset(&ctx, 0, sizeof(ctx)); |
| 344 | for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | ctx.handle = i; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 346 | if (copy_to_user(&res->contexts[i], &ctx, sizeof(ctx))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | return -EFAULT; |
| 348 | } |
| 349 | } |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 350 | res->count = DRM_RESERVED_CONTEXTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return 0; |
| 353 | } |
| 354 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 355 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | * Add context. |
| 357 | * |
| 358 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 359 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | * \param cmd command. |
| 361 | * \param arg user argument pointing to a drm_ctx structure. |
| 362 | * \return zero on success or a negative number on failure. |
| 363 | * |
| 364 | * Get a new handle for the context and copy to userspace. |
| 365 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 366 | int drm_legacy_addctx(struct drm_device *dev, void *data, |
| 367 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 369 | struct drm_ctx_list *ctx_entry; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 370 | struct drm_ctx *ctx = data; |
YueHaibing | c39191f | 2018-12-29 10:49:07 +0800 | [diff] [blame] | 371 | int tmp_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 373 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 374 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Chris Wilson | 69fdf42 | 2018-09-13 20:20:50 +0100 | [diff] [blame] | 375 | return -EOPNOTSUPP; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 376 | |
YueHaibing | c39191f | 2018-12-29 10:49:07 +0800 | [diff] [blame] | 377 | tmp_handle = drm_legacy_ctxbitmap_next(dev); |
| 378 | if (tmp_handle == DRM_KERNEL_CONTEXT) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 379 | /* Skip kernel's context and get a new one. */ |
YueHaibing | c39191f | 2018-12-29 10:49:07 +0800 | [diff] [blame] | 380 | tmp_handle = drm_legacy_ctxbitmap_next(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
YueHaibing | c39191f | 2018-12-29 10:49:07 +0800 | [diff] [blame] | 382 | DRM_DEBUG("%d\n", tmp_handle); |
| 383 | if (tmp_handle < 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 384 | DRM_DEBUG("Not enough free contexts.\n"); |
| 385 | /* Should this return -EBUSY instead? */ |
YueHaibing | c39191f | 2018-12-29 10:49:07 +0800 | [diff] [blame] | 386 | return tmp_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
YueHaibing | c39191f | 2018-12-29 10:49:07 +0800 | [diff] [blame] | 389 | ctx->handle = tmp_handle; |
| 390 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 391 | ctx_entry = kmalloc(sizeof(*ctx_entry), GFP_KERNEL); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 392 | if (!ctx_entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | DRM_DEBUG("out of memory\n"); |
| 394 | return -ENOMEM; |
| 395 | } |
| 396 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 397 | INIT_LIST_HEAD(&ctx_entry->head); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 398 | ctx_entry->handle = ctx->handle; |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 399 | ctx_entry->tag = file_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 401 | mutex_lock(&dev->ctxlist_mutex); |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 402 | list_add(&ctx_entry->head, &dev->ctxlist); |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 403 | mutex_unlock(&dev->ctxlist_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | return 0; |
| 406 | } |
| 407 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 408 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | * Get context. |
| 410 | * |
| 411 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 412 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | * \param cmd command. |
| 414 | * \param arg user argument pointing to a drm_ctx structure. |
| 415 | * \return zero on success or a negative number on failure. |
| 416 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 417 | int drm_legacy_getctx(struct drm_device *dev, void *data, |
| 418 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 420 | struct drm_ctx *ctx = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 422 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 423 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Chris Wilson | 69fdf42 | 2018-09-13 20:20:50 +0100 | [diff] [blame] | 424 | return -EOPNOTSUPP; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | /* This is 0, because we don't handle any context flags */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 427 | ctx->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 432 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | * Switch context. |
| 434 | * |
| 435 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 436 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | * \param cmd command. |
| 438 | * \param arg user argument pointing to a drm_ctx structure. |
| 439 | * \return zero on success or a negative number on failure. |
| 440 | * |
| 441 | * Calls context_switch(). |
| 442 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 443 | int drm_legacy_switchctx(struct drm_device *dev, void *data, |
| 444 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 446 | struct drm_ctx *ctx = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 448 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 449 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Chris Wilson | 69fdf42 | 2018-09-13 20:20:50 +0100 | [diff] [blame] | 450 | return -EOPNOTSUPP; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 451 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 452 | DRM_DEBUG("%d\n", ctx->handle); |
| 453 | return drm_context_switch(dev, dev->last_context, ctx->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 456 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | * New context. |
| 458 | * |
| 459 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 460 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | * \param cmd command. |
| 462 | * \param arg user argument pointing to a drm_ctx structure. |
| 463 | * \return zero on success or a negative number on failure. |
| 464 | * |
| 465 | * Calls context_switch_complete(). |
| 466 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 467 | int drm_legacy_newctx(struct drm_device *dev, void *data, |
| 468 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 470 | struct drm_ctx *ctx = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 472 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 473 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Chris Wilson | 69fdf42 | 2018-09-13 20:20:50 +0100 | [diff] [blame] | 474 | return -EOPNOTSUPP; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 475 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 476 | DRM_DEBUG("%d\n", ctx->handle); |
Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 477 | drm_context_switch_complete(dev, file_priv, ctx->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
Benjamin Gaignard | cc99482 | 2020-03-06 11:29:37 +0100 | [diff] [blame] | 482 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | * Remove context. |
| 484 | * |
| 485 | * \param inode device inode. |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 486 | * \param file_priv DRM file private. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | * \param cmd command. |
| 488 | * \param arg user argument pointing to a drm_ctx structure. |
| 489 | * \return zero on success or a negative number on failure. |
| 490 | * |
| 491 | * If not the special kernel context, calls ctxbitmap_free() to free the specified context. |
| 492 | */ |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 493 | int drm_legacy_rmctx(struct drm_device *dev, void *data, |
| 494 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 496 | struct drm_ctx *ctx = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 498 | if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && |
Daniel Vetter | fa53864 | 2016-08-03 21:11:10 +0200 | [diff] [blame] | 499 | !drm_core_check_feature(dev, DRIVER_LEGACY)) |
Chris Wilson | 69fdf42 | 2018-09-13 20:20:50 +0100 | [diff] [blame] | 500 | return -EOPNOTSUPP; |
Peter Antoine | 0e97598 | 2015-06-23 08:18:49 +0100 | [diff] [blame] | 501 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 502 | DRM_DEBUG("%d\n", ctx->handle); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 503 | if (ctx->handle != DRM_KERNEL_CONTEXT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | if (dev->driver->context_dtor) |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 505 | dev->driver->context_dtor(dev, ctx->handle); |
David Herrmann | e7b96070 | 2014-07-24 12:10:04 +0200 | [diff] [blame] | 506 | drm_legacy_ctxbitmap_free(dev, ctx->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 509 | mutex_lock(&dev->ctxlist_mutex); |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 510 | if (!list_empty(&dev->ctxlist)) { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 511 | struct drm_ctx_list *pos, *n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 513 | list_for_each_entry_safe(pos, n, &dev->ctxlist, head) { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 514 | if (pos->handle == ctx->handle) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 515 | list_del(&pos->head); |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 516 | kfree(pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | } |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 520 | mutex_unlock(&dev->ctxlist_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | /*@}*/ |