How can I test if a physical address is already mapped or not.

Jeff Haran jharan at bytemobile.com
Tue Oct 18 17:16:10 EDT 2011


> -----Original Message-----
> From: StephanT [mailto:stman937-linewbie at yahoo.com]
> Sent: Tuesday, October 18, 2011 1:58 PM
> To: Jeff Haran; kernelnewbies
> Subject: Re: How can I test if a physical address is already mapped or not.
> 
> > unsigned long    * const pReg = (unsigned long*) 0XC0000000 ;
> 
> >
> > printk( KERN_INFO"** read (%p) %08lX.\n", pReg, *pReg) ;
> 
> On any virtual memory processor I am aware of, the above will cause pReg to
> contain a virtual address, not a physical address.
> 
> 
> 
> Jeff,
> 
> I do not follow you... Could you, please be more explicit.
> 
> Thanks.

I am assuming the processor you are running this on has an MMU (Memory Management Unit). This statement:

unsigned long    * const pReg = (unsigned long*) 0XC0000000 ;

will cause the variable pReg to contain the constant 0xC0000000.

When *pReg is evaluated in your printk(), the MMU will load the unsigned long located at virtual address 0xC0000000 into some processor register. How the mapping of the virtual address to physical address occurs is processor specific, but in Linux ultimately the physical address to get the data from will be derived from a page table that provides a mapping between the physical and virtual addresses of 4KB (usually 4KB) pages .

Do a search on "Understanding the Linux Virtual Memory Manager" by Mel Gorman. It's a little dated, but the PDF can be obtained for free. I suspect reading this will help you to understand what is going on better than I can explain in this post. I know it helped me out a lot many years ago when I was puzzling through a problem related to this.

Jeff Haran






More information about the Kernelnewbies mailing list