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.
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)
140 ACPI_FUNCTION_NAME (AcpiRead);
145 return (AE_BAD_PARAMETER);
148 /* Validate contents of the GAS register. Allow 64-bit transfers */
150 Status = AcpiHwValidateRegister (Reg, 64, &Address);
151 if (ACPI_FAILURE (Status))
156 /* Initialize entire 64-bit return value to zero */
162 * Two address spaces supported: Memory or IO. PCI_Config is
163 * not supported here because the GAS structure is insufficient
165 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
167 Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
168 Address, ReturnValue, Reg->BitWidth);
169 if (ACPI_FAILURE (Status))
174 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
176 Width = Reg->BitWidth;
179 Width = 32; /* Break into two 32-bit transfers */
182 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
183 Address, &Value, Width);
184 if (ACPI_FAILURE (Status))
188 *ReturnValue = Value;
190 if (Reg->BitWidth == 64)
192 /* Read the top 32 bits */
194 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
195 (Address + 4), &Value, 32);
196 if (ACPI_FAILURE (Status))
200 *ReturnValue |= ((UINT64) Value << 32);
204 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
205 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
206 ACPI_FORMAT_UINT64 (*ReturnValue), Reg->BitWidth,
207 ACPI_FORMAT_UINT64 (Address),
208 AcpiUtGetRegionName (Reg->SpaceId)));
213 ACPI_EXPORT_SYMBOL (AcpiRead)
216 /******************************************************************************
218 * FUNCTION: AcpiWrite
220 * PARAMETERS: Value - Value to be written
221 * Reg - GAS register structure
225 * DESCRIPTION: Write to either memory or IO space.
227 ******************************************************************************/
232 ACPI_GENERIC_ADDRESS *Reg)
239 ACPI_FUNCTION_NAME (AcpiWrite);
242 /* Validate contents of the GAS register. Allow 64-bit transfers */
244 Status = AcpiHwValidateRegister (Reg, 64, &Address);
245 if (ACPI_FAILURE (Status))
251 * Two address spaces supported: Memory or IO. PCI_Config is
252 * not supported here because the GAS structure is insufficient
254 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
256 Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS)
257 Address, Value, Reg->BitWidth);
258 if (ACPI_FAILURE (Status))
263 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
265 Width = Reg->BitWidth;
268 Width = 32; /* Break into two 32-bit transfers */
271 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
272 Address, ACPI_LODWORD (Value), Width);
273 if (ACPI_FAILURE (Status))
278 if (Reg->BitWidth == 64)
280 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS)
281 (Address + 4), ACPI_HIDWORD (Value), 32);
282 if (ACPI_FAILURE (Status))
289 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
290 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
291 ACPI_FORMAT_UINT64 (Value), Reg->BitWidth,
292 ACPI_FORMAT_UINT64 (Address),
293 AcpiUtGetRegionName (Reg->SpaceId)));
298 ACPI_EXPORT_SYMBOL (AcpiWrite)
301 #if (!ACPI_REDUCED_HARDWARE)
302 /*******************************************************************************
304 * FUNCTION: AcpiReadBitRegister
306 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
307 * ReturnValue - Value that was read from the register,
308 * normalized to bit position zero.
310 * RETURN: Status and the value read from the specified Register. Value
311 * returned is normalized to bit0 (is shifted all the way right)
313 * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
315 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
318 * Note: The hardware lock is not required when reading the ACPI bit registers
319 * since almost all of them are single bit and it does not matter that
320 * the parent hardware register can be split across two physical
321 * registers. The only multi-bit field is SLP_TYP in the PM1 control
322 * register, but this field does not cross an 8-bit boundary (nor does
323 * it make much sense to actually read this field.)
325 ******************************************************************************/
328 AcpiReadBitRegister (
332 ACPI_BIT_REGISTER_INFO *BitRegInfo;
333 UINT32 RegisterValue;
338 ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister, RegisterId);
341 /* Get the info structure corresponding to the requested ACPI Register */
343 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
346 return_ACPI_STATUS (AE_BAD_PARAMETER);
349 /* Read the entire parent register */
351 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
353 if (ACPI_FAILURE (Status))
355 return_ACPI_STATUS (Status);
358 /* Normalize the value that was read, mask off other bits */
360 Value = ((RegisterValue & BitRegInfo->AccessBitMask)
361 >> BitRegInfo->BitPosition);
363 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
364 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
365 RegisterId, BitRegInfo->ParentRegister, RegisterValue, Value));
367 *ReturnValue = Value;
368 return_ACPI_STATUS (AE_OK);
371 ACPI_EXPORT_SYMBOL (AcpiReadBitRegister)
374 /*******************************************************************************
376 * FUNCTION: AcpiWriteBitRegister
378 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
379 * Value - Value to write to the register, in bit
380 * position zero. The bit is automatically
381 * shifted to the correct position.
385 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
386 * since most operations require a read/modify/write sequence.
388 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
391 * Note that at this level, the fact that there may be actually two
392 * hardware registers (A and B - and B may not exist) is abstracted.
394 ******************************************************************************/
397 AcpiWriteBitRegister (
401 ACPI_BIT_REGISTER_INFO *BitRegInfo;
402 ACPI_CPU_FLAGS LockFlags;
403 UINT32 RegisterValue;
404 ACPI_STATUS Status = AE_OK;
407 ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister, RegisterId);
410 /* Get the info structure corresponding to the requested ACPI Register */
412 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
415 return_ACPI_STATUS (AE_BAD_PARAMETER);
418 LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock);
421 * At this point, we know that the parent register is one of the
422 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
424 if (BitRegInfo->ParentRegister != ACPI_REGISTER_PM1_STATUS)
427 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
429 * Perform a register read to preserve the bits that we are not
432 Status = AcpiHwRegisterRead (BitRegInfo->ParentRegister,
434 if (ACPI_FAILURE (Status))
440 * Insert the input bit into the value that was just read
441 * and write the register
443 ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
444 BitRegInfo->AccessBitMask, Value);
446 Status = AcpiHwRegisterWrite (BitRegInfo->ParentRegister,
452 * 2) Case for PM1 Status
454 * The Status register is different from the rest. Clear an event
455 * by writing 1, writing 0 has no effect. So, the only relevant
456 * information is the single bit we're interested in, all others
457 * should be written as 0 so they will be left unchanged.
459 RegisterValue = ACPI_REGISTER_PREPARE_BITS (Value,
460 BitRegInfo->BitPosition, BitRegInfo->AccessBitMask);
462 /* No need to write the register if value is all zeros */
466 Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS,
471 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
472 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
473 RegisterId, BitRegInfo->ParentRegister, Value, RegisterValue));
478 AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags);
479 return_ACPI_STATUS (Status);
482 ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister)
484 #endif /* !ACPI_REDUCED_HARDWARE */
487 /*******************************************************************************
489 * FUNCTION: AcpiGetSleepTypeData
491 * PARAMETERS: SleepState - Numeric sleep state
492 * *SleepTypeA - Where SLP_TYPa is returned
493 * *SleepTypeB - Where SLP_TYPb is returned
497 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
498 * sleep state via the appropriate \_Sx object.
500 * The sleep state package returned from the corresponding \_Sx_ object
501 * must contain at least one integer.
504 * Added support for a package that contains two integers. This
505 * goes against the ACPI specification which defines this object as a
506 * package with one encoded DWORD integer. However, existing practice
507 * by many BIOS vendors is to return a package with 2 or more integer
508 * elements, at least one per sleep type (A/B).
511 * Therefore, we must be prepared to accept a package with either a
512 * single integer or multiple integers.
514 * The single integer DWORD format is as follows:
515 * BYTE 0 - Value for the PM1A SLP_TYP register
516 * BYTE 1 - Value for the PM1B SLP_TYP register
517 * BYTE 2-3 - Reserved
519 * The dual integer format is as follows:
520 * Integer 0 - Value for the PM1A SLP_TYP register
521 * Integer 1 - Value for the PM1A SLP_TYP register
523 ******************************************************************************/
526 AcpiGetSleepTypeData (
532 ACPI_EVALUATE_INFO *Info;
533 ACPI_OPERAND_OBJECT **Elements;
536 ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData);
539 /* Validate parameters */
541 if ((SleepState > ACPI_S_STATES_MAX) ||
542 !SleepTypeA || !SleepTypeB)
544 return_ACPI_STATUS (AE_BAD_PARAMETER);
547 /* Allocate the evaluation information block */
549 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
552 return_ACPI_STATUS (AE_NO_MEMORY);
556 * Evaluate the \_Sx namespace object containing the register values
559 Info->Pathname = ACPI_CAST_PTR (char, AcpiGbl_SleepStateNames[SleepState]);
560 Status = AcpiNsEvaluate (Info);
561 if (ACPI_FAILURE (Status))
566 /* Must have a return object */
568 if (!Info->ReturnObject)
570 ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
572 Status = AE_AML_NO_RETURN_VALUE;
576 /* Return object must be of type Package */
578 if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
580 ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
581 Status = AE_AML_OPERAND_TYPE;
586 * Any warnings about the package length or the object types have
587 * already been issued by the predefined name module -- there is no
588 * need to repeat them here.
590 Elements = Info->ReturnObject->Package.Elements;
591 switch (Info->ReturnObject->Package.Count)
594 Status = AE_AML_PACKAGE_LIMIT;
598 if (Elements[0]->Common.Type != ACPI_TYPE_INTEGER)
600 Status = AE_AML_OPERAND_TYPE;
604 /* A valid _Sx_ package with one integer */
606 *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
607 *SleepTypeB = (UINT8) (Elements[0]->Integer.Value >> 8);
612 if ((Elements[0]->Common.Type != ACPI_TYPE_INTEGER) ||
613 (Elements[1]->Common.Type != ACPI_TYPE_INTEGER))
615 Status = AE_AML_OPERAND_TYPE;
619 /* A valid _Sx_ package with two integers */
621 *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
622 *SleepTypeB = (UINT8) Elements[1]->Integer.Value;
627 AcpiUtRemoveReference (Info->ReturnObject);
630 if (ACPI_FAILURE (Status))
632 ACPI_EXCEPTION ((AE_INFO, Status,
633 "While evaluating Sleep State [%s]", Info->Pathname));
637 return_ACPI_STATUS (Status);
640 ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData)