From owner-svn-src-stable-10@freebsd.org Thu Nov 19 09:52:48 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 267A2A32FA9; Thu, 19 Nov 2015 09:52:48 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C6C841B28; Thu, 19 Nov 2015 09:52:47 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAJ9qk4Z090046; Thu, 19 Nov 2015 09:52:46 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAJ9qkxt090044; Thu, 19 Nov 2015 09:52:46 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201511190952.tAJ9qkxt090044@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 19 Nov 2015 09:52:46 +0000 (UTC) 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 X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Nov 2015 09:52:48 -0000 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_ */