1 /****************************************************************************** 2 * 3 * Module Name: hwxface - Public ACPICA hardware interfaces 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #define EXPORT_ACPI_INTERFACES 153 154 #include <contrib/dev/acpica/include/acpi.h> 155 #include <contrib/dev/acpica/include/accommon.h> 156 #include <contrib/dev/acpica/include/acnamesp.h> 157 158 #define _COMPONENT ACPI_HARDWARE 159 ACPI_MODULE_NAME ("hwxface") 160 161 162 /****************************************************************************** 163 * 164 * FUNCTION: AcpiReset 165 * 166 * PARAMETERS: None 167 * 168 * RETURN: Status 169 * 170 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not 171 * support reset register in PCI config space, this must be 172 * handled separately. 173 * 174 ******************************************************************************/ 175 176 ACPI_STATUS 177 AcpiReset ( 178 void) 179 { 180 ACPI_GENERIC_ADDRESS *ResetReg; 181 ACPI_STATUS Status; 182 183 184 ACPI_FUNCTION_TRACE (AcpiReset); 185 186 187 ResetReg = &AcpiGbl_FADT.ResetRegister; 188 189 /* Check if the reset register is supported */ 190 191 if (!(AcpiGbl_FADT.Flags & ACPI_FADT_RESET_REGISTER) || 192 !ResetReg->Address) 193 { 194 return_ACPI_STATUS (AE_NOT_EXIST); 195 } 196 197 if (ResetReg->SpaceId == ACPI_ADR_SPACE_SYSTEM_IO) 198 { 199 /* 200 * For I/O space, write directly to the OSL. This bypasses the port 201 * validation mechanism, which may block a valid write to the reset 202 * register. 203 * 204 * NOTE: 205 * The ACPI spec requires the reset register width to be 8, so we 206 * hardcode it here and ignore the FADT value. This maintains 207 * compatibility with other ACPI implementations that have allowed 208 * BIOS code with bad register width values to go unnoticed. 209 */ 210 Status = AcpiOsWritePort ((ACPI_IO_ADDRESS) ResetReg->Address, 211 AcpiGbl_FADT.ResetValue, ACPI_RESET_REGISTER_WIDTH); 212 } 213 else 214 { 215 /* Write the reset value to the reset register */ 216 217 Status = AcpiHwWrite (AcpiGbl_FADT.ResetValue, ResetReg); 218 } 219 220 return_ACPI_STATUS (Status); 221 } 222 223 ACPI_EXPORT_SYMBOL (AcpiReset) 224 225 226 /****************************************************************************** 227 * 228 * FUNCTION: AcpiRead 229 * 230 * PARAMETERS: Value - Where the value is returned 231 * Reg - GAS register structure 232 * 233 * RETURN: Status 234 * 235 * DESCRIPTION: Read from either memory or IO space. 236 * 237 * LIMITATIONS: <These limitations also apply to AcpiWrite> 238 * BitWidth must be exactly 8, 16, 32, or 64. 239 * SpaceID must be SystemMemory or SystemIO. 240 * BitOffset and AccessWidth are currently ignored, as there has 241 * not been a need to implement these. 242 * 243 ******************************************************************************/ 244 245 ACPI_STATUS 246 AcpiRead ( 247 UINT64 *ReturnValue, 248 ACPI_GENERIC_ADDRESS *Reg) 249 { 250 UINT32 ValueLo; 251 UINT32 ValueHi; 252 UINT32 Width; 253 UINT64 Address; 254 ACPI_STATUS Status; 255 256 257 ACPI_FUNCTION_NAME (AcpiRead); 258 259 260 if (!ReturnValue) 261 { 262 return (AE_BAD_PARAMETER); 263 } 264 265 /* Validate contents of the GAS register. Allow 64-bit transfers */ 266 267 Status = AcpiHwValidateRegister (Reg, 64, &Address); 268 if (ACPI_FAILURE (Status)) 269 { 270 return (Status); 271 } 272 273 /* 274 * Two address spaces supported: Memory or I/O. PCI_Config is 275 * not supported here because the GAS structure is insufficient 276 */ 277 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) 278 { 279 Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS) 280 Address, ReturnValue, Reg->BitWidth); 281 if (ACPI_FAILURE (Status)) 282 { 283 return (Status); 284 } 285 } 286 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ 287 { 288 ValueLo = 0; 289 ValueHi = 0; 290 291 Width = Reg->BitWidth; 292 if (Width == 64) 293 { 294 Width = 32; /* Break into two 32-bit transfers */ 295 } 296 297 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) 298 Address, &ValueLo, Width); 299 if (ACPI_FAILURE (Status)) 300 { 301 return (Status); 302 } 303 304 if (Reg->BitWidth == 64) 305 { 306 /* Read the top 32 bits */ 307 308 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) 309 (Address + 4), &ValueHi, 32); 310 if (ACPI_FAILURE (Status)) 311 { 312 return (Status); 313 } 314 } 315 316 /* Set the return value only if status is AE_OK */ 317 318 *ReturnValue = (ValueLo | ((UINT64) ValueHi << 32)); 319 } 320 321 ACPI_DEBUG_PRINT ((ACPI_DB_IO, 322 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n", 323 ACPI_FORMAT_UINT64 (*ReturnValue), Reg->BitWidth, 324 ACPI_FORMAT_UINT64 (Address), 325 AcpiUtGetRegionName (Reg->SpaceId))); 326 327 return (AE_OK); 328 } 329 330 ACPI_EXPORT_SYMBOL (AcpiRead) 331 332 333 /****************************************************************************** 334 * 335 * FUNCTION: AcpiWrite 336 * 337 * PARAMETERS: Value - Value to be written 338 * Reg - GAS register structure 339 * 340 * RETURN: Status 341 * 342 * DESCRIPTION: Write to either memory or IO space. 343 * 344 ******************************************************************************/ 345 346 ACPI_STATUS 347 AcpiWrite ( 348 UINT64 Value, 349 ACPI_GENERIC_ADDRESS *Reg) 350 { 351 UINT32 Width; 352 UINT64 Address; 353 ACPI_STATUS Status; 354 355 356 ACPI_FUNCTION_NAME (AcpiWrite); 357 358 359 /* Validate contents of the GAS register. Allow 64-bit transfers */ 360 361 Status = AcpiHwValidateRegister (Reg, 64, &Address); 362 if (ACPI_FAILURE (Status)) 363 { 364 return (Status); 365 } 366 367 /* 368 * Two address spaces supported: Memory or IO. PCI_Config is 369 * not supported here because the GAS structure is insufficient 370 */ 371 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) 372 { 373 Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS) 374 Address, Value, Reg->BitWidth); 375 if (ACPI_FAILURE (Status)) 376 { 377 return (Status); 378 } 379 } 380 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ 381 { 382 Width = Reg->BitWidth; 383 if (Width == 64) 384 { 385 Width = 32; /* Break into two 32-bit transfers */ 386 } 387 388 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) 389 Address, ACPI_LODWORD (Value), Width); 390 if (ACPI_FAILURE (Status)) 391 { 392 return (Status); 393 } 394 395 if (Reg->BitWidth == 64) 396 { 397 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) 398 (Address + 4), ACPI_HIDWORD (Value), 32); 399 if (ACPI_FAILURE (Status)) 400 { 401 return (Status); 402 } 403 } 404 } 405 406 ACPI_DEBUG_PRINT ((ACPI_DB_IO, 407 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n", 408 ACPI_FORMAT_UINT64 (Value), Reg->BitWidth, 409 ACPI_FORMAT_UINT64 (Address), 410 AcpiUtGetRegionName (Reg->SpaceId))); 411 412 return (Status); 413 } 414 415 ACPI_EXPORT_SYMBOL (AcpiWrite) 416 417 418 #if (!ACPI_REDUCED_HARDWARE) 419 /******************************************************************************* 420 * 421 * FUNCTION: AcpiReadBitRegister 422 * 423 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access 424 * ReturnValue - Value that was read from the register, 425 * normalized to bit position zero. 426 * 427 * RETURN: Status and the value read from the specified Register. Value 428 * returned is normalized to bit0 (is shifted all the way right) 429 * 430 * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock. 431 * 432 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and 433 * PM2 Control. 434 * 435 * Note: The hardware lock is not required when reading the ACPI bit registers 436 * since almost all of them are single bit and it does not matter that 437 * the parent hardware register can be split across two physical 438 * registers. The only multi-bit field is SLP_TYP in the PM1 control 439 * register, but this field does not cross an 8-bit boundary (nor does 440 * it make much sense to actually read this field.) 441 * 442 ******************************************************************************/ 443 444 ACPI_STATUS 445 AcpiReadBitRegister ( 446 UINT32 RegisterId, 447 UINT32 *ReturnValue) 448 { 449 ACPI_BIT_REGISTER_INFO *BitRegInfo; 450 UINT32 RegisterValue; 451 UINT32 Value; 452 ACPI_STATUS Status; 453 454 455 ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister, RegisterId); 456 457 458 /* Get the info structure corresponding to the requested ACPI Register */ 459 460 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId); 461 if (!BitRegInfo) 462 { 463 return_ACPI_STATUS (AE_BAD_PARAMETER); 464 } 465 466 /* Read the entire parent register */ 467 468 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister, 469 &RegisterValue); 470 if (ACPI_FAILURE (Status)) 471 { 472 return_ACPI_STATUS (Status); 473 } 474 475 /* Normalize the value that was read, mask off other bits */ 476 477 Value = ((RegisterValue & BitRegInfo->AccessBitMask) 478 >> BitRegInfo->BitPosition); 479 480 ACPI_DEBUG_PRINT ((ACPI_DB_IO, 481 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n", 482 RegisterId, BitRegInfo->ParentRegister, RegisterValue, Value)); 483 484 *ReturnValue = Value; 485 return_ACPI_STATUS (AE_OK); 486 } 487 488 ACPI_EXPORT_SYMBOL (AcpiReadBitRegister) 489 490 491 /******************************************************************************* 492 * 493 * FUNCTION: AcpiWriteBitRegister 494 * 495 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access 496 * Value - Value to write to the register, in bit 497 * position zero. The bit is automatically 498 * shifted to the correct position. 499 * 500 * RETURN: Status 501 * 502 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock 503 * since most operations require a read/modify/write sequence. 504 * 505 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and 506 * PM2 Control. 507 * 508 * Note that at this level, the fact that there may be actually two 509 * hardware registers (A and B - and B may not exist) is abstracted. 510 * 511 ******************************************************************************/ 512 513 ACPI_STATUS 514 AcpiWriteBitRegister ( 515 UINT32 RegisterId, 516 UINT32 Value) 517 { 518 ACPI_BIT_REGISTER_INFO *BitRegInfo; 519 ACPI_CPU_FLAGS LockFlags; 520 UINT32 RegisterValue; 521 ACPI_STATUS Status = AE_OK; 522 523 524 ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister, RegisterId); 525 526 527 /* Get the info structure corresponding to the requested ACPI Register */ 528 529 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId); 530 if (!BitRegInfo) 531 { 532 return_ACPI_STATUS (AE_BAD_PARAMETER); 533 } 534 535 LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock); 536 537 /* 538 * At this point, we know that the parent register is one of the 539 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control 540 */ 541 if (BitRegInfo->ParentRegister != ACPI_REGISTER_PM1_STATUS) 542 { 543 /* 544 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control 545 * 546 * Perform a register read to preserve the bits that we are not 547 * interested in 548 */ 549 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister, 550 &RegisterValue); 551 if (ACPI_FAILURE (Status)) 552 { 553 goto UnlockAndExit; 554 } 555 556 /* 557 * Insert the input bit into the value that was just read 558 * and write the register 559 */ 560 ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition, 561 BitRegInfo->AccessBitMask, Value); 562 563 Status = AcpiHwRegisterWrite (BitRegInfo->ParentRegister, 564 RegisterValue); 565 } 566 else 567 { 568 /* 569 * 2) Case for PM1 Status 570 * 571 * The Status register is different from the rest. Clear an event 572 * by writing 1, writing 0 has no effect. So, the only relevant 573 * information is the single bit we're interested in, all others 574 * should be written as 0 so they will be left unchanged. 575 */ 576 RegisterValue = ACPI_REGISTER_PREPARE_BITS (Value, 577 BitRegInfo->BitPosition, BitRegInfo->AccessBitMask); 578 579 /* No need to write the register if value is all zeros */ 580 581 if (RegisterValue) 582 { 583 Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS, 584 RegisterValue); 585 } 586 } 587 588 ACPI_DEBUG_PRINT ((ACPI_DB_IO, 589 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n", 590 RegisterId, BitRegInfo->ParentRegister, Value, RegisterValue)); 591 592 593 UnlockAndExit: 594 595 AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags); 596 return_ACPI_STATUS (Status); 597 } 598 599 ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister) 600 601 #endif /* !ACPI_REDUCED_HARDWARE */ 602 603 604 /******************************************************************************* 605 * 606 * FUNCTION: AcpiGetSleepTypeData 607 * 608 * PARAMETERS: SleepState - Numeric sleep state 609 * *SleepTypeA - Where SLP_TYPa is returned 610 * *SleepTypeB - Where SLP_TYPb is returned 611 * 612 * RETURN: Status 613 * 614 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested 615 * sleep state via the appropriate \_Sx object. 616 * 617 * The sleep state package returned from the corresponding \_Sx_ object 618 * must contain at least one integer. 619 * 620 * March 2005: 621 * Added support for a package that contains two integers. This 622 * goes against the ACPI specification which defines this object as a 623 * package with one encoded DWORD integer. However, existing practice 624 * by many BIOS vendors is to return a package with 2 or more integer 625 * elements, at least one per sleep type (A/B). 626 * 627 * January 2013: 628 * Therefore, we must be prepared to accept a package with either a 629 * single integer or multiple integers. 630 * 631 * The single integer DWORD format is as follows: 632 * BYTE 0 - Value for the PM1A SLP_TYP register 633 * BYTE 1 - Value for the PM1B SLP_TYP register 634 * BYTE 2-3 - Reserved 635 * 636 * The dual integer format is as follows: 637 * Integer 0 - Value for the PM1A SLP_TYP register 638 * Integer 1 - Value for the PM1A SLP_TYP register 639 * 640 ******************************************************************************/ 641 642 ACPI_STATUS 643 AcpiGetSleepTypeData ( 644 UINT8 SleepState, 645 UINT8 *SleepTypeA, 646 UINT8 *SleepTypeB) 647 { 648 ACPI_STATUS Status; 649 ACPI_EVALUATE_INFO *Info; 650 ACPI_OPERAND_OBJECT **Elements; 651 652 653 ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData); 654 655 656 /* Validate parameters */ 657 658 if ((SleepState > ACPI_S_STATES_MAX) || 659 !SleepTypeA || !SleepTypeB) 660 { 661 return_ACPI_STATUS (AE_BAD_PARAMETER); 662 } 663 664 /* Allocate the evaluation information block */ 665 666 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 667 if (!Info) 668 { 669 return_ACPI_STATUS (AE_NO_MEMORY); 670 } 671 672 /* 673 * Evaluate the \_Sx namespace object containing the register values 674 * for this state 675 */ 676 Info->RelativePathname = AcpiGbl_SleepStateNames[SleepState]; 677 678 Status = AcpiNsEvaluate (Info); 679 if (ACPI_FAILURE (Status)) 680 { 681 if (Status == AE_NOT_FOUND) 682 { 683 /* The _Sx states are optional, ignore NOT_FOUND */ 684 685 goto FinalCleanup; 686 } 687 688 goto WarningCleanup; 689 } 690 691 /* Must have a return object */ 692 693 if (!Info->ReturnObject) 694 { 695 ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]", 696 Info->RelativePathname)); 697 Status = AE_AML_NO_RETURN_VALUE; 698 goto WarningCleanup; 699 } 700 701 /* Return object must be of type Package */ 702 703 if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE) 704 { 705 ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package")); 706 Status = AE_AML_OPERAND_TYPE; 707 goto ReturnValueCleanup; 708 } 709 710 /* 711 * Any warnings about the package length or the object types have 712 * already been issued by the predefined name module -- there is no 713 * need to repeat them here. 714 */ 715 Elements = Info->ReturnObject->Package.Elements; 716 switch (Info->ReturnObject->Package.Count) 717 { 718 case 0: 719 720 Status = AE_AML_PACKAGE_LIMIT; 721 break; 722 723 case 1: 724 725 if (Elements[0]->Common.Type != ACPI_TYPE_INTEGER) 726 { 727 Status = AE_AML_OPERAND_TYPE; 728 break; 729 } 730 731 /* A valid _Sx_ package with one integer */ 732 733 *SleepTypeA = (UINT8) Elements[0]->Integer.Value; 734 *SleepTypeB = (UINT8) (Elements[0]->Integer.Value >> 8); 735 break; 736 737 case 2: 738 default: 739 740 if ((Elements[0]->Common.Type != ACPI_TYPE_INTEGER) || 741 (Elements[1]->Common.Type != ACPI_TYPE_INTEGER)) 742 { 743 Status = AE_AML_OPERAND_TYPE; 744 break; 745 } 746 747 /* A valid _Sx_ package with two integers */ 748 749 *SleepTypeA = (UINT8) Elements[0]->Integer.Value; 750 *SleepTypeB = (UINT8) Elements[1]->Integer.Value; 751 break; 752 } 753 754 ReturnValueCleanup: 755 AcpiUtRemoveReference (Info->ReturnObject); 756 757 WarningCleanup: 758 if (ACPI_FAILURE (Status)) 759 { 760 ACPI_EXCEPTION ((AE_INFO, Status, 761 "While evaluating Sleep State [%s]", 762 Info->RelativePathname)); 763 } 764 765 FinalCleanup: 766 ACPI_FREE (Info); 767 return_ACPI_STATUS (Status); 768 } 769 770 ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData) 771