0

I'm writing a linux driver and to store the frames into the RAM I used the function dma_alloc_coherent(struct device *dev, size_t size,dma_addr_t *dma_handle, gfp_t flag). The first physical address of that area it's returned by the function (dma_handle) (in my case in the first half part of the area there is the luma pixels), but I need also the first physical address of the second half of that area. How can I get the physical address and than convert to virtual? (I don't know if I can do something like this to get the others physical addresses: dma_handle + offset)

MrPromethee
  • 721
  • 9
  • 18
Andrea
  • 21
  • 1
  • 7
  • You are messing up a lot of things. First of all DMA address and physical address are different things. Second, `dma_alloc_coherent()` returns a continuous area of mapped address space. It also returns you a virtual address of the area. – 0andriy Jun 12 '19 at 16:54
  • I know that `dma_alloc_coherent ()` returns a continuous memory area (17 MB in my case) and it is precisely for this reason that I use it, the hardware that writes into the ram needs to have a contiguous allocated area and two physical addresses, one for the luma and a second for the chroma. The address for the luma is the `dma_addr_t`, but now I need to obtain the second address. My idea, to obtain the second address, it's to do something like this `dma_addr_t + offset `. – Andrea Jun 13 '19 at 06:39
  • Physical addresses are not coming from `dma_alloc_coherent()`. You have to figure out what exactly your hardware needs. – 0andriy Jun 13 '19 at 06:47
  • Have a look at the dma_to_phys function if that is what you need. – Sanchayan Maity Jun 13 '19 at 08:20
  • 1
    Maybe now I've understood, the hardware needs the physical address of the ram, with physical I mean the address range that I reserved in device tree to the driver. In my case I've reserved 500MB of memory from the address '0x0E000000'. So to the hw I need to pass the address '0x0E000000', that corresponds to the 'dma_addr_t' returned by 'dma_alloc_coherent()'. This is the DMA address, so to get the next DMA addresses I can just use '0x0E000000 + offset'. – Andrea Jun 13 '19 at 09:14
  • No, hardware most likely needs a **bus** address of the RAM, which is returned by `dma_alloc_coherent()`. Physical address of the same chunk of memory may be different (it depends on several factors, such as CPU architecture, presence of IOMMU). – 0andriy Jun 14 '19 at 05:20
  • Now, with this knowledge, you may read a documentation on the hardware to understand if simple offset will work in your case (most likely). – 0andriy Jun 14 '19 at 05:26
  • Does this answer your question? [Get PFN from DMA address (dma\_addr\_t)?](https://stackoverflow.com/questions/59847162/get-pfn-from-dma-address-dma-addr-t) – Marco Bonelli Jan 21 '20 at 23:22

0 Answers0