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>
36 static int drm_hash_magic(drm_magic_t magic)
38 return magic & (DRM_HASH_SIZE-1);
41 static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
43 drm_file_t *retval = NULL;
44 drm_magic_entry_t *pt;
47 hash = drm_hash_magic(magic);
50 for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
51 if (pt->magic == magic) {
60 static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
63 drm_magic_entry_t *entry;
65 DRM_DEBUG("%d\n", magic);
67 hash = drm_hash_magic(magic);
68 entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT);
69 if (!entry) return DRM_ERR(ENOMEM);
75 if (dev->magiclist[hash].tail) {
76 dev->magiclist[hash].tail->next = entry;
77 dev->magiclist[hash].tail = entry;
79 dev->magiclist[hash].head = entry;
80 dev->magiclist[hash].tail = entry;
87 static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
89 drm_magic_entry_t *prev = NULL;
90 drm_magic_entry_t *pt;
93 DRM_DEBUG("%d\n", magic);
94 hash = drm_hash_magic(magic);
97 for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
98 if (pt->magic == magic) {
99 if (dev->magiclist[hash].head == pt) {
100 dev->magiclist[hash].head = pt->next;
102 if (dev->magiclist[hash].tail == pt) {
103 dev->magiclist[hash].tail = prev;
106 prev->next = pt->next;
115 return DRM_ERR(EINVAL);
118 int drm_getmagic(DRM_IOCTL_ARGS)
121 static drm_magic_t sequence = 0;
126 priv = drm_find_file_by_proc(dev, p);
129 DRM_ERROR("can't find authenticator\n");
133 /* Find unique magic */
135 auth.magic = priv->magic;
142 if (!atomic_cmpset_int(&sequence, old, auth.magic))
144 } while (drm_find_file(dev, auth.magic));
145 priv->magic = auth.magic;
146 drm_add_magic(dev, priv, auth.magic);
149 DRM_DEBUG("%u\n", auth.magic);
151 DRM_COPY_TO_USER_IOCTL((drm_auth_t *)data, auth, sizeof(auth));
156 int drm_authmagic(DRM_IOCTL_ARGS)
162 DRM_COPY_FROM_USER_IOCTL(auth, (drm_auth_t *)data, sizeof(auth));
164 DRM_DEBUG("%u\n", auth.magic);
166 if ((file = drm_find_file(dev, auth.magic))) {
167 file->authenticated = 1;
168 drm_remove_magic(dev, auth.magic);
171 return DRM_ERR(EINVAL);