[ide] add sg_init_one() helper and teach ide about it

Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 2a136606
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/hdreg.h> #include <linux/hdreg.h>
#include <linux/ide.h> #include <linux/ide.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/scatterlist.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/arch/svinto.h> #include <asm/arch/svinto.h>
...@@ -624,12 +625,7 @@ static int e100_ide_build_dmatable (ide_drive_t *drive) ...@@ -624,12 +625,7 @@ static int e100_ide_build_dmatable (ide_drive_t *drive)
ata_tot_size = 0; ata_tot_size = 0;
if (HWGROUP(drive)->rq->flags & REQ_DRIVE_TASKFILE) { if (HWGROUP(drive)->rq->flags & REQ_DRIVE_TASKFILE) {
u8 *virt_addr = rq->buffer; sg_init_one(&sg[0], rq->buffer, rq->nr_sectors * SECTOR_SIZE);
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;
hwif->sg_nents = i = 1; hwif->sg_nents = i = 1;
} }
else else
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/scatterlist.h>
#include <asm/dma.h> #include <asm/dma.h>
#include <asm/ecard.h> #include <asm/ecard.h>
...@@ -223,10 +224,7 @@ static void icside_build_sglist(ide_drive_t *drive, struct request *rq) ...@@ -223,10 +224,7 @@ static void icside_build_sglist(ide_drive_t *drive, struct request *rq)
else else
hwif->sg_dma_direction = DMA_FROM_DEVICE; hwif->sg_dma_direction = DMA_FROM_DEVICE;
memset(sg, 0, sizeof(*sg)); sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
sg->page = virt_to_page(rq->buffer);
sg->offset = offset_in_page(rq->buffer);
sg->length = rq->nr_sectors * SECTOR_SIZE;
nents = 1; nents = 1;
} else { } else {
nents = blk_rq_map_sg(drive->queue, rq, sg); nents = blk_rq_map_sg(drive->queue, rq, sg);
......
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/ide.h> #include <linux/ide.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/scatterlist.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/irq.h> #include <asm/irq.h>
...@@ -253,18 +254,12 @@ int ide_raw_build_sglist(ide_drive_t *drive, struct request *rq) ...@@ -253,18 +254,12 @@ int ide_raw_build_sglist(ide_drive_t *drive, struct request *rq)
#else #else
while (sector_count > 128) { while (sector_count > 128) {
#endif #endif
memset(&sg[nents], 0, sizeof(*sg)); sg_init_one(&sg[nents], virt_addr, 128 * SECTOR_SIZE);
sg[nents].page = virt_to_page(virt_addr);
sg[nents].offset = offset_in_page(virt_addr);
sg[nents].length = 128 * SECTOR_SIZE;
nents++; nents++;
virt_addr = virt_addr + (128 * SECTOR_SIZE); virt_addr = virt_addr + (128 * SECTOR_SIZE);
sector_count -= 128; sector_count -= 128;
} }
memset(&sg[nents], 0, sizeof(*sg)); sg_init_one(&sg[nents], virt_addr, sector_count * SECTOR_SIZE);
sg[nents].page = virt_to_page(virt_addr);
sg[nents].offset = offset_in_page(virt_addr);
sg[nents].length = sector_count * SECTOR_SIZE;
nents++; nents++;
return pci_map_sg(hwif->pci_dev, sg, nents, hwif->sg_dma_direction); return pci_map_sg(hwif->pci_dev, sg, nents, hwif->sg_dma_direction);
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/adb.h> #include <linux/adb.h>
#include <linux/pmu.h> #include <linux/pmu.h>
#include <linux/scatterlist.h>
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -1604,18 +1605,12 @@ pmac_ide_raw_build_sglist(ide_drive_t *drive, struct request *rq) ...@@ -1604,18 +1605,12 @@ pmac_ide_raw_build_sglist(ide_drive_t *drive, struct request *rq)
pmif->sg_dma_direction = PCI_DMA_FROMDEVICE; pmif->sg_dma_direction = PCI_DMA_FROMDEVICE;
if (sector_count > 128) { if (sector_count > 128) {
memset(&sg[nents], 0, sizeof(*sg)); sg_init_one(&sg[nents], virt_addr, 128 * SECTOR_SIZE);
sg[nents].page = virt_to_page(virt_addr);
sg[nents].offset = offset_in_page(virt_addr);
sg[nents].length = 128 * SECTOR_SIZE;
nents++; nents++;
virt_addr = virt_addr + (128 * SECTOR_SIZE); virt_addr = virt_addr + (128 * SECTOR_SIZE);
sector_count -= 128; sector_count -= 128;
} }
memset(&sg[nents], 0, sizeof(*sg)); sg_init_one(&sg[nents], virt_addr, sector_count * SECTOR_SIZE);
sg[nents].page = virt_to_page(virt_addr);
sg[nents].offset = offset_in_page(virt_addr);
sg[nents].length = sector_count * SECTOR_SIZE;
nents++; nents++;
return pci_map_sg(hwif->pci_dev, sg, nents, pmif->sg_dma_direction); return pci_map_sg(hwif->pci_dev, sg, nents, pmif->sg_dma_direction);
......
#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 */
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