xref: /linux/drivers/acpi/x86/s2idle.c (revision 7fc7f25419f5a6b09199ba4b5026b94ef184fa79)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Architecture-specific ACPI-based support for suspend-to-idle.
4  *
5  * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6  * Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
7  * Author: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
8  *
9  * On platforms supporting the Low Power S0 Idle interface there is an ACPI
10  * device object with the PNP0D80 compatible device ID (System Power Management
11  * Controller) and a specific _DSM method under it.  That method, if present,
12  * can be used to indicate to the platform that the OS is transitioning into a
13  * low-power state in which certain types of activity are not desirable or that
14  * it is leaving such a state, which allows the platform to adjust its operation
15  * mode accordingly.
16  */
17 
18 #include <linux/acpi.h>
19 #include <linux/device.h>
20 #include <linux/dmi.h>
21 #include <linux/suspend.h>
22 
23 #include "../sleep.h"
24 
25 #ifdef CONFIG_SUSPEND
26 
27 static bool sleep_no_lps0 __read_mostly;
28 module_param(sleep_no_lps0, bool, 0644);
29 MODULE_PARM_DESC(sleep_no_lps0, "Do not use the special LPS0 device interface");
30 
31 static bool prefer_microsoft_dsm_guid __read_mostly;
32 module_param(prefer_microsoft_dsm_guid, bool, 0644);
33 MODULE_PARM_DESC(prefer_microsoft_dsm_guid, "Prefer using Microsoft GUID in LPS0 device _DSM evaluation");
34 
35 static const struct acpi_device_id lps0_device_ids[] = {
36 	{"PNP0D80", },
37 	{"", },
38 };
39 
40 /* Microsoft platform agnostic UUID */
41 #define ACPI_LPS0_DSM_UUID_MICROSOFT      "11e00d56-ce64-47ce-837b-1f898f9aa461"
42 
43 #define ACPI_LPS0_DSM_UUID	"c4eb40a0-6cd2-11e2-bcfd-0800200c9a66"
44 
45 #define ACPI_LPS0_GET_DEVICE_CONSTRAINTS	1
46 #define ACPI_LPS0_SCREEN_OFF	3
47 #define ACPI_LPS0_SCREEN_ON	4
48 #define ACPI_LPS0_ENTRY		5
49 #define ACPI_LPS0_EXIT		6
50 #define ACPI_LPS0_MS_ENTRY      7
51 #define ACPI_LPS0_MS_EXIT       8
52 
53 /* AMD */
54 #define ACPI_LPS0_DSM_UUID_AMD      "e3f32452-febc-43ce-9039-932122d37721"
55 #define ACPI_LPS0_ENTRY_AMD         2
56 #define ACPI_LPS0_EXIT_AMD          3
57 #define ACPI_LPS0_SCREEN_OFF_AMD    4
58 #define ACPI_LPS0_SCREEN_ON_AMD     5
59 
60 static acpi_handle lps0_device_handle;
61 static guid_t lps0_dsm_guid;
62 static int lps0_dsm_func_mask;
63 
64 static guid_t lps0_dsm_guid_microsoft;
65 static int lps0_dsm_func_mask_microsoft;
66 
67 /* Device constraint entry structure */
68 struct lpi_device_info {
69 	char *name;
70 	int enabled;
71 	union acpi_object *package;
72 };
73 
74 /* Constraint package structure */
75 struct lpi_device_constraint {
76 	int uid;
77 	int min_dstate;
78 	int function_states;
79 };
80 
81 struct lpi_constraints {
82 	acpi_handle handle;
83 	int min_dstate;
84 };
85 
86 /* AMD Constraint package structure */
87 struct lpi_device_constraint_amd {
88 	char *name;
89 	int enabled;
90 	int function_states;
91 	int min_dstate;
92 };
93 
94 static LIST_HEAD(lps0_s2idle_devops_head);
95 
96 static struct lpi_constraints *lpi_constraints_table;
97 static int lpi_constraints_table_size;
98 static int rev_id;
99 
100 static void lpi_device_get_constraints_amd(void)
101 {
102 	union acpi_object *out_obj;
103 	int i, j, k;
104 
105 	out_obj = acpi_evaluate_dsm_typed(lps0_device_handle, &lps0_dsm_guid,
106 					  rev_id, ACPI_LPS0_GET_DEVICE_CONSTRAINTS,
107 					  NULL, ACPI_TYPE_PACKAGE);
108 
109 	acpi_handle_debug(lps0_device_handle, "_DSM function 1 eval %s\n",
110 			  out_obj ? "successful" : "failed");
111 
112 	if (!out_obj)
113 		return;
114 
115 	for (i = 0; i < out_obj->package.count; i++) {
116 		union acpi_object *package = &out_obj->package.elements[i];
117 
118 		if (package->type == ACPI_TYPE_PACKAGE) {
119 			lpi_constraints_table = kcalloc(package->package.count,
120 							sizeof(*lpi_constraints_table),
121 							GFP_KERNEL);
122 
123 			if (!lpi_constraints_table)
124 				goto free_acpi_buffer;
125 
126 			acpi_handle_debug(lps0_device_handle,
127 					  "LPI: constraints list begin:\n");
128 
129 			for (j = 0; j < package->package.count; ++j) {
130 				union acpi_object *info_obj = &package->package.elements[j];
131 				struct lpi_device_constraint_amd dev_info = {};
132 				struct lpi_constraints *list;
133 				acpi_status status;
134 
135 				for (k = 0; k < info_obj->package.count; ++k) {
136 					union acpi_object *obj = &info_obj->package.elements[k];
137 
138 					list = &lpi_constraints_table[lpi_constraints_table_size];
139 					list->min_dstate = -1;
140 
141 					switch (k) {
142 					case 0:
143 						dev_info.enabled = obj->integer.value;
144 						break;
145 					case 1:
146 						dev_info.name = obj->string.pointer;
147 						break;
148 					case 2:
149 						dev_info.function_states = obj->integer.value;
150 						break;
151 					case 3:
152 						dev_info.min_dstate = obj->integer.value;
153 						break;
154 					}
155 
156 					if (!dev_info.enabled || !dev_info.name ||
157 					    !dev_info.min_dstate)
158 						continue;
159 
160 					status = acpi_get_handle(NULL, dev_info.name,
161 								 &list->handle);
162 					if (ACPI_FAILURE(status))
163 						continue;
164 
165 					acpi_handle_debug(lps0_device_handle,
166 							  "Name:%s\n", dev_info.name);
167 
168 					list->min_dstate = dev_info.min_dstate;
169 
170 					if (list->min_dstate < 0) {
171 						acpi_handle_debug(lps0_device_handle,
172 								  "Incomplete constraint defined\n");
173 						continue;
174 					}
175 				}
176 				lpi_constraints_table_size++;
177 			}
178 		}
179 	}
180 
181 	acpi_handle_debug(lps0_device_handle, "LPI: constraints list end\n");
182 
183 free_acpi_buffer:
184 	ACPI_FREE(out_obj);
185 }
186 
187 static void lpi_device_get_constraints(void)
188 {
189 	union acpi_object *out_obj;
190 	int i;
191 
192 	out_obj = acpi_evaluate_dsm_typed(lps0_device_handle, &lps0_dsm_guid,
193 					  1, ACPI_LPS0_GET_DEVICE_CONSTRAINTS,
194 					  NULL, ACPI_TYPE_PACKAGE);
195 
196 	acpi_handle_debug(lps0_device_handle, "_DSM function 1 eval %s\n",
197 			  out_obj ? "successful" : "failed");
198 
199 	if (!out_obj)
200 		return;
201 
202 	lpi_constraints_table = kcalloc(out_obj->package.count,
203 					sizeof(*lpi_constraints_table),
204 					GFP_KERNEL);
205 	if (!lpi_constraints_table)
206 		goto free_acpi_buffer;
207 
208 	acpi_handle_debug(lps0_device_handle, "LPI: constraints list begin:\n");
209 
210 	for (i = 0; i < out_obj->package.count; i++) {
211 		struct lpi_constraints *constraint;
212 		acpi_status status;
213 		union acpi_object *package = &out_obj->package.elements[i];
214 		struct lpi_device_info info = { };
215 		int package_count = 0, j;
216 
217 		if (!package)
218 			continue;
219 
220 		for (j = 0; j < package->package.count; ++j) {
221 			union acpi_object *element =
222 					&(package->package.elements[j]);
223 
224 			switch (element->type) {
225 			case ACPI_TYPE_INTEGER:
226 				info.enabled = element->integer.value;
227 				break;
228 			case ACPI_TYPE_STRING:
229 				info.name = element->string.pointer;
230 				break;
231 			case ACPI_TYPE_PACKAGE:
232 				package_count = element->package.count;
233 				info.package = element->package.elements;
234 				break;
235 			}
236 		}
237 
238 		if (!info.enabled || !info.package || !info.name)
239 			continue;
240 
241 		constraint = &lpi_constraints_table[lpi_constraints_table_size];
242 
243 		status = acpi_get_handle(NULL, info.name, &constraint->handle);
244 		if (ACPI_FAILURE(status))
245 			continue;
246 
247 		acpi_handle_debug(lps0_device_handle,
248 				  "index:%d Name:%s\n", i, info.name);
249 
250 		constraint->min_dstate = -1;
251 
252 		for (j = 0; j < package_count; ++j) {
253 			union acpi_object *info_obj = &info.package[j];
254 			union acpi_object *cnstr_pkg;
255 			union acpi_object *obj;
256 			struct lpi_device_constraint dev_info;
257 
258 			switch (info_obj->type) {
259 			case ACPI_TYPE_INTEGER:
260 				/* version */
261 				break;
262 			case ACPI_TYPE_PACKAGE:
263 				if (info_obj->package.count < 2)
264 					break;
265 
266 				cnstr_pkg = info_obj->package.elements;
267 				obj = &cnstr_pkg[0];
268 				dev_info.uid = obj->integer.value;
269 				obj = &cnstr_pkg[1];
270 				dev_info.min_dstate = obj->integer.value;
271 
272 				acpi_handle_debug(lps0_device_handle,
273 					"uid:%d min_dstate:%s\n",
274 					dev_info.uid,
275 					acpi_power_state_string(dev_info.min_dstate));
276 
277 				constraint->min_dstate = dev_info.min_dstate;
278 				break;
279 			}
280 		}
281 
282 		if (constraint->min_dstate < 0) {
283 			acpi_handle_debug(lps0_device_handle,
284 					  "Incomplete constraint defined\n");
285 			continue;
286 		}
287 
288 		lpi_constraints_table_size++;
289 	}
290 
291 	acpi_handle_debug(lps0_device_handle, "LPI: constraints list end\n");
292 
293 free_acpi_buffer:
294 	ACPI_FREE(out_obj);
295 }
296 
297 static void lpi_check_constraints(void)
298 {
299 	int i;
300 
301 	for (i = 0; i < lpi_constraints_table_size; ++i) {
302 		acpi_handle handle = lpi_constraints_table[i].handle;
303 		struct acpi_device *adev = acpi_fetch_acpi_dev(handle);
304 
305 		if (!adev)
306 			continue;
307 
308 		acpi_handle_debug(handle,
309 			"LPI: required min power state:%s current power state:%s\n",
310 			acpi_power_state_string(lpi_constraints_table[i].min_dstate),
311 			acpi_power_state_string(adev->power.state));
312 
313 		if (!adev->flags.power_manageable) {
314 			acpi_handle_info(handle, "LPI: Device not power manageable\n");
315 			lpi_constraints_table[i].handle = NULL;
316 			continue;
317 		}
318 
319 		if (adev->power.state < lpi_constraints_table[i].min_dstate)
320 			acpi_handle_info(handle,
321 				"LPI: Constraint not met; min power state:%s current power state:%s\n",
322 				acpi_power_state_string(lpi_constraints_table[i].min_dstate),
323 				acpi_power_state_string(adev->power.state));
324 	}
325 }
326 
327 static void acpi_sleep_run_lps0_dsm(unsigned int func, unsigned int func_mask, guid_t dsm_guid)
328 {
329 	union acpi_object *out_obj;
330 
331 	if (!(func_mask & (1 << func)))
332 		return;
333 
334 	out_obj = acpi_evaluate_dsm(lps0_device_handle, &dsm_guid,
335 					rev_id, func, NULL);
336 	ACPI_FREE(out_obj);
337 
338 	acpi_handle_debug(lps0_device_handle, "_DSM function %u evaluation %s\n",
339 			  func, out_obj ? "successful" : "failed");
340 }
341 
342 static bool acpi_s2idle_vendor_amd(void)
343 {
344 	return boot_cpu_data.x86_vendor == X86_VENDOR_AMD;
345 }
346 
347 static int validate_dsm(acpi_handle handle, const char *uuid, int rev, guid_t *dsm_guid)
348 {
349 	union acpi_object *obj;
350 	int ret = -EINVAL;
351 
352 	guid_parse(uuid, dsm_guid);
353 	obj = acpi_evaluate_dsm(handle, dsm_guid, rev, 0, NULL);
354 
355 	/* Check if the _DSM is present and as expected. */
356 	if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length == 0 ||
357 	    obj->buffer.length > sizeof(u32)) {
358 		acpi_handle_debug(handle,
359 				"_DSM UUID %s rev %d function 0 evaluation failed\n", uuid, rev);
360 		goto out;
361 	}
362 
363 	ret = *(int *)obj->buffer.pointer;
364 	acpi_handle_debug(handle, "_DSM UUID %s rev %d function mask: 0x%x\n", uuid, rev, ret);
365 
366 out:
367 	ACPI_FREE(obj);
368 	return ret;
369 }
370 
371 struct amd_lps0_hid_device_data {
372 	const unsigned int rev_id;
373 	const bool check_off_by_one;
374 	const bool prefer_amd_guid;
375 };
376 
377 static const struct amd_lps0_hid_device_data amd_picasso = {
378 	.rev_id = 0,
379 	.check_off_by_one = true,
380 	.prefer_amd_guid = false,
381 };
382 
383 static const struct amd_lps0_hid_device_data amd_cezanne = {
384 	.rev_id = 0,
385 	.check_off_by_one = false,
386 	.prefer_amd_guid = false,
387 };
388 
389 static const struct amd_lps0_hid_device_data amd_rembrandt = {
390 	.rev_id = 2,
391 	.check_off_by_one = false,
392 	.prefer_amd_guid = true,
393 };
394 
395 static const struct acpi_device_id amd_hid_ids[] = {
396 	{"AMD0004",	(kernel_ulong_t)&amd_picasso,	},
397 	{"AMD0005",	(kernel_ulong_t)&amd_picasso,	},
398 	{"AMDI0005",	(kernel_ulong_t)&amd_picasso,	},
399 	{"AMDI0006",	(kernel_ulong_t)&amd_cezanne,	},
400 	{"AMDI0007",	(kernel_ulong_t)&amd_rembrandt,	},
401 	{}
402 };
403 
404 static int lps0_prefer_microsoft(const struct dmi_system_id *id)
405 {
406 	pr_debug("Preferring Microsoft GUID.\n");
407 	prefer_microsoft_dsm_guid = true;
408 	return 0;
409 }
410 
411 static const struct dmi_system_id s2idle_dmi_table[] __initconst = {
412 	{
413 		/*
414 		 * ASUS TUF Gaming A17 FA707RE
415 		 * https://bugzilla.kernel.org/show_bug.cgi?id=216101
416 		 */
417 		.callback = lps0_prefer_microsoft,
418 		.matches = {
419 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
420 			DMI_MATCH(DMI_PRODUCT_NAME, "ASUS TUF Gaming A17"),
421 		},
422 	},
423 	{
424 		/* ASUS ROG Zephyrus G14 (2022) */
425 		.callback = lps0_prefer_microsoft,
426 		.matches = {
427 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
428 			DMI_MATCH(DMI_PRODUCT_NAME, "ROG Zephyrus G14 GA402"),
429 		},
430 	},
431 	{
432 		/*
433 		 * Lenovo Yoga Slim 7 Pro X 14ARH7
434 		 * https://bugzilla.kernel.org/show_bug.cgi?id=216473 : 82V2
435 		 * https://bugzilla.kernel.org/show_bug.cgi?id=216438 : 82TL
436 		 */
437 		.callback = lps0_prefer_microsoft,
438 		.matches = {
439 			DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
440 			DMI_MATCH(DMI_PRODUCT_NAME, "82"),
441 		},
442 	},
443 	{
444 		/*
445 		 * ASUSTeK COMPUTER INC. ROG Flow X13 GV301RE_GV301RE
446 		 * https://gitlab.freedesktop.org/drm/amd/-/issues/2148
447 		 */
448 		.callback = lps0_prefer_microsoft,
449 		.matches = {
450 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
451 			DMI_MATCH(DMI_PRODUCT_NAME, "ROG Flow X13 GV301"),
452 		},
453 	},
454 	{
455 		/*
456 		 * ASUSTeK COMPUTER INC. ROG Flow X16 GV601RW_GV601RW
457 		 * https://gitlab.freedesktop.org/drm/amd/-/issues/2148
458 		 */
459 		.callback = lps0_prefer_microsoft,
460 		.matches = {
461 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
462 			DMI_MATCH(DMI_PRODUCT_NAME, "ROG Flow X16 GV601"),
463 		},
464 	},
465 	{}
466 };
467 
468 static int lps0_device_attach(struct acpi_device *adev,
469 			      const struct acpi_device_id *not_used)
470 {
471 	if (lps0_device_handle)
472 		return 0;
473 
474 	lps0_dsm_func_mask_microsoft = validate_dsm(adev->handle,
475 						    ACPI_LPS0_DSM_UUID_MICROSOFT, 0,
476 						    &lps0_dsm_guid_microsoft);
477 	if (acpi_s2idle_vendor_amd()) {
478 		static const struct acpi_device_id *dev_id;
479 		const struct amd_lps0_hid_device_data *data;
480 
481 		for (dev_id = &amd_hid_ids[0]; dev_id->id[0]; dev_id++)
482 			if (acpi_dev_hid_uid_match(adev, dev_id->id, NULL))
483 				break;
484 		if (dev_id->id[0])
485 			data = (const struct amd_lps0_hid_device_data *) dev_id->driver_data;
486 		else
487 			data = &amd_rembrandt;
488 		rev_id = data->rev_id;
489 		lps0_dsm_func_mask = validate_dsm(adev->handle,
490 					ACPI_LPS0_DSM_UUID_AMD, rev_id, &lps0_dsm_guid);
491 		if (lps0_dsm_func_mask > 0x3 && data->check_off_by_one) {
492 			lps0_dsm_func_mask = (lps0_dsm_func_mask << 1) | 0x1;
493 			acpi_handle_debug(adev->handle, "_DSM UUID %s: Adjusted function mask: 0x%x\n",
494 					  ACPI_LPS0_DSM_UUID_AMD, lps0_dsm_func_mask);
495 		} else if (lps0_dsm_func_mask_microsoft > 0 && data->prefer_amd_guid &&
496 				!prefer_microsoft_dsm_guid) {
497 			lps0_dsm_func_mask_microsoft = -EINVAL;
498 			acpi_handle_debug(adev->handle, "_DSM Using AMD method\n");
499 		}
500 	} else {
501 		rev_id = 1;
502 		lps0_dsm_func_mask = validate_dsm(adev->handle,
503 					ACPI_LPS0_DSM_UUID, rev_id, &lps0_dsm_guid);
504 		if (!prefer_microsoft_dsm_guid)
505 			lps0_dsm_func_mask_microsoft = -EINVAL;
506 	}
507 
508 	if (lps0_dsm_func_mask < 0 && lps0_dsm_func_mask_microsoft < 0)
509 		return 0; //function evaluation failed
510 
511 	lps0_device_handle = adev->handle;
512 
513 	if (acpi_s2idle_vendor_amd())
514 		lpi_device_get_constraints_amd();
515 	else
516 		lpi_device_get_constraints();
517 
518 	/*
519 	 * Use suspend-to-idle by default if ACPI_FADT_LOW_POWER_S0 is set in
520 	 * the FADT and the default suspend mode was not set from the command
521 	 * line.
522 	 */
523 	if ((acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) &&
524 	    mem_sleep_default > PM_SUSPEND_MEM && !acpi_sleep_default_s3) {
525 		mem_sleep_current = PM_SUSPEND_TO_IDLE;
526 		pr_info("Low-power S0 idle used by default for system suspend\n");
527 	}
528 
529 	/*
530 	 * Some LPS0 systems, like ASUS Zenbook UX430UNR/i7-8550U, require the
531 	 * EC GPE to be enabled while suspended for certain wakeup devices to
532 	 * work, so mark it as wakeup-capable.
533 	 */
534 	acpi_ec_mark_gpe_for_wake();
535 
536 	return 0;
537 }
538 
539 static struct acpi_scan_handler lps0_handler = {
540 	.ids = lps0_device_ids,
541 	.attach = lps0_device_attach,
542 };
543 
544 int acpi_s2idle_prepare_late(void)
545 {
546 	struct acpi_s2idle_dev_ops *handler;
547 
548 	if (!lps0_device_handle || sleep_no_lps0)
549 		return 0;
550 
551 	if (pm_debug_messages_on)
552 		lpi_check_constraints();
553 
554 	/* Screen off */
555 	if (lps0_dsm_func_mask > 0)
556 		acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ?
557 					ACPI_LPS0_SCREEN_OFF_AMD :
558 					ACPI_LPS0_SCREEN_OFF,
559 					lps0_dsm_func_mask, lps0_dsm_guid);
560 
561 	if (lps0_dsm_func_mask_microsoft > 0)
562 		acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_OFF,
563 				lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
564 
565 	/* LPS0 entry */
566 	if (lps0_dsm_func_mask > 0)
567 		acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ?
568 					ACPI_LPS0_ENTRY_AMD :
569 					ACPI_LPS0_ENTRY,
570 					lps0_dsm_func_mask, lps0_dsm_guid);
571 	if (lps0_dsm_func_mask_microsoft > 0) {
572 		acpi_sleep_run_lps0_dsm(ACPI_LPS0_ENTRY,
573 				lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
574 		/* modern standby entry */
575 		acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_ENTRY,
576 				lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
577 	}
578 
579 	list_for_each_entry(handler, &lps0_s2idle_devops_head, list_node) {
580 		if (handler->prepare)
581 			handler->prepare();
582 	}
583 
584 	return 0;
585 }
586 
587 void acpi_s2idle_check(void)
588 {
589 	struct acpi_s2idle_dev_ops *handler;
590 
591 	if (!lps0_device_handle || sleep_no_lps0)
592 		return;
593 
594 	list_for_each_entry(handler, &lps0_s2idle_devops_head, list_node) {
595 		if (handler->check)
596 			handler->check();
597 	}
598 }
599 
600 void acpi_s2idle_restore_early(void)
601 {
602 	struct acpi_s2idle_dev_ops *handler;
603 
604 	if (!lps0_device_handle || sleep_no_lps0)
605 		return;
606 
607 	list_for_each_entry(handler, &lps0_s2idle_devops_head, list_node)
608 		if (handler->restore)
609 			handler->restore();
610 
611 	/* Modern standby exit */
612 	if (lps0_dsm_func_mask_microsoft > 0)
613 		acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,
614 				lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
615 
616 	/* LPS0 exit */
617 	if (lps0_dsm_func_mask > 0)
618 		acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ?
619 					ACPI_LPS0_EXIT_AMD :
620 					ACPI_LPS0_EXIT,
621 					lps0_dsm_func_mask, lps0_dsm_guid);
622 	if (lps0_dsm_func_mask_microsoft > 0)
623 		acpi_sleep_run_lps0_dsm(ACPI_LPS0_EXIT,
624 				lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
625 
626 	/* Screen on */
627 	if (lps0_dsm_func_mask_microsoft > 0)
628 		acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_ON,
629 				lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft);
630 	if (lps0_dsm_func_mask > 0)
631 		acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ?
632 					ACPI_LPS0_SCREEN_ON_AMD :
633 					ACPI_LPS0_SCREEN_ON,
634 					lps0_dsm_func_mask, lps0_dsm_guid);
635 }
636 
637 static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = {
638 	.begin = acpi_s2idle_begin,
639 	.prepare = acpi_s2idle_prepare,
640 	.prepare_late = acpi_s2idle_prepare_late,
641 	.check = acpi_s2idle_check,
642 	.wake = acpi_s2idle_wake,
643 	.restore_early = acpi_s2idle_restore_early,
644 	.restore = acpi_s2idle_restore,
645 	.end = acpi_s2idle_end,
646 };
647 
648 void __init acpi_s2idle_setup(void)
649 {
650 	dmi_check_system(s2idle_dmi_table);
651 	acpi_scan_add_handler(&lps0_handler);
652 	s2idle_set_ops(&acpi_s2idle_ops_lps0);
653 }
654 
655 int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg)
656 {
657 	unsigned int sleep_flags;
658 
659 	if (!lps0_device_handle || sleep_no_lps0)
660 		return -ENODEV;
661 
662 	sleep_flags = lock_system_sleep();
663 	list_add(&arg->list_node, &lps0_s2idle_devops_head);
664 	unlock_system_sleep(sleep_flags);
665 
666 	return 0;
667 }
668 EXPORT_SYMBOL_GPL(acpi_register_lps0_dev);
669 
670 void acpi_unregister_lps0_dev(struct acpi_s2idle_dev_ops *arg)
671 {
672 	unsigned int sleep_flags;
673 
674 	if (!lps0_device_handle || sleep_no_lps0)
675 		return;
676 
677 	sleep_flags = lock_system_sleep();
678 	list_del(&arg->list_node);
679 	unlock_system_sleep(sleep_flags);
680 }
681 EXPORT_SYMBOL_GPL(acpi_unregister_lps0_dev);
682 
683 #endif /* CONFIG_SUSPEND */
684