Sanitize resource types. Use new comedi_pci_enable and comedi_pci_disable
authorIan Abbott <abbotti@mev.co.uk>
Thu, 1 Nov 2007 17:47:00 +0000 (17:47 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Thu, 1 Nov 2007 17:47:00 +0000 (17:47 +0000)
functions instead of ad hoc calls to request_region and release_region.

comedi/drivers/addi-data/addi_amcc_s5933.h
comedi/drivers/addi-data/addi_common.c

index 106c9596ce27c884bfbf566df0246be99366b2d3..0d552016e4b8d7aa05f5e379d97c0a6a9087215c 100644 (file)
@@ -57,9 +57,10 @@ You shoud also find the complete GPL in the COPYING file accompanying this sourc
 #ifndef _AMCC_S5933_H_
 #define _AMCC_S5933_H_
 
-#include <linux/pci.h>
 #include <linux/comedidev.h>
 
+#include "../comedi_pci.h"
+
 #ifdef PCI_SUPPORT_VER1
 #error     No support for 2.1.55 and older
 #endif
@@ -238,7 +239,7 @@ struct pcilst_struct{
        unsigned char   pci_bus;
        unsigned char   pci_slot;
        unsigned char   pci_func;
-       unsigned int    io_addr[5];
+       resource_size_t io_addr[5];
        unsigned int    irq;
 };
 
@@ -261,7 +262,7 @@ int i_pci_card_free(struct pcilst_struct *amcc);
 void v_pci_card_list_display(void);
 int i_pci_card_data(struct pcilst_struct *amcc,
        unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func,
-       unsigned long *io_addr, unsigned short *irq);
+       resource_size_t *io_addr, unsigned int *irq);
 
 /****************************************************************************/
 
@@ -295,8 +296,11 @@ void v_pci_card_list_init(unsigned short pci_vendor, char display)
                        amcc->pci_bus=pcidev->bus->number;
                        amcc->pci_slot=PCI_SLOT(pcidev->devfn);
                        amcc->pci_func=PCI_FUNC(pcidev->devfn);
+                       /* Note: resources may be invalid if PCI device
+                        * not enabled, but they are corrected in
+                        * pci_card_alloc. */
                        for (i=0;i<5;i++)
-                               amcc->io_addr[i]=pcidev->resource[i].start & ~3UL;
+                               amcc->io_addr[i]=pci_resource_start(pcidev, i);
                        amcc->irq=pcidev->irq;
                        
                }
@@ -362,10 +366,15 @@ int i_find_free_pci_card_by_position(unsigned short vendor_id, unsigned short de
 /* mark card as used */
 int pci_card_alloc(struct pcilst_struct *amcc, int master)
 {
+       int i;
+
        if (!amcc) return -1;
 
        if (amcc->used) return 1;
-       if (pci_enable_device(amcc->pcidev)) return -1;
+       if (comedi_pci_enable(amcc->pcidev, "addi_amcc_s5933")) return -1;
+       /* Resources will be accurate now. */
+       for (i=0;i<5;i++)
+               amcc->io_addr[i]=pci_resource_start(amcc->pcidev, i);
        if (master) pci_set_master(amcc->pcidev);
        amcc->used=1;
 
@@ -380,6 +389,7 @@ int i_pci_card_free(struct pcilst_struct *amcc)
 
        if (!amcc->used) return 1;
        amcc->used=0;
+       comedi_pci_disable(amcc->pcidev);
        return 0;
 }
 
@@ -394,9 +404,9 @@ void v_pci_card_list_display(void)
 
        for (amcc=amcc_devices;amcc;amcc=next) {
                next=amcc->next;
-               printk("%2d   %2d   %2d  0x%4x 0x%4x   0x%4x 0x%4x  %2d  %2d\n",
+               printk("%2d   %2d   %2d  0x%4x 0x%4x   0x%8llx 0x%8llx  %2u  %2d\n",
                        amcc->pci_bus,amcc->pci_slot,amcc->pci_func,amcc->vendor,amcc->device,
-                       amcc->io_addr[0],amcc->io_addr[2],amcc->irq,amcc->used);
+                       (unsigned long long)amcc->io_addr[0],(unsigned long long)amcc->io_addr[2],amcc->irq,amcc->used);
                
        }
 }
