1*3446Smrj 2*3446Smrj /******************************************************************************* 3*3446Smrj * 4*3446Smrj * Module Name: hwregs - Read/write access functions for the various ACPI 5*3446Smrj * control and status registers. 6*3446Smrj * $Revision: 1.183 $ 7*3446Smrj * 8*3446Smrj ******************************************************************************/ 9*3446Smrj 10*3446Smrj /****************************************************************************** 11*3446Smrj * 12*3446Smrj * 1. Copyright Notice 13*3446Smrj * 14*3446Smrj * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp. 15*3446Smrj * All rights reserved. 16*3446Smrj * 17*3446Smrj * 2. License 18*3446Smrj * 19*3446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property 20*3446Smrj * rights. You may have additional license terms from the party that provided 21*3446Smrj * you this software, covering your right to use that party's intellectual 22*3446Smrj * property rights. 23*3446Smrj * 24*3446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 25*3446Smrj * copy of the source code appearing in this file ("Covered Code") an 26*3446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 27*3446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy, 28*3446Smrj * make derivatives, distribute, use and display any portion of the Covered 29*3446Smrj * Code in any form, with the right to sublicense such rights; and 30*3446Smrj * 31*3446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 32*3446Smrj * license (with the right to sublicense), under only those claims of Intel 33*3446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell, 34*3446Smrj * offer to sell, and import the Covered Code and derivative works thereof 35*3446Smrj * solely to the minimum extent necessary to exercise the above copyright 36*3446Smrj * license, and in no event shall the patent license extend to any additions 37*3446Smrj * to or modifications of the Original Intel Code. No other license or right 38*3446Smrj * is granted directly or by implication, estoppel or otherwise; 39*3446Smrj * 40*3446Smrj * The above copyright and patent license is granted only if the following 41*3446Smrj * conditions are met: 42*3446Smrj * 43*3446Smrj * 3. Conditions 44*3446Smrj * 45*3446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 46*3446Smrj * Redistribution of source code of any substantial portion of the Covered 47*3446Smrj * Code or modification with rights to further distribute source must include 48*3446Smrj * the above Copyright Notice, the above License, this list of Conditions, 49*3446Smrj * and the following Disclaimer and Export Compliance provision. In addition, 50*3446Smrj * Licensee must cause all Covered Code to which Licensee contributes to 51*3446Smrj * contain a file documenting the changes Licensee made to create that Covered 52*3446Smrj * Code and the date of any change. Licensee must include in that file the 53*3446Smrj * documentation of any changes made by any predecessor Licensee. Licensee 54*3446Smrj * must include a prominent statement that the modification is derived, 55*3446Smrj * directly or indirectly, from Original Intel Code. 56*3446Smrj * 57*3446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 58*3446Smrj * Redistribution of source code of any substantial portion of the Covered 59*3446Smrj * Code or modification without rights to further distribute source must 60*3446Smrj * include the following Disclaimer and Export Compliance provision in the 61*3446Smrj * documentation and/or other materials provided with distribution. In 62*3446Smrj * addition, Licensee may not authorize further sublicense of source of any 63*3446Smrj * portion of the Covered Code, and must include terms to the effect that the 64*3446Smrj * license from Licensee to its licensee is limited to the intellectual 65*3446Smrj * property embodied in the software Licensee provides to its licensee, and 66*3446Smrj * not to intellectual property embodied in modifications its licensee may 67*3446Smrj * make. 68*3446Smrj * 69*3446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any 70*3446Smrj * substantial portion of the Covered Code or modification must reproduce the 71*3446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance 72*3446Smrj * provision in the documentation and/or other materials provided with the 73*3446Smrj * distribution. 74*3446Smrj * 75*3446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original 76*3446Smrj * Intel Code. 77*3446Smrj * 78*3446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by 79*3446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or 80*3446Smrj * other dealings in products derived from or relating to the Covered Code 81*3446Smrj * without prior written authorization from Intel. 82*3446Smrj * 83*3446Smrj * 4. Disclaimer and Export Compliance 84*3446Smrj * 85*3446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 86*3446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 87*3446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 88*3446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 89*3446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 90*3446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 91*3446Smrj * PARTICULAR PURPOSE. 92*3446Smrj * 93*3446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 94*3446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 95*3446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 96*3446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 97*3446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 98*3446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 99*3446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 100*3446Smrj * LIMITED REMEDY. 101*3446Smrj * 102*3446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this 103*3446Smrj * software or system incorporating such software without first obtaining any 104*3446Smrj * required license or other approval from the U. S. Department of Commerce or 105*3446Smrj * any other agency or department of the United States Government. In the 106*3446Smrj * event Licensee exports any such software from the United States or 107*3446Smrj * re-exports any such software from a foreign destination, Licensee shall 108*3446Smrj * ensure that the distribution and export/re-export of the software is in 109*3446Smrj * compliance with all laws, regulations, orders, or other restrictions of the 110*3446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor 111*3446Smrj * any of its subsidiaries will export/re-export any technical data, process, 112*3446Smrj * software, or service, directly or indirectly, to any country for which the 113*3446Smrj * United States government or any agency thereof requires an export license, 114*3446Smrj * other governmental approval, or letter of assurance, without first obtaining 115*3446Smrj * such license, approval or letter. 116*3446Smrj * 117*3446Smrj *****************************************************************************/ 118*3446Smrj 119*3446Smrj #define __HWREGS_C__ 120*3446Smrj 121*3446Smrj #include "acpi.h" 122*3446Smrj #include "acnamesp.h" 123*3446Smrj #include "acevents.h" 124*3446Smrj 125*3446Smrj #define _COMPONENT ACPI_HARDWARE 126*3446Smrj ACPI_MODULE_NAME ("hwregs") 127*3446Smrj 128*3446Smrj 129*3446Smrj /******************************************************************************* 130*3446Smrj * 131*3446Smrj * FUNCTION: AcpiHwClearAcpiStatus 132*3446Smrj * 133*3446Smrj * PARAMETERS: Flags - Lock the hardware or not 134*3446Smrj * 135*3446Smrj * RETURN: none 136*3446Smrj * 137*3446Smrj * DESCRIPTION: Clears all fixed and general purpose status bits 138*3446Smrj * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED 139*3446Smrj * 140*3446Smrj * NOTE: TBD: Flags parameter is obsolete, to be removed 141*3446Smrj * 142*3446Smrj ******************************************************************************/ 143*3446Smrj 144*3446Smrj ACPI_STATUS 145*3446Smrj AcpiHwClearAcpiStatus ( 146*3446Smrj UINT32 Flags) 147*3446Smrj { 148*3446Smrj ACPI_STATUS Status; 149*3446Smrj ACPI_CPU_FLAGS LockFlags = 0; 150*3446Smrj 151*3446Smrj 152*3446Smrj ACPI_FUNCTION_TRACE (HwClearAcpiStatus); 153*3446Smrj 154*3446Smrj 155*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %04X to %04X\n", 156*3446Smrj ACPI_BITMASK_ALL_FIXED_STATUS, 157*3446Smrj (UINT16) ACPI_GET_ADDRESS (AcpiGbl_FADT->XPm1aEvtBlk.Address))); 158*3446Smrj 159*3446Smrj LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock); 160*3446Smrj 161*3446Smrj Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 162*3446Smrj ACPI_REGISTER_PM1_STATUS, 163*3446Smrj ACPI_BITMASK_ALL_FIXED_STATUS); 164*3446Smrj if (ACPI_FAILURE (Status)) 165*3446Smrj { 166*3446Smrj goto UnlockAndExit; 167*3446Smrj } 168*3446Smrj 169*3446Smrj /* Clear the fixed events */ 170*3446Smrj 171*3446Smrj if (ACPI_VALID_ADDRESS (AcpiGbl_FADT->XPm1bEvtBlk.Address)) 172*3446Smrj { 173*3446Smrj Status = AcpiHwLowLevelWrite (16, ACPI_BITMASK_ALL_FIXED_STATUS, 174*3446Smrj &AcpiGbl_FADT->XPm1bEvtBlk); 175*3446Smrj if (ACPI_FAILURE (Status)) 176*3446Smrj { 177*3446Smrj goto UnlockAndExit; 178*3446Smrj } 179*3446Smrj } 180*3446Smrj 181*3446Smrj /* Clear the GPE Bits in all GPE registers in all GPE blocks */ 182*3446Smrj 183*3446Smrj Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock); 184*3446Smrj 185*3446Smrj UnlockAndExit: 186*3446Smrj AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags); 187*3446Smrj return_ACPI_STATUS (Status); 188*3446Smrj } 189*3446Smrj 190*3446Smrj 191*3446Smrj /******************************************************************************* 192*3446Smrj * 193*3446Smrj * FUNCTION: AcpiGetSleepTypeData 194*3446Smrj * 195*3446Smrj * PARAMETERS: SleepState - Numeric sleep state 196*3446Smrj * *SleepTypeA - Where SLP_TYPa is returned 197*3446Smrj * *SleepTypeB - Where SLP_TYPb is returned 198*3446Smrj * 199*3446Smrj * RETURN: Status - ACPI status 200*3446Smrj * 201*3446Smrj * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep 202*3446Smrj * state. 203*3446Smrj * 204*3446Smrj ******************************************************************************/ 205*3446Smrj 206*3446Smrj ACPI_STATUS 207*3446Smrj AcpiGetSleepTypeData ( 208*3446Smrj UINT8 SleepState, 209*3446Smrj UINT8 *SleepTypeA, 210*3446Smrj UINT8 *SleepTypeB) 211*3446Smrj { 212*3446Smrj ACPI_STATUS Status = AE_OK; 213*3446Smrj ACPI_EVALUATE_INFO *Info; 214*3446Smrj 215*3446Smrj 216*3446Smrj ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData); 217*3446Smrj 218*3446Smrj 219*3446Smrj /* Validate parameters */ 220*3446Smrj 221*3446Smrj if ((SleepState > ACPI_S_STATES_MAX) || 222*3446Smrj !SleepTypeA || !SleepTypeB) 223*3446Smrj { 224*3446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 225*3446Smrj } 226*3446Smrj 227*3446Smrj /* Allocate the evaluation information block */ 228*3446Smrj 229*3446Smrj Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 230*3446Smrj if (!Info) 231*3446Smrj { 232*3446Smrj return_ACPI_STATUS (AE_NO_MEMORY); 233*3446Smrj } 234*3446Smrj 235*3446Smrj Info->Pathname = ACPI_CAST_PTR (char, AcpiGbl_SleepStateNames[SleepState]); 236*3446Smrj 237*3446Smrj /* Evaluate the namespace object containing the values for this state */ 238*3446Smrj 239*3446Smrj Status = AcpiNsEvaluate (Info); 240*3446Smrj if (ACPI_FAILURE (Status)) 241*3446Smrj { 242*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 243*3446Smrj "%s while evaluating SleepState [%s]\n", 244*3446Smrj AcpiFormatException (Status), Info->Pathname)); 245*3446Smrj 246*3446Smrj goto Cleanup; 247*3446Smrj } 248*3446Smrj 249*3446Smrj /* Must have a return object */ 250*3446Smrj 251*3446Smrj if (!Info->ReturnObject) 252*3446Smrj { 253*3446Smrj ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]", 254*3446Smrj Info->Pathname)); 255*3446Smrj Status = AE_NOT_EXIST; 256*3446Smrj } 257*3446Smrj 258*3446Smrj /* It must be of type Package */ 259*3446Smrj 260*3446Smrj else if (ACPI_GET_OBJECT_TYPE (Info->ReturnObject) != ACPI_TYPE_PACKAGE) 261*3446Smrj { 262*3446Smrj ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package")); 263*3446Smrj Status = AE_AML_OPERAND_TYPE; 264*3446Smrj } 265*3446Smrj 266*3446Smrj /* 267*3446Smrj * The package must have at least two elements. NOTE (March 2005): This 268*3446Smrj * goes against the current ACPI spec which defines this object as a 269*3446Smrj * package with one encoded DWORD element. However, existing practice 270*3446Smrj * by BIOS vendors seems to be to have 2 or more elements, at least 271*3446Smrj * one per sleep type (A/B). 272*3446Smrj */ 273*3446Smrj else if (Info->ReturnObject->Package.Count < 2) 274*3446Smrj { 275*3446Smrj ACPI_ERROR ((AE_INFO, 276*3446Smrj "Sleep State return package does not have at least two elements")); 277*3446Smrj Status = AE_AML_NO_OPERAND; 278*3446Smrj } 279*3446Smrj 280*3446Smrj /* The first two elements must both be of type Integer */ 281*3446Smrj 282*3446Smrj else if ((ACPI_GET_OBJECT_TYPE (Info->ReturnObject->Package.Elements[0]) 283*3446Smrj != ACPI_TYPE_INTEGER) || 284*3446Smrj (ACPI_GET_OBJECT_TYPE (Info->ReturnObject->Package.Elements[1]) 285*3446Smrj != ACPI_TYPE_INTEGER)) 286*3446Smrj { 287*3446Smrj ACPI_ERROR ((AE_INFO, 288*3446Smrj "Sleep State return package elements are not both Integers (%s, %s)", 289*3446Smrj AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[0]), 290*3446Smrj AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[1]))); 291*3446Smrj Status = AE_AML_OPERAND_TYPE; 292*3446Smrj } 293*3446Smrj else 294*3446Smrj { 295*3446Smrj /* Valid _Sx_ package size, type, and value */ 296*3446Smrj 297*3446Smrj *SleepTypeA = (UINT8) 298*3446Smrj (Info->ReturnObject->Package.Elements[0])->Integer.Value; 299*3446Smrj *SleepTypeB = (UINT8) 300*3446Smrj (Info->ReturnObject->Package.Elements[1])->Integer.Value; 301*3446Smrj } 302*3446Smrj 303*3446Smrj if (ACPI_FAILURE (Status)) 304*3446Smrj { 305*3446Smrj ACPI_EXCEPTION ((AE_INFO, Status, 306*3446Smrj "While evaluating SleepState [%s], bad Sleep object %p type %s", 307*3446Smrj Info->Pathname, Info->ReturnObject, 308*3446Smrj AcpiUtGetObjectTypeName (Info->ReturnObject))); 309*3446Smrj } 310*3446Smrj 311*3446Smrj AcpiUtRemoveReference (Info->ReturnObject); 312*3446Smrj 313*3446Smrj Cleanup: 314*3446Smrj ACPI_FREE (Info); 315*3446Smrj return_ACPI_STATUS (Status); 316*3446Smrj } 317*3446Smrj 318*3446Smrj ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData) 319*3446Smrj 320*3446Smrj 321*3446Smrj /******************************************************************************* 322*3446Smrj * 323*3446Smrj * FUNCTION: AcpiHwGetRegisterBitMask 324*3446Smrj * 325*3446Smrj * PARAMETERS: RegisterId - Index of ACPI Register to access 326*3446Smrj * 327*3446Smrj * RETURN: The bitmask to be used when accessing the register 328*3446Smrj * 329*3446Smrj * DESCRIPTION: Map RegisterId into a register bitmask. 330*3446Smrj * 331*3446Smrj ******************************************************************************/ 332*3446Smrj 333*3446Smrj ACPI_BIT_REGISTER_INFO * 334*3446Smrj AcpiHwGetBitRegisterInfo ( 335*3446Smrj UINT32 RegisterId) 336*3446Smrj { 337*3446Smrj ACPI_FUNCTION_ENTRY (); 338*3446Smrj 339*3446Smrj 340*3446Smrj if (RegisterId > ACPI_BITREG_MAX) 341*3446Smrj { 342*3446Smrj ACPI_ERROR ((AE_INFO, "Invalid BitRegister ID: %X", RegisterId)); 343*3446Smrj return (NULL); 344*3446Smrj } 345*3446Smrj 346*3446Smrj return (&AcpiGbl_BitRegisterInfo[RegisterId]); 347*3446Smrj } 348*3446Smrj 349*3446Smrj 350*3446Smrj /******************************************************************************* 351*3446Smrj * 352*3446Smrj * FUNCTION: AcpiGetRegister 353*3446Smrj * 354*3446Smrj * PARAMETERS: RegisterId - ID of ACPI BitRegister to access 355*3446Smrj * ReturnValue - Value that was read from the register 356*3446Smrj * Flags - Lock the hardware or not 357*3446Smrj * 358*3446Smrj * RETURN: Status and the value read from specified Register. Value 359*3446Smrj * returned is normalized to bit0 (is shifted all the way right) 360*3446Smrj * 361*3446Smrj * DESCRIPTION: ACPI BitRegister read function. 362*3446Smrj * 363*3446Smrj * NOTE: TBD: Flags parameter is obsolete, to be removed 364*3446Smrj * 365*3446Smrj ******************************************************************************/ 366*3446Smrj 367*3446Smrj ACPI_STATUS 368*3446Smrj AcpiGetRegister ( 369*3446Smrj UINT32 RegisterId, 370*3446Smrj UINT32 *ReturnValue, 371*3446Smrj UINT32 Flags) 372*3446Smrj { 373*3446Smrj UINT32 RegisterValue = 0; 374*3446Smrj ACPI_BIT_REGISTER_INFO *BitRegInfo; 375*3446Smrj ACPI_STATUS Status; 376*3446Smrj 377*3446Smrj 378*3446Smrj ACPI_FUNCTION_TRACE (AcpiGetRegister); 379*3446Smrj 380*3446Smrj 381*3446Smrj /* Get the info structure corresponding to the requested ACPI Register */ 382*3446Smrj 383*3446Smrj BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId); 384*3446Smrj if (!BitRegInfo) 385*3446Smrj { 386*3446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 387*3446Smrj } 388*3446Smrj 389*3446Smrj /* Read from the register */ 390*3446Smrj 391*3446Smrj Status = AcpiHwRegisterRead (ACPI_MTX_LOCK, 392*3446Smrj BitRegInfo->ParentRegister, &RegisterValue); 393*3446Smrj 394*3446Smrj if (ACPI_SUCCESS (Status)) 395*3446Smrj { 396*3446Smrj /* Normalize the value that was read */ 397*3446Smrj 398*3446Smrj RegisterValue = ((RegisterValue & BitRegInfo->AccessBitMask) 399*3446Smrj >> BitRegInfo->BitPosition); 400*3446Smrj 401*3446Smrj *ReturnValue = RegisterValue; 402*3446Smrj 403*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read value %8.8X register %X\n", 404*3446Smrj RegisterValue, BitRegInfo->ParentRegister)); 405*3446Smrj } 406*3446Smrj 407*3446Smrj return_ACPI_STATUS (Status); 408*3446Smrj } 409*3446Smrj 410*3446Smrj ACPI_EXPORT_SYMBOL (AcpiGetRegister) 411*3446Smrj 412*3446Smrj 413*3446Smrj /******************************************************************************* 414*3446Smrj * 415*3446Smrj * FUNCTION: AcpiSetRegister 416*3446Smrj * 417*3446Smrj * PARAMETERS: RegisterId - ID of ACPI BitRegister to access 418*3446Smrj * Value - (only used on write) value to write to the 419*3446Smrj * Register, NOT pre-normalized to the bit pos 420*3446Smrj * Flags - Lock the hardware or not 421*3446Smrj * 422*3446Smrj * RETURN: Status 423*3446Smrj * 424*3446Smrj * DESCRIPTION: ACPI Bit Register write function. 425*3446Smrj * 426*3446Smrj * NOTE: TBD: Flags parameter is obsolete, to be removed 427*3446Smrj * 428*3446Smrj ******************************************************************************/ 429*3446Smrj 430*3446Smrj ACPI_STATUS 431*3446Smrj AcpiSetRegister ( 432*3446Smrj UINT32 RegisterId, 433*3446Smrj UINT32 Value, 434*3446Smrj UINT32 Flags) 435*3446Smrj { 436*3446Smrj UINT32 RegisterValue = 0; 437*3446Smrj ACPI_BIT_REGISTER_INFO *BitRegInfo; 438*3446Smrj ACPI_STATUS Status; 439*3446Smrj ACPI_CPU_FLAGS LockFlags; 440*3446Smrj 441*3446Smrj 442*3446Smrj ACPI_FUNCTION_TRACE_U32 (AcpiSetRegister, RegisterId); 443*3446Smrj 444*3446Smrj 445*3446Smrj /* Get the info structure corresponding to the requested ACPI Register */ 446*3446Smrj 447*3446Smrj BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId); 448*3446Smrj if (!BitRegInfo) 449*3446Smrj { 450*3446Smrj ACPI_ERROR ((AE_INFO, "Bad ACPI HW RegisterId: %X", RegisterId)); 451*3446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 452*3446Smrj } 453*3446Smrj 454*3446Smrj LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock); 455*3446Smrj 456*3446Smrj /* Always do a register read first so we can insert the new bits */ 457*3446Smrj 458*3446Smrj Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, 459*3446Smrj BitRegInfo->ParentRegister, &RegisterValue); 460*3446Smrj if (ACPI_FAILURE (Status)) 461*3446Smrj { 462*3446Smrj goto UnlockAndExit; 463*3446Smrj } 464*3446Smrj 465*3446Smrj /* 466*3446Smrj * Decode the Register ID 467*3446Smrj * Register ID = [Register block ID] | [bit ID] 468*3446Smrj * 469*3446Smrj * Check bit ID to fine locate Register offset. 470*3446Smrj * Check Mask to determine Register offset, and then read-write. 471*3446Smrj */ 472*3446Smrj switch (BitRegInfo->ParentRegister) 473*3446Smrj { 474*3446Smrj case ACPI_REGISTER_PM1_STATUS: 475*3446Smrj 476*3446Smrj /* 477*3446Smrj * Status Registers are different from the rest. Clear by 478*3446Smrj * writing 1, and writing 0 has no effect. So, the only relevant 479*3446Smrj * information is the single bit we're interested in, all others should 480*3446Smrj * be written as 0 so they will be left unchanged. 481*3446Smrj */ 482*3446Smrj Value = ACPI_REGISTER_PREPARE_BITS (Value, 483*3446Smrj BitRegInfo->BitPosition, BitRegInfo->AccessBitMask); 484*3446Smrj if (Value) 485*3446Smrj { 486*3446Smrj Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 487*3446Smrj ACPI_REGISTER_PM1_STATUS, (UINT16) Value); 488*3446Smrj RegisterValue = 0; 489*3446Smrj } 490*3446Smrj break; 491*3446Smrj 492*3446Smrj 493*3446Smrj case ACPI_REGISTER_PM1_ENABLE: 494*3446Smrj 495*3446Smrj ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition, 496*3446Smrj BitRegInfo->AccessBitMask, Value); 497*3446Smrj 498*3446Smrj Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 499*3446Smrj ACPI_REGISTER_PM1_ENABLE, (UINT16) RegisterValue); 500*3446Smrj break; 501*3446Smrj 502*3446Smrj 503*3446Smrj case ACPI_REGISTER_PM1_CONTROL: 504*3446Smrj 505*3446Smrj /* 506*3446Smrj * Write the PM1 Control register. 507*3446Smrj * Note that at this level, the fact that there are actually TWO 508*3446Smrj * registers (A and B - and B may not exist) is abstracted. 509*3446Smrj */ 510*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM1 control: Read %X\n", 511*3446Smrj RegisterValue)); 512*3446Smrj 513*3446Smrj ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition, 514*3446Smrj BitRegInfo->AccessBitMask, Value); 515*3446Smrj 516*3446Smrj Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 517*3446Smrj ACPI_REGISTER_PM1_CONTROL, (UINT16) RegisterValue); 518*3446Smrj break; 519*3446Smrj 520*3446Smrj 521*3446Smrj case ACPI_REGISTER_PM2_CONTROL: 522*3446Smrj 523*3446Smrj Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, 524*3446Smrj ACPI_REGISTER_PM2_CONTROL, &RegisterValue); 525*3446Smrj if (ACPI_FAILURE (Status)) 526*3446Smrj { 527*3446Smrj goto UnlockAndExit; 528*3446Smrj } 529*3446Smrj 530*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n", 531*3446Smrj RegisterValue, 532*3446Smrj ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS ( 533*3446Smrj AcpiGbl_FADT->XPm2CntBlk.Address)))); 534*3446Smrj 535*3446Smrj ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition, 536*3446Smrj BitRegInfo->AccessBitMask, Value); 537*3446Smrj 538*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n", 539*3446Smrj RegisterValue, 540*3446Smrj ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS ( 541*3446Smrj AcpiGbl_FADT->XPm2CntBlk.Address)))); 542*3446Smrj 543*3446Smrj Status = AcpiHwRegisterWrite (ACPI_MTX_DO_NOT_LOCK, 544*3446Smrj ACPI_REGISTER_PM2_CONTROL, (UINT8) (RegisterValue)); 545*3446Smrj break; 546*3446Smrj 547*3446Smrj 548*3446Smrj default: 549*3446Smrj break; 550*3446Smrj } 551*3446Smrj 552*3446Smrj 553*3446Smrj UnlockAndExit: 554*3446Smrj 555*3446Smrj AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags); 556*3446Smrj 557*3446Smrj /* Normalize the value that was read */ 558*3446Smrj 559*3446Smrj ACPI_DEBUG_EXEC (RegisterValue = 560*3446Smrj ((RegisterValue & BitRegInfo->AccessBitMask) >> 561*3446Smrj BitRegInfo->BitPosition)); 562*3446Smrj 563*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Set bits: %8.8X actual %8.8X register %X\n", 564*3446Smrj Value, RegisterValue, BitRegInfo->ParentRegister)); 565*3446Smrj return_ACPI_STATUS (Status); 566*3446Smrj } 567*3446Smrj 568*3446Smrj ACPI_EXPORT_SYMBOL (AcpiSetRegister) 569*3446Smrj 570*3446Smrj 571*3446Smrj /****************************************************************************** 572*3446Smrj * 573*3446Smrj * FUNCTION: AcpiHwRegisterRead 574*3446Smrj * 575*3446Smrj * PARAMETERS: UseLock - Lock hardware? True/False 576*3446Smrj * RegisterId - ACPI Register ID 577*3446Smrj * ReturnValue - Where the register value is returned 578*3446Smrj * 579*3446Smrj * RETURN: Status and the value read. 580*3446Smrj * 581*3446Smrj * DESCRIPTION: Read from the specified ACPI register 582*3446Smrj * 583*3446Smrj ******************************************************************************/ 584*3446Smrj 585*3446Smrj ACPI_STATUS 586*3446Smrj AcpiHwRegisterRead ( 587*3446Smrj BOOLEAN UseLock, 588*3446Smrj UINT32 RegisterId, 589*3446Smrj UINT32 *ReturnValue) 590*3446Smrj { 591*3446Smrj UINT32 Value1 = 0; 592*3446Smrj UINT32 Value2 = 0; 593*3446Smrj ACPI_STATUS Status; 594*3446Smrj ACPI_CPU_FLAGS LockFlags = 0; 595*3446Smrj 596*3446Smrj 597*3446Smrj ACPI_FUNCTION_TRACE (HwRegisterRead); 598*3446Smrj 599*3446Smrj 600*3446Smrj if (ACPI_MTX_LOCK == UseLock) 601*3446Smrj { 602*3446Smrj LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock); 603*3446Smrj } 604*3446Smrj 605*3446Smrj switch (RegisterId) 606*3446Smrj { 607*3446Smrj case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ 608*3446Smrj 609*3446Smrj Status = AcpiHwLowLevelRead (16, &Value1, &AcpiGbl_FADT->XPm1aEvtBlk); 610*3446Smrj if (ACPI_FAILURE (Status)) 611*3446Smrj { 612*3446Smrj goto UnlockAndExit; 613*3446Smrj } 614*3446Smrj 615*3446Smrj /* PM1B is optional */ 616*3446Smrj 617*3446Smrj Status = AcpiHwLowLevelRead (16, &Value2, &AcpiGbl_FADT->XPm1bEvtBlk); 618*3446Smrj Value1 |= Value2; 619*3446Smrj break; 620*3446Smrj 621*3446Smrj 622*3446Smrj case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ 623*3446Smrj 624*3446Smrj Status = AcpiHwLowLevelRead (16, &Value1, &AcpiGbl_XPm1aEnable); 625*3446Smrj if (ACPI_FAILURE (Status)) 626*3446Smrj { 627*3446Smrj goto UnlockAndExit; 628*3446Smrj } 629*3446Smrj 630*3446Smrj /* PM1B is optional */ 631*3446Smrj 632*3446Smrj Status = AcpiHwLowLevelRead (16, &Value2, &AcpiGbl_XPm1bEnable); 633*3446Smrj Value1 |= Value2; 634*3446Smrj break; 635*3446Smrj 636*3446Smrj 637*3446Smrj case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ 638*3446Smrj 639*3446Smrj Status = AcpiHwLowLevelRead (16, &Value1, &AcpiGbl_FADT->XPm1aCntBlk); 640*3446Smrj if (ACPI_FAILURE (Status)) 641*3446Smrj { 642*3446Smrj goto UnlockAndExit; 643*3446Smrj } 644*3446Smrj 645*3446Smrj Status = AcpiHwLowLevelRead (16, &Value2, &AcpiGbl_FADT->XPm1bCntBlk); 646*3446Smrj Value1 |= Value2; 647*3446Smrj break; 648*3446Smrj 649*3446Smrj 650*3446Smrj case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ 651*3446Smrj 652*3446Smrj Status = AcpiHwLowLevelRead (8, &Value1, &AcpiGbl_FADT->XPm2CntBlk); 653*3446Smrj break; 654*3446Smrj 655*3446Smrj 656*3446Smrj case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ 657*3446Smrj 658*3446Smrj Status = AcpiHwLowLevelRead (32, &Value1, &AcpiGbl_FADT->XPmTmrBlk); 659*3446Smrj break; 660*3446Smrj 661*3446Smrj case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ 662*3446Smrj 663*3446Smrj Status = AcpiOsReadPort (AcpiGbl_FADT->SmiCmd, &Value1, 8); 664*3446Smrj break; 665*3446Smrj 666*3446Smrj default: 667*3446Smrj ACPI_ERROR ((AE_INFO, "Unknown Register ID: %X", 668*3446Smrj RegisterId)); 669*3446Smrj Status = AE_BAD_PARAMETER; 670*3446Smrj break; 671*3446Smrj } 672*3446Smrj 673*3446Smrj UnlockAndExit: 674*3446Smrj if (ACPI_MTX_LOCK == UseLock) 675*3446Smrj { 676*3446Smrj AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags); 677*3446Smrj } 678*3446Smrj 679*3446Smrj if (ACPI_SUCCESS (Status)) 680*3446Smrj { 681*3446Smrj *ReturnValue = Value1; 682*3446Smrj } 683*3446Smrj 684*3446Smrj return_ACPI_STATUS (Status); 685*3446Smrj } 686*3446Smrj 687*3446Smrj 688*3446Smrj /****************************************************************************** 689*3446Smrj * 690*3446Smrj * FUNCTION: AcpiHwRegisterWrite 691*3446Smrj * 692*3446Smrj * PARAMETERS: UseLock - Lock hardware? True/False 693*3446Smrj * RegisterId - ACPI Register ID 694*3446Smrj * Value - The value to write 695*3446Smrj * 696*3446Smrj * RETURN: Status 697*3446Smrj * 698*3446Smrj * DESCRIPTION: Write to the specified ACPI register 699*3446Smrj * 700*3446Smrj * NOTE: In accordance with the ACPI specification, this function automatically 701*3446Smrj * preserves the value of the following bits, meaning that these bits cannot be 702*3446Smrj * changed via this interface: 703*3446Smrj * 704*3446Smrj * PM1_CONTROL[0] = SCI_EN 705*3446Smrj * PM1_CONTROL[9] 706*3446Smrj * PM1_STATUS[11] 707*3446Smrj * 708*3446Smrj * ACPI References: 709*3446Smrj * 1) Hardware Ignored Bits: When software writes to a register with ignored 710*3446Smrj * bit fields, it preserves the ignored bit fields 711*3446Smrj * 2) SCI_EN: OSPM always preserves this bit position 712*3446Smrj * 713*3446Smrj ******************************************************************************/ 714*3446Smrj 715*3446Smrj ACPI_STATUS 716*3446Smrj AcpiHwRegisterWrite ( 717*3446Smrj BOOLEAN UseLock, 718*3446Smrj UINT32 RegisterId, 719*3446Smrj UINT32 Value) 720*3446Smrj { 721*3446Smrj ACPI_STATUS Status; 722*3446Smrj ACPI_CPU_FLAGS LockFlags = 0; 723*3446Smrj UINT32 ReadValue; 724*3446Smrj 725*3446Smrj 726*3446Smrj ACPI_FUNCTION_TRACE (HwRegisterWrite); 727*3446Smrj 728*3446Smrj 729*3446Smrj if (ACPI_MTX_LOCK == UseLock) 730*3446Smrj { 731*3446Smrj LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock); 732*3446Smrj } 733*3446Smrj 734*3446Smrj switch (RegisterId) 735*3446Smrj { 736*3446Smrj case ACPI_REGISTER_PM1_STATUS: /* 16-bit access */ 737*3446Smrj 738*3446Smrj /* Perform a read first to preserve certain bits (per ACPI spec) */ 739*3446Smrj 740*3446Smrj Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, 741*3446Smrj ACPI_REGISTER_PM1_STATUS, &ReadValue); 742*3446Smrj if (ACPI_FAILURE (Status)) 743*3446Smrj { 744*3446Smrj goto UnlockAndExit; 745*3446Smrj } 746*3446Smrj 747*3446Smrj /* Insert the bits to be preserved */ 748*3446Smrj 749*3446Smrj ACPI_INSERT_BITS (Value, ACPI_PM1_STATUS_PRESERVED_BITS, ReadValue); 750*3446Smrj 751*3446Smrj /* Now we can write the data */ 752*3446Smrj 753*3446Smrj Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1aEvtBlk); 754*3446Smrj if (ACPI_FAILURE (Status)) 755*3446Smrj { 756*3446Smrj goto UnlockAndExit; 757*3446Smrj } 758*3446Smrj 759*3446Smrj /* PM1B is optional */ 760*3446Smrj 761*3446Smrj Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1bEvtBlk); 762*3446Smrj break; 763*3446Smrj 764*3446Smrj 765*3446Smrj case ACPI_REGISTER_PM1_ENABLE: /* 16-bit access */ 766*3446Smrj 767*3446Smrj Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_XPm1aEnable); 768*3446Smrj if (ACPI_FAILURE (Status)) 769*3446Smrj { 770*3446Smrj goto UnlockAndExit; 771*3446Smrj } 772*3446Smrj 773*3446Smrj /* PM1B is optional */ 774*3446Smrj 775*3446Smrj Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_XPm1bEnable); 776*3446Smrj break; 777*3446Smrj 778*3446Smrj 779*3446Smrj case ACPI_REGISTER_PM1_CONTROL: /* 16-bit access */ 780*3446Smrj 781*3446Smrj /* 782*3446Smrj * Perform a read first to preserve certain bits (per ACPI spec) 783*3446Smrj * 784*3446Smrj * Note: This includes SCI_EN, we never want to change this bit 785*3446Smrj */ 786*3446Smrj Status = AcpiHwRegisterRead (ACPI_MTX_DO_NOT_LOCK, 787*3446Smrj ACPI_REGISTER_PM1_CONTROL, &ReadValue); 788*3446Smrj if (ACPI_FAILURE (Status)) 789*3446Smrj { 790*3446Smrj goto UnlockAndExit; 791*3446Smrj } 792*3446Smrj 793*3446Smrj /* Insert the bits to be preserved */ 794*3446Smrj 795*3446Smrj ACPI_INSERT_BITS (Value, ACPI_PM1_CONTROL_PRESERVED_BITS, ReadValue); 796*3446Smrj 797*3446Smrj /* Now we can write the data */ 798*3446Smrj 799*3446Smrj Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1aCntBlk); 800*3446Smrj if (ACPI_FAILURE (Status)) 801*3446Smrj { 802*3446Smrj goto UnlockAndExit; 803*3446Smrj } 804*3446Smrj 805*3446Smrj Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1bCntBlk); 806*3446Smrj break; 807*3446Smrj 808*3446Smrj 809*3446Smrj case ACPI_REGISTER_PM1A_CONTROL: /* 16-bit access */ 810*3446Smrj 811*3446Smrj Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1aCntBlk); 812*3446Smrj break; 813*3446Smrj 814*3446Smrj 815*3446Smrj case ACPI_REGISTER_PM1B_CONTROL: /* 16-bit access */ 816*3446Smrj 817*3446Smrj Status = AcpiHwLowLevelWrite (16, Value, &AcpiGbl_FADT->XPm1bCntBlk); 818*3446Smrj break; 819*3446Smrj 820*3446Smrj 821*3446Smrj case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ 822*3446Smrj 823*3446Smrj Status = AcpiHwLowLevelWrite (8, Value, &AcpiGbl_FADT->XPm2CntBlk); 824*3446Smrj break; 825*3446Smrj 826*3446Smrj 827*3446Smrj case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ 828*3446Smrj 829*3446Smrj Status = AcpiHwLowLevelWrite (32, Value, &AcpiGbl_FADT->XPmTmrBlk); 830*3446Smrj break; 831*3446Smrj 832*3446Smrj 833*3446Smrj case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ 834*3446Smrj 835*3446Smrj /* SMI_CMD is currently always in IO space */ 836*3446Smrj 837*3446Smrj Status = AcpiOsWritePort (AcpiGbl_FADT->SmiCmd, Value, 8); 838*3446Smrj break; 839*3446Smrj 840*3446Smrj 841*3446Smrj default: 842*3446Smrj Status = AE_BAD_PARAMETER; 843*3446Smrj break; 844*3446Smrj } 845*3446Smrj 846*3446Smrj UnlockAndExit: 847*3446Smrj if (ACPI_MTX_LOCK == UseLock) 848*3446Smrj { 849*3446Smrj AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags); 850*3446Smrj } 851*3446Smrj 852*3446Smrj return_ACPI_STATUS (Status); 853*3446Smrj } 854*3446Smrj 855*3446Smrj 856*3446Smrj /****************************************************************************** 857*3446Smrj * 858*3446Smrj * FUNCTION: AcpiHwLowLevelRead 859*3446Smrj * 860*3446Smrj * PARAMETERS: Width - 8, 16, or 32 861*3446Smrj * Value - Where the value is returned 862*3446Smrj * Reg - GAS register structure 863*3446Smrj * 864*3446Smrj * RETURN: Status 865*3446Smrj * 866*3446Smrj * DESCRIPTION: Read from either memory or IO space. 867*3446Smrj * 868*3446Smrj ******************************************************************************/ 869*3446Smrj 870*3446Smrj ACPI_STATUS 871*3446Smrj AcpiHwLowLevelRead ( 872*3446Smrj UINT32 Width, 873*3446Smrj UINT32 *Value, 874*3446Smrj ACPI_GENERIC_ADDRESS *Reg) 875*3446Smrj { 876*3446Smrj UINT64 Address; 877*3446Smrj ACPI_STATUS Status; 878*3446Smrj 879*3446Smrj 880*3446Smrj ACPI_FUNCTION_NAME (HwLowLevelRead); 881*3446Smrj 882*3446Smrj 883*3446Smrj /* 884*3446Smrj * Must have a valid pointer to a GAS structure, and 885*3446Smrj * a non-zero address within. However, don't return an error 886*3446Smrj * because the PM1A/B code must not fail if B isn't present. 887*3446Smrj */ 888*3446Smrj if (!Reg) 889*3446Smrj { 890*3446Smrj return (AE_OK); 891*3446Smrj } 892*3446Smrj 893*3446Smrj /* Get a local copy of the address. Handles possible alignment issues */ 894*3446Smrj 895*3446Smrj ACPI_MOVE_64_TO_64 (&Address, &Reg->Address); 896*3446Smrj if (!ACPI_VALID_ADDRESS (Address)) 897*3446Smrj { 898*3446Smrj return (AE_OK); 899*3446Smrj } 900*3446Smrj *Value = 0; 901*3446Smrj 902*3446Smrj /* 903*3446Smrj * Two address spaces supported: Memory or IO. 904*3446Smrj * PCI_Config is not supported here because the GAS struct is insufficient 905*3446Smrj */ 906*3446Smrj switch (Reg->AddressSpaceId) 907*3446Smrj { 908*3446Smrj case ACPI_ADR_SPACE_SYSTEM_MEMORY: 909*3446Smrj 910*3446Smrj Status = AcpiOsReadMemory ( 911*3446Smrj (ACPI_PHYSICAL_ADDRESS) ACPI_GET_ADDRESS (Address), 912*3446Smrj Value, Width); 913*3446Smrj break; 914*3446Smrj 915*3446Smrj 916*3446Smrj case ACPI_ADR_SPACE_SYSTEM_IO: 917*3446Smrj 918*3446Smrj Status = AcpiOsReadPort ((ACPI_IO_ADDRESS) ACPI_GET_ADDRESS (Address), 919*3446Smrj Value, Width); 920*3446Smrj break; 921*3446Smrj 922*3446Smrj 923*3446Smrj default: 924*3446Smrj ACPI_ERROR ((AE_INFO, 925*3446Smrj "Unsupported address space: %X", Reg->AddressSpaceId)); 926*3446Smrj return (AE_BAD_PARAMETER); 927*3446Smrj } 928*3446Smrj 929*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_IO, 930*3446Smrj "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", 931*3446Smrj *Value, Width, 932*3446Smrj ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (Address)), 933*3446Smrj AcpiUtGetRegionName (Reg->AddressSpaceId))); 934*3446Smrj 935*3446Smrj return (Status); 936*3446Smrj } 937*3446Smrj 938*3446Smrj 939*3446Smrj /****************************************************************************** 940*3446Smrj * 941*3446Smrj * FUNCTION: AcpiHwLowLevelWrite 942*3446Smrj * 943*3446Smrj * PARAMETERS: Width - 8, 16, or 32 944*3446Smrj * Value - To be written 945*3446Smrj * Reg - GAS register structure 946*3446Smrj * 947*3446Smrj * RETURN: Status 948*3446Smrj * 949*3446Smrj * DESCRIPTION: Write to either memory or IO space. 950*3446Smrj * 951*3446Smrj ******************************************************************************/ 952*3446Smrj 953*3446Smrj ACPI_STATUS 954*3446Smrj AcpiHwLowLevelWrite ( 955*3446Smrj UINT32 Width, 956*3446Smrj UINT32 Value, 957*3446Smrj ACPI_GENERIC_ADDRESS *Reg) 958*3446Smrj { 959*3446Smrj UINT64 Address; 960*3446Smrj ACPI_STATUS Status; 961*3446Smrj 962*3446Smrj 963*3446Smrj ACPI_FUNCTION_NAME (HwLowLevelWrite); 964*3446Smrj 965*3446Smrj 966*3446Smrj /* 967*3446Smrj * Must have a valid pointer to a GAS structure, and 968*3446Smrj * a non-zero address within. However, don't return an error 969*3446Smrj * because the PM1A/B code must not fail if B isn't present. 970*3446Smrj */ 971*3446Smrj if (!Reg) 972*3446Smrj { 973*3446Smrj return (AE_OK); 974*3446Smrj } 975*3446Smrj 976*3446Smrj /* Get a local copy of the address. Handles possible alignment issues */ 977*3446Smrj 978*3446Smrj ACPI_MOVE_64_TO_64 (&Address, &Reg->Address); 979*3446Smrj if (!ACPI_VALID_ADDRESS (Address)) 980*3446Smrj { 981*3446Smrj return (AE_OK); 982*3446Smrj } 983*3446Smrj 984*3446Smrj /* 985*3446Smrj * Two address spaces supported: Memory or IO. 986*3446Smrj * PCI_Config is not supported here because the GAS struct is insufficient 987*3446Smrj */ 988*3446Smrj switch (Reg->AddressSpaceId) 989*3446Smrj { 990*3446Smrj case ACPI_ADR_SPACE_SYSTEM_MEMORY: 991*3446Smrj 992*3446Smrj Status = AcpiOsWriteMemory ( 993*3446Smrj (ACPI_PHYSICAL_ADDRESS) ACPI_GET_ADDRESS (Address), 994*3446Smrj Value, Width); 995*3446Smrj break; 996*3446Smrj 997*3446Smrj 998*3446Smrj case ACPI_ADR_SPACE_SYSTEM_IO: 999*3446Smrj 1000*3446Smrj Status = AcpiOsWritePort ((ACPI_IO_ADDRESS) ACPI_GET_ADDRESS (Address), 1001*3446Smrj Value, Width); 1002*3446Smrj break; 1003*3446Smrj 1004*3446Smrj 1005*3446Smrj default: 1006*3446Smrj ACPI_ERROR ((AE_INFO, 1007*3446Smrj "Unsupported address space: %X", Reg->AddressSpaceId)); 1008*3446Smrj return (AE_BAD_PARAMETER); 1009*3446Smrj } 1010*3446Smrj 1011*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_IO, 1012*3446Smrj "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", 1013*3446Smrj Value, Width, 1014*3446Smrj ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (Address)), 1015*3446Smrj AcpiUtGetRegionName (Reg->AddressSpaceId))); 1016*3446Smrj 1017*3446Smrj return (Status); 1018*3446Smrj } 1019