Resolving physical addresses

From: gjohnson@research.canon.com.au
Date: Fri Mar 09 2001 - 00:45:28 EST


Hi Kernel-dudes,

I have used this snippet of code previously in a 2.2 kernel
to get the physical address of the user virtual address 'addr'.
It worked fine under 2.2, but gives me crap under 2.4. I have
looked at bits of code in the 2.4 memory manager that do
similar stuff, and it looks much the same. I call 'mlock' (as root)
on the allocated buffer in the user app before my driver
gets called to run this code.

I have tried this on a dual CPU system with both a UP and MP
kernel.

Is there something that I should be doing different in the
2.4 case, or is maybe 'mlock' broken?

I also used 'map_user_kiobuf' on the same buffer and when I
look at iobuf->locked, it says it ain't.

Any ideas, or is there an easier way to get physical address
of a user allocated buffer. The kiobuf is a bit obscure to
divine from the source.

Regards

Greg.

    pgd_t *pgd; /* PaGe Directory */
    pmd_t *pmd; /* Page Mid-level Directory */
    pte_t *pte; /* Page Table Entry */
    unsigned long kern_addr; /* Kernel address of addr. */
    unsigned long addr_ofst; /* Offset of addr within a page */

    /* Get the page table entry of the page that addr belongs */
    pgd = pgd_offset(current->mm, (unsigned long) addr);
    pmd = pmd_offset(pgd, (unsigned long) addr);
    pte = pte_offset(pmd, (unsigned long) addr);

    /* Calculate the offset of addr within a page and add to kern_addr */
    kern_addr = (unsigned long) pte_page(*pte);
    addr_ofst = addr & (PAGE_SIZE - 1);
    kern_addr += addr_ofst;

-- 
+------------------------------------------------------+
| Do you want to know more? www.geocities.com/worfsom/ |
|              ..ooOO Greg Johnson OOoo..              |
| HW/SW Engineer        gjohnson@research.canon.com.au |
| Canon Information Systems Research Australia (CISRA) |
| 1 Thomas Holt Dr., North Ryde, NSW, 2113,  Australia |
|      "I FLEXed my BISON and it went YACC!" - me.     |
+------------------------------------------------------+

- 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/



This archive was generated by hypermail 2b29 : Thu Mar 15 2001 - 21:00:09 EST