acpi_status acpi_hw_legacy_wake_prep(u8 sleep_state, u8 flags) { acpi_status status; struct acpi_bit_register_info *sleep_type_reg_info; struct acpi_bit_register_info *sleep_enable_reg_info; u32 pm1a_control; u32 pm1b_control; ACPI_FUNCTION_TRACE(hw_legacy_wake_prep); /* * Set SLP_TYPE and SLP_EN to state S0. * This is unclear from the ACPI Spec, but it is required * by some machines. */ status = acpi_get_sleep_type_data(ACPI_STATE_S0, &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b); if (ACPI_SUCCESS(status)) { sleep_type_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); sleep_enable_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); /* Get current value of PM1A control */ status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &pm1a_control); if (ACPI_SUCCESS(status)) { /* Clear the SLP_EN and SLP_TYP fields */ pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info-> access_bit_mask); pm1b_control = pm1a_control; /* Insert the SLP_TYP bits */ pm1a_control |= (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); pm1b_control |= (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); /* Write the control registers and ignore any errors */ (void)acpi_hw_write_pm1_control(pm1a_control, pm1b_control); } } /* Optionally execute _BFS (Back From Sleep) */ if (flags & ACPI_EXECUTE_BFS) { acpi_hw_execute_sleep_method(METHOD_PATHNAME__BFS, sleep_state); } return_ACPI_STATUS(status); }
acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) { acpi_status status; struct acpi_object_list arg_list; union acpi_object arg; u32 sst_value; ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep); status = acpi_get_sleep_type_data(sleep_state, &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Execute the _PTS method (Prepare To Sleep) */ arg_list.count = 1; arg_list.pointer = &arg; arg.type = ACPI_TYPE_INTEGER; arg.integer.value = sleep_state; status = acpi_evaluate_object(NULL, METHOD_PATHNAME__PTS, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { return_ACPI_STATUS(status); } /* Setup the argument to the _SST method (System STatus) */ switch (sleep_state) { case ACPI_STATE_S0: sst_value = ACPI_SST_WORKING; break; case ACPI_STATE_S1: case ACPI_STATE_S2: case ACPI_STATE_S3: sst_value = ACPI_SST_SLEEPING; break; case ACPI_STATE_S4: sst_value = ACPI_SST_SLEEP_CONTEXT; break; default: sst_value = ACPI_SST_INDICATOR_OFF; /* Default is off */ break; } /* * Set the system indicators to show the desired sleep state. * _SST is an optional method (return no error if not found) */ acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, sst_value); return_ACPI_STATUS(AE_OK); }
acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) { acpi_status status; struct acpi_object_list arg_list; union acpi_object arg; u32 sst_value; ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep); status = acpi_get_sleep_type_data(sleep_state, &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } arg_list.count = 1; arg_list.pointer = &arg; arg.type = ACPI_TYPE_INTEGER; arg.integer.value = sleep_state; status = acpi_evaluate_object(NULL, METHOD_PATHNAME__PTS, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { return_ACPI_STATUS(status); } switch (sleep_state) { case ACPI_STATE_S0: sst_value = ACPI_SST_WORKING; break; case ACPI_STATE_S1: case ACPI_STATE_S2: case ACPI_STATE_S3: sst_value = ACPI_SST_SLEEPING; break; case ACPI_STATE_S4: sst_value = ACPI_SST_SLEEP_CONTEXT; break; default: sst_value = ACPI_SST_INDICATOR_OFF; break; } acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, sst_value); return_ACPI_STATUS(AE_OK); }
static int acpi_poweroff_init(void) { if (!acpi_disabled) { u8 type_a, type_b; acpi_status status; status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); if (ACPI_SUCCESS(status)) pm_power_off = acpi_power_off; } return 0; }
acpi_status acpi_hw_legacy_wake_prep(u8 sleep_state, u8 flags) { acpi_status status; struct acpi_bit_register_info *sleep_type_reg_info; struct acpi_bit_register_info *sleep_enable_reg_info; u32 pm1a_control; u32 pm1b_control; ACPI_FUNCTION_TRACE(hw_legacy_wake_prep); status = acpi_get_sleep_type_data(ACPI_STATE_S0, &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b); if (ACPI_SUCCESS(status)) { sleep_type_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); sleep_enable_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &pm1a_control); if (ACPI_SUCCESS(status)) { pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info-> access_bit_mask); pm1b_control = pm1a_control; pm1a_control |= (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); pm1b_control |= (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); (void)acpi_hw_write_pm1_control(pm1a_control, pm1b_control); } } if (flags & ACPI_EXECUTE_BFS) { acpi_hw_execute_sleep_method(METHOD_PATHNAME__BFS, sleep_state); } return_ACPI_STATUS(status); }
static int acpi_poweroff_init(void) { if (!acpi_disabled) { u8 type_a, type_b; acpi_status status; status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); if (ACPI_SUCCESS(status)) { int error; error = sysdev_class_register(&acpi_sysclass); if (!error) error = sysdev_register(&device_acpi); if (!error) pm_power_off = acpi_power_off; return error; } } return 0; }
acpi_status acpi_hw_extended_wake_prep(u8 sleep_state) { acpi_status status; u8 sleep_type_value; ACPI_FUNCTION_TRACE(hw_extended_wake_prep); status = acpi_get_sleep_type_data(ACPI_STATE_S0, &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b); if (ACPI_SUCCESS(status)) { sleep_type_value = ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) & ACPI_X_SLEEP_TYPE_MASK); (void)acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE), &acpi_gbl_FADT.sleep_control); } return_ACPI_STATUS(AE_OK); }
/******************************************************************************* * * FUNCTION: acpi_leave_sleep_state * * PARAMETERS: sleep_state - Which sleep state we just exited * * RETURN: Status * * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep * Called with interrupts ENABLED. * ******************************************************************************/ acpi_status acpi_leave_sleep_state(u8 sleep_state) { struct acpi_object_list arg_list; union acpi_object arg; acpi_status status; struct acpi_bit_register_info *sleep_type_reg_info; struct acpi_bit_register_info *sleep_enable_reg_info; u32 PM1Acontrol; u32 PM1Bcontrol; ACPI_FUNCTION_TRACE(acpi_leave_sleep_state); /* * Set SLP_TYPE and SLP_EN to state S0. * This is unclear from the ACPI Spec, but it is required * by some machines. */ status = acpi_get_sleep_type_data(ACPI_STATE_S0, &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b); if (ACPI_SUCCESS(status)) { sleep_type_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE_A); sleep_enable_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); /* Get current value of PM1A control */ status = acpi_hw_register_read(ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_CONTROL, &PM1Acontrol); if (ACPI_SUCCESS(status)) { /* Clear SLP_EN and SLP_TYP fields */ PM1Acontrol &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info-> access_bit_mask); PM1Bcontrol = PM1Acontrol; /* Insert SLP_TYP bits */ PM1Acontrol |= (acpi_gbl_sleep_type_a << sleep_type_reg_info-> bit_position); PM1Bcontrol |= (acpi_gbl_sleep_type_b << sleep_type_reg_info-> bit_position); /* Just ignore any errors */ (void)acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1A_CONTROL, PM1Acontrol); (void)acpi_hw_register_write(ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1B_CONTROL, PM1Bcontrol); } } /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */ acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID; /* Setup parameter object */ arg_list.count = 1; arg_list.pointer = &arg; arg.type = ACPI_TYPE_INTEGER; /* Ignore any errors from these methods */ arg.integer.value = ACPI_SST_WAKING; status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); } arg.integer.value = sleep_state; status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS")); } status = acpi_evaluate_object(NULL, METHOD_NAME__WAK, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { ACPI_EXCEPTION((AE_INFO, status, "During Method _WAK")); } /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */ /* * Restore the GPEs: * 1) Disable/Clear all GPEs * 2) Enable all runtime GPEs */ status = acpi_hw_disable_all_gpes(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } acpi_gbl_system_awake_and_running = TRUE; status = acpi_hw_enable_all_runtime_gpes(); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Enable power button */ (void) acpi_set_register(acpi_gbl_fixed_event_info [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1, ACPI_MTX_DO_NOT_LOCK); (void) acpi_set_register(acpi_gbl_fixed_event_info [ACPI_EVENT_POWER_BUTTON].status_register_id, 1, ACPI_MTX_DO_NOT_LOCK); arg.integer.value = ACPI_SST_WORKING; status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { ACPI_EXCEPTION((AE_INFO, status, "During Method _SST")); } return_ACPI_STATUS(status); }
/******************************************************************************* * * FUNCTION: acpi_enter_sleep_state_prep * * PARAMETERS: sleep_state - Which sleep state to enter * * RETURN: Status * * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231) * This function must execute with interrupts enabled. * We break sleeping into 2 stages so that OSPM can handle * various OS-specific tasks between the two steps. * ******************************************************************************/ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state) { acpi_status status; struct acpi_object_list arg_list; union acpi_object arg; ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep); /* * _PSW methods could be run here to enable wake-on keyboard, LAN, etc. */ status = acpi_get_sleep_type_data(sleep_state, &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* Setup parameter object */ arg_list.count = 1; arg_list.pointer = &arg; arg.type = ACPI_TYPE_INTEGER; arg.integer.value = sleep_state; /* Run the _PTS and _GTS methods */ status = acpi_evaluate_object(NULL, METHOD_NAME__PTS, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { return_ACPI_STATUS(status); } status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { return_ACPI_STATUS(status); } /* Setup the argument to _SST */ switch (sleep_state) { case ACPI_STATE_S0: arg.integer.value = ACPI_SST_WORKING; break; case ACPI_STATE_S1: case ACPI_STATE_S2: case ACPI_STATE_S3: arg.integer.value = ACPI_SST_SLEEPING; break; case ACPI_STATE_S4: arg.integer.value = ACPI_SST_SLEEP_CONTEXT; break; default: arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is off */ break; } /* Set the system indicators to show the desired sleep state. */ status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { ACPI_EXCEPTION((AE_INFO, status, "While executing method _SST")); } return_ACPI_STATUS(AE_OK); }
static void acpi_db_do_one_sleep_state(u8 sleep_state) { acpi_status status; u8 sleep_type_a; u8 sleep_type_b; /* Validate parameter */ if (sleep_state > ACPI_S_STATES_MAX) { acpi_os_printf("Sleep state %d out of range (%d max)\n", sleep_state, ACPI_S_STATES_MAX); return; } acpi_os_printf("\n---- Invoking sleep state S%d (%s):\n", sleep_state, acpi_gbl_sleep_state_names[sleep_state]); /* Get the values for the sleep type registers (for display only) */ status = acpi_get_sleep_type_data(sleep_state, &sleep_type_a, &sleep_type_b); if (ACPI_FAILURE(status)) { acpi_os_printf("Could not evaluate [%s] method, %s\n", acpi_gbl_sleep_state_names[sleep_state], acpi_format_exception(status)); return; } acpi_os_printf ("Register values for sleep state S%d: Sleep-A: %.2X, Sleep-B: %.2X\n", sleep_state, sleep_type_a, sleep_type_b); /* Invoke the various sleep/wake interfaces */ acpi_os_printf("**** Sleep: Prepare to sleep (S%d) ****\n", sleep_state); status = acpi_enter_sleep_state_prep(sleep_state); if (ACPI_FAILURE(status)) { goto error_exit; } acpi_os_printf("**** Sleep: Going to sleep (S%d) ****\n", sleep_state); status = acpi_enter_sleep_state(sleep_state); if (ACPI_FAILURE(status)) { goto error_exit; } acpi_os_printf("**** Wake: Prepare to return from sleep (S%d) ****\n", sleep_state); status = acpi_leave_sleep_state_prep(sleep_state); if (ACPI_FAILURE(status)) { goto error_exit; } acpi_os_printf("**** Wake: Return from sleep (S%d) ****\n", sleep_state); status = acpi_leave_sleep_state(sleep_state); if (ACPI_FAILURE(status)) { goto error_exit; } return; error_exit: ACPI_EXCEPTION((AE_INFO, status, "During invocation of sleep state S%d", sleep_state)); }
static int acpi_system_add ( struct acpi_device *device) { int result = 0; acpi_status status = AE_OK; struct acpi_system *system = NULL; u8 i = 0; ACPI_FUNCTION_TRACE("acpi_system_add"); if (!device) return_VALUE(-EINVAL); system = kmalloc(sizeof(struct acpi_system), GFP_KERNEL); if (!system) return_VALUE(-ENOMEM); memset(system, 0, sizeof(struct acpi_system)); system->handle = device->handle; sprintf(acpi_device_name(device), "%s", ACPI_SYSTEM_DEVICE_NAME); sprintf(acpi_device_class(device), "%s", ACPI_SYSTEM_CLASS); acpi_driver_data(device) = system; result = acpi_system_add_fs(device); if (result) goto end; printk(KERN_INFO PREFIX "%s [%s] (supports", acpi_device_name(device), acpi_device_bid(device)); for (i=0; i<ACPI_S_STATE_COUNT; i++) { u8 type_a, type_b; status = acpi_get_sleep_type_data(i, &type_a, &type_b); switch (i) { case ACPI_STATE_S4: if (acpi_gbl_FACS->S4bios_f && 0 != acpi_gbl_FADT->smi_cmd) { printk(" S4bios"); system->states[i] = 1; } /* no break */ default: if (ACPI_SUCCESS(status)) { system->states[i] = 1; printk(" S%d", i); } } } printk(")\n"); #ifdef CONFIG_PM /* Install the soft-off (S5) handler. */ if (system->states[ACPI_STATE_S5]) { pm_power_off = acpi_power_off; register_sysrq_key('o', &sysrq_acpi_poweroff_op); } #endif end: if (result) kfree(system); return_VALUE(result); }
/******************************************************************************* * * FUNCTION: acpi_leave_sleep_state_prep * * PARAMETERS: sleep_state - Which sleep state we are exiting * * RETURN: Status * * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a * sleep. * Called with interrupts DISABLED. * ******************************************************************************/ acpi_status acpi_leave_sleep_state_prep(u8 sleep_state) { struct acpi_object_list arg_list; union acpi_object arg; acpi_status status; struct acpi_bit_register_info *sleep_type_reg_info; struct acpi_bit_register_info *sleep_enable_reg_info; u32 pm1a_control; u32 pm1b_control; ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep); /* * Set SLP_TYPE and SLP_EN to state S0. * This is unclear from the ACPI Spec, but it is required * by some machines. */ status = acpi_get_sleep_type_data(ACPI_STATE_S0, &acpi_gbl_sleep_type_a, &acpi_gbl_sleep_type_b); if (ACPI_SUCCESS(status)) { sleep_type_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE); sleep_enable_reg_info = acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE); /* Get current value of PM1A control */ status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL, &pm1a_control); if (ACPI_SUCCESS(status)) { /* Clear the SLP_EN and SLP_TYP fields */ pm1a_control &= ~(sleep_type_reg_info->access_bit_mask | sleep_enable_reg_info-> access_bit_mask); pm1b_control = pm1a_control; /* Insert the SLP_TYP bits */ pm1a_control |= (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position); pm1b_control |= (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position); /* Write the control registers and ignore any errors */ (void)acpi_hw_write_pm1_control(pm1a_control, pm1b_control); } } if (bfs) { /* Execute the _BFS method */ arg_list.count = 1; arg_list.pointer = &arg; arg.type = ACPI_TYPE_INTEGER; arg.integer.value = sleep_state; status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS")); } } return_ACPI_STATUS(status); }