From owner-p4-projects@FreeBSD.ORG Fri Jul 21 18:37:56 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1AE9116A4E1; Fri, 21 Jul 2006 18:37:56 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E960916A4DE; Fri, 21 Jul 2006 18:37:55 +0000 (UTC) (envelope-from sam@errno.com) Received: from ebb.errno.com (ebb.errno.com [69.12.149.25]) by mx1.FreeBSD.org (Postfix) with ESMTP id 691A343D58; Fri, 21 Jul 2006 18:37:55 +0000 (GMT) (envelope-from sam@errno.com) Received: from [10.0.0.248] (trouble.errno.com [10.0.0.248]) (authenticated bits=0) by ebb.errno.com (8.13.6/8.12.6) with ESMTP id k6LIbsSX058431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 21 Jul 2006 11:37:55 -0700 (PDT) (envelope-from sam@errno.com) Message-ID: <44C11F02.10404@errno.com> Date: Fri, 21 Jul 2006 11:37:54 -0700 From: Sam Leffler User-Agent: Thunderbird 1.5.0.2 (X11/20060508) MIME-Version: 1.0 To: Hans Petter Selasky References: <200607211829.k6LITQRA092758@repoman.freebsd.org> In-Reply-To: <200607211829.k6LITQRA092758@repoman.freebsd.org> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Perforce Change Reviews Subject: Re: PERFORCE change 102068 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jul 2006 18:37:56 -0000 Hans Petter Selasky wrote: > http://perforce.freebsd.org/chv.cgi?CH=102068 > > Change 102068 by hselasky@hselasky_mini_itx on 2006/07/21 18:29:01 > > Added new functions, usbd_m_copy_in, usbd_do_request_mtx and > usbd_do_request_flags_mtx. > > Affected files ... > > .. //depot/projects/usb/src/sys/dev/usb/usb_subr.c#8 edit > .. //depot/projects/usb/src/sys/dev/usb/usb_subr.h#12 edit > .. //depot/projects/usb/src/sys/dev/usb/usb_transfer.c#9 edit > > Differences ... > > ==== //depot/projects/usb/src/sys/dev/usb/usb_subr.c#8 (text+ko) ==== > > @@ -43,6 +43,7 @@ > #include /* LIST_XXX() */ > #include > #include > +#include > > #include > #include > @@ -1680,6 +1681,42 @@ > return; > } > > + > +/*---------------------------------------------------------------------------* > + * usbd_m_copy_in - copy a mbuf chain directly to DMA-able memory > + *---------------------------------------------------------------------------*/ > +void > +usbd_m_copy_in(struct usbd_page_cache *cache, u_int32_t dst_offset, > + struct mbuf *m, u_int32_t src_offset, u_int32_t src_len) > +{ > + u_int32_t count; > + > + while (src_offset > 0) { > + __KASSERT(m != NULL, ("usbd_m_copy_in, offset > " > + "size of mbuf chain")); > + if (src_offset < m->m_len) { > + break; > + } > + src_offset -= m->m_len; > + m = m->m_next; > + } > + > + while (src_len > 0) { > + __KASSERT(m != NULL, ("usbd_m_copy_in, length > " > + "size of mbuf chain")); > + count = min(m->m_len - src_offset, src_len); > + > + usbd_copy_in(cache, dst_offset, ((caddr_t)(m->m_data)) + > + src_offset, count); > + > + src_len -= count; > + dst_offset += count; > + src_offset = 0; > + m = m->m_next; > + } > + return; > +} FWIW you can also do this with m_apply: struct usbd_arg { struct usbd_page_cache *cache; u_int32_t dst_offset; }; static int usbd_cb(void *arg, void *src, u_int count) { struct usbd_arg *ua = arg; usbd_copy_in(ua->cache, ua->dst_offset, src, count); ua->dst_offset += count; return 0; } struct usbd_arg arg = { cache, dst_offset }; m_apply(m, m, src_offset, src_len, usbd_cb, &arg); You might also look at the various assertion checks and such in m_apply if you decide not to go this route. Sam