[ide] always allocate hwif->sg_table

Allocate hwif->sg_table in hwif_init() so it can also be used for PIO.
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent f98ac82a
......@@ -206,8 +206,6 @@ static void icside_maskproc(ide_drive_t *drive, int mask)
* here, but we rely on the main IDE driver spotting that both
* interfaces use the same IRQ, which should guarantee this.
*/
#define NR_ENTRIES 256
#define TABLE_SIZE (NR_ENTRIES * 8)
static void icside_build_sglist(ide_drive_t *drive, struct request *rq)
{
......@@ -527,7 +525,7 @@ static int icside_dma_lostirq(ide_drive_t *drive)
return 1;
}
static int icside_dma_init(ide_hwif_t *hwif)
static void icside_dma_init(ide_hwif_t *hwif)
{
int autodma = 0;
......@@ -537,11 +535,6 @@ static int icside_dma_init(ide_hwif_t *hwif)
printk(" %s: SG-DMA", hwif->name);
hwif->sg_table = kmalloc(sizeof(struct scatterlist) * NR_ENTRIES,
GFP_KERNEL);
if (!hwif->sg_table)
goto failed;
hwif->atapi_dma = 1;
hwif->mwdma_mask = 7; /* MW0..2 */
hwif->swdma_mask = 7; /* SW0..2 */
......@@ -569,24 +562,9 @@ static int icside_dma_init(ide_hwif_t *hwif)
hwif->drives[1].autodma = hwif->autodma;
printk(" capable%s\n", hwif->autodma ? ", auto-enable" : "");
return 1;
failed:
printk(" disabled, unable to allocate DMA table\n");
return 0;
}
static void icside_dma_exit(ide_hwif_t *hwif)
{
if (hwif->sg_table) {
kfree(hwif->sg_table);
hwif->sg_table = NULL;
}
}
#else
#define icside_dma_init(hwif) (0)
#define icside_dma_exit(hwif) do { } while (0)
#endif
static ide_hwif_t *icside_find_hwif(unsigned long dataport)
......@@ -811,9 +789,6 @@ static void __devexit icside_remove(struct expansion_card *ec)
case ICS_TYPE_V6:
/* FIXME: tell IDE to stop using the interface */
icside_dma_exit(state->hwif[1]);
icside_dma_exit(state->hwif[0]);
if (ec->dma != NO_DMA)
free_dma(ec->dma);
......
......@@ -810,10 +810,6 @@ int ide_release_dma_engine (ide_hwif_t *hwif)
hwif->dmatable_dma);
hwif->dmatable_cpu = NULL;
}
if (hwif->sg_table) {
kfree(hwif->sg_table);
hwif->sg_table = NULL;
}
return 1;
}
......@@ -846,15 +842,12 @@ int ide_allocate_dma_engine (ide_hwif_t *hwif)
hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev,
PRD_ENTRIES * PRD_BYTES,
&hwif->dmatable_dma);
hwif->sg_table = kmalloc(sizeof(struct scatterlist) * PRD_ENTRIES,
GFP_KERNEL);
if ((hwif->dmatable_cpu) && (hwif->sg_table))
if (hwif->dmatable_cpu)
return 0;
printk(KERN_ERR "%s: -- Error, unable to allocate%s%s table(s).\n",
printk(KERN_ERR "%s: -- Error, unable to allocate%s DMA table(s).\n",
(hwif->dmatable_cpu == NULL) ? " CPU" : "",
(hwif->sg_table == NULL) ? " SG DMA" : " DMA",
hwif->cds->name);
ide_release_dma_engine(hwif);
......
......@@ -1246,6 +1246,16 @@ static int hwif_init(ide_hwif_t *hwif)
if (register_blkdev(hwif->major, hwif->name))
return 0;
if (!hwif->sg_max_nents)
hwif->sg_max_nents = PRD_ENTRIES;
hwif->sg_table = kmalloc(sizeof(struct scatterlist)*hwif->sg_max_nents,
GFP_KERNEL);
if (!hwif->sg_table) {
printk(KERN_ERR "%s: unable to allocate SG table.\n", hwif->name);
goto out;
}
if (alloc_disks(hwif) < 0)
goto out;
......
......@@ -712,6 +712,8 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
hwif->INSW = tmp_hwif->INSW;
hwif->INSL = tmp_hwif->INSL;
hwif->sg_max_nents = tmp_hwif->sg_max_nents;
hwif->mmio = tmp_hwif->mmio;
hwif->rqsize = tmp_hwif->rqsize;
hwif->no_lba48 = tmp_hwif->no_lba48;
......@@ -900,6 +902,7 @@ void ide_unregister(unsigned int index)
hwif->drives[i].disk = NULL;
put_disk(disk);
}
kfree(hwif->sg_table);
unregister_blkdev(hwif->major, hwif->name);
spin_lock_irq(&ide_lock);
......
......@@ -404,11 +404,7 @@ ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
if (!hwif->dmatable_cpu)
goto dma_alloc_failure;
hwif->sg_table =
kmalloc(sizeof (struct scatterlist) * IOC4_PRD_ENTRIES, GFP_KERNEL);
if (!hwif->sg_table)
goto dma_sgalloc_failure;
hwif->sg_max_nents = IOC4_PRD_ENTRIES;
hwif->dma_base2 = (unsigned long)
pci_alloc_consistent(hwif->pci_dev,
......@@ -421,9 +417,6 @@ ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
return;
dma_base2alloc_failure:
kfree(hwif->sg_table);
dma_sgalloc_failure:
pci_free_consistent(hwif->pci_dev,
IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
hwif->dmatable_cpu, hwif->dmatable_dma);
......
......@@ -1241,6 +1241,8 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
hwif->noprobe = 0;
#endif /* CONFIG_PMAC_PBOOK */
hwif->sg_max_nents = MAX_DCMDS;
#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
/* has a DBDMA controller channel */
if (pmif->dma_regs)
......@@ -2064,14 +2066,6 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
return;
}
hwif->sg_table = kmalloc(sizeof(struct scatterlist) * MAX_DCMDS,
GFP_KERNEL);
if (hwif->sg_table == NULL) {
pci_free_consistent( hwif->pci_dev,
(MAX_DCMDS + 2) * sizeof(struct dbdma_cmd),
pmif->dma_table_cpu, hwif->dmatable_dma);
return;
}
hwif->ide_dma_off_quietly = &__ide_dma_off_quietly;
hwif->ide_dma_on = &__ide_dma_on;
hwif->ide_dma_check = &pmac_ide_dma_check;
......
......@@ -920,6 +920,7 @@ typedef struct hwif_s {
dma_addr_t dmatable_dma;
/* Scatter-gather list used to build the above */
struct scatterlist *sg_table;
int sg_max_nents; /* Maximum number of entries in it */
int sg_nents; /* Current number of entries in it */
int sg_dma_direction; /* dma transfer direction */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment