From owner-freebsd-arch Wed Jan 29 12:27:14 2003 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4BA1637B401 for ; Wed, 29 Jan 2003 12:27:12 -0800 (PST) Received: from magic.adaptec.com (magic.adaptec.com [208.236.45.80]) by mx1.FreeBSD.org (Postfix) with ESMTP id A15B643F3F for ; Wed, 29 Jan 2003 12:27:11 -0800 (PST) (envelope-from scott_long@btc.adaptec.com) Received: from redfish.adaptec.com (redfish.adaptec.com [162.62.50.11]) by magic.adaptec.com (8.11.6+Sun/8.11.6) with ESMTP id h0TKR3D24897; Wed, 29 Jan 2003 12:27:03 -0800 (PST) Received: from btc.btc.adaptec.com (btc.btc.adaptec.com [10.100.0.52]) by redfish.adaptec.com (8.8.8+Sun/8.8.8) with ESMTP id MAA00538; Wed, 29 Jan 2003 12:26:52 -0800 (PST) Received: from btc.adaptec.com (hollin [10.100.253.56]) by btc.btc.adaptec.com (8.8.8+Sun/8.8.8) with ESMTP id NAA25761; Wed, 29 Jan 2003 13:26:48 -0700 (MST) Message-ID: <3E383846.20308@btc.adaptec.com> Date: Wed, 29 Jan 2003 13:23:34 -0700 From: Scott Long User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.3a) Gecko/20030127 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Hiten Pandya Cc: arch@freebsd.org Subject: Re: bus_dmamem_alloc_size() References: <3E35DE8E.2080706@btc.adaptec.com> <20030129184211.GA70010@unixdaemons.com> In-Reply-To: <20030129184211.GA70010@unixdaemons.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hiten Pandya wrote: > On Mon, Jan 27, 2003 at 06:36:14PM -0700, Scott Long wrote the words in effect of: > >>All, >> >>With the ongoing effort to convert all of our drivers to busdma, it's >>becoming painfully apparrent that bus_dmamem_alloc() needs to >>be able to specify the size of the buffer to create, and not just >>default to the max_size field of the dma tag. The reason is that a >>lot of simple hardware out there do understand scatter-gather lists, >>so any data passed to them must be physically contiguous in a >>single segment. This in turn means that drivers need to allocate a >>single segment buffer via busdma and copy their i/o contents >>into/out of it when talking to the card. These i/o lengths are often >>extremely variable in size. Without the ability to allocate variable >>sized buffers, you're forced to either create a custom dma tag per >>i/o transaction, or pre-allocate a huge chunk up front and do your >>own sub allocations out of it. Both are rather tedious and >>inefficient. >> >>So, how about adding a method called bus_dmamem_alloc_size() >>that takes the normal arguments of bus_dmamem_alloc(), plus an >>allocation size. Driver writers would still be encouraged to be smart >>about memory management since contigmalloc() would still be the >>underlying allocator, and contigmalloc rounds all requests up >>PAGE_SIZE. >> >>Patches to do this are trivial and can be provided on request. If >>I don't hear any arguments against this, I'll commit it this week. >>In case anyone cares, the my motivation for this comes from trying >>to convert the usb driver to busdma. > > > NetBSD had added a size parameter to their bus_dmamem_alloc() at some > point. It was merged from thorpej's branch. We should probably do the > same, but I think this will be a harder/tedious task. > > JFYI. > Cheers. > Well, doing it wasn't that hard (though the sparc64 side of things was horribly tedious). What I probably didn't stress enough in my proposal is that this is just a stop-gap to allow the busdma work to go on. What really needs to happen in for bus_dmamap_load() to learn how to coelesce segments. That way, you define a tag with a max_segs field on 1, pass your data buffer to bus_dmamap_load(), and it does whatever memcpy()'ing or IOMMU magic is neccessary to get it to one physical segment (the same applies to having more than one segment, but it is most relevant with 1). This is the thing that's not very easy to do. I don't have the time or foo right now to do a good job at it. If someone is interested in working on this, it would be very nice to have for 5-STABLE. Things that you would want to consider are 1) sparc64 IOMMU, 2) AGP GART, 3) whatever magic exists for alpha and ia64, 4) how to make this work with PAE on i386. Scott To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message