Home | History | Annotate | Line # | Download | only in drm
drm_auth.c revision 1.2.34.1
      1  1.2.34.1  christos /*	$NetBSD: drm_auth.c,v 1.2.34.1 2019/06/10 22:07:57 christos 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.2.34.1  christos  * Author Rickard E. (Rik) Faith <faith (at) valinux.com>
     11  1.2.34.1  christos  * Author Gareth Hughes <gareth (at) valinux.com>
     12  1.2.34.1  christos  *
     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.2.34.1  christos #include <sys/cdefs.h>
     34  1.2.34.1  christos __KERNEL_RCSID(0, "$NetBSD: drm_auth.c,v 1.2.34.1 2019/06/10 22:07:57 christos Exp $");
     35       1.1  riastrad 
     36  1.2.34.1  christos #include <drm/drmP.h>
     37  1.2.34.1  christos #include "drm_internal.h"
     38       1.1  riastrad 
     39       1.1  riastrad /**
     40  1.2.34.1  christos  * drm_getmagic - Get unique magic of a client
     41  1.2.34.1  christos  * @dev: DRM device to operate on
     42  1.2.34.1  christos  * @data: ioctl data containing the drm_auth object
     43  1.2.34.1  christos  * @file_priv: DRM file that performs the operation
     44       1.1  riastrad  *
     45  1.2.34.1  christos  * This looks up the unique magic of the passed client and returns it. If the
     46  1.2.34.1  christos  * client did not have a magic assigned, yet, a new one is registered. The magic
     47  1.2.34.1  christos  * is stored in the passed drm_auth object.
     48       1.1  riastrad  *
     49  1.2.34.1  christos  * Returns: 0 on success, negative error code on failure.
     50       1.1  riastrad  */
     51       1.1  riastrad int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
     52       1.1  riastrad {
     53       1.1  riastrad 	struct drm_auth *auth = data;
     54  1.2.34.1  christos 	int ret = 0;
     55       1.1  riastrad 
     56  1.2.34.1  christos 	idr_preload(GFP_KERNEL);
     57  1.2.34.1  christos 	mutex_lock(&dev->struct_mutex);
     58  1.2.34.1  christos 	if (!file_priv->magic) {
     59  1.2.34.1  christos 		ret = idr_alloc(&file_priv->master->magic_map, file_priv,
     60  1.2.34.1  christos 				1, 0, GFP_KERNEL);
     61  1.2.34.1  christos 		if (ret >= 0)
     62  1.2.34.1  christos 			file_priv->magic = ret;
     63       1.1  riastrad 	}
     64  1.2.34.1  christos 	auth->magic = file_priv->magic;
     65  1.2.34.1  christos 	mutex_unlock(&dev->struct_mutex);
     66  1.2.34.1  christos 	idr_preload_end();
     67       1.1  riastrad 
     68       1.1  riastrad 	DRM_DEBUG("%u\n", auth->magic);
     69       1.1  riastrad 
     70  1.2.34.1  christos 	return ret < 0 ? ret : 0;
     71       1.1  riastrad }
     72       1.1  riastrad 
     73       1.1  riastrad /**
     74  1.2.34.1  christos  * drm_authmagic - Authenticate client with a magic
     75  1.2.34.1  christos  * @dev: DRM device to operate on
     76  1.2.34.1  christos  * @data: ioctl data containing the drm_auth object
     77  1.2.34.1  christos  * @file_priv: DRM file that performs the operation
     78       1.1  riastrad  *
     79  1.2.34.1  christos  * This looks up a DRM client by the passed magic and authenticates it.
     80  1.2.34.1  christos  *
     81  1.2.34.1  christos  * Returns: 0 on success, negative error code on failure.
     82       1.1  riastrad  */
     83       1.1  riastrad int drm_authmagic(struct drm_device *dev, void *data,
     84       1.1  riastrad 		  struct drm_file *file_priv)
     85       1.1  riastrad {
     86       1.1  riastrad 	struct drm_auth *auth = data;
     87       1.1  riastrad 	struct drm_file *file;
     88       1.1  riastrad 
     89       1.1  riastrad 	DRM_DEBUG("%u\n", auth->magic);
     90  1.2.34.1  christos 
     91  1.2.34.1  christos 	mutex_lock(&dev->struct_mutex);
     92  1.2.34.1  christos 	file = idr_find(&file_priv->master->magic_map, auth->magic);
     93  1.2.34.1  christos 	if (file) {
     94       1.1  riastrad 		file->authenticated = 1;
     95  1.2.34.1  christos 		idr_replace(&file_priv->master->magic_map, NULL, auth->magic);
     96       1.1  riastrad 	}
     97  1.2.34.1  christos 	mutex_unlock(&dev->struct_mutex);
     98  1.2.34.1  christos 
     99  1.2.34.1  christos 	return file ? 0 : -EINVAL;
    100       1.1  riastrad }
    101