09da8dfa98
- ACPI core changes to make it create a struct acpi_device object for every device represented in the ACPI tables during all namespace scans regardless of the current status of that device. In accordance with this, ACPI hotplug operations will not delete those objects, unless the underlying ACPI tables go away. - On top of the above, new sysfs attribute for ACPI device objects allowing user space to check device status by triggering the execution of _STA for its ACPI object. From Srinivas Pandruvada. - ACPI core hotplug changes reducing code duplication, integrating the PCI root hotplug with the core and reworking container hotplug. - ACPI core simplifications making it use ACPI_COMPANION() in the code "glueing" ACPI device objects to "physical" devices. - ACPICA update to upstream version 20131218. This adds support for the DBG2 and PCCT tables to ACPICA, fixes some bugs and improves debug facilities. From Bob Moore, Lv Zheng and Betty Dall. - Init code change to carry out the early ACPI initialization earlier. That should allow us to use ACPI during the timekeeping initialization and possibly to simplify the EFI initialization too. From Chun-Yi Lee. - Clenups of the inclusions of ACPI headers in many places all over from Lv Zheng and Rashika Kheria (work in progress). - New helper for ACPI _DSM execution and rework of the code in drivers that uses _DSM to execute it via the new helper. From Jiang Liu. - New Win8 OSI blacklist entries from Takashi Iwai. - Assorted ACPI fixes and cleanups from Al Stone, Emil Goode, Hanjun Guo, Lan Tianyu, Masanari Iida, Oliver Neukum, Prarit Bhargava, Rashika Kheria, Tang Chen, Zhang Rui. - intel_pstate driver updates, including proper Baytrail support, from Dirk Brandewie and intel_pstate documentation from Ramkumar Ramachandra. - Generic CPU boost ("turbo") support for cpufreq from Lukasz Majewski. - powernow-k6 cpufreq driver fixes from Mikulas Patocka. - cpufreq core fixes and cleanups from Viresh Kumar, Jane Li, Mark Brown. - Assorted cpufreq drivers fixes and cleanups from Anson Huang, John Tobias, Paul Bolle, Paul Walmsley, Sachin Kamat, Shawn Guo, Viresh Kumar. - cpuidle cleanups from Bartlomiej Zolnierkiewicz. - Support for hibernation APM events from Bin Shi. - Hibernation fix to avoid bringing up nonboot CPUs with ACPI EC disabled during thaw transitions from Bjørn Mork. - PM core fixes and cleanups from Ben Dooks, Leonardo Potenza, Ulf Hansson. - PNP subsystem fixes and cleanups from Dmitry Torokhov, Levente Kurusa, Rashika Kheria. - New tool for profiling system suspend from Todd E Brandt and a cpupower tool cleanup from One Thousand Gnomes. / -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABCAAGBQJS3a1eAAoJEILEb/54YlRxnTgP/iGawvgjKWm6Qqp7WSIvd5gQ zZ6q75C6Pc/W2fq1+OzVGnpCF8WYFy+nFDAXOvUHjIXuoxSwFcuW5l4aMckgl/0a TXEWe9MJrCHHRfDApfFacCJ44U02bjJAD5vTyL/hKA+IHeinq4WCSojryYC+8jU0 cBrUIV0aNH8r5JR2WJNAyv/U29rXsDUOu0I4qTqZ4YaZT6AignMjtLXn1e9AH1Pn DPZphTIo/HMnb+kgBOjt4snMk+ahVO9eCOxh/hH8ecnWExw9WynXoU5Nsna0tSZs ssyHC7BYexD3oYsG8D52cFUpp4FCsJ0nFQNa2kw0LY+0FBNay43LySisKYHZPXEs 2WpESDv+/t7yhtnrvM+TtA7aBheKm2XMWGFSu/aERLE17jIidOkXKH5Y7ryYLNf/ uyRKxNS0NcZWZ0G+/wuY02jQYNkfYz3k/nTr8BAUItRBjdporGIRNEnR9gPzgCUC uQhjXWMPulqubr8xbyefPWHTEzU2nvbXwTUWGjrBxSy8zkyy5arfqizUj+VG6afT NsboANoMHa9b+xdzigSFdA3nbVK6xBjtU6Ywntk9TIpODKF5NgfARx0H+oSH+Zrj 32bMzgZtHw/lAbYsnQ9OnTY6AEWQYt6NMuVbTiLXrMHhM3nWwfg/XoN4nZqs6jPo IYvE6WhQZU6L6fptGHFC =dRf6 -----END PGP SIGNATURE----- Merge tag 'pm+acpi-3.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm Pull ACPI and power management updates from Rafael Wysocki: "As far as the number of commits goes, the top spot belongs to ACPI this time with cpufreq in the second position and a handful of PM core, PNP and cpuidle updates. They are fixes and cleanups mostly, as usual, with a couple of new features in the mix. The most visible change is probably that we will create struct acpi_device objects (visible in sysfs) for all devices represented in the ACPI tables regardless of their status and there will be a new sysfs attribute under those objects allowing user space to check that status via _STA. Consequently, ACPI device eject or generally hot-removal will not delete those objects, unless the table containing the corresponding namespace nodes is unloaded, which is extremely rare. Also ACPI container hotplug will be handled quite a bit differently and cpufreq will support CPU boost ("turbo") generically and not only in the acpi-cpufreq driver. Specifics: - ACPI core changes to make it create a struct acpi_device object for every device represented in the ACPI tables during all namespace scans regardless of the current status of that device. In accordance with this, ACPI hotplug operations will not delete those objects, unless the underlying ACPI tables go away. - On top of the above, new sysfs attribute for ACPI device objects allowing user space to check device status by triggering the execution of _STA for its ACPI object. From Srinivas Pandruvada. - ACPI core hotplug changes reducing code duplication, integrating the PCI root hotplug with the core and reworking container hotplug. - ACPI core simplifications making it use ACPI_COMPANION() in the code "glueing" ACPI device objects to "physical" devices. - ACPICA update to upstream version 20131218. This adds support for the DBG2 and PCCT tables to ACPICA, fixes some bugs and improves debug facilities. From Bob Moore, Lv Zheng and Betty Dall. - Init code change to carry out the early ACPI initialization earlier. That should allow us to use ACPI during the timekeeping initialization and possibly to simplify the EFI initialization too. From Chun-Yi Lee. - Clenups of the inclusions of ACPI headers in many places all over from Lv Zheng and Rashika Kheria (work in progress). - New helper for ACPI _DSM execution and rework of the code in drivers that uses _DSM to execute it via the new helper. From Jiang Liu. - New Win8 OSI blacklist entries from Takashi Iwai. - Assorted ACPI fixes and cleanups from Al Stone, Emil Goode, Hanjun Guo, Lan Tianyu, Masanari Iida, Oliver Neukum, Prarit Bhargava, Rashika Kheria, Tang Chen, Zhang Rui. - intel_pstate driver updates, including proper Baytrail support, from Dirk Brandewie and intel_pstate documentation from Ramkumar Ramachandra. - Generic CPU boost ("turbo") support for cpufreq from Lukasz Majewski. - powernow-k6 cpufreq driver fixes from Mikulas Patocka. - cpufreq core fixes and cleanups from Viresh Kumar, Jane Li, Mark Brown. - Assorted cpufreq drivers fixes and cleanups from Anson Huang, John Tobias, Paul Bolle, Paul Walmsley, Sachin Kamat, Shawn Guo, Viresh Kumar. - cpuidle cleanups from Bartlomiej Zolnierkiewicz. - Support for hibernation APM events from Bin Shi. - Hibernation fix to avoid bringing up nonboot CPUs with ACPI EC disabled during thaw transitions from Bjørn Mork. - PM core fixes and cleanups from Ben Dooks, Leonardo Potenza, Ulf Hansson. - PNP subsystem fixes and cleanups from Dmitry Torokhov, Levente Kurusa, Rashika Kheria. - New tool for profiling system suspend from Todd E Brandt and a cpupower tool cleanup from One Thousand Gnomes" * tag 'pm+acpi-3.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (153 commits) thermal: exynos: boost: Automatic enable/disable of BOOST feature (at Exynos4412) cpufreq: exynos4x12: Change L0 driver data to CPUFREQ_BOOST_FREQ Documentation: cpufreq / boost: Update BOOST documentation cpufreq: exynos: Extend Exynos cpufreq driver to support boost cpufreq / boost: Kconfig: Support for software-managed BOOST acpi-cpufreq: Adjust the code to use the common boost attribute cpufreq: Add boost frequency support in core intel_pstate: Add trace point to report internal state. cpufreq: introduce cpufreq_generic_get() routine ARM: SA1100: Create dummy clk_get_rate() to avoid build failures cpufreq: stats: create sysfs entries when cpufreq_stats is a module cpufreq: stats: free table and remove sysfs entry in a single routine cpufreq: stats: remove hotplug notifiers cpufreq: stats: handle cpufreq_unregister_driver() and suspend/resume properly cpufreq: speedstep: remove unused speedstep_get_state platform: introduce OF style 'modalias' support for platform bus PM / tools: new tool for suspend/resume performance optimization ACPI: fix module autoloading for ACPI enumerated devices ACPI: add module autoloading support for ACPI enumerated devices ACPI: fix create_modalias() return value handling ...
321 lines
7.1 KiB
C
321 lines
7.1 KiB
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/wiki/index.php/Oss/libnetdevname 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"
|
|
|
|
#define DEVICE_LABEL_DSM 0x07
|
|
|
|
#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;
|
|
}
|
|
|
|
static umode_t
|
|
smbios_instance_string_exist(struct kobject *kobj, struct attribute *attr,
|
|
int n)
|
|
{
|
|
struct device *dev;
|
|
struct pci_dev *pdev;
|
|
|
|
dev = container_of(kobj, struct device, kobj);
|
|
pdev = to_pci_dev(dev);
|
|
|
|
return find_smbios_instance_string(pdev, NULL, SMBIOS_ATTR_NONE) ?
|
|
S_IRUGO : 0;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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
|
|
static const char device_label_dsm_uuid[] = {
|
|
0xD0, 0x37, 0xC9, 0xE5, 0x53, 0x35, 0x7A, 0x4D,
|
|
0x91, 0x17, 0xEA, 0x4D, 0x19, 0xC3, 0x43, 0x4D
|
|
};
|
|
|
|
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->string.pointer,
|
|
obj->string.length,
|
|
UTF16_LITTLE_ENDIAN,
|
|
buf, PAGE_SIZE);
|
|
buf[len] = '\n';
|
|
}
|
|
|
|
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, device_label_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) {
|
|
/*
|
|
* 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)
|
|
dsm_label_utf16s_to_utf8s(tmp + 1, buf);
|
|
len = strlen(buf) > 0 ? strlen(buf) : -1;
|
|
}
|
|
|
|
ACPI_FREE(obj);
|
|
|
|
return len;
|
|
}
|
|
|
|
static bool
|
|
device_has_dsm(struct device *dev)
|
|
{
|
|
acpi_handle handle;
|
|
|
|
handle = ACPI_HANDLE(dev);
|
|
if (!handle)
|
|
return false;
|
|
|
|
return !!acpi_check_dsm(handle, device_label_dsm_uuid, 0x2,
|
|
1 << DEVICE_LABEL_DSM);
|
|
}
|
|
|
|
static umode_t
|
|
acpi_index_string_exist(struct kobject *kobj, struct attribute *attr, int n)
|
|
{
|
|
struct device *dev;
|
|
|
|
dev = container_of(kobj, struct device, kobj);
|
|
|
|
if (device_has_dsm(dev))
|
|
return S_IRUGO;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t
|
|
acpilabel_show(struct device *dev, struct device_attribute *attr, char *buf)
|
|
{
|
|
return dsm_get_label(dev, buf, ACPI_ATTR_LABEL_SHOW);
|
|
}
|
|
|
|
static ssize_t
|
|
acpiindex_show(struct device *dev, struct device_attribute *attr, char *buf)
|
|
{
|
|
return dsm_get_label(dev, buf, ACPI_ATTR_INDEX_SHOW);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
static inline bool
|
|
device_has_dsm(struct device *dev)
|
|
{
|
|
return false;
|
|
}
|
|
#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);
|
|
}
|
|
|
|
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);
|
|
}
|