cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mrbietola
Scholar
Scholar
1,676 Views
Registered: ‎05-31-2012

Can't set physical address udmabuf

Jump to solution

Hi, i'm tryng to implement udmabuf in a Zynq MPSoc.  https://github.com/ikwzm/udmabuf

I can load the driver as a module and tried, it works.

Now i'm trying to set the physical address for the udmabuf in the device tree, in this way i can write from the PL at an address fixed at compile time. I get the error

[ 0.000000] Reserved memory: incorrect alignment of CMA region
[ 0.000000] cma: Reserved 256 MiB at 0x000000005fc00000

udmabuf@0: of_reserved_mem_device_init failed. return=-22

udmabuf: probe of udmabuf@0 failed with error -22

 

the device tree is

reserved-memory {
        #address-cells = <2>;
        #size-cells = <2>;
        ranges;
        rproc_0_reserved: rproc@3ed00000 {
            no-map;
            reg = <0x0 0x3ed00000 0x0 0x1000000>;
        };

	

		image_buf0: image_buf@0 {
			compatible = "shared-dma-pool";
			reusable;
			reg = <0x0 0x6fc00000 0x0 0x0100000>;
			alignment = <0x0 0x1000>; 
			label = "image_buf0";
	
    	};

	

    };

 udmabuf@0 {
		compatible = "ikwzm,udmabuf-0.10.a";
		device-name = "udmabuf0";
		size = <0x0 0x0100000>; 
		memory-region = <&image_buf0>;
	};

The driver is loaded but in a different physical address

udmabuf0: phys address = 0x000000005fd00000

 

What can i do?

0 Kudos
1 Solution

Accepted Solutions
mrbietola
Scholar
Scholar
1,492 Views
Registered: ‎05-31-2012

i was told that the minimum buffer dimension required by CMA in MPSoC is 4 MBytes. With the following configuration in the device tere i was able to successfully run the udmabuf

        reserved-memory {
                #address-cells = <2>;
                #size-cells = <2>;
                ranges;
                rproc0_reserved: rproc@3ed00000 {
                        no-map;
                        reg = <0x0 0x3ed00000 0x0 0x01000000>;
                };
                image_buf0: image_buf@0 {
                        compatible = "shared-dma-pool";
                        reusable;
                        reg = <0x0 0x6fc00000 0x0 0x10000000>;
                        alignment = <0x0 0x1000>;
                        label = "image_buf0";
                };
        };
        udmabuf@0 {
                compatible = "ikwzm,udmabuf-0.10.a";
                device-name = "udmabuf0";
                size = <0x01000000>;
                memory-region = <&image_buf0>;
      };

View solution in original post

0 Kudos
8 Replies
darko31
Observer
Observer
1,656 Views
Registered: ‎05-07-2018

If you don't have a particular resaon for using aligment entry in image_buf, remove it and use the example provided in the readme without aligment entry. Also, I like  for ease of use to use different start address like 0x20000000 (512MB). Again if you don't have a particular reason for using that exact start address.

For example

 

	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;
		image_buf0: image_buf@0 {
			compatible = "shared-dma-pool";
			reusable;
			reg = <0x0 0x20000000 0x0 0x0100000>; 
			label = "image_buf0";
		};
	};
0 Kudos
mrbietola
Scholar
Scholar
1,646 Views
Registered: ‎05-31-2012

@darko31  the alignement property was added later, because i thought that can resolve the alignment problem. I started from the example given but wasn't working.

Did you manage to make it work?

I will try with the address you suggested

0 Kudos
darko31
Observer
Observer
1,634 Views
Registered: ‎05-07-2018

Yeah, this is devicetree entry we're currently using.

	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;
		image_buf0: image_buf@0 {
			compatible = "shared-dma-pool";
			reusable;
			reg = <0x0 0x20000000 0x0 0x40000000>; 
			label = "image_buf0"; 
		};
	};

	udmabuf@0 {
		compatible = "ikwzm,udmabuf-0.10.a";
		device-name = "udmabuf0";
		size = <0x40000000>;
		memory-region = <&image_buf0>;
	};
