1 /******************************************************************************
3 * Module Name: hwxface - Public ACPICA hardware interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2022, 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 MERCHANTABILITY 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 #define EXPORT_ACPI_INTERFACES
50 #define _COMPONENT ACPI_HARDWARE
51 ACPI_MODULE_NAME ("hwxface")
54 /******************************************************************************
62 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
63 * support reset register in PCI config space, this must be
66 ******************************************************************************/
72 ACPI_GENERIC_ADDRESS
*ResetReg
;
76 ACPI_FUNCTION_TRACE (AcpiReset
);
79 ResetReg
= &AcpiGbl_FADT
.ResetRegister
;
81 /* Check if the reset register is supported */
83 if (!(AcpiGbl_FADT
.Flags
& ACPI_FADT_RESET_REGISTER
) ||
86 return_ACPI_STATUS (AE_NOT_EXIST
);
89 if (ResetReg
->SpaceId
== ACPI_ADR_SPACE_SYSTEM_IO
)
92 * For I/O space, write directly to the OSL. This bypasses the port
93 * validation mechanism, which may block a valid write to the reset
97 * The ACPI spec requires the reset register width to be 8, so we
98 * hardcode it here and ignore the FADT value. This maintains
99 * compatibility with other ACPI implementations that have allowed
100 * BIOS code with bad register width values to go unnoticed.
102 Status
= AcpiOsWritePort ((ACPI_IO_ADDRESS
) ResetReg
->Address
,
103 AcpiGbl_FADT
.ResetValue
, ACPI_RESET_REGISTER_WIDTH
);
107 /* Write the reset value to the reset register */
109 Status
= AcpiHwWrite (AcpiGbl_FADT
.ResetValue
, ResetReg
);
112 return_ACPI_STATUS (Status
);
115 ACPI_EXPORT_SYMBOL (AcpiReset
)
118 /******************************************************************************
122 * PARAMETERS: Value - Where the value is returned
123 * Reg - GAS register structure
127 * DESCRIPTION: Read from either memory or IO space.
129 * LIMITATIONS: <These limitations also apply to AcpiWrite>
130 * BitWidth must be exactly 8, 16, 32, or 64.
131 * SpaceID must be SystemMemory or SystemIO.
132 * BitOffset and AccessWidth are currently ignored, as there has
133 * not been a need to implement these.
135 ******************************************************************************/
140 ACPI_GENERIC_ADDRESS
*Reg
)
145 ACPI_FUNCTION_NAME (AcpiRead
);
148 Status
= AcpiHwRead (ReturnValue
, Reg
);
152 ACPI_EXPORT_SYMBOL (AcpiRead
)
155 /******************************************************************************
157 * FUNCTION: AcpiWrite
159 * PARAMETERS: Value - Value to be written
160 * Reg - GAS register structure
164 * DESCRIPTION: Write to either memory or IO space.
166 ******************************************************************************/
171 ACPI_GENERIC_ADDRESS
*Reg
)
176 ACPI_FUNCTION_NAME (AcpiWrite
);
179 Status
= AcpiHwWrite (Value
, Reg
);
183 ACPI_EXPORT_SYMBOL (AcpiWrite
)
186 #if (!ACPI_REDUCED_HARDWARE)
187 /*******************************************************************************
189 * FUNCTION: AcpiReadBitRegister
191 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
192 * ReturnValue - Value that was read from the register,
193 * normalized to bit position zero.
195 * RETURN: Status and the value read from the specified Register. Value
196 * returned is normalized to bit0 (is shifted all the way right)
198 * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
200 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
203 * Note: The hardware lock is not required when reading the ACPI bit registers
204 * since almost all of them are single bit and it does not matter that
205 * the parent hardware register can be split across two physical
206 * registers. The only multi-bit field is SLP_TYP in the PM1 control
207 * register, but this field does not cross an 8-bit boundary (nor does
208 * it make much sense to actually read this field.)
210 ******************************************************************************/
213 AcpiReadBitRegister (
217 ACPI_BIT_REGISTER_INFO
*BitRegInfo
;
218 UINT32 RegisterValue
;
223 ACPI_FUNCTION_TRACE_U32 (AcpiReadBitRegister
, RegisterId
);
226 /* Get the info structure corresponding to the requested ACPI Register */
228 BitRegInfo
= AcpiHwGetBitRegisterInfo (RegisterId
);
231 return_ACPI_STATUS (AE_BAD_PARAMETER
);
234 /* Read the entire parent register */
236 Status
= AcpiHwRegisterRead (BitRegInfo
->ParentRegister
,
238 if (ACPI_FAILURE (Status
))
240 return_ACPI_STATUS (Status
);
243 /* Normalize the value that was read, mask off other bits */
245 Value
= ((RegisterValue
& BitRegInfo
->AccessBitMask
)
246 >> BitRegInfo
->BitPosition
);
248 ACPI_DEBUG_PRINT ((ACPI_DB_IO
,
249 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
250 RegisterId
, BitRegInfo
->ParentRegister
, RegisterValue
, Value
));
252 *ReturnValue
= Value
;
253 return_ACPI_STATUS (AE_OK
);
256 ACPI_EXPORT_SYMBOL (AcpiReadBitRegister
)
259 /*******************************************************************************
261 * FUNCTION: AcpiWriteBitRegister
263 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
264 * Value - Value to write to the register, in bit
265 * position zero. The bit is automatically
266 * shifted to the correct position.
270 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
271 * since most operations require a read/modify/write sequence.
273 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
276 * Note that at this level, the fact that there may be actually two
277 * hardware registers (A and B - and B may not exist) is abstracted.
279 ******************************************************************************/
282 AcpiWriteBitRegister (
286 ACPI_BIT_REGISTER_INFO
*BitRegInfo
;
287 ACPI_CPU_FLAGS LockFlags
;
288 UINT32 RegisterValue
;
289 ACPI_STATUS Status
= AE_OK
;
292 ACPI_FUNCTION_TRACE_U32 (AcpiWriteBitRegister
, RegisterId
);
295 /* Get the info structure corresponding to the requested ACPI Register */
297 BitRegInfo
= AcpiHwGetBitRegisterInfo (RegisterId
);
300 return_ACPI_STATUS (AE_BAD_PARAMETER
);
303 LockFlags
= AcpiOsAcquireLock (AcpiGbl_HardwareLock
);
306 * At this point, we know that the parent register is one of the
307 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
309 if (BitRegInfo
->ParentRegister
!= ACPI_REGISTER_PM1_STATUS
)
312 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
314 * Perform a register read to preserve the bits that we are not
317 Status
= AcpiHwRegisterRead (BitRegInfo
->ParentRegister
,
319 if (ACPI_FAILURE (Status
))
325 * Insert the input bit into the value that was just read
326 * and write the register
328 ACPI_REGISTER_INSERT_VALUE (RegisterValue
, BitRegInfo
->BitPosition
,
329 BitRegInfo
->AccessBitMask
, Value
);
331 Status
= AcpiHwRegisterWrite (BitRegInfo
->ParentRegister
,
337 * 2) Case for PM1 Status
339 * The Status register is different from the rest. Clear an event
340 * by writing 1, writing 0 has no effect. So, the only relevant
341 * information is the single bit we're interested in, all others
342 * should be written as 0 so they will be left unchanged.
344 RegisterValue
= ACPI_REGISTER_PREPARE_BITS (Value
,
345 BitRegInfo
->BitPosition
, BitRegInfo
->AccessBitMask
);
347 /* No need to write the register if value is all zeros */
351 Status
= AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS
,
356 ACPI_DEBUG_PRINT ((ACPI_DB_IO
,
357 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
358 RegisterId
, BitRegInfo
->ParentRegister
, Value
, RegisterValue
));
363 AcpiOsReleaseLock (AcpiGbl_HardwareLock
, LockFlags
);
364 return_ACPI_STATUS (Status
);
367 ACPI_EXPORT_SYMBOL (AcpiWriteBitRegister
)
369 #endif /* !ACPI_REDUCED_HARDWARE */
372 /*******************************************************************************
374 * FUNCTION: AcpiGetSleepTypeData
376 * PARAMETERS: SleepState - Numeric sleep state
377 * *SleepTypeA - Where SLP_TYPa is returned
378 * *SleepTypeB - Where SLP_TYPb is returned
382 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
383 * sleep state via the appropriate \_Sx object.
385 * The sleep state package returned from the corresponding \_Sx_ object
386 * must contain at least one integer.
389 * Added support for a package that contains two integers. This
390 * goes against the ACPI specification which defines this object as a
391 * package with one encoded DWORD integer. However, existing practice
392 * by many BIOS vendors is to return a package with 2 or more integer
393 * elements, at least one per sleep type (A/B).
396 * Therefore, we must be prepared to accept a package with either a
397 * single integer or multiple integers.
399 * The single integer DWORD format is as follows:
400 * BYTE 0 - Value for the PM1A SLP_TYP register
401 * BYTE 1 - Value for the PM1B SLP_TYP register
402 * BYTE 2-3 - Reserved
404 * The dual integer format is as follows:
405 * Integer 0 - Value for the PM1A SLP_TYP register
406 * Integer 1 - Value for the PM1A SLP_TYP register
408 ******************************************************************************/
411 AcpiGetSleepTypeData (
417 ACPI_EVALUATE_INFO
*Info
;
418 ACPI_OPERAND_OBJECT
**Elements
;
421 ACPI_FUNCTION_TRACE (AcpiGetSleepTypeData
);
424 /* Validate parameters */
426 if ((SleepState
> ACPI_S_STATES_MAX
) ||
427 !SleepTypeA
|| !SleepTypeB
)
429 return_ACPI_STATUS (AE_BAD_PARAMETER
);
432 /* Allocate the evaluation information block */
434 Info
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO
));
437 return_ACPI_STATUS (AE_NO_MEMORY
);
441 * Evaluate the \_Sx namespace object containing the register values
444 Info
->RelativePathname
= AcpiGbl_SleepStateNames
[SleepState
];
446 Status
= AcpiNsEvaluate (Info
);
447 if (ACPI_FAILURE (Status
))
449 if (Status
== AE_NOT_FOUND
)
451 /* The _Sx states are optional, ignore NOT_FOUND */
459 /* Must have a return object */
461 if (!Info
->ReturnObject
)
463 ACPI_ERROR ((AE_INFO
, "No Sleep State object returned from [%s]",
464 Info
->RelativePathname
));
465 Status
= AE_AML_NO_RETURN_VALUE
;
469 /* Return object must be of type Package */
471 if (Info
->ReturnObject
->Common
.Type
!= ACPI_TYPE_PACKAGE
)
473 ACPI_ERROR ((AE_INFO
, "Sleep State return object is not a Package"));
474 Status
= AE_AML_OPERAND_TYPE
;
475 goto ReturnValueCleanup
;
479 * Any warnings about the package length or the object types have
480 * already been issued by the predefined name module -- there is no
481 * need to repeat them here.
483 Elements
= Info
->ReturnObject
->Package
.Elements
;
484 switch (Info
->ReturnObject
->Package
.Count
)
488 Status
= AE_AML_PACKAGE_LIMIT
;
493 if (Elements
[0]->Common
.Type
!= ACPI_TYPE_INTEGER
)
495 Status
= AE_AML_OPERAND_TYPE
;
499 /* A valid _Sx_ package with one integer */
501 *SleepTypeA
= (UINT8
) Elements
[0]->Integer
.Value
;
502 *SleepTypeB
= (UINT8
) (Elements
[0]->Integer
.Value
>> 8);
508 if ((Elements
[0]->Common
.Type
!= ACPI_TYPE_INTEGER
) ||
509 (Elements
[1]->Common
.Type
!= ACPI_TYPE_INTEGER
))
511 Status
= AE_AML_OPERAND_TYPE
;
515 /* A valid _Sx_ package with two integers */
517 *SleepTypeA
= (UINT8
) Elements
[0]->Integer
.Value
;
518 *SleepTypeB
= (UINT8
) Elements
[1]->Integer
.Value
;
523 AcpiUtRemoveReference (Info
->ReturnObject
);
526 if (ACPI_FAILURE (Status
))
528 ACPI_EXCEPTION ((AE_INFO
, Status
,
529 "While evaluating Sleep State [%s]",
530 Info
->RelativePathname
));
535 return_ACPI_STATUS (Status
);
538 ACPI_EXPORT_SYMBOL (AcpiGetSleepTypeData
)