/** * Get a unique magic number (ioctl). * * \param inode device inode. * \param filp file pointer. * \param cmd command. * \param arg pointer to a resulting drm_auth structure. * \return zero on success, or a negative number on failure. * * If there is a magic number in drm_file::magic then use it, otherwise * searches an unique non-zero magic number and add it associating it with \p * filp. */ int drm_getmagic(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { static drm_magic_t sequence = 0; static DEFINE_SPINLOCK(lock); drm_file_t *priv = filp->private_data; drm_device_t *dev = priv->head->dev; drm_auth_t auth; /* Find unique magic */ if (priv->magic) { auth.magic = priv->magic; } else { do { spin_lock(&lock); if (!sequence) ++sequence; /* reserve 0 */ auth.magic = sequence++; spin_unlock(&lock); } while (drm_find_file(dev, auth.magic)); priv->magic = auth.magic; drm_add_magic(dev, priv, auth.magic); } DRM_DEBUG("%u\n", auth.magic); if (copy_to_user((drm_auth_t __user *)arg, &auth, sizeof(auth))) return -EFAULT; return 0; }
/** * Called by the client, this returns a unique magic number to be authorized * by the master. * * The master may use its own knowledge of the client (such as the X * connection that the magic is passed over) to determine if the magic number * should be authenticated. */ int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv) { static drm_magic_t sequence = 0; struct drm_auth *auth = data; /* Find unique magic */ if (file_priv->magic) { auth->magic = file_priv->magic; } else { DRM_LOCK(); do { int old = sequence; auth->magic = old+1; if (!atomic_cmpset_int(&sequence, old, auth->magic)) continue; } while (drm_find_file(dev, auth->magic)); file_priv->magic = auth->magic; drm_add_magic(dev, file_priv, auth->magic); DRM_UNLOCK(); } DRM_DEBUG("%u\n", auth->magic); return 0; }
/*ARGSUSED*/ int drm_getmagic(DRM_IOCTL_ARGS) { DRM_DEVICE; static drm_magic_t sequence = 0; drm_auth_t auth; /* Find unique magic */ if (fpriv->magic) { auth.magic = fpriv->magic; } else { do { int old = sequence; auth.magic = old+1; if (!atomic_cmpset_int(&sequence, old, auth.magic)) continue; } while (drm_find_file(dev, auth.magic)); fpriv->magic = auth.magic; (void) drm_add_magic(dev, fpriv, auth.magic); } DRM_DEBUG("drm_getmagic: %u", auth.magic); DRM_COPYTO_WITH_RETURN((void *)data, &auth, sizeof (auth)); return (0); }
/** * Get a unique magic number (ioctl). * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg pointer to a resulting drm_auth structure. * \return zero on success, or a negative number on failure. * * If there is a magic number in drm_file::magic then use it, otherwise * searches an unique non-zero magic number and add it associating it with \p * file_priv. * This ioctl needs protection by the drm_global_mutex, which protects * struct drm_file::magic and struct drm_magic_entry::priv. */ int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv) { static drm_magic_t sequence = 0; static struct spinlock lock = SPINLOCK_INITIALIZER(&lock, "drm_gm"); struct drm_auth *auth = data; /* Find unique magic */ if (file_priv->magic) { auth->magic = file_priv->magic; } else { do { spin_lock(&lock); if (!sequence) ++sequence; /* reserve 0 */ auth->magic = sequence++; spin_unlock(&lock); } while (drm_find_file(dev, auth->magic)); file_priv->magic = auth->magic; drm_add_magic(dev, file_priv, auth->magic); } DRM_DEBUG("%u\n", auth->magic); return 0; }
int drm_getmagic(DRM_IOCTL_ARGS) { DRM_DEVICE; static drm_magic_t sequence = 0; drm_auth_t auth; drm_file_t *priv; DRM_LOCK(); priv = drm_find_file_by_proc(dev, p); DRM_UNLOCK(); if (priv == NULL) { DRM_ERROR("can't find authenticator\n"); return EINVAL; } /* Find unique magic */ if (priv->magic) { auth.magic = priv->magic; } else { do { int old = sequence; auth.magic = old+1; if (!atomic_cmpset_int(&sequence, old, auth.magic)) continue; } while (drm_find_file(dev, auth.magic)); priv->magic = auth.magic; drm_add_magic(dev, priv, auth.magic); } DRM_DEBUG("%u\n", auth.magic); DRM_COPY_TO_USER_IOCTL((drm_auth_t *)data, auth, sizeof(auth)); return 0; }