Skip to content

Commit 2bbd57c

Browse files
committed
ide: switch to DMA-mapping API part raspberrypi#2
Follow-up to commit 5c05ff6 ("ide: switch to DMA-mapping API"): * pci_{alloc,free}_consistent() -> dma_{alloc,free}_coherent() in ide_{allocate,release}_dma_engine(). * Add ->prd_max_nents and ->prd_ent_size fields to ide_hwif_t (+ set default values in ide_allocate_dma_engine()). * Make ide_{allocate,release}_dma_engine() available also for CONFIG_BLK_DEV_IDEDMA_SFF=n. Then convert au1xxx-ide.c, scc_pata.c and sgiioc4.c to use them. * Add missing ->init_dma method to scc_pata. This patch also fixes: - ->dmatable_cpu leak for au1xxx-ide - too early realease of ->dmatable_cpu for scc_pata - wrong amount of ->dmatable_cpu memory being freed for sgiioc4 While at it: - remove superfluous ->dma_base check from ide_unregister() - return -ENOMEM on error in ide_release_dma_engine() - beautify error message in ide_release_dma_engine() Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent ffa15a6 commit 2bbd57c

6 files changed

Lines changed: 47 additions & 40 deletions

File tree

‎drivers/ide/ide-dma.c‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -844,36 +844,43 @@ void ide_dma_timeout(ide_drive_t *drive)
844844
}
845845
EXPORT_SYMBOL_GPL(ide_dma_timeout);
846846

847-
#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
848847
void ide_release_dma_engine(ide_hwif_t *hwif)
849848
{
850849
if (hwif->dmatable_cpu) {
851-
struct pci_dev *pdev = to_pci_dev(hwif->dev);
850+
int prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
852851

853-
pci_free_consistent(pdev, PRD_ENTRIES * PRD_BYTES,
854-
hwif->dmatable_cpu, hwif->dmatable_dma);
852+
dma_free_coherent(hwif->dev, prd_size,
853+
hwif->dmatable_cpu, hwif->dmatable_dma);
855854
hwif->dmatable_cpu = NULL;
856855
}
857856
}
857+
EXPORT_SYMBOL_GPL(ide_release_dma_engine);
858858

859859
int ide_allocate_dma_engine(ide_hwif_t *hwif)
860860
{
861-
struct pci_dev *pdev = to_pci_dev(hwif->dev);
861+
int prd_size;
862862

863-
hwif->dmatable_cpu = pci_alloc_consistent(pdev,
864-
PRD_ENTRIES * PRD_BYTES,
865-
&hwif->dmatable_dma);
863+
if (hwif->prd_max_nents == 0)
864+
hwif->prd_max_nents = PRD_ENTRIES;
865+
if (hwif->prd_ent_size == 0)
866+
hwif->prd_ent_size = PRD_BYTES;
866867

867-
if (hwif->dmatable_cpu)
868-
return 0;
868+
prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
869869

870-
printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n",
870+
hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, prd_size,
871+
&hwif->dmatable_dma,
872+
GFP_ATOMIC);
873+
if (hwif->dmatable_cpu == NULL) {
874+
printk(KERN_ERR "%s: unable to allocate PRD table\n",
871875
hwif->name);
876+
return -ENOMEM;
877+
}
872878

873-
return 1;
879+
return 0;
874880
}
875881
EXPORT_SYMBOL_GPL(ide_allocate_dma_engine);
876882

883+
#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
877884
const struct ide_dma_ops sff_dma_ops = {
878885
.dma_host_set = ide_dma_host_set,
879886
.dma_setup = ide_dma_setup,

‎drivers/ide/ide.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ void ide_unregister(ide_hwif_t *hwif)
227227
kfree(hwif->sg_table);
228228
unregister_blkdev(hwif->major, hwif->name);
229229

230-
if (hwif->dma_base)
231-
ide_release_dma_engine(hwif);
230+
ide_release_dma_engine(hwif);
232231

233232
mutex_unlock(&ide_cfg_mtx);
234233
}

‎drivers/ide/mips/au1xxx-ide.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,9 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
427427
NUM_DESCRIPTORS);
428428
auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
429429
NUM_DESCRIPTORS);
430-
431-
hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev,
432-
PRD_ENTRIES * PRD_BYTES, /* 1 Page */
433-
&hwif->dmatable_dma, GFP_KERNEL);
430+
431+
/* FIXME: check return value */
432+
(void)ide_allocate_dma_engine(hwif);
434433

435434
au1xxx_dbdma_start( auide->tx_chan );
436435
au1xxx_dbdma_start( auide->rx_chan );

‎drivers/ide/pci/scc_pata.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,12 @@ static void __devinit init_iops_scc(ide_hwif_t *hwif)
821821
init_mmio_iops_scc(hwif);
822822
}
823823

