acpi_status acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc, union acpi_operand_object **result_desc) { union acpi_operand_object *return_desc; u8 *new_buf; ACPI_FUNCTION_TRACE_PTR(ex_convert_to_buffer, obj_desc); switch (obj_desc->common.type) { case ACPI_TYPE_BUFFER: /* No conversion necessary */ *result_desc = obj_desc; return_ACPI_STATUS(AE_OK); case ACPI_TYPE_INTEGER: /* * Create a new Buffer object. * Need enough space for one integer */ return_desc = acpi_ut_create_buffer_object(acpi_gbl_integer_byte_width); if (!return_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Copy the integer to the buffer, LSB first */ new_buf = return_desc->buffer.pointer; ACPI_MEMCPY(new_buf, &obj_desc->integer.value, acpi_gbl_integer_byte_width); break; case ACPI_TYPE_STRING: /* * Create a new Buffer object * Size will be the string length * * NOTE: Add one to the string length to include the null terminator. * The ACPI spec is unclear on this subject, but there is existing * ASL/AML code that depends on the null being transferred to the new * buffer. */ return_desc = acpi_ut_create_buffer_object((acpi_size) obj_desc->string. length + 1); if (!return_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Copy the string to the buffer */ new_buf = return_desc->buffer.pointer; ACPI_STRNCPY((char *)new_buf, (char *)obj_desc->string.pointer, obj_desc->string.length); break; default: return_ACPI_STATUS(AE_TYPE); } /* Mark buffer initialized */ return_desc->common.flags |= AOPOBJ_DATA_VALID; *result_desc = return_desc; return_ACPI_STATUS(AE_OK); }
acpi_status acpi_ex_write_data_to_field(union acpi_operand_object *source_desc, union acpi_operand_object *obj_desc, union acpi_operand_object **result_desc) { acpi_status status; u32 length; void *buffer; union acpi_operand_object *buffer_desc; u32 function; u16 accessor_type; ACPI_FUNCTION_TRACE_PTR(ex_write_data_to_field, obj_desc); /* Parameter validation */ if (!source_desc || !obj_desc) { return_ACPI_STATUS(AE_AML_NO_OPERAND); } if (obj_desc->common.type == ACPI_TYPE_BUFFER_FIELD) { /* * If the buffer_field arguments have not been previously evaluated, * evaluate them now and save the results. */ if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { status = acpi_ds_get_buffer_field_arguments(obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } } else if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) && (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_SMBUS || obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS || obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_IPMI)) { /* * This is an SMBus, GSBus or IPMI write. We will bypass the entire field * mechanism and handoff the buffer directly to the handler. For * these address spaces, the buffer is bi-directional; on a write, * return data is returned in the same buffer. * * Source must be a buffer of sufficient size: * ACPI_SMBUS_BUFFER_SIZE, ACPI_GSBUS_BUFFER_SIZE, or ACPI_IPMI_BUFFER_SIZE. * * Note: SMBus and GSBus protocol type is passed in upper 16-bits of Function */ if (source_desc->common.type != ACPI_TYPE_BUFFER) { ACPI_ERROR((AE_INFO, "SMBus/IPMI/GenericSerialBus write requires Buffer, found type %s", acpi_ut_get_object_type_name(source_desc))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } if (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_SMBUS) { length = ACPI_SMBUS_BUFFER_SIZE; function = ACPI_WRITE | (obj_desc->field.attribute << 16); } else if (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS) { accessor_type = obj_desc->field.attribute; length = acpi_ex_get_serial_access_length(accessor_type, obj_desc-> field. access_length); /* * Add additional 2 bytes for the generic_serial_bus data buffer: * * Status; (Byte 0 of the data buffer) * Length; (Byte 1 of the data buffer) * Data[x-1]; (Bytes 2-x of the arbitrary length data buffer) */ length += 2; function = ACPI_WRITE | (accessor_type << 16); } else { /* IPMI */ length = ACPI_IPMI_BUFFER_SIZE; function = ACPI_WRITE; } if (source_desc->buffer.length < length) { ACPI_ERROR((AE_INFO, "SMBus/IPMI/GenericSerialBus write requires Buffer of length %u, found length %u", length, source_desc->buffer.length)); return_ACPI_STATUS(AE_AML_BUFFER_LIMIT); } /* Create the bi-directional buffer */ buffer_desc = acpi_ut_create_buffer_object(length); if (!buffer_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } buffer = buffer_desc->buffer.pointer; ACPI_MEMCPY(buffer, source_desc->buffer.pointer, length); /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* * Perform the write (returns status and perhaps data in the * same buffer) */ status = acpi_ex_access_region(obj_desc, 0, (u64 *) buffer, function); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); *result_desc = buffer_desc; return_ACPI_STATUS(status); } else if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) && (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_GPIO)) { /* * For GPIO (general_purpose_io), we will bypass the entire field * mechanism and handoff the bit address and bit width directly to * the handler. The Address will be the bit offset * from the previous Connection() operator, making it effectively a * pin number index. The bit_length is the length of the field, which * is thus the number of pins. */ if (source_desc->common.type != ACPI_TYPE_INTEGER) { return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "GPIO FieldWrite [FROM]: (%s:%X), Val %.8X [TO]: Pin %u Bits %u\n", acpi_ut_get_type_name(source_desc->common. type), source_desc->common.type, (u32)source_desc->integer.value, obj_desc->field.pin_number_index, obj_desc->field.bit_length)); buffer = &source_desc->integer.value; /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* Perform the write */ status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, ACPI_WRITE); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); return_ACPI_STATUS(status); } /* Get a pointer to the data to be written */ switch (source_desc->common.type) { case ACPI_TYPE_INTEGER: buffer = &source_desc->integer.value; length = sizeof(source_desc->integer.value); break; case ACPI_TYPE_BUFFER: buffer = source_desc->buffer.pointer; length = source_desc->buffer.length; break; case ACPI_TYPE_STRING: buffer = source_desc->string.pointer; length = source_desc->string.length; break; default: return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n", source_desc, acpi_ut_get_type_name(source_desc->common.type), source_desc->common.type, buffer, length)); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n", obj_desc, acpi_ut_get_type_name(obj_desc->common.type), obj_desc->common.type, obj_desc->common_field.bit_length, obj_desc->common_field.start_field_bit_offset, obj_desc->common_field.base_byte_offset)); /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* Write to the field */ status = acpi_ex_insert_into_field(obj_desc, buffer, length); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); return_ACPI_STATUS(status); }
static acpi_status acpi_ns_repair_FDE(struct acpi_predefined_data *data, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *return_object = *return_object_ptr; union acpi_operand_object *buffer_object; u8 *byte_buffer; u32 *dword_buffer; u32 i; ACPI_FUNCTION_NAME(ns_repair_FDE); switch (return_object->common.type) { case ACPI_TYPE_BUFFER: /* This is the expected type. Length should be (at least) 5 DWORDs */ if (return_object->buffer.length >= ACPI_FDE_DWORD_BUFFER_SIZE) { return (AE_OK); } /* We can only repair if we have exactly 5 BYTEs */ if (return_object->buffer.length != ACPI_FDE_BYTE_BUFFER_SIZE) { ACPI_WARN_PREDEFINED((AE_INFO, data->pathname, data->node_flags, "Incorrect return buffer length %u, expected %u", return_object->buffer.length, ACPI_FDE_DWORD_BUFFER_SIZE)); return (AE_AML_OPERAND_TYPE); } /* Create the new (larger) buffer object */ buffer_object = acpi_ut_create_buffer_object(ACPI_FDE_DWORD_BUFFER_SIZE); if (!buffer_object) { return (AE_NO_MEMORY); } /* Expand each byte to a DWORD */ byte_buffer = return_object->buffer.pointer; dword_buffer = ACPI_CAST_PTR(u32, buffer_object->buffer.pointer); for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++) { *dword_buffer = (u32) *byte_buffer; dword_buffer++; byte_buffer++; } ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, "%s Expanded Byte Buffer to expected DWord Buffer\n", data->pathname)); break; default: return (AE_AML_OPERAND_TYPE); } /* Delete the original return object, return the new buffer object */ acpi_ut_remove_reference(return_object); *return_object_ptr = buffer_object; data->flags |= ACPI_OBJECT_REPAIRED; return (AE_OK); }
acpi_status acpi_ex_read_data_from_field(struct acpi_walk_state * walk_state, union acpi_operand_object *obj_desc, union acpi_operand_object **ret_buffer_desc) { acpi_status status; union acpi_operand_object *buffer_desc; acpi_size length; void *buffer; u32 function; u16 accessor_type; ACPI_FUNCTION_TRACE_PTR(ex_read_data_from_field, obj_desc); /* Parameter validation */ if (!obj_desc) { return_ACPI_STATUS(AE_AML_NO_OPERAND); } if (!ret_buffer_desc) { return_ACPI_STATUS(AE_BAD_PARAMETER); } if (obj_desc->common.type == ACPI_TYPE_BUFFER_FIELD) { /* * If the buffer_field arguments have not been previously evaluated, * evaluate them now and save the results. */ if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { status = acpi_ds_get_buffer_field_arguments(obj_desc); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } } } else if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) && (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_SMBUS || obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS || obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_IPMI)) { /* * This is an SMBus, GSBus or IPMI read. We must create a buffer to hold * the data and then directly access the region handler. * * Note: SMBus and GSBus protocol value is passed in upper 16-bits of Function */ if (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_SMBUS) { length = ACPI_SMBUS_BUFFER_SIZE; function = ACPI_READ | (obj_desc->field.attribute << 16); } else if (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS) { accessor_type = obj_desc->field.attribute; length = acpi_ex_get_serial_access_length(accessor_type, obj_desc-> field. access_length); /* * Add additional 2 bytes for the generic_serial_bus data buffer: * * Status; (Byte 0 of the data buffer) * Length; (Byte 1 of the data buffer) * Data[x-1]; (Bytes 2-x of the arbitrary length data buffer) */ length += 2; function = ACPI_READ | (accessor_type << 16); } else { /* IPMI */ length = ACPI_IPMI_BUFFER_SIZE; function = ACPI_READ; } buffer_desc = acpi_ut_create_buffer_object(length); if (!buffer_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* Call the region handler for the read */ status = acpi_ex_access_region(obj_desc, 0, ACPI_CAST_PTR(u64, buffer_desc-> buffer.pointer), function); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); goto exit; } /* * Allocate a buffer for the contents of the field. * * If the field is larger than the current integer width, create * a BUFFER to hold it. Otherwise, use an INTEGER. This allows * the use of arithmetic operators on the returned value if the * field size is equal or smaller than an Integer. * * Note: Field.length is in bits. */ length = (acpi_size) ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->field.bit_length); if (length > acpi_gbl_integer_byte_width) { /* Field is too large for an Integer, create a Buffer instead */ buffer_desc = acpi_ut_create_buffer_object(length); if (!buffer_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } buffer = buffer_desc->buffer.pointer; } else { /* Field will fit within an Integer (normal case) */ buffer_desc = acpi_ut_create_integer_object((u64) 0); if (!buffer_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } length = acpi_gbl_integer_byte_width; buffer = &buffer_desc->integer.value; } if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) && (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_GPIO)) { /* * For GPIO (general_purpose_io), the Address will be the bit offset * from the previous Connection() operator, making it effectively a * pin number index. The bit_length is the length of the field, which * is thus the number of pins. */ ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "GPIO FieldRead [FROM]: Pin %u Bits %u\n", obj_desc->field.pin_number_index, obj_desc->field.bit_length)); /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* Perform the write */ status = acpi_ex_access_region(obj_desc, 0, (u64 *)buffer, ACPI_READ); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); if (ACPI_FAILURE(status)) { acpi_ut_remove_reference(buffer_desc); } else { *ret_buffer_desc = buffer_desc; } return_ACPI_STATUS(status); } ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n", obj_desc, obj_desc->common.type, buffer, (u32) length)); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n", obj_desc->common_field.bit_length, obj_desc->common_field.start_field_bit_offset, obj_desc->common_field.base_byte_offset)); /* Lock entire transaction if requested */ acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags); /* Read from the field */ status = acpi_ex_extract_from_field(obj_desc, buffer, (u32) length); acpi_ex_release_global_lock(obj_desc->common_field.field_flags); exit: if (ACPI_FAILURE(status)) { acpi_ut_remove_reference(buffer_desc); } else { *ret_buffer_desc = buffer_desc; } return_ACPI_STATUS(status); }
acpi_status acpi_ns_repair_null_element(struct acpi_evaluate_info * info, u32 expected_btypes, u32 package_index, union acpi_operand_object **return_object_ptr) { union acpi_operand_object *return_object = *return_object_ptr; union acpi_operand_object *new_object; ACPI_FUNCTION_NAME(ns_repair_null_element); /* No repair needed if return object is non-NULL */ if (return_object) { return (AE_OK); } /* * Attempt to repair a NULL element of a Package object. This applies to * predefined names that return a fixed-length package and each element * is required. It does not apply to variable-length packages where NULL * elements are allowed, especially at the end of the package. */ if (expected_btypes & ACPI_RTYPE_INTEGER) { /* Need an integer - create a zero-value integer */ new_object = acpi_ut_create_integer_object((u64)0); } else if (expected_btypes & ACPI_RTYPE_STRING) { /* Need a string - create a NULL string */ new_object = acpi_ut_create_string_object(0); } else if (expected_btypes & ACPI_RTYPE_BUFFER) { /* Need a buffer - create a zero-length buffer */ new_object = acpi_ut_create_buffer_object(0); } else { /* Error for all other expected types */ return (AE_AML_OPERAND_TYPE); } if (!new_object) { return (AE_NO_MEMORY); } /* Set the reference count according to the parent Package object */ new_object->common.reference_count = info->parent_package->common.reference_count; ACPI_DEBUG_PRINT((ACPI_DB_REPAIR, "%s: Converted NULL package element to expected %s at index %u\n", info->full_pathname, acpi_ut_get_object_type_name(new_object), package_index)); *return_object_ptr = new_object; info->return_flags |= ACPI_OBJECT_REPAIRED; return (AE_OK); }
acpi_status acpi_ex_do_concatenate ( union acpi_operand_object *operand0, union acpi_operand_object *operand1, union acpi_operand_object **actual_return_desc, struct acpi_walk_state *walk_state) { union acpi_operand_object *local_operand1 = operand1; union acpi_operand_object *return_desc; char *new_buf; acpi_status status; acpi_size new_length; ACPI_FUNCTION_TRACE ("ex_do_concatenate"); /* * Convert the second operand if necessary. The first operand * determines the type of the second operand, (See the Data Types * section of the ACPI specification.) Both object types are * guaranteed to be either Integer/String/Buffer by the operand * resolution mechanism. */ switch (ACPI_GET_OBJECT_TYPE (operand0)) { case ACPI_TYPE_INTEGER: status = acpi_ex_convert_to_integer (operand1, &local_operand1, 16); break; case ACPI_TYPE_STRING: status = acpi_ex_convert_to_string (operand1, &local_operand1, ACPI_IMPLICIT_CONVERT_HEX); break; case ACPI_TYPE_BUFFER: status = acpi_ex_convert_to_buffer (operand1, &local_operand1); break; default: ACPI_REPORT_ERROR (("Concat - invalid obj type: %X\n", ACPI_GET_OBJECT_TYPE (operand0))); status = AE_AML_INTERNAL; } if (ACPI_FAILURE (status)) { goto cleanup; } /* * Both operands are now known to be the same object type * (Both are Integer, String, or Buffer), and we can now perform the * concatenation. */ /* * There are three cases to handle: * * 1) Two Integers concatenated to produce a new Buffer * 2) Two Strings concatenated to produce a new String * 3) Two Buffers concatenated to produce a new Buffer */ switch (ACPI_GET_OBJECT_TYPE (operand0)) { case ACPI_TYPE_INTEGER: /* Result of two Integers is a Buffer */ /* Need enough buffer space for two integers */ return_desc = acpi_ut_create_buffer_object ( ACPI_MUL_2 (acpi_gbl_integer_byte_width)); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } new_buf = (char *) return_desc->buffer.pointer; /* Copy the first integer, LSB first */ ACPI_MEMCPY (new_buf, &operand0->integer.value, acpi_gbl_integer_byte_width); /* Copy the second integer (LSB first) after the first */ ACPI_MEMCPY (new_buf + acpi_gbl_integer_byte_width, &local_operand1->integer.value, acpi_gbl_integer_byte_width); break; case ACPI_TYPE_STRING: /* Result of two Strings is a String */ new_length = (acpi_size) operand0->string.length + (acpi_size) local_operand1->string.length; if (new_length > ACPI_MAX_STRING_CONVERSION) { status = AE_AML_STRING_LIMIT; goto cleanup; } return_desc = acpi_ut_create_string_object (new_length); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } new_buf = return_desc->string.pointer; /* Concatenate the strings */ ACPI_STRCPY (new_buf, operand0->string.pointer); ACPI_STRCPY (new_buf + operand0->string.length, local_operand1->string.pointer); break; case ACPI_TYPE_BUFFER: /* Result of two Buffers is a Buffer */ return_desc = acpi_ut_create_buffer_object ( (acpi_size) operand0->buffer.length + (acpi_size) local_operand1->buffer.length); if (!return_desc) { status = AE_NO_MEMORY; goto cleanup; } new_buf = (char *) return_desc->buffer.pointer; /* Concatenate the buffers */ ACPI_MEMCPY (new_buf, operand0->buffer.pointer, operand0->buffer.length); ACPI_MEMCPY (new_buf + operand0->buffer.length, local_operand1->buffer.pointer, local_operand1->buffer.length); break; default: /* Invalid object type, should not happen here */ ACPI_REPORT_ERROR (("Concatenate - Invalid object type: %X\n", ACPI_GET_OBJECT_TYPE (operand0))); status =AE_AML_INTERNAL; goto cleanup; } *actual_return_desc = return_desc; cleanup: if (local_operand1 != operand1) { acpi_ut_remove_reference (local_operand1); } return_ACPI_STATUS (status); }
acpi_status acpi_ex_read_data_from_field ( struct acpi_walk_state *walk_state, union acpi_operand_object *obj_desc, union acpi_operand_object **ret_buffer_desc) { acpi_status status; union acpi_operand_object *buffer_desc; acpi_size length; void *buffer; u8 locked; ACPI_FUNCTION_TRACE_PTR ("ex_read_data_from_field", obj_desc); /* Parameter validation */ if (!obj_desc) { return_ACPI_STATUS (AE_AML_NO_OPERAND); } if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_BUFFER_FIELD) { /* * If the buffer_field arguments have not been previously evaluated, * evaluate them now and save the results. */ if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { status = acpi_ds_get_buffer_field_arguments (obj_desc); if (ACPI_FAILURE (status)) { return_ACPI_STATUS (status); } } } else if ((ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD) && (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_SMBUS)) { /* * This is an SMBus read. We must create a buffer to hold the data * and directly access the region handler. */ buffer_desc = acpi_ut_create_buffer_object (ACPI_SMBUS_BUFFER_SIZE); if (!buffer_desc) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Lock entire transaction if requested */ locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); /* * Perform the read. * Note: Smbus protocol value is passed in upper 16-bits of Function */ status = acpi_ex_access_region (obj_desc, 0, ACPI_CAST_PTR (acpi_integer, buffer_desc->buffer.pointer), ACPI_READ | (obj_desc->field.attribute << 16)); acpi_ex_release_global_lock (locked); goto exit; } /* * Allocate a buffer for the contents of the field. * * If the field is larger than the size of an acpi_integer, create * a BUFFER to hold it. Otherwise, use an INTEGER. This allows * the use of arithmetic operators on the returned value if the * field size is equal or smaller than an Integer. * * Note: Field.length is in bits. */ length = (acpi_size) ACPI_ROUND_BITS_UP_TO_BYTES (obj_desc->field.bit_length); if (length > acpi_gbl_integer_byte_width) { /* Field is too large for an Integer, create a Buffer instead */ buffer_desc = acpi_ut_create_buffer_object (length); if (!buffer_desc) { return_ACPI_STATUS (AE_NO_MEMORY); } buffer = buffer_desc->buffer.pointer; } else { /* Field will fit within an Integer (normal case) */ buffer_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); if (!buffer_desc) { return_ACPI_STATUS (AE_NO_MEMORY); } length = acpi_gbl_integer_byte_width; buffer_desc->integer.value = 0; buffer = &buffer_desc->integer.value; } ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "field_read [TO]: Obj %p, Type %X, Buf %p, byte_len %X\n", obj_desc, ACPI_GET_OBJECT_TYPE (obj_desc), buffer, (u32) length)); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "field_read [FROM]: bit_len %X, bit_off %X, byte_off %X\n", obj_desc->common_field.bit_length, obj_desc->common_field.start_field_bit_offset, obj_desc->common_field.base_byte_offset)); /* Lock entire transaction if requested */ locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); /* Read from the field */ status = acpi_ex_extract_from_field (obj_desc, buffer, (u32) length); acpi_ex_release_global_lock (locked); exit: if (ACPI_FAILURE (status)) { acpi_ut_remove_reference (buffer_desc); } else if (ret_buffer_desc) { *ret_buffer_desc = buffer_desc; } return_ACPI_STATUS (status); }
acpi_status acpi_ex_write_data_to_field ( union acpi_operand_object *source_desc, union acpi_operand_object *obj_desc, union acpi_operand_object **result_desc) { acpi_status status; u32 length; u32 required_length; void *buffer; void *new_buffer; u8 locked; union acpi_operand_object *buffer_desc; ACPI_FUNCTION_TRACE_PTR ("ex_write_data_to_field", obj_desc); /* Parameter validation */ if (!source_desc || !obj_desc) { return_ACPI_STATUS (AE_AML_NO_OPERAND); } if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_BUFFER_FIELD) { /* * If the buffer_field arguments have not been previously evaluated, * evaluate them now and save the results. */ if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) { status = acpi_ds_get_buffer_field_arguments (obj_desc); if (ACPI_FAILURE (status)) { return_ACPI_STATUS (status); } } } else if ((ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_LOCAL_REGION_FIELD) && (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_SMBUS)) { /* * This is an SMBus write. We will bypass the entire field mechanism * and handoff the buffer directly to the handler. * * Source must be a buffer of sufficient size (ACPI_SMBUS_BUFFER_SIZE). */ if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) { ACPI_REPORT_ERROR (("SMBus write requires Buffer, found type %s\n", acpi_ut_get_object_type_name (source_desc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } if (source_desc->buffer.length < ACPI_SMBUS_BUFFER_SIZE) { ACPI_REPORT_ERROR (("SMBus write requires Buffer of length %X, found length %X\n", ACPI_SMBUS_BUFFER_SIZE, source_desc->buffer.length)); return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); } buffer_desc = acpi_ut_create_buffer_object (ACPI_SMBUS_BUFFER_SIZE); if (!buffer_desc) { return_ACPI_STATUS (AE_NO_MEMORY); } buffer = buffer_desc->buffer.pointer; ACPI_MEMCPY (buffer, source_desc->buffer.pointer, ACPI_SMBUS_BUFFER_SIZE); /* Lock entire transaction if requested */ locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); /* * Perform the write (returns status and perhaps data in the same buffer) * Note: SMBus protocol type is passed in upper 16-bits of Function. */ status = acpi_ex_access_region (obj_desc, 0, (acpi_integer *) buffer, ACPI_WRITE | (obj_desc->field.attribute << 16)); acpi_ex_release_global_lock (locked); *result_desc = buffer_desc; return_ACPI_STATUS (status); } /* * Get a pointer to the data to be written */ switch (ACPI_GET_OBJECT_TYPE (source_desc)) { case ACPI_TYPE_INTEGER: buffer = &source_desc->integer.value; length = sizeof (source_desc->integer.value); break; case ACPI_TYPE_BUFFER: buffer = source_desc->buffer.pointer; length = source_desc->buffer.length; break; case ACPI_TYPE_STRING: buffer = source_desc->string.pointer; length = source_desc->string.length; break; default: return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* * We must have a buffer that is at least as long as the field * we are writing to. This is because individual fields are * indivisible and partial writes are not supported -- as per * the ACPI specification. */ new_buffer = NULL; required_length = ACPI_ROUND_BITS_UP_TO_BYTES (obj_desc->common_field.bit_length); if (length < required_length) { /* We need to create a new buffer */ new_buffer = ACPI_MEM_CALLOCATE (required_length); if (!new_buffer) { return_ACPI_STATUS (AE_NO_MEMORY); } /* * Copy the original data to the new buffer, starting * at Byte zero. All unused (upper) bytes of the * buffer will be 0. */ ACPI_MEMCPY ((char *) new_buffer, (char *) buffer, length); buffer = new_buffer; length = required_length; } ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "field_write [FROM]: Obj %p (%s:%X), Buf %p, byte_len %X\n", source_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (source_desc)), ACPI_GET_OBJECT_TYPE (source_desc), buffer, length)); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "field_write [TO]: Obj %p (%s:%X), bit_len %X, bit_off %X, byte_off %X\n", obj_desc, acpi_ut_get_type_name (ACPI_GET_OBJECT_TYPE (obj_desc)), ACPI_GET_OBJECT_TYPE (obj_desc), obj_desc->common_field.bit_length, obj_desc->common_field.start_field_bit_offset, obj_desc->common_field.base_byte_offset)); /* Lock entire transaction if requested */ locked = acpi_ex_acquire_global_lock (obj_desc->common_field.field_flags); /* Write to the field */ status = acpi_ex_insert_into_field (obj_desc, buffer, length); acpi_ex_release_global_lock (locked); /* Free temporary buffer if we used one */ if (new_buffer) { ACPI_MEM_FREE (new_buffer); } return_ACPI_STATUS (status); }