1 /* drm_auth.h -- IOCTLs for authentication -*- linux-c -*-
2 * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
28 * Rickard E. (Rik) Faith <faith@valinux.com>
29 * Gareth Hughes <gareth@valinux.com>
32 #define __NO_VERSION__
35 static int DRM(hash_magic)(drm_magic_t magic)
37 return magic & (DRM_HASH_SIZE-1);
40 static drm_file_t *DRM(find_file)(drm_device_t *dev, drm_magic_t magic)
42 drm_file_t *retval = NULL;
43 drm_magic_entry_t *pt;
44 int hash = DRM(hash_magic)(magic);
46 down(&dev->struct_sem);
47 for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
48 if (pt->magic == magic) {
57 int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
60 drm_magic_entry_t *entry;
62 DRM_DEBUG("%d\n", magic);
64 hash = DRM(hash_magic)(magic);
65 entry = DRM(alloc)(sizeof(*entry), DRM_MEM_MAGIC);
66 if (!entry) return -ENOMEM;
67 memset(entry, 0, sizeof(*entry));
72 down(&dev->struct_sem);
73 if (dev->magiclist[hash].tail) {
74 dev->magiclist[hash].tail->next = entry;
75 dev->magiclist[hash].tail = entry;
77 dev->magiclist[hash].head = entry;
78 dev->magiclist[hash].tail = entry;
85 int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic)
87 drm_magic_entry_t *prev = NULL;
88 drm_magic_entry_t *pt;
91 DRM_DEBUG("%d\n", magic);
92 hash = DRM(hash_magic)(magic);
94 down(&dev->struct_sem);
95 for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
96 if (pt->magic == magic) {
97 if (dev->magiclist[hash].head == pt) {
98 dev->magiclist[hash].head = pt->next;
100 if (dev->magiclist[hash].tail == pt) {
101 dev->magiclist[hash].tail = prev;
104 prev->next = pt->next;
106 up(&dev->struct_sem);
110 up(&dev->struct_sem);
112 DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC);
117 int DRM(getmagic)(struct inode *inode, struct file *filp,
118 unsigned int cmd, unsigned long arg)
120 static drm_magic_t sequence = 0;
121 static spinlock_t lock = SPIN_LOCK_UNLOCKED;
122 drm_file_t *priv = filp->private_data;
123 drm_device_t *dev = priv->dev;
126 /* Find unique magic */
128 auth.magic = priv->magic;
132 if (!sequence) ++sequence; /* reserve 0 */
133 auth.magic = sequence++;
135 } while (DRM(find_file)(dev, auth.magic));
136 priv->magic = auth.magic;
137 DRM(add_magic)(dev, priv, auth.magic);
140 DRM_DEBUG("%u\n", auth.magic);
141 if (copy_to_user((drm_auth_t *)arg, &auth, sizeof(auth)))
146 int DRM(authmagic)(struct inode *inode, struct file *filp,
147 unsigned int cmd, unsigned long arg)
149 drm_file_t *priv = filp->private_data;
150 drm_device_t *dev = priv->dev;
154 if (copy_from_user(&auth, (drm_auth_t *)arg, sizeof(auth)))
156 DRM_DEBUG("%u\n", auth.magic);
157 if ((file = DRM(find_file)(dev, auth.magic))) {
158 file->authenticated = 1;
159 DRM(remove_magic)(dev, auth.magic);