@@ -405,7 +415,7 @@ void v_pci_card_list_display(void)
 /* return all card information for driver */
 int i_pci_card_data(struct pcilst_struct *amcc,
        unsigned char *pci_bus, unsigned char *pci_slot, unsigned char *pci_func,
-       unsigned long *io_addr, unsigned short *irq)
+       resource_size_t *io_addr, unsigned int *irq)
 {
        int     i;
        
index dbf21bedfb4b30d609c85df8cd78799bf2703b47..441baa9906dae5f8032d27e82f3738fa8238d5bb 100644 (file)
@@ -2541,9 +2541,9 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it)
        comedi_subdevice *s;
        int ret,pages,i,n_subdevices;
         DWORD dw_Dummy; 
-       unsigned long io_addr[5];
-       unsigned short irq;//v_58
-        unsigned long iobase_a,iobase_main,iobase_addon,iobase_reserved;
+       resource_size_t io_addr[5];
+       unsigned int irq;
+        resource_size_t iobase_a,iobase_main,iobase_addon,iobase_reserved;
        struct pcilst_struct *card=NULL;
        unsigned char pci_bus,pci_slot,pci_func;
        int i_Dma = 0;
@@ -2584,8 +2584,10 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it)
        iobase_main=io_addr[1];
        iobase_addon=io_addr[2];
         iobase_reserved=io_addr[3];
-       printk("\nBus %d: Slot %d: Funct%d\nBase0: 0x%8lx\nBase1: 0x%8lx\nBase2: 0x%8lx\nBase3: 0x%8lx\n",
-               pci_bus,pci_slot,pci_func,io_addr[0],io_addr[1],io_addr[2],io_addr[3]);
+       printk("\nBus %d: Slot %d: Funct%d\nBase0: 0x%8llx\nBase1: 0x%8llx\nBase2: 0x%8llx\nBase3: 0x%8llx\n",
+               pci_bus,pci_slot,pci_func,(unsigned long long)io_addr[0],
+               (unsigned long long)io_addr[1],(unsigned long long)io_addr[2],
+               (unsigned long long)io_addr[3]);
        
        if ((this_board->pc_EepromChip == NULL) || (strcmp (this_board->pc_EepromChip, ADDIDATA_9054) != 0))
           {
@@ -2595,17 +2597,11 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it)
        
           if (this_board->i_IorangeBase1 != 0)
              {
-             dev->iobase=iobase_main;// DAQ base address...
-             printk("\nrequest_region i_IorangeBase1 - 1\n");
-             request_region(dev->iobase,  this_board->i_IorangeBase1, c_Identifier);
-             printk("\nrequest_region i_IorangeBase1 - 1 OK\n");
+             dev->iobase=(unsigned long)iobase_main;// DAQ base address...
              }
           else
              {
-             dev->iobase=iobase_a;// DAQ base address...
-             printk("\nrequest_region i_IorangeBase0 - 2");
-             request_region(dev->iobase,  this_board->i_IorangeBase0, c_Identifier);
-             printk("\nrequest_region i_IorangeBase0 - 2 %lX OK", dev->iobase);
+             dev->iobase=(unsigned long)iobase_a;// DAQ base address...
              }
 
           dev->board_name =this_board->pc_DriverName;
@@ -2614,26 +2610,11 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it)
              return -ENOMEM;
              }
           devpriv->amcc=card;
-           devpriv->iobase=dev->iobase;
-          devpriv->i_IobaseAmcc=iobase_a;//AMCC base address...
-          devpriv->i_IobaseAddon=iobase_addon;//ADD ON base address....
-           devpriv->i_IobaseReserved=iobase_reserved; 
+           devpriv->iobase=(INT)dev->iobase;
+          devpriv->i_IobaseAmcc=(INT)iobase_a;//AMCC base address...
+          devpriv->i_IobaseAddon=(INT)iobase_addon;//ADD ON base address....
+           devpriv->i_IobaseReserved=(INT)iobase_reserved; 
           devpriv->ps_BoardInfo = this_board;
