Skip to content

Commit

Permalink
Merge branches 'pm-sleep', 'pm-acpi', 'pm-domains' and 'powercap'
Browse files Browse the repository at this point in the history
* pm-sleep:
  PM: sleep: Add dev_wakeup_path() helper
  PM / suspend: fix kernel-doc markup
  PM: sleep: Print driver flags for all devices during suspend/resume

* pm-acpi:
  PM: ACPI: Refresh wakeup device power configuration every time
  PM: ACPI: PCI: Drop acpi_pm_set_bridge_wakeup()
  PM: ACPI: reboot: Use S5 for reboot

* pm-domains:
  PM: domains: create debugfs nodes when adding power domains
  PM: domains: replace -ENOTSUPP with -EOPNOTSUPP

* powercap:
  powercap: Adjust printing the constraint name with new line
  powercap: RAPL: Add AMD Fam19h RAPL support
  powercap: Add AMD Fam17h RAPL support
  powercap/intel_rapl_msr: Convert rapl_msr_priv into pointer
  x86/msr-index: sort AMD RAPL MSRs by address
  • Loading branch information
rafaeljw committed Dec 15, 2020
5 parents 4c5744a + 4e1d9a7 + b93b7ef + 718072c + b4ba76f commit 42b4ca0
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 102 deletions.
3 changes: 2 additions & 1 deletion arch/x86/include/asm/msr-index.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@
#define MSR_PP1_ENERGY_STATUS 0x00000641
#define MSR_PP1_POLICY 0x00000642

#define MSR_AMD_PKG_ENERGY_STATUS 0xc001029b
#define MSR_AMD_RAPL_POWER_UNIT 0xc0010299
#define MSR_AMD_CORE_ENERGY_STATUS 0xc001029a
#define MSR_AMD_PKG_ENERGY_STATUS 0xc001029b

/* Config TDP MSRs */
#define MSR_CONFIG_TDP_NOMINAL 0x00000648
Expand Down
62 changes: 29 additions & 33 deletions drivers/acpi/device_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,23 +749,34 @@ static void acpi_pm_notify_work_func(struct acpi_device_wakeup_context *context)
static DEFINE_MUTEX(acpi_wakeup_lock);

static int __acpi_device_wakeup_enable(struct acpi_device *adev,
u32 target_state, int max_count)
u32 target_state)
{
struct acpi_device_wakeup *wakeup = &adev->wakeup;
acpi_status status;
int error = 0;

mutex_lock(&acpi_wakeup_lock);

if (wakeup->enable_count >= max_count)
goto out;

/*
* If the device wakeup power is already enabled, disable it and enable
* it again in case it depends on the configuration of subordinate
* devices and the conditions have changed since it was enabled last
* time.
*/
if (wakeup->enable_count > 0)
goto inc;
acpi_disable_wakeup_device_power(adev);

error = acpi_enable_wakeup_device_power(adev, target_state);
if (error)
if (error) {
if (wakeup->enable_count > 0) {
acpi_disable_gpe(wakeup->gpe_device, wakeup->gpe_number);
wakeup->enable_count = 0;
}
goto out;
}

if (wakeup->enable_count > 0)
goto inc;

status = acpi_enable_gpe(wakeup->gpe_device, wakeup->gpe_number);
if (ACPI_FAILURE(status)) {
Expand All @@ -778,7 +789,10 @@ static int __acpi_device_wakeup_enable(struct acpi_device *adev,
(unsigned int)wakeup->gpe_number);

inc:
wakeup->enable_count++;
if (wakeup->enable_count < INT_MAX)
wakeup->enable_count++;
else
acpi_handle_info(adev->handle, "Wakeup enable count out of bounds!\n");

out:
mutex_unlock(&acpi_wakeup_lock);
Expand All @@ -799,7 +813,7 @@ static int __acpi_device_wakeup_enable(struct acpi_device *adev,
*/
static int acpi_device_wakeup_enable(struct acpi_device *adev, u32 target_state)
{
return __acpi_device_wakeup_enable(adev, target_state, 1);
return __acpi_device_wakeup_enable(adev, target_state);
}

/**
Expand Down Expand Up @@ -829,8 +843,12 @@ static void acpi_device_wakeup_disable(struct acpi_device *adev)
mutex_unlock(&acpi_wakeup_lock);
}

static int __acpi_pm_set_device_wakeup(struct device *dev, bool enable,
int max_count)
/**
* acpi_pm_set_device_wakeup - Enable/disable remote wakeup for given device.
* @dev: Device to enable/disable to generate wakeup events.
* @enable: Whether to enable or disable the wakeup functionality.
*/
int acpi_pm_set_device_wakeup(struct device *dev, bool enable)
{
struct acpi_device *adev;
int error;
Expand All @@ -850,36 +868,14 @@ static int __acpi_pm_set_device_wakeup(struct device *dev, bool enable,
return 0;
}

error = __acpi_device_wakeup_enable(adev, acpi_target_system_state(),
max_count);
error = __acpi_device_wakeup_enable(adev, acpi_target_system_state());
if (!error)
dev_dbg(dev, "Wakeup enabled by ACPI\n");

return error;
}

/**
* acpi_pm_set_device_wakeup - Enable/disable remote wakeup for given device.
* @dev: Device to enable/disable to generate wakeup events.
* @enable: Whether to enable or disable the wakeup functionality.
*/
int acpi_pm_set_device_wakeup(struct device *dev, bool enable)
{
return __acpi_pm_set_device_wakeup(dev, enable, 1);
}
EXPORT_SYMBOL_GPL(acpi_pm_set_device_wakeup);

/**
* acpi_pm_set_bridge_wakeup - Enable/disable remote wakeup for given bridge.
* @dev: Bridge device to enable/disable to generate wakeup events.
* @enable: Whether to enable or disable the wakeup functionality.
*/
int acpi_pm_set_bridge_wakeup(struct device *dev, bool enable)
{
return __acpi_pm_set_device_wakeup(dev, enable, INT_MAX);
}
EXPORT_SYMBOL_GPL(acpi_pm_set_bridge_wakeup);

/**
* acpi_dev_pm_low_power - Put ACPI device into a low-power state.
* @dev: Device to put into a low-power state.
Expand Down
77 changes: 47 additions & 30 deletions drivers/base/power/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/suspend.h>
#include <linux/export.h>
#include <linux/cpu.h>
#include <linux/debugfs.h>

#include "power.h"

Expand Down Expand Up @@ -210,6 +211,18 @@ static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
}

#ifdef CONFIG_DEBUG_FS
static struct dentry *genpd_debugfs_dir;

static void genpd_debug_add(struct generic_pm_domain *genpd);

static void genpd_debug_remove(struct generic_pm_domain *genpd)
{
struct dentry *d;

d = debugfs_lookup(genpd->name, genpd_debugfs_dir);
debugfs_remove(d);
}

static void genpd_update_accounting(struct generic_pm_domain *genpd)
{
ktime_t delta, now;
Expand All @@ -234,6 +247,8 @@ static void genpd_update_accounting(struct generic_pm_domain *genpd)
genpd->accounting_time = now;
}
#else
static inline void genpd_debug_add(struct generic_pm_domain *genpd) {}
static inline void genpd_debug_remove(struct generic_pm_domain *genpd) {}
static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {}
#endif

Expand Down Expand Up @@ -1142,7 +1157,7 @@ static int genpd_finish_suspend(struct device *dev, bool poweroff)
if (ret)
return ret;

if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))
if (device_wakeup_path(dev) && genpd_is_active_wakeup(genpd))
return 0;

if (genpd->dev_ops.stop && genpd->dev_ops.start &&
Expand Down Expand Up @@ -1196,7 +1211,7 @@ static int genpd_resume_noirq(struct device *dev)
if (IS_ERR(genpd))
return -EINVAL;

if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))
if (device_wakeup_path(dev) && genpd_is_active_wakeup(genpd))
return pm_generic_resume_noirq(dev);

genpd_lock(genpd);
Expand Down Expand Up @@ -1973,6 +1988,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,

mutex_lock(&gpd_list_lock);
list_add(&genpd->gpd_list_node, &gpd_list);
genpd_debug_add(genpd);
mutex_unlock(&gpd_list_lock);

return 0;
Expand Down Expand Up @@ -2006,6 +2022,7 @@ static int genpd_remove(struct generic_pm_domain *genpd)
kfree(link);
}

genpd_debug_remove(genpd);
list_del(&genpd->gpd_list_node);
genpd_unlock(genpd);
cancel_work_sync(&genpd->power_off_work);
Expand Down Expand Up @@ -2912,14 +2929,6 @@ core_initcall(genpd_bus_init);
/*** debugfs support ***/

#ifdef CONFIG_DEBUG_FS
#include <linux/pm.h>
#include <linux/device.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/init.h>
#include <linux/kobject.h>
static struct dentry *genpd_debugfs_dir;

/*
* TODO: This function is a slightly modified version of rtpm_status_show
* from sysfs.c, so generalize it.
Expand Down Expand Up @@ -3196,35 +3205,43 @@ DEFINE_SHOW_ATTRIBUTE(total_idle_time);
DEFINE_SHOW_ATTRIBUTE(devices);
DEFINE_SHOW_ATTRIBUTE(perf_state);

static int __init genpd_debug_init(void)
static void genpd_debug_add(struct generic_pm_domain *genpd)
{
struct dentry *d;

if (!genpd_debugfs_dir)
return;

d = debugfs_create_dir(genpd->name, genpd_debugfs_dir);

debugfs_create_file("current_state", 0444,
d, genpd, &status_fops);
debugfs_create_file("sub_domains", 0444,
d, genpd, &sub_domains_fops);
debugfs_create_file("idle_states", 0444,
d, genpd, &idle_states_fops);
debugfs_create_file("active_time", 0444,
d, genpd, &active_time_fops);
debugfs_create_file("total_idle_time", 0444,
d, genpd, &total_idle_time_fops);
debugfs_create_file("devices", 0444,
d, genpd, &devices_fops);
if (genpd->set_performance_state)
debugfs_create_file("perf_state", 0444,
d, genpd, &perf_state_fops);
}

static int __init genpd_debug_init(void)
{
struct generic_pm_domain *genpd;

genpd_debugfs_dir = debugfs_create_dir("pm_genpd", NULL);

debugfs_create_file("pm_genpd_summary", S_IRUGO, genpd_debugfs_dir,
NULL, &summary_fops);

list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
d = debugfs_create_dir(genpd->name, genpd_debugfs_dir);

debugfs_create_file("current_state", 0444,
d, genpd, &status_fops);
debugfs_create_file("sub_domains", 0444,
d, genpd, &sub_domains_fops);
debugfs_create_file("idle_states", 0444,
d, genpd, &idle_states_fops);
debugfs_create_file("active_time", 0444,
d, genpd, &active_time_fops);
debugfs_create_file("total_idle_time", 0444,
d, genpd, &total_idle_time_fops);
debugfs_create_file("devices", 0444,
d, genpd, &devices_fops);
if (genpd->set_performance_state)
debugfs_create_file("perf_state", 0444,
d, genpd, &perf_state_fops);
}
list_for_each_entry(genpd, &gpd_list, gpd_list_node)
genpd_debug_add(genpd);

return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/base/power/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ static pm_callback_t pm_noirq_op(const struct dev_pm_ops *ops, pm_message_t stat

static void pm_dev_dbg(struct device *dev, pm_message_t state, const char *info)
{
dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event),
dev_dbg(dev, "%s%s%s driver flags: %x\n", info, pm_verb(state.event),
((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ?
", may wakeup" : "");
", may wakeup" : "", dev->power.driver_flags);
}

static void pm_dev_err(struct device *dev, pm_message_t state, const char *info,
Expand Down Expand Up @@ -1359,7 +1359,7 @@ static void dpm_propagate_wakeup_to_parent(struct device *dev)

spin_lock_irq(&parent->power.lock);

if (dev->power.wakeup_path && !parent->power.ignore_children)
if (device_wakeup_path(dev) && !parent->power.ignore_children)
parent->power.wakeup_path = true;

spin_unlock_irq(&parent->power.lock);
Expand Down Expand Up @@ -1627,7 +1627,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
goto Complete;

/* Avoid direct_complete to let wakeup_path propagate. */
if (device_may_wakeup(dev) || dev->power.wakeup_path)
if (device_may_wakeup(dev) || device_wakeup_path(dev))
dev->power.direct_complete = false;

if (dev->power.direct_complete) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/i2c/busses/i2c-stm32f7.c
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,7 @@ static int stm32f7_i2c_suspend(struct device *dev)

i2c_mark_adapter_suspended(&i2c_dev->adap);

if (!device_may_wakeup(dev) && !dev->power.wakeup_path) {
if (!device_may_wakeup(dev) && !device_wakeup_path(dev)) {
ret = stm32f7_i2c_regs_backup(i2c_dev);
if (ret < 0) {
i2c_mark_adapter_resumed(&i2c_dev->adap);
Expand All @@ -2341,7 +2341,7 @@ static int stm32f7_i2c_resume(struct device *dev)
struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev);
int ret;

if (!device_may_wakeup(dev) && !dev->power.wakeup_path) {
if (!device_may_wakeup(dev) && !device_wakeup_path(dev)) {
ret = pm_runtime_force_resume(dev);
if (ret < 0)
return ret;
Expand Down
4 changes: 2 additions & 2 deletions drivers/pci/pci-acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,15 +1060,15 @@ static int acpi_pci_propagate_wakeup(struct pci_bus *bus, bool enable)
{
while (bus->parent) {
if (acpi_pm_device_can_wakeup(&bus->self->dev))
return acpi_pm_set_bridge_wakeup(&bus->self->dev, enable);
return acpi_pm_set_device_wakeup(&bus->self->dev, enable);

bus = bus->parent;
}

/* We have reached the root bus. */
if (bus->bridge) {
if (acpi_pm_device_can_wakeup(bus->bridge))
return acpi_pm_set_bridge_wakeup(bus->bridge, enable);
return acpi_pm_set_device_wakeup(bus->bridge, enable);
}
return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions drivers/powercap/intel_rapl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,10 @@ static const struct rapl_defaults rapl_defaults_cht = {
.compute_time_window = rapl_compute_time_window_atom,
};

static const struct rapl_defaults rapl_defaults_amd = {
.check_unit = rapl_check_unit_core,
};

static const struct x86_cpu_id rapl_ids[] __initconst = {
X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE, &rapl_defaults_core),
X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE_X, &rapl_defaults_core),
Expand Down Expand Up @@ -1061,6 +1065,9 @@ static const struct x86_cpu_id rapl_ids[] __initconst = {

X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNL, &rapl_defaults_hsw_server),
X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNM, &rapl_defaults_hsw_server),

X86_MATCH_VENDOR_FAM(AMD, 0x17, &rapl_defaults_amd),
X86_MATCH_VENDOR_FAM(AMD, 0x19, &rapl_defaults_amd),
{}
};
MODULE_DEVICE_TABLE(x86cpu, rapl_ids);
Expand Down
Loading

0 comments on commit 42b4ca0

Please sign in to comment.