2 /******************************************************************************
4 * Module Name: hwxface - Public ACPICA hardware interfaces
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2009, 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 *****************************************************************************/
117 #include <contrib/dev/acpica/include/acpi.h>
118 #include <contrib/dev/acpica/include/accommon.h>
119 #include <contrib/dev/acpica/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 /* Write the reset value to the reset register */
162 Status = AcpiWrite (AcpiGbl_FADT.ResetValue, ResetReg);
163 return_ACPI_STATUS (Status);
166 ACPI_EXPORT_SYMBOL (AcpiReset)
169 /******************************************************************************
173 * PARAMETERS: Value - Where the value is returned
174 * Reg - GAS register structure
178 * DESCRIPTION: Read from either memory or IO space.
180 ******************************************************************************/
185 ACPI_GENERIC_ADDRESS *Reg)
192 ACPI_FUNCTION_NAME (AcpiRead);
196 * Must have a valid pointer to a GAS structure, and a non-zero address
201 return (AE_BAD_PARAMETER);
204 /* Get a local copy of the address. Handles possible alignment issues */
206 ACPI_MOVE_64_TO_64 (&Address, &Reg->Address);
209 return (AE_BAD_ADDRESS);
212 /* Supported widths are 8/16/32 */
214 Width = Reg->BitWidth;
215 if ((Width != 8) && (Width != 16) && (Width != 32))
220 /* Initialize entire 32-bit return value to zero */
225 * Two address spaces supported: Memory or IO. PCI_Config is
226 * not supported here because the GAS structure is insufficient
228 switch (Reg->SpaceId)
230 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
232 Status = AcpiOsReadMemory (
233 (ACPI_PHYSICAL_ADDRESS) Address, Value, Width);
237 case ACPI_ADR_SPACE_SYSTEM_IO:
239 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address, Value, Width);
244 ACPI_ERROR ((AE_INFO,
245 "Unsupported address space: %X", Reg->SpaceId));
246 return (AE_BAD_PARAMETER);
249 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
250 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
251 *Value, Width, ACPI_FORMAT_UINT64 (Address),
252 AcpiUtGetRegionName (Reg->SpaceId)));
257 ACPI_EXPORT_SYMBOL (AcpiRead)
260 /******************************************************************************
262 * FUNCTION: AcpiWrite
264 * PARAMETERS: Value - To be written
265 * Reg - GAS register structure
269 * DESCRIPTION: Write to either memory or IO space.
271 ******************************************************************************/
276 ACPI_GENERIC_ADDRESS *Reg)
283 ACPI_FUNCTION_NAME (AcpiWrite);
287 * Must have a valid pointer to a GAS structure, and a non-zero address
292 return (AE_BAD_PARAMETER);
295 /* Get a local copy of the address. Handles possible alignment issues */
297 ACPI_MOVE_64_TO_64 (&Address, &Reg->Address);
300 return (AE_BAD_ADDRESS);
303 /* Supported widths are 8/16/32 */
305 Width = Reg->BitWidth;
306 if ((Width != 8) && (Width != 16) && (Width != 32))
312 * Two address spaces supported: Memory or IO.
313 * PCI_Config is not supported here because the GAS struct is insufficient
315 switch (Reg->SpaceId)
317 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
319 Status = AcpiOsWriteMemory (
320 (ACPI_PHYSICAL_ADDRESS) Address, Value, Width);
324 case ACPI_ADR_SPACE_SYSTEM_IO:
326 Status = AcpiHwWritePort (
327 (ACPI_IO_ADDRESS) Address, Value, Width);
332 ACPI_ERROR ((AE_INFO,
333 "Unsupported address space: %X", Reg->SpaceId));
334 return (AE_BAD_PARAMETER);
337 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
338 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
339 Value, Width, ACPI_FORMAT_UINT64 (Address),
340 AcpiUtGetRegionName (Reg->SpaceId)));
345 ACPI_EXPORT_SYMBOL (AcpiWrite)
348 /*******************************************************************************
350 * FUNCTION: AcpiReadBitRegister
352 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
353 * ReturnValue - Value that was read from the register,
354 * normalized to bit position zero.
356 * RETURN: Status and the value read from the specified Register. Value
357 * returned is normalized to bit0 (is shifted all the way right)
359 * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
361 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
364 * Note: The hardware lock is not required when reading the ACPI bit registers
365 * since almost all of them are single bit and it does not matter that
366 * the parent hardware register can be split across two physical
367 * registers. The only multi-bit field is SLP_TYP in the PM1 control
368 * register, but this field does not cross an 8-bit boundary (nor does
369 * it make much sense to actually read this field.)
371 ******************************************************************************/
374 AcpiReadBitRegister (
378 ACPI_BIT_REGISTER_INFO *BitRegInfo;
379 UINT32 RegisterValue;
384 ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister, RegisterId);
387 /* Get the info structure corresponding to the requested ACPI Register */
389 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
392 return_ACPI_STATUS (AE_BAD_PARAMETER);
395 /* Read the entire parent register */
397 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
399 if (ACPI_FAILURE (Status))
401 return_ACPI_STATUS (Status);
404 /* Normalize the value that was read, mask off other bits */
406 Value = ((RegisterValue & BitRegInfo->AccessBitMask)
407 >> BitRegInfo->BitPosition);
409 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
410 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
411 RegisterId, BitRegInfo->ParentRegister, RegisterValue, Value));
413 *ReturnValue = Value;
414 return_ACPI_STATUS (AE_OK);
417 ACPI_EXPORT_SYMBOL (AcpiReadBitRegister)
420 /*******************************************************************************
422 * FUNCTION: AcpiWriteBitRegister
424 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
425 * Value - Value to write to the register, in bit
426 * position zero. The bit is automaticallly
427 * shifted to the correct position.
431 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
432 * since most operations require a read/modify/write sequence.
434 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
437 * Note that at this level, the fact that there may be actually two
438 * hardware registers (A and B - and B may not exist) is abstracted.
440 ******************************************************************************/
443 AcpiWriteBitRegister (
447 ACPI_BIT_REGISTER_INFO *BitRegInfo;
448 ACPI_CPU_FLAGS LockFlags;
449 UINT32 RegisterValue;
450 ACPI_STATUS Status = AE_OK;
453 ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister, RegisterId);
456 /* Get the info structure corresponding to the requested ACPI Register */
458 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
461 return_ACPI_STATUS (AE_BAD_PARAMETER);
464 LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock);
467 * At this point, we know that the parent register is one of the
468 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
470 if (BitRegInfo->ParentRegister != ACPI_REGISTER_PM1_STATUS)
473 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
475 * Perform a register read to preserve the bits that we are not
478 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
480 if (ACPI_FAILURE (Status))
486 * Insert the input bit into the value that was just read
487 * and write the register
489 ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
490 BitRegInfo->AccessBitMask, Value);
492 Status = AcpiHwRegisterWrite (BitRegInfo->ParentRegister,
498 * 2) Case for PM1 Status
500 * The Status register is different from the rest. Clear an event
501 * by writing 1, writing 0 has no effect. So, the only relevant
502 * information is the single bit we're interested in, all others
503 * should be written as 0 so they will be left unchanged.
505 RegisterValue = ACPI_REGISTER_PREPARE_BITS (Value,
506 BitRegInfo->BitPosition, BitRegInfo->AccessBitMask);
508 /* No need to write the register if value is all zeros */
512 Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS,
517 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
518 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
519 RegisterId, BitRegInfo->ParentRegister, Value, RegisterValue));
524 AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags);
525 return_ACPI_STATUS (Status);
528 ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister)
531 /*******************************************************************************
533 * FUNCTION: AcpiGetSleepTypeData
535 * PARAMETERS: SleepState - Numeric sleep state
536 * *SleepTypeA - Where SLP_TYPa is returned
537 * *SleepTypeB - Where SLP_TYPb is returned
539 * RETURN: Status - ACPI status
541 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
544 ******************************************************************************/
547 AcpiGetSleepTypeData (
552 ACPI_STATUS Status = AE_OK;
553 ACPI_EVALUATE_INFO *Info;
556 ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData);
559 /* Validate parameters */
561 if ((SleepState > ACPI_S_STATES_MAX) ||
565 return_ACPI_STATUS (AE_BAD_PARAMETER);
568 /* Allocate the evaluation information block */
570 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
573 return_ACPI_STATUS (AE_NO_MEMORY);
576 Info->Pathname = ACPI_CAST_PTR (char, AcpiGbl_SleepStateNames[SleepState]);
578 /* Evaluate the namespace object containing the values for this state */
580 Status = AcpiNsEvaluate (Info);
581 if (ACPI_FAILURE (Status))
583 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
584 "%s while evaluating SleepState [%s]\n",
585 AcpiFormatException (Status), Info->Pathname));
590 /* Must have a return object */
592 if (!Info->ReturnObject)
594 ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
596 Status = AE_NOT_EXIST;
599 /* It must be of type Package */
601 else if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
603 ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
604 Status = AE_AML_OPERAND_TYPE;
608 * The package must have at least two elements. NOTE (March 2005): This
609 * goes against the current ACPI spec which defines this object as a
610 * package with one encoded DWORD element. However, existing practice
611 * by BIOS vendors seems to be to have 2 or more elements, at least
612 * one per sleep type (A/B).
614 else if (Info->ReturnObject->Package.Count < 2)
616 ACPI_ERROR ((AE_INFO,
617 "Sleep State return package does not have at least two elements"));
618 Status = AE_AML_NO_OPERAND;
621 /* The first two elements must both be of type Integer */
623 else if (((Info->ReturnObject->Package.Elements[0])->Common.Type
624 != ACPI_TYPE_INTEGER) ||
625 ((Info->ReturnObject->Package.Elements[1])->Common.Type
626 != ACPI_TYPE_INTEGER))
628 ACPI_ERROR ((AE_INFO,
629 "Sleep State return package elements are not both Integers "
631 AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[0]),
632 AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[1])));
633 Status = AE_AML_OPERAND_TYPE;
637 /* Valid _Sx_ package size, type, and value */
639 *SleepTypeA = (UINT8)
640 (Info->ReturnObject->Package.Elements[0])->Integer.Value;
641 *SleepTypeB = (UINT8)
642 (Info->ReturnObject->Package.Elements[1])->Integer.Value;
645 if (ACPI_FAILURE (Status))
647 ACPI_EXCEPTION ((AE_INFO, Status,
648 "While evaluating SleepState [%s], bad Sleep object %p type %s",
649 Info->Pathname, Info->ReturnObject,
650 AcpiUtGetObjectTypeName (Info->ReturnObject)));
653 AcpiUtRemoveReference (Info->ReturnObject);
657 return_ACPI_STATUS (Status);
660 ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData)