LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-29-2013, 05:42 AM   #1
dgashu
Member
 
Registered: Apr 2010
Location: Banglore
Distribution: fedora , rhel,Ubuntu
Posts: 61

Rep: Reputation: 1
Unhappy Can we perform TWO MMAP operation on same /dev file


I have build an character driver in which i am allocating two PAGESIZE buffer using dma_alloc_coherent

Now i am passing the PHYSICAL address of these BUFFER
[src_ptr & dest_ptr] to user space using IOCTL as source_offset and dest_offset .

In user space this offeset is used as an offset for mmap call.
So on same /dev file say /dev/250 i am making TWO MMAP call

usr_src_ptr= mmap(0,page_size, PROT_READ|PROT_WRITE,MAP_SHARED, dev_FD,src_offset );
if (usr_src_ptr == MAP_FAILED){
printf("USR[UPP]:SOURCE MMAP FAiled \n\n");
close(dev_FD);
exit(-1);
}else{
printf("USR[UPP]:SOURCE MMAP is %X..\n",usr_src_ptr);
}

usr_dest_ptr= mmap(0,page_size, PROT_READ|PROT_WRITE,MAP_SHARED,dev_FD,dest_offset );

if (usr_dest_ptr == MAP_FAILED){
printf("USR[UPP]DEST MMAP FAiled \n\n");
close(dev_FD);
exit(-1);
}else{
printf("USR[UPP]DEST MMAP is %X..\n",usr_dest_ptr);
}


1. I am writing 0x77 in user_src_ptr in user space & printing
user_src_ptr in user space and dest_src_ptr in KERNEL space .
I get correct data for both user and kernel space

2. I am writng 0x55 in dest_ptr in kernel space & printing dest_ptr
in kernel space and usr_dest_ptr in user space.
NOW FOR THIS CASE I GET CORRECT DATA I.E 0X55 IN KERNEL BUFFER
dest_ptR , BUT THE USER SPACE BUFFER OF DESTINATION ALWAYS
RETURNS 0X77 . i.e THE DATA WHICH I HAVE WRITTEN IN usr_src_ptr.


Can any one please let me know if we can do TWO MMAP operation on same file at different OFFSET ?????

Thank You Ashish Mishra

Last edited by dgashu; 01-29-2013 at 06:02 AM.
 
Old 01-29-2013, 06:39 AM   #2
dgashu
Member
 
Registered: Apr 2010
Location: Banglore
Distribution: fedora , rhel,Ubuntu
Posts: 61

Original Poster
Rep: Reputation: 1
The issue was with :-
if ((ret = remap_pfn_range(vma,vma->vm_start,
(virt_to_phys((void *)src_ptr) >> PAGE_SHIFT),
size,vma->vm_page_prot)) < 0)
{
return ret;
}

Due to this ir-respective of offset , i was getting mapped to same PHYSICAL address
 
Old 01-30-2013, 07:16 AM   #3
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
Originally Posted by dgashu View Post
Now i am passing the PHYSICAL address of these BUFFER [src_ptr & dest_ptr] to user space using IOCTL as source_offset and dest_offset.
You are doing it wrong. Why are you passing physical address to user space? Why does user space need to know it?

Quote:
Originally Posted by dgashu View Post
Can any one please let me know if we can do TWO MMAP operation on same file at different OFFSET?
Of course.
 
Old 01-31-2013, 09:48 AM   #4
dgashu
Member
 
Registered: Apr 2010
Location: Banglore
Distribution: fedora , rhel,Ubuntu
Posts: 61

Original Poster
Rep: Reputation: 1
Mina86 ,
Actually i wanted to do an mmap of two kernel buffer of my character driver.
So on single /dev file i am doing an mmap of two buffer .
To distinguish these buffer i am using PHYSICAL address of both buffer as an OFFSET parameter from user space .

IS THIS MECHANISM CORRECT !!!!!!!!!!!!!
 
  


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
Kernels refuses to mmap (open FD) on /dev/mem ( CAP_SYS_RAWIO) DannyGilbert Linux - Kernel 5 08-04-2009 10:30 PM
mmap /dev/mem on arm11 mpcore with linux 2.6.23 debrupam Linux - Kernel 0 06-21-2009 08:14 AM
mmap /dev/mem returns 0 stz Programming 2 11-27-2006 12:11 AM
mmap() of /dev/kmem - can it work? wwc Programming 1 02-04-2006 01:47 PM
Quake 1, snd_linux.c using mmap(/dev/dsp) randyding Programming 1 06-19-2005 09:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:54 PM.

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