^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: exfldio - Aml Field I/O
^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) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "acinterp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "amlcode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "acevents.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "acdispat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define _COMPONENT ACPI_EXECUTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ACPI_MODULE_NAME("exfldio")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) u32 field_datum_byte_offset, u64 *value, u32 read_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static u8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) acpi_ex_register_overflow(union acpi_operand_object *obj_desc, u64 value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) acpi_ex_setup_region(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u32 field_datum_byte_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * FUNCTION: acpi_ex_setup_region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * PARAMETERS: obj_desc - Field to be read or written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * field_datum_byte_offset - Byte offset of this datum within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * parent field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * DESCRIPTION: Common processing for acpi_ex_extract_from_field and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * acpi_ex_insert_into_field. Initialize the Region if necessary and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * validate the request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *
^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) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) acpi_ex_setup_region(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u32 field_datum_byte_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) union acpi_operand_object *rgn_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u8 space_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ACPI_FUNCTION_TRACE_U32(ex_setup_region, field_datum_byte_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) rgn_desc = obj_desc->common_field.region_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* We must have a valid region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (rgn_desc->common.type != ACPI_TYPE_REGION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ACPI_ERROR((AE_INFO, "Needed Region, found type 0x%X (%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) rgn_desc->common.type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) acpi_ut_get_object_type_name(rgn_desc)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) space_id = rgn_desc->region.space_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Validate the Space ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (!acpi_is_valid_space_id(space_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) "Invalid/unknown Address Space ID: 0x%2.2X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) space_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * If the Region Address and Length have not been previously evaluated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * evaluate them now and save the results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (!(rgn_desc->common.flags & AOPOBJ_DATA_VALID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) status = acpi_ds_get_region_arguments(rgn_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Exit now for SMBus, GSBus or IPMI address space, it has a non-linear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * address space and the request cannot be directly validated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (space_id == ACPI_ADR_SPACE_SMBUS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) space_id == ACPI_ADR_SPACE_GSBUS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) space_id == ACPI_ADR_SPACE_IPMI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* SMBus or IPMI has a non-linear address space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #ifdef ACPI_UNDER_DEVELOPMENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * If the Field access is any_acc, we can now compute the optimal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * access (because we know know the length of the parent region)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Validate the request. The entire request from the byte offset for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * length of one field datum (access width) must fit within the region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * (Region length is specified in bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (rgn_desc->region.length <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) (obj_desc->common_field.base_byte_offset + field_datum_byte_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) obj_desc->common_field.access_byte_width)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (acpi_gbl_enable_interpreter_slack) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * Slack mode only: We will go ahead and allow access to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * field if it is within the region length rounded up to the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * access width boundary. acpi_size cast for 64-bit compile.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (ACPI_ROUND_UP(rgn_desc->region.length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) access_byte_width) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ((acpi_size)obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) base_byte_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) obj_desc->common_field.access_byte_width +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) field_datum_byte_offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (rgn_desc->region.length <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) obj_desc->common_field.access_byte_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * This is the case where the access_type (acc_word, etc.) is wider
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * than the region itself. For example, a region of length one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * byte, and a field with Dword access specified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) "Field [%4.4s] access width (%u bytes) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) "too large for region [%4.4s] (length %u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) acpi_ut_get_node_name(obj_desc->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) common_field.node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) obj_desc->common_field.access_byte_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) acpi_ut_get_node_name(rgn_desc->region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) rgn_desc->region.length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * Offset rounded up to next multiple of field width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * exceeds region length, indicate an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) "Field [%4.4s] Base+Offset+Width %u+%u+%u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) "is beyond end of region [%4.4s] (length %u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) acpi_ut_get_node_name(obj_desc->common_field.node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) obj_desc->common_field.base_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) field_datum_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) obj_desc->common_field.access_byte_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) acpi_ut_get_node_name(rgn_desc->region.node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) rgn_desc->region.length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return_ACPI_STATUS(AE_AML_REGION_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * FUNCTION: acpi_ex_access_region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * PARAMETERS: obj_desc - Field to be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * field_datum_byte_offset - Byte offset of this datum within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * parent field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * value - Where to store value (must at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * 64 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * function - Read or Write flag plus other region-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * dependent flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * DESCRIPTION: Read or Write a single field datum to an Operation Region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) acpi_ex_access_region(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) u32 field_datum_byte_offset, u64 *value, u32 function)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) union acpi_operand_object *rgn_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u32 region_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ACPI_FUNCTION_TRACE(ex_access_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * Ensure that the region operands are fully evaluated and verify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * the validity of the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) status = acpi_ex_setup_region(obj_desc, field_datum_byte_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * The physical address of this field datum is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * 1) The base of the region, plus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * 2) The base offset of the field, plus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * 3) The current offset into the field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) rgn_desc = obj_desc->common_field.region_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) region_offset =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) obj_desc->common_field.base_byte_offset + field_datum_byte_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if ((function & ACPI_IO_MASK) == ACPI_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[READ]"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "[WRITE]"));
^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) ACPI_DEBUG_PRINT_RAW((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) " Region [%s:%X], Width %X, ByteBase %X, Offset %X at %8.8X%8.8X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) acpi_ut_get_region_name(rgn_desc->region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) space_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) rgn_desc->region.space_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) obj_desc->common_field.access_byte_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) obj_desc->common_field.base_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) field_datum_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ACPI_FORMAT_UINT64(rgn_desc->region.address +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) region_offset)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* Invoke the appropriate address_space/op_region handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) status = acpi_ev_address_space_dispatch(rgn_desc, obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) function, region_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ACPI_MUL_8(obj_desc->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) access_byte_width),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (status == AE_NOT_IMPLEMENTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) "Region %s (ID=%u) not implemented",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) acpi_ut_get_region_name(rgn_desc->region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) space_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) rgn_desc->region.space_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) } else if (status == AE_NOT_EXIST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) "Region %s (ID=%u) has no handler",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) acpi_ut_get_region_name(rgn_desc->region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) space_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) rgn_desc->region.space_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * FUNCTION: acpi_ex_register_overflow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * PARAMETERS: obj_desc - Register(Field) to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * value - Value to be stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * RETURN: TRUE if value overflows the field, FALSE otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * DESCRIPTION: Check if a value is out of range of the field being written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * Used to check if the values written to Index and Bank registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * are out of range. Normally, the value is simply truncated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * to fit the field, but this case is most likely a serious
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * coding error in the ASL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static u8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) acpi_ex_register_overflow(union acpi_operand_object *obj_desc, u64 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (obj_desc->common_field.bit_length >= ACPI_INTEGER_BIT_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * The field is large enough to hold the maximum integer, so we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * never overflow it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return (FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (value >= ((u64) 1 << obj_desc->common_field.bit_length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * The Value is larger than the maximum value that can fit into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * the register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) "Index value 0x%8.8X%8.8X overflows field width 0x%X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ACPI_FORMAT_UINT64(value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) obj_desc->common_field.bit_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return (TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /* The Value will fit into the field with no truncation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return (FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * FUNCTION: acpi_ex_field_datum_io
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * PARAMETERS: obj_desc - Field to be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * field_datum_byte_offset - Byte offset of this datum within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * parent field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * value - Where to store value (must be 64 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * read_write - Read or Write flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * DESCRIPTION: Read or Write a single datum of a field. The field_type is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * demultiplexed here to handle the different types of fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * (buffer_field, region_field, index_field, bank_field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) u32 field_datum_byte_offset, u64 *value, u32 read_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) u64 local_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ACPI_FUNCTION_TRACE_U32(ex_field_datum_io, field_datum_byte_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (read_write == ACPI_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (!value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) local_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /* To support reads without saving return value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) value = &local_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /* Clear the entire return buffer first, [Very Important!] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) *value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * The four types of fields are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * buffer_field - Read/write from/to a Buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * region_field - Read/write from/to a Operation Region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * bank_field - Write to a Bank Register, then read/write from/to an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * operation_region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * index_field - Write to an Index Register, then read/write from/to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * Data Register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) switch (obj_desc->common.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) case ACPI_TYPE_BUFFER_FIELD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * If the buffer_field arguments have not been previously evaluated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * evaluate them now and save the results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) status = acpi_ds_get_buffer_field_arguments(obj_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (read_write == ACPI_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * Copy the data from the source buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * Length is the field width in bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) memcpy(value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) (obj_desc->buffer_field.buffer_obj)->buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) pointer +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) obj_desc->buffer_field.base_byte_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) field_datum_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) obj_desc->common_field.access_byte_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * Copy the data to the target buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * Length is the field width in bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) memcpy((obj_desc->buffer_field.buffer_obj)->buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) pointer +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) obj_desc->buffer_field.base_byte_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) field_datum_byte_offset, value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) obj_desc->common_field.access_byte_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) case ACPI_TYPE_LOCAL_BANK_FIELD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * Ensure that the bank_value is not beyond the capacity of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * the register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (acpi_ex_register_overflow(obj_desc->bank_field.bank_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) (u64) obj_desc->bank_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * For bank_fields, we must write the bank_value to the bank_register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * (itself a region_field) before we can access the data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) acpi_ex_insert_into_field(obj_desc->bank_field.bank_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) &obj_desc->bank_field.value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) sizeof(obj_desc->bank_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^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) * Now that the Bank has been selected, fall through to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * region_field case and write the datum to the Operation Region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /*lint -fallthrough */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) case ACPI_TYPE_LOCAL_REGION_FIELD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * For simple region_fields, we just directly access the owning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * Operation Region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) acpi_ex_access_region(obj_desc, field_datum_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) value, read_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) case ACPI_TYPE_LOCAL_INDEX_FIELD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * Ensure that the index_value is not beyond the capacity of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * the register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (acpi_ex_register_overflow(obj_desc->index_field.index_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) (u64) obj_desc->index_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return_ACPI_STATUS(AE_AML_REGISTER_LIMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /* Write the index value to the index_register (itself a region_field) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) field_datum_byte_offset += obj_desc->index_field.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) "Write to Index Register: Value %8.8X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) field_datum_byte_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) acpi_ex_insert_into_field(obj_desc->index_field.index_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) &field_datum_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) sizeof(field_datum_byte_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (read_write == ACPI_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* Read the datum from the data_register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) "Read from Data Register\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) acpi_ex_extract_from_field(obj_desc->index_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) data_obj, value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* Write the datum to the data_register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) "Write to Data Register: Value %8.8X%8.8X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) ACPI_FORMAT_UINT64(*value)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) acpi_ex_insert_into_field(obj_desc->index_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) data_obj, value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) obj_desc->common.type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) status = AE_AML_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (read_write == ACPI_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) "Value Read %8.8X%8.8X, Width %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) ACPI_FORMAT_UINT64(*value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) access_byte_width));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) "Value Written %8.8X%8.8X, Width %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) ACPI_FORMAT_UINT64(*value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) access_byte_width));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * FUNCTION: acpi_ex_write_with_update_rule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * PARAMETERS: obj_desc - Field to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * mask - bitmask within field datum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * field_value - Value to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * field_datum_byte_offset - Offset of datum within field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * DESCRIPTION: Apply the field update rule to a field write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) acpi_ex_write_with_update_rule(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) u64 mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) u64 field_value, u32 field_datum_byte_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) u64 merged_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) u64 current_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) ACPI_FUNCTION_TRACE_U32(ex_write_with_update_rule, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /* Start with the new bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) merged_value = field_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /* If the mask is all ones, we don't need to worry about the update rule */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (mask != ACPI_UINT64_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /* Decode the update rule */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) switch (obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) field_flags & AML_FIELD_UPDATE_RULE_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) case AML_FIELD_UPDATE_PRESERVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * Check if update rule needs to be applied (not if mask is all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * ones) The left shift drops the bits we want to ignore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if ((~mask << (ACPI_MUL_8(sizeof(mask)) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) ACPI_MUL_8(obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) access_byte_width))) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * Read the current contents of the byte/word/dword containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * the field, and merge with the new field value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) acpi_ex_field_datum_io(obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) field_datum_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) ¤t_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) ACPI_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) merged_value |= (current_value & ~mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) case AML_FIELD_UPDATE_WRITE_AS_ONES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) /* Set positions outside the field to all ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) merged_value |= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) case AML_FIELD_UPDATE_WRITE_AS_ZEROS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) /* Set positions outside the field to all zeros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) merged_value &= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) "Unknown UpdateRule value: 0x%X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) (obj_desc->common_field.field_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) AML_FIELD_UPDATE_RULE_MASK)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) "Mask %8.8X%8.8X, DatumOffset %X, Width %X, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) "Value %8.8X%8.8X, MergedValue %8.8X%8.8X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) ACPI_FORMAT_UINT64(mask),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) field_datum_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) obj_desc->common_field.access_byte_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) ACPI_FORMAT_UINT64(field_value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) ACPI_FORMAT_UINT64(merged_value)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /* Write the merged value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) acpi_ex_field_datum_io(obj_desc, field_datum_byte_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) &merged_value, ACPI_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * FUNCTION: acpi_ex_extract_from_field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * PARAMETERS: obj_desc - Field to be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * buffer - Where to store the field data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * buffer_length - Length of Buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) * DESCRIPTION: Retrieve the current value of the given field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) void *buffer, u32 buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) u64 raw_datum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) u64 merged_datum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) u32 field_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) u32 buffer_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) u32 buffer_tail_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) u32 datum_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) u32 field_datum_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) u32 access_bit_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) ACPI_FUNCTION_TRACE(ex_extract_from_field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) /* Validate target buffer and clear it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (buffer_length <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) ACPI_ERROR((AE_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) "Field size %u (bits) is too large for buffer (%u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) obj_desc->common_field.bit_length, buffer_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) memset(buffer, 0, buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) access_bit_width = ACPI_MUL_8(obj_desc->common_field.access_byte_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) /* Handle the simple case here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if ((obj_desc->common_field.start_field_bit_offset == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) (obj_desc->common_field.bit_length == access_bit_width)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (buffer_length >= sizeof(u64)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) acpi_ex_field_datum_io(obj_desc, 0, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) ACPI_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* Use raw_datum (u64) to handle buffers < 64 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) acpi_ex_field_datum_io(obj_desc, 0, &raw_datum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) ACPI_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) memcpy(buffer, &raw_datum, buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* TBD: Move to common setup code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) /* Field algorithm is limited to sizeof(u64), truncate if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if (obj_desc->common_field.access_byte_width > sizeof(u64)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) obj_desc->common_field.access_byte_width = sizeof(u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) access_bit_width = sizeof(u64) * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) /* Compute the number of datums (access width data items) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) datum_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) access_bit_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) start_field_bit_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) access_bit_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) /* Priming read from the field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) acpi_ex_field_datum_io(obj_desc, field_offset, &raw_datum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) ACPI_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) merged_datum =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) raw_datum >> obj_desc->common_field.start_field_bit_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /* Read the rest of the field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) for (i = 1; i < field_datum_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) /* Get next input datum from the field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) field_offset += obj_desc->common_field.access_byte_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) acpi_ex_field_datum_io(obj_desc, field_offset, &raw_datum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) ACPI_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * Merge with previous datum if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * Note: Before the shift, check if the shift value will be larger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * the integer size. If so, there is no need to perform the operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) * This avoids the differences in behavior between different compilers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * concerning shift values larger than the target data width.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (access_bit_width -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) obj_desc->common_field.start_field_bit_offset <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) ACPI_INTEGER_BIT_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) merged_datum |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) raw_datum << (access_bit_width -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) start_field_bit_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (i == datum_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) /* Write merged datum to target buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) memcpy(((char *)buffer) + buffer_offset, &merged_datum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) ACPI_MIN(obj_desc->common_field.access_byte_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) buffer_length - buffer_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) buffer_offset += obj_desc->common_field.access_byte_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) merged_datum =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) raw_datum >> obj_desc->common_field.start_field_bit_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /* Mask off any extra bits in the last datum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) buffer_tail_bits = obj_desc->common_field.bit_length % access_bit_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (buffer_tail_bits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) merged_datum &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) /* Write the last datum to the buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) memcpy(((char *)buffer) + buffer_offset, &merged_datum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) ACPI_MIN(obj_desc->common_field.access_byte_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) buffer_length - buffer_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * FUNCTION: acpi_ex_insert_into_field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * PARAMETERS: obj_desc - Field to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * buffer - Data to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * buffer_length - Length of Buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * DESCRIPTION: Store the Buffer contents into the given field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) void *buffer, u32 buffer_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) void *new_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) u64 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) u64 width_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) u64 merged_datum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) u64 raw_datum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) u32 field_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) u32 buffer_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) u32 buffer_tail_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) u32 datum_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) u32 field_datum_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) u32 access_bit_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) u32 required_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) ACPI_FUNCTION_TRACE(ex_insert_into_field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) /* Validate input buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) new_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) required_length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * We must have a buffer that is at least as long as the field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * we are writing to. This is because individual fields are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) * indivisible and partial writes are not supported -- as per
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) * the ACPI specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (buffer_length < required_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) /* We need to create a new buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) new_buffer = ACPI_ALLOCATE_ZEROED(required_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (!new_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) * Copy the original data to the new buffer, starting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * at Byte zero. All unused (upper) bytes of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * buffer will be 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) memcpy((char *)new_buffer, (char *)buffer, buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) buffer = new_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) buffer_length = required_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) /* TBD: Move to common setup code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) /* Algo is limited to sizeof(u64), so cut the access_byte_width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (obj_desc->common_field.access_byte_width > sizeof(u64)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) obj_desc->common_field.access_byte_width = sizeof(u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) access_bit_width = ACPI_MUL_8(obj_desc->common_field.access_byte_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) /* Create the bitmasks used for bit insertion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) width_mask = ACPI_MASK_BITS_ABOVE_64(access_bit_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) mask = width_mask &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) ACPI_MASK_BITS_BELOW(obj_desc->common_field.start_field_bit_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) /* Compute the number of datums (access width data items) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) access_bit_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) field_datum_count = ACPI_ROUND_UP_TO(obj_desc->common_field.bit_length +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) start_field_bit_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) access_bit_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) /* Get initial Datum from the input buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) memcpy(&raw_datum, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) ACPI_MIN(obj_desc->common_field.access_byte_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) buffer_length - buffer_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) merged_datum =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) raw_datum << obj_desc->common_field.start_field_bit_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) /* Write the entire field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) for (i = 1; i < field_datum_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) /* Write merged datum to the target field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) merged_datum &= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) acpi_ex_write_with_update_rule(obj_desc, mask, merged_datum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) field_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) field_offset += obj_desc->common_field.access_byte_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * Start new output datum by merging with previous input datum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) * Note: Before the shift, check if the shift value will be larger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * the integer size. If so, there is no need to perform the operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * This avoids the differences in behavior between different compilers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) * concerning shift values larger than the target data width.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) if ((access_bit_width -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) obj_desc->common_field.start_field_bit_offset) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) ACPI_INTEGER_BIT_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) merged_datum =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) raw_datum >> (access_bit_width -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) obj_desc->common_field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) start_field_bit_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) merged_datum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) mask = width_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) if (i == datum_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) /* Get the next input datum from the buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) buffer_offset += obj_desc->common_field.access_byte_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) memcpy(&raw_datum, ((char *)buffer) + buffer_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) ACPI_MIN(obj_desc->common_field.access_byte_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) buffer_length - buffer_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) merged_datum |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) raw_datum << obj_desc->common_field.start_field_bit_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) /* Mask off any extra bits in the last datum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) buffer_tail_bits = (obj_desc->common_field.bit_length +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) obj_desc->common_field.start_field_bit_offset) %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) access_bit_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (buffer_tail_bits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) mask &= ACPI_MASK_BITS_ABOVE(buffer_tail_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) /* Write the last datum to the field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) merged_datum &= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) acpi_ex_write_with_update_rule(obj_desc, mask, merged_datum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) field_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) /* Free temporary buffer if we used one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) if (new_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) ACPI_FREE(new_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) return_ACPI_STATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) }