LinuxQuestions.org
Visit Jeremy's Blog.
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 03-19-2013, 06:53 AM   #1
tamilvanan
LQ Newbie
 
Registered: Sep 2012
Posts: 10

Rep: Reputation: Disabled
Regarding accessing memory mapping of the pcie device


Hi Everyone,

I like to know about how a physical memory is linked to virtual memory ,for example if u type a command lspci -v , i have found the pcie ethernet controller ,is possible to access Memory of it, if so what are the functions used to do .

02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06)
Subsystem: Giga-byte Technology GA-EP45-DS5/GA-EG45M-DS2H Motherboard
Flags: bus master, fast devsel, latency 0, IRQ 40
I/O ports at de00 [size=256]
Memory at fbeff000 (64-bit, prefetchable) [size=4K]
Memory at fbef8000 (64-bit, prefetchable) [size=16K]

Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable+ Count=1/1 Maskable- 64bit+
Capabilities: [70] Express Endpoint, MSI 01
Capabilities: [b0] MSI-X: Enable- Count=4 Masked-
Capabilities: [d0] Vital Product Data
Capabilities: [100] Advanced Error Reporting
Capabilities: [140] Virtual Channel
Capabilities: [160] Device Serial Number 12-34-56-78-12-34-56-78
Kernel driver in use: r8169
Kernel modules: r8169
regards,

Tamil
 
Old 03-19-2013, 11:08 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
It is possible to access the memory of a PCI device, but you probably should not. For sure, you will need root privileges. All of this is conceptually different from virtual memory. To access memory mapped into PCI space from a userspace process, you would use mmap(). There is a reasonable jumping-off point for further research at Bill Farrow's Blog, which I found by doing a Google search for 'mmap pci memory'.
--- rod.
 
1 members found this post helpful.
Old 03-20-2013, 11:33 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Almost forgot. There is also the /dev/mem interface that allows you to access memory arbitrarily from userspace. It abstracts memory access to use filesystem semantics. Still requires root privileges, of course.
--- rod.
 
Old 03-20-2013, 01:13 PM   #4
tamilvanan
LQ Newbie
 
Registered: Sep 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Regarding Accessing the PCie Memory region

Hi theNbomr,

Thanks for your useful reply,I find its very useful. I too have few doubts in the program available in the blog you have suggested .
1)why should i need to open the resource file
fd = open("/sys/devices/pci0001\:00/0001\:00\:07.0/resource0", O_RDWR | O_SYNC);

is there a way to use without it or shall i able to create my own which shows the memory address of the pcie device.

2)Memory at fbeff000 (64-bit, prefetchable) [size=4K]
Memory at fbef8000 (64-bit, prefetchable) [size=16K] (please refer to my first conversation) is it possible for to access the memory by directly providing the address . If this question is not valid please excuse me and please provide me necessary docs or links to understand.i am a newbie

regards,

Tamil
 
Old 03-20-2013, 04:41 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I guess if you are need to have a file descriptor, it might as well serve the purpose of confirming that the device you're trying to mmap() actually exists. If the entry doesn't exist in /sys/devices, then there is no point in proceding further. You are not bound to do this if you don't want to; any open file descriptor will do.

If by 'access the memory by directly providing the address' you mean assigning the address to a pointer, and then dereferencing the pointer, then no. You can't do that from userspace. From kernel space, you are not so constrained. I gather from the nature of your question, you are not programming in kernel space. If any program could do that, it would be trivial to circumvent system security by directly accessing hardware.

--- rod.
 
Old 03-21-2013, 09:09 AM   #6
tamilvanan
LQ Newbie
 
Registered: Sep 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Reg direct memory access

Hi theNbomr,

Thanks for your reply,ya i have understood i cant able to access it from userspace.if wanna to access from kernel space which function i should use.

Regards,

Tamil
 
Old 03-21-2013, 09:12 AM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Simple pointer indirection should work fine from kernel space. You will need to do a lot of work to understand all the rest of the implications of coding in kernel space.
--- rod.
 
  


Reply

Tags
devicedrivers, memory management


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
mapping device memory to userspace in embeded environment in coldfire processor clnbabu Linux - Kernel 5 10-03-2011 02:17 PM
PCIe dma-able memory location in physical memory for Intel Nehalem / Tylersburg arch robvoo Linux - Kernel 4 07-31-2009 06:21 AM
Help!?! RH 8 Memory Mapping -High Memory-Virtural Memory issues.. Merlin53 Linux - Hardware 2 06-18-2003 04:48 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 > Non-*NIX Forums > Programming

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