Skip to content

Commit 81bbf03

Browse files
niklas88hcahca
authored andcommitted
s390/pci: expose a PCI device's UID as its index
On s390 each PCI device has a user-defined ID (UID) exposed under /sys/bus/pci/devices/<dev>/uid. This ID was designed to serve as the PCI device's primary index and to match the device within Linux to the device configured in the hypervisor. To serve as a primary identifier the UID must be unique within the Linux instance, this is guaranteed by the platform if and only if the UID Uniqueness Checking flag is set within the CLP List PCI Functions response. In this sense the UID serves an analogous function as the SMBIOS instance number or ACPI index exposed as the "index" respectively "acpi_index" device attributes and used by e.g. systemd to set interface names. As s390 does not use and will likely never use ACPI nor SMBIOS there is no conflict and we can just expose the UID under the "index" attribute whenever UID Uniqueness Checking is active and get systemd's interface naming support for free. Link: https://lore.kernel.org/lkml/[email protected]/ Acked-by: Viktor Mihajlovski <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Acked-by: Narendra K <[email protected]> Signed-off-by: Niklas Schnelle <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent a637b3b commit 81bbf03

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

Documentation/ABI/testing/sysfs-bus-pci

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,13 @@ What: /sys/bus/pci/devices/.../index
195195
Date: July 2010
196196
Contact: Narendra K <[email protected]>, [email protected]
197197
Description:
198-
Reading this attribute will provide the firmware
199-
given instance (SMBIOS type 41 device type instance) of the
200-
PCI device. The attribute will be created only if the firmware
201-
has given an instance number to the PCI device.
198+
Reading this attribute will provide the firmware given instance
199+
number of the PCI device. Depending on the platform this can
200+
be for example the SMBIOS type 41 device type instance or the
201+
user-defined ID (UID) on s390. The attribute will be created
202+
only if the firmware has given an instance number to the PCI
203+
device and that number is guaranteed to uniquely identify the
204+
device in the system.
202205
Users:
203206
Userspace applications interested in knowing the
204207
firmware assigned device type instance of the PCI

arch/s390/pci/pci_sysfs.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,38 @@ static ssize_t uid_is_unique_show(struct device *dev,
138138
}
139139
static DEVICE_ATTR_RO(uid_is_unique);
140140

141+
#ifndef CONFIG_DMI
142+
/* analogous to smbios index */
143+
static ssize_t index_show(struct device *dev,
144+
struct device_attribute *attr, char *buf)
145+
{
146+
struct zpci_dev *zdev = to_zpci(to_pci_dev(dev));
147+
u32 index = ~0;
148+
149+
if (zpci_unique_uid)
150+
index = zdev->uid;
151+
152+
return sysfs_emit(buf, "%u\n", index);
153+
}
154+
static DEVICE_ATTR_RO(index);
155+
156+
static umode_t zpci_index_is_visible(struct kobject *kobj,
157+
struct attribute *attr, int n)
158+
{
159+
return zpci_unique_uid ? attr->mode : 0;
160+
}
161+
162+
static struct attribute *zpci_ident_attrs[] = {
163+
&dev_attr_index.attr,
164+
NULL,
165+
};
166+
167+
static struct attribute_group zpci_ident_attr_group = {
168+
.attrs = zpci_ident_attrs,
169+
.is_visible = zpci_index_is_visible,
170+
};
171+
#endif
172+
141173
static struct bin_attribute *zpci_bin_attrs[] = {
142174
&bin_attr_util_string,
143175
&bin_attr_report_error,
@@ -179,5 +211,8 @@ static struct attribute_group pfip_attr_group = {
179211
const struct attribute_group *zpci_attr_groups[] = {
180212
&zpci_attr_group,
181213
&pfip_attr_group,
214+
#ifndef CONFIG_DMI
215+
&zpci_ident_attr_group,
216+
#endif
182217
NULL,
183218
};

0 commit comments

Comments
 (0)