kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* RE: a question about dma_set_mask function
@ 2021-07-22  8:06 ckim
  0 siblings, 0 replies; 2+ messages in thread
From: ckim @ 2021-07-22  8:06 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 2585 bytes --]

 

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 <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
<https://www.kernel.org/doc/Documentation/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
<https://www.kernel.org/doc/Documentation/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

 

 

 


[-- Attachment #1.2: Type: text/html, Size: 7477 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 2+ messages in thread

* a question about dma_set_mask function
@ 2021-07-22  7:33 ckim
  0 siblings, 0 replies; 2+ messages in thread
From: ckim @ 2021-07-22  7:33 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 1661 bytes --]

Hello,

 

I have a question about DNA (I was reading DMA-API-HOWTO.txt
<https://www.kernel.org/doc/Documentation/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
<https://www.kernel.org/doc/Documentation/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

 

 

 


[-- Attachment #1.2: Type: text/html, Size: 4891 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-22  8:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22  8:06 a question about dma_set_mask function ckim
  -- strict thread matches above, loose matches on Subject: below --
2021-07-22  7:33 ckim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).