0 Kudos
mrbietola
Scholar
Scholar
1,611 Views
Registered: ‎05-31-2012

Wow you are really reserving a big buffer! 

Reserving only 1 MB with the address you provided doesn't work, i made it work with the following modifications, but the buffer is at address 0x6fD00000 instead of expected0x6fC00000.

I redefined the CMA memory (linux,cma-default) and image_buf0 will use 1MB of that. I also added "reserved-memory" in compatible property as Xilinx Wiki

 

reserved-memory {
        #address-cells = <2>;
        #size-cells = <2>;
        ranges;
      

	

		image_buf0: image_buf@0 {
			compatible = "shared-dma-pool";
			reusable;
			reg = <0x0 0x6fc00000 0x0 0x10000000>;
			linux,cma-default;
			label = "image_buf0";
	
    	};

	

    };

 udmabuf@0 {
		compatible = "ikwzm,udmabuf-0.10.a,reserved-memory";
		device-name = "udmabuf0";
		size = <0x0 0x0100000>; 
		memory-region = <&image_buf0>;
	};

 

 

0 Kudos
darko31
Observer
Observer
1,597 Views
Registered: ‎05-07-2018

Great!

Yeah, it's a big one.

If you encounter performance problems, I'd suggest running the udmabuf_test.c provided in the repo to verify everything. IIRC, we had slow read and write speeds to the buffer because of the linux,cma-default; and no-map; properties in image_buf entry.

Also, make sure to reserve enough CMA for other drivers. With default kernel config, we had kernel panics on our ZynqMP devices because not enough memory was being allocated for CMA. By increasing it to 256MB in the kernel config, everything seems to be working well.

0 Kudos
mrbietola
Scholar
Scholar
1,592 Views
Registered: ‎05-31-2012

thanks for the suggestion.

I'm totally noob for this, but i think if you use "no-map" the CMA will not be used.

My CMA is 256MB as well.  Do you remember some performance values to do a comparison?

I want to use udmabuf to do some processing in PS from a buffer written from PL and use hardware coherency. Do you gain good performances?

0 Kudos
darko31
Observer
Observer
1,559 Views
Registered: ‎05-07-2018

I don't remember of the top of my head exact numbers, but I do remember it was in line with results in udmabuf readme, and even better in some cases.

For the no-map from the kernel documentation

no-map (optional) - empty property
    - Indicates the operating system must not create a virtual mapping
      of the region as part of its standard mapping of system memory,
      nor permit speculative access to it under any circumstances other
      than under the control of the device driver using the region.

So it shoudn't affect performance, but things were very slow. It didn't matter which sync mode I've tried to use it always acted as CPU cache and write-combine were disabled. As for coherency, I haven't tested anything regarding it so I can't say.

0 Kudos
mrbietola
Scholar
Scholar
1,493 Views
Registered: ‎05-31-2012

i was told that the minimum buffer dimension required by CMA in MPSoC is 4 MBytes. With the following configuration in the device tere i was able to successfully run the udmabuf

        reserved-memory {
                #address-cells = <2>;
                #size-cells = <2>;
                ranges;
                rproc0_reserved: rproc@3ed00000 {
                        no-map;
                        reg = <0x0 0x3ed00000 0x0 0x01000000>;
                };
                image_buf0: image_buf@0 {
                        compatible = "shared-dma-pool";
                        reusable;
                        reg = <0x0 0x6fc00000 0x0 0x10000000>;
                        alignment = <0x0 0x1000>;
                        label = "image_buf0";
                };
        };
        udmabuf@0 {
                compatible = "ikwzm,udmabuf-0.10.a";
                device-name = "udmabuf0";
                size = <0x01000000>;
                memory-region = <&image_buf0>;
      };

View solution in original post

0 Kudos