Can this fuction be uesd like this?:
fd=shm_open("/databuffer",O_RDWR|O_CREAT,S_IRWXU);
addr = mmap( 0,
262144,
PROT_READ|PROT_WRITE|PROT_NOCACHE,
MAP_PHYS|MAP_ANON,
fd,
0 );
because I want to alloc a physically contiguous memory for DMA transfer,and use this memory like shared memory that can be used between threads or processes.
We tried similar, as soon we put MAP_ANON into there was no access anymore, since it returns a memory pointer outside your process-space.
Also we did not yet manage using real DMA access for copying from host-cpu-memory into client-cpu-memory (which we woul like to do^^).
In your example there was one more function to call i think: mem_offset ();
in fact my program step is like this( I refered to the sample code in shm_ctl() function .):
addr = mmap(0,sizeof(shmem_t),PROT_READ|PROT_WRITE|PROT_NOCACHE,MAP_PHYS|MAP_SHARED,NOFD,0);
your call to mmap, is before shm_open and with parameter NOFD, this implements you would like to map physical memory. Therefore the last parameter must not be 0 (am i wrong). The last parameter can be retrieved through the pci_* functions for example with pci-cards.
You also do not have to use mem_offset() in this example (afaik).
The rest looks like it is written in the example code, but i am a bit confused about the phy_addr pointer ^^
(I will try that here with our card, may this wil also solve some of our problems ^^)
calls shm_ctl() with a different physical address than that supplied to mmap() (which, as stated in 1, isn’t a valid invocation in any case).
If you want to map physical memory, you need to supply the same physical address to a correctly formed mmap() call, as well as to the shm_ctl() call. The code from the example works fine.
I want alloc a 2M shared memory file ,and this memory could be a physically contiguous memory for DMA transfer.In the sample code in library reference ,these two kinds of methods have respective specific.But I down how to make them coorperate each other in one function.
I have made some changes in my code according to micro and rgallen’s advice.but the programme didn’t work too.Because I still don’t know the key point about the problem.
to map physical memory means you want to map memory on a special hardware (graphics card, client cpu ram, other pci/usb/whatever plugged in devices)
if you just need 2M shared RAM-memory try: