LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-29-2008, 04:44 PM   #1
fardad
LQ Newbie
 
Registered: Apr 2008
Posts: 11

Rep: Reputation: 0
mmap a physical address


Hi --

I am trying to map a PCI physical address bar to my user space program. In order to be able to map this physical address to user space I am creating a dummy character driver and capture the bar address in my driver. Later, I send this address to user (using IOCTL) and call mmap on the physical address.

As you can see I am not trying to map a file or something, I am trying to map the real physical memory which I know its address.

I am calling mmap() as follow:

mmap(0 , mem_length , PORT_READ|PROT_WRITE|MAP_SHARED, fd , offset);

1) mem_length = phy_addr_end - phy_addr_start
2) fd = open("/dev/_dummy_char_dev_name", O_WRONLY)
3) offset = phy_addr_start

mmap is returing MAP_FAILED . Could you please give me some hint on this?

also, my kernel mosule map funciton is as follow:


kernel_map(struct file * filp , struct vm_area_struct * vma)
{
remap_pfn_range(vma,vma->vm_Start,
vma->pgoff,
vma->vm_end-vma->vm_Start,
vm->vm_page_prot)

rturn 0
}


any help is much appreciated.
 
Old 10-29-2008, 05:08 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,535

Rep: Reputation: 148Reputation: 148
What is the error code in errno? My guess is (from mmap manual):
Quote:
EACCES A file descriptor refers to a non-regular file. Or MAP_PRIVATE was requested, but fd is not open for reading. Or MAP_SHARED was
requested and PROT_WRITE is set, but fd is not open in read/write (O_RDWR) mode. Or PROT_WRITE is set, but the file is append-only.
You have MAP_SHARED and PROT_READ, but open the file only with O_WRONLY.
 
Old 10-29-2008, 06:46 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
(nevermind)
ta0kira

Last edited by ta0kira; 10-29-2008 at 06:53 PM.
 
Old 10-30-2008, 11:30 AM   #4
fardad
LQ Newbie
 
Registered: Apr 2008
Posts: 11

Original Poster
Rep: Reputation: 0
Mara,

thank you so much for your advise. I changed O_WRONLY to O_RDWR and it worked.

Fardad
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Question on using mmap to access physical memory Gnu2Linux2 Linux - Embedded & Single-board computer 1 10-05-2009 03:54 AM
Mmap and munmap physical address to user space karttik Linux - Software 0 10-28-2007 02:10 AM
how to find physical address of kernel virtual address kushneeraj Programming 0 10-20-2006 07:29 PM
API for mapping Physical Address to Virtual Address Lakshman_smt Linux - Software 2 10-15-2006 09:08 PM
Memory Mapping (same physical address = virtual address) skd.tech Linux - Kernel 7 07-24-2006 11:13 PM


All times are GMT -5. The time now is 10:05 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration