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; }