1/****************************************************************************** 2 * 3 * Module Name: utobject - ACPI object create/delete/size/cache routines 4 * $Revision: 1.1.1.1 $ 5 * 6 *****************************************************************************/ 7 8/* 9 * Copyright (C) 2000, 2001 R. Byron Moore 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 27#include "acpi.h" 28#include "acinterp.h" 29#include "acnamesp.h" 30#include "actables.h" 31#include "amlcode.h" 32 33 34#define _COMPONENT ACPI_UTILITIES 35 MODULE_NAME ("utobject") 36 37 38/******************************************************************************* 39 * 40 * FUNCTION: Acpi_ut_create_internal_object_dbg 41 * 42 * PARAMETERS: Address - Address of the memory to deallocate 43 * Component - Component type of caller 44 * Module - Source file name of caller 45 * Line - Line number of caller 46 * Type - ACPI Type of the new object 47 * 48 * RETURN: Object - The new object. Null on failure 49 * 50 * DESCRIPTION: Create and initialize a new internal object. 51 * 52 * NOTE: We always allocate the worst-case object descriptor because 53 * these objects are cached, and we want them to be 54 * one-size-satisifies-any-request. This in itself may not be 55 * the most memory efficient, but the efficiency of the object 56 * cache should more than make up for this! 57 * 58 ******************************************************************************/ 59 60acpi_operand_object * 61acpi_ut_create_internal_object_dbg ( 62 NATIVE_CHAR *module_name, 63 u32 line_number, 64 u32 component_id, 65 acpi_object_type8 type) 66{ 67 acpi_operand_object *object; 68 69 70 FUNCTION_TRACE_STR ("Ut_create_internal_object_dbg", acpi_ut_get_type_name (type)); 71 72 73 /* Allocate the raw object descriptor */ 74 75 object = acpi_ut_allocate_object_desc_dbg (module_name, line_number, component_id); 76 if (!object) { 77 /* Allocation failure */ 78 79 return_PTR (NULL); 80 } 81 82 /* Save the object type in the object descriptor */ 83 84 object->common.type = type; 85 86 /* Init the reference count */ 87 88 object->common.reference_count = 1; 89 90 /* Any per-type initialization should go here */ 91 92 return_PTR (object); 93} 94 95 96/******************************************************************************* 97 * 98 * FUNCTION: Acpi_ut_valid_internal_object 99 * 100 * PARAMETERS: Operand - Object to be validated 101 * 102 * RETURN: Validate a pointer to be an acpi_operand_object 103 * 104 ******************************************************************************/ 105 106u8 107acpi_ut_valid_internal_object ( 108 void *object) 109{ 110 111 PROC_NAME ("Ut_valid_internal_object"); 112 113 114 /* Check for a null pointer */ 115 116 if (!object) { 117 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 118 "**** Null Object Ptr\n")); 119 return (FALSE); 120 } 121 122 /* Check the descriptor type field */ 123 124 if (!VALID_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_INTERNAL)) { 125 /* Not an ACPI internal object, do some further checking */ 126 127 if (VALID_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_NAMED)) { 128 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 129 "**** Obj %p is a named obj, not ACPI obj\n", object)); 130 } 131 132 else if (VALID_DESCRIPTOR_TYPE (object, ACPI_DESC_TYPE_PARSER)) { 133 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 134 "**** Obj %p is a parser obj, not ACPI obj\n", object)); 135 } 136 137 else { 138 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 139 "**** Obj %p is of unknown type\n", object)); 140 } 141 142 return (FALSE); 143 } 144 145 146 /* The object appears to be a valid acpi_operand_object */ 147 148 return (TRUE); 149} 150 151 152/******************************************************************************* 153 * 154 * FUNCTION: Acpi_ut_allocate_object_desc_dbg 155 * 156 * PARAMETERS: Module_name - Caller's module name (for error output) 157 * Line_number - Caller's line number (for error output) 158 * Component_id - Caller's component ID (for error output) 159 * Message - Error message to use on failure 160 * 161 * RETURN: Pointer to newly allocated object descriptor. Null on error 162 * 163 * DESCRIPTION: Allocate a new object descriptor. Gracefully handle 164 * error conditions. 165 * 166 ******************************************************************************/ 167 168void * 169acpi_ut_allocate_object_desc_dbg ( 170 NATIVE_CHAR *module_name, 171 u32 line_number, 172 u32 component_id) 173{ 174 acpi_operand_object *object; 175 176 177 FUNCTION_TRACE ("Ut_allocate_object_desc_dbg"); 178 179 180 object = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_OPERAND); 181 if (!object) { 182 _REPORT_ERROR (module_name, line_number, component_id, 183 ("Could not allocate an object descriptor\n")); 184 185 return_PTR (NULL); 186 } 187 188 189 /* Mark the descriptor type */ 190 191 object->common.data_type = ACPI_DESC_TYPE_INTERNAL; 192 193 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", 194 object, sizeof (acpi_operand_object))); 195 196 return_PTR (object); 197} 198 199 200/******************************************************************************* 201 * 202 * FUNCTION: Acpi_ut_delete_object_desc 203 * 204 * PARAMETERS: Object - Acpi internal object to be deleted 205 * 206 * RETURN: None. 207 * 208 * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache 209 * 210 ******************************************************************************/ 211 212void 213acpi_ut_delete_object_desc ( 214 acpi_operand_object *object) 215{ 216 FUNCTION_TRACE_PTR ("Ut_delete_object_desc", object); 217 218 219 /* Object must be an acpi_operand_object */ 220 221 if (object->common.data_type != ACPI_DESC_TYPE_INTERNAL) { 222 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 223 "Obj %p is not an ACPI object\n", object)); 224 return_VOID; 225 } 226 227 acpi_ut_release_to_cache (ACPI_MEM_LIST_OPERAND, object); 228 229 return_VOID; 230} 231 232 233/******************************************************************************* 234 * 235 * FUNCTION: Acpi_ut_delete_object_cache 236 * 237 * PARAMETERS: None 238 * 239 * RETURN: Status 240 * 241 * DESCRIPTION: Purge the global state object cache. Used during subsystem 242 * termination. 243 * 244 ******************************************************************************/ 245 246void 247acpi_ut_delete_object_cache ( 248 void) 249{ 250 FUNCTION_TRACE ("Ut_delete_object_cache"); 251 252 253 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_OPERAND); 254 return_VOID; 255} 256 257 258/******************************************************************************* 259 * 260 * FUNCTION: Acpi_ut_get_simple_object_size 261 * 262 * PARAMETERS: *Internal_object - Pointer to the object we are examining 263 * *Ret_length - Where the length is returned 264 * 265 * RETURN: Status 266 * 267 * DESCRIPTION: This function is called to determine the space required to 268 * contain a simple object for return to an API user. 269 * 270 * The length includes the object structure plus any additional 271 * needed space. 272 * 273 ******************************************************************************/ 274 275acpi_status 276acpi_ut_get_simple_object_size ( 277 acpi_operand_object *internal_object, 278 u32 *obj_length) 279{ 280 u32 length; 281 acpi_status status = AE_OK; 282 283 284 FUNCTION_TRACE_PTR ("Ut_get_simple_object_size", internal_object); 285 286 287 /* Handle a null object (Could be a uninitialized package element -- which is legal) */ 288 289 if (!internal_object) { 290 *obj_length = 0; 291 return_ACPI_STATUS (AE_OK); 292 } 293 294 295 /* Start with the length of the Acpi object */ 296 297 length = sizeof (acpi_object); 298 299 if (VALID_DESCRIPTOR_TYPE (internal_object, ACPI_DESC_TYPE_NAMED)) { 300 /* Object is a named object (reference), just return the length */ 301 302 *obj_length = (u32) ROUND_UP_TO_NATIVE_WORD (length); 303 return_ACPI_STATUS (status); 304 } 305 306 307 /* 308 * The final length depends on the object type 309 * Strings and Buffers are packed right up against the parent object and 310 * must be accessed bytewise or there may be alignment problems on 311 * certain processors 312 */ 313 314 switch (internal_object->common.type) { 315 316 case ACPI_TYPE_STRING: 317 318 length += internal_object->string.length + 1; 319 break; 320 321 322 case ACPI_TYPE_BUFFER: 323 324 length += internal_object->buffer.length; 325 break; 326 327 328 case ACPI_TYPE_INTEGER: 329 case ACPI_TYPE_PROCESSOR: 330 case ACPI_TYPE_POWER: 331 332 /* 333 * No extra data for these types 334 */ 335 break; 336 337 338 case INTERNAL_TYPE_REFERENCE: 339 340 /* 341 * The only type that should be here is internal opcode NAMEPATH_OP -- since 342 * this means an object reference 343 */ 344 if (internal_object->reference.opcode != AML_INT_NAMEPATH_OP) { 345 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 346 "Unsupported Reference opcode=%X in object %p\n", 347 internal_object->reference.opcode, internal_object)); 348 status = AE_TYPE; 349 } 350 351 else { 352 /* 353 * Get the actual length of the full pathname to this object. 354 * The reference will be converted to the pathname to the object 355 */ 356 length += ROUND_UP_TO_NATIVE_WORD (acpi_ns_get_pathname_length (internal_object->reference.node)); 357 } 358 break; 359 360 361 default: 362 363 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unsupported type=%X in object %p\n", 364 internal_object->common.type, internal_object)); 365 status = AE_TYPE; 366 break; 367 } 368 369 370 /* 371 * Account for the space required by the object rounded up to the next 372 * multiple of the machine word size. This keeps each object aligned 373 * on a machine word boundary. (preventing alignment faults on some 374 * machines.) 375 */ 376 *obj_length = (u32) ROUND_UP_TO_NATIVE_WORD (length); 377 378 return_ACPI_STATUS (status); 379} 380 381 382/******************************************************************************* 383 * 384 * FUNCTION: Acpi_ut_get_element_length 385 * 386 * PARAMETERS: ACPI_PKG_CALLBACK 387 * 388 * RETURN: Status - the status of the call 389 * 390 * DESCRIPTION: Get the length of one package element. 391 * 392 ******************************************************************************/ 393 394acpi_status 395acpi_ut_get_element_length ( 396 u8 object_type, 397 acpi_operand_object *source_object, 398 acpi_generic_state *state, 399 void *context) 400{ 401 acpi_status status = AE_OK; 402 acpi_pkg_info *info = (acpi_pkg_info *) context; 403 u32 object_space; 404 405 406 switch (object_type) { 407 case 0: 408 409 /* 410 * Simple object - just get the size (Null object/entry is handled 411 * here also) and sum it into the running package length 412 */ 413 status = acpi_ut_get_simple_object_size (source_object, &object_space); 414 if (ACPI_FAILURE (status)) { 415 return (status); 416 } 417 418 info->length += object_space; 419 break; 420 421 422 case 1: 423 /* Package - nothing much to do here, let the walk handle it */ 424 425 info->num_packages++; 426 state->pkg.this_target_obj = NULL; 427 break; 428 429 default: 430 return (AE_BAD_PARAMETER); 431 } 432 433 434 return (status); 435} 436 437 438/******************************************************************************* 439 * 440 * FUNCTION: Acpi_ut_get_package_object_size 441 * 442 * PARAMETERS: *Internal_object - Pointer to the object we are examining 443 * *Ret_length - Where the length is returned 444 * 445 * RETURN: Status 446 * 447 * DESCRIPTION: This function is called to determine the space required to 448 * contain a package object for return to an API user. 449 * 450 * This is moderately complex since a package contains other 451 * objects including packages. 452 * 453 ******************************************************************************/ 454 455acpi_status 456acpi_ut_get_package_object_size ( 457 acpi_operand_object *internal_object, 458 u32 *obj_length) 459{ 460 acpi_status status; 461 acpi_pkg_info info; 462 463 464 FUNCTION_TRACE_PTR ("Ut_get_package_object_size", internal_object); 465 466 467 info.length = 0; 468 info.object_space = 0; 469 info.num_packages = 1; 470 471 status = acpi_ut_walk_package_tree (internal_object, NULL, 472 acpi_ut_get_element_length, &info); 473 474 /* 475 * We have handled all of the objects in all levels of the package. 476 * just add the length of the package objects themselves. 477 * Round up to the next machine word. 478 */ 479 info.length += ROUND_UP_TO_NATIVE_WORD (sizeof (acpi_object)) * 480 info.num_packages; 481 482 /* Return the total package length */ 483 484 *obj_length = info.length; 485 return_ACPI_STATUS (status); 486} 487 488 489/******************************************************************************* 490 * 491 * FUNCTION: Acpi_ut_get_object_size 492 * 493 * PARAMETERS: *Internal_object - Pointer to the object we are examining 494 * *Ret_length - Where the length will be returned 495 * 496 * RETURN: Status 497 * 498 * DESCRIPTION: This function is called to determine the space required to 499 * contain an object for return to an API user. 500 * 501 ******************************************************************************/ 502 503acpi_status 504acpi_ut_get_object_size( 505 acpi_operand_object *internal_object, 506 u32 *obj_length) 507{ 508 acpi_status status; 509 510 511 FUNCTION_ENTRY (); 512 513 514 if ((VALID_DESCRIPTOR_TYPE (internal_object, ACPI_DESC_TYPE_INTERNAL)) && 515 (IS_THIS_OBJECT_TYPE (internal_object, ACPI_TYPE_PACKAGE))) { 516 status = acpi_ut_get_package_object_size (internal_object, obj_length); 517 } 518 519 else { 520 status = acpi_ut_get_simple_object_size (internal_object, obj_length); 521 } 522 523 return (status); 524} 525 526 527