2 /******************************************************************************
4 * Module Name: hwxface - Public ACPICA hardware interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acnamesp.h>
49 #define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwxface")
53 /******************************************************************************
61 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
62 * support reset register in PCI config space, this must be
65 ******************************************************************************/
71 ACPI_GENERIC_ADDRESS *ResetReg;
75 ACPI_FUNCTION_TRACE (AcpiReset);
78 ResetReg = &AcpiGbl_FADT.ResetRegister;
80 /* Check if the reset register is supported */
82 if (!(AcpiGbl_FADT.Flags & ACPI_FADT_RESET_REGISTER) ||
85 return_ACPI_STATUS (AE_NOT_EXIST);
88 if (ResetReg->SpaceId == ACPI_ADR_SPACE_SYSTEM_IO)
91 * For I/O space, write directly to the OSL. This bypasses the port
92 * validation mechanism, which may block a valid write to the reset
95 Status = AcpiOsWritePort ((ACPI_IO_ADDRESS) ResetReg->Address,
96 AcpiGbl_FADT.ResetValue, ResetReg->BitWidth);
100 /* Write the reset value to the reset register */
102 Status = AcpiHwWrite (AcpiGbl_FADT.ResetValue, ResetReg);
105 return_ACPI_STATUS (Status);
108 ACPI_EXPORT_SYMBOL (AcpiReset)
111 /******************************************************************************
115 * PARAMETERS: Value - Where the value is returned
116 * Reg - GAS register structure
120 * DESCRIPTION: Read from either memory or IO space.
122 * LIMITATIONS: <These limitations also apply to AcpiWrite>
123 * BitWidth must be exactly 8, 16, 32, or 64.
124 * SpaceID must be SystemMemory or SystemIO.
125 * BitOffset and AccessWidth are currently ignored, as there has
126 * not been a need to implement these.
128 ******************************************************************************/
133 ACPI_GENERIC_ADDRESS *Reg)
141 ACPI_FUNCTION_NAME (AcpiRead);
146 return (AE_BAD_PARAMETER);
149 /* Validate contents of the GAS register. Allow 64-bit transfers */
151 Status = AcpiHwValidateRegister (Reg, 64, &Address);
152 if (ACPI_FAILURE (Status))
157 Width = Reg->BitWidth;
160 Width = 32; /* Break into two 32-bit transfers */
163 /* Initialize entire 64-bit return value to zero */
169 * Two address spaces supported: Memory or IO. PCI_Config is
170 * not supported here because the GAS structure is insufficient
172 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
174 Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
175 Address, &Value, Width);
176 if (ACPI_FAILURE (Status))
180 *ReturnValue = Value;
182 if (Reg->BitWidth == 64)
184 /* Read the top 32 bits */
186 Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
187 (Address + 4), &Value, 32);
188 if (ACPI_FAILURE (Status))
192 *ReturnValue |= ((UINT64) Value << 32);
195 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
197 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
198 Address, &Value, Width);
199 if (ACPI_FAILURE (Status))
203 *ReturnValue = Value;
205 if (Reg->BitWidth == 64)
207 /* Read the top 32 bits */
209 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
210 (Address + 4), &Value, 32);
211 if (ACPI_FAILURE (Status))
215 *ReturnValue |= ((UINT64) Value << 32);
219 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
220 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
221 ACPI_FORMAT_UINT64 (*ReturnValue), Reg->BitWidth,
222 ACPI_FORMAT_UINT64 (Address),
223 AcpiUtGetRegionName (Reg->SpaceId)));
228 ACPI_EXPORT_SYMBOL (AcpiRead)
231 /******************************************************************************
233 * FUNCTION: AcpiWrite
235 * PARAMETERS: Value - Value to be written
236 * Reg - GAS register structure
240 * DESCRIPTION: Write to either memory or IO space.
242 ******************************************************************************/
247 ACPI_GENERIC_ADDRESS *Reg)
254 ACPI_FUNCTION_NAME (AcpiWrite);
257 /* Validate contents of the GAS register. Allow 64-bit transfers */
259 Status = AcpiHwValidateRegister (Reg, 64, &Address);
260 if (ACPI_FAILURE (Status))
265 Width = Reg->BitWidth;
268 Width = 32; /* Break into two 32-bit transfers */
272 * Two address spaces supported: Memory or IO. PCI_Config is
273 * not supported here because the GAS structure is insufficient
275 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
277 Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
278 Address, ACPI_LODWORD (Value), Width);
279 if (ACPI_FAILURE (Status))
284 if (Reg->BitWidth == 64)
286 Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
287 (Address + 4), ACPI_HIDWORD (Value), 32);
288 if (ACPI_FAILURE (Status))
294 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
296 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
297 Address, ACPI_LODWORD (Value), Width);
298 if (ACPI_FAILURE (Status))
303 if (Reg->BitWidth == 64)
305 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
306 (Address + 4), ACPI_HIDWORD (Value), 32);
307 if (ACPI_FAILURE (Status))
314 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
315 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
316 ACPI_FORMAT_UINT64 (Value), Reg->BitWidth,
317 ACPI_FORMAT_UINT64 (Address),
318 AcpiUtGetRegionName (Reg->SpaceId)));
323 ACPI_EXPORT_SYMBOL (AcpiWrite)
326 /*******************************************************************************
328 * FUNCTION: AcpiReadBitRegister
330 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
331 * ReturnValue - Value that was read from the register,
332 * normalized to bit position zero.
334 * RETURN: Status and the value read from the specified Register. Value
335 * returned is normalized to bit0 (is shifted all the way right)
337 * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
339 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
342 * Note: The hardware lock is not required when reading the ACPI bit registers
343 * since almost all of them are single bit and it does not matter that
344 * the parent hardware register can be split across two physical
345 * registers. The only multi-bit field is SLP_TYP in the PM1 control
346 * register, but this field does not cross an 8-bit boundary (nor does
347 * it make much sense to actually read this field.)
349 ******************************************************************************/
352 AcpiReadBitRegister (
356 ACPI_BIT_REGISTER_INFO *BitRegInfo;
357 UINT32 RegisterValue;
362 ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister, RegisterId);
365 /* Get the info structure corresponding to the requested ACPI Register */
367 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
370 return_ACPI_STATUS (AE_BAD_PARAMETER);
373 /* Read the entire parent register */
375 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
377 if (ACPI_FAILURE (Status))
379 return_ACPI_STATUS (Status);
382 /* Normalize the value that was read, mask off other bits */
384 Value = ((RegisterValue & BitRegInfo->AccessBitMask)
385 >> BitRegInfo->BitPosition);
387 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
388 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
389 RegisterId, BitRegInfo->ParentRegister, RegisterValue, Value));
391 *ReturnValue = Value;
392 return_ACPI_STATUS (AE_OK);
395 ACPI_EXPORT_SYMBOL (AcpiReadBitRegister)
398 /*******************************************************************************
400 * FUNCTION: AcpiWriteBitRegister
402 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
403 * Value - Value to write to the register, in bit
404 * position zero. The bit is automaticallly
405 * shifted to the correct position.
409 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
410 * since most operations require a read/modify/write sequence.
412 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
415 * Note that at this level, the fact that there may be actually two
416 * hardware registers (A and B - and B may not exist) is abstracted.
418 ******************************************************************************/
421 AcpiWriteBitRegister (
425 ACPI_BIT_REGISTER_INFO *BitRegInfo;
426 ACPI_CPU_FLAGS LockFlags;
427 UINT32 RegisterValue;
428 ACPI_STATUS Status = AE_OK;
431 ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister, RegisterId);
434 /* Get the info structure corresponding to the requested ACPI Register */
436 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
439 return_ACPI_STATUS (AE_BAD_PARAMETER);
442 LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock);
445 * At this point, we know that the parent register is one of the
446 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
448 if (BitRegInfo->ParentRegister != ACPI_REGISTER_PM1_STATUS)
451 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
453 * Perform a register read to preserve the bits that we are not
456 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
458 if (ACPI_FAILURE (Status))
464 * Insert the input bit into the value that was just read
465 * and write the register
467 ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
468 BitRegInfo->AccessBitMask, Value);
470 Status = AcpiHwRegisterWrite (BitRegInfo->ParentRegister,
476 * 2) Case for PM1 Status
478 * The Status register is different from the rest. Clear an event
479 * by writing 1, writing 0 has no effect. So, the only relevant
480 * information is the single bit we're interested in, all others
481 * should be written as 0 so they will be left unchanged.
483 RegisterValue = ACPI_REGISTER_PREPARE_BITS (Value,
484 BitRegInfo->BitPosition, BitRegInfo->AccessBitMask);
486 /* No need to write the register if value is all zeros */
490 Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS,
495 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
496 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
497 RegisterId, BitRegInfo->ParentRegister, Value, RegisterValue));
502 AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags);
503 return_ACPI_STATUS (Status);
506 ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister)
509 /*******************************************************************************
511 * FUNCTION: AcpiGetSleepTypeData
513 * PARAMETERS: SleepState - Numeric sleep state
514 * *SleepTypeA - Where SLP_TYPa is returned
515 * *SleepTypeB - Where SLP_TYPb is returned
517 * RETURN: Status - ACPI status
519 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
522 ******************************************************************************/
525 AcpiGetSleepTypeData (
530 ACPI_STATUS Status = AE_OK;
531 ACPI_EVALUATE_INFO *Info;
534 ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData);
537 /* Validate parameters */
539 if ((SleepState > ACPI_S_STATES_MAX) ||
543 return_ACPI_STATUS (AE_BAD_PARAMETER);
546 /* Allocate the evaluation information block */
548 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
551 return_ACPI_STATUS (AE_NO_MEMORY);
554 Info->Pathname = ACPI_CAST_PTR (char, AcpiGbl_SleepStateNames[SleepState]);
556 /* Evaluate the namespace object containing the values for this state */
558 Status = AcpiNsEvaluate (Info);
559 if (ACPI_FAILURE (Status))
561 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
562 "%s while evaluating SleepState [%s]\n",
563 AcpiFormatException (Status), Info->Pathname));
568 /* Must have a return object */
570 if (!Info->ReturnObject)
572 ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
574 Status = AE_NOT_EXIST;
577 /* It must be of type Package */
579 else if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
581 ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
582 Status = AE_AML_OPERAND_TYPE;
586 * The package must have at least two elements. NOTE (March 2005): This
587 * goes against the current ACPI spec which defines this object as a
588 * package with one encoded DWORD element. However, existing practice
589 * by BIOS vendors seems to be to have 2 or more elements, at least
590 * one per sleep type (A/B).
592 else if (Info->ReturnObject->Package.Count < 2)
594 ACPI_ERROR ((AE_INFO,
595 "Sleep State return package does not have at least two elements"));
596 Status = AE_AML_NO_OPERAND;
599 /* The first two elements must both be of type Integer */
601 else if (((Info->ReturnObject->Package.Elements[0])->Common.Type
602 != ACPI_TYPE_INTEGER) ||
603 ((Info->ReturnObject->Package.Elements[1])->Common.Type
604 != ACPI_TYPE_INTEGER))
606 ACPI_ERROR ((AE_INFO,
607 "Sleep State return package elements are not both Integers "
609 AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[0]),
610 AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[1])));
611 Status = AE_AML_OPERAND_TYPE;
615 /* Valid _Sx_ package size, type, and value */
617 *SleepTypeA = (UINT8)
618 (Info->ReturnObject->Package.Elements[0])->Integer.Value;
619 *SleepTypeB = (UINT8)
620 (Info->ReturnObject->Package.Elements[1])->Integer.Value;
623 if (ACPI_FAILURE (Status))
625 ACPI_EXCEPTION ((AE_INFO, Status,
626 "While evaluating SleepState [%s], bad Sleep object %p type %s",
627 Info->Pathname, Info->ReturnObject,
628 AcpiUtGetObjectTypeName (Info->ReturnObject)));
631 AcpiUtRemoveReference (Info->ReturnObject);
635 return_ACPI_STATUS (Status);
638 ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData)