/*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);
}
Exemple #2
0
/**
 * 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;
}
Exemple #3
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;
}
Exemple #4
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;
}
Exemple #5
0
/**
 * Authenticate with a magic.
 *
 * \param inode device inode.
 * \param file_priv DRM file private.
 * \param cmd command.
 * \param arg pointer to a drm_auth structure.
 * \return zero if authentication successed, or a negative number otherwise.
 *
 * Checks if \p file_priv is associated with the magic number passed in \arg.
 * This ioctl needs protection by the drm_global_mutex, which protects
 * struct drm_file::magic and struct drm_magic_entry::priv.
 */
int drm_authmagic(struct drm_device *dev, void *data,
		  struct drm_file *file_priv)
{
	struct drm_auth *auth = data;
	struct drm_file *file;

	DRM_DEBUG("%u\n", auth->magic);
	if ((file = drm_find_file(dev, auth->magic))) {
		file->authenticated = 1;
		drm_remove_magic(dev, auth->magic);
		return 0;
	}
	return -EINVAL;
}
/*ARGSUSED*/
int
drm_authmagic(DRM_IOCTL_ARGS)
{
	drm_auth_t	   auth;
	drm_file_t	   *file;
	DRM_DEVICE;

	DRM_COPYFROM_WITH_RETURN(&auth, (void *)data, sizeof (auth));

	if ((file = drm_find_file(dev, auth.magic))) {
		file->authenticated = 1;
		(void) drm_remove_magic(dev, auth.magic);
		return (0);
	}
	return (EINVAL);
}
Exemple #7
0
int drm_authmagic(DRM_IOCTL_ARGS)
{
	drm_auth_t	   auth;
	drm_file_t	   *file;
	DRM_DEVICE;

	DRM_COPY_FROM_USER_IOCTL(auth, (drm_auth_t *)data, sizeof(auth));

	DRM_DEBUG("%u\n", auth.magic);

	if ((file = drm_find_file(dev, auth.magic))) {
		file->authenticated = 1;
		drm_remove_magic(dev, auth.magic);
		return 0;
	}
	return DRM_ERR(EINVAL);
}
Exemple #8
0
/**
 * Authenticate with a magic.
 *
 * \param inode device inode.
 * \param filp file pointer.
 * \param cmd command.
 * \param arg pointer to a drm_auth structure.
 * \return zero if authentication successed, or a negative number otherwise.
 *
 * Checks if \p filp is associated with the magic number passed in \arg.
 */
int drm_authmagic(struct inode *inode, struct file *filp,
		   unsigned int cmd, unsigned long arg)
{
	drm_file_t	   *priv    = filp->private_data;
	drm_device_t	   *dev	    = priv->head->dev;
	drm_auth_t	   auth;
	drm_file_t	   *file;

	if (copy_from_user(&auth, (drm_auth_t __user *)arg, sizeof(auth)))
		return -EFAULT;
	DRM_DEBUG("%u\n", auth.magic);
	if ((file = drm_find_file(dev, auth.magic))) {
		file->authenticated = 1;
		drm_remove_magic(dev, auth.magic);
		return 0;
	}
	return -EINVAL;
}
Exemple #9
0
/**
 * Marks the client associated with the given magic number as authenticated.
 */
int drm_authmagic(struct drm_device *dev, void *data,
		  struct drm_file *file_priv)
{
	struct drm_auth *auth = data;
	struct drm_file *priv;

	DRM_DEBUG("%u\n", auth->magic);

	DRM_LOCK();
	priv = drm_find_file(dev, auth->magic);
	if (priv != NULL) {
		priv->authenticated = 1;
		drm_remove_magic(dev, auth->magic);
		DRM_UNLOCK();
		return 0;
	} else {
		DRM_UNLOCK();
		return EINVAL;
	}
}
Exemple #10
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;
}