PCI/sysfs: Convert "config" to static attribute
The "config" sysfs attribute allows access to either the legacy (PCI and
PCI-X Mode 1) or the extended (PCI-X Mode 2 and PCIe) device configuration
space. Previously it was dynamically created either when a device was
added (for hot-added devices) or via a late_initcall (for devices present
at boot):
pci_bus_add_devices
pci_bus_add_device
pci_create_sysfs_dev_files
if (!sysfs_initialized)
return
sysfs_create_bin_file # for hot-added devices
pci_sysfs_init # late_initcall
sysfs_initialized = 1
for_each_pci_dev(pdev)
pci_create_sysfs_dev_files(pdev) # for devices present at boot
And dynamically removed when the PCI device is stopped and removed:
pci_stop_bus_device
pci_stop_dev
pci_remove_sysfs_dev_files
sysfs_remove_bin_file
This attribute does not need to be created or removed dynamically, so we
can use a static attribute so the device model takes care of addition and
removal automatically.
Convert "config" to a static attribute and use the .is_bin_visible()
callback to set the correct object size (either 256 bytes or 4 KiB) at
runtime.
The pci_sysfs_init() scheme was added in the pre-git era by
https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/drivers/pci/pci-sysfs.c?id=
f6d553444da2
[bhelgaas: commit log]
Suggested-by: Oliver O'Halloran <oohall@gmail.com>
Link: https://lore.kernel.org/r/CAOSf1CHss03DBSDO4PmTtMp0tCEu5kScn704ZEwLKGXQzBfqaA@mail.gmail.com
Link: https://lore.kernel.org/r/20210416205856.3234481-2-kw@linux.com
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>