Messages in this thread |  | | From | "Imran Badr" <> | Subject | Calculating kernel logical address .. | Date | Thu, 5 Sep 2002 20:34:07 -0700 |
| |
Hi,
I need help to correctly calculate kernel logical address for a user pointer which I mmaped from device driver. In mmap() file operation, I allocate some memory using kmalloc() and call :
remap_page_range(vma->vm_start, virt_to_phys((void *)(Uint32)kmalloc_buffer), size, PAGE_SHARED);
after reserving all pages and doing some other stuff. Now when I get a user pointer and I need to calculate correspoding kernel logical address, I use following code:
adr = user_address; pgd_offset(current->mm, adr);
if (!pgd_none(*pgd)) { pmd = pmd_offset(pgd, adr); if (!pmd_none(*pmd)) { ptep = pte_offset(pmd, adr); pte = *ptep; if(pte_present(pte)) { kaddr = (unsigned long) page_address(pte_page(pte)); kaddr |= (adr & (PAGE_SIZE - 1)); } } }
Will this code always give me correct kernel logical address?
I will really appreciate any guidance.
Thanks, Imran.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
|  |