From mboxrd@z Thu Jan 1 00:00:00 1970 From: orca.chen@gmail.com (Miles MH Chen) Date: Sat, 13 Sep 2014 16:31:33 +0800 Subject: On virt_to_phys doubts. In-Reply-To: References: Message-ID: To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Hi, Do you know the value of PHYS_OFFSET of your platform? PHYS_OFFSET defines the starting physical address of your DRAM. physical address = kmalloc'ed address - PAGE_OFFSET + PHYS_OFFSET MH On Sat, Sep 13, 2014 at 4:02 PM, mind entropy wrote: > Hi, > > I want to know the physical address [just for debugging and info.Not > for DMA etc] of a particular virtual address allocated via kmalloc. > > I am running the below code on S3C2440 with 64MB of RAM. The > /proc/meminfo returns > > MemTotal: 59164 kB > MemFree: 35884 kB > MemAvailable: 47148 kB > > > I run the following module for printing the addresses. [This module > is only for test. So excuse if I have cut corners]. > > ------------------------------------------------ > > #include > #include > #include > #include > #include > #include > #include > #include > #include > > static int vm_mem_test_init(void) > { > > void *km; > > printk(KERN_ALERT "vm mem test init\n"); > > km = kmalloc(1,GFP_KERNEL); > > if(km == NULL) { > printk(KERN_ALERT "Could not kmalloc\n"); > return -1; > } else { > printk(KERN_ALERT "Allocated\n"); > printk(KERN_ALERT "Virtual addr : %x\n",(unsigned int)km); > printk(KERN_ALERT "Kernel physical addr : > 0x%x\n",virt_to_phys(km)); > kfree(km); > } > > return 0; > > } > > > The output for the following is: > > Virtual addr : c2c080e0 > Kernel physical addr : 0x32c080e0 > > ----------------------------------------------------------- > > The kernel physical address is wrong as I only have 64MB. Should I be > doing a kernel page table walk to get the associated physical address? > > Thanks > Gautam. > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies at kernelnewbies.org > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140913/342faf6a/attachment.html