2005-04-16 16:20:36 -06: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-04 13:01:30 -06:00
|
|
|
* Author Rickard E. (Rik) Faith <faith@valinux.com>
|
|
|
|
* Author Gareth Hughes <gareth@valinux.com>
|
|
|
|
*
|
2005-04-16 16:20:36 -06: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-02 11:01:07 -06:00
|
|
|
#include <drm/drmP.h>
|
2014-09-10 04:43:53 -06:00
|
|
|
#include "drm_internal.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/**
|
2015-05-04 13:01:30 -06: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-16 16:20:36 -06:00
|
|
|
*
|
2015-05-04 13:01:30 -06: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-16 16:20:36 -06:00
|
|
|
*
|
2015-05-04 13:01:30 -06:00
|
|
|
* Returns: 0 on success, negative error code on failure.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2007-09-02 20:06:45 -06:00
|
|
|
int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-09-02 20:06:45 -06:00
|
|
|
struct drm_auth *auth = data;
|
2015-05-04 13:01:30 -06:00
|
|
|
int ret = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-05-04 13:01:30 -06: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-16 16:20:36 -06:00
|
|
|
}
|
2015-05-04 13:01:30 -06:00
|
|
|
auth->magic = file_priv->magic;
|
|
|
|
mutex_unlock(&dev->struct_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-09-02 20:06:45 -06:00
|
|
|
DRM_DEBUG("%u\n", auth->magic);
|
|
|
|
|
2015-05-04 13:01:30 -06:00
|
|
|
return ret < 0 ? ret : 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-04 13:01:30 -06: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-16 16:20:36 -06:00
|
|
|
*
|
2015-05-04 13:01:30 -06:00
|
|
|
* This looks up a DRM client by the passed magic and authenticates it.
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
2015-05-04 13:01:30 -06:00
|
|
|
* Returns: 0 on success, negative error code on failure.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2007-09-02 20:06:45 -06:00
|
|
|
int drm_authmagic(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-09-02 20:06:45 -06:00
|
|
|
struct drm_auth *auth = data;
|
2007-07-10 23:53:27 -06:00
|
|
|
struct drm_file *file;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-09-02 20:06:45 -06:00
|
|
|
DRM_DEBUG("%u\n", auth->magic);
|
2015-05-04 13:01:30 -06:00
|
|
|
|
|
|
|
mutex_lock(&dev->struct_mutex);
|
|
|
|
file = idr_find(&file_priv->master->magic_map, auth->magic);
|
|
|
|
if (file) {
|
2005-04-16 16:20:36 -06:00
|
|
|
file->authenticated = 1;
|
2015-05-04 13:01:30 -06:00
|
|
|
idr_replace(&file_priv->master->magic_map, NULL, auth->magic);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2015-05-04 13:01:30 -06:00
|
|
|
mutex_unlock(&dev->struct_mutex);
|
|
|
|
|
|
|
|
return file ? 0 : -EINVAL;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|