From owner-p4-projects@FreeBSD.ORG Fri Nov 14 18:20:36 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1AB7E106568E; Fri, 14 Nov 2008 18:20:36 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D1D471065689 for ; Fri, 14 Nov 2008 18:20:35 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from cmail.optima.ua (cmail.optima.ua [195.248.191.121]) by mx1.freebsd.org (Postfix) with ESMTP id 61F178FC12 for ; Fri, 14 Nov 2008 18:20:35 +0000 (UTC) (envelope-from mav@FreeBSD.org) X-Spam-Flag: SKIP X-Spam-Yversion: Spamooborona-2.1.0 Received: from [212.86.226.226] (account mav@alkar.net HELO mavbook.mavhome.dp.ua) by cmail.optima.ua (CommuniGate Pro SMTP 5.2.9) with ESMTPSA id 227761763; Fri, 14 Nov 2008 20:20:34 +0200 Message-ID: <491DC170.7090409@FreeBSD.org> Date: Fri, 14 Nov 2008 20:20:32 +0200 From: Alexander Motin User-Agent: Thunderbird 2.0.0.17 (X11/20081029) MIME-Version: 1.0 To: Hans Petter Selasky References: <200811080910.mA89AgTZ048172@repoman.freebsd.org> <200811140915.18846.hselasky@c2i.net> <491D8282.5060506@FreeBSD.org> <200811141644.55773.hselasky@c2i.net> In-Reply-To: <200811141644.55773.hselasky@c2i.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Fri, 14 Nov 2008 18:29:35 +0000 Cc: Perforce Change Reviews Subject: Re: PERFORCE change 152649 for review - busdma problem 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, 14 Nov 2008 18:20:36 -0000 Hans Petter Selasky wrote: > The thing is, you cannot specify how many bytes are on the first page which > can take a full physical address. It is assumed that after the page offset > wraps to zero a new page begins. > > Example: > > xxx: means data > > Virtual memory: > PG0 PG1 > | xxx|xxx | > > In busdma bounce buffer: > > PG0 PG1 > |xxx |xxx | > > You see there is a hole just before PG1, and it is impossible to tell the USB > hardware to skip this hole. I have seen very alike organization at SD host controller. There is SDMA mode, to which most existing controllers limited. There is just initial address and total data size can be specified. But on every page boundary controller stops transfer and allows software to load the address of the next data page. This technique is ugly and new specification provides new ADMA and ADMA2 modes which allow start address and length to be specified for every data segment. Now within my sdhci driver I have implemented page bouncing by myself, I am preallocating one aligned 4K page and reloading it with new data on each page boundary hit. There are many different data alignment bugs/limitations in that controllers, so such unperfect DMA operation also allows me to manage most of them. Linux sdhci driver instead just don't use this page boundary interrupt, operating with only one continuous memory block, completely disabling DMA on buggy controllers. If I understand correctly present busdma API (may be not), it does not allow you to be sure that both of segment boundaries will be aligned to the page boundaries. You are only specifying maximum number of segments and maximum segment size, so busdma, if it wish, may theoretically give you several small segments instead of single complete page. So if you are not ready to receive uneven sized segments, you probably should not specify that you want to receive more then 1 segment. May be it would be good to add some flag to the bus_dma_tag_create() which would signaled that hardware is able to handle segment boundaries only at page boundaries. It would also allow us to properly combine alignment and page boundary requirements. But it is surely not easy task. Correct me please if I am wrong. -- Alexander Motin