Home | History | Annotate | Line # | Download | only in drm
drm_auth.c revision 1.3
      1  1.3  riastrad /*	$NetBSD: drm_auth.c,v 1.3 2018/08/27 04:58:19 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Created: Tue Feb  2 08:37:54 1999 by faith (at) valinux.com
      5  1.1  riastrad  *
      6  1.1  riastrad  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
      7  1.1  riastrad  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
      8  1.1  riastrad  * All Rights Reserved.
      9  1.1  riastrad  *
     10  1.3  riastrad  * Author Rickard E. (Rik) Faith <faith (at) valinux.com>
     11  1.3  riastrad  * Author Gareth Hughes <gareth (at) valinux.com>
     12  1.3  riastrad  *
     13  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
     14  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
     15  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     16  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     17  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     18  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     19  1.1  riastrad  *
     20  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     21  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     22  1.1  riastrad  * Software.
     23  1.1  riastrad  *
     24  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     25  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     26  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     27  1.1  riastrad  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     28  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     29  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     30  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     31  1.1  riastrad  */
     32  1.1  riastrad 
     33  1.3  riastrad #include <sys/cdefs.h>
     34  1.3  riastrad __KERNEL_RCSID(0, "$NetBSD: drm_auth.c,v 1.3 2018/08/27 04:58:19 riastradh Exp $");
     35  1.3  riastrad 
     36  1.1  riastrad #include <drm/drmP.h>
     37  1.3  riastrad #include "drm_internal.h"
     38  1.1  riastrad 
     39  1.1  riastrad /**
     40  1.3  riastrad  * drm_getmagic - Get unique magic of a client
     41  1.3  riastrad  * @dev: DRM device to operate on
     42  1.3  riastrad  * @data: ioctl data containing the drm_auth object
     43  1.3  riastrad  * @file_priv: DRM file that performs the operation
     44  1.1  riastrad  *
     45  1.3  riastrad  * This looks up the unique magic of the passed client and returns it. If the
     46  1.3  riastrad  * client did not have a magic assigned, yet, a new one is registered. The magic
     47  1.3  riastrad  * is stored in the passed drm_auth object.
     48  1.1  riastrad  *
     49  1.3  riastrad  * Returns: 0 on success, negative error code on failure.
     50  1.1  riastrad  */
     51  1.3  riastrad int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
     52  1.1  riastrad {
     53  1.3  riastrad 	struct drm_auth *auth = data;
     54  1.3  riastrad 	int ret = 0;
     55  1.1  riastrad 
     56  1.1  riastrad 	mutex_lock(&dev->struct_mutex);
     57  1.3  riastrad 	if (!file_priv->magic) {
     58  1.3  riastrad 		ret = idr_alloc(&file_priv->master->magic_map, file_priv,
     59  1.3  riastrad 				1, 0, GFP_KERNEL);
     60  1.3  riastrad 		if (ret >= 0)
     61  1.3  riastrad 			file_priv->magic = ret;
     62  1.1  riastrad 	}
     63  1.3  riastrad 	auth->magic = file_priv->magic;
     64  1.1  riastrad 	mutex_unlock(&dev->struct_mutex);
     65  1.1  riastrad 
     66  1.3  riastrad 	DRM_DEBUG("%u\n", auth->magic);
     67  1.1  riastrad 
     68  1.3  riastrad 	return ret < 0 ? ret : 0;
     69  1.1  riastrad }
     70  1.1  riastrad 
     71  1.1  riastrad /**
     72  1.3  riastrad  * drm_authmagic - Authenticate client with a magic
     73  1.3  riastrad  * @dev: DRM device to operate on
     74  1.3  riastrad  * @data: ioctl data containing the drm_auth object
     75  1.3  riastrad  * @file_priv: DRM file that performs the operation
     76  1.1  riastrad  *
     77  1.3  riastrad  * This looks up a DRM client by the passed magic and authenticates it.
     78  1.1  riastrad  *
     79  1.3  riastrad  * Returns: 0 on success, negative error code on failure.
     80  1.1  riastrad  */
     81  1.1  riastrad int drm_authmagic(struct drm_device *dev, void *data,
     82  1.1  riastrad 		  struct drm_file *file_priv)
     83  1.1  riastrad {
     84  1.1  riastrad 	struct drm_auth *auth = data;
     85  1.1  riastrad 	struct drm_file *file;
     86  1.1  riastrad 
     87  1.1  riastrad 	DRM_DEBUG("%u\n", auth->magic);
     88  1.3  riastrad 
     89  1.3  riastrad 	mutex_lock(&dev->struct_mutex);
     90  1.3  riastrad 	file = idr_find(&file_priv->master->magic_map, auth->magic);
     91  1.3  riastrad 	if (file) {
     92  1.1  riastrad 		file->authenticated = 1;
     93  1.3  riastrad 		idr_replace(&file_priv->master->magic_map, NULL, auth->magic);
     94  1.1  riastrad 	}
     95  1.3  riastrad 	mutex_unlock(&dev->struct_mutex);
     96  1.3  riastrad 
     97  1.3  riastrad 	return file ? 0 : -EINVAL;
     98  1.1  riastrad }
     99