LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 05-01-2015, 12:50 AM   #1
Vinny_P
LQ Newbie
 
Registered: May 2009
Posts: 4

Rep: Reputation: 0
Virtual to physical address translation


Hi all,

I have an embedded system running Linux. I would like to translate the virtual addresses to the physical address accessed by the processor.

What I tried:
When in the kernel space (in a kernel module), I used the virt_to_phys function. However, I later found out that this function only translates the virtual address created by kmalloc to physical address. I do have some virtual address created using ioremap that do not work with this function. I found this post: http://stackoverflow.com/questions/6...-kernel-module that states that you need to traverse the page table to reconstruct the physical address.

End goal:
I would like to pass any virtual address to a module and get the physical address translation. I would like virtual address created from kernel space (ioremap and kmalloc) or user space (malloc) to be translated.

I presume there is a function that the kernel uses to make its translation. I would like to hook into this function. I'm looking for guidance and help on this issue.

I am also available for a one-on-one chat if a discussion is needed since the topic is too complex to explain on a forum post.

Thank you in advance.
 
Old 05-01-2015, 03:12 AM   #2
Vinny_P
LQ Newbie
 
Registered: May 2009
Posts: 4

Original Poster
Rep: Reputation: 0
I noticed there is a iopa function that does what I need in the pgtable file. I would need to link this file (and the many other dependent files) to my modules Makefile. Is this a recommended approach? (It doesn't seem very simplistic). I was hoping to hook into this function more easily.

Any comments/suggestions?

Thanks.
 
Old 05-01-2015, 12:23 PM   #3
Vinny_P
LQ Newbie
 
Registered: May 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Here is the solution (snippet of code) from post#2:
Code:
// Address for symbol iopa
#include <linux/kallsyms.h>
#define IOPA_SYM "iopa"

// function address holder
unsigned long (*iopa_ptr)(unsigned long addr);

// in module function (say exit)
static int __init vinny_exit(void)
{
		unsigned long address = 0xF20A0000;//random address
		unsigned long new = iopa_ptr(address);
		printk("VAddr 0x%08lx translates to PAddr 0x%08lx\n", address, new);
}
// in module function (say init)
static int __init vinny_init(void)
{
	int iopa_address = kallsyms_lookup_name(IOPA_SYM);
	printk("Address of %s 0x%08x\n", IOPA_SYM, iopa_address);
	iopa_ptr = (void *) iopa_address;
}
Hope this helps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux kernel is running in physical address or virtual address? clp510 Linux - Kernel 8 06-04-2014 06:53 AM
linux kernel is running in physical address or virtual address? clp510 Linux - Newbie 3 06-03-2014 06:59 AM
When IOMMU is enabled, how to get the Kernel Virtual Address from a Physical address leechaotang Linux - Kernel 1 11-10-2011 12:21 AM
how to translate virtual address to physical address in linux application saurin Programming 1 11-18-2009 09:05 PM
Memory Mapping (same physical address = virtual address) skd.tech Linux - Kernel 7 07-24-2006 11:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 09:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration