union acpi_operand_object *acpi_ut_create_internal_object_dbg(char *module_name, u32 line_number, u32 component_id, acpi_object_type type) { union acpi_operand_object *object; union acpi_operand_object *second_object; ACPI_FUNCTION_TRACE_STR("ut_create_internal_object_dbg", acpi_ut_get_type_name(type)); /* Allocate the raw object descriptor */ object = acpi_ut_allocate_object_desc_dbg(module_name, line_number, component_id); if (!object) { return_PTR(NULL); } switch (type) { case ACPI_TYPE_REGION: case ACPI_TYPE_BUFFER_FIELD: /* These types require a secondary object */ second_object = acpi_ut_allocate_object_desc_dbg(module_name, line_number, component_id); if (!second_object) { acpi_ut_delete_object_desc(object); return_PTR(NULL); } second_object->common.type = ACPI_TYPE_LOCAL_EXTRA; second_object->common.reference_count = 1; /* Link the second object to the first */ object->common.next_object = second_object; break; default: /* All others have no secondary object */ break; } /* Save the object type in the object descriptor */ object->common.type = (u8) type; /* Init the reference count */ object->common.reference_count = 1; /* Any per-type initialization should go here */ return_PTR(object); }
static acpi_status acpi_ds_create_method_mutex(union acpi_operand_object *method_desc) { union acpi_operand_object *mutex_desc; acpi_status status; ACPI_FUNCTION_TRACE(ds_create_method_mutex); /* Create the new mutex object */ mutex_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX); if (!mutex_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Create the actual OS Mutex */ status = acpi_os_create_mutex(&mutex_desc->mutex.os_mutex); if (ACPI_FAILURE(status)) { acpi_ut_delete_object_desc(mutex_desc); return_ACPI_STATUS(status); } mutex_desc->mutex.sync_level = method_desc->method.sync_level; method_desc->method.mutex = mutex_desc; return_ACPI_STATUS(AE_OK); }
union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char *module_name, u32 line_number, u32 component_id, acpi_object_type type) { union acpi_operand_object *object; union acpi_operand_object *second_object; ACPI_FUNCTION_TRACE_STR(ut_create_internal_object_dbg, acpi_ut_get_type_name(type)); object = acpi_ut_allocate_object_desc_dbg(module_name, line_number, component_id); if (!object) { return_PTR(NULL); } switch (type) { case ACPI_TYPE_REGION: case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: second_object = acpi_ut_allocate_object_desc_dbg(module_name, line_number, component_id); if (!second_object) { acpi_ut_delete_object_desc(object); return_PTR(NULL); } second_object->common.type = ACPI_TYPE_LOCAL_EXTRA; second_object->common.reference_count = 1; object->common.next_object = second_object; break; default: break; } object->common.type = (u8) type; object->common.reference_count = 1; return_PTR(object); }
acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info) { union acpi_operand_object *obj_desc; union acpi_operand_object *second_desc = NULL; u32 type; acpi_status status; ACPI_FUNCTION_TRACE(ex_prep_field_value); /* Parameter validation */ if (info->field_type != ACPI_TYPE_LOCAL_INDEX_FIELD) { if (!info->region_node) { ACPI_ERROR((AE_INFO, "Null RegionNode")); return_ACPI_STATUS(AE_AML_NO_OPERAND); } type = acpi_ns_get_type(info->region_node); if (type != ACPI_TYPE_REGION) { ACPI_ERROR((AE_INFO, "Needed Region, found type 0x%X (%s)", type, acpi_ut_get_type_name(type))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } } /* Allocate a new field object */ obj_desc = acpi_ut_create_internal_object(info->field_type); if (!obj_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Initialize areas of the object that are common to all fields */ obj_desc->common_field.node = info->field_node; status = acpi_ex_prep_common_field_object(obj_desc, info->field_flags, info->attribute, info->field_bit_position, info->field_bit_length); if (ACPI_FAILURE(status)) { acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(status); } /* Initialize areas of the object that are specific to the field type */ switch (info->field_type) { case ACPI_TYPE_LOCAL_REGION_FIELD: obj_desc->field.region_obj = acpi_ns_get_attached_object(info->region_node); /* An additional reference for the container */ acpi_ut_add_reference(obj_desc->field.region_obj); /* allow full data read from EC address space */ if (obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_EC) { if (obj_desc->common_field.bit_length > 8) { unsigned width = ACPI_ROUND_BITS_UP_TO_BYTES( obj_desc->common_field.bit_length); // access_bit_width is u8, don't overflow it if (width > 8) width = 8; obj_desc->common_field.access_byte_width = width; obj_desc->common_field.access_bit_width = 8 * width; } } ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n", obj_desc->field.start_field_bit_offset, obj_desc->field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->field.region_obj)); break; case ACPI_TYPE_LOCAL_BANK_FIELD: obj_desc->bank_field.value = info->bank_value; obj_desc->bank_field.region_obj = acpi_ns_get_attached_object(info->region_node); obj_desc->bank_field.bank_obj = acpi_ns_get_attached_object(info->register_node); /* An additional reference for the attached objects */ acpi_ut_add_reference(obj_desc->bank_field.region_obj); acpi_ut_add_reference(obj_desc->bank_field.bank_obj); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n", obj_desc->bank_field.start_field_bit_offset, obj_desc->bank_field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->bank_field.region_obj, obj_desc->bank_field.bank_obj)); /* * Remember location in AML stream of the field unit * opcode and operands -- since the bank_value * operands must be evaluated. */ second_desc = obj_desc->common.next_object; second_desc->extra.aml_start = ACPI_CAST_PTR(union acpi_parse_object, info->data_register_node)->named.data; second_desc->extra.aml_length = ACPI_CAST_PTR(union acpi_parse_object, info->data_register_node)->named.length; break; case ACPI_TYPE_LOCAL_INDEX_FIELD: /* Get the Index and Data registers */ obj_desc->index_field.index_obj = acpi_ns_get_attached_object(info->register_node); obj_desc->index_field.data_obj = acpi_ns_get_attached_object(info->data_register_node); if (!obj_desc->index_field.data_obj || !obj_desc->index_field.index_obj) { ACPI_ERROR((AE_INFO, "Null Index Object during field prep")); acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(AE_AML_INTERNAL); } /* An additional reference for the attached objects */ acpi_ut_add_reference(obj_desc->index_field.data_obj); acpi_ut_add_reference(obj_desc->index_field.index_obj); /* * April 2006: Changed to match MS behavior * * The value written to the Index register is the byte offset of the * target field in units of the granularity of the index_field * * Previously, the value was calculated as an index in terms of the * width of the Data register, as below: * * obj_desc->index_field.Value = (u32) * (Info->field_bit_position / ACPI_MUL_8 ( * obj_desc->Field.access_byte_width)); * * February 2006: Tried value as a byte offset: * obj_desc->index_field.Value = (u32) * ACPI_DIV_8 (Info->field_bit_position); */ obj_desc->index_field.value = (u32) ACPI_ROUND_DOWN(ACPI_DIV_8(info->field_bit_position), obj_desc->index_field. access_byte_width); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "IndexField: BitOff %X, Off %X, Value %X, Gran %X, Index %p, Data %p\n", obj_desc->index_field.start_field_bit_offset, obj_desc->index_field.base_byte_offset, obj_desc->index_field.value, obj_desc->field.access_byte_width, obj_desc->index_field.index_obj, obj_desc->index_field.data_obj)); break; default: /* No other types should get here */ break; } /* * Store the constructed descriptor (obj_desc) into the parent Node, * preserving the current type of that named_obj. */ status = acpi_ns_attach_object(info->field_node, obj_desc, acpi_ns_get_type(info->field_node)); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Set NamedObj %p [%4.4s], ObjDesc %p\n", info->field_node, acpi_ut_get_node_name(info->field_node), obj_desc)); /* Remove local reference to the object */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); }
acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info) { union acpi_operand_object *obj_desc; union acpi_operand_object *second_desc = NULL; acpi_status status; u32 access_byte_width; u32 type; ACPI_FUNCTION_TRACE(ex_prep_field_value); /* */ if (info->field_type != ACPI_TYPE_LOCAL_INDEX_FIELD) { if (!info->region_node) { ACPI_ERROR((AE_INFO, "Null RegionNode")); return_ACPI_STATUS(AE_AML_NO_OPERAND); } type = acpi_ns_get_type(info->region_node); if (type != ACPI_TYPE_REGION) { ACPI_ERROR((AE_INFO, "Needed Region, found type 0x%X (%s)", type, acpi_ut_get_type_name(type))); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } } /* */ obj_desc = acpi_ut_create_internal_object(info->field_type); if (!obj_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* */ obj_desc->common_field.node = info->field_node; status = acpi_ex_prep_common_field_object(obj_desc, info->field_flags, info->attribute, info->field_bit_position, info->field_bit_length); if (ACPI_FAILURE(status)) { acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(status); } /* */ switch (info->field_type) { case ACPI_TYPE_LOCAL_REGION_FIELD: obj_desc->field.region_obj = acpi_ns_get_attached_object(info->region_node); /* */ obj_desc->field.access_length = info->access_length; if (info->connection_node) { second_desc = info->connection_node->object; if (!(second_desc->common.flags & AOPOBJ_DATA_VALID)) { status = acpi_ds_get_buffer_arguments(second_desc); if (ACPI_FAILURE(status)) { acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(status); } } obj_desc->field.resource_buffer = second_desc->buffer.pointer; obj_desc->field.resource_length = (u16)second_desc->buffer.length; } else if (info->resource_buffer) { obj_desc->field.resource_buffer = info->resource_buffer; obj_desc->field.resource_length = info->resource_length; } /* */ if ((obj_desc->field.region_obj->region.space_id == ACPI_ADR_SPACE_EC) && (obj_desc->common_field.bit_length > 8)) { access_byte_width = ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field. bit_length); /* */ if (access_byte_width < 256) { obj_desc->common_field.access_byte_width = (u8)access_byte_width; } } /* */ acpi_ut_add_reference(obj_desc->field.region_obj); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n", obj_desc->field.start_field_bit_offset, obj_desc->field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->field.region_obj)); break; case ACPI_TYPE_LOCAL_BANK_FIELD: obj_desc->bank_field.value = info->bank_value; obj_desc->bank_field.region_obj = acpi_ns_get_attached_object(info->region_node); obj_desc->bank_field.bank_obj = acpi_ns_get_attached_object(info->register_node); /* */ acpi_ut_add_reference(obj_desc->bank_field.region_obj); acpi_ut_add_reference(obj_desc->bank_field.bank_obj); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n", obj_desc->bank_field.start_field_bit_offset, obj_desc->bank_field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->bank_field.region_obj, obj_desc->bank_field.bank_obj)); /* */ second_desc = obj_desc->common.next_object; second_desc->extra.aml_start = ACPI_CAST_PTR(union acpi_parse_object, info->data_register_node)->named.data; second_desc->extra.aml_length = ACPI_CAST_PTR(union acpi_parse_object, info->data_register_node)->named.length; break; case ACPI_TYPE_LOCAL_INDEX_FIELD: /* */ obj_desc->index_field.index_obj = acpi_ns_get_attached_object(info->register_node); obj_desc->index_field.data_obj = acpi_ns_get_attached_object(info->data_register_node); if (!obj_desc->index_field.data_obj || !obj_desc->index_field.index_obj) { ACPI_ERROR((AE_INFO, "Null Index Object during field prep")); acpi_ut_delete_object_desc(obj_desc); return_ACPI_STATUS(AE_AML_INTERNAL); } /* */ acpi_ut_add_reference(obj_desc->index_field.data_obj); acpi_ut_add_reference(obj_desc->index_field.index_obj); /* */ obj_desc->index_field.value = (u32) ACPI_ROUND_DOWN(ACPI_DIV_8(info->field_bit_position), obj_desc->index_field. access_byte_width); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "IndexField: BitOff %X, Off %X, Value %X, Gran %X, Index %p, Data %p\n", obj_desc->index_field.start_field_bit_offset, obj_desc->index_field.base_byte_offset, obj_desc->index_field.value, obj_desc->field.access_byte_width, obj_desc->index_field.index_obj, obj_desc->index_field.data_obj)); break; default: /* */ break; } /* */ status = acpi_ns_attach_object(info->field_node, obj_desc, acpi_ns_get_type(info->field_node)); ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, "Set NamedObj %p [%4.4s], ObjDesc %p\n", info->field_node, acpi_ut_get_node_name(info->field_node), obj_desc)); /* */ acpi_ut_remove_reference(obj_desc); return_ACPI_STATUS(status); }
static void acpi_ut_delete_internal_obj(union acpi_operand_object *object) { void *obj_pointer = NULL; union acpi_operand_object *handler_desc; union acpi_operand_object *second_desc; union acpi_operand_object *next_desc; ACPI_FUNCTION_TRACE_PTR(ut_delete_internal_obj, object); if (!object) { return_VOID; } /* * Must delete or free any pointers within the object that are not * actual ACPI objects (for example, a raw buffer pointer). */ switch (ACPI_GET_OBJECT_TYPE(object)) { case ACPI_TYPE_STRING: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n", object, object->string.pointer)); /* Free the actual string buffer */ if (!(object->common.flags & AOPOBJ_STATIC_POINTER)) { /* But only if it is NOT a pointer into an ACPI table */ obj_pointer = object->string.pointer; } break; case ACPI_TYPE_BUFFER: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n", object, object->buffer.pointer)); /* Free the actual buffer */ if (!(object->common.flags & AOPOBJ_STATIC_POINTER)) { /* But only if it is NOT a pointer into an ACPI table */ obj_pointer = object->buffer.pointer; } break; case ACPI_TYPE_PACKAGE: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n", object->package.count)); /* * Elements of the package are not handled here, they are deleted * separately */ /* Free the (variable length) element pointer array */ obj_pointer = object->package.elements; break; case ACPI_TYPE_DEVICE: if (object->device.gpe_block) { (void)acpi_ev_delete_gpe_block(object->device. gpe_block); } /* Walk the handler list for this device */ handler_desc = object->device.handler; while (handler_desc) { next_desc = handler_desc->address_space.next; acpi_ut_remove_reference(handler_desc); handler_desc = next_desc; } break; case ACPI_TYPE_MUTEX: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Mutex %p, OS Mutex %p\n", object, object->mutex.os_mutex)); if (object->mutex.os_mutex == acpi_gbl_global_lock_mutex) { /* Global Lock has extra semaphore */ (void) acpi_os_delete_semaphore (acpi_gbl_global_lock_semaphore); acpi_gbl_global_lock_semaphore = NULL; acpi_os_delete_mutex(object->mutex.os_mutex); acpi_gbl_global_lock_mutex = NULL; } else { acpi_ex_unlink_mutex(object); acpi_os_delete_mutex(object->mutex.os_mutex); } break; case ACPI_TYPE_EVENT: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Event %p, OS Semaphore %p\n", object, object->event.os_semaphore)); (void)acpi_os_delete_semaphore(object->event.os_semaphore); object->event.os_semaphore = NULL; break; case ACPI_TYPE_METHOD: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Method %p\n", object)); /* Delete the method mutex if it exists */ if (object->method.mutex) { acpi_os_delete_mutex(object->method.mutex->mutex. os_mutex); acpi_ut_delete_object_desc(object->method.mutex); object->method.mutex = NULL; } break; case ACPI_TYPE_REGION: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Region %p\n", object)); second_desc = acpi_ns_get_secondary_object(object); if (second_desc) { /* * Free the region_context if and only if the handler is one of the * default handlers -- and therefore, we created the context object * locally, it was not created by an external caller. */ handler_desc = object->region.handler; if (handler_desc) { if (handler_desc->address_space.handler_flags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) { /* Deactivate region and free region context */ if (handler_desc->address_space.setup) { (void)handler_desc-> address_space.setup(object, ACPI_REGION_DEACTIVATE, handler_desc-> address_space. context, &second_desc-> extra. region_context); } } acpi_ut_remove_reference(handler_desc); } /* Now we can free the Extra object */ acpi_ut_delete_object_desc(second_desc); } break; case ACPI_TYPE_BUFFER_FIELD: ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "***** Buffer Field %p\n", object)); second_desc = acpi_ns_get_secondary_object(object); if (second_desc) { acpi_ut_delete_object_desc(second_desc); } break; default: break; } /* Free any allocated memory (pointer within the object) found above */ if (obj_pointer) { ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n", obj_pointer)); ACPI_FREE(obj_pointer); } /* Now the object can be safely deleted */ ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n", object, acpi_ut_get_object_type_name(object))); acpi_ut_delete_object_desc(object); return_VOID; }
acpi_status acpi_ex_prep_field_value ( struct acpi_create_field_info *info) { union acpi_operand_object *obj_desc; u32 type; acpi_status status; ACPI_FUNCTION_TRACE ("ex_prep_field_value"); /* Parameter validation */ if (info->field_type != ACPI_TYPE_LOCAL_INDEX_FIELD) { if (!info->region_node) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null region_node\n")); return_ACPI_STATUS (AE_AML_NO_OPERAND); } type = acpi_ns_get_type (info->region_node); if (type != ACPI_TYPE_REGION) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Needed Region, found type %X %s\n", type, acpi_ut_get_type_name (type))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } } /* Allocate a new field object */ obj_desc = acpi_ut_create_internal_object (info->field_type); if (!obj_desc) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Initialize areas of the object that are common to all fields */ obj_desc->common_field.node = info->field_node; status = acpi_ex_prep_common_field_object (obj_desc, info->field_flags, info->attribute, info->field_bit_position, info->field_bit_length); if (ACPI_FAILURE (status)) { acpi_ut_delete_object_desc (obj_desc); return_ACPI_STATUS (status); } /* Initialize areas of the object that are specific to the field type */ switch (info->field_type) { case ACPI_TYPE_LOCAL_REGION_FIELD: obj_desc->field.region_obj = acpi_ns_get_attached_object (info->region_node); /* An additional reference for the container */ acpi_ut_add_reference (obj_desc->field.region_obj); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "region_field: Bitoff=%X Off=%X Gran=%X Region %p\n", obj_desc->field.start_field_bit_offset, obj_desc->field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->field.region_obj)); break; case ACPI_TYPE_LOCAL_BANK_FIELD: obj_desc->bank_field.value = info->bank_value; obj_desc->bank_field.region_obj = acpi_ns_get_attached_object (info->region_node); obj_desc->bank_field.bank_obj = acpi_ns_get_attached_object (info->register_node); /* An additional reference for the attached objects */ acpi_ut_add_reference (obj_desc->bank_field.region_obj); acpi_ut_add_reference (obj_desc->bank_field.bank_obj); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "Bank Field: bit_off=%X Off=%X Gran=%X Region %p bank_reg %p\n", obj_desc->bank_field.start_field_bit_offset, obj_desc->bank_field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->bank_field.region_obj, obj_desc->bank_field.bank_obj)); break; case ACPI_TYPE_LOCAL_INDEX_FIELD: obj_desc->index_field.index_obj = acpi_ns_get_attached_object (info->register_node); obj_desc->index_field.data_obj = acpi_ns_get_attached_object (info->data_register_node); obj_desc->index_field.value = (u32) (info->field_bit_position / ACPI_MUL_8 (obj_desc->field.access_byte_width)); if (!obj_desc->index_field.data_obj || !obj_desc->index_field.index_obj) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Index Object\n")); return_ACPI_STATUS (AE_AML_INTERNAL); } /* An additional reference for the attached objects */ acpi_ut_add_reference (obj_desc->index_field.data_obj); acpi_ut_add_reference (obj_desc->index_field.index_obj); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "index_field: bitoff=%X off=%X gran=%X Index %p Data %p\n", obj_desc->index_field.start_field_bit_offset, obj_desc->index_field.base_byte_offset, obj_desc->field.access_byte_width, obj_desc->index_field.index_obj, obj_desc->index_field.data_obj)); break; default: /* No other types should get here */ break; } /* * Store the constructed descriptor (obj_desc) into the parent Node, * preserving the current type of that named_obj. */ status = acpi_ns_attach_object (info->field_node, obj_desc, acpi_ns_get_type (info->field_node)); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "set named_obj %p (%4.4s) val = %p\n", info->field_node, info->field_node->name.ascii, obj_desc)); /* Remove local reference to the object */ acpi_ut_remove_reference (obj_desc); return_ACPI_STATUS (status); }
acpi_status acpi_ds_build_internal_package_obj ( struct acpi_walk_state *walk_state, union acpi_parse_object *op, u32 package_length, union acpi_operand_object **obj_desc_ptr) { union acpi_parse_object *arg; union acpi_parse_object *parent; union acpi_operand_object *obj_desc = NULL; u32 package_list_length; acpi_status status = AE_OK; u32 i; ACPI_FUNCTION_TRACE ("ds_build_internal_package_obj"); /* Find the parent of a possibly nested package */ parent = op->common.parent; while ((parent->common.aml_opcode == AML_PACKAGE_OP) || (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) { parent = parent->common.parent; } obj_desc = *obj_desc_ptr; if (obj_desc) { /* * We are evaluating a Named package object "Name (xxxx, Package)". * Get the existing package object from the NS node */ } else { obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_PACKAGE); *obj_desc_ptr = obj_desc; if (!obj_desc) { return_ACPI_STATUS (AE_NO_MEMORY); } obj_desc->package.node = parent->common.node; } obj_desc->package.count = package_length; /* Count the number of items in the package list */ package_list_length = 0; arg = op->common.value.arg; arg = arg->common.next; while (arg) { package_list_length++; arg = arg->common.next; } /* * The package length (number of elements) will be the greater * of the specified length and the length of the initializer list */ if (package_list_length > package_length) { obj_desc->package.count = package_list_length; } /* * Allocate the pointer array (array of pointers to the * individual objects). Add an extra pointer slot so * that the list is always null terminated. */ obj_desc->package.elements = ACPI_MEM_CALLOCATE ( ((acpi_size) obj_desc->package.count + 1) * sizeof (void *)); if (!obj_desc->package.elements) { acpi_ut_delete_object_desc (obj_desc); return_ACPI_STATUS (AE_NO_MEMORY); } /* * Now init the elements of the package */ i = 0; arg = op->common.value.arg; arg = arg->common.next; while (arg) { if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { /* Object (package or buffer) is already built */ obj_desc->package.elements[i] = ACPI_CAST_PTR (union acpi_operand_object, arg->common.node); } else {
acpi_status acpi_ds_build_internal_buffer_obj ( struct acpi_walk_state *walk_state, union acpi_parse_object *op, u32 buffer_length, union acpi_operand_object **obj_desc_ptr) { union acpi_parse_object *arg; union acpi_operand_object *obj_desc; union acpi_parse_object *byte_list; u32 byte_list_length = 0; ACPI_FUNCTION_TRACE ("ds_build_internal_buffer_obj"); obj_desc = *obj_desc_ptr; if (obj_desc) { /* * We are evaluating a Named buffer object "Name (xxxx, Buffer)". * The buffer object already exists (from the NS node) */ } else { /* Create a new buffer object */ obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_BUFFER); *obj_desc_ptr = obj_desc; if (!obj_desc) { return_ACPI_STATUS (AE_NO_MEMORY); } } /* * Second arg is the buffer data (optional) byte_list can be either * individual bytes or a string initializer. In either case, a * byte_list appears in the AML. */ arg = op->common.value.arg; /* skip first arg */ byte_list = arg->named.next; if (byte_list) { if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Expecting bytelist, got AML opcode %X in op %p\n", byte_list->common.aml_opcode, byte_list)); acpi_ut_remove_reference (obj_desc); return (AE_TYPE); } byte_list_length = (u32) byte_list->common.value.integer; } /* * The buffer length (number of bytes) will be the larger of: * 1) The specified buffer length and * 2) The length of the initializer byte list */ obj_desc->buffer.length = buffer_length; if (byte_list_length > buffer_length) { obj_desc->buffer.length = byte_list_length; } /* Allocate the buffer */ if (obj_desc->buffer.length == 0) { obj_desc->buffer.pointer = NULL; ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer defined with zero length in AML, creating\n")); } else { obj_desc->buffer.pointer = ACPI_MEM_CALLOCATE ( obj_desc->buffer.length); if (!obj_desc->buffer.pointer) { acpi_ut_delete_object_desc (obj_desc); return_ACPI_STATUS (AE_NO_MEMORY); } /* Initialize buffer from the byte_list (if present) */ if (byte_list) { ACPI_MEMCPY (obj_desc->buffer.pointer, byte_list->named.data, byte_list_length); } } obj_desc->buffer.flags |= AOPOBJ_DATA_VALID; op->common.node = (struct acpi_namespace_node *) obj_desc; return_ACPI_STATUS (AE_OK); }