UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor asuarez
Visitor
2,107 Views
Registered: ‎02-14-2018

Petalinux2017.4 How to Create VDMA Video Buffers

Jump to solution

I'm working on a zc702 board and am trying to use VDMA to send data from the PL to the PS. I set up one channel in Vivado, below is the content of pl.dtsi from the petalinux build. 

 

		axi_vdma_0: dma@44a00000 {
			#dma-cells = <1>;
			clock-names = "s_axi_lite_aclk", "m_axi_s2mm_aclk", "m_axi_s2mm_aclk";
			clocks = <&clkc 15>, <&clkc 15>, <&clkc 15>;
			compatible = "xlnx,axi-vdma-1.00.a";
			interrupt-parent = <&intc>;
			interrupts = <0 31 4>;
			reg = <0x44a00000 0x10000>;
			xlnx,addrwidth = <0x20>;
			xlnx,flush-fsync = <0x1>;
			xlnx,num-fstores = <0x20>;
			dma-channel@44a00030 {
				compatible = "xlnx,axi-vdma-s2mm-channel";
				interrupts = <0 31 4>;
				xlnx,datawidth = <0x20>;
				xlnx,device-id = <0x0>;
			};
		};

I created a UIO node for the VDMA and am able to access the VDMA registers through UIO. 

 

vdma@44a00000 {
    compatible = "generic-uio";
    reg = <0x44a00000 0x10000>;
    interrupts = <0 31 4>;
    interrupt-parent = <&intc>;
};

This part I've had no issues with but what I don't know how to do now is creating the video buffers in Linux and using them with the VDMA. I did try to mmap a random memory region but kept getting Bus error when I tried to read/write to it. 

 

Does anyone have any advice on how to create the video buffers?

0 Kudos
1 Solution

Accepted Solutions
Visitor asuarez
Visitor
2,366 Views
Registered: ‎02-14-2018

Re: Petalinux2017.4 How to Create VDMA Video Buffers

Jump to solution

 

Thank you all for the replies.

 

I've done a quick test of reserving some memory and calling mmap on it. The reservation of memory is done in the device tree with the reserved-memory node. The idea came from http://www.wiki.xilinx.com/Linux+Reserved+Memory

 

This so far appears to work and the VDMA doesn't seem to care. Does anyone know if a possible pitfall to this approach?

 

/include/ "system-conf.dtsi"
/ {
    vdma@44a00000 {
        compatible = "generic-uio";
        reg = <0x44a00000 0x10000>;
        interrupts = <0 31 4>;
        interrupt-parent = <&intc>;
    };
    
    reserved-memory {
        #address-cells = <1>;
        #size-cells = <1>;
        ranges;
        reserved: buffer@0x3FF00000 {
            no-map;
            reg = <0x3FF00000 0x100000>;
        };
    };

    reserved-driver@0 {
        compatible = "xlnx,reserved-memory";
        memory-region = <&reserved>;
    };

};

 

The result of the free command.

 

root@petalinux:~# free -k
             total       used       free     shared    buffers     cached
Mem:       1029220      55888     973332        344       4696      36936
-/+ buffers/cache:      14256    1014964
Swap:            0          0          0

 

[edited to add the link to Xilinx reserve memory]

0 Kudos
4 Replies
Adventurer
Adventurer
2,072 Views
Registered: ‎10-04-2017

Re: Petalinux2017.4 How to Create VDMA Video Buffers

Jump to solution
One way if you had a kernel driver is to malloc the buffers in the kernel and then give that physical address to the userspace app so that it can mmap. Search the vdma proxy driver, there are some other example around the are pure userspace.

jeff
2,062 Views
Registered: ‎04-20-2017

Re: Petalinux2017.4 How to Create VDMA Video Buffers

Jump to solution
If you always need that memory as vdma buffer then a much simpler approach is to just exclude some of your DDR from petalinux. So some of your memory is not touched by the Linux memory management. You still can mount it though with mmap

For that you have to override the memory node in system-user.dtsi. Dtsi and reduce the designated memory in the device tree by the amount you want to use for frame buffers
Explorer
Explorer
2,056 Views
Registered: ‎03-13-2014

Re: Petalinux2017.4 How to Create VDMA Video Buffers

Jump to solution

My advice would be to use a kernel driver, can be very simple, to allocate memory with dma_alloc_coherent() 

Then return the physical address with ioctrl 

Why not copy to/fro with a read and write method in your driver then no need to mmap()

Note you can send parameters to your driver using the device tree so you can change size and number of buffers.

Also you can change (increase) the amount of cma  memory by changing the boot args to linux in the system-user.dtsi

e.g.

 

/include/ "system-conf.dtsi"
/ {

chosen {
bootargs = "earlycon cma=64M";
stdout-path = "serial0:115200n8";
};

amba_pl: amba_pl {
#address-cells = <1>;
#size-cells = <1>;
compatible = "simple-bus";
ranges ;
luscher_instance: luscher@40400000 {
compatible = "vendor,luscher";
reg = <0x40400000 0x10000>;
interrupt-parent = <0x3>;
interrupts = < 0x0 59 0x4 >; /* int 59 */
buff-size = < 0x40000 >;
buff-number = < 0x80 >;
};

};

};

 

Reserving memory that Linux does not use will also work but I found performance issues as the cache settings of that memory make it slow.

 

regards Dave

Visitor asuarez
Visitor
2,367 Views
Registered: ‎02-14-2018

Re: Petalinux2017.4 How to Create VDMA Video Buffers

Jump to solution

 

Thank you all for the replies.

 

I've done a quick test of reserving some memory and calling mmap on it. The reservation of memory is done in the device tree with the reserved-memory node. The idea came from http://www.wiki.xilinx.com/Linux+Reserved+Memory

 

This so far appears to work and the VDMA doesn't seem to care. Does anyone know if a possible pitfall to this approach?

 

/include/ "system-conf.dtsi"
/ {
    vdma@44a00000 {
        compatible = "generic-uio";
        reg = <0x44a00000 0x10000>;
        interrupts = <0 31 4>;
        interrupt-parent = <&intc>;
    };
    
    reserved-memory {
        #address-cells = <1>;
        #size-cells = <1>;
        ranges;
        reserved: buffer@0x3FF00000 {
            no-map;
            reg = <0x3FF00000 0x100000>;
        };
    };

    reserved-driver@0 {
        compatible = "xlnx,reserved-memory";
        memory-region = <&reserved>;
    };

};

 

The result of the free command.

 

root@petalinux:~# free -k
             total       used       free     shared    buffers     cached
Mem:       1029220      55888     973332        344       4696      36936
-/+ buffers/cache:      14256    1014964
Swap:            0          0          0

 

[edited to add the link to Xilinx reserve memory]

0 Kudos