Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB838C63793 for ; Thu, 22 Jul 2021 08:07:02 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C0CF961283 for ; Thu, 22 Jul 2021 08:07:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0CF961283 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=etri.re.kr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1m6Tj0-0007ub-Cw; Thu, 22 Jul 2021 04:06:34 -0400 Received: from mscreen.etri.re.kr ([129.254.9.16]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (Exim 4.94.2) (envelope-from ) id 1m6Tiy-0007uV-EB for kernelnewbies@kernelnewbies.org; Thu, 22 Jul 2021 04:06:33 -0400 Received: from unknown (HELO send002-relay.gov-dooray.com) (211.180.235.153) by 129.254.9.16 with ESMTP; 22 Jul 2021 17:06:25 +0900 X-Original-SENDERIP: 211.180.235.153 X-Original-MAILFROM: ckim@etri.re.kr X-Original-RCPTTO: kernelnewbies@kernelnewbies.org Received: from [10.162.225.112] (HELO smtp002-imp.gov-dooray.com) ([10.162.225.112]) by send002-relay.gov-dooray.com with SMTP id 8cc09c0c60f92701; Thu, 22 Jul 2021 17:06:25 +0900 DKIM-Signature: a=rsa-sha256; b=ZIuJOPWgJJTRCRT+mQvdJB0XwOXf4CYM2f5ZQy6OOIxjuN6sElhfjYgkpdU4gG2is9oMY0dgHQ Gw+8zOlZI+ZQtZzNa3BgtYRX7kJVtTLNgWuNGHYAFxlGApTX35AI0Nj69cFnUxDWBNu/NqJC/cCl dvok0GS77yk6nXKjAeAV4OKWfLaybwV7KmvbUPZz7XKlmoJ+djKInwtwLNfdj104lHR2FAmB97zo +u1atf+v87PUwXG9uJEDo6p/ubWotIB5ucVX38V6GY69ng8NiypOrZcLtIHmYGf2gdWky8w4NeVc 49iV+GvE3slva2xQ2Mppb4hmNpkSLqClpRL9vAAQ==; c=relaxed/relaxed; s=selector; d=dooray.com; v=1; bh=PNeVRtQmf/kPDp3/0LHSVwMGIwtrmCbOcpf/xONd7Y0=; h=From:To:Subject:Message-ID; Received: from [129.254.132.39] (HELO CHANKIMPC) ([129.254.132.39]) by smtp002-imp.gov-dooray.com with SMTP id 3b15b5ea60f92701; Thu, 22 Jul 2021 17:06:25 +0900 From: To: References: In-Reply-To: Subject: RE: a question about dma_set_mask function Date: Thu, 22 Jul 2021 17:06:24 +0900 Message-ID: <00cc01d77ed0$77006190$650124b0$@etri.re.kr> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 thread-index: AQGG8QaC2kDN5ouYAblFhCOovyjTAqvvu47w Content-Language: ko X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============6373152565182363740==" Errors-To: kernelnewbies-bounces@kernelnewbies.org This is a multipart message in MIME format. --===============6373152565182363740== Content-Type: multipart/alternative; boundary="----=_NextPart_000_00CD_01D77F1B.E6E8CCE0" Content-Language: ko This is a multipart message in MIME format. ------=_NextPart_000_00CD_01D77F1B.E6E8CCE0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Further reading down the document, I realized the returned DMA address (=bus address) is used for setting the dma descriptors or the device register so that the address value is used for actual DMA. But I'm still confused for cases of using iommu. When the iommu exists for the device, does the dma_alloc function allocates virtual address range (which can be physically dis-contiguous) instead of the (physically contiguous) bus address? I mean, will the handle value below be pointing to virtual address for {this process and the device} pair? (virtual to bus address translation being done by iommu). dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp) Any help will be really appreciated. Thanks! Chan Kim From: ckim@etri.re.kr Sent: Thursday, July 22, 2021 4:33 PM To: kernelnewbies@kernelnewbies.org Subject: a question about dma_set_mask function Hello, I have a question about DNA (I was reading DMA-API-HOWTO.txt ). You know regarding DMA, there is cpu virtual address, cpu physical address and bus address for the device. Bus address is converted to cpu physical address using bridge or bus controller to which the device is attached. And for platform device, bus address is equal to the cpu physical address. The DMA-API-HOWTO.txt says > When dma_set_mask() or dma_set_mask_and_coherent() is successful, and > returns zero, the kernel saves away this mask you have provided. The > kernel will use this information later when you make DMA mappings. So I guess when the driver later requests memory for dma using dma_map_..(ex. dma_map_single, or dma_map_sg) function, the kernel allocates memory and sets up page table and it sets the bus address in the ranges supported by the dma_mask. The virtual address is returned by the function, but where is this 'bus address' kept? I see a pointer to the struct page in the function argument, Is it kept in this struct array? Or is the bus address just the physical address(pfn) in the page table?(I guess so) And when the device has a separate iommu(like arm64's SMMU), I guess the DMA virtual address (assigned for dma by the kernel) for the device is first converted to the bus address by iommu and then the bus address is converted to physical address by bus bridge. Is my understanding correct? It's so confusing.. Any explanation or comment will be deeply appreciated. Thanks! Chan Kim ------=_NextPart_000_00CD_01D77F1B.E6E8CCE0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

 

Further reading down the document, = I realized the returned DMA address (=3Dbus address) is used for setting = the dma descriptors or the device register so that the address value is = used for actual DMA.

But I’m still confused for cases of using iommu. =

When the = iommu exists for the device, does the dma_alloc function allocates = virtual address range (which can be physically dis-contiguous) instead = of the (physically contiguous) bus address?

I mean, will the handle value below = be pointing to virtual address for {this process and the device} pair? = (virtual to bus address translation being done by = iommu).

dma_alloc_coherent(struct device *dev, size_t size, = dma_addr_t *handle, gfp_t gfp)

Any help will be really = appreciated.

Thanks!

Chan Kim

 

From:<= /b> = ckim@etri.re.kr <ckim@etri.re.kr>
Sent: Thursday, July = 22, 2021 4:33 PM
To: = kernelnewbies@kernelnewbies.org
Subject: a question about = dma_set_mask function

 

Hello,

 

I have a question about DNA (I was reading DMA-A= PI-HOWTO.txt ).

You know regarding DMA, there is cpu virtual address, cpu = physical address and bus address for the device. =

Bus = address is converted to cpu physical address using bridge or bus = controller to which the device is attached.

And for platform device, bus = address is equal to the cpu physical address.

 

The DMA-A= PI-HOWTO.txt says

 

> When dma_set_mask() or dma_set_mask_and_coherent() is = successful, and

> returns zero, the kernel saves away this mask you have = provided.  The

> kernel will use this information later when you make = DMA mappings.

 

So I guess when the driver later requests memory for dma = using dma_map_..(ex. dma_map_single, or dma_map_sg) function, =

the kernel = allocates memory and sets up page table and it sets the bus address in = the ranges supported by the dma_mask.

The virtual address is returned by = the function, but where is this ‘bus = address’ kept? I see a pointer to the = struct page in the function argument, Is it kept in this struct array? = Or is the bus address just the physical address(pfn) in the page = table?(I guess so)

And when the device has a separate iommu(like = arm64’s SMMU), I guess the DMA virtual = address (assigned for dma by the kernel) for the device is first = converted to the bus address by iommu and then the bus address is = converted to physical address by bus bridge. Is my understanding = correct?

It’s so confusing.. Any = explanation or comment will be deeply = appreciated.

Thanks!

 

Chan Kim

 

 

 

------=_NextPart_000_00CD_01D77F1B.E6E8CCE0-- --===============6373152565182363740== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============6373152565182363740==--