Date: Thu, 19 Nov 2015 09:52:46 +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-10@freebsd.org Subject: svn commit: r291062 - stable/10/sys/dev/usb Message-ID: <201511190952.tAJ9qkxt090044@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Thu Nov 19 09:52:46 2015 New Revision: 291062 URL: https://svnweb.freebsd.org/changeset/base/291062 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/10/sys/dev/usb/usb_busdma.c stable/10/sys/dev/usb/usb_busdma.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/usb/usb_busdma.c ============================================================================== --- stable/10/sys/dev/usb/usb_busdma.c Thu Nov 19 08:04:05 2015 (r291061) +++ stable/10/sys/dev/usb/usb_busdma.c Thu Nov 19 09:52:46 2015 (r291062) @@ -134,6 +134,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/10/sys/dev/usb/usb_busdma.h ============================================================================== --- stable/10/sys/dev/usb/usb_busdma.h Thu Nov 19 08:04:05 2015 (r291061) +++ stable/10/sys/dev/usb/usb_busdma.h Thu Nov 19 09:52:46 2015 (r291062) @@ -159,5 +159,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?201511190952.tAJ9qkxt090044>