2 /******************************************************************************
4 * Module Name: hwxface - Public ACPICA hardware interfaces
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 * All rights reserved.
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
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
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;
38 * The above copyright and patent license is granted only if the following
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.
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
81 * 4. Disclaimer and Export Compliance
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
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
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.
115 *****************************************************************************/
118 #include "accommon.h"
119 #include "acnamesp.h"
121 #define _COMPONENT ACPI_HARDWARE
122 ACPI_MODULE_NAME ("hwxface")
125 /******************************************************************************
127 * FUNCTION: AcpiReset
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.
137 ******************************************************************************/
143 ACPI_GENERIC_ADDRESS
*ResetReg
;
147 ACPI_FUNCTION_TRACE (AcpiReset
);
150 ResetReg
= &AcpiGbl_FADT
.ResetRegister
;
152 /* Check if the reset register is supported */
154 if (!(AcpiGbl_FADT
.Flags
& ACPI_FADT_RESET_REGISTER
) ||
157 return_ACPI_STATUS (AE_NOT_EXIST
);
160 if (ResetReg
->SpaceId
== ACPI_ADR_SPACE_SYSTEM_IO
)
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
167 Status
= AcpiOsWritePort ((ACPI_IO_ADDRESS
) ResetReg
->Address
,
168 AcpiGbl_FADT
.ResetValue
, ResetReg
->BitWidth
);
172 /* Write the reset value to the reset register */
174 Status
= AcpiHwWrite (AcpiGbl_FADT
.ResetValue
, ResetReg
);
177 return_ACPI_STATUS (Status
);
180 ACPI_EXPORT_SYMBOL (AcpiReset
)
183 /******************************************************************************
187 * PARAMETERS: Value - Where the value is returned
188 * Reg - GAS register structure
192 * DESCRIPTION: Read from either memory or IO space.
194 * LIMITATIONS: <These limitations also apply to AcpiWrite>
195 * BitWidth must be exactly 8, 16, 32, or 64.
196 * SpaceID must be SystemMemory or SystemIO.
197 * BitOffset and AccessWidth are currently ignored, as there has
198 * not been a need to implement these.
200 ******************************************************************************/
205 ACPI_GENERIC_ADDRESS
*Reg
)
213 ACPI_FUNCTION_NAME (AcpiRead
);
218 return (AE_BAD_PARAMETER
);
221 /* Validate contents of the GAS register. Allow 64-bit transfers */
223 Status
= AcpiHwValidateRegister (Reg
, 64, &Address
);
224 if (ACPI_FAILURE (Status
))
229 Width
= Reg
->BitWidth
;
232 Width
= 32; /* Break into two 32-bit transfers */
235 /* Initialize entire 64-bit return value to zero */
241 * Two address spaces supported: Memory or IO. PCI_Config is
242 * not supported here because the GAS structure is insufficient
244 if (Reg
->SpaceId
== ACPI_ADR_SPACE_SYSTEM_MEMORY
)
246 Status
= AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS
)
247 Address
, &Value
, Width
);
248 if (ACPI_FAILURE (Status
))
252 *ReturnValue
= Value
;
254 if (Reg
->BitWidth
== 64)
256 /* Read the top 32 bits */
258 Status
= AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS
)
259 (Address
+ 4), &Value
, 32);
260 if (ACPI_FAILURE (Status
))
264 *ReturnValue
|= ((UINT64
) Value
<< 32);
267 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
269 Status
= AcpiHwReadPort ((ACPI_IO_ADDRESS
)
270 Address
, &Value
, Width
);
271 if (ACPI_FAILURE (Status
))
275 *ReturnValue
= Value
;
277 if (Reg
->BitWidth
== 64)
279 /* Read the top 32 bits */
281 Status
= AcpiHwReadPort ((ACPI_IO_ADDRESS
)
282 (Address
+ 4), &Value
, 32);
283 if (ACPI_FAILURE (Status
))
287 *ReturnValue
|= ((UINT64
) Value
<< 32);
291 ACPI_DEBUG_PRINT ((ACPI_DB_IO
,
292 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
293 ACPI_FORMAT_UINT64 (*ReturnValue
), Reg
->BitWidth
,
294 ACPI_FORMAT_UINT64 (Address
),
295 AcpiUtGetRegionName (Reg
->SpaceId
)));
300 ACPI_EXPORT_SYMBOL (AcpiRead
)
303 /******************************************************************************
305 * FUNCTION: AcpiWrite
307 * PARAMETERS: Value - Value to be written
308 * Reg - GAS register structure
312 * DESCRIPTION: Write to either memory or IO space.
314 ******************************************************************************/
319 ACPI_GENERIC_ADDRESS
*Reg
)
326 ACPI_FUNCTION_NAME (AcpiWrite
);
329 /* Validate contents of the GAS register. Allow 64-bit transfers */
331 Status
= AcpiHwValidateRegister (Reg
, 64, &Address
);
332 if (ACPI_FAILURE (Status
))
337 Width
= Reg
->BitWidth
;
340 Width
= 32; /* Break into two 32-bit transfers */
344 * Two address spaces supported: Memory or IO. PCI_Config is
345 * not supported here because the GAS structure is insufficient
347 if (Reg
->SpaceId
== ACPI_ADR_SPACE_SYSTEM_MEMORY
)
349 Status
= AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS
)
350 Address
, ACPI_LODWORD (Value
), Width
);
351 if (ACPI_FAILURE (Status
))
356 if (Reg
->BitWidth
== 64)
358 Status
= AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS
)
359 (Address
+ 4), ACPI_HIDWORD (Value
), 32);
360 if (ACPI_FAILURE (Status
))
366 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
368 Status
= AcpiHwWritePort ((ACPI_IO_ADDRESS
)
369 Address
, ACPI_LODWORD (Value
), Width
);
370 if (ACPI_FAILURE (Status
))
375 if (Reg
->BitWidth
== 64)
377 Status
= AcpiHwWritePort ((ACPI_IO_ADDRESS
)
378 (Address
+ 4), ACPI_HIDWORD (Value
), 32);
379 if (ACPI_FAILURE (Status
))
386 ACPI_DEBUG_PRINT ((ACPI_DB_IO
,
387 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
388 ACPI_FORMAT_UINT64 (Value
), Reg
->BitWidth
,
389 ACPI_FORMAT_UINT64 (Address
),
390 AcpiUtGetRegionName (Reg
->SpaceId
)));
395 ACPI_EXPORT_SYMBOL (AcpiWrite
)
398 /*******************************************************************************
400 * FUNCTION: AcpiReadBitRegister
402 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
403 * ReturnValue - Value that was read from the register,
404 * normalized to bit position zero.
406 * RETURN: Status and the value read from the specified Register. Value
407 * returned is normalized to bit0 (is shifted all the way right)
409 * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
411 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
414 * Note: The hardware lock is not required when reading the ACPI bit registers
415 * since almost all of them are single bit and it does not matter that
416 * the parent hardware register can be split across two physical
417 * registers. The only multi-bit field is SLP_TYP in the PM1 control
418 * register, but this field does not cross an 8-bit boundary (nor does
419 * it make much sense to actually read this field.)
421 ******************************************************************************/
424 AcpiReadBitRegister (
428 ACPI_BIT_REGISTER_INFO
*BitRegInfo
;
429 UINT32 RegisterValue
;
434 ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister
, RegisterId
);
437 /* Get the info structure corresponding to the requested ACPI Register */
439 BitRegInfo
= AcpiHwGetBitRegisterInfo (RegisterId
);
442 return_ACPI_STATUS (AE_BAD_PARAMETER
);
445 /* Read the entire parent register */
447 Status
= AcpiHwRegisterRead (BitRegInfo
->ParentRegister
,
449 if (ACPI_FAILURE (Status
))
451 return_ACPI_STATUS (Status
);
454 /* Normalize the value that was read, mask off other bits */
456 Value
= ((RegisterValue
& BitRegInfo
->AccessBitMask
)
457 >> BitRegInfo
->BitPosition
);
459 ACPI_DEBUG_PRINT ((ACPI_DB_IO
,
460 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
461 RegisterId
, BitRegInfo
->ParentRegister
, RegisterValue
, Value
));
463 *ReturnValue
= Value
;
464 return_ACPI_STATUS (AE_OK
);
467 ACPI_EXPORT_SYMBOL (AcpiReadBitRegister
)
470 /*******************************************************************************
472 * FUNCTION: AcpiWriteBitRegister
474 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
475 * Value - Value to write to the register, in bit
476 * position zero. The bit is automaticallly
477 * shifted to the correct position.
481 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
482 * since most operations require a read/modify/write sequence.
484 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
487 * Note that at this level, the fact that there may be actually two
488 * hardware registers (A and B - and B may not exist) is abstracted.
490 ******************************************************************************/
493 AcpiWriteBitRegister (
497 ACPI_BIT_REGISTER_INFO
*BitRegInfo
;
498 ACPI_CPU_FLAGS LockFlags
;
499 UINT32 RegisterValue
;
500 ACPI_STATUS Status
= AE_OK
;
503 ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister
, RegisterId
);
506 /* Get the info structure corresponding to the requested ACPI Register */
508 BitRegInfo
= AcpiHwGetBitRegisterInfo (RegisterId
);
511 return_ACPI_STATUS (AE_BAD_PARAMETER
);
514 LockFlags
= AcpiOsAcquireLock (AcpiGbl_HardwareLock
);
517 * At this point, we know that the parent register is one of the
518 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
520 if (BitRegInfo
->ParentRegister
!= ACPI_REGISTER_PM1_STATUS
)
523 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
525 * Perform a register read to preserve the bits that we are not
528 Status
= AcpiHwRegisterRead (BitRegInfo
->ParentRegister
,
530 if (ACPI_FAILURE (Status
))
536 * Insert the input bit into the value that was just read
537 * and write the register
539 ACPI_REGISTER_INSERT_VALUE (RegisterValue
, BitRegInfo
->BitPosition
,
540 BitRegInfo
->AccessBitMask
, Value
);
542 Status
= AcpiHwRegisterWrite (BitRegInfo
->ParentRegister
,
548 * 2) Case for PM1 Status
550 * The Status register is different from the rest. Clear an event
551 * by writing 1, writing 0 has no effect. So, the only relevant
552 * information is the single bit we're interested in, all others
553 * should be written as 0 so they will be left unchanged.
555 RegisterValue
= ACPI_REGISTER_PREPARE_BITS (Value
,
556 BitRegInfo
->BitPosition
, BitRegInfo
->AccessBitMask
);
558 /* No need to write the register if value is all zeros */
562 Status
= AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS
,
567 ACPI_DEBUG_PRINT ((ACPI_DB_IO
,
568 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
569 RegisterId
, BitRegInfo
->ParentRegister
, Value
, RegisterValue
));
574 AcpiOsReleaseLock (AcpiGbl_HardwareLock
, LockFlags
);
575 return_ACPI_STATUS (Status
);
578 ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister
)
581 /*******************************************************************************
583 * FUNCTION: AcpiGetSleepTypeData
585 * PARAMETERS: SleepState - Numeric sleep state
586 * *SleepTypeA - Where SLP_TYPa is returned
587 * *SleepTypeB - Where SLP_TYPb is returned
589 * RETURN: Status - ACPI status
591 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
594 ******************************************************************************/
597 AcpiGetSleepTypeData (
602 ACPI_STATUS Status
= AE_OK
;
603 ACPI_EVALUATE_INFO
*Info
;
606 ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData
);
609 /* Validate parameters */
611 if ((SleepState
> ACPI_S_STATES_MAX
) ||
615 return_ACPI_STATUS (AE_BAD_PARAMETER
);
618 /* Allocate the evaluation information block */
620 Info
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO
));
623 return_ACPI_STATUS (AE_NO_MEMORY
);
626 Info
->Pathname
= ACPI_CAST_PTR (char, AcpiGbl_SleepStateNames
[SleepState
]);
628 /* Evaluate the namespace object containing the values for this state */
630 Status
= AcpiNsEvaluate (Info
);
631 if (ACPI_FAILURE (Status
))
633 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
634 "%s while evaluating SleepState [%s]\n",
635 AcpiFormatException (Status
), Info
->Pathname
));
640 /* Must have a return object */
642 if (!Info
->ReturnObject
)
644 ACPI_ERROR ((AE_INFO
, "No Sleep State object returned from [%s]",
646 Status
= AE_NOT_EXIST
;
649 /* It must be of type Package */
651 else if (Info
->ReturnObject
->Common
.Type
!= ACPI_TYPE_PACKAGE
)
653 ACPI_ERROR ((AE_INFO
, "Sleep State return object is not a Package"));
654 Status
= AE_AML_OPERAND_TYPE
;
658 * The package must have at least two elements. NOTE (March 2005): This
659 * goes against the current ACPI spec which defines this object as a
660 * package with one encoded DWORD element. However, existing practice
661 * by BIOS vendors seems to be to have 2 or more elements, at least
662 * one per sleep type (A/B).
664 else if (Info
->ReturnObject
->Package
.Count
< 2)
666 ACPI_ERROR ((AE_INFO
,
667 "Sleep State return package does not have at least two elements"));
668 Status
= AE_AML_NO_OPERAND
;
671 /* The first two elements must both be of type Integer */
673 else if (((Info
->ReturnObject
->Package
.Elements
[0])->Common
.Type
674 != ACPI_TYPE_INTEGER
) ||
675 ((Info
->ReturnObject
->Package
.Elements
[1])->Common
.Type
676 != ACPI_TYPE_INTEGER
))
678 ACPI_ERROR ((AE_INFO
,
679 "Sleep State return package elements are not both Integers "
681 AcpiUtGetObjectTypeName (Info
->ReturnObject
->Package
.Elements
[0]),
682 AcpiUtGetObjectTypeName (Info
->ReturnObject
->Package
.Elements
[1])));
683 Status
= AE_AML_OPERAND_TYPE
;
687 /* Valid _Sx_ package size, type, and value */
689 *SleepTypeA
= (UINT8
)
690 (Info
->ReturnObject
->Package
.Elements
[0])->Integer
.Value
;
691 *SleepTypeB
= (UINT8
)
692 (Info
->ReturnObject
->Package
.Elements
[1])->Integer
.Value
;
695 if (ACPI_FAILURE (Status
))
697 ACPI_EXCEPTION ((AE_INFO
, Status
,
698 "While evaluating SleepState [%s], bad Sleep object %p type %s",
699 Info
->Pathname
, Info
->ReturnObject
,
700 AcpiUtGetObjectTypeName (Info
->ReturnObject
)));
703 AcpiUtRemoveReference (Info
->ReturnObject
);
707 return_ACPI_STATUS (Status
);
710 ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData
)