Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com |
| 3 | * |
| 4 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. |
| 5 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 6 | * All Rights Reserved. |
| 7 | * |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +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 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 31 | #include <drm/drmP.h> |
Daniel Vetter | 67d0ec4 | 2014-09-10 12:43:53 +0200 | [diff] [blame] | 32 | #include "drm_internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 35 | * drm_getmagic - Get unique magic of a client |
| 36 | * @dev: DRM device to operate on |
| 37 | * @data: ioctl data containing the drm_auth object |
| 38 | * @file_priv: DRM file that performs the operation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | * |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 40 | * This looks up the unique magic of the passed client and returns it. If the |
| 41 | * client did not have a magic assigned, yet, a new one is registered. The magic |
| 42 | * is stored in the passed drm_auth object. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | * |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 44 | * Returns: 0 on success, negative error code on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 46 | int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 48 | struct drm_auth *auth = data; |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 49 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 51 | mutex_lock(&dev->struct_mutex); |
| 52 | if (!file_priv->magic) { |
| 53 | ret = idr_alloc(&file_priv->master->magic_map, file_priv, |
| 54 | 1, 0, GFP_KERNEL); |
| 55 | if (ret >= 0) |
| 56 | file_priv->magic = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 58 | auth->magic = file_priv->magic; |
| 59 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 61 | DRM_DEBUG("%u\n", auth->magic); |
| 62 | |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 63 | return ret < 0 ? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 67 | * drm_authmagic - Authenticate client with a magic |
| 68 | * @dev: DRM device to operate on |
| 69 | * @data: ioctl data containing the drm_auth object |
| 70 | * @file_priv: DRM file that performs the operation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | * |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 72 | * This looks up a DRM client by the passed magic and authenticates it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | * |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 74 | * Returns: 0 on success, negative error code on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 76 | int drm_authmagic(struct drm_device *dev, void *data, |
| 77 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 79 | struct drm_auth *auth = data; |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 80 | struct drm_file *file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 82 | DRM_DEBUG("%u\n", auth->magic); |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 83 | |
| 84 | mutex_lock(&dev->struct_mutex); |
| 85 | file = idr_find(&file_priv->master->magic_map, auth->magic); |
| 86 | if (file) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | file->authenticated = 1; |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 88 | idr_replace(&file_priv->master->magic_map, NULL, auth->magic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
David Herrmann | 32e7b94 | 2015-05-04 21:01:30 +0200 | [diff] [blame] | 90 | mutex_unlock(&dev->struct_mutex); |
| 91 | |
| 92 | return file ? 0 : -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |