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

share DDR between PL and PS on custom board

Jump to solution

Hi,all

 

I use petalinux2015.4 on custom board , and use AMP mode, linux run on cpu0, bare metal application run on cpu1.

 

PL and PS share the same DDR which capability 1G. I want to reserve 256M DDR space for PL.

 

what should I do? any suggestions are appreciative!!!

 

 

Tom

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Teacher
Teacher
10,032 Views
Registered: ‎03-31-2012

@atower Yes. Also assuming you connect PL to memory through non-acp interface you need to solve the cache coherency issues when communicating between processors and the PL.

- 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.

View solution in original post

0 Kudos
17 Replies
Highlighted
Teacher
Teacher
5,793 Views
Registered: ‎03-31-2012

@atower allocate 256 MB using the contiguous memory allocator?

- 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
Highlighted
Adventurer
Adventurer
5,756 Views
Registered: ‎09-28-2016

Hi, muzaffer

 

Thanks for your suggestion. I configurated the kernel and set CMA size 256M, and after system startup, print the log:  "cma:Reserved 256 MiB at 0x38000000"

But how can I use contiguous memory allocato(CMA), I have not any idea about CMA.

 

 

Tom

0 Kudos
Highlighted
Explorer
Explorer
5,615 Views
Registered: ‎11-22-2015

CMA is usually access via  the linux DMA API.  If you are just trying to reserve a block of memory and you want it at a fixed physical address just mark it reserved in the devicetree:

 

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

 

and if you want to access from a  piece of code just mmap that address.

 

jeff

 

0 Kudos
Highlighted
Teacher
Teacher
5,740 Views
Registered: ‎03-31-2012

@atower If CMA has reserved the amount of memory at a specific address, I think your job is done. the address given (which I believe is also stored somewhere in the sysconfig) is the physical address of the reserved memory which you can use for PL.

- 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
Highlighted
Adventurer
Adventurer
5,730 Views
Registered: ‎09-28-2016

HI, muzaffer

 

you mean that PL and cpu1 which run bare metal app can  directly handle the DDR physical space from 0x38000000 to 0x3fffffff?

 

if I want to handle the physical space in linux user space run on cpu0, do I have to write mmap kernel driver, map the physical space to linux user space?

 

Thank you so much!!!

 

Tom

0 Kudos
Highlighted
Teacher
Teacher
10,033 Views
Registered: ‎03-31-2012

@atower Yes. Also assuming you connect PL to memory through non-acp interface you need to solve the cache coherency issues when communicating between processors and the PL.

- 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.

View solution in original post

0 Kudos
Highlighted
Explorer
Explorer
5,615 Views
Registered: ‎11-22-2015

Hi,

  You don't want to use CMA you just want to reserve a block of memory.  CMA is managed by the kernel and you use the DMA API to access it.

  Instead, you just want to reserve a block of private memory in the devicetree

 

        reserved-memory {

                #address-cells = <1>;

                #size-cells = <1>;

                ranges;

 

                vin_reserved: vin@0x10000000 {

                        reg = <0x10000000 0x100000>;

                };

        };

 

The kernel will not touch this block of memory and you can just mmap the address in userspace.

0 Kudos
Highlighted
Explorer
Explorer
5,615 Views
Registered: ‎11-22-2015

You really don't want to use CMA as this is memory that is reserved for DMA and is supposed to be accessed via the DMA API.  You just want to reserve a block of memory, like this:

 

        reserved-memory {

                #address-cells = <1>;

                #size-cells = <1>;

                ranges;

                vin_reserved: vin@0x10000000 {

                        reg = <0x10000000 0x1000000>;

                };

        };

 

This just reserves a block of memory at a physical address and this prevents the kernel from trying to use it for anything.  You can access the memory from userspace by just doing a mmap on the physical address.

 

jeff

 

0 Kudos
Highlighted
Explorer
Explorer
5,655 Views
Registered: ‎11-22-2015

You don't want to use CMA as this is then reserved for DMA by the kernel and you are supposed to use the DMA API to access it.  You just want to reserved a block of memory in the devicetree using the reserved-memory keyword.   This reserves a generic block of memory and prevents the kernel from using it.  You can access it from userspace using mmap.

 

