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