|
|
|
@ -64,6 +64,7 @@ struct pcie_link_state {
|
|
|
|
|
u32 clkpm_capable:1; /* Clock PM capable? */
|
|
|
|
|
u32 clkpm_enabled:1; /* Current Clock PM state */
|
|
|
|
|
u32 clkpm_default:1; /* Default Clock PM state by BIOS */
|
|
|
|
|
u32 clkpm_disable:1; /* Clock PM disabled */
|
|
|
|
|
|
|
|
|
|
/* Exit latencies */
|
|
|
|
|
struct aspm_latency latency_up; /* Upstream direction exit latency */
|
|
|
|
@ -161,8 +162,11 @@ static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable)
|
|
|
|
|
|
|
|
|
|
static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
|
|
|
|
|
{
|
|
|
|
|
/* Don't enable Clock PM if the link is not Clock PM capable */
|
|
|
|
|
if (!link->clkpm_capable)
|
|
|
|
|
/*
|
|
|
|
|
* Don't enable Clock PM if the link is not Clock PM capable
|
|
|
|
|
* or Clock PM is disabled
|
|
|
|
|
*/
|
|
|
|
|
if (!link->clkpm_capable || link->clkpm_disable)
|
|
|
|
|
enable = 0;
|
|
|
|
|
/* Need nothing if the specified equals to current state */
|
|
|
|
|
if (link->clkpm_enabled == enable)
|
|
|
|
@ -192,7 +196,8 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
|
|
|
|
|
}
|
|
|
|
|
link->clkpm_enabled = enabled;
|
|
|
|
|
link->clkpm_default = enabled;
|
|
|
|
|
link->clkpm_capable = (blacklist) ? 0 : capable;
|
|
|
|
|
link->clkpm_capable = capable;
|
|
|
|
|
link->clkpm_disable = blacklist ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool pcie_retrain_link(struct pcie_link_state *link)
|
|
|
|
@ -894,6 +899,14 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
|
|
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void pcie_aspm_update_sysfs_visibility(struct pci_dev *pdev)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *child;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(child, &pdev->subordinate->devices, bus_list)
|
|
|
|
|
sysfs_update_group(&child->dev.kobj, &aspm_ctrl_attr_group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* pcie_aspm_init_link_state: Initiate PCI express link state.
|
|
|
|
|
* It is called after the pcie and its children devices are scanned.
|
|
|
|
@ -955,6 +968,8 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
|
|
|
|
|
pcie_set_clkpm(link, policy_to_clkpm_state(link));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pcie_aspm_update_sysfs_visibility(pdev);
|
|
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
|
mutex_unlock(&aspm_lock);
|
|
|
|
|
out:
|
|
|
|
@ -1061,19 +1076,26 @@ void pcie_aspm_powersave_config_link(struct pci_dev *pdev)
|
|
|
|
|
up_read(&pci_bus_sem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
|
|
|
|
|
static struct pcie_link_state *pcie_aspm_get_link(struct pci_dev *pdev)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *parent = pdev->bus->self;
|
|
|
|
|
struct pcie_link_state *link;
|
|
|
|
|
struct pci_dev *bridge;
|
|
|
|
|
|
|
|
|
|
if (!pci_is_pcie(pdev))
|
|
|
|
|
return 0;
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if (pcie_downstream_port(pdev))
|
|
|
|
|
parent = pdev;
|
|
|
|
|
if (!parent || !parent->link_state)
|
|
|
|
|
bridge = pci_upstream_bridge(pdev);
|
|
|
|
|
if (!bridge || !pci_is_pcie(bridge))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return bridge->link_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
|
|
|
|
|
{
|
|
|
|
|
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
|
|
|
|
|
|
|
|
|
|
if (!link)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A driver requested that ASPM be disabled on this device, but
|
|
|
|
|
* if we don't have permission to manage ASPM (e.g., on ACPI
|
|
|
|
@ -1090,17 +1112,24 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
|
|
|
|
|
if (sem)
|
|
|
|
|
down_read(&pci_bus_sem);
|
|
|
|
|
mutex_lock(&aspm_lock);
|
|
|
|
|
link = parent->link_state;
|
|
|
|
|
if (state & PCIE_LINK_STATE_L0S)
|
|
|
|
|
link->aspm_disable |= ASPM_STATE_L0S;
|
|
|
|
|
if (state & PCIE_LINK_STATE_L1)
|
|
|
|
|
link->aspm_disable |= ASPM_STATE_L1;
|
|
|
|
|
/* L1 PM substates require L1 */
|
|
|
|
|
link->aspm_disable |= ASPM_STATE_L1 | ASPM_STATE_L1SS;
|
|
|
|
|
if (state & PCIE_LINK_STATE_L1_1)
|
|
|
|
|
link->aspm_disable |= ASPM_STATE_L1_1;
|
|
|
|
|
if (state & PCIE_LINK_STATE_L1_2)
|
|
|
|
|
link->aspm_disable |= ASPM_STATE_L1_2;
|
|
|
|
|
if (state & PCIE_LINK_STATE_L1_1_PCIPM)
|
|
|
|
|
link->aspm_disable |= ASPM_STATE_L1_1_PCIPM;
|
|
|
|
|
if (state & PCIE_LINK_STATE_L1_2_PCIPM)
|
|
|
|
|
link->aspm_disable |= ASPM_STATE_L1_2_PCIPM;
|
|
|
|
|
pcie_config_aspm_link(link, policy_to_aspm_state(link));
|
|
|
|
|
|
|
|
|
|
if (state & PCIE_LINK_STATE_CLKPM) {
|
|
|
|
|
link->clkpm_capable = 0;
|
|
|
|
|
pcie_set_clkpm(link, 0);
|
|
|
|
|
}
|
|
|
|
|
if (state & PCIE_LINK_STATE_CLKPM)
|
|
|
|
|
link->clkpm_disable = 1;
|
|
|
|
|
pcie_set_clkpm(link, policy_to_clkpm_state(link));
|
|
|
|
|
mutex_unlock(&aspm_lock);
|
|
|
|
|
if (sem)
|
|
|
|
|
up_read(&pci_bus_sem);
|
|
|
|
@ -1172,127 +1201,161 @@ module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy,
|
|
|
|
|
/**
|
|
|
|
|
* pcie_aspm_enabled - Check if PCIe ASPM has been enabled for a device.
|
|
|
|
|
* @pdev: Target device.
|
|
|
|
|
*
|
|
|
|
|
* Relies on the upstream bridge's link_state being valid. The link_state
|
|
|
|
|
* is deallocated only when the last child of the bridge (i.e., @pdev or a
|
|
|
|
|
* sibling) is removed, and the caller should be holding a reference to
|
|
|
|
|
* @pdev, so this should be safe.
|
|
|
|
|
*/
|
|
|
|
|
bool pcie_aspm_enabled(struct pci_dev *pdev)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *bridge = pci_upstream_bridge(pdev);
|
|
|
|
|
bool ret;
|
|
|
|
|
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
|
|
|
|
|
|
|
|
|
|
if (!bridge)
|
|
|
|
|
if (!link)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&aspm_lock);
|
|
|
|
|
ret = bridge->link_state ? !!bridge->link_state->aspm_enabled : false;
|
|
|
|
|
mutex_unlock(&aspm_lock);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
return link->aspm_enabled;
|
|
|
|
|
}
|
|
|
|
|
EXPORT_SYMBOL_GPL(pcie_aspm_enabled);
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PCIEASPM_DEBUG
|
|
|
|
|
static ssize_t link_state_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr,
|
|
|
|
|
char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *pci_device = to_pci_dev(dev);
|
|
|
|
|
struct pcie_link_state *link_state = pci_device->link_state;
|
|
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", link_state->aspm_enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t link_state_store(struct device *dev,
|
|
|
|
|
struct device_attribute *attr,
|
|
|
|
|
const char *buf,
|
|
|
|
|
size_t n)
|
|
|
|
|
static ssize_t aspm_attr_show_common(struct device *dev,
|
|
|
|
|
struct device_attribute *attr,
|
|
|
|
|
char *buf, u8 state)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
|
struct pcie_link_state *link, *root = pdev->link_state->root;
|
|
|
|
|
u32 state;
|
|
|
|
|
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
|
|
|
|
|
|
|
|
|
|
if (aspm_disabled)
|
|
|
|
|
return -EPERM;
|
|
|
|
|
return sprintf(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (kstrtouint(buf, 10, &state))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if ((state & ~ASPM_STATE_ALL) != 0)
|
|
|
|
|
static ssize_t aspm_attr_store_common(struct device *dev,
|
|
|
|
|
struct device_attribute *attr,
|
|
|
|
|
const char *buf, size_t len, u8 state)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
|
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
|
|
|
|
|
bool state_enable;
|
|
|
|
|
|
|
|
|
|
if (strtobool(buf, &state_enable) < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
down_read(&pci_bus_sem);
|
|
|
|
|
mutex_lock(&aspm_lock);
|
|
|
|
|
list_for_each_entry(link, &link_list, sibling) {
|
|
|
|
|
if (link->root != root)
|
|
|
|
|
continue;
|
|
|
|
|
pcie_config_aspm_link(link, state);
|
|
|
|
|
|
|
|
|
|
if (state_enable) {
|
|
|
|
|
link->aspm_disable &= ~state;
|
|
|
|
|
/* need to enable L1 for substates */
|
|
|
|
|
if (state & ASPM_STATE_L1SS)
|
|
|
|
|
link->aspm_disable &= ~ASPM_STATE_L1;
|
|
|
|
|
} else {
|
|
|
|
|
link->aspm_disable |= state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pcie_config_aspm_link(link, policy_to_aspm_state(link));
|
|
|
|
|
|
|
|
|
|
mutex_unlock(&aspm_lock);
|
|
|
|
|
up_read(&pci_bus_sem);
|
|
|
|
|
return n;
|
|
|
|
|
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t clk_ctl_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr,
|
|
|
|
|
char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *pci_device = to_pci_dev(dev);
|
|
|
|
|
struct pcie_link_state *link_state = pci_device->link_state;
|
|
|
|
|
#define ASPM_ATTR(_f, _s) \
|
|
|
|
|
static ssize_t _f##_show(struct device *dev, \
|
|
|
|
|
struct device_attribute *attr, char *buf) \
|
|
|
|
|
{ return aspm_attr_show_common(dev, attr, buf, ASPM_STATE_##_s); } \
|
|
|
|
|
\
|
|
|
|
|
static ssize_t _f##_store(struct device *dev, \
|
|
|
|
|
struct device_attribute *attr, \
|
|
|
|
|
const char *buf, size_t len) \
|
|
|
|
|
{ return aspm_attr_store_common(dev, attr, buf, len, ASPM_STATE_##_s); }
|
|
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", link_state->clkpm_enabled);
|
|
|
|
|
}
|
|
|
|
|
ASPM_ATTR(l0s_aspm, L0S)
|
|
|
|
|
ASPM_ATTR(l1_aspm, L1)
|
|
|
|
|
ASPM_ATTR(l1_1_aspm, L1_1)
|
|
|
|
|
ASPM_ATTR(l1_2_aspm, L1_2)
|
|
|
|
|
ASPM_ATTR(l1_1_pcipm, L1_1_PCIPM)
|
|
|
|
|
ASPM_ATTR(l1_2_pcipm, L1_2_PCIPM)
|
|
|
|
|
|
|
|
|
|
static ssize_t clk_ctl_store(struct device *dev,
|
|
|
|
|
struct device_attribute *attr,
|
|
|
|
|
const char *buf,
|
|
|
|
|
size_t n)
|
|
|
|
|
static ssize_t clkpm_show(struct device *dev,
|
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
|
bool state;
|
|
|
|
|
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
|
|
|
|
|
|
|
|
|
|
if (strtobool(buf, &state))
|
|
|
|
|
return sprintf(buf, "%d\n", link->clkpm_enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t clkpm_store(struct device *dev,
|
|
|
|
|
struct device_attribute *attr,
|
|
|
|
|
const char *buf, size_t len)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
|
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
|
|
|
|
|
bool state_enable;
|
|
|
|
|
|
|
|
|
|
if (strtobool(buf, &state_enable) < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
down_read(&pci_bus_sem);
|
|
|
|
|
mutex_lock(&aspm_lock);
|
|
|
|
|
pcie_set_clkpm_nocheck(pdev->link_state, state);
|
|
|
|
|
|
|
|
|
|
link->clkpm_disable = !state_enable;
|
|
|
|
|
pcie_set_clkpm(link, policy_to_clkpm_state(link));
|
|
|
|
|
|
|
|
|
|
mutex_unlock(&aspm_lock);
|
|
|
|
|
up_read(&pci_bus_sem);
|
|
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DEVICE_ATTR_RW(link_state);
|
|
|
|
|
static DEVICE_ATTR_RW(clk_ctl);
|
|
|
|
|
static DEVICE_ATTR_RW(clkpm);
|
|
|
|
|
static DEVICE_ATTR_RW(l0s_aspm);
|
|
|
|
|
static DEVICE_ATTR_RW(l1_aspm);
|
|
|
|
|
static DEVICE_ATTR_RW(l1_1_aspm);
|
|
|
|
|
static DEVICE_ATTR_RW(l1_2_aspm);
|
|
|
|
|
static DEVICE_ATTR_RW(l1_1_pcipm);
|
|
|
|
|
static DEVICE_ATTR_RW(l1_2_pcipm);
|
|
|
|
|
|
|
|
|
|
static char power_group[] = "power";
|
|
|
|
|
void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev)
|
|
|
|
|
static struct attribute *aspm_ctrl_attrs[] = {
|
|
|
|
|
&dev_attr_clkpm.attr,
|
|
|
|
|
&dev_attr_l0s_aspm.attr,
|
|
|
|
|
&dev_attr_l1_aspm.attr,
|
|
|
|
|
&dev_attr_l1_1_aspm.attr,
|
|
|
|
|
&dev_attr_l1_2_aspm.attr,
|
|
|
|
|
&dev_attr_l1_1_pcipm.attr,
|
|
|
|
|
&dev_attr_l1_2_pcipm.attr,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static umode_t aspm_ctrl_attrs_are_visible(struct kobject *kobj,
|
|
|
|
|
struct attribute *a, int n)
|
|
|
|
|
{
|
|
|
|
|
struct pcie_link_state *link_state = pdev->link_state;
|
|
|
|
|
struct device *dev = kobj_to_dev(kobj);
|
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
|
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
|
|
|
|
|
static const u8 aspm_state_map[] = {
|
|
|
|
|
ASPM_STATE_L0S,
|
|
|
|
|
ASPM_STATE_L1,
|
|
|
|
|
ASPM_STATE_L1_1,
|
|
|
|
|
ASPM_STATE_L1_2,
|
|
|
|
|
ASPM_STATE_L1_1_PCIPM,
|
|
|
|
|
ASPM_STATE_L1_2_PCIPM,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!link_state)
|
|
|
|
|
return;
|
|
|
|
|
if (aspm_disabled || !link)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (link_state->aspm_support)
|
|
|
|
|
sysfs_add_file_to_group(&pdev->dev.kobj,
|
|
|
|
|
&dev_attr_link_state.attr, power_group);
|
|
|
|
|
if (link_state->clkpm_capable)
|
|
|
|
|
sysfs_add_file_to_group(&pdev->dev.kobj,
|
|
|
|
|
&dev_attr_clk_ctl.attr, power_group);
|
|
|
|
|
if (n == 0)
|
|
|
|
|
return link->clkpm_capable ? a->mode : 0;
|
|
|
|
|
|
|
|
|
|
return link->aspm_capable & aspm_state_map[n - 1] ? a->mode : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev)
|
|
|
|
|
{
|
|
|
|
|
struct pcie_link_state *link_state = pdev->link_state;
|
|
|
|
|
|
|
|
|
|
if (!link_state)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (link_state->aspm_support)
|
|
|
|
|
sysfs_remove_file_from_group(&pdev->dev.kobj,
|
|
|
|
|
&dev_attr_link_state.attr, power_group);
|
|
|
|
|
if (link_state->clkpm_capable)
|
|
|
|
|
sysfs_remove_file_from_group(&pdev->dev.kobj,
|
|
|
|
|
&dev_attr_clk_ctl.attr, power_group);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
const struct attribute_group aspm_ctrl_attr_group = {
|
|
|
|
|
.name = "link",
|
|
|
|
|
.attrs = aspm_ctrl_attrs,
|
|
|
|
|
.is_visible = aspm_ctrl_attrs_are_visible,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int __init pcie_aspm_disable(char *str)
|
|
|
|
|
{
|
|
|
|
|