1 /****************************************************************************** 2 * 3 * Module Name: utxface - External interfaces, miscellaneous utility functions 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 __UTXFACE_C__ 46 47 #include <contrib/dev/acpica/include/acpi.h> 48 #include <contrib/dev/acpica/include/accommon.h> 49 #include <contrib/dev/acpica/include/acdebug.h> 50 51 #define _COMPONENT ACPI_UTILITIES 52 ACPI_MODULE_NAME ("utxface") 53 54 55 /******************************************************************************* 56 * 57 * FUNCTION: AcpiTerminate 58 * 59 * PARAMETERS: None 60 * 61 * RETURN: Status 62 * 63 * DESCRIPTION: Shutdown the ACPICA subsystem and release all resources. 64 * 65 ******************************************************************************/ 66 67 ACPI_STATUS 68 AcpiTerminate ( 69 void) 70 { 71 ACPI_STATUS Status; 72 73 74 ACPI_FUNCTION_TRACE (AcpiTerminate); 75 76 77 /* Just exit if subsystem is already shutdown */ 78 79 if (AcpiGbl_Shutdown) 80 { 81 ACPI_ERROR ((AE_INFO, "ACPI Subsystem is already terminated")); 82 return_ACPI_STATUS (AE_OK); 83 } 84 85 /* Subsystem appears active, go ahead and shut it down */ 86 87 AcpiGbl_Shutdown = TRUE; 88 AcpiGbl_StartupFlags = 0; 89 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n")); 90 91 /* Terminate the AML Debugger if present */ 92 93 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = TRUE); 94 95 /* Shutdown and free all resources */ 96 97 AcpiUtSubsystemShutdown (); 98 99 /* Free the mutex objects */ 100 101 AcpiUtMutexTerminate (); 102 103 104 #ifdef ACPI_DEBUGGER 105 106 /* Shut down the debugger */ 107 108 AcpiDbTerminate (); 109 #endif 110 111 /* Now we can shutdown the OS-dependent layer */ 112 113 Status = AcpiOsTerminate (); 114 return_ACPI_STATUS (Status); 115 } 116 117 ACPI_EXPORT_SYMBOL (AcpiTerminate) 118 119 120 #ifndef ACPI_ASL_COMPILER 121 /******************************************************************************* 122 * 123 * FUNCTION: AcpiSubsystemStatus 124 * 125 * PARAMETERS: None 126 * 127 * RETURN: Status of the ACPI subsystem 128 * 129 * DESCRIPTION: Other drivers that use the ACPI subsystem should call this 130 * before making any other calls, to ensure the subsystem 131 * initialized successfully. 132 * 133 ******************************************************************************/ 134 135 ACPI_STATUS 136 AcpiSubsystemStatus ( 137 void) 138 { 139 140 if (AcpiGbl_StartupFlags & ACPI_INITIALIZED_OK) 141 { 142 return (AE_OK); 143 } 144 else 145 { 146 return (AE_ERROR); 147 } 148 } 149 150 ACPI_EXPORT_SYMBOL (AcpiSubsystemStatus) 151 152 153 /******************************************************************************* 154 * 155 * FUNCTION: AcpiGetSystemInfo 156 * 157 * PARAMETERS: OutBuffer - A buffer to receive the resources for the 158 * device 159 * 160 * RETURN: Status - the status of the call 161 * 162 * DESCRIPTION: This function is called to get information about the current 163 * state of the ACPI subsystem. It will return system information 164 * in the OutBuffer. 165 * 166 * If the function fails an appropriate status will be returned 167 * and the value of OutBuffer is undefined. 168 * 169 ******************************************************************************/ 170 171 ACPI_STATUS 172 AcpiGetSystemInfo ( 173 ACPI_BUFFER *OutBuffer) 174 { 175 ACPI_SYSTEM_INFO *InfoPtr; 176 ACPI_STATUS Status; 177 178 179 ACPI_FUNCTION_TRACE (AcpiGetSystemInfo); 180 181 182 /* Parameter validation */ 183 184 Status = AcpiUtValidateBuffer (OutBuffer); 185 if (ACPI_FAILURE (Status)) 186 { 187 return_ACPI_STATUS (Status); 188 } 189 190 /* Validate/Allocate/Clear caller buffer */ 191 192 Status = AcpiUtInitializeBuffer (OutBuffer, sizeof (ACPI_SYSTEM_INFO)); 193 if (ACPI_FAILURE (Status)) 194 { 195 return_ACPI_STATUS (Status); 196 } 197 198 /* 199 * Populate the return buffer 200 */ 201 InfoPtr = (ACPI_SYSTEM_INFO *) OutBuffer->Pointer; 202 203 InfoPtr->AcpiCaVersion = ACPI_CA_VERSION; 204 205 /* System flags (ACPI capabilities) */ 206 207 InfoPtr->Flags = ACPI_SYS_MODE_ACPI; 208 209 /* Timer resolution - 24 or 32 bits */ 210 211 if (AcpiGbl_FADT.Flags & ACPI_FADT_32BIT_TIMER) 212 { 213 InfoPtr->TimerResolution = 24; 214 } 215 else 216 { 217 InfoPtr->TimerResolution = 32; 218 } 219 220 /* Clear the reserved fields */ 221 222 InfoPtr->Reserved1 = 0; 223 InfoPtr->Reserved2 = 0; 224 225 /* Current debug levels */ 226 227 InfoPtr->DebugLayer = AcpiDbgLayer; 228 InfoPtr->DebugLevel = AcpiDbgLevel; 229 230 return_ACPI_STATUS (AE_OK); 231 } 232 233 ACPI_EXPORT_SYMBOL (AcpiGetSystemInfo) 234 235 236 /******************************************************************************* 237 * 238 * FUNCTION: AcpiGetStatistics 239 * 240 * PARAMETERS: Stats - Where the statistics are returned 241 * 242 * RETURN: Status - the status of the call 243 * 244 * DESCRIPTION: Get the contents of the various system counters 245 * 246 ******************************************************************************/ 247 248 ACPI_STATUS 249 AcpiGetStatistics ( 250 ACPI_STATISTICS *Stats) 251 { 252 ACPI_FUNCTION_TRACE (AcpiGetStatistics); 253 254 255 /* Parameter validation */ 256 257 if (!Stats) 258 { 259 return_ACPI_STATUS (AE_BAD_PARAMETER); 260 } 261 262 /* Various interrupt-based event counters */ 263 264 Stats->SciCount = AcpiSciCount; 265 Stats->GpeCount = AcpiGpeCount; 266 267 ACPI_MEMCPY (Stats->FixedEventCount, AcpiFixedEventCount, 268 sizeof (AcpiFixedEventCount)); 269 270 271 /* Other counters */ 272 273 Stats->MethodCount = AcpiMethodCount; 274 275 return_ACPI_STATUS (AE_OK); 276 } 277 278 ACPI_EXPORT_SYMBOL (AcpiGetStatistics) 279 280 281 /***************************************************************************** 282 * 283 * FUNCTION: AcpiInstallInitializationHandler 284 * 285 * PARAMETERS: Handler - Callback procedure 286 * Function - Not (currently) used, see below 287 * 288 * RETURN: Status 289 * 290 * DESCRIPTION: Install an initialization handler 291 * 292 * TBD: When a second function is added, must save the Function also. 293 * 294 ****************************************************************************/ 295 296 ACPI_STATUS 297 AcpiInstallInitializationHandler ( 298 ACPI_INIT_HANDLER Handler, 299 UINT32 Function) 300 { 301 302 if (!Handler) 303 { 304 return (AE_BAD_PARAMETER); 305 } 306 307 if (AcpiGbl_InitHandler) 308 { 309 return (AE_ALREADY_EXISTS); 310 } 311 312 AcpiGbl_InitHandler = Handler; 313 return (AE_OK); 314 } 315 316 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler) 317 318 319 /***************************************************************************** 320 * 321 * FUNCTION: AcpiPurgeCachedObjects 322 * 323 * PARAMETERS: None 324 * 325 * RETURN: Status 326 * 327 * DESCRIPTION: Empty all caches (delete the cached objects) 328 * 329 ****************************************************************************/ 330 331 ACPI_STATUS 332 AcpiPurgeCachedObjects ( 333 void) 334 { 335 ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects); 336 337 338 (void) AcpiOsPurgeCache (AcpiGbl_StateCache); 339 (void) AcpiOsPurgeCache (AcpiGbl_OperandCache); 340 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache); 341 (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache); 342 343 return_ACPI_STATUS (AE_OK); 344 } 345 346 ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects) 347 348 349 /***************************************************************************** 350 * 351 * FUNCTION: AcpiInstallInterface 352 * 353 * PARAMETERS: InterfaceName - The interface to install 354 * 355 * RETURN: Status 356 * 357 * DESCRIPTION: Install an _OSI interface to the global list 358 * 359 ****************************************************************************/ 360 361 ACPI_STATUS 362 AcpiInstallInterface ( 363 ACPI_STRING InterfaceName) 364 { 365 ACPI_STATUS Status; 366 ACPI_INTERFACE_INFO *InterfaceInfo; 367 368 369 /* Parameter validation */ 370 371 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0)) 372 { 373 return (AE_BAD_PARAMETER); 374 } 375 376 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER); 377 378 /* Check if the interface name is already in the global list */ 379 380 InterfaceInfo = AcpiUtGetInterface (InterfaceName); 381 if (InterfaceInfo) 382 { 383 /* 384 * The interface already exists in the list. This is OK if the 385 * interface has been marked invalid -- just clear the bit. 386 */ 387 if (InterfaceInfo->Flags & ACPI_OSI_INVALID) 388 { 389 InterfaceInfo->Flags &= ~ACPI_OSI_INVALID; 390 Status = AE_OK; 391 } 392 else 393 { 394 Status = AE_ALREADY_EXISTS; 395 } 396 } 397 else 398 { 399 /* New interface name, install into the global list */ 400 401 Status = AcpiUtInstallInterface (InterfaceName); 402 } 403 404 AcpiOsReleaseMutex (AcpiGbl_OsiMutex); 405 return (Status); 406 } 407 408 ACPI_EXPORT_SYMBOL (AcpiInstallInterface) 409 410 411 /***************************************************************************** 412 * 413 * FUNCTION: AcpiRemoveInterface 414 * 415 * PARAMETERS: InterfaceName - The interface to remove 416 * 417 * RETURN: Status 418 * 419 * DESCRIPTION: Remove an _OSI interface from the global list 420 * 421 ****************************************************************************/ 422 423 ACPI_STATUS 424 AcpiRemoveInterface ( 425 ACPI_STRING InterfaceName) 426 { 427 ACPI_STATUS Status; 428 429 430 /* Parameter validation */ 431 432 if (!InterfaceName || (ACPI_STRLEN (InterfaceName) == 0)) 433 { 434 return (AE_BAD_PARAMETER); 435 } 436 437 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER); 438 439 Status = AcpiUtRemoveInterface (InterfaceName); 440 441 AcpiOsReleaseMutex (AcpiGbl_OsiMutex); 442 return (Status); 443 } 444 445 ACPI_EXPORT_SYMBOL (AcpiRemoveInterface) 446 447 448 /***************************************************************************** 449 * 450 * FUNCTION: AcpiInstallInterfaceHandler 451 * 452 * PARAMETERS: Handler - The _OSI interface handler to install 453 * NULL means "remove existing handler" 454 * 455 * RETURN: Status 456 * 457 * DESCRIPTION: Install a handler for the predefined _OSI ACPI method. 458 * invoked during execution of the internal implementation of 459 * _OSI. A NULL handler simply removes any existing handler. 460 * 461 ****************************************************************************/ 462 463 ACPI_STATUS 464 AcpiInstallInterfaceHandler ( 465 ACPI_INTERFACE_HANDLER Handler) 466 { 467 ACPI_STATUS Status = AE_OK; 468 469 470 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER); 471 472 if (Handler && AcpiGbl_InterfaceHandler) 473 { 474 Status = AE_ALREADY_EXISTS; 475 } 476 else 477 { 478 AcpiGbl_InterfaceHandler = Handler; 479 } 480 481 AcpiOsReleaseMutex (AcpiGbl_OsiMutex); 482 return (Status); 483 } 484 485 ACPI_EXPORT_SYMBOL (AcpiInstallInterfaceHandler) 486 487 488 /***************************************************************************** 489 * 490 * FUNCTION: AcpiCheckAddressRange 491 * 492 * PARAMETERS: SpaceId - Address space ID 493 * Address - Start address 494 * Length - Length 495 * Warn - TRUE if warning on overlap desired 496 * 497 * RETURN: Count of the number of conflicts detected. 498 * 499 * DESCRIPTION: Check if the input address range overlaps any of the 500 * ASL operation region address ranges. 501 * 502 ****************************************************************************/ 503 504 UINT32 505 AcpiCheckAddressRange ( 506 ACPI_ADR_SPACE_TYPE SpaceId, 507 ACPI_PHYSICAL_ADDRESS Address, 508 ACPI_SIZE Length, 509 BOOLEAN Warn) 510 { 511 UINT32 Overlaps; 512 ACPI_STATUS Status; 513 514 515 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 516 if (ACPI_FAILURE (Status)) 517 { 518 return (0); 519 } 520 521 Overlaps = AcpiUtCheckAddressRange (SpaceId, Address, 522 (UINT32) Length, Warn); 523 524 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 525 return (Overlaps); 526 } 527 528 ACPI_EXPORT_SYMBOL (AcpiCheckAddressRange) 529 530 #endif /* !ACPI_ASL_COMPILER */ 531 532 533 /******************************************************************************* 534 * 535 * FUNCTION: AcpiDecodePldBuffer 536 * 537 * PARAMETERS: InBuffer - Buffer returned by _PLD method 538 * Length - Length of the InBuffer 539 * ReturnBuffer - Where the decode buffer is returned 540 * 541 * RETURN: Status and the decoded _PLD buffer. User must deallocate 542 * the buffer via ACPI_FREE. 543 * 544 * DESCRIPTION: Decode the bit-packed buffer returned by the _PLD method into 545 * a local struct that is much more useful to an ACPI driver. 546 * 547 ******************************************************************************/ 548 549 ACPI_STATUS 550 AcpiDecodePldBuffer ( 551 UINT8 *InBuffer, 552 ACPI_SIZE Length, 553 ACPI_PLD_INFO **ReturnBuffer) 554 { 555 ACPI_PLD_INFO *PldInfo; 556 UINT32 *Buffer = ACPI_CAST_PTR (UINT32, InBuffer); 557 UINT32 Dword; 558 559 560 /* Parameter validation */ 561 562 if (!InBuffer || !ReturnBuffer || (Length < 16)) 563 { 564 return (AE_BAD_PARAMETER); 565 } 566 567 PldInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PLD_INFO)); 568 if (!PldInfo) 569 { 570 return (AE_NO_MEMORY); 571 } 572 573 /* First 32-bit DWord */ 574 575 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[0]); 576 PldInfo->Revision = ACPI_PLD_GET_REVISION (&Dword); 577 PldInfo->IgnoreColor = ACPI_PLD_GET_IGNORE_COLOR (&Dword); 578 PldInfo->Color = ACPI_PLD_GET_COLOR (&Dword); 579 580 /* Second 32-bit DWord */ 581 582 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[1]); 583 PldInfo->Width = ACPI_PLD_GET_WIDTH (&Dword); 584 PldInfo->Height = ACPI_PLD_GET_HEIGHT(&Dword); 585 586 /* Third 32-bit DWord */ 587 588 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[2]); 589 PldInfo->UserVisible = ACPI_PLD_GET_USER_VISIBLE (&Dword); 590 PldInfo->Dock = ACPI_PLD_GET_DOCK (&Dword); 591 PldInfo->Lid = ACPI_PLD_GET_LID (&Dword); 592 PldInfo->Panel = ACPI_PLD_GET_PANEL (&Dword); 593 PldInfo->VerticalPosition = ACPI_PLD_GET_VERTICAL (&Dword); 594 PldInfo->HorizontalPosition = ACPI_PLD_GET_HORIZONTAL (&Dword); 595 PldInfo->Shape = ACPI_PLD_GET_SHAPE (&Dword); 596 PldInfo->GroupOrientation = ACPI_PLD_GET_ORIENTATION (&Dword); 597 PldInfo->GroupToken = ACPI_PLD_GET_TOKEN (&Dword); 598 PldInfo->GroupPosition = ACPI_PLD_GET_POSITION (&Dword); 599 PldInfo->Bay = ACPI_PLD_GET_BAY (&Dword); 600 601 /* Fourth 32-bit DWord */ 602 603 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[3]); 604 PldInfo->Ejectable = ACPI_PLD_GET_EJECTABLE (&Dword); 605 PldInfo->OspmEjectRequired = ACPI_PLD_GET_OSPM_EJECT (&Dword); 606 PldInfo->CabinetNumber = ACPI_PLD_GET_CABINET (&Dword); 607 PldInfo->CardCageNumber = ACPI_PLD_GET_CARD_CAGE (&Dword); 608 PldInfo->Reference = ACPI_PLD_GET_REFERENCE (&Dword); 609 PldInfo->Rotation = ACPI_PLD_GET_ROTATION (&Dword); 610 PldInfo->Order = ACPI_PLD_GET_ORDER (&Dword); 611 612 if (Length >= ACPI_PLD_BUFFER_SIZE) 613 { 614 /* Fifth 32-bit DWord (Revision 2 of _PLD) */ 615 616 ACPI_MOVE_32_TO_32 (&Dword, &Buffer[4]); 617 PldInfo->VerticalOffset = ACPI_PLD_GET_VERT_OFFSET (&Dword); 618 PldInfo->HorizontalOffset = ACPI_PLD_GET_HORIZ_OFFSET (&Dword); 619 } 620 621 *ReturnBuffer = PldInfo; 622 return (AE_OK); 623 } 624 625 ACPI_EXPORT_SYMBOL (AcpiDecodePldBuffer) 626