<div dir="ltr"><div><div>Hi,<br><br></div>Do you know the value of PHYS_OFFSET of your platform?<br></div><div>PHYS_OFFSET defines the starting physical address of your DRAM.<br></div><div><br></div><div>physical address = kmalloc'ed address - PAGE_OFFSET + PHYS_OFFSET<br><br></div><div>MH<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 13, 2014 at 4:02 PM, mind entropy <span dir="ltr"><<a href="mailto:mindentropy@gmail.com" target="_blank">mindentropy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I want to know the physical address [just for debugging and info.Not<br>
for DMA etc] of a particular virtual address allocated via kmalloc.<br>
<br>
I am running the below code on S3C2440 with 64MB of RAM. The<br>
/proc/meminfo returns<br>
<br>
MemTotal: 59164 kB<br>
MemFree: 35884 kB<br>
MemAvailable: 47148 kB<br>
<br>
<br>
I run the following module for printing the addresses. [This module<br>
is only for test. So excuse if I have cut corners].<br>
<br>
------------------------------------------------<br>
<br>
#include <linux/init.h><br>
#include <linux/kernel.h><br>
#include <linux/printk.h><br>
#include <linux/module.h><br>
#include <linux/gfp.h><br>
#include <linux/types.h><br>
#include <linux/mm.h><br>
#include <linux/mm_types.h><br>
#include <linux/slab.h><br>
<br>
static int vm_mem_test_init(void)<br>
{<br>
<br>
void *km;<br>
<br>
printk(KERN_ALERT "vm mem test init\n");<br>
<br>
km = kmalloc(1,GFP_KERNEL);<br>
<br>
if(km == NULL) {<br>
printk(KERN_ALERT "Could not kmalloc\n");<br>
return -1;<br>
} else {<br>
printk(KERN_ALERT "Allocated\n");<br>
printk(KERN_ALERT "Virtual addr : %x\n",(unsigned int)km);<br>
printk(KERN_ALERT "Kernel physical addr : 0x%x\n",virt_to_phys(km));<br>
kfree(km);<br>
}<br>
<br>
return 0;<br>
<br>
}<br>
<br>
<br>
The output for the following is:<br>
<br>
Virtual addr : c2c080e0<br>
Kernel physical addr : 0x32c080e0<br>
<br>
-----------------------------------------------------------<br>
<br>
The kernel physical address is wrong as I only have 64MB. Should I be<br>
doing a kernel page table walk to get the associated physical address?<br>
<br>
Thanks<br>
Gautam.<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br></div>