获取linux中每个设备的内存映射
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10334596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting memory map of every device in linux
提问by manugupt1
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?
如何获取 Linux 识别的所有物理设备的内存映射。我已经查过 /proc/iomem 和 /proc/ioports。但是,我无法找到每个设备的内存映射。关于如何实现这一目标的任何想法?
回答by flolo
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.
当我记得我的内核编码时间时,iomem/ports 的输出只是列出了驱动程序在那里注册的内容。所以它更像是每个驱动程序而不是每个设备的输出。
As most devices are today pci devices a lspci -v
is maybe the best you can get, which shows used memory and io ports.
由于当今大多数设备都是 pci 设备,alspci -v
可能是您能得到的最好的设备,它显示了已使用的内存和 io 端口。
回答by mpe
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.
据我所知,唯一的通用方法是/proc/iomem
. 这向您展示了内存范围分配给谁的内核。
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).
您可能会从中获得更多信息,/proc/vmallocinfo
因为ioremap()
用途vmalloc
(尽管可能不是在所有架构上)。
回答by m-ric
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.
您机器的外围设备寄存器位于何处?我相信以前的答案已经为您提供了宝贵的意见。结合/proc/iomem
并/proc/vmallocinfo
为您提供大量信息。请注意,使用vmalloc
,您需要深入研究内核源代码以将函数名称与设备驱动程序相关联。
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.
在我看来,您正在尝试直接访问设备的物理内存,您应该依赖 ioctl、sysfs 或驱动程序提供的现有服务与设备“对话”。
Don't forget this : if Linux does not show you the information you want, it is probably because you are notlooking 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.
不要忘记这一点:如果 Linux 没有向您显示您想要的信息,这可能是因为您没有在寻找正确的信息,或者您正试图绕过现有服务。从用户空间的角度来看,即应用程序,你永远不应该关心物理内存位置。
回答by kibichii
This question is way old, but I've struggled with this issue for a few days while trying to install Linux (still a newbie).
这个问题已经很老了,但是我在尝试安装 Linux 时已经为这个问题苦苦挣扎了几天(仍然是新手)。
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.
在 /sys/dev, 文件夹中,每个块/字符设备都位于其各自文件夹中的符号链接。这些是指向 /sys 文件夹中物理设备信息的链接。
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.
/dev 文件夹中有并行的 block/char 文件夹,每个文件夹都有对应的符号链接。这些符号链接指向 /dev 文件夹中的实际设备文件。
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.
因此,如果您可以获得设备的主要:次要,则可以将 /dev 中的设备映射到 /sys 中的设备。对于驱动器,您可以使用 lsblk 获取主要:次要。