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.

TDA4VM: [E-mirror][sdk8.5][tda4vm]convert physical address to virtual address

Part Number: TDA4VM

Hello TI:

     how to convert  physical address to virtual address in linux? We use mmap(), but we found that the Operation not permitted.

Best regards

Alun 

  • Hi,

    In application space you may use "phys_to_virt(phys_addr)"
    In kernel space i.e. at driver level you can use ioremap(phys_addr, length).

    Best Regards,
    Sudheer

  • Hi

    thanks ,we will try. And we get phys address in other app use tivxMemHost2SharedPtr

    Best Regards,

    Alun

  • Hello ,

           do you have another suggestion if our app run on A72?

    Best Regards,

    Alun

  • Hi,

    do you have another suggestion if our app run on A72?

    We have devmem2 tool for reading the registers from A72 (Linux), which uses mmap only.
    Please refer to source code of devmem2 tool from git link, which is using mmap for accessing physical address space.

    Best Regards,
    Sudheer

  • hi,

       

    void *appMemMap_local(void *phys_ptr, uint32_t size)
    
    {
    
        uint32_t  pageSize = getpagesize ();
    
        uintptr_t taddr;
    
        uint32_t  tsize;
    
        void     *virt_ptr = NULL;
    
        int32_t   status = 0;
    
        static int dev_mem_fd = -1;
    
    
    
        if(dev_mem_fd == -1)
    
        {
    
            dev_mem_fd = open("/dev/mem",O_RDWR|O_SYNC);
    
            if(dev_mem_fd  < 0)
    
            {
    
                ULOGE("[EBD]APP_LOG: ERROR: Unable to open /dev/mem !!!\n");
    
                status = -1;
    
            }
    
        }
    
        if(status==0 && dev_mem_fd >= 0)
    
        {
    
            #ifdef APP_LOG_DEBUG
    
            printf("APP_LOG: Mapping %p ...\n", phys_ptr);
    
            #endif
    
            /* Mapping this physical address to linux user space */
    
            taddr = (uintptr_t)phys_ptr;
    
            tsize = size;
    
    
    
            /* Align the physical address to page boundary */
    
            tsize = Align(tsize + (taddr % pageSize), pageSize);
    
            taddr = Floor(taddr, pageSize);
    
    
    
            virt_ptr  = mmap(0, tsize,
    
                            (PROT_READ | PROT_WRITE),
    
                            (MAP_SHARED), dev_mem_fd, taddr);
    
    
    
            if(virt_ptr==MAP_FAILED)
    
            {
    
                virt_ptr = NULL;
    
            }
    
            else
    
            {
    
                virt_ptr = (void*)((uintptr_t)virt_ptr + ((uintptr_t)phys_ptr % pageSize));
    
            }
    
            #ifdef APP_LOG_DEBUG
    
            printf("APP_LOG: Mapped %p -> %p of size %d bytes \n", phys_ptr, virt_ptr, size);
    
            #endif
    
        }
    
        if(virt_ptr==NULL)
    
        {
    
             ULOGE("[EBD]APP_LOG: ERROR: Unable to map memory @ %p of size %d bytes !!!\n", phys_ptr, size);
    
        }
    
        return virt_ptr;
    
    }

        this is our function to mmap, but Operation not permitted

    Best Regards,

    alun

  • hi,

    our phys address is 0xbb5b0000 and 0xc0e30000, and our ddr_shared_mem buffers from 0xB9000000 to 0xD7FFFFFF.

    Why we mmap failed?

    Best Regards,

    alun

  • hi, 

    And our image is  3120x1500, NV12 

    Best Regards,

    alun

  • Hi Alun,

    mmap operation is not permitted in dma-heap-carveout region because it is a reserved memory region for DMA (Direct Memory Access) operations.

    This memory region is used by the kernel to allocate memory for DMA operations, which are used by devices to directly access the system’s memory without involving the CPU.

    The CONFIG_STRICT_DEVMEM kernel configuration option restricts access to /dev/mem files, which provide direct access to the physical memory of the system. When this option is enabled, only privileged users can access these files. Since dma-heap-carveout is a reserved memory region for DMA operations, it is not accessible through mmap operation when CONFIG_STRICT_DEVMEM is enabled.

    Regards,

    Nikhil

  • hi ,

    thanks very much!

  •  hi Nikhil

      so how to get correct image data from other app ? Two app have different graph.

    Best Regards,

    alun

  • Hi Alun,

    You could refer the demo in the SDK for the same.

    Please refer the demo in ${PSDKRA}/vision_apps/apps/basic_demos/app_fd_exchange/

    Regards,

    Nikhil

  • Hi Nikhil

        Thanks!

    Regards,

    alun