At present, I have a Linux 2.6 kernel module which accesses a certain device via pci_get_device() and pci_read_config_dword(). In future, the module shall be modified to also work a different machine which seems to have no PCI bus (/sys/bus/pci doesn't exist), but has the certain device at a fixed, known address. Now, I would like to have one module binary without parameters which works on both machines. To be able to load the module on the non-PCI machine, I think I must refrain from using pci_get_device() etc.; thus I have to get the needed config space info on the PCI machine in some other way. I could read it from /sys/bus/pci/devices/.../resource in my init_module(), but I gather it is considered bad practice to make kernel modules read files. Are there better ways to achieve my goal?
0
votes
1 Answers
0
votes
When functions like pci_get_device() cannot be used (because the module must work also with kernels that don't provide such functions), apparently there is no better way to get the PCI address info than reading /sys/bus/pci/devices/.../resource.
I resorted to doing so, using filp_open(), vfs_read() and filp_close() on the basis of How to read/write files within a Linux kernel module?.
pci_get_deviceis not the standard way to write drivers for PCI devices. Have you read the PCI chapter of "Linux Device Drivers 3"? - Peterpci_register_driver()instead ofpci_get_device()doesn't suit. @BenjaminLeinweber: The CPU in both systems is a PowerPC MPC5200. Yes, there are device-trees in both systems. - Armali/sys/bus/pci/devices/.../resource? - Armali