Regarding accessing memory mapping of the pcie device
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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,
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.
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.