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