jeff

 

0 Kudos
Highlighted
Adventurer
Adventurer
5,528 Views
Registered: ‎09-28-2016

Hi, jeff

 

Thanks for your reply. I also think CMA isn't the best solution in my case. according to your idea, how can I reserved a block of memory in the devicetree using the reserved-memory keyword, would you please give some detail procedure?

 

thanks in advance

 

 

Tom

0 Kudos
Highlighted
Explorer
Explorer
5,500 Views
Registered: ‎11-22-2015

OK, this is strange.  I posted to this thread a couple of times but my post never showed up until today???  Can you see what I posted on the 20th?  That has the devicetree info.

 

jeff

0 Kudos
Highlighted
Adventurer
Adventurer
5,402 Views
Registered: ‎09-28-2016

Hi, jiff

 

I am sorry for response so late. I have seen your post, and show below, thank you very much.

 

You really don't want to use CMA as this is memory that is reserved for DMA and is supposed to be accessed via the DMA API.  You just want to reserve a block of memory, like this:

 

        reserved-memory {

                #address-cells = <1>;

                #size-cells = <1>;

                ranges;

                vin_reserved: vin@0x10000000 {

                        reg = <0x10000000 0x1000000>;

                };

        };

 

This just reserves a block of memory at a physical address and this prevents the kernel from trying to use it for anything.  You can access the memory from userspace by just doing a mmap on the physical address.

 

another question, if I want to use this physical memory space in linux user space, I should use mmap as below:

map_base = mmap(NULL, 0x1000000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x10000000 );

 is this ok?

 

 

Tom

0 Kudos
Highlighted
Adventurer
Adventurer
5,402 Views
Registered: ‎09-28-2016

Hi, jiff

 

I am sorry for response so late. I have seen your post, and show below, thank you very much.

 

You really don't want to use CMA as this is memory that is reserved for DMA and is supposed to be accessed via the DMA API.  You just want to reserve a block of memory, like this:

 

        reserved-memory {

                #address-cells = <1>;

                #size-cells = <1>;

                ranges;

                vin_reserved: vin@0x10000000 {

                        reg = <0x10000000 0x1000000>;

                };

        };

 

This just reserves a block of memory at a physical address and this prevents the kernel from trying to use it for anything.  You can access the memory from userspace by just doing a mmap on the physical address.

 

another question, if I want to use this physical memory space in linux user space, I should use mmap as below:

map_base = mmap(NULL, 0x1000000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x10000000 );

 is this ok?

0 Kudos
Highlighted
Explorer
Explorer
5,389 Views
Registered: ‎11-22-2015

yes, that should work.

 

jeff

 

0 Kudos
Highlighted
Adventurer
Adventurer
5,304 Views
Registered: ‎09-28-2016

hi, jeff

 

if I use below entry add to dts file,  after linux startup, how can I verify whether the system reserve this range memory.

reserved-memory {

                #address-cells = <1>;

                #size-cells = <1>;

                ranges;

                vin_reserved: vin@0x10000000 {

                        reg = <0x10000000 0x1000000>;

                };

        };

 

and how can I set this range "uncached" attribute?

 

Thanks a lot in advance

 

Tom

0 Kudos
Highlighted
Explorer
Explorer
5,278 Views
Registered: ‎11-22-2015

Hi,

 

  I don't know how to "really" verify that it reserved it.  I know I'll see the devicetree in /proc but I guess that doesn't mean it's really been reserved.   I use it when we are a PCIe endpoint and dma data to/from the host from this memory and haven't had an issue.  I also don't have know about setting the uncached.  

 

good luck,

jeff

 

0 Kudos
Highlighted
Adventurer
Adventurer
5,275 Views
Registered: ‎09-28-2016

Hi, jeff

 

thanks for your reply.

 

when you used reserved memory for PCIE, did you need to keep coherence between DDR and cache by yourself? if you did, how did you keep coherence?

 

 

Tom

0 Kudos