[PATCH v2 0/7] PCI: Convert dynamic PCI resources sysfs objects into static

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Currently, a lot of PCI-related sysfs objects are dynamically created
under the "/sys/bus/pci/devices/..." path when either the PCI driver is
initialised or when a new device is hot-added.

When PCI driver loads and the PCI sub-system initialises, the sysfs
attributes are then added when late_initcall() function is called:

    pci_sysfs_init
      sysfs_initialized = 1
      for_each_pci_dev
        pci_create_sysfs_dev_files
          sysfs_create_bin_file

Otherwise, for hot-added devices, the sysfs attributes are then added
when the pci_bus_add_devices() function is called:

  pci_bus_add_devices
    pci_bus_add_device
      pci_create_sysfs_dev_files
        if (!sysfs_initialized)
	  return
        sysfs_create_bin_file

When a device is removed the pci_remove_sysfs_dev_files() function is
called from pci_stop_dev() to remove all the attributes that were
previously added:

  pci_stop_bus_device
    pci_stop_dev
      if (pci_dev_is_added)
        pci_remove_sysfs_dev_files
          sysfs_remove_bin_file

The current implementation is known to cause problems:

  https://lore.kernel.org/linux-pci/1366196798-15929-1-git-send-email-artem.savkov@xxxxxxxxx/
  https://lore.kernel.org/linux-pci/20200716110423.xtfyb3n6tn5ixedh@pali/
  https://lore.kernel.org/linux-pci/m3eebg9puj.fsf@xxxxxxxxxxx/
  https://lore.kernel.org/linux-pci/20210507102706.7658-1-danijel.slivka@xxxxxxx/

Most of the PCI-related attributes do not need to be created and removed
dynamically and there is no need to also manage their create and remove
life cycle manually.

The aim is also to first reduce the reliance on using late_initcall() to
eventually remove the need for it completely.

This particular series focusing on PCI resources files on platforms that
provide either the HAVE_PCI_MMAP or ARCH_GENERIC_PCI_MMAP_RESOURCE
definitions (other platforms, such as the Alpha platform, will not be
affected) continues the on-going effort to convert the majority of the
dynamic sysfs objects into static ones so that the PCI driver core can
add and remove sysfs objects and related attributes automatically.

Please note that this series depends on the commits from the following
series to be added prior to applying it:

  https://lore.kernel.org/linux-pci/20210729233235.1508920-1-kw@xxxxxxxxx/
  https://lore.kernel.org/linux-pci/20210812132144.791268-1-kw@xxxxxxxxx/

	Krzysztof

---
Changes in v2:
  Refactored code so that the macros, helpers and internal functions can
  be used to correctly leverage the read(), write() and mmap() callbacks
  rather than to use the .is_bin_visible() callback to set up sysfs
  objects internals as this is not supported.
  Refactored some if-statements to check for a resource flag first, and
  then call either arch_can_pci_mmap_io() or arch_can_pci_mmap_wc(),
  plus store result of testing for IORESOURCE_MEM and
  IORESOURCE_PREFETCH flags into a boolean variable, as per Bjorn
  Helgaas' suggestion.
  Renamed pci_read_resource_io() and pci_write_resource_io() callbacks
  so that these are not specifically tied to I/O BARs read() and write()
  operations also as per Bjorn Helgaas' suggestion.
  Updated style for code handling bitwise operations to match the style
  that is preferred as per Bjorn Helgaas' suggestion.
  Updated commit messages adding more details about the implementation
  as requested by Bjorn Helgaas.

Krzysztof Wilczyński (7):
  PCI/sysfs: Add pci_dev_resource_attr_is_visible() helper
  PCI/sysfs: Add pci_dev_resource_attr() macro
  PCI/sysfs: Only allow IORESOURCE_IO in pci_resource_io()
  PCI/sysfs: Only allow supported resource type in pci_mmap_resource()
  PCI/sysfs: Convert PCI resource files to static attributes
  PCI/sysfs: Rename pci_read_resource_io() and pci_write_resource_io()
  PCI/sysfs: Update code to match the preferred style

 drivers/pci/pci-sysfs.c | 213 +++++++++++++++++++++-------------------
 include/linux/pci.h     |   2 +
 2 files changed, 116 insertions(+), 99 deletions(-)

-- 
2.33.0




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux