From owner-freebsd-drivers@FreeBSD.ORG Mon Oct 13 14:57:35 2014 Return-Path: Delivered-To: freebsd-drivers@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 162535C7 for ; Mon, 13 Oct 2014 14:57:35 +0000 (UTC) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) (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 D5E07E4C for ; Mon, 13 Oct 2014 14:57:34 +0000 (UTC) Received: by mail-pd0-f170.google.com with SMTP id p10so5777108pdj.15 for ; Mon, 13 Oct 2014 07:57:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:content-type:mime-version:subject:from :in-reply-to:date:cc:message-id:references:to; bh=hThUuOmJBfqCnnFUFdGJ8k1qBQERv+rOtd6RBfsZdvE=; b=WM+npBp6FUZgUheZOa2P1HcBMatDngxksjp8cMWzhqpouAnmG5qt4GgBX/7sxpdLKM PxylGhXOVeEj2G7nnrTcYSwpUbxkn3lN5utfkTnlpz4kGMaNV+K1DhaR+5ipuZjSD9fG wel/kVNsEDBCUznlhZjyNAOZ/F4gdaoeP0KZUELHp/oDHYH8yk0n4S2x1QnxC9vMzfr/ E2wncuuOoXgIJg5vjMH+03bSOt3ZzXUc5U1KovLfZQHZ+yLfY+levbyneA2LeWmLbycV FKhT3t8Epbh8hUTAQevpAAXyT1Sdnvl7dl1wdd+JLV8g4XuQxQqxxTczEpbjUXGip/Qr wxKw== X-Gm-Message-State: ALoCoQmw0cn2dqReLR6fJhby2xX2K5G9Fv7XtrTvaH43McG0uG8aTETngwhgCyDlLia1GOEVs3LO X-Received: by 10.70.130.136 with SMTP id oe8mr24063394pdb.18.1413212248404; Mon, 13 Oct 2014 07:57:28 -0700 (PDT) Received: from [10.64.26.87] (dc1-prod.netflix.com. [69.53.236.251]) by mx.google.com with ESMTPSA id z13sm11417281pbt.74.2014.10.13.07.57.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 07:57:27 -0700 (PDT) Sender: Warner Losh Content-Type: multipart/signed; boundary="Apple-Mail=_5C375B95-34D5-468C-8AAB-B190D7984D7E"; protocol="application/pgp-signature"; micalg=pgp-sha512 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: A few questions about SD/MMC drivers From: Warner Losh In-Reply-To: Date: Mon, 13 Oct 2014 08:57:25 -0600 Message-Id: <0B7F1C7B-7E38-48FD-B3CF-A4512A45E4C0@bsdimp.com> References: <20141006171521.GD26076@kib.kiev.ua> To: Martin Galvan X-Mailer: Apple Mail (2.1878.6) 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 14:57:35 -0000 --Apple-Mail=_5C375B95-34D5-468C-8AAB-B190D7984D7E Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii On Oct 12, 2014, at 11:24 PM, 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. see busdma(8) for all your DMA needs. It also takes care of situations where bounce buffers are needed, returning properly aligned memory, etc. > 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. Warner --Apple-Mail=_5C375B95-34D5-468C-8AAB-B190D7984D7E Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJUO+hVAAoJEGwc0Sh9sBEAxK8QAKrCbArDptS8Zd70zY3wah/L mmii/TgD2aOE/lcB1weJB57lK/2uyRD9EKUOXI4v/TN13mPcUQ9Fo8uaSHSxY8wg NVjiaCmvKHHwB9eQG12SbGnXbcc/ZwY5s8IU58wEC662OEkXShXyUfIOxc+hl1GJ wtIzjS1GQ33WfsgCjhYYMzOIgD04thAhomdrowzo+deWHD7QtOjsiPqn12+OhJdG QDjcSy1+0Z1TA4KtB7hvZR5uDBaSlksGabYzPfPY96yZnfK4ybJSkGRMmKLWpT69 NEgSJ19Fju8egG5tF04Oj2JMV7Retwff5nhA84YFaL0nswY1VxGsT9CdEmyAZq9N 1+l4cMxI01YS2fZRkYdFCzWYO5J42vMqPXoI7+iNfe2QUPIT5fp8XLJdkoyE8Jpo fLg9tGrI+yH8qQq5I31FHG//htSibgG9uUiX57UL6PbVixHANhmkiA3l77/1CpnD 896fs/Den3o1lUSk/eQEa4sJ9ioiyXuOhvykfU2Obpl7IoQ6KwFgLvBOmjgXdNs/ OMXre0F/w7RRFfZ0z8tfEbl7A1gEIox6+oQyTNUP62xit2hrrdizarqy7hPDHdye DGWmgcjLbMGhu3mmOyralyCguJifm+Tuvpr8c6EIFllQrjWcxvP41qalKB+hoM2p xJDJC03VUTUM01kD5GSl =dF3R -----END PGP SIGNATURE----- --Apple-Mail=_5C375B95-34D5-468C-8AAB-B190D7984D7E--