^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: hwxface - Public ACPICA hardware interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define EXPORT_ACPI_INTERFACES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "acnamesp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define _COMPONENT ACPI_HARDWARE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) ACPI_MODULE_NAME("hwxface")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * FUNCTION: acpi_reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * PARAMETERS: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * support reset register in PCI config space, this must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * handled separately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) acpi_status acpi_reset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct acpi_generic_address *reset_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ACPI_FUNCTION_TRACE(acpi_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) reset_reg = &acpi_gbl_FADT.reset_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* Check if the reset register is supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) !reset_reg->address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return_ACPI_STATUS(AE_NOT_EXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (reset_reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * For I/O space, write directly to the OSL. This bypasses the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * validation mechanism, which may block a valid write to the reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * NOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * The ACPI spec requires the reset register width to be 8, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * hardcode it here and ignore the FADT value. This maintains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * compatibility with other ACPI implementations that have allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * BIOS code with bad register width values to go unnoticed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) status = acpi_os_write_port((acpi_io_address)reset_reg->address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) acpi_gbl_FADT.reset_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ACPI_RESET_REGISTER_WIDTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* Write the reset value to the reset register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) status = acpi_hw_write(acpi_gbl_FADT.reset_value, reset_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ACPI_EXPORT_SYMBOL(acpi_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * FUNCTION: acpi_read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * PARAMETERS: value - Where the value is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * reg - GAS register structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * DESCRIPTION: Read from either memory or IO space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * LIMITATIONS: <These limitations also apply to acpi_write>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * bit_width must be exactly 8, 16, 32, or 64.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * space_ID must be system_memory or system_IO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * bit_offset and access_width are currently ignored, as there has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * not been a need to implement these.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ACPI_FUNCTION_NAME(acpi_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) status = acpi_hw_read(return_value, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ACPI_EXPORT_SYMBOL(acpi_read)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * FUNCTION: acpi_write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * PARAMETERS: value - Value to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * reg - GAS register structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * DESCRIPTION: Write to either memory or IO space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) acpi_status acpi_write(u64 value, struct acpi_generic_address *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ACPI_FUNCTION_NAME(acpi_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) status = acpi_hw_write(value, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ACPI_EXPORT_SYMBOL(acpi_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #if (!ACPI_REDUCED_HARDWARE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * FUNCTION: acpi_read_bit_register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * PARAMETERS: register_id - ID of ACPI Bit Register to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * return_value - Value that was read from the register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * normalized to bit position zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * RETURN: Status and the value read from the specified Register. Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * returned is normalized to bit0 (is shifted all the way right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * DESCRIPTION: ACPI bit_register read function. Does not acquire the HW lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * PM2 Control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Note: The hardware lock is not required when reading the ACPI bit registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * since almost all of them are single bit and it does not matter that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * the parent hardware register can be split across two physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * registers. The only multi-bit field is SLP_TYP in the PM1 control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * register, but this field does not cross an 8-bit boundary (nor does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * it make much sense to actually read this field.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) acpi_status acpi_read_bit_register(u32 register_id, u32 *return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct acpi_bit_register_info *bit_reg_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) u32 register_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ACPI_FUNCTION_TRACE_U32(acpi_read_bit_register, register_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* Get the info structure corresponding to the requested ACPI Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) bit_reg_info = acpi_hw_get_bit_register_info(register_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (!bit_reg_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* Read the entire parent register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) status = acpi_hw_register_read(bit_reg_info->parent_register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) ®ister_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* Normalize the value that was read, mask off other bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) value = ((register_value & bit_reg_info->access_bit_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) >> bit_reg_info->bit_position);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ACPI_DEBUG_PRINT((ACPI_DB_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) register_id, bit_reg_info->parent_register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) register_value, value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *return_value = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ACPI_EXPORT_SYMBOL(acpi_read_bit_register)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * FUNCTION: acpi_write_bit_register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * PARAMETERS: register_id - ID of ACPI Bit Register to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * value - Value to write to the register, in bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * position zero. The bit is automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * shifted to the correct position.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * since most operations require a read/modify/write sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * PM2 Control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * Note that at this level, the fact that there may be actually two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * hardware registers (A and B - and B may not exist) is abstracted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) acpi_status acpi_write_bit_register(u32 register_id, u32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct acpi_bit_register_info *bit_reg_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) acpi_cpu_flags lock_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) u32 register_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ACPI_FUNCTION_TRACE_U32(acpi_write_bit_register, register_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Get the info structure corresponding to the requested ACPI Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) bit_reg_info = acpi_hw_get_bit_register_info(register_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!bit_reg_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) lock_flags = acpi_os_acquire_raw_lock(acpi_gbl_hardware_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * At this point, we know that the parent register is one of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (bit_reg_info->parent_register != ACPI_REGISTER_PM1_STATUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * Perform a register read to preserve the bits that we are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * interested in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) status = acpi_hw_register_read(bit_reg_info->parent_register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ®ister_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) goto unlock_and_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * Insert the input bit into the value that was just read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * and write the register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ACPI_REGISTER_INSERT_VALUE(register_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) bit_reg_info->bit_position,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) bit_reg_info->access_bit_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) status = acpi_hw_register_write(bit_reg_info->parent_register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) register_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * 2) Case for PM1 Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * The Status register is different from the rest. Clear an event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * by writing 1, writing 0 has no effect. So, the only relevant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * information is the single bit we're interested in, all others
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * should be written as 0 so they will be left unchanged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) register_value = ACPI_REGISTER_PREPARE_BITS(value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) bit_reg_info->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) bit_position,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) bit_reg_info->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) access_bit_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* No need to write the register if value is all zeros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (register_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) register_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ACPI_DEBUG_PRINT((ACPI_DB_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) register_id, bit_reg_info->parent_register, value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) register_value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) unlock_and_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) acpi_os_release_raw_lock(acpi_gbl_hardware_lock, lock_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) ACPI_EXPORT_SYMBOL(acpi_write_bit_register)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #endif /* !ACPI_REDUCED_HARDWARE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * FUNCTION: acpi_get_sleep_type_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * PARAMETERS: sleep_state - Numeric sleep state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * *sleep_type_a - Where SLP_TYPa is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * *sleep_type_b - Where SLP_TYPb is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * sleep state via the appropriate \_Sx object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * The sleep state package returned from the corresponding \_Sx_ object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * must contain at least one integer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * March 2005:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * Added support for a package that contains two integers. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * goes against the ACPI specification which defines this object as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * package with one encoded DWORD integer. However, existing practice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * by many BIOS vendors is to return a package with 2 or more integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * elements, at least one per sleep type (A/B).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * January 2013:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * Therefore, we must be prepared to accept a package with either a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * single integer or multiple integers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * The single integer DWORD format is as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * BYTE 0 - Value for the PM1A SLP_TYP register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * BYTE 1 - Value for the PM1B SLP_TYP register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * BYTE 2-3 - Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * The dual integer format is as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * Integer 0 - Value for the PM1A SLP_TYP register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * Integer 1 - Value for the PM1A SLP_TYP register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct acpi_evaluate_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) union acpi_operand_object **elements;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) ACPI_FUNCTION_TRACE(acpi_get_sleep_type_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /* Validate parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if ((sleep_state > ACPI_S_STATES_MAX) || !sleep_type_a || !sleep_type_b) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return_ACPI_STATUS(AE_BAD_PARAMETER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /* Allocate the evaluation information block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (!info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * Evaluate the \_Sx namespace object containing the register values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * for this state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) info->relative_pathname = acpi_gbl_sleep_state_names[sleep_state];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) status = acpi_ns_evaluate(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (status == AE_NOT_FOUND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* The _Sx states are optional, ignore NOT_FOUND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) goto final_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) goto warning_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /* Must have a return object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (!info->return_object) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) info->relative_pathname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) status = AE_AML_NO_RETURN_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) goto warning_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /* Return object must be of type Package */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (info->return_object->common.type != ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) "Sleep State return object is not a Package"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) status = AE_AML_OPERAND_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) goto return_value_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * Any warnings about the package length or the object types have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * already been issued by the predefined name module -- there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * need to repeat them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) elements = info->return_object->package.elements;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) switch (info->return_object->package.count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) status = AE_AML_PACKAGE_LIMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (elements[0]->common.type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) status = AE_AML_OPERAND_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /* A valid _Sx_ package with one integer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) *sleep_type_a = (u8)elements[0]->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) *sleep_type_b = (u8)(elements[0]->integer.value >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if ((elements[0]->common.type != ACPI_TYPE_INTEGER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) (elements[1]->common.type != ACPI_TYPE_INTEGER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) status = AE_AML_OPERAND_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /* A valid _Sx_ package with two integers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) *sleep_type_a = (u8)elements[0]->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) *sleep_type_b = (u8)elements[1]->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return_value_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) acpi_ut_remove_reference(info->return_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) warning_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) ACPI_EXCEPTION((AE_INFO, status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) "While evaluating Sleep State [%s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) info->relative_pathname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) final_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ACPI_FREE(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) ACPI_EXPORT_SYMBOL(acpi_get_sleep_type_data)