Skip to content

Commit ebb00fb

Browse files
committed
ide: factor out simplex handling from ide_pci_dma_base()
* Factor out simplex handling from ide_pci_dma_base() to ide_pci_check_simplex(). * Set hwif->dma_base early in ->init_dma method / ide_hwif_setup_dma() and reset it in ide_init_port() if DMA initialization fails. * Use ->read_sff_dma_status instead of ->INB in ide_pci_dma_base(). There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 81e8d5a commit ebb00fb

5 files changed

Lines changed: 43 additions & 18 deletions

File tree

‎drivers/ide/ide-probe.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
13631363

13641364
if (rc < 0) {
13651365
printk(KERN_INFO "%s: DMA disabled\n", hwif->name);
1366+
hwif->dma_base = 0;
13661367
hwif->swdma_mask = 0;
13671368
hwif->mwdma_mask = 0;
13681369
hwif->ultra_mask = 0;

‎drivers/ide/pci/alim15x3.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,15 @@ static int __devinit init_dma_ali15x3(ide_hwif_t *hwif,
471471
struct pci_dev *dev = to_pci_dev(hwif->dev);
472472
unsigned long base = ide_pci_dma_base(hwif, d);
473473

474-
if (base == 0 || ide_pci_set_master(dev, d->name) < 0)
474+
if (base == 0)
475+
return -1;
476+
477+
hwif->dma_base = base;
478+
479+
if (ide_pci_check_simplex(hwif, d) < 0)
480+
return -1;
481+
482+
if (ide_pci_set_master(dev, d->name) < 0)
475483
return -1;
476484

477485
if (!hwif->channel)
@@ -483,8 +491,6 @@ static int __devinit init_dma_ali15x3(ide_hwif_t *hwif,
483491
if (ide_allocate_dma_engine(hwif))
484492
return -1;
485493

486-
hwif->dma_base = base;
487-
488494
hwif->dma_ops = &sff_dma_ops;
489495

490496
return 0;

‎drivers/ide/pci/hpt366.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,15 @@ static int __devinit init_dma_hpt366(ide_hwif_t *hwif,
13201320
unsigned long flags, base = ide_pci_dma_base(hwif, d);
13211321
u8 dma_old, dma_new, masterdma = 0, slavedma = 0;
13221322

1323-
if (base == 0 || ide_pci_set_master(dev, d->name) < 0)
1323+
if (base == 0)
1324+
return -1;
1325+
1326+
hwif->dma_base = base;
1327+
1328+
if (ide_pci_check_simplex(hwif, d) < 0)
1329+
return -1;
1330+
1331+
if (ide_pci_set_master(dev, d->name) < 0)
13241332
return -1;
13251333

13261334
dma_old = inb(base + 2);
@@ -1346,8 +1354,6 @@ static int __devinit init_dma_hpt366(ide_hwif_t *hwif,
13461354
if (ide_allocate_dma_engine(hwif))
13471355
return -1;
13481356

1349-
hwif->dma_base = base;
1350-
13511357
hwif->dma_ops = &sff_dma_ops;
13521358

13531359
return 0;

‎drivers/ide/setup-pci.c‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,12 @@ static void ide_pci_clear_simplex(unsigned long dma_base, const char *name)
7373
* @d: IDE port info
7474
*
7575
* Fetch the DMA Bus-Master-I/O-Base-Address (BMIBA) from PCI space.
76-
* Where a device has a partner that is already in DMA mode we check
77-
* and enforce IDE simplex rules.
7876
*/
7977

8078
unsigned long ide_pci_dma_base(ide_hwif_t *hwif, const struct ide_port_info *d)
8179
{
8280
struct pci_dev *dev = to_pci_dev(hwif->dev);
8381
unsigned long dma_base = 0;
84-
u8 dma_stat = 0;
8582

8683
if (hwif->host_flags & IDE_HFLAG_MMIO)
8784
return hwif->dma_base;
@@ -102,11 +99,19 @@ unsigned long ide_pci_dma_base(ide_hwif_t *hwif, const struct ide_port_info *d)
10299
if (hwif->channel)
103100
dma_base += 8;
104101

105-
if (d->host_flags & IDE_HFLAG_CS5520)
102+
return dma_base;
103+
}
104+
EXPORT_SYMBOL_GPL(ide_pci_dma_base);
105+
106+
int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
107+
{
108+
u8 dma_stat;
109+
110+
if (d->host_flags & (IDE_HFLAG_MMIO | IDE_HFLAG_CS5520))
106111
goto out;
107112

108113
if (d->host_flags & IDE_HFLAG_CLEAR_SIMPLEX) {
109-
ide_pci_clear_simplex(dma_base, d->name);
114+
ide_pci_clear_simplex(hwif->dma_base, d->name);
110115
goto out;
111116
}
112117

@@ -120,15 +125,15 @@ unsigned long ide_pci_dma_base(ide_hwif_t *hwif, const struct ide_port_info *d)
120125
* we tune the drive then try to grab DMA ownership if we want to be
121126
* the DMA end. This has to be become dynamic to handle hot-plug.
122127
*/
123-
dma_stat = hwif->INB(dma_base + 2);
128+
dma_stat = hwif->read_sff_dma_status(hwif);
124129
if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) {
125130
printk(KERN_INFO "%s: simplex device: DMA disabled\n", d->name);
126-
dma_base = 0;
131+
return -1;
127132
}
128133
out:
129-
return dma_base;
134+
return 0;
130135
}
131-
EXPORT_SYMBOL_GPL(ide_pci_dma_base);
136+
EXPORT_SYMBOL_GPL(ide_pci_check_simplex);
132137

133138
/*
134139
* Set up BM-DMA capability (PnP BIOS should have done this)
@@ -363,7 +368,15 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
363368
(dev->class & 0x80))) {
364369
unsigned long base = ide_pci_dma_base(hwif, d);
365370

366-
if (base == 0 || ide_pci_set_master(dev, d->name) < 0)
371+
if (base == 0)
372+
return -1;
373+
374+
hwif->dma_base = base;
375+
376+
if (ide_pci_check_simplex(hwif, d) < 0)
377+
return -1;
378+
379+
if (ide_pci_set_master(dev, d->name) < 0)
367380
return -1;
368381

369382
if (hwif->host_flags & IDE_HFLAG_MMIO)
@@ -377,8 +390,6 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
377390
if (ide_allocate_dma_engine(hwif))
378391
return -1;
379392

380-
hwif->dma_base = base;
381-
382393
hwif->dma_ops = &sff_dma_ops;
383394
}
384395

‎include/linux/ide.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *);
10081008
int ide_pci_set_master(struct pci_dev *, const char *);
10091009
unsigned long ide_pci_dma_base(ide_hwif_t *, const struct ide_port_info *);
10101010
extern const struct ide_dma_ops sff_dma_ops;
1011+
int ide_pci_check_simplex(ide_hwif_t *, const struct ide_port_info *);
10111012
int ide_hwif_setup_dma(ide_hwif_t *, const struct ide_port_info *);
10121013
#else
10131014
static inline int ide_hwif_setup_dma(ide_hwif_t *hwif,

0 commit comments

Comments
 (0)