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