ikwzm / udmabuf

User space mappable dma buffer device driver for Linux.
BSD 2-Clause "Simplified" License
539 stars 165 forks source link

dma_alloc_coherent(size=16777216) failed. return(0) #88

Closed azAghaee closed 1 year ago

azAghaee commented 2 years ago

Hi, I'm trying to use u-dma-buffer on my ultra96 board. here is my device tree /include/ "system-conf.dtsi" / { reserved-memory {

address-cells = <2>;

    #size-cells = <2>;
    ranges;
    image_buf0: image_buf@0 {
        compatible = "shared-dma-pool";
        reusable;
        reg = <0x0 0x20000000 0x0 0x01000000>; 
        linux,cma-default;
        label = "image_buf0";
    };
};
udmabuf@0 {
    compatible = "ikwzm,u-dma-buf";
    device-name = "udmabuf0";
    size = <0x0 0x01000000>; // 16MiB
    memory-region = <&image_buf0>;
};

};

below is part of linux boot report image image linux version is 4.14 I read whole the related issues but can't fix the problem. hope you can guide me.

ikwzm commented 2 years ago

Thank you for the issue.

In your device tree, the image_buf@0 node has the linux, cma-default property set. If this property is set, this area will be allocated as the CMA area used by the kernel by default. Therefore, other device drivers also use this area as his DMA buffer. Therefore, it seems that the size reserved by CMA is not enough for the buffer size (16MiB) required by u-dma-buf.

If you want to use image_buf@0 only as an image buffer, remove the linux, cma-default property. In this case, her CMA area of the kernel is reserved separately so that no other device driver will use image_buf@0 as DMA buffer.

azAghaee commented 2 years ago

Thanks for your great answer problem solved after removing line "linux, cma-default" image Again Thanks for your time

Now when I use mmap on this region, the output address is 40bit and something like 0x7f.... (0x74AADAA000). is this a correct address?! image image

ikwzm commented 2 years ago

How a physical address is mapped to a virtual address depends on the kernel. For example, the Linux Kernel for ARM64 has a parameter called CONFIG_ARM64_VA_BITS that specifies the number of bits allocated to a virtual address. Therefore, I'm not sure if the question address is correct.

azAghaee commented 2 years ago

Thanks for your answer In fact I knew about that but when I give that address to Xilinx VDMA core, it return an invalid address! I can read the address content. perhaps this is an VDMA issue. Thanks for your hint and driver

ikwzm commented 2 years ago

The virtual address returned by mmap() is used by the CPU to access the buffer. You must specify the physical address for DMA. Try specifying the value of /sys/class/u-dma-buf/udmabuf0/phys_addr for VDMA.

azAghaee commented 2 years ago

After I replaced the physical address, problem solved. Thank you for your time and precious guidance.