Release 4.7 drivers/pci/pci-label.c
/*
* Purpose: Export the firmware instance and label associated with
* a pci device to sysfs
* Copyright (C) 2010 Dell Inc.
* by Narendra K <Narendra_K@dell.com>,
* Jordan Hargrave <Jordan_Hargrave@dell.com>
*
* PCI Firmware Specification Revision 3.1 section 4.6.7 (DSM for Naming a
* PCI or PCI Express Device Under Operating Systems) defines an instance
* number and string name. This code retrieves them and exports them to sysfs.
* If the system firmware does not provide the ACPI _DSM (Device Specific
* Method), then the SMBIOS type 41 instance number and string is exported to
* sysfs.
*
* SMBIOS defines type 41 for onboard pci devices. This code retrieves
* the instance number and string from the type 41 record and exports
* it to sysfs.
*
* Please see http://linux.dell.com/files/biosdevname/ for more
* information.
*/
#include <linux/dmi.h>
#include <linux/sysfs.h>
#include <linux/pci.h>
#include <linux/pci_ids.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/nls.h>
#include <linux/acpi.h>
#include <linux/pci-acpi.h>
#include "pci.h"
#ifdef CONFIG_DMI
enum smbios_attr_enum {
SMBIOS_ATTR_NONE = 0,
SMBIOS_ATTR_LABEL_SHOW,
SMBIOS_ATTR_INSTANCE_SHOW,
};
static size_t find_smbios_instance_string(struct pci_dev *pdev, char *buf,
enum smbios_attr_enum attribute)
{
const struct dmi_device *dmi;
struct dmi_dev_onboard *donboard;
int bus;
int devfn;
bus = pdev->bus->number;
devfn = pdev->devfn;
dmi = NULL;
while ((dmi = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD,
NULL, dmi)) != NULL) {
donboard = dmi->device_data;
if (donboard && donboard->bus == bus &&
donboard->devfn == devfn) {
if (buf) {
if (attribute == SMBIOS_ATTR_INSTANCE_SHOW)
return scnprintf(buf, PAGE_SIZE,
"%d\n",
donboard->instance);
else if (attribute == SMBIOS_ATTR_LABEL_SHOW)
return scnprintf(buf, PAGE_SIZE,
"%s\n",
dmi->name);
}
return strlen(dmi->name);
}
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 154 | 99.35% | 1 | 50.00% |
al viro | al viro | 1 | 0.65% | 1 | 50.00% |
| Total | 155 | 100.00% | 2 | 100.00% |
static umode_t smbios_instance_string_exist(struct kobject *kobj,
struct attribute *attr, int n)
{
struct device *dev;
struct pci_dev *pdev;
dev = kobj_to_dev(kobj);
pdev = to_pci_dev(dev);
return find_smbios_instance_string(pdev, NULL, SMBIOS_ATTR_NONE) ?
S_IRUGO : 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 55 | 96.49% | 1 | 33.33% |
geliang tang | geliang tang | 1 | 1.75% | 1 | 33.33% |
al viro | al viro | 1 | 1.75% | 1 | 33.33% |
| Total | 57 | 100.00% | 3 | 100.00% |
static ssize_t smbioslabel_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pci_dev *pdev;
pdev = to_pci_dev(dev);
return find_smbios_instance_string(pdev, buf,
SMBIOS_ATTR_LABEL_SHOW);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 42 | 100.00% | 1 | 100.00% |
| Total | 42 | 100.00% | 1 | 100.00% |
static ssize_t smbiosinstance_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pci_dev *pdev;
pdev = to_pci_dev(dev);
return find_smbios_instance_string(pdev, buf,
SMBIOS_ATTR_INSTANCE_SHOW);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 42 | 100.00% | 1 | 100.00% |
| Total | 42 | 100.00% | 1 | 100.00% |
static struct device_attribute smbios_attr_label = {
.attr = {.name = "label", .mode = 0444},
.show = smbioslabel_show,
};
static struct device_attribute smbios_attr_instance = {
.attr = {.name = "index", .mode = 0444},
.show = smbiosinstance_show,
};
static struct attribute *smbios_attributes[] = {
&smbios_attr_label.attr,
&smbios_attr_instance.attr,
NULL,
};
static struct attribute_group smbios_attr_group = {
.attrs = smbios_attributes,
.is_visible = smbios_instance_string_exist,
};
static int pci_create_smbiosname_file(struct pci_dev *pdev)
{
return sysfs_create_group(&pdev->dev.kobj, &smbios_attr_group);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 25 | 100.00% | 2 | 100.00% |
| Total | 25 | 100.00% | 2 | 100.00% |
static void pci_remove_smbiosname_file(struct pci_dev *pdev)
{
sysfs_remove_group(&pdev->dev.kobj, &smbios_attr_group);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 24 | 100.00% | 1 | 100.00% |
| Total | 24 | 100.00% | 1 | 100.00% |
#else
static inline int pci_create_smbiosname_file(struct pci_dev *pdev)
{
return -1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 15 | 93.75% | 2 | 66.67% |
bjorn helgaas | bjorn helgaas | 1 | 6.25% | 1 | 33.33% |
| Total | 16 | 100.00% | 3 | 100.00% |
static inline void pci_remove_smbiosname_file(struct pci_dev *pdev)
{
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 8 | 72.73% | 2 | 66.67% |
bjorn helgaas | bjorn helgaas | 3 | 27.27% | 1 | 33.33% |
| Total | 11 | 100.00% | 3 | 100.00% |
#endif
#ifdef CONFIG_ACPI
enum acpi_attr_enum {
ACPI_ATTR_LABEL_SHOW,
ACPI_ATTR_INDEX_SHOW,
};
static void dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf)
{
int len;
len = utf16s_to_utf8s((const wchar_t *)obj->buffer.pointer,
obj->buffer.length,
UTF16_LITTLE_ENDIAN,
buf, PAGE_SIZE);
buf[len] = '\n';
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 51 | 96.23% | 1 | 50.00% |
simone gotti | simone gotti | 2 | 3.77% | 1 | 50.00% |
| Total | 53 | 100.00% | 2 | 100.00% |
static int dsm_get_label(struct device *dev, char *buf,
enum acpi_attr_enum attr)
{
acpi_handle handle;
union acpi_object *obj, *tmp;
int len = -1;
handle = ACPI_HANDLE(dev);
if (!handle)
return -1;
obj = acpi_evaluate_dsm(handle, pci_acpi_dsm_uuid, 0x2,
DEVICE_LABEL_DSM, NULL);
if (!obj)
return -1;
tmp = obj->package.elements;
if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 2 &&
tmp[0].type == ACPI_TYPE_INTEGER &&
(tmp[1].type == ACPI_TYPE_STRING ||
tmp[1].type == ACPI_TYPE_BUFFER)) {
/*
* The second string element is optional even when
* this _DSM is implemented; when not implemented,
* this entry must return a null string.
*/
if (attr == ACPI_ATTR_INDEX_SHOW) {
scnprintf(buf, PAGE_SIZE, "%llu\n", tmp->integer.value);
} else if (attr == ACPI_ATTR_LABEL_SHOW) {
if (tmp[1].type == ACPI_TYPE_STRING)
scnprintf(buf, PAGE_SIZE, "%s\n",
tmp[1].string.pointer);
else if (tmp[1].type == ACPI_TYPE_BUFFER)
dsm_label_utf16s_to_utf8s(tmp + 1, buf);
}
len = strlen(buf) > 0 ? strlen(buf) : -1;
}
ACPI_FREE(obj);
return len;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 115 | 48.12% | 1 | 16.67% |
jiang liu | jiang liu | 67 | 28.03% | 3 | 50.00% |
simone gotti | simone gotti | 56 | 23.43% | 1 | 16.67% |
aaron lu | aaron lu | 1 | 0.42% | 1 | 16.67% |
| Total | 239 | 100.00% | 6 | 100.00% |
static bool device_has_dsm(struct device *dev)
{
acpi_handle handle;
handle = ACPI_HANDLE(dev);
if (!handle)
return false;
return !!acpi_check_dsm(handle, pci_acpi_dsm_uuid, 0x2,
1 << DEVICE_LABEL_DSM);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 34 | 75.56% | 1 | 25.00% |
jiang liu | jiang liu | 9 | 20.00% | 1 | 25.00% |
aaron lu | aaron lu | 1 | 2.22% | 1 | 25.00% |
rafael j. wysocki | rafael j. wysocki | 1 | 2.22% | 1 | 25.00% |
| Total | 45 | 100.00% | 4 | 100.00% |
static umode_t acpi_index_string_exist(struct kobject *kobj,
struct attribute *attr, int n)
{
struct device *dev;
dev = kobj_to_dev(kobj);
if (device_has_dsm(dev))
return S_IRUGO;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 42 | 95.45% | 1 | 33.33% |
geliang tang | geliang tang | 1 | 2.27% | 1 | 33.33% |
al viro | al viro | 1 | 2.27% | 1 | 33.33% |
| Total | 44 | 100.00% | 3 | 100.00% |
static ssize_t acpilabel_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return dsm_get_label(dev, buf, ACPI_ATTR_LABEL_SHOW);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 29 | 96.67% | 1 | 50.00% |
jiang liu | jiang liu | 1 | 3.33% | 1 | 50.00% |
| Total | 30 | 100.00% | 2 | 100.00% |
static ssize_t acpiindex_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return dsm_get_label(dev, buf, ACPI_ATTR_INDEX_SHOW);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 29 | 96.67% | 1 | 50.00% |
jiang liu | jiang liu | 1 | 3.33% | 1 | 50.00% |
| Total | 30 | 100.00% | 2 | 100.00% |
static struct device_attribute acpi_attr_label = {
.attr = {.name = "label", .mode = 0444},
.show = acpilabel_show,
};
static struct device_attribute acpi_attr_index = {
.attr = {.name = "acpi_index", .mode = 0444},
.show = acpiindex_show,
};
static struct attribute *acpi_attributes[] = {
&acpi_attr_label.attr,
&acpi_attr_index.attr,
NULL,
};
static struct attribute_group acpi_attr_group = {
.attrs = acpi_attributes,
.is_visible = acpi_index_string_exist,
};
static int pci_create_acpi_index_label_files(struct pci_dev *pdev)
{
return sysfs_create_group(&pdev->dev.kobj, &acpi_attr_group);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 25 | 100.00% | 1 | 100.00% |
| Total | 25 | 100.00% | 1 | 100.00% |
static int pci_remove_acpi_index_label_files(struct pci_dev *pdev)
{
sysfs_remove_group(&pdev->dev.kobj, &acpi_attr_group);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 27 | 100.00% | 1 | 100.00% |
| Total | 27 | 100.00% | 1 | 100.00% |
#else
static inline int pci_create_acpi_index_label_files(struct pci_dev *pdev)
{
return -1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
bjorn helgaas | bjorn helgaas | 16 | 100.00% | 1 | 100.00% |
| Total | 16 | 100.00% | 1 | 100.00% |
static inline int pci_remove_acpi_index_label_files(struct pci_dev *pdev)
{
return -1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
bjorn helgaas | bjorn helgaas | 16 | 100.00% | 1 | 100.00% |
| Total | 16 | 100.00% | 1 | 100.00% |
static inline bool device_has_dsm(struct device *dev)
{
return false;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
bjorn helgaas | bjorn helgaas | 15 | 100.00% | 1 | 100.00% |
| Total | 15 | 100.00% | 1 | 100.00% |
#endif
void pci_create_firmware_label_files(struct pci_dev *pdev)
{
if (device_has_dsm(&pdev->dev))
pci_create_acpi_index_label_files(pdev);
else
pci_create_smbiosname_file(pdev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 31 | 100.00% | 1 | 100.00% |
| Total | 31 | 100.00% | 1 | 100.00% |
void pci_remove_firmware_label_files(struct pci_dev *pdev)
{
if (device_has_dsm(&pdev->dev))
pci_remove_acpi_index_label_files(pdev);
else
pci_remove_smbiosname_file(pdev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 31 | 100.00% | 2 | 100.00% |
| Total | 31 | 100.00% | 2 | 100.00% |
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
narendra k | narendra k | 1016 | 83.07% | 2 | 15.38% |
jiang liu | jiang liu | 78 | 6.38% | 3 | 23.08% |
bjorn helgaas | bjorn helgaas | 62 | 5.07% | 1 | 7.69% |
simone gotti | simone gotti | 58 | 4.74% | 1 | 7.69% |
al viro | al viro | 3 | 0.25% | 2 | 15.38% |
geliang tang | geliang tang | 2 | 0.16% | 1 | 7.69% |
aaron lu | aaron lu | 2 | 0.16% | 1 | 7.69% |
naga venkata sai indubhaskar jupudi | naga venkata sai indubhaskar jupudi | 1 | 0.08% | 1 | 7.69% |
rafael j. wysocki | rafael j. wysocki | 1 | 0.08% | 1 | 7.69% |
ryan desfosses | ryan desfosses | | 0.00% | 0 | 0.00% |
| Total | 1223 | 100.00% | 13 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.