patch-2.4.20 linux-2.4.20/drivers/ide/ide-dma.c
Next file: linux-2.4.20/drivers/ide/ide-geometry.c
Previous file: linux-2.4.20/drivers/ide/ide-disk.c
Back to the patch index
Back to the overall index
- Lines: 196
- Date:
Thu Nov 28 15:53:13 2002
- Orig file:
linux-2.4.19/drivers/ide/ide-dma.c
- Orig date:
Fri Aug 2 17:39:44 2002
diff -urN linux-2.4.19/drivers/ide/ide-dma.c linux-2.4.20/drivers/ide/ide-dma.c
@@ -252,33 +252,53 @@
{
struct buffer_head *bh;
struct scatterlist *sg = hwif->sg_table;
+ unsigned long lastdataend = ~0UL;
int nents = 0;
if (hwif->sg_dma_active)
BUG();
-
+
if (rq->cmd == READ)
hwif->sg_dma_direction = PCI_DMA_FROMDEVICE;
else
hwif->sg_dma_direction = PCI_DMA_TODEVICE;
+
bh = rq->bh;
do {
- unsigned char *virt_addr = bh->b_data;
- unsigned int size = bh->b_size;
+ struct scatterlist *sge;
+
+ /*
+ * continue segment from before?
+ */
+ if (bh_phys(bh) == lastdataend) {
+ sg[nents - 1].length += bh->b_size;
+ lastdataend += bh->b_size;
+ continue;
+ }
+ /*
+ * start new segment
+ */
if (nents >= PRD_ENTRIES)
return 0;
- while ((bh = bh->b_reqnext) != NULL) {
- if ((virt_addr + size) != (unsigned char *) bh->b_data)
- break;
- size += bh->b_size;
+ sge = &sg[nents];
+ memset(sge, 0, sizeof(*sge));
+
+ if (bh->b_page) {
+ sge->page = bh->b_page;
+ sge->offset = bh_offset(bh);
+ } else {
+ if (((unsigned long) bh->b_data) < PAGE_SIZE)
+ BUG();
+
+ sge->address = bh->b_data;
}
- memset(&sg[nents], 0, sizeof(*sg));
- sg[nents].address = virt_addr;
- sg[nents].length = size;
+
+ sge->length = bh->b_size;
+ lastdataend = bh_phys(bh) + bh->b_size;
nents++;
- } while (bh != NULL);
+ } while ((bh = bh->b_reqnext) != NULL);
return pci_map_sg(hwif->pci_dev, sg, nents, hwif->sg_dma_direction);
}
@@ -340,7 +360,7 @@
return 0;
sg = HWIF(drive)->sg_table;
- while (i && sg_dma_len(sg)) {
+ while (i) {
u32 cur_addr;
u32 cur_len;
@@ -354,36 +374,35 @@
*/
while (cur_len) {
- if (count++ >= PRD_ENTRIES) {
- printk("%s: DMA table too small\n", drive->name);
- goto use_pio_instead;
- } else {
- u32 xcount, bcount = 0x10000 - (cur_addr & 0xffff);
-
- if (bcount > cur_len)
- bcount = cur_len;
- *table++ = cpu_to_le32(cur_addr);
- xcount = bcount & 0xffff;
- if (is_trm290_chipset)
- xcount = ((xcount >> 2) - 1) << 16;
- if (xcount == 0x0000) {
- /*
- * Most chipsets correctly interpret a length of 0x0000 as 64KB,
- * but at least one (e.g. CS5530) misinterprets it as zero (!).
- * So here we break the 64KB entry into two 32KB entries instead.
- */
- if (count++ >= PRD_ENTRIES) {
- printk("%s: DMA table too small\n", drive->name);
- goto use_pio_instead;
- }
- *table++ = cpu_to_le32(0x8000);
- *table++ = cpu_to_le32(cur_addr + 0x8000);
- xcount = 0x8000;
- }
- *table++ = cpu_to_le32(xcount);
- cur_addr += bcount;
- cur_len -= bcount;
+ u32 xcount, bcount = 0x10000 - (cur_addr & 0xffff);
+
+ if (count++ >= PRD_ENTRIES)
+ BUG();
+
+ if (bcount > cur_len)
+ bcount = cur_len;
+ *table++ = cpu_to_le32(cur_addr);
+ xcount = bcount & 0xffff;
+ if (is_trm290_chipset)
+ xcount = ((xcount >> 2) - 1) << 16;
+ if (xcount == 0x0000) {
+ /*
+ * Most chipsets correctly interpret a length
+ * of 0x0000 as 64KB, but at least one
+ * (e.g. CS5530) misinterprets it as zero (!).
+ * So here we break the 64KB entry into two
+ * 32KB entries instead.
+ */
+ if (count++ >= PRD_ENTRIES)
+ goto use_pio_instead;
+
+ *table++ = cpu_to_le32(0x8000);
+ *table++ = cpu_to_le32(cur_addr + 0x8000);
+ xcount = 0x8000;
}
+ *table++ = cpu_to_le32(xcount);
+ cur_addr += bcount;
+ cur_len -= bcount;
}
sg++;
@@ -584,6 +603,23 @@
}
#endif /* CONFIG_BLK_DEV_IDEDMA_TIMEOUT */
+static inline void ide_toggle_bounce(ide_drive_t *drive, int on)
+{
+ dma64_addr_t addr = BLK_BOUNCE_HIGH;
+
+ if (HWIF(drive)->no_highio || HWIF(drive)->pci_dev == NULL)
+ return;
+
+ if (on && drive->media == ide_disk) {
+ if (!PCI_DMA_BUS_IS_PHYS)
+ addr = BLK_BOUNCE_ANY;
+ else
+ addr = HWIF(drive)->pci_dev->dma_mask;
+ }
+
+ blk_queue_bounce_limit(&drive->queue, addr);
+}
+
/*
* ide_dmaproc() initiates/aborts DMA read/write operations on a drive.
*
@@ -606,18 +642,20 @@
ide_hwif_t *hwif = HWIF(drive);
unsigned long dma_base = hwif->dma_base;
byte unit = (drive->select.b.unit & 0x01);
- unsigned int count, reading = 0;
+ unsigned int count, reading = 0, set_high = 1;
byte dma_stat;
switch (func) {
case ide_dma_off:
printk("%s: DMA disabled\n", drive->name);
case ide_dma_off_quietly:
+ set_high = 0;
outb(inb(dma_base+2) & ~(1<<(5+unit)), dma_base+2);
case ide_dma_on:
drive->using_dma = (func == ide_dma_on);
if (drive->using_dma)
outb(inb(dma_base+2)|(1<<(5+unit)), dma_base+2);
+ ide_toggle_bounce(drive, set_high);
return 0;
case ide_dma_check:
return config_drive_for_dma (drive);
@@ -759,8 +797,8 @@
request_region(dma_base, num_ports, hwif->name);
hwif->dma_base = dma_base;
hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev,
- PRD_ENTRIES * PRD_BYTES,
- &hwif->dmatable_dma);
+ PRD_ENTRIES * PRD_BYTES,
+ &hwif->dmatable_dma);
if (hwif->dmatable_cpu == NULL)
goto dma_alloc_failure;
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)