diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-04-26 16:25:19 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-04-26 16:25:19 -0400 |
commit | 0d1bad216c43bcee84cc24d1ed003c19134d2645 (patch) | |
tree | 3cdcf7592c4e1a8899cde78beb512bffa21abf77 /drivers | |
parent | 7ebe5936c214c656a1625abf9ec3b09e3d1bf34a (diff) |
ide: manage resources for PCI devices in ide_pci_enable() (take 3)
* 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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/ide/ide-dma.c | 43 | ||||
-rw-r--r-- | drivers/ide/ide-probe.c | 6 | ||||
-rw-r--r-- | drivers/ide/ide.c | 2 | ||||
-rw-r--r-- | drivers/ide/pci/scc_pata.c | 31 | ||||
-rw-r--r-- | drivers/ide/pci/trm290.c | 6 | ||||
-rw-r--r-- | drivers/ide/setup-pci.c | 22 |
6 files changed, 28 insertions, 82 deletions
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c index dc4bc06f9871..986ec465cb77 100644 --- a/drivers/ide/ide-dma.c +++ b/drivers/ide/ide-dma.c | |||
@@ -810,7 +810,7 @@ void ide_dma_timeout (ide_drive_t *drive) | |||
810 | 810 | ||
811 | EXPORT_SYMBOL(ide_dma_timeout); | 811 | EXPORT_SYMBOL(ide_dma_timeout); |
812 | 812 | ||
813 | static void ide_release_dma_engine(ide_hwif_t *hwif) | 813 | void ide_release_dma_engine(ide_hwif_t *hwif) |
814 | { | 814 | { |
815 | if (hwif->dmatable_cpu) { | 815 | if (hwif->dmatable_cpu) { |
816 | struct pci_dev *pdev = to_pci_dev(hwif->dev); | 816 | struct pci_dev *pdev = to_pci_dev(hwif->dev); |
@@ -821,27 +821,6 @@ static void ide_release_dma_engine(ide_hwif_t *hwif) | |||
821 | } | 821 | } |
822 | } | 822 | } |
823 | 823 | ||
824 | static int ide_release_iomio_dma(ide_hwif_t *hwif) | ||
825 | { | ||
826 | release_region(hwif->dma_base, 8); | ||
827 | if (hwif->extra_ports) | ||
828 | release_region(hwif->extra_base, hwif->extra_ports); | ||
829 | return 1; | ||
830 | } | ||
831 | |||
832 | /* | ||
833 | * Needed for allowing full modular support of ide-driver | ||
834 | */ | ||
835 | int ide_release_dma(ide_hwif_t *hwif) | ||
836 | { | ||
837 | ide_release_dma_engine(hwif); | ||
838 | |||
839 | if (hwif->mmio) | ||
840 | return 1; | ||
841 | else | ||
842 | return ide_release_iomio_dma(hwif); | ||
843 | } | ||
844 | |||
845 | static int ide_allocate_dma_engine(ide_hwif_t *hwif) | 824 | static int ide_allocate_dma_engine(ide_hwif_t *hwif) |
846 | { | 825 | { |
847 | struct pci_dev *pdev = to_pci_dev(hwif->dev); | 826 | 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) | |||
871 | printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx", | 850 | printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx", |
872 | hwif->name, base, base + 7); | 851 | hwif->name, base, base + 7); |
873 | 852 | ||
874 | if (!request_region(base, 8, hwif->name)) { | 853 | if (hwif->cds->extra) |
875 | printk(" -- Error, ports in use.\n"); | ||
876 | return 1; | ||
877 | } | ||
878 | |||
879 | if (hwif->cds->extra) { | ||
880 | hwif->extra_base = base + (hwif->channel ? 8 : 16); | 854 | hwif->extra_base = base + (hwif->channel ? 8 : 16); |
881 | 855 | ||
882 | if (!hwif->mate || !hwif->mate->extra_ports) { | ||
883 | if (!request_region(hwif->extra_base, | ||
884 | hwif->cds->extra, hwif->cds->name)) { | ||
885 | printk(" -- Error, extra ports in use.\n"); | ||
886 | release_region(base, 8); | ||
887 | return 1; | ||
888 | } | ||
889 | hwif->extra_ports = hwif->cds->extra; | ||
890 | } | ||
891 | } | ||
892 | |||
893 | return 0; | 856 | return 0; |
894 | } | 857 | } |
895 | 858 | ||
@@ -909,7 +872,7 @@ void ide_setup_dma(ide_hwif_t *hwif, unsigned long base) | |||
909 | return; | 872 | return; |
910 | 873 | ||
911 | if (ide_allocate_dma_engine(hwif)) { | 874 | if (ide_allocate_dma_engine(hwif)) { |
912 | ide_release_dma(hwif); | 875 | ide_release_dma_engine(hwif); |
913 | return; | 876 | return; |
914 | } | 877 | } |
915 | 878 | ||
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c index 670d7f9ccf0e..4a8a482b43a3 100644 --- a/drivers/ide/ide-probe.c +++ b/drivers/ide/ide-probe.c | |||
@@ -1530,12 +1530,6 @@ int ide_device_add_all(u8 *idx, const struct ide_port_info *d) | |||
1530 | 1530 | ||
1531 | hwif = &ide_hwifs[idx[i]]; | 1531 | hwif = &ide_hwifs[idx[i]]; |
1532 | 1532 | ||
1533 | if (ide_hwif_request_regions(hwif)) { | ||
1534 | printk(KERN_ERR "%s: ports already in use, " | ||
1535 | "skipping probe\n", hwif->name); | ||
1536 | continue; | ||
1537 | } | ||
1538 | |||
1539 | if (ide_probe_port(hwif) == 0) | 1533 | if (ide_probe_port(hwif) == 0) |
1540 | hwif->present = 1; | 1534 | hwif->present = 1; |
1541 | 1535 | ||
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index 629383dd37db..694d997ce50f 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c | |||
@@ -413,7 +413,7 @@ void ide_unregister(unsigned int index) | |||
413 | spin_lock_irq(&ide_lock); | 413 | spin_lock_irq(&ide_lock); |
414 | 414 | ||
415 | if (hwif->dma_base) | 415 | if (hwif->dma_base) |
416 | (void)ide_release_dma(hwif); | 416 | ide_release_dma_engine(hwif); |
417 | 417 | ||
418 | /* restore hwif data to pristine status */ | 418 | /* restore hwif data to pristine status */ |
419 | ide_init_port_data(hwif, index); | 419 | ide_init_port_data(hwif, index); |
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c index c01e2da5c9e6..41a993f3ded2 100644 --- a/drivers/ide/pci/scc_pata.c +++ b/drivers/ide/pci/scc_pata.c | |||
@@ -483,7 +483,7 @@ static int setup_mmio_scc (struct pci_dev *dev, const char *name) | |||
483 | unsigned long dma_size = pci_resource_len(dev, 1); | 483 | unsigned long dma_size = pci_resource_len(dev, 1); |
484 | void __iomem *ctl_addr; | 484 | void __iomem *ctl_addr; |
485 | void __iomem *dma_addr; | 485 | void __iomem *dma_addr; |
486 | int i; | 486 | int i, ret; |
487 | 487 | ||
488 | for (i = 0; i < MAX_HWIFS; i++) { | 488 | for (i = 0; i < MAX_HWIFS; i++) { |
489 | if (scc_ports[i].ctl == 0) | 489 | if (scc_ports[i].ctl == 0) |
@@ -492,21 +492,17 @@ static int setup_mmio_scc (struct pci_dev *dev, const char *name) | |||
492 | if (i >= MAX_HWIFS) | 492 | if (i >= MAX_HWIFS) |
493 | return -ENOMEM; | 493 | return -ENOMEM; |
494 | 494 | ||
495 | if (!request_mem_region(ctl_base, ctl_size, name)) { | 495 | ret = pci_request_selected_regions(dev, (1 << 2) - 1, name); |
496 | printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME); | 496 | if (ret < 0) { |
497 | goto fail_0; | 497 | printk(KERN_ERR "%s: can't reserve resources\n", name); |
498 | } | 498 | return ret; |
499 | |||
500 | if (!request_mem_region(dma_base, dma_size, name)) { | ||
501 | printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME); | ||
502 | goto fail_1; | ||
503 | } | 499 | } |
504 | 500 | ||
505 | if ((ctl_addr = ioremap(ctl_base, ctl_size)) == NULL) | 501 | if ((ctl_addr = ioremap(ctl_base, ctl_size)) == NULL) |
506 | goto fail_2; | 502 | goto fail_0; |
507 | 503 | ||
508 | if ((dma_addr = ioremap(dma_base, dma_size)) == NULL) | 504 | if ((dma_addr = ioremap(dma_base, dma_size)) == NULL) |
509 | goto fail_3; | 505 | goto fail_1; |
510 | 506 | ||
511 | pci_set_master(dev); | 507 | pci_set_master(dev); |
512 | scc_ports[i].ctl = (unsigned long)ctl_addr; | 508 | scc_ports[i].ctl = (unsigned long)ctl_addr; |
@@ -515,12 +511,8 @@ static int setup_mmio_scc (struct pci_dev *dev, const char *name) | |||
515 | 511 | ||
516 | return 1; | 512 | return 1; |
517 | 513 | ||
518 | fail_3: | ||
519 | iounmap(ctl_addr); | ||
520 | fail_2: | ||
521 | release_mem_region(dma_base, dma_size); | ||
522 | fail_1: | 514 | fail_1: |
523 | release_mem_region(ctl_base, ctl_size); | 515 | iounmap(ctl_addr); |
524 | fail_0: | 516 | fail_0: |
525 | return -ENOMEM; | 517 | return -ENOMEM; |
526 | } | 518 | } |
@@ -757,10 +749,6 @@ static void __devexit scc_remove(struct pci_dev *dev) | |||
757 | { | 749 | { |
758 | struct scc_ports *ports = pci_get_drvdata(dev); | 750 | struct scc_ports *ports = pci_get_drvdata(dev); |
759 | ide_hwif_t *hwif = ports->hwif; | 751 | ide_hwif_t *hwif = ports->hwif; |
760 | unsigned long ctl_base = pci_resource_start(dev, 0); | ||
761 | unsigned long dma_base = pci_resource_start(dev, 1); | ||
762 | unsigned long ctl_size = pci_resource_len(dev, 0); | ||
763 | unsigned long dma_size = pci_resource_len(dev, 1); | ||
764 | 752 | ||
765 | if (hwif->dmatable_cpu) { | 753 | if (hwif->dmatable_cpu) { |
766 | pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES, | 754 | pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES, |
@@ -773,8 +761,7 @@ static void __devexit scc_remove(struct pci_dev *dev) | |||
773 | hwif->chipset = ide_unknown; | 761 | hwif->chipset = ide_unknown; |
774 | iounmap((void*)ports->dma); | 762 | iounmap((void*)ports->dma); |
775 | iounmap((void*)ports->ctl); | 763 | iounmap((void*)ports->ctl); |
776 | release_mem_region(dma_base, dma_size); | 764 | pci_release_selected_regions(dev, (1 << 2) - 1); |
777 | release_mem_region(ctl_base, ctl_size); | ||
778 | memset(ports, 0, sizeof(*ports)); | 765 | memset(ports, 0, sizeof(*ports)); |
779 | } | 766 | } |
780 | 767 | ||
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c index 47265030f87d..0677ab016ef8 100644 --- a/drivers/ide/pci/trm290.c +++ b/drivers/ide/pci/trm290.c | |||
@@ -257,16 +257,10 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif) | |||
257 | printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx", | 257 | printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx", |
258 | hwif->name, hwif->dma_base, hwif->dma_base + 3); | 258 | hwif->name, hwif->dma_base, hwif->dma_base + 3); |
259 | 259 | ||
260 | if (!request_region(hwif->dma_base, 4, hwif->name)) { | ||
261 | printk(KERN_CONT " -- Error, ports in use.\n"); | ||
262 | return; | ||
263 | } | ||
264 | |||
265 | hwif->dmatable_cpu = pci_alloc_consistent(dev, PRD_ENTRIES * PRD_BYTES, | 260 | hwif->dmatable_cpu = pci_alloc_consistent(dev, PRD_ENTRIES * PRD_BYTES, |
266 | &hwif->dmatable_dma); | 261 | &hwif->dmatable_dma); |
267 | if (!hwif->dmatable_cpu) { | 262 | if (!hwif->dmatable_cpu) { |
268 | printk(KERN_CONT " -- Error, unable to allocate DMA table.\n"); | 263 | printk(KERN_CONT " -- Error, unable to allocate DMA table.\n"); |
269 | release_region(hwif->dma_base, 4); | ||
270 | return; | 264 | return; |
271 | } | 265 | } |
272 | printk(KERN_CONT "\n"); | 266 | printk(KERN_CONT "\n"); |
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c index 6302010fd8e2..8812eaa7f169 100644 --- a/drivers/ide/setup-pci.c +++ b/drivers/ide/setup-pci.c | |||
@@ -158,7 +158,7 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise); | |||
158 | 158 | ||
159 | static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d) | 159 | static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d) |
160 | { | 160 | { |
161 | int ret; | 161 | int ret, bars; |
162 | 162 | ||
163 | if (pci_enable_device(dev)) { | 163 | if (pci_enable_device(dev)) { |
164 | ret = pci_enable_device_io(dev); | 164 | 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) | |||
181 | goto out; | 181 | goto out; |
182 | } | 182 | } |
183 | 183 | ||
184 | /* FIXME: Temporary - until we put in the hotplug interface logic | 184 | if (d->host_flags & IDE_HFLAG_SINGLE) |
185 | Check that the bits we want are not in use by someone else. */ | 185 | bars = (1 << 2) - 1; |
186 | ret = pci_request_region(dev, 4, "ide_tmp"); | 186 | else |
187 | if (ret < 0) | 187 | bars = (1 << 4) - 1; |
188 | goto out; | ||
189 | 188 | ||
190 | pci_release_region(dev, 4); | 189 | if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) { |
190 | if (d->host_flags & IDE_HFLAG_CS5520) | ||
191 | bars |= (1 << 2); | ||
192 | else | ||
193 | bars |= (1 << 4); | ||
194 | } | ||
195 | |||
196 | ret = pci_request_selected_regions(dev, bars, d->name); | ||
197 | if (ret < 0) | ||
198 | printk(KERN_ERR "%s: can't reserve resources\n", d->name); | ||
191 | out: | 199 | out: |
192 | return ret; | 200 | return ret; |
193 | } | 201 | } |