1 /* drm_auth.h -- IOCTLs for authentication -*- linux-c -*-
2 * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
35 #include "dev/drm/drmP.h"
37 static int drm_hash_magic(drm_magic_t magic)
39 return magic & (DRM_HASH_SIZE-1);
42 static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
44 drm_file_t *retval = NULL;
45 drm_magic_entry_t *pt;
48 hash = drm_hash_magic(magic);
51 for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
52 if (pt->magic == magic) {
61 static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
64 drm_magic_entry_t *entry;
66 DRM_DEBUG("%d\n", magic);
68 hash = drm_hash_magic(magic);
69 entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT);
70 if (!entry) return DRM_ERR(ENOMEM);
76 if (dev->magiclist[hash].tail) {
77 dev->magiclist[hash].tail->next = entry;
78 dev->magiclist[hash].tail = entry;
80 dev->magiclist[hash].head = entry;
81 dev->magiclist[hash].tail = entry;
88 static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
90 drm_magic_entry_t *prev = NULL;
91 drm_magic_entry_t *pt;
94 DRM_DEBUG("%d\n", magic);
95 hash = drm_hash_magic(magic);
98 for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
99 if (pt->magic == magic) {
100 if (dev->magiclist[hash].head == pt) {
101 dev->magiclist[hash].head = pt->next;
103 if (dev->magiclist[hash].tail == pt) {
104 dev->magiclist[hash].tail = prev;
107 prev->next = pt->next;
116 return DRM_ERR(EINVAL);
119 int drm_getmagic(DRM_IOCTL_ARGS)
122 static drm_magic_t sequence = 0;
127 priv = drm_find_file_by_proc(dev, p);
130 DRM_ERROR("can't find authenticator\n");
134 /* Find unique magic */
136 auth.magic = priv->magic;
143 if (!atomic_cmpset_int(&sequence, old, auth.magic))
145 } while (drm_find_file(dev, auth.magic));
146 priv->magic = auth.magic;
147 drm_add_magic(dev, priv, auth.magic);
150 DRM_DEBUG("%u\n", auth.magic);
152 DRM_COPY_TO_USER_IOCTL((drm_auth_t *)data, auth, sizeof(auth));
157 int drm_authmagic(DRM_IOCTL_ARGS)
163 DRM_COPY_FROM_USER_IOCTL(auth, (drm_auth_t *)data, sizeof(auth));
165 DRM_DEBUG("%u\n", auth.magic);
167 if ((file = drm_find_file(dev, auth.magic))) {
168 file->authenticated = 1;
169 drm_remove_magic(dev, auth.magic);
172 return DRM_ERR(EINVAL);