From 81a5ff942906eb736b1da151e1d3070c5fb43996 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Tue, 26 Nov 2002 23:36:29 +0000 Subject: [PATCH] Move auxiliary data to options[30,31] --- comedi/comedi_fops.c | 26 +++++++++++++++++++++++++- comedi/drivers/daqboard2000.c | 32 ++++++++------------------------ comedi/drivers/me_daq.c | 16 +++++++++++++--- include/linux/comedi.h | 2 ++ 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index ff92eebc..f6a45647 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -154,6 +154,9 @@ static int comedi_ioctl(struct inode * inode,struct file * file, static int do_devconfig_ioctl(comedi_device *dev,comedi_devconfig *arg,kdev_t minor) { comedi_devconfig it; + int ret; + unsigned char *aux_data = NULL; + int aux_len; if(!suser()) return -EPERM; @@ -167,7 +170,28 @@ static int do_devconfig_ioctl(comedi_device *dev,comedi_devconfig *arg,kdev_t mi it.board_name[COMEDI_NAMELEN-1]=0; - return comedi_device_attach(dev,&it); + if(it.options[COMEDI_DEVCONF_AUX_DATA] && + it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]){ + aux_len = it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; + if(aux_len<0)return -EFAULT; + + aux_data = kmalloc(aux_len, GFP_KERNEL); + if(!aux_data)return -EFAULT; + + if(copy_from_user(aux_data, + (void *)it.options[COMEDI_DEVCONF_AUX_DATA], aux_len)){ + kfree(aux_data); + return -EFAULT; + } + + it.options[COMEDI_DEVCONF_AUX_DATA] = (unsigned long)aux_data; + } + + ret = comedi_device_attach(dev,&it); + + if(aux_data) kfree(aux_data); + + return ret; } /* diff --git a/comedi/drivers/daqboard2000.c b/comedi/drivers/daqboard2000.c index ca8841b2..56411c76 100644 --- a/comedi/drivers/daqboard2000.c +++ b/comedi/drivers/daqboard2000.c @@ -684,6 +684,8 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) int result = 0; comedi_subdevice *s; struct pci_dev *card = NULL; + void *aux_data; + unsigned int aux_len; printk("comedi%d: daqboard2000:", dev->minor); @@ -744,33 +746,15 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) pci_read_config_byte(card, PCI_INTERRUPT_LINE, &interrupt); printk("Interrupt before is: %x\n", interrupt); */ - if(it->options[0] && it->options[1]){ - void *ptr; - unsigned int size = it->options[1]; - - /* Note: using copy_from_user here is a hack. I would prefer - * to have a generic solution for copying extended data at - * device configuration, but that will require changes to the - * devconfig interface. Wait until devconfig gets a little - * more crufty (than it already is?!?), and then fix it. -ds */ - ptr = kmalloc(size,GFP_KERNEL); - if(!ptr){ - result=-ENOMEM; - goto out; - } - if(copy_from_user(ptr,(void *)it->options[0],size)){ - result=-EFAULT; - goto out; - } - result = initialize_daqboard2000(dev,ptr,size); - kfree(ptr); + + aux_data = (void *)it->options[COMEDI_DEVCONF_AUX_DATA]; + aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; + + if(aux_data && aux_len){ + result = initialize_daqboard2000(dev, aux_data, aux_len); }else{ -#ifdef CONFIG_COMEDI_DAQBOARD2000_FPGA - result = initialize_daqboard2000(dev,bTopBitArray,bTopBitSize); -#else printk("no FPGA initialization code, aborting\n"); result=-EIO; -#endif } if(result<0)goto out; daqboard2000_initializeAdc(dev); diff --git a/comedi/drivers/me_daq.c b/comedi/drivers/me_daq.c index 7b3ecaa7..d9c1a72e 100644 --- a/comedi/drivers/me_daq.c +++ b/comedi/drivers/me_daq.c @@ -47,7 +47,7 @@ Configuration options: #include -#include "me2600_fw.h" +//#include "me2600_fw.h" #define ME_DRIVER_NAME "me_daq" @@ -571,7 +571,8 @@ static int me_ao_insn_read(comedi_device * dev, // Xilinx firmware download for card: ME-2600i // -static int me2600_xilinx_download(comedi_device *dev) +static int me2600_xilinx_download(comedi_device *dev, unsigned char + *me2600_firmware, unsigned int length) { unsigned int value; unsigned int file_length; @@ -598,6 +599,7 @@ static int me2600_xilinx_download(comedi_device *dev) * Byte 8-11: date * Byte 12-15: reserved */ + if(length<16)return -EINVAL; file_length = (((unsigned int)me2600_firmware[0] & 0xff)<<24) + (((unsigned int)me2600_firmware[1] & 0xff)<<16) + @@ -801,7 +803,15 @@ found: // Download firmware and reset card if(board->device_id == ME2600_DEVICE_ID) { - me2600_xilinx_download(dev); + unsigned char *aux_data; + int aux_len; + + aux_data = (unsigned char *)it->options[COMEDI_DEVCONF_AUX_DATA]; + aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; + + if(!aux_data || aux_len)return -EINVAL; + + me2600_xilinx_download(dev, aux_data, aux_len); } me_reset(dev); diff --git a/include/linux/comedi.h b/include/linux/comedi.h index c9765864..38eb079f 100644 --- a/include/linux/comedi.h +++ b/include/linux/comedi.h @@ -41,6 +41,8 @@ extern "C" { /* number of config options in the config structure */ #define COMEDI_NDEVCONFOPTS 32 +#define COMEDI_DEVCONF_AUX_DATA 30 +#define COMEDI_DEVCONF_AUX_DATA_LENGTH 31 /* max length of device and driver names */ #define COMEDI_NAMELEN 20 -- 2.26.2