summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2008-08-13 19:33:30 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2008-08-13 19:33:30 +0000
commit374ec5ab0b2b7aed2e7475d6e513e01a52625bb5 (patch)
tree2e9ac29a0f16f700e9da82bb6b3012101de37e7d /sys/dev
parent075f6e881e3d8ef1efe4d1b70a1ff9f0eec77db2 (diff)
Generate the magic id using idgen32(). While i'm here fix the locking a
bit so we don't sleep with a spinlock. ok djm@.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/drm/drmP.h2
-rw-r--r--sys/dev/pci/drm/drm_auth.c17
-rw-r--r--sys/dev/pci/drm/drm_drv.c1
3 files changed, 11 insertions, 9 deletions
diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h
index 66766471048..5529ce22b85 100644
--- a/sys/dev/pci/drm/drmP.h
+++ b/sys/dev/pci/drm/drmP.h
@@ -66,6 +66,7 @@
#include <dev/pci/vga_pcivar.h>
#include <machine/param.h>
#include <machine/bus.h>
+#include <crypto/idgen.h>
#include "drm.h"
#include "drm_linux_list.h"
@@ -634,6 +635,7 @@ struct drm_device {
/* Authentication */
drm_file_list_t files;
+ struct idgen32_ctx magicid;
SPLAY_HEAD(drm_magic_tree, drm_magic_entry) magiclist;
/* Linked list of mappable regions. Protected by dev_lock */
diff --git a/sys/dev/pci/drm/drm_auth.c b/sys/dev/pci/drm/drm_auth.c
index 02568d915cd..4b1e20ca92d 100644
--- a/sys/dev/pci/drm/drm_auth.c
+++ b/sys/dev/pci/drm/drm_auth.c
@@ -70,7 +70,10 @@ drm_add_magic(struct drm_device *dev, struct drm_file *priv, drm_magic_t magic)
DRM_SPINLOCK_ASSERT(&dev->dev_lock);
- if ((entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC)) == NULL)
+ DRM_UNLOCK();
+ entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
+ DRM_LOCK();
+ if (entry == NULL)
return (ENOMEM);
entry->magic = magic;
entry->priv = priv;
@@ -97,7 +100,9 @@ drm_remove_magic(struct drm_device *dev, drm_magic_t magic)
if ((pt = SPLAY_FIND(drm_magic_tree, &dev->magiclist, &key)) == NULL)
return (EINVAL);
SPLAY_REMOVE(drm_magic_tree, &dev->magiclist, pt);
+ DRM_UNLOCK();
drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
+ DRM_LOCK();
return (0);
}
@@ -112,8 +117,7 @@ drm_remove_magic(struct drm_device *dev, drm_magic_t magic)
int
drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
{
- static drm_magic_t sequence = 0;
- drm_auth_t *auth = data;
+ drm_auth_t *auth = data;
/* Find unique magic */
if (file_priv->magic) {
@@ -121,12 +125,7 @@ drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
} else {
DRM_LOCK();
do {
- int old = sequence;
-
- auth->magic = ++old;
-
- if (!atomic_cmpset_int(&sequence, old, auth->magic))
- continue;
+ auth->magic = idgen32(&dev->magicid);
} while (drm_find_file(dev, auth->magic));
file_priv->magic = auth->magic;
diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c
index 88fc5316ed8..f5b201e32e1 100644
--- a/sys/dev/pci/drm/drm_drv.c
+++ b/sys/dev/pci/drm/drm_drv.c
@@ -253,6 +253,7 @@ drm_firstopen(struct drm_device *dev)
for ( i = 0 ; i < DRM_ARRAY_SIZE(dev->counts) ; i++ )
atomic_set( &dev->counts[i], 0 );
+ idgen32_init(&dev->magicid);
SPLAY_INIT(&dev->magiclist);
dev->lock.lock_queue = 0;