[patch] 2.3.39: Don't use bounce buffer when not needed (parport)

From: Tim Waugh (twaugh@redhat.com)
Date: Wed Jan 12 2000 - 07:56:27 EST


This patch from Bert De Jonghe avoids a memcpy when it isn't needed.
Since parport_pc.c is used by several architectures, should this be
protected with #ifdef __i386__? I'm not sure if architectures like Sparc
or Alpha have the same DMA limitation.

Tim.
*/

Index: drivers/parport/parport_pc.c
===================================================================
RCS file: /usr/local/src/cvsroot/linux/drivers/parport/parport_pc.c,v
retrieving revision 1.17
diff -u -r1.17 parport_pc.c
--- drivers/parport/parport_pc.c 2000/01/10 12:25:18 1.17
+++ drivers/parport/parport_pc.c 2000/01/12 12:29:08
@@ -549,9 +549,18 @@
 {
         int ret = 0;
         unsigned long dmaflag;
- size_t left = length;
+ size_t left = length;
         const struct parport_pc_private *priv = port->physport->private_data;
 
+ unsigned long dma_addr = virt_to_bus((volatile char *)buf);
+ size_t maxlen = 0x10000; /* max 64k per DMA transfer */
+
+ /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */
+ if ((dma_addr + length) >= 0x1000000L) {
+ maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */
+ dma_addr = virt_to_bus((volatile char *) priv->dma_buf);
+ }
+
         port = port->physport;
 
         /* We don't want to be interrupted every character. */
@@ -566,16 +575,17 @@
 
                 size_t count = left;
 
- if (count > PAGE_SIZE)
- count = PAGE_SIZE;
+ if (count > maxlen)
+ count = maxlen;
 
- memcpy(priv->dma_buf, buf, count);
+ if (maxlen == PAGE_SIZE) /* bounce buffer ! */
+ memcpy(priv->dma_buf, buf, count);
 
                 dmaflag = claim_dma_lock();
                 disable_dma(port->dma);
                 clear_dma_ff(port->dma);
                 set_dma_mode(port->dma, DMA_MODE_WRITE);
- set_dma_addr(port->dma, virt_to_bus((volatile char *) priv->dma_buf));
+ set_dma_addr(port->dma, dma_addr);
                 set_dma_count(port->dma, count);
 
                 /* Set DMA mode */

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jan 15 2000 - 21:00:20 EST