Skip to content

Commit ef0b042

Browse files
committed
ide: add ide_pci_remove() helper
* Add 'unsigned long host_flags' field to struct ide_host. * Set ->host_flags in ide_host_alloc_all(). * Always set PCI dev's ->driver_data in ide_pci_init_{one,two}(). * Add ide_pci_remove() helper (the default implementation for struct pci_driver's ->remove method). Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 37525be commit ef0b042

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

‎drivers/ide/ide-probe.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,9 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
16091609
if (hws[0])
16101610
host->dev[0] = hws[0]->dev;
16111611

1612+
if (d)
1613+
host->host_flags = d->host_flags;
1614+
16121615
return host;
16131616
}
16141617
EXPORT_SYMBOL_GPL(ide_host_alloc_all);

‎drivers/ide/setup-pci.c‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,7 @@ int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
548548

549549
host->host_priv = priv;
550550

551-
if (priv)
552-
pci_set_drvdata(dev, host);
551+
pci_set_drvdata(dev, host);
553552

554553
ret = do_ide_setup_pci_device(dev, d, 1);
555554
if (ret < 0)
@@ -593,10 +592,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
593592

594593
host->host_priv = priv;
595594

596-
if (priv) {
597-
pci_set_drvdata(pdev[0], host);
598-
pci_set_drvdata(pdev[1], host);
599-
}
595+
pci_set_drvdata(pdev[0], host);
596+
pci_set_drvdata(pdev[1], host);
600597

601598
for (i = 0; i < 2; i++) {
602599
ret = do_ide_setup_pci_device(pdev[i], d, !i);
@@ -619,3 +616,33 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
619616
return ret;
620617
}
621618
EXPORT_SYMBOL_GPL(ide_pci_init_two);
619+
620+
void ide_pci_remove(struct pci_dev *dev)
621+
{
622+
struct ide_host *host = pci_get_drvdata(dev);
623+
struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
624+
int bars;
625+
626+
if (host->host_flags & IDE_HFLAG_SINGLE)
627+
bars = (1 << 2) - 1;
628+
else
629+
bars = (1 << 4) - 1;
630+
631+
if ((host->host_flags & IDE_HFLAG_NO_DMA) == 0) {
632+
if (host->host_flags & IDE_HFLAG_CS5520)
633+
bars |= (1 << 2);
634+
else
635+
bars |= (1 << 4);
636+
}
637+
638+
ide_host_remove(host);
639+
640+
if (dev2)
641+
pci_release_selected_regions(dev2, bars);
642+
pci_release_selected_regions(dev, bars);
643+
644+
if (dev2)
645+
pci_disable_device(dev2);
646+
pci_disable_device(dev);
647+
}
648+
EXPORT_SYMBOL_GPL(ide_pci_remove);

‎include/linux/ide.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ struct ide_host {
631631
ide_hwif_t *ports[MAX_HWIFS];
632632
unsigned int n_ports;
633633
struct device *dev[2];
634+
unsigned long host_flags;
634635
void *host_priv;
635636
};
636637

@@ -1213,6 +1214,7 @@ struct ide_port_info {
12131214
int ide_pci_init_one(struct pci_dev *, const struct ide_port_info *, void *);
12141215
int ide_pci_init_two(struct pci_dev *, struct pci_dev *,
12151216
const struct ide_port_info *, void *);
1217+
void ide_pci_remove(struct pci_dev *);
12161218

12171219
void ide_map_sg(ide_drive_t *, struct request *);
12181220
void ide_init_sg_cmd(ide_drive_t *, struct request *);

0 commit comments

Comments
 (0)