Date: Sat, 7 Nov 2015 11:40:35 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290489 - head/sys/dev/usb Message-ID: <201511071140.tA7BeZ01014590@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Sat Nov 7 11:40:35 2015 New Revision: 290489 URL: https://svnweb.freebsd.org/changeset/base/290489 Log: Add helper function to check if a USB page cache buffer is properly aligned to reduce the use of bounce buffers in PIO mode. MFC after: 1 week Modified: head/sys/dev/usb/usb_busdma.c head/sys/dev/usb/usb_busdma.h Modified: head/sys/dev/usb/usb_busdma.c ============================================================================== --- head/sys/dev/usb/usb_busdma.c Sat Nov 7 11:28:25 2015 (r290488) +++ head/sys/dev/usb/usb_busdma.c Sat Nov 7 11:40:35 2015 (r290489) @@ -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: head/sys/dev/usb/usb_busdma.h ============================================================================== --- head/sys/dev/usb/usb_busdma.h Sat Nov 7 11:28:25 2015 (r290488) +++ head/sys/dev/usb/usb_busdma.h Sat Nov 7 11:40:35 2015 (r290489) @@ -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?201511071140.tA7BeZ01014590>