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>
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "dev/drm/drmP.h"
39 static int drm_hash_magic(drm_magic_t magic)
41 return magic & (DRM_HASH_SIZE-1);
44 static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
46 drm_file_t *retval = NULL;
47 drm_magic_entry_t *pt;
50 hash = drm_hash_magic(magic);
53 for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
54 if (pt->magic == magic) {
63 static int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
66 drm_magic_entry_t *entry;
68 DRM_DEBUG("%d\n", magic);
70 hash = drm_hash_magic(magic);
71 entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT);
72 if (!entry) return DRM_ERR(ENOMEM);
78 if (dev->magiclist[hash].tail) {
79 dev->magiclist[hash].tail->next = entry;
80 dev->magiclist[hash].tail = entry;
82 dev->magiclist[hash].head = entry;
83 dev->magiclist[hash].tail = entry;
90 static int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
92 drm_magic_entry_t *prev = NULL;
93 drm_magic_entry_t *pt;
96 DRM_DEBUG("%d\n", magic);
97 hash = drm_hash_magic(magic);
100 for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
101 if (pt->magic == magic) {
102 if (dev->magiclist[hash].head == pt) {
103 dev->magiclist[hash].head = pt->next;
105 if (dev->magiclist[hash].tail == pt) {
106 dev->magiclist[hash].tail = prev;
109 prev->next = pt->next;
118 return DRM_ERR(EINVAL);
121 int drm_getmagic(DRM_IOCTL_ARGS)
124 static drm_magic_t sequence = 0;
129 priv = drm_find_file_by_proc(dev, p);
132 DRM_ERROR("can't find authenticator\n");
136 /* Find unique magic */
138 auth.magic = priv->magic;
145 if (!atomic_cmpset_int(&sequence, old, auth.magic))
147 } while (drm_find_file(dev, auth.magic));
148 priv->magic = auth.magic;
149 drm_add_magic(dev, priv, auth.magic);
152 DRM_DEBUG("%u\n", auth.magic);
154 DRM_COPY_TO_USER_IOCTL((drm_auth_t *)data, auth, sizeof(auth));
159 int drm_authmagic(DRM_IOCTL_ARGS)
165 DRM_COPY_FROM_USER_IOCTL(auth, (drm_auth_t *)data, sizeof(auth));
167 DRM_DEBUG("%u\n", auth.magic);
169 if ((file = drm_find_file(dev, auth.magic))) {
170 file->authenticated = 1;
171 drm_remove_magic(dev, auth.magic);
174 return DRM_ERR(EINVAL);