diff options
author | hselasky <hselasky@FreeBSD.org> | 2015-11-19 09:52:46 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2015-11-19 09:52:46 +0000 |
commit | 9f1fb5440fcc5f101d26145b486fdf5840f8fa13 (patch) | |
tree | 9347882fd4fa3a8009de503e282b648903e805b1 /sys/dev | |
parent | 1f6525c547353b50e1ffd11e65d8d449602ecc4e (diff) | |
download | FreeBSD-src-9f1fb5440fcc5f101d26145b486fdf5840f8fa13.zip FreeBSD-src-9f1fb5440fcc5f101d26145b486fdf5840f8fa13.tar.gz |
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.
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/usb/usb_busdma.c | 29 | ||||
-rw-r--r-- | sys/dev/usb/usb_busdma.h | 3 |
2 files changed, 32 insertions, 0 deletions
diff --git a/sys/dev/usb/usb_busdma.c b/sys/dev/usb/usb_busdma.c index 08425bf..e7e2f6a 100644 --- a/sys/dev/usb/usb_busdma.c +++ b/sys/dev/usb/usb_busdma.c @@ -134,6 +134,35 @@ usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset, } /*------------------------------------------------------------------------* + * 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 diff --git a/sys/dev/usb/usb_busdma.h b/sys/dev/usb/usb_busdma.h index eee91f3..077bf8b 100644 --- a/sys/dev/usb/usb_busdma.h +++ b/sys/dev/usb/usb_busdma.h @@ -159,5 +159,8 @@ void usb_pc_cpu_flush(struct usb_page_cache *pc); 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_ */ |