1152 lines · 28.3 KB · C
RawDownload
// SPDX-License-Identifier: GPL-2.0-only/* * sleep.c - ACPI sleep support. * * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com> * Copyright (c) 2000-2003 Patrick Mochel * Copyright (c) 2003 Open Source Development Lab */ #define pr_fmt(fmt) "ACPI: PM: " fmt #include <linux/delay.h>#include <linux/irq.h>#include <linux/dmi.h>#include <linux/device.h>#include <linux/interrupt.h>#include <linux/suspend.h>#include <linux/reboot.h>#include <linux/acpi.h>#include <linux/module.h>#include <linux/syscore_ops.h>#include <asm/io.h>#include <trace/events/power.h> #include "internal.h"#include "sleep.h" /* * Some HW-full platforms do not have _S5, so they may need * to leverage efi power off for a shutdown. */bool acpi_no_s5;static u8 sleep_states[ACPI_S_STATE_COUNT]; static void acpi_sleep_tts_switch(u32 acpi_state){	acpi_status status; 	status = acpi_execute_simple_method(NULL, "\\_TTS", acpi_state);	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {		/*		 * OS can't evaluate the _TTS object correctly. Some warning		 * message will be printed. But it won't break anything.		 */		pr_notice("Failure in evaluating _TTS object\n");	}} static int tts_notify_reboot(struct notifier_block *this,			unsigned long code, void *x){	acpi_sleep_tts_switch(ACPI_STATE_S5);	return NOTIFY_DONE;} static struct notifier_block tts_notifier = {	.notifier_call	= tts_notify_reboot,	.next		= NULL,	.priority	= 0,}; #ifndef acpi_skip_set_wakeup_address#define acpi_skip_set_wakeup_address() false#endif static int acpi_sleep_prepare(u32 acpi_state){#ifdef CONFIG_ACPI_SLEEP	unsigned long acpi_wakeup_address; 	/* do we have a wakeup address for S2 and S3? */	if (acpi_state == ACPI_STATE_S3 && !acpi_skip_set_wakeup_address()) {		acpi_wakeup_address = acpi_get_wakeup_address();		if (!acpi_wakeup_address)			return -EFAULT;		acpi_set_waking_vector(acpi_wakeup_address); 	}#endif	pr_info("Preparing to enter system sleep state S%d\n", acpi_state);	acpi_enable_wakeup_devices(acpi_state);	acpi_enter_sleep_state_prep(acpi_state);	return 0;} bool acpi_sleep_state_supported(u8 sleep_state){	acpi_status status;	u8 type_a, type_b; 	status = acpi_get_sleep_type_data(sleep_state, &type_a, &type_b);	return ACPI_SUCCESS(status) && (!acpi_gbl_reduced_hardware		|| (acpi_gbl_FADT.sleep_control.address			&& acpi_gbl_FADT.sleep_status.address));} #ifdef CONFIG_ACPI_SLEEPstatic u32 acpi_target_sleep_state = ACPI_STATE_S0; u32 acpi_target_system_state(void){	return acpi_target_sleep_state;}EXPORT_SYMBOL_GPL(acpi_target_system_state); static bool pwr_btn_event_pending; /* * The ACPI specification wants us to save NVS memory regions during hibernation * and to restore them during the subsequent resume.  Windows does that also for * suspend to RAM.  However, it is known that this mechanism does not work on * all machines, so we allow the user to disable it with the help of the * 'acpi_sleep=nonvs' kernel command line option. */static bool nvs_nosave; void __init acpi_nvs_nosave(void){	nvs_nosave = true;} /* * The ACPI specification wants us to save NVS memory regions during hibernation * but says nothing about saving NVS during S3.  Not all versions of Windows * save NVS on S3 suspend either, and it is clear that not all systems need * NVS to be saved at S3 time.  To improve suspend/resume time, allow the * user to disable saving NVS on S3 if their system does not require it, but * continue to save/restore NVS for S4 as specified. */static bool nvs_nosave_s3; void __init acpi_nvs_nosave_s3(void){	nvs_nosave_s3 = true;} static int __init init_nvs_save_s3(const struct dmi_system_id *d){	nvs_nosave_s3 = false;	return 0;} /* * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the * user to request that behavior by using the 'acpi_old_suspend_ordering' * kernel command line option that causes the following variable to be set. */static bool old_suspend_ordering; void __init acpi_old_suspend_ordering(void){	old_suspend_ordering = true;} static int __init init_old_suspend_ordering(const struct dmi_system_id *d){	acpi_old_suspend_ordering();	return 0;} static int __init init_nvs_nosave(const struct dmi_system_id *d){	acpi_nvs_nosave();	return 0;} bool acpi_sleep_default_s3; static int __init init_default_s3(const struct dmi_system_id *d){	acpi_sleep_default_s3 = true;	return 0;} static const struct dmi_system_id acpisleep_dmi_table[] __initconst = {	{	.callback = init_old_suspend_ordering,	.ident = "Abit KN9 (nForce4 variant)",	.matches = {		DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),		DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),		},	},	{	.callback = init_old_suspend_ordering,	.ident = "HP xw4600 Workstation",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),		DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),		},	},	{	.callback = init_old_suspend_ordering,	.ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",	.matches = {		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),		DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),		},	},	{	.callback = init_old_suspend_ordering,	.ident = "Panasonic CF51-2L",	.matches = {		DMI_MATCH(DMI_BOARD_VENDOR,				"Matsushita Electric Industrial Co.,Ltd."),		DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VGN-FW41E_H",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW41E_H"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VGN-FW21E",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VGN-FW21M",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21M"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VPCEB17FX",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VGN-SR11M",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Everex StepNote Series",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),		DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VPCEB1Z1E",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VGN-NW130D",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VPCCW29FX",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Averatec AV1020-ED2",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),		DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),		},	},	{	.callback = init_old_suspend_ordering,	.ident = "Asus A8N-SLI DELUXE",	.matches = {		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),		DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),		},	},	{	.callback = init_old_suspend_ordering,	.ident = "Asus A8N-SLI Premium",	.matches = {		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),		DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VGN-SR26GN_P",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VPCEB1S1E",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1S1E"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Sony Vaio VGN-FW520F",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Asus K54C",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),		DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),		},	},	{	.callback = init_nvs_nosave,	.ident = "Asus K54HR",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),		DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),		},	},	{	.callback = init_nvs_save_s3,	.ident = "Asus 1025C",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),		DMI_MATCH(DMI_PRODUCT_NAME, "1025C"),		},	},	/*	 * The ASUS ROG M16 from 2023 has many events which wake it from s2idle	 * resulting in excessive battery drain and risk of laptop overheating,	 * these events can be caused by the MMC or  y AniMe display if installed.	 * The match is valid for all of the GU604V<x> range.	 */	{	.callback = init_default_s3,	.ident = "ASUS ROG Zephyrus M16 (2023)",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),		DMI_MATCH(DMI_PRODUCT_NAME, "ROG Zephyrus M16 GU604V"),		},	},	/*	 * https://bugzilla.kernel.org/show_bug.cgi?id=189431	 * Lenovo G50-45 is a platform later than 2012, but needs nvs memory	 * saving during S3.	 */	{	.callback = init_nvs_save_s3,	.ident = "Lenovo G50-45",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),		DMI_MATCH(DMI_PRODUCT_NAME, "80E3"),		},	},	{	.callback = init_nvs_save_s3,	.ident = "Lenovo G40-45",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),		DMI_MATCH(DMI_PRODUCT_NAME, "80E1"),		},	},	{	.callback = init_nvs_save_s3,	.ident = "Lenovo G70-35",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),		DMI_MATCH(DMI_PRODUCT_NAME, "80Q5"),		},	},	/*	 * ThinkPad X1 Tablet(2016) cannot do suspend-to-idle using	 * the Low Power S0 Idle firmware interface (see	 * https://bugzilla.kernel.org/show_bug.cgi?id=199057).	 */	{	.callback = init_default_s3,	.ident = "ThinkPad X1 Tablet(2016)",	.matches = {		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),		DMI_MATCH(DMI_PRODUCT_NAME, "20GGA00L00"),		},	},	{},}; static bool ignore_blacklist; void __init acpi_sleep_no_blacklist(void){	ignore_blacklist = true;} static void __init acpi_sleep_dmi_check(void){	if (ignore_blacklist)		return; 	if (dmi_get_bios_year() >= 2012)		acpi_nvs_nosave_s3(); 	dmi_check_system(acpisleep_dmi_table);} /** * acpi_pm_freeze - Disable the GPEs and suspend EC transactions. */static int acpi_pm_freeze(void){	acpi_disable_all_gpes();	acpi_os_wait_events_complete();	acpi_ec_block_transactions();	return 0;} /** * acpi_pm_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS. */static int acpi_pm_pre_suspend(void){	acpi_pm_freeze();	return suspend_nvs_save();} /** *	__acpi_pm_prepare - Prepare the platform to enter the target state. * *	If necessary, set the firmware waking vector and do arch-specific *	nastiness to get the wakeup code to the waking vector. */static int __acpi_pm_prepare(void){	int error = acpi_sleep_prepare(acpi_target_sleep_state);	if (error)		acpi_target_sleep_state = ACPI_STATE_S0; 	return error;} /** *	acpi_pm_prepare - Prepare the platform to enter the target sleep *		state and disable the GPEs. */static int acpi_pm_prepare(void){	int error = __acpi_pm_prepare();	if (!error)		error = acpi_pm_pre_suspend(); 	return error;} /** *	acpi_pm_finish - Instruct the platform to leave a sleep state. * *	This is called after we wake back up (or if entering the sleep state *	failed). */static void acpi_pm_finish(void){	struct acpi_device *pwr_btn_adev;	u32 acpi_state = acpi_target_sleep_state; 	acpi_ec_unblock_transactions();	suspend_nvs_free(); 	if (acpi_state == ACPI_STATE_S0)		return; 	pr_info("Waking up from system sleep state S%d\n", acpi_state);	acpi_disable_wakeup_devices(acpi_state);	acpi_leave_sleep_state(acpi_state); 	/* reset firmware waking vector */

Lines 1–500 of 1152.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t