mem_offset always failed in getting the physical address

Hi All,

I want to allocate a block of continuous memory as video work buffer for DMA usage. But I always get failure in converting the virtual address to physical one with return -1, and physical address always zero.

Can anyone give me some clues on this issue?

my code:
{
unsigned int ptr = NULL, phys_addr = NULL;
int ret = 0;
size = (size + 0x3FF) & (~0x3FF);

ptr = mmap( 0, size,
             PROT_READ|PROT_WRITE|PROT_NOCACHE,
             MAP_PHYS|MAP_ANON,
             NOFD,
             0 );

if (ptr == MAP_FAILED)
{
    printf("memory allocation failed\n");
    return (void *)NULL;
}
else
{
    ret = mem_offset(ptr, NOFD, 1, &phys_addr, 0);
    printf("RET:%d vitual memory 0x%x, physical from 0x%x to 0x%x\n", ret, ptr, phys_addr, phys_addr + size);
    return (void *)phys_addr;
}

}

BR
-Ray

Are you running as super user? You can’t access DMA memory unless you are super user. I don’t think you have to request anything with ThreadCtrl() but I’d check it out too.

try replacing the 1 in the call to mem_offset with the real size. I have code that I know is working and that is the only difference between my code and yours.

try replacing the 1 in the call to mem_offset with the real size. I have code that I know is working and that is the only difference between my code and yours.