예제 #1
0
int a4l_release_driver(a4l_cxt_t * cxt)
{
	int ret = 0;
	a4l_dev_t *dev = a4l_get_dev(cxt);

	if ((ret = dev->driver->detach(dev)) != 0)
		goto out_release_driver;

	/* Decrease module's count
	   so as to allow module unloading */
	module_put(dev->driver->owner);

	/* In case, the driver developer did not free the subdevices */
	while (&dev->subdvsq != dev->subdvsq.next) {
		struct list_head *this = dev->subdvsq.next;
		a4l_subd_t *tmp = list_entry(this, a4l_subd_t, list);

		list_del(this);
		rtdm_free(tmp);
	}

	/* Free the private field */
	rtdm_free(dev->priv);
	dev->driver = NULL;

out_release_driver:
	return ret;
}
예제 #2
0
void a4l_free_lnkdesc(a4l_cxt_t * cxt, a4l_lnkdesc_t * link_arg)
{
	if (link_arg->bname != NULL)
		rtdm_free(link_arg->bname);

	if (link_arg->opts != NULL)
		rtdm_free(link_arg->opts);
}
예제 #3
0
void a4l_free_lnkdesc(a4l_cxt_t * cxt, a4l_lnkdesc_t * link_arg)
{
	__a4l_dbg(1, core_dbg, 
		  "a4l_free_lnkdesc: minor=%d\n", a4l_get_minor(cxt));

	if (link_arg->bname != NULL)
		rtdm_free(link_arg->bname);

	if (link_arg->opts != NULL)
		rtdm_free(link_arg->opts);
}
예제 #4
0
int a4l_assign_driver(a4l_cxt_t * cxt,
			 a4l_drv_t * drv, a4l_lnkdesc_t * link_arg)
{
	int ret = 0;
	a4l_dev_t *dev = a4l_get_dev(cxt);

	__a4l_dbg(1, core_dbg, 
		  "a4l_assign_driver: minor=%d\n", a4l_get_minor(cxt));

	dev->driver = drv;

	if (drv->privdata_size == 0)
		__a4l_dbg(1, core_dbg, 
			  "a4l_assign_driver: warning! "
			  "the field priv will not be usable\n");
	else {

		INIT_LIST_HEAD(&dev->subdvsq);
	
		dev->priv = rtdm_malloc(drv->privdata_size);
		if (dev->priv == NULL && drv->privdata_size != 0) {
			__a4l_err("a4l_assign_driver: "
				  "call(alloc) failed\n");
			ret = -ENOMEM;
			goto out_assign_driver;
		}

		/* Initialize the private data even if it not our role
		   (the driver should do it), that may prevent hard to
		   find bugs */
		memset(dev->priv, 0, drv->privdata_size);
	}

	if ((ret = drv->attach(dev, link_arg)) != 0)
		__a4l_err("a4l_assign_driver: "
			  "call(drv->attach) failed (ret=%d)\n",
		     ret);

out_assign_driver:

	/* Increments module's count */
	if (ret == 0 && (!try_module_get(drv->owner))) {
		__a4l_err("a4l_assign_driver: "
			  "driver's owner field wrongly set\n");
		ret = -ENODEV;
	}

	if (ret != 0 && dev->priv != NULL) {
		rtdm_free(dev->priv);
		dev->driver = NULL;
	}

	return ret;
}
예제 #5
0
파일: command.c 프로젝트: rcn-ee/xenomai-3
/* --- Command descriptor management functions --- */
int a4l_fill_cmddesc(struct a4l_device_context *cxt, struct a4l_cmd_desc *desc,
                     unsigned int **chan_descs, void *arg)
{
    unsigned int *tmpchans = NULL;
    int ret = 0;

    ret = rtdm_safe_copy_from_user(rtdm_private_to_fd(cxt),
                                   desc, arg, sizeof(struct a4l_cmd_desc));
    if (ret != 0)
        goto out_cmddesc;


    if (desc->nb_chan == 0) {
        ret = -EINVAL;
        goto out_cmddesc;
    }

    tmpchans = rtdm_malloc(desc->nb_chan * sizeof(unsigned int));
    if (tmpchans == NULL) {
        ret = -ENOMEM;
        goto out_cmddesc;
    }

    ret = rtdm_safe_copy_from_user(rtdm_private_to_fd(cxt),
                                   tmpchans,
                                   desc->chan_descs,
                                   desc->nb_chan * sizeof(unsigned int));
    if (ret != 0) {
        __a4l_err("%s invalid arguments \n", __FUNCTION__);
        goto out_cmddesc;
    }

    *chan_descs = desc->chan_descs;
    desc->chan_descs = tmpchans;

    __a4l_dbg(1, core_dbg, "desc dump: \n");
    __a4l_dbg(1, core_dbg, "\t->idx_subd=%u\n", desc->idx_subd);
    __a4l_dbg(1, core_dbg, "\t->flags=%lu\n", desc->flags);
    __a4l_dbg(1, core_dbg, "\t->nb_chan=%u\n", desc->nb_chan);
    __a4l_dbg(1, core_dbg, "\t->chan_descs=0x%x\n", *desc->chan_descs);
    __a4l_dbg(1, core_dbg, "\t->data_len=%u\n", desc->data_len);
    __a4l_dbg(1, core_dbg, "\t->pdata=0x%p\n", desc->data);

out_cmddesc:

    if (ret != 0) {
        __a4l_err("a4l_fill_cmddesc: %d \n", ret);
        if (tmpchans != NULL)
            rtdm_free(tmpchans);
        desc->chan_descs = NULL;
    }

    return ret;
}
예제 #6
0
int a4l_free_insndsc(a4l_cxt_t * cxt, a4l_kinsn_t * dsc)
{
	int ret = 0;

	if ((dsc->type & A4L_INSN_MASK_READ) != 0)
		ret = rtdm_safe_copy_to_user(cxt->user_info,
					     dsc->__udata,
					     dsc->data, dsc->data_size);

	if (dsc->data != NULL)
		rtdm_free(dsc->data);

	return ret;
}
예제 #7
0
static ssize_t uart_rd_rt(struct rtdm_dev_context *context,rtdm_user_info_t * user_info, void *buf,size_t nbyte)
{
	int err;
	int ret=0;
	int count;
	 MY_DEV *up=(MY_DEV *)context->device->device_data;
	u8 *tmp;

	printk("..............uart_rd_rt start\n");
	tmp=(u8 *)rtdm_malloc(nbyte);
	up->buf_rx=(u8 *)tmp;
	up->buf_len_rx = nbyte;
	count =nbyte;

	if (!(up->ier & UART_IER_RDI))
        {
                up->ier |= UART_IER_RDI;
                serial_out(up, UART_IER, up->ier);
        }

	 err=rtdm_event_wait(&up->w_event_rx);
         if(err<0)
         {
                dev_err(up->dev,"controller timed out\n");
                rtdm_printk("rtdm_event_timedwait: timeout\n");
                return -ETIMEDOUT;
         }
         if(err==0)
         {
         ret=nbyte;
         }
	
	while(count--)
	{
	*tmp=read_buffer(up);
	printk("Receive rd=%x\n",*tmp);
	tmp = tmp +1;
	}
	tmp=tmp-nbyte;
	if(rtdm_safe_copy_to_user(user_info,buf,(void *)tmp, nbyte))
                rtdm_printk("ERROR : can't copy data from driver\n");

	printk("............uart_rd_rt end\n");

        rtdm_free(tmp);
	
	return ret;
}
예제 #8
0
int a4l_free_ilstdsc(a4l_cxt_t * cxt, a4l_kilst_t * dsc)
{
	int i, ret = 0;

	if (dsc->insns != NULL) {

		for (i = 0; i < dsc->count && ret == 0; i++)
			ret = a4l_free_insndsc(cxt, &(dsc->insns[i]));

		while (i < dsc->count) {
			a4l_free_insndsc(cxt, &(dsc->insns[i]));
			i++;
		}

		rtdm_free(dsc->insns);
	}

	return ret;
}
예제 #9
0
int a4l_fill_insndsc(a4l_cxt_t * cxt, a4l_kinsn_t * dsc, void *arg)
{
	int ret = 0;
	void *tmp_data = NULL;

	ret = rtdm_safe_copy_from_user(cxt->user_info, 
				       dsc, arg, sizeof(a4l_insn_t));
	if (ret != 0)
		goto out_insndsc;

	if (dsc->data_size != 0 && dsc->data == NULL) {
		__a4l_err("a4l_fill_insndsc: no data pointer specified\n");
		ret = -EINVAL;
		goto out_insndsc;
	}

	if (dsc->data_size != 0 && dsc->data != NULL) {
		tmp_data = rtdm_malloc(dsc->data_size);
		if (tmp_data == NULL) {
			ret = -ENOMEM;
			goto out_insndsc;
		}

		if ((dsc->type & A4L_INSN_MASK_WRITE) != 0) {
			ret = rtdm_safe_copy_from_user(cxt->user_info,
						       tmp_data, dsc->data,
						       dsc->data_size);
			if (ret < 0)
				goto out_insndsc;
		}
	}

	dsc->__udata = dsc->data;
	dsc->data = tmp_data;

out_insndsc:

	if (ret != 0 && tmp_data != NULL)
		rtdm_free(tmp_data);

	return ret;
}
예제 #10
0
int a4l_proc_attach(a4l_cxt_t * cxt)
{
	int ret = 0;
	a4l_dev_t *dev = a4l_get_dev(cxt);
	struct proc_dir_entry *entry;
	char *entry_name, *p;

	/* Allocates the buffer for the file name */
	entry_name = rtdm_malloc(A4L_NAMELEN + 4);
	if ((p = entry_name) == NULL) {
		__a4l_err("a4l_proc_attach: failed to allocate buffer\n");
		return -ENOMEM;
	}

	/* Creates the proc file name */
	p += sprintf(p, "%02d-", a4l_get_minor(cxt));
	strncpy(p, dev->driver->board_name, A4L_NAMELEN);

	/* Creates the proc entry */
	entry = create_proc_entry(entry_name, 0444, a4l_proc_root);
	if (entry == NULL) {
		__a4l_err("a4l_proc_attach: "
			  "failed to create /proc/analogy/%s\n",
			  entry_name);
		ret = -ENOMEM;
		goto out_setup_proc_transfer;
	}

	entry->nlink = 1;
	entry->data = &dev->transfer;
	entry->write_proc = NULL;
	entry->read_proc = a4l_rdproc_transfer;
	wrap_proc_dir_entry_owner(entry);

      out_setup_proc_transfer:
	/* Frees the file name buffer */
	rtdm_free(entry_name);

	return ret;
}
예제 #11
0
int a4l_fill_ilstdsc(a4l_cxt_t * cxt, a4l_kilst_t * dsc, void *arg)
{
	int i, ret = 0;

	dsc->insns = NULL;

	/* Recovers the structure from user space */
	ret = rtdm_safe_copy_from_user(cxt->user_info, 
				       dsc, arg, sizeof(a4l_insnlst_t));
	if (ret < 0)
		return ret;

	/* Some basic checking */
	if (dsc->count == 0) {
		__a4l_err("a4l_fill_ilstdsc: instruction list's count is 0\n");
		return -EINVAL;
	}

	/* Keeps the user pointer in an opaque field */
	dsc->__uinsns = (a4l_insn_t *)dsc->insns;

	dsc->insns = rtdm_malloc(dsc->count * sizeof(a4l_kinsn_t));
	if (dsc->insns == NULL)
		return -ENOMEM;

	/* Recovers the instructions, one by one. This part is not 
	   optimized */
	for (i = 0; i < dsc->count && ret == 0; i++)
		ret = a4l_fill_insndsc(cxt,
				       &(dsc->insns[i]),
				       &(dsc->__uinsns[i]));

	/* In case of error, frees the allocated memory */
	if (ret < 0 && dsc->insns != NULL)
		rtdm_free(dsc->insns);

	return ret;
}
예제 #12
0
void a4l_proc_detach(a4l_cxt_t * cxt)
{
	char *entry_name, *p;
	a4l_dev_t *dev = a4l_get_dev(cxt);

	/* Allocate the buffer for the file name */
	entry_name = rtdm_malloc(A4L_NAMELEN + 4);
	if ((p = entry_name) == NULL) {
		__a4l_err("a4l_proc_detach: "
			  "failed to allocate filename buffer\n");
		return;
	}

	/* Build the name */
	p += sprintf(p, "%02d-", a4l_get_minor(cxt));
	strncpy(p, dev->driver->board_name, A4L_NAMELEN);

	/* Remove the proc file */
	remove_proc_entry(entry_name, a4l_proc_root);

	/* Free the temporary buffer */
	rtdm_free(entry_name);
}
예제 #13
0
int a4l_close(struct rtdm_dev_context *context, rtdm_user_info_t * user_info)
{
	int err;
	a4l_cxt_t *cxt = (a4l_cxt_t *)rtdm_context_to_private(context);

	/* Cancel the maybe occuring asynchronous transfer */
	err = a4l_cancel_buffer(cxt);
	if (err < 0) {
		__a4l_err("close: unable to stop the asynchronous transfer\n");
		return err;
	}

	/* Free the buffer which was linked with this context and... */
	a4l_free_buffer(cxt->buffer);

	/* ...free the other buffer resources (sync) and... */
	a4l_cleanup_buffer(cxt->buffer);

	/* ...free the structure */
	rtdm_free(cxt->buffer);

	return 0;
}
예제 #14
0
static ssize_t uart_wr_rt(struct rtdm_dev_context *context,rtdm_user_info_t * user_info,const void *buf, size_t nbyte)
{
	int ret=0;
	int err;	
	int count;
	char c;

	MY_DEV *up=(MY_DEV *)context->device->device_data;
	
	char *tmp;
	up->buf_len_tx = nbyte;
	
	printk("uart_wr_rt  start\n");
	tmp=rtdm_malloc(nbyte);
	
	if ((rtdm_safe_copy_from_user(user_info,tmp, buf, up->buf_len_tx)))
                rtdm_printk("ERROR : can't copy data to driver\n");
	

	 count=nbyte;
	while(count--)
	{
	write_buffer(up,*tmp);
	tmp=tmp+1;
	
//	up->buf_tx=(char *)tmp;
//	printk("up->buf_tx=%x\n",*up->buf_tx);
			
	//enable Trasmitter holding Register
	if (!(up->ier & UART_IER_THRI)) 
	{
		up->ier |= UART_IER_THRI;
		 up->systime = rtdm_clock_read();
		serial_out(up, UART_IER, up->ier);
	}

	}

	printk("Tx interrupt enable\n");
	printk("rtdm_event_wait before\n");

	err=rtdm_event_wait(&up->w_event_tx);
        if(err<0)
        {
                dev_err(up->dev,"controller timed out\n");
                rtdm_printk("rtdm_event_timedwait: timeout\n");
                return -ETIMEDOUT;
        }

	up->systime1 = rtdm_clock_read();

	up->timeout=(up->systime1)-(up->systime);

	printk("scheduling latency=%ld\n",up->timeout);

	if(err==0)
	{
	 	ret=nbyte;
	}
	printk("rtdm_event_wait after\n");
	printk("uart_wr_rt end\n");
	rtdm_free(tmp);
	return ret;
}
예제 #15
0
파일: command.c 프로젝트: rcn-ee/xenomai-3
void a4l_free_cmddesc(struct a4l_cmd_desc * desc)
{
    if (desc->chan_descs != NULL)
        rtdm_free(desc->chan_descs);
}
예제 #16
0
파일: command.c 프로젝트: rcn-ee/xenomai-3
int a4l_ioctl_cmd(struct a4l_device_context * ctx, void *arg)
{
    int ret = 0, simul_flag = 0;
    struct a4l_cmd_desc *cmd_desc = NULL;
    struct a4l_device *dev = a4l_get_dev(ctx);
    unsigned int *chan_descs, *tmp;
    struct a4l_subdevice *subd;

    /* The command launching cannot be done in real-time because
       of some possible buffer allocations in the drivers */
    if (rtdm_in_rt_context())
        return -ENOSYS;

    /* Basically check the device */
    if (!test_bit(A4L_DEV_ATTACHED_NR, &dev->flags)) {
        __a4l_err("a4l_ioctl_cmd: cannot command "
                  "an unattached device\n");
        return -EINVAL;
    }

    /* Allocates the command */
    cmd_desc = (struct a4l_cmd_desc *) rtdm_malloc(sizeof(struct a4l_cmd_desc));
    if (cmd_desc == NULL)
        return -ENOMEM;
    memset(cmd_desc, 0, sizeof(struct a4l_cmd_desc));

    /* Gets the command */
    ret = a4l_fill_cmddesc(ctx, cmd_desc, &chan_descs, arg);
    if (ret != 0)
        goto out_ioctl_cmd;

    /* Checks the command */
    ret = a4l_check_cmddesc(ctx, cmd_desc);
    if (ret != 0)
        goto out_ioctl_cmd;

    ret = a4l_check_generic_cmdcnt(cmd_desc);
    if (ret != 0)
        goto out_ioctl_cmd;

    ret = a4l_check_specific_cmdcnt(ctx, cmd_desc);
    if (ret != 0)
        goto out_ioctl_cmd;

    __a4l_dbg(1, core_dbg,"1st cmd checks passed\n");
    subd = dev->transfer.subds[cmd_desc->idx_subd];

    /* Tests the command with the cmdtest function */
    if (cmd_desc->flags & A4L_CMD_SIMUL) {
        simul_flag = 1;

        if (!subd->do_cmdtest) {
            __a4l_err("a4l_ioctl_cmd: driver's cmd_test NULL\n");
            ret = -EINVAL;
            goto out_ioctl_cmd;
        }

        ret = subd->do_cmdtest(subd, cmd_desc);
        if (ret != 0) {
            __a4l_err("a4l_ioctl_cmd: driver's cmd_test failed\n");
            goto out_ioctl_cmd;
        }
        __a4l_dbg(1, core_dbg, "driver's cmd checks passed\n");
        goto out_ioctl_cmd;
    }


    /* Gets the transfer system ready */
    ret = a4l_setup_buffer(ctx, cmd_desc);
    if (ret < 0)
        goto out_ioctl_cmd;

    /* Eventually launches the command */
    ret = subd->do_cmd(subd, cmd_desc);

    if (ret != 0) {
        a4l_cancel_buffer(ctx);
        goto out_ioctl_cmd;
    }

out_ioctl_cmd:

    if (simul_flag) {
        /* copy the kernel based descriptor */
        tmp = cmd_desc->chan_descs;
        /* return the user based descriptor */
        cmd_desc->chan_descs = chan_descs;
        rtdm_safe_copy_to_user(rtdm_private_to_fd(ctx), arg, cmd_desc,
                               sizeof(struct a4l_cmd_desc));
        /* make sure we release the memory associated to the kernel */
        cmd_desc->chan_descs = tmp;

    }

    if (ret != 0 || simul_flag == 1) {
        a4l_free_cmddesc(cmd_desc);
        rtdm_free(cmd_desc);
    }

    return ret;
}