2 /******************************************************************************
4 * Module Name: hwxface - Public ACPICA hardware interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2012, 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 /* Initialize entire 64-bit return value to zero */
163 * Two address spaces supported: Memory or IO. PCI_Config is
164 * not supported here because the GAS structure is insufficient
166 if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
168 Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
169 Address, ReturnValue, Reg->BitWidth);
170 if (ACPI_FAILURE (Status))
175 else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
177 Width = Reg->BitWidth;
180 Width = 32; /* Break into two 32-bit transfers */
183 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
184 Address, &Value, Width);
185 if (ACPI_FAILURE (Status))
189 *ReturnValue = Value;
191 if (Reg->BitWidth == 64)
193 /* Read the top 32 bits */
195 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
196 (Address + 4), &Value, 32);
197 if (ACPI_FAILURE (Status))
201 *ReturnValue |= ((UINT64) Value << 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 automaticallly
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
496 * RETURN: Status - ACPI status
498 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested sleep
501 ******************************************************************************/
504 AcpiGetSleepTypeData (
509 ACPI_STATUS Status = AE_OK;
510 ACPI_EVALUATE_INFO *Info;
513 ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData);
516 /* Validate parameters */
518 if ((SleepState > ACPI_S_STATES_MAX) ||
522 return_ACPI_STATUS (AE_BAD_PARAMETER);
525 /* Allocate the evaluation information block */
527 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
530 return_ACPI_STATUS (AE_NO_MEMORY);
533 Info->Pathname = ACPI_CAST_PTR (char, AcpiGbl_SleepStateNames[SleepState]);
535 /* Evaluate the namespace object containing the values for this state */
537 Status = AcpiNsEvaluate (Info);
538 if (ACPI_FAILURE (Status))
540 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
541 "%s while evaluating SleepState [%s]\n",
542 AcpiFormatException (Status), Info->Pathname));
547 /* Must have a return object */
549 if (!Info->ReturnObject)
551 ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
553 Status = AE_NOT_EXIST;
556 /* It must be of type Package */
558 else if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
560 ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
561 Status = AE_AML_OPERAND_TYPE;
565 * The package must have at least two elements. NOTE (March 2005): This
566 * goes against the current ACPI spec which defines this object as a
567 * package with one encoded DWORD element. However, existing practice
568 * by BIOS vendors seems to be to have 2 or more elements, at least
569 * one per sleep type (A/B).
571 else if (Info->ReturnObject->Package.Count < 2)
573 ACPI_ERROR ((AE_INFO,
574 "Sleep State return package does not have at least two elements"));
575 Status = AE_AML_NO_OPERAND;
578 /* The first two elements must both be of type Integer */
580 else if (((Info->ReturnObject->Package.Elements[0])->Common.Type
581 != ACPI_TYPE_INTEGER) ||
582 ((Info->ReturnObject->Package.Elements[1])->Common.Type
583 != ACPI_TYPE_INTEGER))
585 ACPI_ERROR ((AE_INFO,
586 "Sleep State return package elements are not both Integers "
588 AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[0]),
589 AcpiUtGetObjectTypeName (Info->ReturnObject->Package.Elements[1])));
590 Status = AE_AML_OPERAND_TYPE;
594 /* Valid _Sx_ package size, type, and value */
596 *SleepTypeA = (UINT8)
597 (Info->ReturnObject->Package.Elements[0])->Integer.Value;
598 *SleepTypeB = (UINT8)
599 (Info->ReturnObject->Package.Elements[1])->Integer.Value;
602 if (ACPI_FAILURE (Status))
604 ACPI_EXCEPTION ((AE_INFO, Status,
605 "While evaluating SleepState [%s], bad Sleep object %p type %s",
606 Info->Pathname, Info->ReturnObject,
607 AcpiUtGetObjectTypeName (Info->ReturnObject)));
610 AcpiUtRemoveReference (Info->ReturnObject);
614 return_ACPI_STATUS (Status);
617 ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData)