]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
ide: manage resources for PCI devices in ide_pci_enable() (take 3)
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Sat, 26 Apr 2008 20:25:19 +0000 (22:25 +0200)
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Sat, 26 Apr 2008 20:25:19 +0000 (22:25 +0200)
* Reserve PCI BARs 0-3 (0-1 for single port controllers) in
  ide_pci_enable() and remove ide_hwif_request_regions() call
  from ide_device_add_all() (also cleanup resource management
  in scc_pata host driver).

* Fix handling of PCI BAR 4 in ide_pci_enable(), then cleanup
  ide_iomio_dma() (+ init_hwif_trm290() in trm290 host driver)
  and remove ide_release[_iomio]_dma().

v2:
* Fixup trm290 host driver.

v3:
* Because of scc_pata host driver changes we need to call
  pci_request_selected_regions() also in setup_mmio_scc().

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
drivers/ide/ide-dma.c
drivers/ide/ide-probe.c
drivers/ide/ide.c
drivers/ide/pci/scc_pata.c
drivers/ide/pci/trm290.c
drivers/ide/setup-pci.c
include/linux/ide.h

index dc4bc06f98714b557c64730434311103cfd21bee..986ec465cb77bd08f373cd4270ca987e1e133297 100644 (file)
@@ -810,7 +810,7 @@ void ide_dma_timeout (ide_drive_t *drive)
 
 EXPORT_SYMBOL(ide_dma_timeout);
 
-static void ide_release_dma_engine(ide_hwif_t *hwif)
+void ide_release_dma_engine(ide_hwif_t *hwif)
 {
        if (hwif->dmatable_cpu) {
                struct pci_dev *pdev = to_pci_dev(hwif->dev);
@@ -821,27 +821,6 @@ static void ide_release_dma_engine(ide_hwif_t *hwif)
        }
 }
 
-static int ide_release_iomio_dma(ide_hwif_t *hwif)
-{
-       release_region(hwif->dma_base, 8);
-       if (hwif->extra_ports)
-               release_region(hwif->extra_base, hwif->extra_ports);
-       return 1;
-}
-
-/*
- * Needed for allowing full modular support of ide-driver
- */
-int ide_release_dma(ide_hwif_t *hwif)
-{
-       ide_release_dma_engine(hwif);
-
-       if (hwif->mmio)
-               return 1;
-       else
-               return ide_release_iomio_dma(hwif);
-}
-
 static int ide_allocate_dma_engine(ide_hwif_t *hwif)
 {
        struct pci_dev *pdev = to_pci_dev(hwif->dev);
@@ -871,25 +850,9 @@ static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base)
        printk(KERN_INFO "    %s: BM-DMA at 0x%04lx-0x%04lx",
               hwif->name, base, base + 7);
 
-       if (!request_region(base, 8, hwif->name)) {
-               printk(" -- Error, ports in use.\n");
-               return 1;
-       }
-
-       if (hwif->cds->extra) {
+       if (hwif->cds->extra)
                hwif->extra_base = base + (hwif->channel ? 8 : 16);
 
-               if (!hwif->mate || !hwif->mate->extra_ports) {
-                       if (!request_region(hwif->extra_base,
-                                           hwif->cds->extra, hwif->cds->name)) {
-                               printk(" -- Error, extra ports in use.\n");
-                               release_region(base, 8);
-                               return 1;
-                       }
-                       hwif->extra_ports = hwif->cds->extra;
-               }
-       }
-
        return 0;
 }
 
@@ -909,7 +872,7 @@ void ide_setup_dma(ide_hwif_t *hwif, unsigned long base)
                return;
 
        if (ide_allocate_dma_engine(hwif)) {
-               ide_release_dma(hwif);
+               ide_release_dma_engine(hwif);
                return;
        }
 
index 670d7f9ccf0e3692e7179e4a7eab36a08056d760..4a8a482b43a3dffb69e37ae2f083c0772698f89c 100644 (file)
@@ -1530,12 +1530,6 @@ int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
 
                hwif = &ide_hwifs[idx[i]];
 
-               if (ide_hwif_request_regions(hwif)) {
-                       printk(KERN_ERR "%s: ports already in use, "
-                                       "skipping probe\n", hwif->name);
-                       continue;
-               }
-
                if (ide_probe_port(hwif) == 0)
                        hwif->present = 1;
 
index 629383dd37db826544e2e102199e78c39d6c8410..694d997ce50f080a5207a2f7b464f2409d156256 100644 (file)
@@ -413,7 +413,7 @@ void ide_unregister(unsigned int index)
        spin_lock_irq(&ide_lock);
 
        if (hwif->dma_base)
-               (void)ide_release_dma(hwif);
+               ide_release_dma_engine(hwif);
 
        /* restore hwif data to pristine status */
        ide_init_port_data(hwif, index);
index c01e2da5c9e69fd3f010aba68ad65747c9b59f0f..41a993f3ded24ca84f7096ddb67b2fc22d31753c 100644 (file)
@@ -483,7 +483,7 @@ static int setup_mmio_scc (struct pci_dev *dev, const char *name)
        unsigned long dma_size = pci_resource_len(dev, 1);
        void __iomem *ctl_addr;
        void __iomem *dma_addr;
