📄 utobject.c
字号:
/****************************************************************************** * * Module Name: utobject - ACPI object create/delete/size/cache routines * *****************************************************************************//* * Copyright (C) 2000 - 2005, R. Byron Moore * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */#include <acpi/acpi.h>#include <acpi/acnamesp.h>#include <acpi/amlcode.h>#define _COMPONENT ACPI_UTILITIESACPI_MODULE_NAME("utobject")/* Local prototypes */static acpi_statusacpi_ut_get_simple_object_size(union acpi_operand_object *obj, acpi_size * obj_length);static acpi_statusacpi_ut_get_package_object_size(union acpi_operand_object *obj, acpi_size * obj_length);static acpi_statusacpi_ut_get_element_length(u8 object_type, union acpi_operand_object *source_object, union acpi_generic_state *state, void *context);/******************************************************************************* * * FUNCTION: acpi_ut_create_internal_object_dbg * * PARAMETERS: module_name - Source file name of caller * line_number - Line number of caller * component_id - Component type of caller * Type - ACPI Type of the new object * * RETURN: A new internal object, null on failure * * DESCRIPTION: Create and initialize a new internal object. * * NOTE: We always allocate the worst-case object descriptor because * these objects are cached, and we want them to be * one-size-satisifies-any-request. This in itself may not be * the most memory efficient, but the efficiency of the object * cache should more than make up for this! * ******************************************************************************/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);}/******************************************************************************* * * FUNCTION: acpi_ut_create_buffer_object * * PARAMETERS: buffer_size - Size of buffer to be created * * RETURN: Pointer to a new Buffer object, null on failure * * DESCRIPTION: Create a fully initialized buffer object * ******************************************************************************/union acpi_operand_object *acpi_ut_create_buffer_object(acpi_size buffer_size){ union acpi_operand_object *buffer_desc; u8 *buffer = NULL; ACPI_FUNCTION_TRACE_U32("ut_create_buffer_object", buffer_size); /* Create a new Buffer object */ buffer_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER); if (!buffer_desc) { return_PTR(NULL); } /* Create an actual buffer only if size > 0 */ if (buffer_size > 0) { /* Allocate the actual buffer */ buffer = ACPI_MEM_CALLOCATE(buffer_size); if (!buffer) { ACPI_REPORT_ERROR(("create_buffer: could not allocate size %X\n", (u32) buffer_size)); acpi_ut_remove_reference(buffer_desc); return_PTR(NULL); } } /* Complete buffer object initialization */ buffer_desc->buffer.flags |= AOPOBJ_DATA_VALID; buffer_desc->buffer.pointer = buffer; buffer_desc->buffer.length = (u32) buffer_size; /* Return the new buffer descriptor */ return_PTR(buffer_desc);}/******************************************************************************* * * FUNCTION: acpi_ut_create_string_object * * PARAMETERS: string_size - Size of string to be created. Does not * include NULL terminator, this is added * automatically. * * RETURN: Pointer to a new String object * * DESCRIPTION: Create a fully initialized string object * ******************************************************************************/union acpi_operand_object *acpi_ut_create_string_object(acpi_size string_size){ union acpi_operand_object *string_desc; char *string; ACPI_FUNCTION_TRACE_U32("ut_create_string_object", string_size); /* Create a new String object */ string_desc = acpi_ut_create_internal_object(ACPI_TYPE_STRING); if (!string_desc) { return_PTR(NULL); } /* * Allocate the actual string buffer -- (Size + 1) for NULL terminator. * NOTE: Zero-length strings are NULL terminated */ string = ACPI_MEM_CALLOCATE(string_size + 1); if (!string) { ACPI_REPORT_ERROR(("create_string: could not allocate size %X\n", (u32) string_size)); acpi_ut_remove_reference(string_desc); return_PTR(NULL); } /* Complete string object initialization */ string_desc->string.pointer = string; string_desc->string.length = (u32) string_size; /* Return the new string descriptor */ return_PTR(string_desc);}/******************************************************************************* * * FUNCTION: acpi_ut_valid_internal_object * * PARAMETERS: Object - Object to be validated * * RETURN: TRUE if object is valid, FALSE otherwise * * DESCRIPTION: Validate a pointer to be an union acpi_operand_object * ******************************************************************************/u8 acpi_ut_valid_internal_object(void *object){ ACPI_FUNCTION_NAME("ut_valid_internal_object"); /* Check for a null pointer */ if (!object) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "**** Null Object Ptr\n")); return (FALSE); } /* Check the descriptor type field */ switch (ACPI_GET_DESCRIPTOR_TYPE(object)) { case ACPI_DESC_TYPE_OPERAND: /* The object appears to be a valid union acpi_operand_object */ return (TRUE); default: ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%p is not not an ACPI operand obj [%s]\n", object, acpi_ut_get_descriptor_name(object))); break; } return (FALSE);}/******************************************************************************* * * FUNCTION: acpi_ut_allocate_object_desc_dbg * * PARAMETERS: module_name - Caller's module name (for error output) * line_number - Caller's line number (for error output) * component_id - Caller's component ID (for error output) * * RETURN: Pointer to newly allocated object descriptor. Null on error * * DESCRIPTION: Allocate a new object descriptor. Gracefully handle * error conditions. * ******************************************************************************/void *acpi_ut_allocate_object_desc_dbg(char *module_name, u32 line_number, u32 component_id){ union acpi_operand_object *object; ACPI_FUNCTION_TRACE("ut_allocate_object_desc_dbg"); object = acpi_os_acquire_object(acpi_gbl_operand_cache);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -