From 162aa2bca3010f84f734016cec915f0eea7f748c Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Tue, 19 Oct 2004 23:46:59 +0200 Subject: [PATCH] [ide] add sg_init_one() helper and teach ide about it Signed-off-by: Bartlomiej Zolnierkiewicz --- arch/cris/arch-v10/drivers/ide.c | 8 ++------ drivers/ide/arm/icside.c | 6 ++---- drivers/ide/ide-dma.c | 11 +++-------- drivers/ide/ppc/pmac.c | 11 +++-------- include/linux/scatterlist.h | 14 ++++++++++++++ 5 files changed, 24 insertions(+), 26 deletions(-) create mode 100644 include/linux/scatterlist.h diff --git a/arch/cris/arch-v10/drivers/ide.c b/arch/cris/arch-v10/drivers/ide.c index 335473c453cf0..32ded35c63a75 100644 --- a/arch/cris/arch-v10/drivers/ide.c +++ b/arch/cris/arch-v10/drivers/ide.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -624,12 +625,7 @@ static int e100_ide_build_dmatable (ide_drive_t *drive) ata_tot_size = 0; if (HWGROUP(drive)->rq->flags & REQ_DRIVE_TASKFILE) { - u8 *virt_addr = rq->buffer; - int sector_count = rq->nr_sectors; - memset(&sg[0], 0, sizeof(*sg)); - sg[0].page = virt_to_page(virt_addr); - sg[0].offset = offset_in_page(virt_addr); - sg[0].length = sector_count * SECTOR_SIZE; + sg_init_one(&sg[0], rq->buffer, rq->nr_sectors * SECTOR_SIZE); hwif->sg_nents = i = 1; } else diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c index edc9de7801651..dde480e55099e 100644 --- a/drivers/ide/arm/icside.c +++ b/drivers/ide/arm/icside.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -223,10 +224,7 @@ static void icside_build_sglist(ide_drive_t *drive, struct request *rq) else hwif->sg_dma_direction = DMA_FROM_DEVICE; - memset(sg, 0, sizeof(*sg)); - sg->page = virt_to_page(rq->buffer); - sg->offset = offset_in_page(rq->buffer); - sg->length = rq->nr_sectors * SECTOR_SIZE; + sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE); nents = 1; } else { nents = blk_rq_map_sg(drive->queue, rq, sg); diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c index cd32057b53a97..dd7cabd1834bd 100644 --- a/drivers/ide/ide-dma.c +++ b/drivers/ide/ide-dma.c @@ -85,6 +85,7 @@ #include #include #include +#include #include #include @@ -253,18 +254,12 @@ int ide_raw_build_sglist(ide_drive_t *drive, struct request *rq) #else while (sector_count > 128) { #endif - memset(&sg[nents], 0, sizeof(*sg)); - sg[nents].page = virt_to_page(virt_addr); - sg[nents].offset = offset_in_page(virt_addr); - sg[nents].length = 128 * SECTOR_SIZE; + sg_init_one(&sg[nents], virt_addr, 128 * SECTOR_SIZE); nents++; virt_addr = virt_addr + (128 * SECTOR_SIZE); sector_count -= 128; } - memset(&sg[nents], 0, sizeof(*sg)); - sg[nents].page = virt_to_page(virt_addr); - sg[nents].offset = offset_in_page(virt_addr); - sg[nents].length = sector_count * SECTOR_SIZE; + sg_init_one(&sg[nents], virt_addr, sector_count * SECTOR_SIZE); nents++; return pci_map_sg(hwif->pci_dev, sg, nents, hwif->sg_dma_direction); diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c index 3625e38a7dced..fabbdef2ee101 100644 --- a/drivers/ide/ppc/pmac.c +++ b/drivers/ide/ppc/pmac.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -1604,18 +1605,12 @@ pmac_ide_raw_build_sglist(ide_drive_t *drive, struct request *rq) pmif->sg_dma_direction = PCI_DMA_FROMDEVICE; if (sector_count > 128) { - memset(&sg[nents], 0, sizeof(*sg)); - sg[nents].page = virt_to_page(virt_addr); - sg[nents].offset = offset_in_page(virt_addr); - sg[nents].length = 128 * SECTOR_SIZE; + sg_init_one(&sg[nents], virt_addr, 128 * SECTOR_SIZE); nents++; virt_addr = virt_addr + (128 * SECTOR_SIZE); sector_count -= 128; } - memset(&sg[nents], 0, sizeof(*sg)); - sg[nents].page = virt_to_page(virt_addr); - sg[nents].offset = offset_in_page(virt_addr); - sg[nents].length = sector_count * SECTOR_SIZE; + sg_init_one(&sg[nents], virt_addr, sector_count * SECTOR_SIZE); nents++; return pci_map_sg(hwif->pci_dev, sg, nents, pmif->sg_dma_direction); diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h new file mode 100644 index 0000000000000..7f717e95ae377 --- /dev/null +++ b/include/linux/scatterlist.h @@ -0,0 +1,14 @@ +#ifndef _LINUX_SCATTERLIST_H +#define _LINUX_SCATTERLIST_H + +static inline void sg_init_one(struct scatterlist *sg, + u8 *buf, unsigned int buflen) +{ + memset(sg, 0, sizeof(*sg)); + + sg->page = virt_to_page(buf); + sg->offset = offset_in_page(buf); + sg->length = buflen; +} + +#endif /* _LINUX_SCATTERLIST_H */ -- 2.53.0