#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"
/* 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 */
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;
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);
}
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) {
} 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;
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;