2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * drm_auth.h -- IOCTLs for authentication -*- linux-c -*-
8 * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
11 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
12 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
13 * All Rights Reserved.
15 * Permission is hereby granted, free of charge, to any person obtaining a
16 * copy of this software and associated documentation files (the "Software"),
17 * to deal in the Software without restriction, including without limitation
18 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 * and/or sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following conditions:
22 * The above copyright notice and this permission notice (including the next
23 * paragraph) shall be included in all copies or substantial portions of the
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 * OTHER DEALINGS IN THE SOFTWARE.
35 * Rickard E. (Rik) Faith <faith@valinux.com>
36 * Gareth Hughes <gareth@valinux.com>
40 #pragma ident "%Z%%M% %I% %E% SMI"
45 drm_hash_magic(drm_magic_t magic
)
47 return (magic
& (DRM_HASH_SIZE
-1));
51 drm_find_file(drm_device_t
*dev
, drm_magic_t magic
)
53 drm_file_t
*retval
= NULL
;
54 drm_magic_entry_t
*pt
;
57 hash
= drm_hash_magic(magic
);
58 for (pt
= dev
->magiclist
[hash
].head
; pt
; pt
= pt
->next
) {
59 if (pt
->magic
== magic
) {
69 drm_add_magic(drm_device_t
*dev
, drm_file_t
*priv
, drm_magic_t magic
)
72 drm_magic_entry_t
*entry
;
74 hash
= drm_hash_magic(magic
);
75 entry
= drm_alloc(sizeof (*entry
), DRM_MEM_MAGIC
);
83 if (dev
->magiclist
[hash
].tail
) {
84 dev
->magiclist
[hash
].tail
->next
= entry
;
85 dev
->magiclist
[hash
].tail
= entry
;
87 dev
->magiclist
[hash
].head
= entry
;
88 dev
->magiclist
[hash
].tail
= entry
;
96 drm_remove_magic(drm_device_t
*dev
, drm_magic_t magic
)
98 drm_magic_entry_t
*prev
= NULL
;
99 drm_magic_entry_t
*pt
;
102 DRM_DEBUG("drm_remove_magic : %d", magic
);
103 hash
= drm_hash_magic(magic
);
106 for (pt
= dev
->magiclist
[hash
].head
; pt
; prev
= pt
, pt
= pt
->next
) {
107 if (pt
->magic
== magic
) {
108 if (dev
->magiclist
[hash
].head
== pt
) {
109 dev
->magiclist
[hash
].head
= pt
->next
;
111 if (dev
->magiclist
[hash
].tail
== pt
) {
112 dev
->magiclist
[hash
].tail
= prev
;
115 prev
->next
= pt
->next
;
118 drm_free(pt
, sizeof (*pt
), DRM_MEM_MAGIC
);
129 drm_getmagic(DRM_IOCTL_ARGS
)
132 static drm_magic_t sequence
= 0;
135 /* Find unique magic */
137 auth
.magic
= fpriv
->magic
;
142 if (!atomic_cmpset_int(&sequence
, old
, auth
.magic
))
144 } while (drm_find_file(dev
, auth
.magic
));
145 fpriv
->magic
= auth
.magic
;
146 (void) drm_add_magic(dev
, fpriv
, auth
.magic
);
150 DRM_DEBUG("drm_getmagic: %u", auth
.magic
);
152 DRM_COPYTO_WITH_RETURN((void *)data
, &auth
, sizeof (auth
));
159 drm_authmagic(DRM_IOCTL_ARGS
)
165 DRM_COPYFROM_WITH_RETURN(&auth
, (void *)data
, sizeof (auth
));
167 if ((file
= drm_find_file(dev
, auth
.magic
))) {
168 file
->authenticated
= 1;
169 (void) drm_remove_magic(dev
, auth
.magic
);