^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: exstorob - AML object store support, store to object
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _COMPONENT ACPI_EXECUTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) ACPI_MODULE_NAME("exstorob")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * FUNCTION: acpi_ex_store_buffer_to_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * PARAMETERS: source_desc - Source object to copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * target_desc - Destination object of the copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * DESCRIPTION: Copy a buffer object to another buffer object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) acpi_ex_store_buffer_to_buffer(union acpi_operand_object *source_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) union acpi_operand_object *target_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u8 *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ACPI_FUNCTION_TRACE_PTR(ex_store_buffer_to_buffer, source_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* If Source and Target are the same, just return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (source_desc == target_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* We know that source_desc is a buffer by now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) buffer = ACPI_CAST_PTR(u8, source_desc->buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) length = source_desc->buffer.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * If target is a buffer of length zero or is a static buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * allocate a new buffer of the proper length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if ((target_desc->buffer.length == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) (target_desc->common.flags & AOPOBJ_STATIC_POINTER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) target_desc->buffer.pointer = ACPI_ALLOCATE(length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (!target_desc->buffer.pointer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return_ACPI_STATUS(AE_NO_MEMORY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) target_desc->buffer.length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Copy source buffer to target buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (length <= target_desc->buffer.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* Clear existing buffer and copy in the new one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) memset(target_desc->buffer.pointer, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) target_desc->buffer.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) memcpy(target_desc->buffer.pointer, buffer, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #ifdef ACPI_OBSOLETE_BEHAVIOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * NOTE: ACPI versions up to 3.0 specified that the buffer must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * truncated if the string is smaller than the buffer. However, "other"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * implementations of ACPI never did this and thus became the defacto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * standard. ACPI 3.0A changes this behavior such that the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * is no longer truncated.
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * OBSOLETE BEHAVIOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * If the original source was a string, we must truncate the buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * according to the ACPI spec. Integer-to-Buffer and Buffer-to-Buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * copy must not truncate the original buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (original_src_type == ACPI_TYPE_STRING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* Set the new length of the target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) target_desc->buffer.length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Truncate the source, copy only what will fit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) memcpy(target_desc->buffer.pointer, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) target_desc->buffer.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) "Truncating source buffer from %X to %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) length, target_desc->buffer.length));
^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) /* Copy flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) target_desc->buffer.flags = source_desc->buffer.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^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) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * FUNCTION: acpi_ex_store_string_to_string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * PARAMETERS: source_desc - Source object to copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * target_desc - Destination object of the copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * DESCRIPTION: Copy a String object to another String object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) *
^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_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) acpi_ex_store_string_to_string(union acpi_operand_object *source_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) union acpi_operand_object *target_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) u8 *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ACPI_FUNCTION_TRACE_PTR(ex_store_string_to_string, source_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* If Source and Target are the same, just return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (source_desc == target_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return_ACPI_STATUS(AE_OK);
^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) /* We know that source_desc is a string by now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) buffer = ACPI_CAST_PTR(u8, source_desc->string.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) length = source_desc->string.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * Replace existing string value if it will fit and the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * pointer is not a static pointer (part of an ACPI table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if ((length < target_desc->string.length) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * String will fit in existing non-static buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * Clear old string and copy in the new one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) memset(target_desc->string.pointer, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) (acpi_size)target_desc->string.length + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) memcpy(target_desc->string.pointer, buffer, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * Free the current buffer, then allocate a new buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * large enough to hold the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (target_desc->string.pointer &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* Only free if not a pointer into the DSDT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ACPI_FREE(target_desc->string.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) target_desc->string.pointer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ACPI_ALLOCATE_ZEROED((acpi_size)length + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (!target_desc->string.pointer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return_ACPI_STATUS(AE_NO_MEMORY);
^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) target_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) memcpy(target_desc->string.pointer, buffer, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* Set the new target length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) target_desc->string.length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }