This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4M How to change PhyBufPtr to VirtBufPtr

Hi Processors Team:

In out situation have tow process: app1.out and  app2.out.

app1.out send  PhyBufPtr to app2.out .  app2.out  need to change PhyBufPtr to VirtBufPtr .

Howerve, in  \tiovx\source\platform\psdk_j7\common\tivx_mem.c ,API to implement PhyBufPtr to VirtBufPtr can not  be  found.

So,How could I  change  PhyBufPtr to VirtBufPtr in TDA4M ?

Regards,

Zhao Shiming

  • Hi Zhao,

    Are you using 6.1 release? 

    This release uses ion memory allocater.  ion has different mechanism for sharing buffer. 

    Also if you are running two graphs in app1 and app2, this would need some changes, which will be available in the next release.

    Rgds,

    Brijesh

  • TO add to this the recommended way to exchange buffers between processes is below.

    Every memory allocated using ION has a file descriptor. One can exchange file descriptors between process using unix domain sockets, see below

    Given a virtual pointer you can get file descriptor using below API,

    appMemGetDmaBufFd(virtAddr, &bufFd)

    Here the virtual pointer MUST have been allocated using appMemAlloc()

    bufFd can be passed to other process using unix domain socket.

    On the other side you can map this bufFd to get virtual address on that process.

    We don't have a utility API for this, but you can see how this is done in void *appMemAlloc(uint32_t block, uint32_t size, uint32_t align)

    Specfically below lines ...

            virtual_ptr = mmap((void *)0x00000000u,
                               size,
                               PROT_WRITE | PROT_READ,
                               MAP_SHARED,
                               dma_buf_fd,
                               0u
                               );

    The functions are in file vision_apps/utils/mem

    regards
    Kedar

  • Hi Zhao,

    Any further question on this? Let us know if we can close this thread..

    Rgds,

    Brijesh

  • Hi Brijesh

    Sorry for not repy in time . I just got invited to join J721E today.

    I am using 06.00.01 release.

    QNX is used ,so when I call  appMemGetDmaBufFd , I got bufFd=0;

    what mechanism could I use to  share buffer in QNX?

    Rgds,

    Zhao Shiming

  • Hi Zhao,

    To translate between Physical and virtual addresses the below QNX APIs can be used.  

    /* Physical to virtual */

    uint64_t *virtAddr;

    virtAddr = mmap_device_memory(0, length, PROT_READ|PROT_WRITE, 0, phyAddr);
    if((virtAddr == MAP_FAILED))
    {
        printf("%s: mmmap_device_memory failed\n",__FUNCTION__);
    }
    .....

    /* Virtual to Physical */

    ret = mem_offset64(virtAddr, NOFD, length, &phyAddr, NULL);
    if (ret) {
            printf("%s:Error from mem_offset\n",__FUNCTION__);
    }

    These APIs are used throughout the PSDKRA code that has been ported to QNX, and there is documentation available for them in the QNX online documentation.

    Regards,

    Kip

  • Hi Zhao,

     

    The call to mmap_device_memory() will create a new virtual memory mapping to same physical address. 

     

    In the case of the sample code, creating the new memory map in this case is not necessary, as the original mapping is still available.

     

    The output from the code as written is expected.

    Regards,

    Kip