1 1.1 jruoho /****************************************************************************** 2 1.1 jruoho * 3 1.1 jruoho * Module Name: utobject - ACPI object create/delete/size/cache routines 4 1.1 jruoho * 5 1.1 jruoho *****************************************************************************/ 6 1.1 jruoho 7 1.11 christos /****************************************************************************** 8 1.11 christos * 9 1.11 christos * 1. Copyright Notice 10 1.11 christos * 11 1.12 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp. 12 1.1 jruoho * All rights reserved. 13 1.1 jruoho * 14 1.11 christos * 2. License 15 1.11 christos * 16 1.11 christos * 2.1. This is your license from Intel Corp. under its intellectual property 17 1.11 christos * rights. You may have additional license terms from the party that provided 18 1.11 christos * you this software, covering your right to use that party's intellectual 19 1.11 christos * property rights. 20 1.11 christos * 21 1.11 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 1.11 christos * copy of the source code appearing in this file ("Covered Code") an 23 1.11 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 1.11 christos * base code distributed originally by Intel ("Original Intel Code") to copy, 25 1.11 christos * make derivatives, distribute, use and display any portion of the Covered 26 1.11 christos * Code in any form, with the right to sublicense such rights; and 27 1.11 christos * 28 1.11 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 1.11 christos * license (with the right to sublicense), under only those claims of Intel 30 1.11 christos * patents that are infringed by the Original Intel Code, to make, use, sell, 31 1.11 christos * offer to sell, and import the Covered Code and derivative works thereof 32 1.11 christos * solely to the minimum extent necessary to exercise the above copyright 33 1.11 christos * license, and in no event shall the patent license extend to any additions 34 1.11 christos * to or modifications of the Original Intel Code. No other license or right 35 1.11 christos * is granted directly or by implication, estoppel or otherwise; 36 1.11 christos * 37 1.11 christos * The above copyright and patent license is granted only if the following 38 1.11 christos * conditions are met: 39 1.11 christos * 40 1.11 christos * 3. Conditions 41 1.11 christos * 42 1.11 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 1.11 christos * Redistribution of source code of any substantial portion of the Covered 44 1.11 christos * Code or modification with rights to further distribute source must include 45 1.11 christos * the above Copyright Notice, the above License, this list of Conditions, 46 1.11 christos * and the following Disclaimer and Export Compliance provision. In addition, 47 1.11 christos * Licensee must cause all Covered Code to which Licensee contributes to 48 1.11 christos * contain a file documenting the changes Licensee made to create that Covered 49 1.11 christos * Code and the date of any change. Licensee must include in that file the 50 1.11 christos * documentation of any changes made by any predecessor Licensee. Licensee 51 1.11 christos * must include a prominent statement that the modification is derived, 52 1.11 christos * directly or indirectly, from Original Intel Code. 53 1.11 christos * 54 1.11 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 1.11 christos * Redistribution of source code of any substantial portion of the Covered 56 1.11 christos * Code or modification without rights to further distribute source must 57 1.11 christos * include the following Disclaimer and Export Compliance provision in the 58 1.11 christos * documentation and/or other materials provided with distribution. In 59 1.11 christos * addition, Licensee may not authorize further sublicense of source of any 60 1.11 christos * portion of the Covered Code, and must include terms to the effect that the 61 1.11 christos * license from Licensee to its licensee is limited to the intellectual 62 1.11 christos * property embodied in the software Licensee provides to its licensee, and 63 1.11 christos * not to intellectual property embodied in modifications its licensee may 64 1.11 christos * make. 65 1.11 christos * 66 1.11 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 1.11 christos * substantial portion of the Covered Code or modification must reproduce the 68 1.11 christos * above Copyright Notice, and the following Disclaimer and Export Compliance 69 1.11 christos * provision in the documentation and/or other materials provided with the 70 1.11 christos * distribution. 71 1.11 christos * 72 1.11 christos * 3.4. Intel retains all right, title, and interest in and to the Original 73 1.11 christos * Intel Code. 74 1.11 christos * 75 1.11 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 1.11 christos * Intel shall be used in advertising or otherwise to promote the sale, use or 77 1.11 christos * other dealings in products derived from or relating to the Covered Code 78 1.11 christos * without prior written authorization from Intel. 79 1.11 christos * 80 1.11 christos * 4. Disclaimer and Export Compliance 81 1.11 christos * 82 1.11 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 1.11 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 1.11 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 1.11 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 1.11 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 1.11 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 1.11 christos * PARTICULAR PURPOSE. 89 1.11 christos * 90 1.11 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 1.11 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 1.11 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 1.11 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 1.11 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 1.11 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 1.11 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 1.11 christos * LIMITED REMEDY. 98 1.11 christos * 99 1.11 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 1.11 christos * software or system incorporating such software without first obtaining any 101 1.11 christos * required license or other approval from the U. S. Department of Commerce or 102 1.11 christos * any other agency or department of the United States Government. In the 103 1.11 christos * event Licensee exports any such software from the United States or 104 1.11 christos * re-exports any such software from a foreign destination, Licensee shall 105 1.11 christos * ensure that the distribution and export/re-export of the software is in 106 1.11 christos * compliance with all laws, regulations, orders, or other restrictions of the 107 1.11 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 1.11 christos * any of its subsidiaries will export/re-export any technical data, process, 109 1.11 christos * software, or service, directly or indirectly, to any country for which the 110 1.11 christos * United States government or any agency thereof requires an export license, 111 1.11 christos * other governmental approval, or letter of assurance, without first obtaining 112 1.11 christos * such license, approval or letter. 113 1.11 christos * 114 1.11 christos ***************************************************************************** 115 1.11 christos * 116 1.11 christos * Alternatively, you may choose to be licensed under the terms of the 117 1.11 christos * following license: 118 1.11 christos * 119 1.2 christos * Redistribution and use in source and binary forms, with or without 120 1.2 christos * modification, are permitted provided that the following conditions 121 1.2 christos * are met: 122 1.2 christos * 1. Redistributions of source code must retain the above copyright 123 1.2 christos * notice, this list of conditions, and the following disclaimer, 124 1.2 christos * without modification. 125 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below 127 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon 128 1.2 christos * including a substantially similar Disclaimer requirement for further 129 1.2 christos * binary redistribution. 130 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names 131 1.2 christos * of any contributors may be used to endorse or promote products derived 132 1.2 christos * from this software without specific prior written permission. 133 1.2 christos * 134 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 1.8 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 1.11 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 1.11 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 1.11 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 1.11 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 1.11 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 1.11 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 1.11 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 1.11 christos * 146 1.11 christos * Alternatively, you may choose to be licensed under the terms of the 147 1.11 christos * GNU General Public License ("GPL") version 2 as published by the Free 148 1.11 christos * Software Foundation. 149 1.11 christos * 150 1.11 christos *****************************************************************************/ 151 1.1 jruoho 152 1.1 jruoho #include "acpi.h" 153 1.1 jruoho #include "accommon.h" 154 1.1 jruoho #include "acnamesp.h" 155 1.1 jruoho 156 1.1 jruoho 157 1.1 jruoho #define _COMPONENT ACPI_UTILITIES 158 1.1 jruoho ACPI_MODULE_NAME ("utobject") 159 1.1 jruoho 160 1.1 jruoho /* Local prototypes */ 161 1.1 jruoho 162 1.1 jruoho static ACPI_STATUS 163 1.1 jruoho AcpiUtGetSimpleObjectSize ( 164 1.1 jruoho ACPI_OPERAND_OBJECT *Obj, 165 1.1 jruoho ACPI_SIZE *ObjLength); 166 1.1 jruoho 167 1.1 jruoho static ACPI_STATUS 168 1.1 jruoho AcpiUtGetPackageObjectSize ( 169 1.1 jruoho ACPI_OPERAND_OBJECT *Obj, 170 1.1 jruoho ACPI_SIZE *ObjLength); 171 1.1 jruoho 172 1.1 jruoho static ACPI_STATUS 173 1.1 jruoho AcpiUtGetElementLength ( 174 1.1 jruoho UINT8 ObjectType, 175 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject, 176 1.1 jruoho ACPI_GENERIC_STATE *State, 177 1.1 jruoho void *Context); 178 1.1 jruoho 179 1.1 jruoho 180 1.1 jruoho /******************************************************************************* 181 1.1 jruoho * 182 1.1 jruoho * FUNCTION: AcpiUtCreateInternalObjectDbg 183 1.1 jruoho * 184 1.1 jruoho * PARAMETERS: ModuleName - Source file name of caller 185 1.1 jruoho * LineNumber - Line number of caller 186 1.1 jruoho * ComponentId - Component type of caller 187 1.1 jruoho * Type - ACPI Type of the new object 188 1.1 jruoho * 189 1.1 jruoho * RETURN: A new internal object, null on failure 190 1.1 jruoho * 191 1.1 jruoho * DESCRIPTION: Create and initialize a new internal object. 192 1.1 jruoho * 193 1.1 jruoho * NOTE: We always allocate the worst-case object descriptor because 194 1.1 jruoho * these objects are cached, and we want them to be 195 1.7 christos * one-size-satisfies-any-request. This in itself may not be 196 1.1 jruoho * the most memory efficient, but the efficiency of the object 197 1.1 jruoho * cache should more than make up for this! 198 1.1 jruoho * 199 1.1 jruoho ******************************************************************************/ 200 1.1 jruoho 201 1.1 jruoho ACPI_OPERAND_OBJECT * 202 1.1 jruoho AcpiUtCreateInternalObjectDbg ( 203 1.1 jruoho const char *ModuleName, 204 1.1 jruoho UINT32 LineNumber, 205 1.1 jruoho UINT32 ComponentId, 206 1.1 jruoho ACPI_OBJECT_TYPE Type) 207 1.1 jruoho { 208 1.1 jruoho ACPI_OPERAND_OBJECT *Object; 209 1.1 jruoho ACPI_OPERAND_OBJECT *SecondObject; 210 1.1 jruoho 211 1.1 jruoho 212 1.1 jruoho ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg, 213 1.2 christos __UNCONST(AcpiUtGetTypeName (Type))); 214 1.1 jruoho 215 1.1 jruoho 216 1.1 jruoho /* Allocate the raw object descriptor */ 217 1.1 jruoho 218 1.2 christos Object = AcpiUtAllocateObjectDescDbg ( 219 1.2 christos ModuleName, LineNumber, ComponentId); 220 1.1 jruoho if (!Object) 221 1.1 jruoho { 222 1.1 jruoho return_PTR (NULL); 223 1.1 jruoho } 224 1.1 jruoho 225 1.1 jruoho switch (Type) 226 1.1 jruoho { 227 1.1 jruoho case ACPI_TYPE_REGION: 228 1.1 jruoho case ACPI_TYPE_BUFFER_FIELD: 229 1.1 jruoho case ACPI_TYPE_LOCAL_BANK_FIELD: 230 1.1 jruoho 231 1.1 jruoho /* These types require a secondary object */ 232 1.1 jruoho 233 1.2 christos SecondObject = AcpiUtAllocateObjectDescDbg ( 234 1.2 christos ModuleName, LineNumber, ComponentId); 235 1.1 jruoho if (!SecondObject) 236 1.1 jruoho { 237 1.1 jruoho AcpiUtDeleteObjectDesc (Object); 238 1.1 jruoho return_PTR (NULL); 239 1.1 jruoho } 240 1.1 jruoho 241 1.1 jruoho SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA; 242 1.1 jruoho SecondObject->Common.ReferenceCount = 1; 243 1.1 jruoho 244 1.1 jruoho /* Link the second object to the first */ 245 1.1 jruoho 246 1.1 jruoho Object->Common.NextObject = SecondObject; 247 1.1 jruoho break; 248 1.1 jruoho 249 1.1 jruoho default: 250 1.2 christos 251 1.1 jruoho /* All others have no secondary object */ 252 1.1 jruoho break; 253 1.1 jruoho } 254 1.1 jruoho 255 1.1 jruoho /* Save the object type in the object descriptor */ 256 1.1 jruoho 257 1.1 jruoho Object->Common.Type = (UINT8) Type; 258 1.1 jruoho 259 1.1 jruoho /* Init the reference count */ 260 1.1 jruoho 261 1.1 jruoho Object->Common.ReferenceCount = 1; 262 1.1 jruoho 263 1.1 jruoho /* Any per-type initialization should go here */ 264 1.1 jruoho 265 1.1 jruoho return_PTR (Object); 266 1.1 jruoho } 267 1.1 jruoho 268 1.1 jruoho 269 1.1 jruoho /******************************************************************************* 270 1.1 jruoho * 271 1.1 jruoho * FUNCTION: AcpiUtCreatePackageObject 272 1.1 jruoho * 273 1.1 jruoho * PARAMETERS: Count - Number of package elements 274 1.1 jruoho * 275 1.1 jruoho * RETURN: Pointer to a new Package object, null on failure 276 1.1 jruoho * 277 1.1 jruoho * DESCRIPTION: Create a fully initialized package object 278 1.1 jruoho * 279 1.1 jruoho ******************************************************************************/ 280 1.1 jruoho 281 1.1 jruoho ACPI_OPERAND_OBJECT * 282 1.1 jruoho AcpiUtCreatePackageObject ( 283 1.1 jruoho UINT32 Count) 284 1.1 jruoho { 285 1.1 jruoho ACPI_OPERAND_OBJECT *PackageDesc; 286 1.1 jruoho ACPI_OPERAND_OBJECT **PackageElements; 287 1.1 jruoho 288 1.1 jruoho 289 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count); 290 1.1 jruoho 291 1.1 jruoho 292 1.1 jruoho /* Create a new Package object */ 293 1.1 jruoho 294 1.1 jruoho PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE); 295 1.1 jruoho if (!PackageDesc) 296 1.1 jruoho { 297 1.1 jruoho return_PTR (NULL); 298 1.1 jruoho } 299 1.1 jruoho 300 1.1 jruoho /* 301 1.1 jruoho * Create the element array. Count+1 allows the array to be null 302 1.1 jruoho * terminated. 303 1.1 jruoho */ 304 1.1 jruoho PackageElements = ACPI_ALLOCATE_ZEROED ( 305 1.2 christos ((ACPI_SIZE) Count + 1) * sizeof (void *)); 306 1.1 jruoho if (!PackageElements) 307 1.1 jruoho { 308 1.1 jruoho ACPI_FREE (PackageDesc); 309 1.1 jruoho return_PTR (NULL); 310 1.1 jruoho } 311 1.1 jruoho 312 1.1 jruoho PackageDesc->Package.Count = Count; 313 1.1 jruoho PackageDesc->Package.Elements = PackageElements; 314 1.1 jruoho return_PTR (PackageDesc); 315 1.1 jruoho } 316 1.1 jruoho 317 1.1 jruoho 318 1.1 jruoho /******************************************************************************* 319 1.1 jruoho * 320 1.1 jruoho * FUNCTION: AcpiUtCreateIntegerObject 321 1.1 jruoho * 322 1.1 jruoho * PARAMETERS: InitialValue - Initial value for the integer 323 1.1 jruoho * 324 1.1 jruoho * RETURN: Pointer to a new Integer object, null on failure 325 1.1 jruoho * 326 1.1 jruoho * DESCRIPTION: Create an initialized integer object 327 1.1 jruoho * 328 1.1 jruoho ******************************************************************************/ 329 1.1 jruoho 330 1.1 jruoho ACPI_OPERAND_OBJECT * 331 1.1 jruoho AcpiUtCreateIntegerObject ( 332 1.1 jruoho UINT64 InitialValue) 333 1.1 jruoho { 334 1.1 jruoho ACPI_OPERAND_OBJECT *IntegerDesc; 335 1.1 jruoho 336 1.1 jruoho 337 1.1 jruoho ACPI_FUNCTION_TRACE (UtCreateIntegerObject); 338 1.1 jruoho 339 1.1 jruoho 340 1.1 jruoho /* Create and initialize a new integer object */ 341 1.1 jruoho 342 1.1 jruoho IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER); 343 1.1 jruoho if (!IntegerDesc) 344 1.1 jruoho { 345 1.1 jruoho return_PTR (NULL); 346 1.1 jruoho } 347 1.1 jruoho 348 1.1 jruoho IntegerDesc->Integer.Value = InitialValue; 349 1.1 jruoho return_PTR (IntegerDesc); 350 1.1 jruoho } 351 1.1 jruoho 352 1.1 jruoho 353 1.1 jruoho /******************************************************************************* 354 1.1 jruoho * 355 1.1 jruoho * FUNCTION: AcpiUtCreateBufferObject 356 1.1 jruoho * 357 1.1 jruoho * PARAMETERS: BufferSize - Size of buffer to be created 358 1.1 jruoho * 359 1.1 jruoho * RETURN: Pointer to a new Buffer object, null on failure 360 1.1 jruoho * 361 1.1 jruoho * DESCRIPTION: Create a fully initialized buffer object 362 1.1 jruoho * 363 1.1 jruoho ******************************************************************************/ 364 1.1 jruoho 365 1.1 jruoho ACPI_OPERAND_OBJECT * 366 1.1 jruoho AcpiUtCreateBufferObject ( 367 1.1 jruoho ACPI_SIZE BufferSize) 368 1.1 jruoho { 369 1.1 jruoho ACPI_OPERAND_OBJECT *BufferDesc; 370 1.1 jruoho UINT8 *Buffer = NULL; 371 1.1 jruoho 372 1.1 jruoho 373 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize); 374 1.1 jruoho 375 1.1 jruoho 376 1.1 jruoho /* Create a new Buffer object */ 377 1.1 jruoho 378 1.1 jruoho BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER); 379 1.1 jruoho if (!BufferDesc) 380 1.1 jruoho { 381 1.1 jruoho return_PTR (NULL); 382 1.1 jruoho } 383 1.1 jruoho 384 1.1 jruoho /* Create an actual buffer only if size > 0 */ 385 1.1 jruoho 386 1.1 jruoho if (BufferSize > 0) 387 1.1 jruoho { 388 1.1 jruoho /* Allocate the actual buffer */ 389 1.1 jruoho 390 1.1 jruoho Buffer = ACPI_ALLOCATE_ZEROED (BufferSize); 391 1.1 jruoho if (!Buffer) 392 1.1 jruoho { 393 1.1 jruoho ACPI_ERROR ((AE_INFO, "Could not allocate size %u", 394 1.1 jruoho (UINT32) BufferSize)); 395 1.2 christos 396 1.1 jruoho AcpiUtRemoveReference (BufferDesc); 397 1.1 jruoho return_PTR (NULL); 398 1.1 jruoho } 399 1.1 jruoho } 400 1.1 jruoho 401 1.1 jruoho /* Complete buffer object initialization */ 402 1.1 jruoho 403 1.1 jruoho BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID; 404 1.1 jruoho BufferDesc->Buffer.Pointer = Buffer; 405 1.1 jruoho BufferDesc->Buffer.Length = (UINT32) BufferSize; 406 1.1 jruoho 407 1.1 jruoho /* Return the new buffer descriptor */ 408 1.1 jruoho 409 1.1 jruoho return_PTR (BufferDesc); 410 1.1 jruoho } 411 1.1 jruoho 412 1.1 jruoho 413 1.1 jruoho /******************************************************************************* 414 1.1 jruoho * 415 1.1 jruoho * FUNCTION: AcpiUtCreateStringObject 416 1.1 jruoho * 417 1.1 jruoho * PARAMETERS: StringSize - Size of string to be created. Does not 418 1.1 jruoho * include NULL terminator, this is added 419 1.1 jruoho * automatically. 420 1.1 jruoho * 421 1.1 jruoho * RETURN: Pointer to a new String object 422 1.1 jruoho * 423 1.1 jruoho * DESCRIPTION: Create a fully initialized string object 424 1.1 jruoho * 425 1.1 jruoho ******************************************************************************/ 426 1.1 jruoho 427 1.1 jruoho ACPI_OPERAND_OBJECT * 428 1.1 jruoho AcpiUtCreateStringObject ( 429 1.1 jruoho ACPI_SIZE StringSize) 430 1.1 jruoho { 431 1.1 jruoho ACPI_OPERAND_OBJECT *StringDesc; 432 1.1 jruoho char *String; 433 1.1 jruoho 434 1.1 jruoho 435 1.1 jruoho ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize); 436 1.1 jruoho 437 1.1 jruoho 438 1.1 jruoho /* Create a new String object */ 439 1.1 jruoho 440 1.1 jruoho StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING); 441 1.1 jruoho if (!StringDesc) 442 1.1 jruoho { 443 1.1 jruoho return_PTR (NULL); 444 1.1 jruoho } 445 1.1 jruoho 446 1.1 jruoho /* 447 1.1 jruoho * Allocate the actual string buffer -- (Size + 1) for NULL terminator. 448 1.1 jruoho * NOTE: Zero-length strings are NULL terminated 449 1.1 jruoho */ 450 1.1 jruoho String = ACPI_ALLOCATE_ZEROED (StringSize + 1); 451 1.1 jruoho if (!String) 452 1.1 jruoho { 453 1.1 jruoho ACPI_ERROR ((AE_INFO, "Could not allocate size %u", 454 1.1 jruoho (UINT32) StringSize)); 455 1.2 christos 456 1.1 jruoho AcpiUtRemoveReference (StringDesc); 457 1.1 jruoho return_PTR (NULL); 458 1.1 jruoho } 459 1.1 jruoho 460 1.1 jruoho /* Complete string object initialization */ 461 1.1 jruoho 462 1.1 jruoho StringDesc->String.Pointer = String; 463 1.1 jruoho StringDesc->String.Length = (UINT32) StringSize; 464 1.1 jruoho 465 1.1 jruoho /* Return the new string descriptor */ 466 1.1 jruoho 467 1.1 jruoho return_PTR (StringDesc); 468 1.1 jruoho } 469 1.1 jruoho 470 1.1 jruoho 471 1.1 jruoho /******************************************************************************* 472 1.1 jruoho * 473 1.1 jruoho * FUNCTION: AcpiUtValidInternalObject 474 1.1 jruoho * 475 1.1 jruoho * PARAMETERS: Object - Object to be validated 476 1.1 jruoho * 477 1.1 jruoho * RETURN: TRUE if object is valid, FALSE otherwise 478 1.1 jruoho * 479 1.2 christos * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT 480 1.1 jruoho * 481 1.1 jruoho ******************************************************************************/ 482 1.1 jruoho 483 1.1 jruoho BOOLEAN 484 1.1 jruoho AcpiUtValidInternalObject ( 485 1.1 jruoho void *Object) 486 1.1 jruoho { 487 1.1 jruoho 488 1.1 jruoho ACPI_FUNCTION_NAME (UtValidInternalObject); 489 1.1 jruoho 490 1.1 jruoho 491 1.1 jruoho /* Check for a null pointer */ 492 1.1 jruoho 493 1.1 jruoho if (!Object) 494 1.1 jruoho { 495 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n")); 496 1.1 jruoho return (FALSE); 497 1.1 jruoho } 498 1.1 jruoho 499 1.1 jruoho /* Check the descriptor type field */ 500 1.1 jruoho 501 1.1 jruoho switch (ACPI_GET_DESCRIPTOR_TYPE (Object)) 502 1.1 jruoho { 503 1.1 jruoho case ACPI_DESC_TYPE_OPERAND: 504 1.1 jruoho 505 1.2 christos /* The object appears to be a valid ACPI_OPERAND_OBJECT */ 506 1.1 jruoho 507 1.1 jruoho return (TRUE); 508 1.1 jruoho 509 1.1 jruoho default: 510 1.2 christos 511 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 512 1.2 christos "%p is not an ACPI operand obj [%s]\n", 513 1.2 christos Object, AcpiUtGetDescriptorName (Object))); 514 1.1 jruoho break; 515 1.1 jruoho } 516 1.1 jruoho 517 1.1 jruoho return (FALSE); 518 1.1 jruoho } 519 1.1 jruoho 520 1.1 jruoho 521 1.1 jruoho /******************************************************************************* 522 1.1 jruoho * 523 1.1 jruoho * FUNCTION: AcpiUtAllocateObjectDescDbg 524 1.1 jruoho * 525 1.1 jruoho * PARAMETERS: ModuleName - Caller's module name (for error output) 526 1.1 jruoho * LineNumber - Caller's line number (for error output) 527 1.1 jruoho * ComponentId - Caller's component ID (for error output) 528 1.1 jruoho * 529 1.2 christos * RETURN: Pointer to newly allocated object descriptor. Null on error 530 1.1 jruoho * 531 1.2 christos * DESCRIPTION: Allocate a new object descriptor. Gracefully handle 532 1.1 jruoho * error conditions. 533 1.1 jruoho * 534 1.1 jruoho ******************************************************************************/ 535 1.1 jruoho 536 1.1 jruoho void * 537 1.1 jruoho AcpiUtAllocateObjectDescDbg ( 538 1.1 jruoho const char *ModuleName, 539 1.1 jruoho UINT32 LineNumber, 540 1.1 jruoho UINT32 ComponentId) 541 1.1 jruoho { 542 1.1 jruoho ACPI_OPERAND_OBJECT *Object; 543 1.1 jruoho 544 1.1 jruoho 545 1.1 jruoho ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg); 546 1.1 jruoho 547 1.1 jruoho 548 1.1 jruoho Object = AcpiOsAcquireObject (AcpiGbl_OperandCache); 549 1.1 jruoho if (!Object) 550 1.1 jruoho { 551 1.1 jruoho ACPI_ERROR ((ModuleName, LineNumber, 552 1.1 jruoho "Could not allocate an object descriptor")); 553 1.1 jruoho 554 1.1 jruoho return_PTR (NULL); 555 1.1 jruoho } 556 1.1 jruoho 557 1.1 jruoho /* Mark the descriptor type */ 558 1.1 jruoho 559 1.1 jruoho ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND); 560 1.1 jruoho 561 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", 562 1.2 christos Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT))); 563 1.1 jruoho 564 1.1 jruoho return_PTR (Object); 565 1.1 jruoho } 566 1.1 jruoho 567 1.1 jruoho 568 1.1 jruoho /******************************************************************************* 569 1.1 jruoho * 570 1.1 jruoho * FUNCTION: AcpiUtDeleteObjectDesc 571 1.1 jruoho * 572 1.1 jruoho * PARAMETERS: Object - An Acpi internal object to be deleted 573 1.1 jruoho * 574 1.1 jruoho * RETURN: None. 575 1.1 jruoho * 576 1.1 jruoho * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache 577 1.1 jruoho * 578 1.1 jruoho ******************************************************************************/ 579 1.1 jruoho 580 1.1 jruoho void 581 1.1 jruoho AcpiUtDeleteObjectDesc ( 582 1.1 jruoho ACPI_OPERAND_OBJECT *Object) 583 1.1 jruoho { 584 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object); 585 1.1 jruoho 586 1.1 jruoho 587 1.2 christos /* Object must be of type ACPI_OPERAND_OBJECT */ 588 1.1 jruoho 589 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND) 590 1.1 jruoho { 591 1.1 jruoho ACPI_ERROR ((AE_INFO, 592 1.1 jruoho "%p is not an ACPI Operand object [%s]", Object, 593 1.1 jruoho AcpiUtGetDescriptorName (Object))); 594 1.1 jruoho return_VOID; 595 1.1 jruoho } 596 1.1 jruoho 597 1.1 jruoho (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object); 598 1.1 jruoho return_VOID; 599 1.1 jruoho } 600 1.1 jruoho 601 1.1 jruoho 602 1.1 jruoho /******************************************************************************* 603 1.1 jruoho * 604 1.1 jruoho * FUNCTION: AcpiUtGetSimpleObjectSize 605 1.1 jruoho * 606 1.1 jruoho * PARAMETERS: InternalObject - An ACPI operand object 607 1.1 jruoho * ObjLength - Where the length is returned 608 1.1 jruoho * 609 1.1 jruoho * RETURN: Status 610 1.1 jruoho * 611 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to 612 1.1 jruoho * contain a simple object for return to an external user. 613 1.1 jruoho * 614 1.1 jruoho * The length includes the object structure plus any additional 615 1.1 jruoho * needed space. 616 1.1 jruoho * 617 1.1 jruoho ******************************************************************************/ 618 1.1 jruoho 619 1.1 jruoho static ACPI_STATUS 620 1.1 jruoho AcpiUtGetSimpleObjectSize ( 621 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject, 622 1.1 jruoho ACPI_SIZE *ObjLength) 623 1.1 jruoho { 624 1.1 jruoho ACPI_SIZE Length; 625 1.1 jruoho ACPI_SIZE Size; 626 1.1 jruoho ACPI_STATUS Status = AE_OK; 627 1.1 jruoho 628 1.1 jruoho 629 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject); 630 1.1 jruoho 631 1.1 jruoho 632 1.1 jruoho /* Start with the length of the (external) Acpi object */ 633 1.1 jruoho 634 1.1 jruoho Length = sizeof (ACPI_OBJECT); 635 1.1 jruoho 636 1.1 jruoho /* A NULL object is allowed, can be a legal uninitialized package element */ 637 1.1 jruoho 638 1.1 jruoho if (!InternalObject) 639 1.1 jruoho { 640 1.1 jruoho /* 641 1.1 jruoho * Object is NULL, just return the length of ACPI_OBJECT 642 1.1 jruoho * (A NULL ACPI_OBJECT is an object of all zeroes.) 643 1.1 jruoho */ 644 1.1 jruoho *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length); 645 1.1 jruoho return_ACPI_STATUS (AE_OK); 646 1.1 jruoho } 647 1.1 jruoho 648 1.1 jruoho /* A Namespace Node should never appear here */ 649 1.1 jruoho 650 1.1 jruoho if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED) 651 1.1 jruoho { 652 1.1 jruoho /* A namespace node should never get here */ 653 1.1 jruoho 654 1.4 christos ACPI_ERROR ((AE_INFO, 655 1.4 christos "Received a namespace node [%4.4s] " 656 1.4 christos "where an operand object is required", 657 1.4 christos ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, InternalObject)->Name.Ascii)); 658 1.1 jruoho return_ACPI_STATUS (AE_AML_INTERNAL); 659 1.1 jruoho } 660 1.1 jruoho 661 1.1 jruoho /* 662 1.1 jruoho * The final length depends on the object type 663 1.1 jruoho * Strings and Buffers are packed right up against the parent object and 664 1.1 jruoho * must be accessed bytewise or there may be alignment problems on 665 1.1 jruoho * certain processors 666 1.1 jruoho */ 667 1.1 jruoho switch (InternalObject->Common.Type) 668 1.1 jruoho { 669 1.1 jruoho case ACPI_TYPE_STRING: 670 1.1 jruoho 671 1.1 jruoho Length += (ACPI_SIZE) InternalObject->String.Length + 1; 672 1.1 jruoho break; 673 1.1 jruoho 674 1.1 jruoho case ACPI_TYPE_BUFFER: 675 1.1 jruoho 676 1.1 jruoho Length += (ACPI_SIZE) InternalObject->Buffer.Length; 677 1.1 jruoho break; 678 1.1 jruoho 679 1.1 jruoho case ACPI_TYPE_INTEGER: 680 1.1 jruoho case ACPI_TYPE_PROCESSOR: 681 1.1 jruoho case ACPI_TYPE_POWER: 682 1.1 jruoho 683 1.1 jruoho /* No extra data for these types */ 684 1.1 jruoho 685 1.1 jruoho break; 686 1.1 jruoho 687 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE: 688 1.1 jruoho 689 1.1 jruoho switch (InternalObject->Reference.Class) 690 1.1 jruoho { 691 1.1 jruoho case ACPI_REFCLASS_NAME: 692 1.1 jruoho /* 693 1.1 jruoho * Get the actual length of the full pathname to this object. 694 1.1 jruoho * The reference will be converted to the pathname to the object 695 1.1 jruoho */ 696 1.1 jruoho Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node); 697 1.1 jruoho if (!Size) 698 1.1 jruoho { 699 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER); 700 1.1 jruoho } 701 1.1 jruoho 702 1.1 jruoho Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size); 703 1.1 jruoho break; 704 1.1 jruoho 705 1.1 jruoho default: 706 1.1 jruoho /* 707 1.1 jruoho * No other reference opcodes are supported. 708 1.1 jruoho * Notably, Locals and Args are not supported, but this may be 709 1.1 jruoho * required eventually. 710 1.1 jruoho */ 711 1.1 jruoho ACPI_ERROR ((AE_INFO, "Cannot convert to external object - " 712 1.1 jruoho "unsupported Reference Class [%s] 0x%X in object %p", 713 1.1 jruoho AcpiUtGetReferenceName (InternalObject), 714 1.1 jruoho InternalObject->Reference.Class, InternalObject)); 715 1.1 jruoho Status = AE_TYPE; 716 1.1 jruoho break; 717 1.1 jruoho } 718 1.1 jruoho break; 719 1.1 jruoho 720 1.1 jruoho default: 721 1.1 jruoho 722 1.1 jruoho ACPI_ERROR ((AE_INFO, "Cannot convert to external object - " 723 1.1 jruoho "unsupported type [%s] 0x%X in object %p", 724 1.1 jruoho AcpiUtGetObjectTypeName (InternalObject), 725 1.1 jruoho InternalObject->Common.Type, InternalObject)); 726 1.1 jruoho Status = AE_TYPE; 727 1.1 jruoho break; 728 1.1 jruoho } 729 1.1 jruoho 730 1.1 jruoho /* 731 1.1 jruoho * Account for the space required by the object rounded up to the next 732 1.2 christos * multiple of the machine word size. This keeps each object aligned 733 1.1 jruoho * on a machine word boundary. (preventing alignment faults on some 734 1.1 jruoho * machines.) 735 1.1 jruoho */ 736 1.1 jruoho *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length); 737 1.1 jruoho return_ACPI_STATUS (Status); 738 1.1 jruoho } 739 1.1 jruoho 740 1.1 jruoho 741 1.1 jruoho /******************************************************************************* 742 1.1 jruoho * 743 1.1 jruoho * FUNCTION: AcpiUtGetElementLength 744 1.1 jruoho * 745 1.1 jruoho * PARAMETERS: ACPI_PKG_CALLBACK 746 1.1 jruoho * 747 1.1 jruoho * RETURN: Status 748 1.1 jruoho * 749 1.1 jruoho * DESCRIPTION: Get the length of one package element. 750 1.1 jruoho * 751 1.1 jruoho ******************************************************************************/ 752 1.1 jruoho 753 1.1 jruoho static ACPI_STATUS 754 1.1 jruoho AcpiUtGetElementLength ( 755 1.1 jruoho UINT8 ObjectType, 756 1.1 jruoho ACPI_OPERAND_OBJECT *SourceObject, 757 1.1 jruoho ACPI_GENERIC_STATE *State, 758 1.1 jruoho void *Context) 759 1.1 jruoho { 760 1.1 jruoho ACPI_STATUS Status = AE_OK; 761 1.1 jruoho ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context; 762 1.1 jruoho ACPI_SIZE ObjectSpace; 763 1.1 jruoho 764 1.1 jruoho 765 1.1 jruoho switch (ObjectType) 766 1.1 jruoho { 767 1.1 jruoho case ACPI_COPY_TYPE_SIMPLE: 768 1.1 jruoho /* 769 1.1 jruoho * Simple object - just get the size (Null object/entry is handled 770 1.1 jruoho * here also) and sum it into the running package length 771 1.1 jruoho */ 772 1.1 jruoho Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace); 773 1.1 jruoho if (ACPI_FAILURE (Status)) 774 1.1 jruoho { 775 1.1 jruoho return (Status); 776 1.1 jruoho } 777 1.1 jruoho 778 1.1 jruoho Info->Length += ObjectSpace; 779 1.1 jruoho break; 780 1.1 jruoho 781 1.1 jruoho case ACPI_COPY_TYPE_PACKAGE: 782 1.1 jruoho 783 1.1 jruoho /* Package object - nothing much to do here, let the walk handle it */ 784 1.1 jruoho 785 1.1 jruoho Info->NumPackages++; 786 1.1 jruoho State->Pkg.ThisTargetObj = NULL; 787 1.1 jruoho break; 788 1.1 jruoho 789 1.1 jruoho default: 790 1.1 jruoho 791 1.1 jruoho /* No other types allowed */ 792 1.1 jruoho 793 1.1 jruoho return (AE_BAD_PARAMETER); 794 1.1 jruoho } 795 1.1 jruoho 796 1.1 jruoho return (Status); 797 1.1 jruoho } 798 1.1 jruoho 799 1.1 jruoho 800 1.1 jruoho /******************************************************************************* 801 1.1 jruoho * 802 1.1 jruoho * FUNCTION: AcpiUtGetPackageObjectSize 803 1.1 jruoho * 804 1.1 jruoho * PARAMETERS: InternalObject - An ACPI internal object 805 1.1 jruoho * ObjLength - Where the length is returned 806 1.1 jruoho * 807 1.1 jruoho * RETURN: Status 808 1.1 jruoho * 809 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to 810 1.1 jruoho * contain a package object for return to an external user. 811 1.1 jruoho * 812 1.1 jruoho * This is moderately complex since a package contains other 813 1.1 jruoho * objects including packages. 814 1.1 jruoho * 815 1.1 jruoho ******************************************************************************/ 816 1.1 jruoho 817 1.1 jruoho static ACPI_STATUS 818 1.1 jruoho AcpiUtGetPackageObjectSize ( 819 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject, 820 1.1 jruoho ACPI_SIZE *ObjLength) 821 1.1 jruoho { 822 1.1 jruoho ACPI_STATUS Status; 823 1.1 jruoho ACPI_PKG_INFO Info; 824 1.1 jruoho 825 1.1 jruoho 826 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject); 827 1.1 jruoho 828 1.1 jruoho 829 1.2 christos Info.Length = 0; 830 1.1 jruoho Info.ObjectSpace = 0; 831 1.1 jruoho Info.NumPackages = 1; 832 1.1 jruoho 833 1.2 christos Status = AcpiUtWalkPackageTree ( 834 1.2 christos InternalObject, NULL, AcpiUtGetElementLength, &Info); 835 1.1 jruoho if (ACPI_FAILURE (Status)) 836 1.1 jruoho { 837 1.1 jruoho return_ACPI_STATUS (Status); 838 1.1 jruoho } 839 1.1 jruoho 840 1.1 jruoho /* 841 1.1 jruoho * We have handled all of the objects in all levels of the package. 842 1.1 jruoho * just add the length of the package objects themselves. 843 1.1 jruoho * Round up to the next machine word. 844 1.1 jruoho */ 845 1.2 christos Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD ( 846 1.2 christos sizeof (ACPI_OBJECT)) * (ACPI_SIZE) Info.NumPackages; 847 1.1 jruoho 848 1.1 jruoho /* Return the total package length */ 849 1.1 jruoho 850 1.1 jruoho *ObjLength = Info.Length; 851 1.1 jruoho return_ACPI_STATUS (Status); 852 1.1 jruoho } 853 1.1 jruoho 854 1.1 jruoho 855 1.1 jruoho /******************************************************************************* 856 1.1 jruoho * 857 1.1 jruoho * FUNCTION: AcpiUtGetObjectSize 858 1.1 jruoho * 859 1.1 jruoho * PARAMETERS: InternalObject - An ACPI internal object 860 1.1 jruoho * ObjLength - Where the length will be returned 861 1.1 jruoho * 862 1.1 jruoho * RETURN: Status 863 1.1 jruoho * 864 1.1 jruoho * DESCRIPTION: This function is called to determine the space required to 865 1.1 jruoho * contain an object for return to an API user. 866 1.1 jruoho * 867 1.1 jruoho ******************************************************************************/ 868 1.1 jruoho 869 1.1 jruoho ACPI_STATUS 870 1.1 jruoho AcpiUtGetObjectSize ( 871 1.1 jruoho ACPI_OPERAND_OBJECT *InternalObject, 872 1.1 jruoho ACPI_SIZE *ObjLength) 873 1.1 jruoho { 874 1.1 jruoho ACPI_STATUS Status; 875 1.1 jruoho 876 1.1 jruoho 877 1.1 jruoho ACPI_FUNCTION_ENTRY (); 878 1.1 jruoho 879 1.1 jruoho 880 1.2 christos if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == 881 1.2 christos ACPI_DESC_TYPE_OPERAND) && 882 1.1 jruoho (InternalObject->Common.Type == ACPI_TYPE_PACKAGE)) 883 1.1 jruoho { 884 1.1 jruoho Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength); 885 1.1 jruoho } 886 1.1 jruoho else 887 1.1 jruoho { 888 1.1 jruoho Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength); 889 1.1 jruoho } 890 1.1 jruoho 891 1.1 jruoho return (Status); 892 1.1 jruoho } 893