Reputation: 1103
I have looked into similar questions on this site (listed at the end) but still feel like missing a couple points, hopefully someone can help here:
Is there a hook into the proc
file system that connects the /proc/iomem
inode
to a function that dumps the information? I wasn't able to find where in proc fs this function lives. I did a grep
under the linux source tree fs/proc
for iomem
, got nothing. So maybe it is a more of a procfs
question... The answer to this question might help me to dig up the answer to the next question..
The /proc/iomem
has more entries than the BIOS E820 information I extracted from either dmesg
or /sys/firmware/memmap
(these two are actually consistent with each other). For example, /sys/firmware/memmap
does not seem to have pci memory mapped regions. Drivers' init code calls the request_mem_region()
and add more info to the map, so somewhere there should be a global variable (root of all resources ?) that remembers this graph?
The questions on stackoverflow I have looked into:
Upvotes: 1
Views: 1833
Reputation: 291
struct resource iomem_resource
is what you're looking for, and it is defined and initialized in kernel/resource.c
(via proc_create_seq_data()
). In the same file, the instance struct seq_operations resource_op
defines what happens when you, for example cat
the file from userland.iomem_resource
is a globally exported symbol, and is used throughout the kernel, drivers included, to request resources. You can find instances scattered across the kernel of devm_/request_resource()
which take either iomem_resource
or its sibling ioport_resource
based on either fixed settings, or based on configurations. Examples of methods that take configurations are a) device trees which is prevalent in embedded settings, and b) E820 or UEFI, which can be found more on x86.Starting with b) which was asked in the question, the file arch/x86/kernel/e820.c
shows examples of how reserved memory gets inserted into /proc/iomem
via insert_resource()
.
This excellent link has more details on the dynamics of requesting memory map details from the BIOS.
Another alternative sequence (which relies on CONFIG_OF
) for how a device driver requests the needed resources is:
struct of_device_id
. struct platform_device
which contains both the struct of_device_id
and a probe function. This probing function is thus called.platform_get_resource()
is made which reads the reg
property from the device tree. This property defines the physical memory map for a specific device. devm_request_mem_region()
is made (which is just a call to request_region()
) to actually allocate the resources and add it to /proc/iomem
.Upvotes: 2