-
-           //if(this_board->i_Dma)
-          if((iobase_a) && (iobase_a != dev->iobase))
-             {
-             request_region(devpriv->i_IobaseAmcc,this_board->i_IorangeBase0, c_Identifier);
-             printk("\nrequest_region i_IorangeBase0 - 3 OK\n");
-             }
-        
-           //##
-          if(io_addr[2])
-             {
-             printk("request_region i_IorangeBase2\n");
-             request_region(io_addr[2],this_board->i_IorangeBase2, c_Identifier);
-             printk("request_region i_IorangeBase2 OK\n");
-             }
           }
        else
           {
@@ -2642,18 +2623,12 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it)
              return -ENOMEM;
              }
           
-          if (pci_request_regions (card->pcidev, c_Identifier))
-             {
-             printk("\nRequest regions error\n");
-             return -EIO;
-             }
-             
           dev->board_name =this_board->pc_DriverName;
-          dev->iobase=io_addr[2];
+          dev->iobase=(unsigned long)io_addr[2];
           devpriv->amcc=card;
-           devpriv->iobase=io_addr[2];
+           devpriv->iobase=(INT)io_addr[2];
           devpriv->ps_BoardInfo = this_board;
-          devpriv->i_IobaseReserved=io_addr[3];
+          devpriv->i_IobaseReserved=(INT)io_addr[3];
           printk ("\nioremap begin");
           devpriv->dw_AiBase=(ULONG_PTR) ioremap(io_addr[3],this_board->i_IorangeBase3);
           printk ("\nioremap end");
@@ -2665,13 +2640,12 @@ static int i_ADDI_Attach(comedi_device *dev,comedi_devconfig *it)
           {
           if (comedi_request_irq(irq, v_ADDI_Interrupt, IRQF_SHARED, c_Identifier, dev) < 0) 
              {
-             printk(", unable to allocate IRQ %d, DISABLING IT", irq);
+             printk(", unable to allocate IRQ %u, DISABLING IT", irq);
              irq=0; /* Can't use IRQ */
              } 
           else 
              {
-             rt_printk("\nirq=%d", irq);
-             enable_irq (irq);
+             rt_printk("\nirq=%u", irq);
              }    
           } 
        else 
@@ -2975,30 +2949,14 @@ static int i_ADDI_Detach(comedi_device *dev)
              {
              i_ADDI_Reset(dev);
              }
+           
+          if(dev->irq)
+             {
+             comedi_free_irq(dev->irq,dev);
+             }
           
           if ((devpriv->ps_BoardInfo->pc_EepromChip == NULL) || (strcmp (devpriv->ps_BoardInfo->pc_EepromChip, ADDIDATA_9054) != 0))
              {
-             if(devpriv->i_IobaseAmcc)
-                {
-                printk("\nrelease_region base address 0");
-                release_region(devpriv->i_IobaseAmcc,this_board->i_IorangeBase0);
-                printk("\nrelease_region base address 0 OK");
-                }
-                
-             if(this_board->i_IorangeBase1) 
-                {
-                printk("\nrelease_region base address 1");
-                release_region(dev->iobase,this_board->i_IorangeBase1);
-                printk("\nrelease_region base address 1 OK");
-                }
-
-             if(this_board->i_IorangeBase2) 
-                {
-                printk("\nrelease_region base address 2");
-                release_region(devpriv->i_IobaseAddon,this_board->i_IorangeBase2); 
-                printk("\nrelease_region base address 2 OK");
-                }
-                
              if (devpriv->allocated)
                 {          
                 i_pci_card_free(devpriv->amcc);
@@ -3018,18 +2976,11 @@ static int i_ADDI_Detach(comedi_device *dev)
              {
              iounmap ((void *) devpriv->dw_AiBase);
              
-             pci_release_regions(devpriv->amcc->pcidev);
-
              if (devpriv->allocated)
                 {          
                 i_pci_card_free(devpriv->amcc);
                 }
              }
-           
-          if(dev->irq)
-             {
-             free_irq(dev->irq,dev);
-             }
        
           if (pci_list_builded) 
              {