-       int i;
+       int i, ret;
 
        for (i = 0; i < MAX_HWIFS; i++) {
                if (scc_ports[i].ctl == 0)
@@ -492,21 +492,17 @@ static int setup_mmio_scc (struct pci_dev *dev, const char *name)
        if (i >= MAX_HWIFS)
                return -ENOMEM;
 
-       if (!request_mem_region(ctl_base, ctl_size, name)) {
-               printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME);
-               goto fail_0;
-       }
-
-       if (!request_mem_region(dma_base, dma_size, name)) {
-               printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME);
-               goto fail_1;
+       ret = pci_request_selected_regions(dev, (1 << 2) - 1, name);
+       if (ret < 0) {
+               printk(KERN_ERR "%s: can't reserve resources\n", name);
+               return ret;
        }
 
        if ((ctl_addr = ioremap(ctl_base, ctl_size)) == NULL)
-               goto fail_2;
+               goto fail_0;
 
        if ((dma_addr = ioremap(dma_base, dma_size)) == NULL)
-               goto fail_3;
+               goto fail_1;
 
        pci_set_master(dev);
        scc_ports[i].ctl = (unsigned long)ctl_addr;
@@ -515,12 +511,8 @@ static int setup_mmio_scc (struct pci_dev *dev, const char *name)
 
        return 1;
 
- fail_3:
-       iounmap(ctl_addr);
- fail_2:
-       release_mem_region(dma_base, dma_size);
  fail_1:
-       release_mem_region(ctl_base, ctl_size);
+       iounmap(ctl_addr);
  fail_0:
        return -ENOMEM;
 }
@@ -757,10 +749,6 @@ static void __devexit scc_remove(struct pci_dev *dev)
 {
        struct scc_ports *ports = pci_get_drvdata(dev);
        ide_hwif_t *hwif = ports->hwif;
-       unsigned long ctl_base = pci_resource_start(dev, 0);
-       unsigned long dma_base = pci_resource_start(dev, 1);
-       unsigned long ctl_size = pci_resource_len(dev, 0);
-       unsigned long dma_size = pci_resource_len(dev, 1);
 
        if (hwif->dmatable_cpu) {
                pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES,
@@ -773,8 +761,7 @@ static void __devexit scc_remove(struct pci_dev *dev)
        hwif->chipset = ide_unknown;
        iounmap((void*)ports->dma);
        iounmap((void*)ports->ctl);
-       release_mem_region(dma_base, dma_size);
-       release_mem_region(ctl_base, ctl_size);
+       pci_release_selected_regions(dev, (1 << 2) - 1);
        memset(ports, 0, sizeof(*ports));
 }
 
index 47265030f87d08f83a82ebaef851736724319e78..0677ab016ef8b2f87567fffbb9239e0ece73d6f6 100644 (file)
@@ -257,16 +257,10 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
        printk(KERN_INFO "    %s: BM-DMA at 0x%04lx-0x%04lx",
               hwif->name, hwif->dma_base, hwif->dma_base + 3);
 
-       if (!request_region(hwif->dma_base, 4, hwif->name)) {
-               printk(KERN_CONT " -- Error, ports in use.\n");
-               return;
-       }
-
        hwif->dmatable_cpu = pci_alloc_consistent(dev, PRD_ENTRIES * PRD_BYTES,
                                                  &hwif->dmatable_dma);
        if (!hwif->dmatable_cpu) {
                printk(KERN_CONT " -- Error, unable to allocate DMA table.\n");
-               release_region(hwif->dma_base, 4);
                return;
        }
        printk(KERN_CONT "\n");
index 6302010fd8e232ab17ad71d56f2c4e615aebc9da..8812eaa7f16907fa146649f3e88a005f20cbb5d4 100644 (file)
@@ -158,7 +158,7 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
 
 static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
 {
-       int ret;
+       int ret, bars;
 
        if (pci_enable_device(dev)) {
                ret = pci_enable_device_io(dev);
@@ -181,13 +181,21 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
                goto out;
        }
 
-       /* FIXME: Temporary - until we put in the hotplug interface logic
-          Check that the bits we want are not in use by someone else. */
-       ret = pci_request_region(dev, 4, "ide_tmp");
-       if (ret < 0)
-               goto out;
+       if (d->host_flags & IDE_HFLAG_SINGLE)
+               bars = (1 << 2) - 1;
+       else
+               bars = (1 << 4) - 1;
 
-       pci_release_region(dev, 4);
+       if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) {
+               if (d->host_flags & IDE_HFLAG_CS5520)
+                       bars |= (1 << 2);
+               else
+                       bars |= (1 << 4);
+       }
+
+       ret = pci_request_selected_regions(dev, bars, d->name);
+       if (ret < 0)
+               printk(KERN_ERR "%s: can't reserve resources\n", d->name);
 out:
        return ret;
 }
index a2d7800a4d30f518e471d5a54a242ab8fa175369..4204d1f35eceb1da6d58bd59463603c5f97573d4 100644 (file)
@@ -1158,7 +1158,7 @@ void ide_destroy_dmatable(ide_drive_t *);
 
 #ifdef CONFIG_BLK_DEV_IDEDMA_SFF
 extern int ide_build_dmatable(ide_drive_t *, struct request *);
-extern int ide_release_dma(ide_hwif_t *);
+extern void ide_release_dma_engine(ide_hwif_t *);
 extern void ide_setup_dma(ide_hwif_t *, unsigned long);
 
 void ide_dma_host_set(ide_drive_t *, int);
@@ -1182,7 +1182,7 @@ static inline void ide_check_dma_crc(ide_drive_t *drive) { ; }
 #endif /* CONFIG_BLK_DEV_IDEDMA */
 
 #ifndef CONFIG_BLK_DEV_IDEDMA_SFF
-static inline void ide_release_dma(ide_hwif_t *drive) {;}
+static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; }
 #endif
 
 #ifdef CONFIG_BLK_DEV_IDEACPI