/* Perform the DMA mapping magic necessary to access the source or target buffers of a request via DMA. The lower layers of the kernel provide the necessary cache management so that we can operate in a portable fashion.  */
static int ide_dma_map_sg(ide_drive_t *drive, struct ide_cmd *cmd)
/* Perform the DMA mapping magic necessary to access the source or target buffers of a request via DMA. The lower layers of the kernel provide the necessary cache management so that we can operate in a portable fashion.  */
static int ide_dma_map_sg(ide_drive_t *drive, struct ide_cmd *cmd)
{
	ide_hwif_t *hwif = drive->hwif;
	struct scatterlist *sg = hwif->sg_table;
	int i;
	if (cmd->tf_flags & IDE_TFLAG_WRITE)
		cmd->sg_dma_direction = DMA_TO_DEVICE;
	else
		cmd->sg_dma_direction = DMA_FROM_DEVICE;
	i = dma_map_sg(hwif->dev, sg, cmd->sg_nents, cmd->sg_dma_direction);
	if (i) {
		cmd->orig_sg_nents = cmd->sg_nents;
		cmd->sg_nents = i;
	}
	return i;
}