824+
static int __devinit scc_init_dma(ide_hwif_t *hwif,
825+
const struct ide_port_info *d)
826+
{
827+
return ide_allocate_dma_engine(hwif);
828+
}
829+
824830
static u8 scc_cable_detect(ide_hwif_t *hwif)
825831
{
826832
return ATA_CBL_PATA80;
@@ -885,6 +891,7 @@ static const struct ide_dma_ops scc_dma_ops = {
885891
{ \
886892
.name = name_str, \
887893
.init_iops = init_iops_scc, \
894+
.init_dma = scc_init_dma, \
888895
.init_hwif = init_hwif_scc, \
889896
.tp_ops = &scc_tp_ops, \
890897
.port_ops = &scc_port_ops, \
@@ -922,13 +929,6 @@ static void __devexit scc_remove(struct pci_dev *dev)
922929
{
923930
struct scc_ports *ports = pci_get_drvdata(dev);
924931
struct ide_host *host = ports->host;
925-
ide_hwif_t *hwif = host->ports[0];
926-
927-
if (hwif->dmatable_cpu) {
928-
pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES,
929-
hwif->dmatable_cpu, hwif->dmatable_dma);
930-
hwif->dmatable_cpu = NULL;
931-
}
932932

933933
ide_host_remove(host);
934934

‎drivers/ide/pci/sgiioc4.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,13 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
357357
}
358358
hwif->dma_base = (unsigned long) virt_dma_base;
359359

360-
hwif->dmatable_cpu = pci_alloc_consistent(dev,
361-
IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
362-
&hwif->dmatable_dma);
360+
hwif->sg_max_nents = IOC4_PRD_ENTRIES;
363361

364-
if (!hwif->dmatable_cpu)
365-
goto dma_pci_alloc_failure;
362+
hwif->prd_max_nents = IOC4_PRD_ENTRIES;
363+
hwif->prd_ent_size = IOC4_PRD_BYTES;
366364

367-
hwif->sg_max_nents = IOC4_PRD_ENTRIES;
365+
if (ide_allocate_dma_engine(hwif))
366+
goto dma_pci_alloc_failure;
368367

369368
pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE,
370369
(dma_addr_t *)&hwif->extra_base);
@@ -373,8 +372,8 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
373372
return 0;
374373
}
375374

376-
pci_free_consistent(dev, IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
377-
hwif->dmatable_cpu, hwif->dmatable_dma);
375+
ide_release_dma_engine(hwif);
376+
378377
printk(KERN_ERR "%s(%s) -- ERROR: Unable to allocate DMA maps\n",
379378
__func__, hwif->name);
380379
printk(KERN_INFO "%s: changing from DMA to PIO mode", hwif->name);

‎include/linux/ide.h‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,12 @@ typedef struct hwif_s {
788788
unsigned int *dmatable_cpu;
789789
/* dma physical region descriptor table (dma view) */
790790
dma_addr_t dmatable_dma;
791+
792+
/* maximum number of PRD table entries */
793+
int prd_max_nents;
794+
/* PRD entry size in bytes */
795+
int prd_ent_size;
796+
791797
/* Scatter-gather list used to build the above */
792798
struct scatterlist *sg_table;
793799
int sg_max_nents; /* Maximum number of entries in it */
@@ -1423,14 +1429,14 @@ int ide_set_dma(ide_drive_t *);
14231429
void ide_check_dma_crc(ide_drive_t *);
14241430
ide_startstop_t ide_dma_intr(ide_drive_t *);
14251431

1432+
int ide_allocate_dma_engine(ide_hwif_t *);
1433+
void ide_release_dma_engine(ide_hwif_t *);
1434+
14261435
int ide_build_sglist(ide_drive_t *, struct request *);
14271436
void ide_destroy_dmatable(ide_drive_t *);
14281437

14291438
#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
14301439
extern int ide_build_dmatable(ide_drive_t *, struct request *);
1431-
int ide_allocate_dma_engine(ide_hwif_t *);
1432-
void ide_release_dma_engine(ide_hwif_t *);
1433-
14341440
void ide_dma_host_set(ide_drive_t *, int);
14351441
extern int ide_dma_setup(ide_drive_t *);
14361442
void ide_dma_exec_cmd(ide_drive_t *, u8);
@@ -1453,11 +1459,8 @@ static inline void ide_dma_on(ide_drive_t *drive) { ; }
14531459
static inline void ide_dma_verbose(ide_drive_t *drive) { ; }
14541460
static inline int ide_set_dma(ide_drive_t *drive) { return 1; }
14551461
static inline void ide_check_dma_crc(ide_drive_t *drive) { ; }
1456-
#endif /* CONFIG_BLK_DEV_IDEDMA */
1457-
1458-
#ifndef CONFIG_BLK_DEV_IDEDMA_SFF
14591462
static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; }
1460-
#endif
1463+
#endif /* CONFIG_BLK_DEV_IDEDMA */
14611464

14621465
#ifdef CONFIG_BLK_DEV_IDEACPI
14631466
extern int ide_acpi_exec_tfs(ide_drive_t *drive);

0 commit comments

Comments
 (0)