Getting memory map of every device in linux

十年热恋 提交于 2019-12-04 12:31:27

问题


How do I get memory map of all the physical devices that are recognized by Linux. I have already looked up at /proc/iomem and /proc/ioports. However, I was not able to find a per device memory maps. Any idea on how to achieve this?


回答1:


As far as I know the only generic way is /proc/iomem. That shows you the kernels of view of what memory ranges are assigned to who.

If you want more detail you'll need to look at each individual driver.

You might get some more information from /proc/vmallocinfo because ioremap() uses vmalloc (though possibly not on all architectures).




回答2:


Where your machine's peripherals registers are located? Previous answers already gave you valuable inputs I believe. Combination of /proc/iomem and /proc/vmallocinfo provide you a lot of information. Please note that with vmalloc, you'll need to dig into the kernel source code to associate the function name with the device's driver.

But true question is what you want to know exactly? For what purpose do you want this information?

It seems to me that you are trying to directly access a device's physical memory, where you should rely on ioctl, sysfs, or existing services provided by the driver to "talk" with the device.

Don't forget this : if Linux does not show you the information you want, it is probably because you are not looking for the right information, or you are trying to bypass existing services. From user-space point of view, ie apps, you should never care of physical memory location.




回答3:


When I remember my kernel coding times right, the output of iomem/ports just lists what a driver registers there. So it is more a per-driver instead a per-device output.

As most devices are today pci devices a lspci -v is maybe the best you can get, which shows used memory and io ports.




回答4:


This question is way old, but I've struggled with this issue for a few days while trying to install Linux (still a newbie).

From what I've gathered, each device is uniquely identified by whether it's a block or a character device, and also by a major:minor number.

In the /sys/dev, folder, there are symbolic links for each block/character device located in their respective folders. These are links to physical device info within the /sys folder.

There are parallel block/char folders within the /dev folder, each of which has corresponding symbolic links. These symbolic links are to the actual device files in the /dev folder.

So if you can get the major:minor of a device, you can map devices in /dev to devices in /sys. For drives, you can get the major:minor with lsblk.



来源:https://stackoverflow.com/questions/10334596/getting-memory-map-of-every-device-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!