From owner-freebsd-embedded@FreeBSD.ORG Mon Oct 13 14:21:42 2014 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9327EC1B; Mon, 13 Oct 2014 14:21:42 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F01A0B13; Mon, 13 Oct 2014 14:21:41 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id s9DELWlq051238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 13 Oct 2014 17:21:32 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua s9DELWlq051238 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id s9DELWYi051237; Mon, 13 Oct 2014 17:21:32 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 13 Oct 2014 17:21:32 +0300 From: Konstantin Belousov To: Martin Galvan Subject: Re: A few questions about SD/MMC drivers Message-ID: <20141013142132.GN2153@kib.kiev.ua> References: <20141006171521.GD26076@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: freebsd-drivers@freebsd.org, freebsd-embedded@freebsd.org X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2014 14:21:42 -0000 On Mon, Oct 13, 2014 at 02:24:52AM -0300, Martin Galvan wrote: > Hi again! I'm in the middle of implementing DMA support for the > Allwinner driver, and I was surprised to see that BSD doesn't have a > simple DMA API as Linux does. Namely, I didn't see anything like the > scatterlists used in Linux. > > The host found in Allwinner SoCs uses a DMA controller which works > with a linked list of descriptors, each having info on a data buffer. > In the Linux driver they allocate a coherent DMA buffer using > dma_alloc_coherent to get both the virtual and bus addresses of the > descriptor list. When it's time to do a DMA transfer, the Linux driver > allocates a scatterlist with each entry being a buffer corresponding > to a descriptor; it then loops through the descriptor list setting the > "buffer pointer" field of each one to the bus address of the > corresponding scatterlist entry, and the "next descriptor" to the bus > address of the following descriptor. It's pretty neat, though it's > worth mentioning the scatterlist that the MMC request handler maps > already contains the virtual addresses of the requested buffers. > > Do we have anything like that on BSD? If not, what would be a simple > algorithm to make this work? I am not sure about the scope of your question. Are you aware of busdma(9) ? This is the KPI to use for DMA programming on *BSD, and it is typically enough for most hardware. If you do know about busdma(9) and do not consider it not suitable for the task, this is completely different situation, and you should describe why.