LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-23-2011, 07:52 AM   #1
clnbabu
LQ Newbie
 
Registered: Aug 2007
Posts: 8

Rep: Reputation: 0
mapping device memory to userspace in embeded environment in coldfire processor


In my embedded board there is a alphanumeric display.It is 5 bytes in size. We are using linux-2.6.25 kernel.
Now i am accessing the memory in my kernel driver like below.

DISP_ADDR 0xfB80020

unsigned short *disp_base;
if(!disp_base =ioremap(DISP_ADDR, 0x05)
{
printk("ioremap fialed");return -1;
}

It is working fine. i am using disp_base in further part of dirver for accessing. Now i want to remap this to userspace. So that i can directly access form the userspace. Please help me out. I only now that in the file operations i have to write mmap function. Please help me how to write this mmap function in detail. I am new to this linux.

Last edited by clnbabu; 09-23-2011 at 08:27 AM.
 
Old 09-23-2011, 02:09 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
The book has a good example, Linux Device Drivers: http://lwn.net/Kernel/LDD3/.
 
Old 09-29-2011, 12:08 AM   #3
clnbabu
LQ Newbie
 
Registered: Aug 2007
Posts: 8

Original Poster
Rep: Reputation: 0
i have gone through the book, i implemented like this in kernel

int disp_mmap(struct file *file, struct vm_area_struct *vma)
{
if(remap_pfn_range(vma,vma->vm_start,DISP_ADDR >>PAGE_SHIFT,0x05,vma->vm_page_prot))
return -EAGAIN;
return 0;
}

in usermode i tried to access the pointer like this

map_buff=mmap(0,0x05,PROT_READ| PROT_WRITE, MAP_FILE|MAP_SHARED,disp_fd,0);

i am getting the error as below.

"Unable to handle kernel access at virtual address 0xc756804b"

Please help me out
 
Old 09-30-2011, 02:26 PM   #4
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
You should read section, Remapping Specific I/O Regions, again. The remap_pfn_range parameter is wrong.
 
Old 10-03-2011, 02:22 AM   #5
clnbabu
LQ Newbie
 
Registered: Aug 2007
Posts: 8

Original Poster
Rep: Reputation: 0
in the remap_pfn_range,function
remap_pfn_range(vma,vma->vm_start,DISP_ADDR >>PAGE_SHIFT,0x05,vma->vm_page_prot)

I think problem may be in physical address parameter.
Can you please point out which paremeter is represented wrongly.

thanks and regards
babu
 
Old 10-03-2011, 02:17 PM   #6
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
I copied and pasted some example code from book.


The following does the trick for a driver mapping a region of simple_region_size bytes, beginning at physical address simple_region_start (which should be page-aligned):

unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
unsigned long physical = simple_region_start + off;
unsigned long vsize = vma->vm_end - vma->vm_start;
unsigned long psize = simple_region_size - off;

if (vsize > psize)
return -EINVAL; /* spans too high */
remap_pfn_range(vma, vma_>vm_start, physical, vsize, vma->vm_page_prot);
 
  


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 Virtual memory mapping to Board memory map !rajkums! Linux - Kernel 4 10-19-2008 12:27 PM
Help!?! RH 8 Memory Mapping -High Memory-Virtural Memory issues.. Merlin53 Linux - Hardware 2 06-18-2003 04:48 PM
RH 8.0 Mapping Virtual Memory to get access to VMIC Reflective Memory PCI card. Merlin53 Linux - Hardware 0 05-05-2003 12:50 PM
physical scsi channel mapping to scsiX device node mapping, how to configure manually drthornt Linux - Hardware 3 02-09-2003 11:50 AM
Memory mapping a device PLEASE HELP!!!! mpalmer Linux - Newbie 1 08-16-2001 03:09 PM

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

All times are GMT -5. The time now is 02:24 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