2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
|
|
|
*
|
|
|
|
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
|
|
|
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
2015-05-05 02:01:30 +07:00
|
|
|
* Author Rickard E. (Rik) Faith <faith@valinux.com>
|
|
|
|
* Author Gareth Hughes <gareth@valinux.com>
|
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2012-10-03 00:01:07 +07:00
|
|
|
#include <drm/drmP.h>
|
2014-09-10 17:43:53 +07:00
|
|
|
#include "drm_internal.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
2015-05-05 02:01:30 +07:00
|
|
|
* drm_getmagic - Get unique magic of a client
|
|
|
|
* @dev: DRM device to operate on
|
|
|
|
* @data: ioctl data containing the drm_auth object
|
|
|
|
* @file_priv: DRM file that performs the operation
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2015-05-05 02:01:30 +07:00
|
|
|
* This looks up the unique magic of the passed client and returns it. If the
|
|
|
|
* client did not have a magic assigned, yet, a new one is registered. The magic
|
|
|
|
* is stored in the passed drm_auth object.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2015-05-05 02:01:30 +07:00
|
|
|
* Returns: 0 on success, negative error code on failure.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2007-09-03 09:06:45 +07:00
|
|
|
int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-09-03 09:06:45 +07:00
|
|
|
struct drm_auth *auth = data;
|
2015-05-05 02:01:30 +07:00
|
|
|
int ret = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-05-05 02:01:30 +07:00
|
|
|
mutex_lock(&dev->struct_mutex);
|
|
|
|
if (!file_priv->magic) {
|
|
|
|
ret = idr_alloc(&file_priv->master->magic_map, file_priv,
|
|
|
|
1, 0, GFP_KERNEL);
|
|
|
|
if (ret >= 0)
|
|
|
|
file_priv->magic = ret;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2015-05-05 02:01:30 +07:00
|
|
|
auth->magic = file_priv->magic;
|
|
|
|
mutex_unlock(&dev->struct_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-09-03 09:06:45 +07:00
|
|
|
DRM_DEBUG("%u\n", auth->magic);
|
|
|
|
|
2015-05-05 02:01:30 +07:00
|
|
|
return ret < 0 ? ret : 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-05 02:01:30 +07:00
|
|
|
* drm_authmagic - Authenticate client with a magic
|
|
|
|
* @dev: DRM device to operate on
|
|
|
|
* @data: ioctl data containing the drm_auth object
|
|
|
|
* @file_priv: DRM file that performs the operation
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2015-05-05 02:01:30 +07:00
|
|
|
* This looks up a DRM client by the passed magic and authenticates it.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2015-05-05 02:01:30 +07:00
|
|
|
* Returns: 0 on success, negative error code on failure.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2007-09-03 09:06:45 +07:00
|
|
|
int drm_authmagic(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-09-03 09:06:45 +07:00
|
|
|
struct drm_auth *auth = data;
|
2007-07-11 12:53:27 +07:00
|
|
|
struct drm_file *file;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-09-03 09:06:45 +07:00
|
|
|
DRM_DEBUG("%u\n", auth->magic);
|
2015-05-05 02:01:30 +07:00
|
|
|
|
|
|
|
mutex_lock(&dev->struct_mutex);
|
|
|
|
file = idr_find(&file_priv->master->magic_map, auth->magic);
|
|
|
|
if (file) {
|
2005-04-17 05:20:36 +07:00
|
|
|
file->authenticated = 1;
|
2015-05-05 02:01:30 +07:00
|
|
|
idr_replace(&file_priv->master->magic_map, NULL, auth->magic);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2015-05-05 02:01:30 +07:00
|
|
|
mutex_unlock(&dev->struct_mutex);
|
|
|
|
|
|
|
|
return file ? 0 : -EINVAL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|