From: Frank Mori Hess Date: Mon, 19 Jun 2006 01:12:37 +0000 (+0000) Subject: patch from Ian Abbott : X-Git-Tag: r0_7_71~25 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d85afbfd489d60ea5330a632a1e41838a7c9ffb3;p=comedi.git patch from Ian Abbott : I have a patch that changes the adl_pci9118 and adv_pci1710 drivers. It mimics their old behaviour of searching for an unused card, rather than using the first card it finds. I didn't need to change the cb_pcidas driver after all as it wasn't using the amcc_s5933 driver, only some macros from amcc_s5933.h. The patch also removes the amcc_s5933 module from the Makefile.am and Kbuild files and removes the function declarations, etc., from the amcc_s5933.h file. --- diff --git a/comedi/drivers/Kbuild b/comedi/drivers/Kbuild index e3f25dcf..2dcb48c1 100644 --- a/comedi/drivers/Kbuild +++ b/comedi/drivers/Kbuild @@ -18,7 +18,6 @@ obj-$(CONFIG_COMEDI_USB_MODULES) += usbduxfast.o obj-$(CONFIG_COMEDI_USB_MODULES) += dt9812.o obj-m += 8255.o -obj-m += amcc_s5933.o obj-m += comedi_fc.o obj-m += das08.o obj-m += mite.o diff --git a/comedi/drivers/Makefile.am b/comedi/drivers/Makefile.am index 82909dbd..51c1d5a4 100644 --- a/comedi/drivers/Makefile.am +++ b/comedi/drivers/Makefile.am @@ -5,7 +5,6 @@ AM_CFLAGS = $(COMEDI_CFLAGS) $(LINUX_CFLAGS) $(RTAI_CFLAGS) $(RTLINUX_CFLAGS) LINK = $(top_builddir)/modtool --link -o $@ \ -i ../.mods/comedi.o.symvers \ -i .mods/8255.o.symvers \ - -i .mods/amcc_s5933.o.symvers \ -i .mods/comedi_fc.o.symvers \ -i .mods/das08.o.symvers \ -i .mods/mite.o.symvers \ @@ -13,8 +12,6 @@ LINK = $(top_builddir)/modtool --link -o $@ \ 8255_ko_LINK = $(top_builddir)/modtool --link -o $@ \ -i ../.mods/comedi.o.symvers -amcc_s5933_ko_LINK = $(top_builddir)/modtool --link -o $@ \ - -i ../.mods/comedi.o.symvers comedi_fc_ko_LINK = $(top_builddir)/modtool --link -o $@ \ -i ../.mods/comedi.o.symvers das08_ko_LINK = $(top_builddir)/modtool --link -o $@ \ @@ -25,7 +22,6 @@ ni_labpc_ko_LINK = $(top_builddir)/modtool --link -o $@ \ -i ../.mods/comedi.o.symvers 8255_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB -amcc_s5933_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB comedi_fc_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB das08_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB mite_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB @@ -86,7 +82,6 @@ module_PROGRAMS = else !CONFIG_KBUILD module_PROGRAMS = \ 8255.ko \ - amcc_s5933.ko \ comedi_fc.ko \ das08.ko \ mite.ko \ @@ -179,7 +174,6 @@ adl_pci8164_ko_SOURCES = adl_pci8164.c adl_pci9111_ko_SOURCES = adl_pci9111.c adl_pci9118_ko_SOURCES = adl_pci9118.c adv_pci1710_ko_SOURCES = adv_pci1710.c -amcc_s5933_ko_SOURCES = amcc_s5933.c adv_pci_dio_ko_SOURCES = adv_pci_dio.c amplc_pci224_ko_SOURCES = amplc_pci224.c amplc_pci230_ko_SOURCES = amplc_pci230.c diff --git a/comedi/drivers/adl_pci9118.c b/comedi/drivers/adl_pci9118.c index c80e0010..e52e4586 100644 --- a/comedi/drivers/adl_pci9118.c +++ b/comedi/drivers/adl_pci9118.c @@ -63,6 +63,7 @@ Configuration options: */ #include +#include #include @@ -180,8 +181,6 @@ static comedi_lrange range_pci9118hg={ 8, { static int pci9118_attach(comedi_device *dev,comedi_devconfig *it); static int pci9118_detach(comedi_device *dev); -static unsigned short pci_list_builded=0; /*>0 list of cards is known */ - typedef struct { char *name; // driver name int vendor_id; // PCI vendor a device ID of card @@ -243,7 +242,6 @@ COMEDI_INITCLEANUP(driver_pci9118); typedef struct{ int iobase_a; // base+size for AMCC chip - struct pcilst_struct *amcc; // ptr too AMCC data unsigned int master; // master capable struct pci_dev *pcidev; // ptr to actual pcidev unsigned int usemux; // we want to use external multiplexor! @@ -1670,53 +1668,84 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; int ret,pages,i; - unsigned short io_addr[5],master,irq,m; + unsigned short master,irq; unsigned int iobase_a,iobase_9; - struct pcilst_struct *card=NULL; + struct pci_dev *pcidev; + int opt_bus, opt_slot; + const char *errstr; unsigned char pci_bus,pci_slot,pci_func; u16 u16w; - if (pci_list_builded++ == 0) { - pci_card_list_init(PCI_VENDOR_ID_AMCC,0); - } - rt_printk("comedi%d: adl_pci9118: board=%s",dev->minor,this_board->name); + opt_bus = it->options[0]; + opt_slot = it->options[1]; if (it->options[3]&1) { master=0; // user don't want use bus master } else { master=1; } - /* this call pci_enable_device(), pci_request_regions(), - * and pci_set_master() */ - if ((card=select_and_alloc_pci_card(PCI_VENDOR_ID_AMCC, this_board->device_id, it->options[0], it->options[1], master))==NULL) - return -EIO; - - if ((pci_card_data(card,&pci_bus,&pci_slot,&pci_func, - &io_addr[0],&irq,&m))<0) { - pci_card_free(card); - rt_printk(" - Can't get AMCC data!\n"); + if((ret=alloc_private(dev,sizeof(pci9118_private)))<0) { + rt_printk(" - Allocation failed!\n"); + return -ENOMEM; + } + + /* Look for matching PCI device */ + errstr = "not found!"; + pcidev = NULL; + while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_AMCC, + this_board->device_id, pcidev))) { + /* Found matching vendor/device. */ + if (opt_bus || opt_slot) { + /* Check bus/slot. */ + if (opt_bus != pcidev->bus->number + || opt_slot != PCI_SLOT(pcidev->devfn)) + continue; /* no match */ + } + /* + * Look for device that isn't in use. + * Enable PCI device and request regions. + */ + if (pci_enable_device(pcidev)) { + errstr = "failed to enable PCI device!"; + continue; + } + if (pci_request_regions(pcidev, "adl_pci9118")) { + errstr = "in use or I/O port conflict!"; + continue; + } + break; + } + + if (!pcidev) { + if (opt_bus || opt_slot) { + rt_printk(" - Card at b:s %d:%d %s\n", + opt_bus, opt_slot, errstr); + } else { + rt_printk(" - Card %s\n", errstr); + } return -EIO; } - iobase_a=io_addr[0]; - iobase_9=io_addr[2]; + if (master) { + pci_set_master(pcidev); + } + + pci_bus = pcidev->bus->number; + pci_slot = PCI_SLOT(pcidev->devfn); + pci_func = PCI_FUNC(pcidev->devfn); + irq = pcidev->irq; + iobase_a = pci_resource_start(pcidev, 0); + iobase_9 = pci_resource_start(pcidev, 2); rt_printk(", b:s:f=%d:%d:%d, io=0x%4x, 0x%4x",pci_bus,pci_slot,pci_func,iobase_9,iobase_a); dev->iobase=iobase_9; dev->board_name = this_board->name; - - if((ret=alloc_private(dev,sizeof(pci9118_private)))<0) { - pci_card_free(card); - rt_printk(" - Allocation failed!\n"); - return -ENOMEM; - } - devpriv->amcc=card; - devpriv->pcidev=card->pcidev; + devpriv->pcidev=pcidev; devpriv->iobase_a=iobase_a; if (it->options[3]&2) irq=0; // user don't want use IRQ @@ -1862,15 +1891,17 @@ static int pci9118_detach(comedi_device *dev) if (dev->private) { if (devpriv->valid) pci9118_reset(dev); if(dev->irq) comedi_free_irq(dev->irq,dev); - if (devpriv->amcc) pci_card_free(devpriv->amcc); + if (devpriv->pcidev) { + if (dev->iobase) { + pci_release_regions(devpriv->pcidev); + pci_disable_device(devpriv->pcidev); + } + pci_dev_put(devpriv->pcidev); + } if (devpriv->dmabuf_virt[0]) free_pages((unsigned long)devpriv->dmabuf_virt[0],devpriv->dmabuf_pages[0]); if (devpriv->dmabuf_virt[1]) free_pages((unsigned long)devpriv->dmabuf_virt[1],devpriv->dmabuf_pages[1]); } - if (--pci_list_builded == 0) { - pci_card_list_cleanup(PCI_VENDOR_ID_AMCC); - } - return 0; } diff --git a/comedi/drivers/adv_pci1710.c b/comedi/drivers/adv_pci1710.c index ca3d77e1..2ee39c27 100644 --- a/comedi/drivers/adv_pci1710.c +++ b/comedi/drivers/adv_pci1710.c @@ -182,8 +182,6 @@ static comedi_lrange range_pci171x_da={ 2, { static int pci1710_attach(comedi_device *dev,comedi_devconfig *it); static int pci1710_detach(comedi_device *dev); -static unsigned short pci_list_builded=0; /*>0 list of card is known */ - typedef struct { char *name; // driver name int device_id; @@ -262,7 +260,7 @@ static comedi_driver driver_pci1710={ }; typedef struct{ - struct pcilst_struct *amcc; // ptr to AMCC data + struct pci_dev *pcidev; // ptr to PCI device char valid; // card is usable char neverending_ai; // we do unlimited AI unsigned int CntrlReg; // Control register @@ -1223,49 +1221,72 @@ static int pci1710_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; int ret,subdev,n_subdevices; - unsigned short io_addr[5],master,irq; - struct pcilst_struct *card=NULL; + unsigned short irq; unsigned int iobase; + struct pci_dev *pcidev; + int opt_bus, opt_slot; + const char *errstr; unsigned char pci_bus,pci_slot,pci_func; - if (pci_list_builded++ == 0) { - pci_card_list_init(PCI_VENDOR_ID_ADVANTECH, -#ifdef PCI171X_EXTDEBUG - 1 -#else - 0 -#endif - ); - } - rt_printk("comedi%d: adv_pci1710: board=%s",dev->minor,this_board->name); - /* this call pci_enable_device() and pci_request_regions() */ - if ((card=select_and_alloc_pci_card(PCI_VENDOR_ID_ADVANTECH, this_board->device_id, it->options[0], it->options[1], 0))==NULL) - return -EIO; + opt_bus = it->options[0]; + opt_slot = it->options[1]; + + if((ret=alloc_private(dev,sizeof(pci1710_private)))<0) { + rt_printk(" - Allocation failed!\n"); + return -ENOMEM; + } + + /* Look for matching PCI device */ + errstr = "not found!"; + pcidev = NULL; + while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_ADVANTECH, + this_board->device_id, pcidev))) { + /* Found matching vendor/device. */ + if (opt_bus || opt_slot) { + /* Check bus/slot. */ + if (opt_bus != pcidev->bus->number + || opt_slot != PCI_SLOT(pcidev->devfn)) + continue; /* no match */ + } + /* + * Look for device that isn't in use. + * Enable PCI device and request regions. + */ + if (pci_enable_device(pcidev)) { + errstr = "failed to enable PCI device!"; + continue; + } + if (pci_request_regions(pcidev, "adl_pci9118")) { + errstr = "in use or I/O port conflict!"; + continue; + } + break; + } - if ((pci_card_data(card,&pci_bus,&pci_slot,&pci_func, - &io_addr[0],&irq,&master))<0) { - pci_card_free(card); - rt_printk(" - Can't get configuration data!\n"); + if (!pcidev) { + if (opt_bus || opt_slot) { + rt_printk(" - Card at b:s %d:%d %s\n", + opt_bus, opt_slot, errstr); + } else { + rt_printk(" - Card %s\n", errstr); + } return -EIO; } - iobase=io_addr[2]; + pci_bus = pcidev->bus->number; + pci_slot = PCI_SLOT(pcidev->devfn); + pci_func = PCI_FUNC(pcidev->devfn); + irq = pcidev->irq; + iobase = pci_resource_start(pcidev, 2); rt_printk(", b:s:f=%d:%d:%d, io=0x%4x",pci_bus,pci_slot,pci_func,iobase); dev->iobase=iobase; dev->board_name = this_board->name; - - if((ret=alloc_private(dev,sizeof(pci1710_private)))<0) { - pci_card_free(card); - rt_printk(" - Allocation failed!\n"); - return -ENOMEM; - } - - devpriv->amcc = card; + devpriv->pcidev = pcidev; n_subdevices = 0; if (this_board->n_aichan) n_subdevices++; @@ -1397,11 +1418,13 @@ static int pci1710_detach(comedi_device *dev) if (dev->private) { if (devpriv->valid) pci1710_reset(dev); if (dev->irq) comedi_free_irq(dev->irq,dev); - if (devpriv->amcc) pci_card_free(devpriv->amcc); - } - - if (--pci_list_builded == 0) { - pci_card_list_cleanup(PCI_VENDOR_ID_ADVANTECH); + if (devpriv->pcidev) { + if (dev->iobase) { + pci_release_regions(devpriv->pcidev); + pci_disable_device(devpriv->pcidev); + } + pci_dev_put(devpriv->pcidev); + } } diff --git a/comedi/drivers/amcc_s5933.h b/comedi/drivers/amcc_s5933.h index c28f3401..86b211a9 100644 --- a/comedi/drivers/amcc_s5933.h +++ b/comedi/drivers/amcc_s5933.h @@ -15,9 +15,6 @@ #ifndef _AMCC_S5933_H_ #define _AMCC_S5933_H_ -#include -#include - /****************************************************************************/ /* AMCC Operation Register Offsets - PCI */ @@ -173,39 +170,4 @@ #define TARGET_ABORT_INT 0x00200000L #define BUS_MASTER_INT 0x00200000L -/****************************************************************************/ - -struct pcilst_struct{ - struct pcilst_struct *next; - int used; - struct pci_dev *pcidev; - unsigned short vendor; - unsigned short device; - unsigned int master; - unsigned char pci_bus; - unsigned char pci_slot; - unsigned char pci_func; - unsigned int io_addr[5]; - unsigned int irq; -}; - -struct pcilst_struct *amcc_devices; // ptr to root list of all amcc devices - -/****************************************************************************/ - -void pci_card_list_init(unsigned short pci_vendor, char display); -void pci_card_list_cleanup(unsigned short pci_vendor); -struct pcilst_struct *find_free_pci_card_by_device(unsigned short vendor_id, unsigned short device_id); -int find_free_pci_card_by_position(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, struct pcilst_struct **card); -struct pcilst_struct *select_and_alloc_pci_card(unsigned short vendor_id, unsigned short device_id, unsigned short pci_bus, unsigned short pci_slot, char master); - -//int pci_card_alloc(struct pcilst_struct *amcc); -int pci_card_free(struct pcilst_struct *amcc); -void pci_card_list_display(void); -int pci_card_data(struct pcilst_struct *amcc, - unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func, - unsigned short *io_addr, unsigned short *irq, unsigned short *master); - -/****************************************************************************/ - #endif