1 /******************************************************************************
3 * Module Name: hwxface - Public ACPICA hardware interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acnamesp.h>
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME ("hwxface")
52 /******************************************************************************
60 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
61 * support reset register in PCI config space, this must be
64 ******************************************************************************/
70 ACPI_GENERIC_ADDRESS *ResetReg;
74 ACPI_FUNCTION_TRACE (AcpiReset);
77 ResetReg = &AcpiGbl_FADT.ResetRegister;
79 /* Check if the reset register is supported */
81 if (!(AcpiGbl_FADT.Flags & ACPI_FADT_RESET_REGISTER) ||
84 return_ACPI_STATUS (AE_NOT_EXIST);
87 if (ResetReg->SpaceId == ACPI_ADR_SPACE_SYSTEM_IO)
90 * For I/O space, write directly to the OSL. This bypasses the port
91 * validation mechanism, which may block a valid write to the reset
94 Status = AcpiOsWritePort ((ACPI_IO_ADDRESS) ResetReg->Address,
95 AcpiGbl_FADT.ResetValue, ResetReg->BitWidth);
99 /* Write the reset value to the reset register */
101 Status = AcpiHwWrite (AcpiGbl_FADT.ResetValue, ResetReg);
104 return_ACPI_STATUS (Status);
107 ACPI_EXPORT_SYMBOL (AcpiReset)
110 /******************************************************************************
114 * PARAMETERS: Value - Where the value is returned
115 * Reg - GAS register structure
119 * DESCRIPTION: Read from either memory or IO space.
121 * LIMITATIONS: <These limitations also apply to AcpiWrite>
122 * BitWidth must be exactly 8, 16, 32, or 64.
123 * SpaceID must be SystemMemory or SystemIO.
124 * BitOffset and AccessWidth are currently ignored, as there has
125 * not been a need to implement these.
127 ******************************************************************************/
132 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))
158 * Two address spaces supported: Memory or I/O. PCI_Config is
159 * not supported here because the GAS structure is insufficient
161 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
163 Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
164 Address, ReturnValue, Reg->BitWidth);
165 if (ACPI_FAILURE (Status))
170 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
175 Width = Reg->BitWidth;
178 Width = 32; /* Break into two 32-bit transfers */
181 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
182 Address, &ValueLo, Width);
183 if (ACPI_FAILURE (Status))
188 if (Reg->BitWidth == 64)
190 /* Read the top 32 bits */
192 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
193 (Address + 4), &ValueHi, 32);
194 if (ACPI_FAILURE (Status))
200 /* Set the return value only if status is AE_OK */
202 *ReturnValue = (ValueLo | ((UINT64) ValueHi << 32));
205 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
206 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
207 ACPI_FORMAT_UINT64 (*ReturnValue), Reg->BitWidth,
208 ACPI_FORMAT_UINT64 (Address),
209 AcpiUtGetRegionName (Reg->SpaceId)));
214 ACPI_EXPORT_SYMBOL (AcpiRead)
217 /******************************************************************************
219 * FUNCTION: AcpiWrite
221 * PARAMETERS: Value - Value to be written
222 * Reg - GAS register structure
226 * DESCRIPTION: Write to either memory or IO space.
228 ******************************************************************************/
233 ACPI_GENERIC_ADDRESS *Reg)
240 ACPI_FUNCTION_NAME (AcpiWrite);
243 /* Validate contents of the GAS register. Allow 64-bit transfers */
245 Status = AcpiHwValidateRegister (Reg, 64, &Address);
246 if (ACPI_FAILURE (Status))
252 * Two address spaces supported: Memory or IO. PCI_Config is
253 * not supported here because the GAS structure is insufficient
255 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
257 Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
258 Address, Value, Reg->BitWidth);
259 if (ACPI_FAILURE (Status))
264 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
266 Width = Reg->BitWidth;
269 Width = 32; /* Break into two 32-bit transfers */
272 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
273 Address, ACPI_LODWORD (Value), Width);
274 if (ACPI_FAILURE (Status))
279 if (Reg->BitWidth == 64)
281 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
282 (Address + 4), ACPI_HIDWORD (Value), 32);
283 if (ACPI_FAILURE (Status))
290 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
291 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
292 ACPI_FORMAT_UINT64 (Value), Reg->BitWidth,
293 ACPI_FORMAT_UINT64 (Address),
294 AcpiUtGetRegionName (Reg->SpaceId)));
299 ACPI_EXPORT_SYMBOL (AcpiWrite)
302 #if (!ACPI_REDUCED_HARDWARE)
303 /*******************************************************************************
305 * FUNCTION: AcpiReadBitRegister
307 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
308 * ReturnValue - Value that was read from the register,
309 * normalized to bit position zero.
311 * RETURN: Status and the value read from the specified Register. Value
312 * returned is normalized to bit0 (is shifted all the way right)
314 * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
316 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
319 * Note: The hardware lock is not required when reading the ACPI bit registers
320 * since almost all of them are single bit and it does not matter that
321 * the parent hardware register can be split across two physical
322 * registers. The only multi-bit field is SLP_TYP in the PM1 control
323 * register, but this field does not cross an 8-bit boundary (nor does
324 * it make much sense to actually read this field.)
326 ******************************************************************************/
329 AcpiReadBitRegister (
333 ACPI_BIT_REGISTER_INFO *BitRegInfo;
334 UINT32 RegisterValue;
339 ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister, RegisterId);
342 /* Get the info structure corresponding to the requested ACPI Register */
344 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
347 return_ACPI_STATUS (AE_BAD_PARAMETER);
350 /* Read the entire parent register */
352 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
354 if (ACPI_FAILURE (Status))
356 return_ACPI_STATUS (Status);
359 /* Normalize the value that was read, mask off other bits */
361 Value = ((RegisterValue & BitRegInfo->AccessBitMask)
362 >> BitRegInfo->BitPosition);
364 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
365 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
366 RegisterId, BitRegInfo->ParentRegister, RegisterValue, Value));
368 *ReturnValue = Value;
369 return_ACPI_STATUS (AE_OK);
372 ACPI_EXPORT_SYMBOL (AcpiReadBitRegister)
375 /*******************************************************************************
377 * FUNCTION: AcpiWriteBitRegister
379 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
380 * Value - Value to write to the register, in bit
381 * position zero. The bit is automatically
382 * shifted to the correct position.
386 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
387 * since most operations require a read/modify/write sequence.
389 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
392 * Note that at this level, the fact that there may be actually two
393 * hardware registers (A and B - and B may not exist) is abstracted.
395 ******************************************************************************/
398 AcpiWriteBitRegister (
402 ACPI_BIT_REGISTER_INFO *BitRegInfo;
403 ACPI_CPU_FLAGS LockFlags;
404 UINT32 RegisterValue;
405 ACPI_STATUS Status = AE_OK;
408 ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister, RegisterId);
411 /* Get the info structure corresponding to the requested ACPI Register */
413 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
416 return_ACPI_STATUS (AE_BAD_PARAMETER);
419 LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock);
422 * At this point, we know that the parent register is one of the
423 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
425 if (BitRegInfo->ParentRegister != ACPI_REGISTER_PM1_STATUS)
428 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
430 * Perform a register read to preserve the bits that we are not
433 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
435 if (ACPI_FAILURE (Status))
441 * Insert the input bit into the value that was just read
442 * and write the register
444 ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
445 BitRegInfo->AccessBitMask, Value);
447 Status = AcpiHwRegisterWrite (BitRegInfo->ParentRegister,
453 * 2) Case for PM1 Status
455 * The Status register is different from the rest. Clear an event
456 * by writing 1, writing 0 has no effect. So, the only relevant
457 * information is the single bit we're interested in, all others
458 * should be written as 0 so they will be left unchanged.
460 RegisterValue = ACPI_REGISTER_PREPARE_BITS (Value,
461 BitRegInfo->BitPosition, BitRegInfo->AccessBitMask);
463 /* No need to write the register if value is all zeros */
467 Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS,
472 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
473 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
474 RegisterId, BitRegInfo->ParentRegister, Value, RegisterValue));
479 AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags);
480 return_ACPI_STATUS (Status);
483 ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister)
485 #endif /* !ACPI_REDUCED_HARDWARE */
488 /*******************************************************************************
490 * FUNCTION: AcpiGetSleepTypeData
492 * PARAMETERS: SleepState - Numeric sleep state
493 * *SleepTypeA - Where SLP_TYPa is returned
494 * *SleepTypeB - Where SLP_TYPb is returned
498 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
499 * sleep state via the appropriate \_Sx object.
501 * The sleep state package returned from the corresponding \_Sx_ object
502 * must contain at least one integer.
505 * Added support for a package that contains two integers. This
506 * goes against the ACPI specification which defines this object as a
507 * package with one encoded DWORD integer. However, existing practice
508 * by many BIOS vendors is to return a package with 2 or more integer
509 * elements, at least one per sleep type (A/B).
512 * Therefore, we must be prepared to accept a package with either a
513 * single integer or multiple integers.
515 * The single integer DWORD format is as follows:
516 * BYTE 0 - Value for the PM1A SLP_TYP register
517 * BYTE 1 - Value for the PM1B SLP_TYP register
518 * BYTE 2-3 - Reserved
520 * The dual integer format is as follows:
521 * Integer 0 - Value for the PM1A SLP_TYP register
522 * Integer 1 - Value for the PM1A SLP_TYP register
524 ******************************************************************************/
527 AcpiGetSleepTypeData (
533 ACPI_EVALUATE_INFO *Info;
534 ACPI_OPERAND_OBJECT **Elements;
537 ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData);
540 /* Validate parameters */
542 if ((SleepState > ACPI_S_STATES_MAX) ||
543 !SleepTypeA || !SleepTypeB)
545 return_ACPI_STATUS (AE_BAD_PARAMETER);
548 /* Allocate the evaluation information block */
550 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
553 return_ACPI_STATUS (AE_NO_MEMORY);
557 * Evaluate the \_Sx namespace object containing the register values
560 Info->RelativePathname = ACPI_CAST_PTR (
561 char, AcpiGbl_SleepStateNames[SleepState]);
562 Status = AcpiNsEvaluate (Info);
563 if (ACPI_FAILURE (Status))
568 /* Must have a return object */
570 if (!Info->ReturnObject)
572 ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
573 Info->RelativePathname));
574 Status = AE_AML_NO_RETURN_VALUE;
578 /* Return object must be of type Package */
580 if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
582 ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
583 Status = AE_AML_OPERAND_TYPE;
588 * Any warnings about the package length or the object types have
589 * already been issued by the predefined name module -- there is no
590 * need to repeat them here.
592 Elements = Info->ReturnObject->Package.Elements;
593 switch (Info->ReturnObject->Package.Count)
597 Status = AE_AML_PACKAGE_LIMIT;
602 if (Elements[0]->Common.Type != ACPI_TYPE_INTEGER)
604 Status = AE_AML_OPERAND_TYPE;
608 /* A valid _Sx_ package with one integer */
610 *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
611 *SleepTypeB = (UINT8) (Elements[0]->Integer.Value >> 8);
617 if ((Elements[0]->Common.Type != ACPI_TYPE_INTEGER) ||
618 (Elements[1]->Common.Type != ACPI_TYPE_INTEGER))
620 Status = AE_AML_OPERAND_TYPE;
624 /* A valid _Sx_ package with two integers */
626 *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
627 *SleepTypeB = (UINT8) Elements[1]->Integer.Value;
632 AcpiUtRemoveReference (Info->ReturnObject);
635 if (ACPI_FAILURE (Status))
637 ACPI_EXCEPTION ((AE_INFO, Status,
638 "While evaluating Sleep State [%s]", Info->RelativePathname));
642 return_ACPI_STATUS (Status);
645 ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData)