From owner-freebsd-drivers@FreeBSD.ORG Mon Oct 13 23:25:36 2014 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 96040593; Mon, 13 Oct 2014 23:25:36 +0000 (UTC) Received: from mail-oi0-x231.google.com (mail-oi0-x231.google.com [IPv6:2607:f8b0:4003:c06::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5576EFD6; Mon, 13 Oct 2014 23:25:36 +0000 (UTC) Received: by mail-oi0-f49.google.com with SMTP id a3so14424594oib.8 for ; Mon, 13 Oct 2014 16:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=0R+2P5F54HpR/to7EogwN75vk1D5W2Gquxuanq4K+XE=; b=lSHl6J9vyDiASkeMHfKi4tibdwQBu01LniS40mzT72/nrB5LAOFG4Ho1bAO0geiuCn rDK/1cwGe2qEHzppktXIM6RXmkPoeVMX46GosBQxNmHpECYHP4A0M5hlDMYM3f/Rir8c POTEJKg/pqWubaibxSv68RMcmoTcmvDvtBJkRrfzBXxz0Zdu/r42eF3n67Eo9K8BvFgb 859Bce3OSG+c2F987FVUkNVv0XpD7+3kR6XHMRsiUR1rypBeLsF6fy0xHGN4Nmap4NU5 aNGG/JKxJLapIfvdL0XrOjYGVavrAynVamKBvzzDcnyiByQAUzglnyapkJYN6fo8gvBn GTjA== MIME-Version: 1.0 X-Received: by 10.202.194.67 with SMTP id s64mr1308404oif.22.1413242735697; Mon, 13 Oct 2014 16:25:35 -0700 (PDT) Received: by 10.60.118.196 with HTTP; Mon, 13 Oct 2014 16:25:35 -0700 (PDT) In-Reply-To: <0B7F1C7B-7E38-48FD-B3CF-A4512A45E4C0@bsdimp.com> References: <20141006171521.GD26076@kib.kiev.ua> <0B7F1C7B-7E38-48FD-B3CF-A4512A45E4C0@bsdimp.com> Date: Mon, 13 Oct 2014 20:25:35 -0300 Message-ID: Subject: Re: A few questions about SD/MMC drivers From: Martin Galvan To: Warner Losh Content-Type: text/plain; charset=UTF-8 Cc: freebsd-drivers@freebsd.org, freebsd-embedded@freebsd.org X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2014 23:25:36 -0000 2014-10-13 11:57 GMT-03:00 Warner Losh : > On Oct 12, 2014, at 11:24 PM, Martin Galvan wrote: >> 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? > > Pretty much all of that is covered in busdma(8). The mechanics are a bit > different than Linux, sure, but all that functionality is there. Actually, other than being able to alloc DMA buffers and get their bus addresses I didn't see anything like the Linux scatterlists. The main problem here is that the Linux mmc_data struct comes with an already-filled scatterlist. In that case, all I have to do is build the descriptor chain with the buffer addresses from the scatterlist entries. The only thing that's similar to that in the BSD API is mbuf_sg, which is used for network stuff. I didn't see anything that could allow me to build a descriptor chain-- all I saw was that the BSD mmc_data type has a buffer instead of a scatterlist. I'm thinking of telling the DMA controller to work with a single descriptor whose buffer is the one that comes inside mmc_data, but I'm not sure if this would be right. Again thanks a lot for your answers.