Exemple #1
0
static ssize_t parrot_device_read(struct file* filp, char __user *buffer, size_t length, loff_t* offset)
{
	int retval;
	unsigned int copied;

	/* The default from 'cat' is to issue multiple reads until the FIFO is depleted
	 * one_shot avoids that */
	if (one_shot && message_read) return 0;
	dbg("");

	if (kfifo_is_empty(&parrot_msg_fifo)) {
		dbg("no message in fifo\n");
		return 0;
	}

	retval = kfifo_to_user(&parrot_msg_fifo, buffer, parrot_msg_len[parrot_msg_idx_rd], &copied);
	/* Ignore short reads (but warn about them) */
	if (parrot_msg_len[parrot_msg_idx_rd] != copied) {
		warn("short read detected\n");
	}
	/* loop into the message length table */
	parrot_msg_idx_rd = (parrot_msg_idx_rd+1)%PARROT_MSG_FIFO_MAX;
	message_read = true;

	return retval ? retval : copied;
}
static ssize_t pfsRead(struct file *file, char __user *buffer, size_t count, loff_t *pffset)	{
    int ret;
    unsigned int copied;

    if(!strcmp(PDE_DATA(file_inode(file)),"procEntry"))	{
        ret = kfifo_to_user(&myfifo, buffer, 32, &copied);
        rc+=1;
        return ret?ret:copied;
    }
    else if(!strcmp(PDE_DATA(file_inode(file)),"rwCount"))	{
        if(flag>0)	{
            flag=0;
            ret=0;
        }
        else	{
            ret = sprintf(buffer, "Number of Reads : %d\nNumber of Writes : %d\n", rc, wc);
            flag = 1;
        }
        return ret;
    }
    else	{
        printk(KERN_ALERT "Invalid Data\n");
        return 0;
    }
    return 0;
}
static ssize_t rpmsg_dev_read(struct file *filp, char __user *ubuff,
                              size_t len, loff_t *p_off)
{
    struct _rpmsg_device *_prpmsg_device = (struct _rpmsg_device *)filp->private_data;
    struct _rpmsg_params *local = ( struct _rpmsg_params *)&_prpmsg_device->rpmsg_params;

    int retval;
    unsigned int data_available, data_used, bytes_copied;

    /* Acquire lock to access rpmsg kfifo */
    static int count = 0;
    while (mutex_lock_interruptible(&local->sync_lock))
    {
        if (!count)
        {
            pr_info("%s: error = %d.\n", __func__,mutex_lock_interruptible(&local->sync_lock));
            count++;
        }
    }

    data_available = kfifo_len(&local->rpmsg_kfifo);

    if (data_available ==  0)
    {
        /* Release lock */
        mutex_unlock(&local->sync_lock);

        /* if non-blocking read is requested return error */
        if (filp->f_flags & O_NONBLOCK)
            return -EAGAIN;

        /* Block the calling context till data becomes available */
        wait_event_interruptible(local->usr_wait_q,
                                 local->block_flag != 0);
        while (mutex_lock_interruptible(&local->sync_lock));
    }

    /* reset block flag */
    local->block_flag = 0;

    /* Provide requested data size to user space */
    data_available = kfifo_len(&local->rpmsg_kfifo);
    data_used = (data_available > len) ? len : data_available;
    retval = kfifo_to_user(&local->rpmsg_kfifo, ubuff, data_used, &bytes_copied);

    /* Release lock on rpmsg kfifo */
    mutex_unlock(&local->sync_lock);

    return retval ? retval : bytes_copied;
}
static int iio_read_first_n_kfifo(struct iio_buffer *r,
			   size_t n, char __user *buf)
{
	int ret, copied;
	struct iio_kfifo *kf = iio_to_kfifo(r);

	if (n < r->bytes_per_datum)
		return -EINVAL;

	n = rounddown(n, r->bytes_per_datum);
	ret = kfifo_to_user(&kf->kf, buf, n, &copied);

	return copied;
}
static ssize_t fifo_read(struct file *file, char __user *buf,
						size_t count, loff_t *ppos)
{
	int ret;
	unsigned int copied;

	if (mutex_lock_interruptible(&read_lock))
		return -ERESTARTSYS;

	ret = kfifo_to_user(&test, buf, count, &copied);

	mutex_unlock(&read_lock);

	return ret ? ret : copied;
}
static ssize_t ami_read(struct file *file, char *buf, size_t count, loff_t *ptr)
{
	struct ami306_dev_data *pdev = container_of(file->private_data, struct ami306_dev_data, dev);
	u32 iRead = 0;
	int res;

	wait_event_interruptible(pdev->waitq, (kfifo_len(&(pdev->ebuff))> 0));

	/* copy to user */
	res = kfifo_to_user(&pdev->ebuff, buf, count, &iRead);
	if (res < 0) {
		printk("ami_read failed to copy\n");
		return -EFAULT;
	}

	return iRead;
}
Exemple #7
0
static int iio_read_kfifo(struct iio_buffer *r, size_t n, char __user *buf)
{
	int ret, copied;
	struct iio_kfifo *kf = iio_to_kfifo(r);

	if (mutex_lock_interruptible(&kf->user_lock))
		return -ERESTARTSYS;

	if (!kfifo_initialized(&kf->kf) || n < kfifo_esize(&kf->kf))
		ret = -EINVAL;
	else
		ret = kfifo_to_user(&kf->kf, buf, n, &copied);
	mutex_unlock(&kf->user_lock);
	if (ret < 0)
		return ret;

	return copied;
}
static int iio_read_first_n_kfifo(struct iio_buffer *r,
			   size_t n, char __user *buf)
{
	int ret, copied;
	struct iio_kfifo *kf = iio_to_kfifo(r);

	if (n < r->bytes_per_datum)
		return -EINVAL;

	n = rounddown(n, r->bytes_per_datum);
	ret = kfifo_to_user(&kf->kf, buf, n, &copied);
	if (kfifo_is_empty(&kf->kf))
		r->stufftoread = false;
	/* verify it is still empty to avoid race */
	if (!kfifo_is_empty(&kf->kf))
		r->stufftoread = true;

	return copied;
}
Exemple #9
0
ssize_t cons_read(struct file *filp, char __user *buf, size_t count,
		loff_t *f_pos)
{
	int ret;
	int copied;
	pr_info("%s() : FIFO size = %d, count = %d\n", __func__,
			(int)kfifo_len(&fifo), (int)count);
	if (down_interruptible(&cons_sem))
		return -ERESTARTSYS;

	while (kfifo_len(&fifo) <= 0) { /* nothing to read */
		up(&cons_sem); /* release the lock */
		if (filp->f_flags & O_NONBLOCK)
			return -EAGAIN;
		pr_info("%s () : \"%s\" going to sleep\n", __func__,
				current->comm);
		if (wait_event_interruptible(cons_que, kfifo_len(&fifo) > 0)) {
			pr_info("%s() wait_event_interruptible() : signal: "
				"tell the fs layer to handle it\n", __func__);
			return -ERESTARTSYS;
			/* signal: inform the fs layer to handle it */
		}
		if (down_interruptible(&cons_sem))
			return -ERESTARTSYS;
	}
	/* ok, data is there, return something */
	count = min((long)count, (long)kfifo_len(&fifo));
	pr_info("%s() : \"%s\" data to copy = %li bytes\n",
		__func__, current->comm, (long)count);
	ret = kfifo_to_user(&fifo, buf, count, &copied);
	up(&cons_sem);
	if (ret < 0)
		return -EFAULT;
	pr_info("%s() : \"%s\" read %li bytes. FIFO new Size = %d\n",
		__func__, current->comm, (long)count, (int)kfifo_len(&fifo));
	pr_info("%s() : \"%s\" waking up producer processes\n", __func__,
				current->comm);
	wake_up_interruptible(&prod_que);
	return copied;

}