2001-03-09 05:46:18

by gjohnson

[permalink] [raw]
Subject: Resolving physical addresses

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? http://www.geocities.com/worfsom/ |
| ..ooOO Greg Johnson OOoo.. |
| HW/SW Engineer [email protected] |
| Canon Information Systems Research Australia (CISRA) |
| 1 Thomas Holt Dr., North Ryde, NSW, 2113, Australia |
| "I FLEXed my BISON and it went YACC!" - me. |
+------------------------------------------------------+


2001-03-09 06:02:50

by David Miller

[permalink] [raw]
Subject: Re: Resolving physical addresses


In 2.4.x pte_page() gives a pointer to a page struct, not an address
as in 2.2.x.

Later,
David S. Miller
[email protected]

2001-03-09 06:17:42

by gjohnson

[permalink] [raw]
Subject: Re: Resolving physical addresses

Thank you,

But how do I get the physical address out of the page
structure? It is non-obvious to me. Is there some majic
macro? We are talking about 'struct page' in mm.h, correct?

Greg.

Quoth David S. Miller:
> In 2.4.x pte_page() gives a pointer to a page struct, not an address
> as in 2.2.x.

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

2001-03-09 12:15:54

by Martin Frey

[permalink] [raw]
Subject: RE: Resolving physical addresses

>But how do I get the physical address out of the page
>structure? It is non-obvious to me. Is there some majic
>macro? We are talking about 'struct page' in mm.h, correct?
>
virt_to_phys(page_address(page))

>Quoth David S. Miller:
>> In 2.4.x pte_page() gives a pointer to a page struct, not an address
>> as in 2.2.x.

--
Supercomputing Systems AG email: [email protected]
Martin Frey web: http://www.scs.ch/~frey/
at Compaq Computer Corporation phone: +1 603 884 4266
ZKO2-3P09, 110 Spit Brook Road, Nashua, NH 03062