PCI/sysfs: Convert "index", "acpi_index", "label" to static attributes
The "label", "index", and "acpi_index" sysfs attributes show firmware label information about the device. If the ACPI Device Name _DSM is implemented for the device, we have: label Device name (optional, may be null) acpi_index Instance number (unique under \_SB scope) When there is no ACPI _DSM and SMBIOS provides an Onboard Devices structure for the device, we have: label Reference Designation, e.g., a silkscreen label index Device Type Instance Previously these attributes were dynamically created either by pci_bus_add_device() or the pci_sysfs_init() initcall, but since they don't need to be created or removed dynamically, we can use a static attribute so the device model takes care of addition and removal automatically. Convert "label", "index", and "acpi_index" to static attributes. Presence of the ACPI _DSM (device_has_acpi_name()) determines whether the ACPI information (label, acpi_index) or the SMBIOS information (label, index) is visible. [bhelgaas: commit log, split to separate patch, add "pci_dev_" prefix] Suggested-by: Oliver O'Halloran <oohall@gmail.com> Link: https://lore.kernel.org/r/20210416205856.3234481-6-kw@linux.com Signed-off-by: Krzysztof Wilczyński <kw@linux.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
parent
4dd7dfa166
commit
506140f9c0
|
@ -101,6 +101,9 @@ static umode_t smbios_attr_is_visible(struct kobject *kobj, struct attribute *a,
|
|||
dev = kobj_to_dev(kobj);
|
||||
pdev = to_pci_dev(dev);
|
||||
|
||||
if (device_has_acpi_name(dev))
|
||||
return 0;
|
||||
|
||||
if (!find_smbios_instance_string(pdev, NULL, SMBIOS_ATTR_NONE))
|
||||
return 0;
|
||||
|
||||
|
@ -136,29 +139,10 @@ static struct attribute *smbios_attrs[] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group smbios_attr_group = {
|
||||
const struct attribute_group pci_dev_smbios_attr_group = {
|
||||
.attrs = smbios_attrs,
|
||||
.is_visible = smbios_attr_is_visible,
|
||||
};
|
||||
|
||||
static int pci_create_smbiosname_file(struct pci_dev *pdev)
|
||||
{
|
||||
return sysfs_create_group(&pdev->dev.kobj, &smbios_attr_group);
|
||||
}
|
||||
|
||||
static void pci_remove_smbiosname_file(struct pci_dev *pdev)
|
||||
{
|
||||
sysfs_remove_group(&pdev->dev.kobj, &smbios_attr_group);
|
||||
}
|
||||
#else
|
||||
static inline int pci_create_smbiosname_file(struct pci_dev *pdev)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline void pci_remove_smbiosname_file(struct pci_dev *pdev)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ACPI
|
||||
|
@ -253,45 +237,8 @@ static struct attribute *acpi_attrs[] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group acpi_attr_group = {
|
||||
const struct attribute_group pci_dev_acpi_attr_group = {
|
||||
.attrs = acpi_attrs,
|
||||
.is_visible = acpi_attr_is_visible,
|
||||
};
|
||||
|
||||
static int pci_create_acpi_index_label_files(struct pci_dev *pdev)
|
||||
{
|
||||
return sysfs_create_group(&pdev->dev.kobj, &acpi_attr_group);
|
||||
}
|
||||
|
||||
static int pci_remove_acpi_index_label_files(struct pci_dev *pdev)
|
||||
{
|
||||
sysfs_remove_group(&pdev->dev.kobj, &acpi_attr_group);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static inline int pci_create_acpi_index_label_files(struct pci_dev *pdev)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int pci_remove_acpi_index_label_files(struct pci_dev *pdev)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void pci_create_firmware_label_files(struct pci_dev *pdev)
|
||||
{
|
||||
if (device_has_acpi_name(&pdev->dev))
|
||||
pci_create_acpi_index_label_files(pdev);
|
||||
else
|
||||
pci_create_smbiosname_file(pdev);
|
||||
}
|
||||
|
||||
void pci_remove_firmware_label_files(struct pci_dev *pdev)
|
||||
{
|
||||
if (device_has_acpi_name(&pdev->dev))
|
||||
pci_remove_acpi_index_label_files(pdev);
|
||||
else
|
||||
pci_remove_smbiosname_file(pdev);
|
||||
}
|
||||
|
|
|
@ -1380,18 +1380,10 @@ static const struct attribute_group pci_dev_reset_attr_group = {
|
|||
|
||||
int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (!sysfs_initialized)
|
||||
return -EACCES;
|
||||
|
||||
retval = pci_create_resource_files(pdev);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
pci_create_firmware_label_files(pdev);
|
||||
|
||||
return 0;
|
||||
return pci_create_resource_files(pdev);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1406,7 +1398,6 @@ void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
|
|||
return;
|
||||
|
||||
pci_remove_resource_files(pdev);
|
||||
pci_remove_firmware_label_files(pdev);
|
||||
}
|
||||
|
||||
static int __init pci_sysfs_init(void)
|
||||
|
@ -1501,6 +1492,12 @@ const struct attribute_group *pci_dev_groups[] = {
|
|||
&pci_dev_rom_attr_group,
|
||||
&pci_dev_reset_attr_group,
|
||||
&pci_dev_vpd_attr_group,
|
||||
#ifdef CONFIG_DMI
|
||||
&pci_dev_smbios_attr_group,
|
||||
#endif
|
||||
#ifdef CONFIG_ACPI
|
||||
&pci_dev_acpi_attr_group,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
|
@ -21,16 +21,10 @@ bool pcie_cap_has_rtctl(const struct pci_dev *dev);
|
|||
|
||||
int pci_create_sysfs_dev_files(struct pci_dev *pdev);
|
||||
void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
|
||||
#if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI)
|
||||
static inline void pci_create_firmware_label_files(struct pci_dev *pdev)
|
||||
{ return; }
|
||||
static inline void pci_remove_firmware_label_files(struct pci_dev *pdev)
|
||||
{ return; }
|
||||
#else
|
||||
void pci_create_firmware_label_files(struct pci_dev *pdev);
|
||||
void pci_remove_firmware_label_files(struct pci_dev *pdev);
|
||||
#endif
|
||||
void pci_cleanup_rom(struct pci_dev *dev);
|
||||
#ifdef CONFIG_DMI
|
||||
extern const struct attribute_group pci_dev_smbios_attr_group;
|
||||
#endif
|
||||
|
||||
enum pci_mmap_api {
|
||||
PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
|
||||
|
@ -695,6 +689,7 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL
|
|||
|
||||
#ifdef CONFIG_ACPI
|
||||
int pci_acpi_program_hp_params(struct pci_dev *dev);
|
||||
extern const struct attribute_group pci_dev_acpi_attr_group;
|
||||
#else
|
||||
static inline int pci_acpi_program_hp_params(struct pci_dev *dev)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue