mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 16:30:52 +07:00
8a537ece3d
The system wakeup framework is not very consistent with respect to the way it handles suspend-to-idle and generally wakeup events occurring during transitions to system low-power states. First off, system transitions in progress are aborted by the event reporting helpers like pm_wakeup_event() only if the wakeup_count sysfs attribute is in use (as documented), but there are cases in which system-wide transitions should be aborted even if that is not the case. For example, a wakeup signal from a designated wakeup device during system-wide PM transition, it should cause the transition to be aborted right away. Moreover, there is a freeze_wake() call in wakeup_source_activate(), but that really is only effective after suspend_freeze_state has been set to FREEZE_STATE_ENTER by freeze_enter(). However, it is very unlikely that wakeup_source_activate() will ever be called at that time, as it could only be triggered by a IRQF_NO_SUSPEND interrupt handler, so wakeups from suspend-to-idle don't really occur in wakeup_source_activate(). At the same time there is a way to abort a system suspend in progress (or wake up the system from suspend-to-idle), which is by calling pm_system_wakeup(), but in turn that doesn't cause any wakeup source objects to be activated, so it will not be covered by wakeup source statistics and will not prevent the system from suspending again immediately (in case autosleep is used, for example). Consequently, if anyone wants to abort system transitions in progress and allow the wakeup_count mechanism to work, they need to use both pm_system_wakeup() and pm_wakeup_event(), say, at the same time which is awkward. For the above reasons, make it possible to trigger pm_system_wakeup() from within wakeup_source_activate() and provide a new pm_wakeup_hard_event() helper to do so within the wakeup framework. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
222 lines
6.6 KiB
C
222 lines
6.6 KiB
C
/*
|
|
* pm_wakeup.h - Power management wakeup interface
|
|
*
|
|
* Copyright (C) 2008 Alan Stern
|
|
* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#ifndef _LINUX_PM_WAKEUP_H
|
|
#define _LINUX_PM_WAKEUP_H
|
|
|
|
#ifndef _DEVICE_H_
|
|
# error "please don't include this file directly"
|
|
#endif
|
|
|
|
#include <linux/types.h>
|
|
|
|
struct wake_irq;
|
|
|
|
/**
|
|
* struct wakeup_source - Representation of wakeup sources
|
|
*
|
|
* @name: Name of the wakeup source
|
|
* @entry: Wakeup source list entry
|
|
* @lock: Wakeup source lock
|
|
* @wakeirq: Optional device specific wakeirq
|
|
* @timer: Wakeup timer list
|
|
* @timer_expires: Wakeup timer expiration
|
|
* @total_time: Total time this wakeup source has been active.
|
|
* @max_time: Maximum time this wakeup source has been continuously active.
|
|
* @last_time: Monotonic clock when the wakeup source's was touched last time.
|
|
* @prevent_sleep_time: Total time this source has been preventing autosleep.
|
|
* @event_count: Number of signaled wakeup events.
|
|
* @active_count: Number of times the wakeup source was activated.
|
|
* @relax_count: Number of times the wakeup source was deactivated.
|
|
* @expire_count: Number of times the wakeup source's timeout has expired.
|
|
* @wakeup_count: Number of times the wakeup source might abort suspend.
|
|
* @active: Status of the wakeup source.
|
|
* @has_timeout: The wakeup source has been activated with a timeout.
|
|
*/
|
|
struct wakeup_source {
|
|
const char *name;
|
|
struct list_head entry;
|
|
spinlock_t lock;
|
|
struct wake_irq *wakeirq;
|
|
struct timer_list timer;
|
|
unsigned long timer_expires;
|
|
ktime_t total_time;
|
|
ktime_t max_time;
|
|
ktime_t last_time;
|
|
ktime_t start_prevent_time;
|
|
ktime_t prevent_sleep_time;
|
|
unsigned long event_count;
|
|
unsigned long active_count;
|
|
unsigned long relax_count;
|
|
unsigned long expire_count;
|
|
unsigned long wakeup_count;
|
|
bool active:1;
|
|
bool autosleep_enabled:1;
|
|
};
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
/*
|
|
* Changes to device_may_wakeup take effect on the next pm state change.
|
|
*/
|
|
|
|
static inline bool device_can_wakeup(struct device *dev)
|
|
{
|
|
return dev->power.can_wakeup;
|
|
}
|
|
|
|
static inline bool device_may_wakeup(struct device *dev)
|
|
{
|
|
return dev->power.can_wakeup && !!dev->power.wakeup;
|
|
}
|
|
|
|
/* drivers/base/power/wakeup.c */
|
|
extern void wakeup_source_prepare(struct wakeup_source *ws, const char *name);
|
|
extern struct wakeup_source *wakeup_source_create(const char *name);
|
|
extern void wakeup_source_drop(struct wakeup_source *ws);
|
|
extern void wakeup_source_destroy(struct wakeup_source *ws);
|
|
extern void wakeup_source_add(struct wakeup_source *ws);
|
|
extern void wakeup_source_remove(struct wakeup_source *ws);
|
|
extern struct wakeup_source *wakeup_source_register(const char *name);
|
|
extern void wakeup_source_unregister(struct wakeup_source *ws);
|
|
extern int device_wakeup_enable(struct device *dev);
|
|
extern int device_wakeup_disable(struct device *dev);
|
|
extern void device_set_wakeup_capable(struct device *dev, bool capable);
|
|
extern int device_init_wakeup(struct device *dev, bool val);
|
|
extern int device_set_wakeup_enable(struct device *dev, bool enable);
|
|
extern void __pm_stay_awake(struct wakeup_source *ws);
|
|
extern void pm_stay_awake(struct device *dev);
|
|
extern void __pm_relax(struct wakeup_source *ws);
|
|
extern void pm_relax(struct device *dev);
|
|
extern void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard);
|
|
extern void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard);
|
|
|
|
#else /* !CONFIG_PM_SLEEP */
|
|
|
|
static inline void device_set_wakeup_capable(struct device *dev, bool capable)
|
|
{
|
|
dev->power.can_wakeup = capable;
|
|
}
|
|
|
|
static inline bool device_can_wakeup(struct device *dev)
|
|
{
|
|
return dev->power.can_wakeup;
|
|
}
|
|
|
|
static inline void wakeup_source_prepare(struct wakeup_source *ws,
|
|
const char *name) {}
|
|
|
|
static inline struct wakeup_source *wakeup_source_create(const char *name)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline void wakeup_source_drop(struct wakeup_source *ws) {}
|
|
|
|
static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
|
|
|
|
static inline void wakeup_source_add(struct wakeup_source *ws) {}
|
|
|
|
static inline void wakeup_source_remove(struct wakeup_source *ws) {}
|
|
|
|
static inline struct wakeup_source *wakeup_source_register(const char *name)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
|
|
|
|
static inline int device_wakeup_enable(struct device *dev)
|
|
{
|
|
dev->power.should_wakeup = true;
|
|
return 0;
|
|
}
|
|
|
|
static inline int device_wakeup_disable(struct device *dev)
|
|
{
|
|
dev->power.should_wakeup = false;
|
|
return 0;
|
|
}
|
|
|
|
static inline int device_set_wakeup_enable(struct device *dev, bool enable)
|
|
{
|
|
dev->power.should_wakeup = enable;
|
|
return 0;
|
|
}
|
|
|
|
static inline int device_init_wakeup(struct device *dev, bool val)
|
|
{
|
|
device_set_wakeup_capable(dev, val);
|
|
device_set_wakeup_enable(dev, val);
|
|
return 0;
|
|
}
|
|
|
|
static inline bool device_may_wakeup(struct device *dev)
|
|
{
|
|
return dev->power.can_wakeup && dev->power.should_wakeup;
|
|
}
|
|
|
|
static inline void __pm_stay_awake(struct wakeup_source *ws) {}
|
|
|
|
static inline void pm_stay_awake(struct device *dev) {}
|
|
|
|
static inline void __pm_relax(struct wakeup_source *ws) {}
|
|
|
|
static inline void pm_relax(struct device *dev) {}
|
|
|
|
static inline void pm_wakeup_ws_event(struct wakeup_source *ws,
|
|
unsigned int msec, bool hard) {}
|
|
|
|
static inline void pm_wakeup_dev_event(struct device *dev, unsigned int msec,
|
|
bool hard) {}
|
|
|
|
#endif /* !CONFIG_PM_SLEEP */
|
|
|
|
static inline void wakeup_source_init(struct wakeup_source *ws,
|
|
const char *name)
|
|
{
|
|
wakeup_source_prepare(ws, name);
|
|
wakeup_source_add(ws);
|
|
}
|
|
|
|
static inline void wakeup_source_trash(struct wakeup_source *ws)
|
|
{
|
|
wakeup_source_remove(ws);
|
|
wakeup_source_drop(ws);
|
|
}
|
|
|
|
static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
|
|
{
|
|
return pm_wakeup_ws_event(ws, msec, false);
|
|
}
|
|
|
|
static inline void pm_wakeup_event(struct device *dev, unsigned int msec)
|
|
{
|
|
return pm_wakeup_dev_event(dev, msec, false);
|
|
}
|
|
|
|
static inline void pm_wakeup_hard_event(struct device *dev)
|
|
{
|
|
return pm_wakeup_dev_event(dev, 0, true);
|
|
}
|
|
|
|
#endif /* _LINUX_PM_WAKEUP_H */
|