evxfevnt.c revision 231844
1/****************************************************************************** 2 * 3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable 4 * 5 *****************************************************************************/ 6 7/* 8 * Copyright (C) 2000 - 2012, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 45#define __EVXFEVNT_C__ 46 47#include <contrib/dev/acpica/include/acpi.h> 48#include <contrib/dev/acpica/include/accommon.h> 49#include <contrib/dev/acpica/include/actables.h> 50 51#define _COMPONENT ACPI_EVENTS 52 ACPI_MODULE_NAME ("evxfevnt") 53 54 55#if (!ACPI_REDUCED_HARDWARE) /* Entire module */ 56/******************************************************************************* 57 * 58 * FUNCTION: AcpiEnable 59 * 60 * PARAMETERS: None 61 * 62 * RETURN: Status 63 * 64 * DESCRIPTION: Transfers the system into ACPI mode. 65 * 66 ******************************************************************************/ 67 68ACPI_STATUS 69AcpiEnable ( 70 void) 71{ 72 ACPI_STATUS Status = AE_OK; 73 74 75 ACPI_FUNCTION_TRACE (AcpiEnable); 76 77 78 /* ACPI tables must be present */ 79 80 if (!AcpiTbTablesLoaded ()) 81 { 82 return_ACPI_STATUS (AE_NO_ACPI_TABLES); 83 } 84 85 /* Check current mode */ 86 87 if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI) 88 { 89 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n")); 90 } 91 else 92 { 93 /* Transition to ACPI mode */ 94 95 Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI); 96 if (ACPI_FAILURE (Status)) 97 { 98 ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode")); 99 return_ACPI_STATUS (Status); 100 } 101 102 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 103 "Transition to ACPI mode successful\n")); 104 } 105 106 return_ACPI_STATUS (Status); 107} 108 109ACPI_EXPORT_SYMBOL (AcpiEnable) 110 111 112/******************************************************************************* 113 * 114 * FUNCTION: AcpiDisable 115 * 116 * PARAMETERS: None 117 * 118 * RETURN: Status 119 * 120 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode. 121 * 122 ******************************************************************************/ 123 124ACPI_STATUS 125AcpiDisable ( 126 void) 127{ 128 ACPI_STATUS Status = AE_OK; 129 130 131 ACPI_FUNCTION_TRACE (AcpiDisable); 132 133 134 if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY) 135 { 136 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 137 "System is already in legacy (non-ACPI) mode\n")); 138 } 139 else 140 { 141 /* Transition to LEGACY mode */ 142 143 Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY); 144 145 if (ACPI_FAILURE (Status)) 146 { 147 ACPI_ERROR ((AE_INFO, 148 "Could not exit ACPI mode to legacy mode")); 149 return_ACPI_STATUS (Status); 150 } 151 152 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n")); 153 } 154 155 return_ACPI_STATUS (Status); 156} 157 158ACPI_EXPORT_SYMBOL (AcpiDisable) 159 160 161/******************************************************************************* 162 * 163 * FUNCTION: AcpiEnableEvent 164 * 165 * PARAMETERS: Event - The fixed eventto be enabled 166 * Flags - Reserved 167 * 168 * RETURN: Status 169 * 170 * DESCRIPTION: Enable an ACPI event (fixed) 171 * 172 ******************************************************************************/ 173 174ACPI_STATUS 175AcpiEnableEvent ( 176 UINT32 Event, 177 UINT32 Flags) 178{ 179 ACPI_STATUS Status = AE_OK; 180 UINT32 Value; 181 182 183 ACPI_FUNCTION_TRACE (AcpiEnableEvent); 184 185 186 /* Decode the Fixed Event */ 187 188 if (Event > ACPI_EVENT_MAX) 189 { 190 return_ACPI_STATUS (AE_BAD_PARAMETER); 191 } 192 193 /* 194 * Enable the requested fixed event (by writing a one to the enable 195 * register bit) 196 */ 197 Status = AcpiWriteBitRegister ( 198 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 199 ACPI_ENABLE_EVENT); 200 if (ACPI_FAILURE (Status)) 201 { 202 return_ACPI_STATUS (Status); 203 } 204 205 /* Make sure that the hardware responded */ 206 207 Status = AcpiReadBitRegister ( 208 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value); 209 if (ACPI_FAILURE (Status)) 210 { 211 return_ACPI_STATUS (Status); 212 } 213 214 if (Value != 1) 215 { 216 ACPI_ERROR ((AE_INFO, 217 "Could not enable %s event", AcpiUtGetEventName (Event))); 218 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 219 } 220 221 return_ACPI_STATUS (Status); 222} 223 224ACPI_EXPORT_SYMBOL (AcpiEnableEvent) 225 226 227/******************************************************************************* 228 * 229 * FUNCTION: AcpiDisableEvent 230 * 231 * PARAMETERS: Event - The fixed event to be disabled 232 * Flags - Reserved 233 * 234 * RETURN: Status 235 * 236 * DESCRIPTION: Disable an ACPI event (fixed) 237 * 238 ******************************************************************************/ 239 240ACPI_STATUS 241AcpiDisableEvent ( 242 UINT32 Event, 243 UINT32 Flags) 244{ 245 ACPI_STATUS Status = AE_OK; 246 UINT32 Value; 247 248 249 ACPI_FUNCTION_TRACE (AcpiDisableEvent); 250 251 252 /* Decode the Fixed Event */ 253 254 if (Event > ACPI_EVENT_MAX) 255 { 256 return_ACPI_STATUS (AE_BAD_PARAMETER); 257 } 258 259 /* 260 * Disable the requested fixed event (by writing a zero to the enable 261 * register bit) 262 */ 263 Status = AcpiWriteBitRegister ( 264 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 265 ACPI_DISABLE_EVENT); 266 if (ACPI_FAILURE (Status)) 267 { 268 return_ACPI_STATUS (Status); 269 } 270 271 Status = AcpiReadBitRegister ( 272 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value); 273 if (ACPI_FAILURE (Status)) 274 { 275 return_ACPI_STATUS (Status); 276 } 277 278 if (Value != 0) 279 { 280 ACPI_ERROR ((AE_INFO, 281 "Could not disable %s events", AcpiUtGetEventName (Event))); 282 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 283 } 284 285 return_ACPI_STATUS (Status); 286} 287 288ACPI_EXPORT_SYMBOL (AcpiDisableEvent) 289 290 291/******************************************************************************* 292 * 293 * FUNCTION: AcpiClearEvent 294 * 295 * PARAMETERS: Event - The fixed event to be cleared 296 * 297 * RETURN: Status 298 * 299 * DESCRIPTION: Clear an ACPI event (fixed) 300 * 301 ******************************************************************************/ 302 303ACPI_STATUS 304AcpiClearEvent ( 305 UINT32 Event) 306{ 307 ACPI_STATUS Status = AE_OK; 308 309 310 ACPI_FUNCTION_TRACE (AcpiClearEvent); 311 312 313 /* Decode the Fixed Event */ 314 315 if (Event > ACPI_EVENT_MAX) 316 { 317 return_ACPI_STATUS (AE_BAD_PARAMETER); 318 } 319 320 /* 321 * Clear the requested fixed event (By writing a one to the status 322 * register bit) 323 */ 324 Status = AcpiWriteBitRegister ( 325 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, 326 ACPI_CLEAR_STATUS); 327 328 return_ACPI_STATUS (Status); 329} 330 331ACPI_EXPORT_SYMBOL (AcpiClearEvent) 332 333 334/******************************************************************************* 335 * 336 * FUNCTION: AcpiGetEventStatus 337 * 338 * PARAMETERS: Event - The fixed event 339 * EventStatus - Where the current status of the event will 340 * be returned 341 * 342 * RETURN: Status 343 * 344 * DESCRIPTION: Obtains and returns the current status of the event 345 * 346 ******************************************************************************/ 347 348ACPI_STATUS 349AcpiGetEventStatus ( 350 UINT32 Event, 351 ACPI_EVENT_STATUS *EventStatus) 352{ 353 ACPI_STATUS Status = AE_OK; 354 355 356 ACPI_FUNCTION_TRACE (AcpiGetEventStatus); 357 358 359 if (!EventStatus) 360 { 361 return_ACPI_STATUS (AE_BAD_PARAMETER); 362 } 363 364 /* Decode the Fixed Event */ 365 366 if (Event > ACPI_EVENT_MAX) 367 { 368 return_ACPI_STATUS (AE_BAD_PARAMETER); 369 } 370 371 /* Get the status of the requested fixed event */ 372 373 Status = AcpiReadBitRegister ( 374 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, EventStatus); 375 376 return_ACPI_STATUS (Status); 377} 378 379ACPI_EXPORT_SYMBOL (AcpiGetEventStatus) 380 381#endif /* !ACPI_REDUCED_HARDWARE */ 382