Search code examples
linuxembedded-linuxxilinxdevice-treepetalinux

Cannot reserve memory on Petalinux2020.2?


I'm building a project using petalinux2020.2 and an RFSOC, zcu111 board, for my application I need to reserve a section of memory from petalinux to use with DMA, implemented on the programmable logic of the FPGA. I tried following this tutorial, but I get an error at boot time. enter image description here

Which terminates with a kernel panic, shown here: enter image description here I've tried to modify Memory Size by using petalinux-config command, setting the Memory Size to 0x70000000 but it did not help.

The entry for the device tree is shown here:

/include/ "system-conf.dtsi"
/{
    reserved-memory {
        #address-cells = <2>;
        #size-cells = <2>;
        ranges;
 
        reserved: buffer@0 {
            no-map;
            reg = <0x0 0x70000000 0x0 0x10000000>;
        };
    };
    reserved-driver@0 {
        compatible = "xlnx,reserved-memory";
        memory-region = <&reserved>;
    };
};

How can I make this work?


Solution

  • I'm running PetaLinux 2018.1 on a Zynq-7020 board and can successfully reserve memory for my DMA operations. While not your exact set up it should be similar enough. You'll need to adjust the memory addresses to suit your system.

    I'm using the DMA API "shared-dma-pool" property. That way my device driver will use my reserved space instead of the default CMA pool.

    Also, note that I had problems reserving the memory until I added the vmalloc=512M statement to the bootargs. Although I was only reserving 256MB for DMA, I needed to vmalloc a larger value (double in my case) to get things to work.

    My device tree entry:

    /include/ "system-conf.dtsi"
    / {
        chosen {
        bootargs = "console=ttyPS0,115200 earlyprintk vmalloc=512M";
        stdout-path = "serial0:115200n8";
        };
    
    reserved-memory {
            #address-cells = <1>;
            #size-cells = <1>;
            ranges;
     
                dma_reserved: buffer@30000000 {
            compatible = "shared-dma-pool";
                no-map;
            reg = <0x30000000 0x10000000>;
                };
        };
    
        //Required properties: 
        // - dmas: a list of <[DMA device phandle] [Channel ID]> pairs, 
        //         where Channel ID is (if both channels are enabled):
        //      '0' for write/tx channel
        //      '1' for read/rx channel 
        //     If only one channel is enabled, either tx or rx: 
        //      Channel ID is '0'. 
        // - dma-names: a list of DMA channel names, one per "dmas" entry 
        dma_proxy@0 {
            compatible ="xlnx,dma_proxy";
            dmas = <&axi_dma_0 0;
            dma-names = "dma1";
        memory-region = <&dma_reserved>;
        };
    }
    

    Console showing reserved memory (PetaLinux 2018.1):   I

    Update: I've since updated my design to a ZynqMP architecture using PetaLinux 2022.1 and wanted to post the differences I encountered while getting the reserved memory working.

    I am booting with an initramfs image and also ran into trouble when trying to reserve memory in the 0x70000000 address space you see in the Xilinx Wiki. This is because the system likes to load the ramdisk into this region, so it's already booked when you try to reserve it, similar to what the OP ran into. Reserving a different address space (0x40000000 in the example below) is all it took to get it working.

    /include/ "system-conf.dtsi"
    / {
        chosen {
        bootargs = "earlycon console=ttyPS0,115200 clk_ignore_unused";
        };
    
        reserved-memory {
        #address-cells = <2>;
        #size-cells = <2>;
        ranges;
     
                dma_reserved: buffer@0 {
                compatible = "shared-dma-pool";
                no-map;
                reg = <0x0 0x40000000 0x0 0x10000000>;
                };
            };
    
        dma_proxy@0 {
            compatible ="xlnx,dma_proxy";
            dmas = <&axi_dma_0 1>;
            dma-names = "dma1";
            memory-region = <&dma_reserved>;
        };
    }
    

    Console showing reserved memory (PetaLinux 2022.1): enter image description here