1 /****************************************************************************** 2 * 3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2013, 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 68 ACPI_STATUS 69 AcpiEnable ( 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 /* If the Hardware Reduced flag is set, machine is always in acpi mode */ 86 87 if (AcpiGbl_ReducedHardware) 88 { 89 return_ACPI_STATUS (AE_OK); 90 } 91 92 /* Check current mode */ 93 94 if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI) 95 { 96 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n")); 97 } 98 else 99 { 100 /* Transition to ACPI mode */ 101 102 Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI); 103 if (ACPI_FAILURE (Status)) 104 { 105 ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode")); 106 return_ACPI_STATUS (Status); 107 } 108 109 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 110 "Transition to ACPI mode successful\n")); 111 } 112 113 return_ACPI_STATUS (Status); 114 } 115 116 ACPI_EXPORT_SYMBOL (AcpiEnable) 117 118 119 /******************************************************************************* 120 * 121 * FUNCTION: AcpiDisable 122 * 123 * PARAMETERS: None 124 * 125 * RETURN: Status 126 * 127 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode. 128 * 129 ******************************************************************************/ 130 131 ACPI_STATUS 132 AcpiDisable ( 133 void) 134 { 135 ACPI_STATUS Status = AE_OK; 136 137 138 ACPI_FUNCTION_TRACE (AcpiDisable); 139 140 141 /* If the Hardware Reduced flag is set, machine is always in acpi mode */ 142 143 if (AcpiGbl_ReducedHardware) 144 { 145 return_ACPI_STATUS (AE_OK); 146 } 147 148 if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY) 149 { 150 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 151 "System is already in legacy (non-ACPI) mode\n")); 152 } 153 else 154 { 155 /* Transition to LEGACY mode */ 156 157 Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY); 158 159 if (ACPI_FAILURE (Status)) 160 { 161 ACPI_ERROR ((AE_INFO, 162 "Could not exit ACPI mode to legacy mode")); 163 return_ACPI_STATUS (Status); 164 } 165 166 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n")); 167 } 168 169 return_ACPI_STATUS (Status); 170 } 171 172 ACPI_EXPORT_SYMBOL (AcpiDisable) 173 174 175 /******************************************************************************* 176 * 177 * FUNCTION: AcpiEnableEvent 178 * 179 * PARAMETERS: Event - The fixed eventto be enabled 180 * Flags - Reserved 181 * 182 * RETURN: Status 183 * 184 * DESCRIPTION: Enable an ACPI event (fixed) 185 * 186 ******************************************************************************/ 187 188 ACPI_STATUS 189 AcpiEnableEvent ( 190 UINT32 Event, 191 UINT32 Flags) 192 { 193 ACPI_STATUS Status = AE_OK; 194 UINT32 Value; 195 196 197 ACPI_FUNCTION_TRACE (AcpiEnableEvent); 198 199 200 /* Decode the Fixed Event */ 201 202 if (Event > ACPI_EVENT_MAX) 203 { 204 return_ACPI_STATUS (AE_BAD_PARAMETER); 205 } 206 207 /* 208 * Enable the requested fixed event (by writing a one to the enable 209 * register bit) 210 */ 211 Status = AcpiWriteBitRegister ( 212 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 213 ACPI_ENABLE_EVENT); 214 if (ACPI_FAILURE (Status)) 215 { 216 return_ACPI_STATUS (Status); 217 } 218 219 /* Make sure that the hardware responded */ 220 221 Status = AcpiReadBitRegister ( 222 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value); 223 if (ACPI_FAILURE (Status)) 224 { 225 return_ACPI_STATUS (Status); 226 } 227 228 if (Value != 1) 229 { 230 ACPI_ERROR ((AE_INFO, 231 "Could not enable %s event", AcpiUtGetEventName (Event))); 232 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 233 } 234 235 return_ACPI_STATUS (Status); 236 } 237 238 ACPI_EXPORT_SYMBOL (AcpiEnableEvent) 239 240 241 /******************************************************************************* 242 * 243 * FUNCTION: AcpiDisableEvent 244 * 245 * PARAMETERS: Event - The fixed event to be disabled 246 * Flags - Reserved 247 * 248 * RETURN: Status 249 * 250 * DESCRIPTION: Disable an ACPI event (fixed) 251 * 252 ******************************************************************************/ 253 254 ACPI_STATUS 255 AcpiDisableEvent ( 256 UINT32 Event, 257 UINT32 Flags) 258 { 259 ACPI_STATUS Status = AE_OK; 260 UINT32 Value; 261 262 263 ACPI_FUNCTION_TRACE (AcpiDisableEvent); 264 265 266 /* Decode the Fixed Event */ 267 268 if (Event > ACPI_EVENT_MAX) 269 { 270 return_ACPI_STATUS (AE_BAD_PARAMETER); 271 } 272 273 /* 274 * Disable the requested fixed event (by writing a zero to the enable 275 * register bit) 276 */ 277 Status = AcpiWriteBitRegister ( 278 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 279 ACPI_DISABLE_EVENT); 280 if (ACPI_FAILURE (Status)) 281 { 282 return_ACPI_STATUS (Status); 283 } 284 285 Status = AcpiReadBitRegister ( 286 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value); 287 if (ACPI_FAILURE (Status)) 288 { 289 return_ACPI_STATUS (Status); 290 } 291 292 if (Value != 0) 293 { 294 ACPI_ERROR ((AE_INFO, 295 "Could not disable %s events", AcpiUtGetEventName (Event))); 296 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 297 } 298 299 return_ACPI_STATUS (Status); 300 } 301 302 ACPI_EXPORT_SYMBOL (AcpiDisableEvent) 303 304 305 /******************************************************************************* 306 * 307 * FUNCTION: AcpiClearEvent 308 * 309 * PARAMETERS: Event - The fixed event to be cleared 310 * 311 * RETURN: Status 312 * 313 * DESCRIPTION: Clear an ACPI event (fixed) 314 * 315 ******************************************************************************/ 316 317 ACPI_STATUS 318 AcpiClearEvent ( 319 UINT32 Event) 320 { 321 ACPI_STATUS Status = AE_OK; 322 323 324 ACPI_FUNCTION_TRACE (AcpiClearEvent); 325 326 327 /* Decode the Fixed Event */ 328 329 if (Event > ACPI_EVENT_MAX) 330 { 331 return_ACPI_STATUS (AE_BAD_PARAMETER); 332 } 333 334 /* 335 * Clear the requested fixed event (By writing a one to the status 336 * register bit) 337 */ 338 Status = AcpiWriteBitRegister ( 339 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, 340 ACPI_CLEAR_STATUS); 341 342 return_ACPI_STATUS (Status); 343 } 344 345 ACPI_EXPORT_SYMBOL (AcpiClearEvent) 346 347 348 /******************************************************************************* 349 * 350 * FUNCTION: AcpiGetEventStatus 351 * 352 * PARAMETERS: Event - The fixed event 353 * EventStatus - Where the current status of the event will 354 * be returned 355 * 356 * RETURN: Status 357 * 358 * DESCRIPTION: Obtains and returns the current status of the event 359 * 360 ******************************************************************************/ 361 362 ACPI_STATUS 363 AcpiGetEventStatus ( 364 UINT32 Event, 365 ACPI_EVENT_STATUS *EventStatus) 366 { 367 ACPI_STATUS Status = AE_OK; 368 369 370 ACPI_FUNCTION_TRACE (AcpiGetEventStatus); 371 372 373 if (!EventStatus) 374 { 375 return_ACPI_STATUS (AE_BAD_PARAMETER); 376 } 377 378 /* Decode the Fixed Event */ 379 380 if (Event > ACPI_EVENT_MAX) 381 { 382 return_ACPI_STATUS (AE_BAD_PARAMETER); 383 } 384 385 /* Get the status of the requested fixed event */ 386 387 Status = AcpiReadBitRegister ( 388 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, EventStatus); 389 390 return_ACPI_STATUS (Status); 391 } 392 393 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus) 394 395 #endif /* !ACPI_REDUCED_HARDWARE */ 396