1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/******************************************************************************
*
* Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface
* $Revision: 22 $
*
*****************************************************************************/
/*
* Copyright (C) 2000, 2001 R. Byron Moore
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "acpi.h"
#include "acnamesp.h"
#include "achware.h"
#define _COMPONENT ACPI_HARDWARE
MODULE_NAME ("hwsleep")
/******************************************************************************
*
* FUNCTION: Acpi_set_firmware_waking_vector
*
* PARAMETERS: Physical_address - Physical address of ACPI real mode
* entry point.
*
* RETURN: AE_OK or AE_ERROR
*
* DESCRIPTION: Access function for d_firmware_waking_vector field in FACS
*
******************************************************************************/
acpi_status
acpi_set_firmware_waking_vector (
ACPI_PHYSICAL_ADDRESS physical_address)
{
FUNCTION_TRACE ("Acpi_set_firmware_waking_vector");
/* Make sure that we have an FACS */
if (!acpi_gbl_FACS) {
return_ACPI_STATUS (AE_NO_ACPI_TABLES);
}
/* Set the vector */
if (acpi_gbl_FACS->vector_width == 32) {
* (u32 *) acpi_gbl_FACS->firmware_waking_vector = (u32) physical_address;
}
else {
*acpi_gbl_FACS->firmware_waking_vector = physical_address;
}
return_ACPI_STATUS (AE_OK);
}
/******************************************************************************
*
* FUNCTION: Acpi_get_firmware_waking_vector
*
* PARAMETERS: *Physical_address - Output buffer where contents of
* the Firmware_waking_vector field of
* the FACS will be stored.
*
* RETURN: Status
*
* DESCRIPTION: Access function for d_firmware_waking_vector field in FACS
*
******************************************************************************/
acpi_status
acpi_get_firmware_waking_vector (
ACPI_PHYSICAL_ADDRESS *physical_address)
{
FUNCTION_TRACE ("Acpi_get_firmware_waking_vector");
if (!physical_address) {
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
/* Make sure that we have an FACS */
if (!acpi_gbl_FACS) {
return_ACPI_STATUS (AE_NO_ACPI_TABLES);
}
/* Get the vector */
if (acpi_gbl_FACS->vector_width == 32) {
*physical_address = * (u32 *) acpi_gbl_FACS->firmware_waking_vector;
}
else {
*physical_address = *acpi_gbl_FACS->firmware_waking_vector;
}
return_ACPI_STATUS (AE_OK);
}
/******************************************************************************
*
* FUNCTION: Acpi_enter_sleep_state
*
* PARAMETERS: Sleep_state - Which sleep state to enter
*
* RETURN: Status
*
* DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
*
******************************************************************************/
acpi_status
acpi_enter_sleep_state (
u8 sleep_state)
{
acpi_status status;
acpi_object_list arg_list;
acpi_object arg;
u8 type_a;
u8 type_b;
u16 PM1Acontrol;
u16 PM1Bcontrol;
FUNCTION_TRACE ("Acpi_enter_sleep_state");
/*
* _PSW methods could be run here to enable wake-on keyboard, LAN, etc.
*/
status = acpi_hw_obtain_sleep_type_register_data (sleep_state, &type_a, &type_b);
if (!ACPI_SUCCESS (status)) {
return status;
}
/* run the _PTS and _GTS methods */
MEMSET(&arg_list, 0, sizeof(arg_list));
arg_list.count = 1;
arg_list.pointer = &arg;
MEMSET(&arg, 0, sizeof(arg));
arg.type = ACPI_TYPE_INTEGER;
arg.integer.value = sleep_state;
acpi_evaluate_object (NULL, "\\_PTS", &arg_list, NULL);
acpi_evaluate_object (NULL, "\\_GTS", &arg_list, NULL);
/* clear wake status */
acpi_hw_register_bit_access (ACPI_WRITE, ACPI_MTX_LOCK, WAK_STS, 1);
disable ();
acpi_hw_disable_non_wakeup_gpes();
PM1Acontrol = (u16) acpi_hw_register_read (ACPI_MTX_LOCK, PM1_CONTROL);
ACPI_DEBUG_PRINT ((ACPI_DB_OK, "Entering S%d\n", sleep_state));
/* mask off SLP_EN and SLP_TYP fields */
PM1Acontrol &= ~(SLP_TYPE_X_MASK | SLP_EN_MASK);
PM1Bcontrol = PM1Acontrol;
/* mask in SLP_TYP */
PM1Acontrol |= (type_a << acpi_hw_get_bit_shift (SLP_TYPE_X_MASK));
PM1Bcontrol |= (type_b << acpi_hw_get_bit_shift (SLP_TYPE_X_MASK));
/* write #1: fill in SLP_TYP data */
acpi_hw_register_write (ACPI_MTX_LOCK, PM1A_CONTROL, PM1Acontrol);
acpi_hw_register_write (ACPI_MTX_LOCK, PM1B_CONTROL, PM1Bcontrol);
/* mask in SLP_EN */
PM1Acontrol |= (1 << acpi_hw_get_bit_shift (SLP_EN_MASK));
PM1Bcontrol |= (1 << acpi_hw_get_bit_shift (SLP_EN_MASK));
/* flush caches */
wbinvd();
/* write #2: SLP_TYP + SLP_EN */
acpi_hw_register_write (ACPI_MTX_LOCK, PM1A_CONTROL, PM1Acontrol);
acpi_hw_register_write (ACPI_MTX_LOCK, PM1B_CONTROL, PM1Bcontrol);
/*
* Wait a second, then try again. This is to get S4/5 to work on all machines.
*/
if (sleep_state > ACPI_STATE_S3) {
acpi_os_stall(1000000);
acpi_hw_register_write (ACPI_MTX_LOCK, PM1_CONTROL,
(1 << acpi_hw_get_bit_shift (SLP_EN_MASK)));
}
/* wait until we enter sleep state */
do {
acpi_os_stall(10000);
}
while (!acpi_hw_register_bit_access (ACPI_READ, ACPI_MTX_LOCK, WAK_STS));
acpi_hw_enable_non_wakeup_gpes();
enable ();
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
*
******************************************************************************/
acpi_status
acpi_leave_sleep_state (
u8 sleep_state)
{
acpi_object_list arg_list;
acpi_object arg;
FUNCTION_TRACE ("Acpi_leave_sleep_state");
MEMSET (&arg_list, 0, sizeof(arg_list));
arg_list.count = 1;
arg_list.pointer = &arg;
MEMSET (&arg, 0, sizeof(arg));
arg.type = ACPI_TYPE_INTEGER;
arg.integer.value = sleep_state;
acpi_evaluate_object (NULL, "\\_BFS", &arg_list, NULL);
acpi_evaluate_object (NULL, "\\_WAK", &arg_list, NULL);
/* _WAK returns stuff - do we want to look at it? */
acpi_hw_enable_non_wakeup_gpes();
return_ACPI_STATUS (AE_OK);
}
|