From owner-freebsd-arch Wed Feb 13 1:46:25 2002 Delivered-To: freebsd-arch@freebsd.org Received: from albatross.prod.itd.earthlink.net (albatross.mail.pas.earthlink.net [207.217.120.120]) by hub.freebsd.org (Postfix) with ESMTP id 1336E37B417 for ; Wed, 13 Feb 2002 01:46:21 -0800 (PST) Received: from pool0136.cvx21-bradley.dialup.earthlink.net ([209.179.192.136] helo=mindspring.com) by albatross.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16avzS-0000MW-00; Wed, 13 Feb 2002 01:46:14 -0800 Message-ID: <3C6A35DC.F03DC26A@mindspring.com> Date: Wed, 13 Feb 2002 01:46:04 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: mike varga Cc: Steve Kargl , freebsd-arch@freebsd.org Subject: Re: bus_dma_load_uio() function References: <00d401c1b428$e4929df0$b210a8c0@netscreen5> <20020212172445.A85182@troutmask.apl.washington.edu> <000701c1b42e$7835eda0$b210a8c0@netscreen5> Content-Type: text/plain; charset=us-ascii 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 mike varga wrote: > My question essentially > boils down to,"How do you > map and lock user pages (buffers) > for use in a driver that wants > to do a DMA directly > from/to them. > > It removes unnecessary > copies. Hi, Mike. Normally, this type of copy elimination is done, not by taking user pages and making them available to the driver, but by taking driver pages, and making them available to the user space program. There are a lot of ways to do this, but it normally depends on how you intend to do the accesses. If your driver has a device node, the simplest way is to allocate a memory region when the driver is instanced, and then use mmap() on the device itself to map the pages into the user space program. This has the usually desirable side effect of making the memory access controls equal to the driver enforced access controls on the open. There are a number of drivers, such as the bktr and other capture cards, as well as the linear frame buffer devices. See also /dev/agpgart. Another alternative is to use System V shared memory, which is implemented as a KVA space allocation which gets mapped into the user process address space as a result of the attach. This memory is wired down, and it also will not move out from under you while you are using it. You can use this approach by making a single call to the driver to identify the shared memory segment to it, and then use relative addressing in both user and kernel space to end up with invariant pointers relative to the base address (which will be different in kernel and user space). If you are building a special purpose embedded system, rather than a just a driver for use in a general purpose system, then there are other ways to make the code faster that involve giving up some of the guarantees that you normally get from a protected mode OS. My personal suggestion, given what I know of your intended application, would be to use the first approach. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message