cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Adventurer
Adventurer
5,206 Views
Registered: ‎09-28-2016

reserve ddr memory and mmap it?

Hi,all

 

now I have using petalinux2015.4 on board zc706

 

I take AMP mode that cpu0 run linux, cpu1 run bare metal application. main set amp as below:

1.Run petalinux-config, and set the kernel base address to 0x10000000, as
follows:
Subsystem AUTO Hardware Settings --->
Memory Settings --->
(0x10000000) kernel base address

 

2.For the Zynq-7000 All Programmable (AP) SoC (Zynq) only, set memory split to
2G/2G (or use 1G/3G user/kernel):
Kernel Features--->
Memory split (...)--->
(x) 2G/2G user/kernel split

 

and I reserve ddr 128M physical space that add device tree entry in system-conf.dtsi  as below:

memory {
device_type = "memory";
reg = <0x0 0x40000000>;
};

reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
vin_reserved: vin@0x38000000 {
reg = <0x38000000 0x8000000>;
};

 

 

in my original design, wirte date to 0x38000000 in bare metal application run on cpu1, and read date from linux user space applicaton run on cpu0

 

cpu0 coder as below:

map_base_tmp = mmap(NULL, 0xff, PROT_READ|PROT_WRITE, MAP_SHARED, map_fd, 0x38000000);

for (i = 0; i < 0xff; i++)
    {
        if (i % 16 == 0)
        {
            printf("\r\n");
        }
        printf("%d\t", map_base_tmp[i]);
    }

 

cpu1 code as below:

unsigned char* map_addr = (unsigned char*)0x38000000;

for (i = 0; i < 0xff; i++)
{
      map_addr[i] = i;
}

 

 

but it read failed, the date wrong. if I modify the mmap offset addr to 0x18000000, the read date are right. why?

 

another question, how can I set the reserve ddr space to uncache use mmap function or other method?

 

thanks a lot in advance

 

 

Tom

 

 

0 Kudos
1 Reply
Highlighted
Xilinx Employee
Xilinx Employee
5,174 Views
Registered: ‎07-01-2010

@atower

 

looks like the offset 0x38000000 is untouched as this is reserved and you might have not defined memory-region for the peripheral you wanted to use. See if you can set the offset (0x38000000) as contiguous memory allocator (CMA).

 

Example:

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

		/* global autoconfigured region for contiguous allocations */
		linux,cma {
			compatible = "shared-dma-pool";
			reusable;
			size = <0x4000000>;
			alignment = <0x2000>;
			linux,cma-default;
		};

		display_reserved: framebuffer@78000000 {
			reg = <0x78000000 0x800000>;
		};

		multimedia_reserved: multimedia@77000000 {
			compatible = "acme,multimedia-memory";
			reg = <0x77000000 0x4000000>;
		};
	};

	/* ... */

	fb0: video@12300000 {
		memory-region = <&display_reserved>;
		/* ... */
	};

	scaler: scaler@12500000 {
		memory-region = <&multimedia_reserved>;
		/* ... */
	};

	codec: codec@12600000 {
		memory-region = <&multimedia_reserved>;
		/* ... */
	};

 

Please refer to the below binding for better understanding of reserved-memory nodes.

 

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt

 

Regards,

Achutha

---------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------
0 Kudos