Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Nov 2015 09:54:28 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r291063 - stable/9/sys/dev/usb
Message-ID:  <201511190954.tAJ9sSqB090265@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu Nov 19 09:54:28 2015
New Revision: 291063
URL: https://svnweb.freebsd.org/changeset/base/291063

Log:
  MFC r290489:
  Add helper function to check if a USB page cache buffer is properly
  aligned to reduce the use of bounce buffers in PIO mode.

Modified:
  stable/9/sys/dev/usb/usb_busdma.c
  stable/9/sys/dev/usb/usb_busdma.h
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/dev/   (props changed)

Modified: stable/9/sys/dev/usb/usb_busdma.c
==============================================================================
--- stable/9/sys/dev/usb/usb_busdma.c	Thu Nov 19 09:52:46 2015	(r291062)
+++ stable/9/sys/dev/usb/usb_busdma.c	Thu Nov 19 09:54:28 2015	(r291063)
@@ -130,6 +130,35 @@ usbd_get_page(struct usb_page_cache *pc,
 }
 
 /*------------------------------------------------------------------------*
+ *  usb_pc_buffer_is_aligned - verify alignment
+ * 
+ * This function is used to check if a page cache buffer is properly
+ * aligned to reduce the use of bounce buffers in PIO mode.
+ *------------------------------------------------------------------------*/
+uint8_t
+usb_pc_buffer_is_aligned(struct usb_page_cache *pc, usb_frlength_t offset,
+    usb_frlength_t len, usb_frlength_t mask)
+{
+	struct usb_page_search buf_res;
+
+	while (len != 0) {
+
+		usbd_get_page(pc, offset, &buf_res);
+
+		if (buf_res.length > len)
+			buf_res.length = len;
+		if (USB_P2U(buf_res.buffer) & mask)
+			return (0);
+		if (buf_res.length & mask)
+			return (0);
+
+		offset += buf_res.length;
+		len -= buf_res.length;
+	}
+	return (1);
+}
+
+/*------------------------------------------------------------------------*
  *  usbd_copy_in - copy directly to DMA-able memory
  *------------------------------------------------------------------------*/
 void

Modified: stable/9/sys/dev/usb/usb_busdma.h
==============================================================================
--- stable/9/sys/dev/usb/usb_busdma.h	Thu Nov 19 09:52:46 2015	(r291062)
+++ stable/9/sys/dev/usb/usb_busdma.h	Thu Nov 19 09:54:28 2015	(r291063)
@@ -157,5 +157,8 @@ void	usb_pc_cpu_flush(struct usb_page_ca
 void	usb_pc_cpu_invalidate(struct usb_page_cache *pc);
 void	usb_pc_dmamap_destroy(struct usb_page_cache *pc);
 void	usb_pc_free_mem(struct usb_page_cache *pc);
+uint8_t	usb_pc_buffer_is_aligned(struct usb_page_cache *pc,
+	    usb_frlength_t offset, usb_frlength_t len,
+	    usb_frlength_t mask);
 
 #endif					/* _USB_BUSDMA_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511190954.tAJ9sSqB090265>