|
||||
Warning, cross-references for /kernel/drivers/acpica/utalloc.c need to be fixed.
0001 /****************************************************************************** 0002 * 0003 * Module Name: utalloc - local memory allocation routines 0004 * 0005 *****************************************************************************/ 0006 0007 /****************************************************************************** 0008 * 0009 * 1. Copyright Notice 0010 * 0011 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 0012 * All rights reserved. 0013 * 0014 * 2. License 0015 * 0016 * 2.1. This is your license from Intel Corp. under its intellectual property 0017 * rights. You may have additional license terms from the party that provided 0018 * you this software, covering your right to use that party's intellectual 0019 * property rights. 0020 * 0021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 0022 * copy of the source code appearing in this file ("Covered Code") an 0023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 0024 * base code distributed originally by Intel ("Original Intel Code") to copy, 0025 * make derivatives, distribute, use and display any portion of the Covered 0026 * Code in any form, with the right to sublicense such rights; and 0027 * 0028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 0029 * license (with the right to sublicense), under only those claims of Intel 0030 * patents that are infringed by the Original Intel Code, to make, use, sell, 0031 * offer to sell, and import the Covered Code and derivative works thereof 0032 * solely to the minimum extent necessary to exercise the above copyright 0033 * license, and in no event shall the patent license extend to any additions 0034 * to or modifications of the Original Intel Code. No other license or right 0035 * is granted directly or by implication, estoppel or otherwise; 0036 * 0037 * The above copyright and patent license is granted only if the following 0038 * conditions are met: 0039 * 0040 * 3. Conditions 0041 * 0042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 0043 * Redistribution of source code of any substantial portion of the Covered 0044 * Code or modification with rights to further distribute source must include 0045 * the above Copyright Notice, the above License, this list of Conditions, 0046 * and the following Disclaimer and Export Compliance provision. In addition, 0047 * Licensee must cause all Covered Code to which Licensee contributes to 0048 * contain a file documenting the changes Licensee made to create that Covered 0049 * Code and the date of any change. Licensee must include in that file the 0050 * documentation of any changes made by any predecessor Licensee. Licensee 0051 * must include a prominent statement that the modification is derived, 0052 * directly or indirectly, from Original Intel Code. 0053 * 0054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 0055 * Redistribution of source code of any substantial portion of the Covered 0056 * Code or modification without rights to further distribute source must 0057 * include the following Disclaimer and Export Compliance provision in the 0058 * documentation and/or other materials provided with distribution. In 0059 * addition, Licensee may not authorize further sublicense of source of any 0060 * portion of the Covered Code, and must include terms to the effect that the 0061 * license from Licensee to its licensee is limited to the intellectual 0062 * property embodied in the software Licensee provides to its licensee, and 0063 * not to intellectual property embodied in modifications its licensee may 0064 * make. 0065 * 0066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 0067 * substantial portion of the Covered Code or modification must reproduce the 0068 * above Copyright Notice, and the following Disclaimer and Export Compliance 0069 * provision in the documentation and/or other materials provided with the 0070 * distribution. 0071 * 0072 * 3.4. Intel retains all right, title, and interest in and to the Original 0073 * Intel Code. 0074 * 0075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 0076 * Intel shall be used in advertising or otherwise to promote the sale, use or 0077 * other dealings in products derived from or relating to the Covered Code 0078 * without prior written authorization from Intel. 0079 * 0080 * 4. Disclaimer and Export Compliance 0081 * 0082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 0083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 0084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 0085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 0086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 0087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 0088 * PARTICULAR PURPOSE. 0089 * 0090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 0091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 0092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 0093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 0094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 0095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 0096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 0097 * LIMITED REMEDY. 0098 * 0099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 0100 * software or system incorporating such software without first obtaining any 0101 * required license or other approval from the U. S. Department of Commerce or 0102 * any other agency or department of the United States Government. In the 0103 * event Licensee exports any such software from the United States or 0104 * re-exports any such software from a foreign destination, Licensee shall 0105 * ensure that the distribution and export/re-export of the software is in 0106 * compliance with all laws, regulations, orders, or other restrictions of the 0107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 0108 * any of its subsidiaries will export/re-export any technical data, process, 0109 * software, or service, directly or indirectly, to any country for which the 0110 * United States government or any agency thereof requires an export license, 0111 * other governmental approval, or letter of assurance, without first obtaining 0112 * such license, approval or letter. 0113 * 0114 *****************************************************************************/ 0115 0116 #define __UTALLOC_C__ 0117 0118 #include "acpi.h" 0119 #include "accommon.h" 0120 #include "acdebug.h" 0121 0122 #define _COMPONENT ACPI_UTILITIES 0123 ACPI_MODULE_NAME ("utalloc") 0124 0125 0126 /******************************************************************************* 0127 * 0128 * FUNCTION: AcpiUtCreateCaches 0129 * 0130 * PARAMETERS: None 0131 * 0132 * RETURN: Status 0133 * 0134 * DESCRIPTION: Create all local caches 0135 * 0136 ******************************************************************************/ 0137 0138 ACPI_STATUS 0139 AcpiUtCreateCaches ( 0140 void) 0141 { 0142 ACPI_STATUS Status; 0143 0144 0145 /* Object Caches, for frequently used objects */ 0146 0147 Status = AcpiOsCreateCache ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE), 0148 ACPI_MAX_NAMESPACE_CACHE_DEPTH, &AcpiGbl_NamespaceCache); 0149 if (ACPI_FAILURE (Status)) 0150 { 0151 return (Status); 0152 } 0153 0154 Status = AcpiOsCreateCache ("Acpi-State", sizeof (ACPI_GENERIC_STATE), 0155 ACPI_MAX_STATE_CACHE_DEPTH, &AcpiGbl_StateCache); 0156 if (ACPI_FAILURE (Status)) 0157 { 0158 return (Status); 0159 } 0160 0161 Status = AcpiOsCreateCache ("Acpi-Parse", sizeof (ACPI_PARSE_OBJ_COMMON), 0162 ACPI_MAX_PARSE_CACHE_DEPTH, &AcpiGbl_PsNodeCache); 0163 if (ACPI_FAILURE (Status)) 0164 { 0165 return (Status); 0166 } 0167 0168 Status = AcpiOsCreateCache ("Acpi-ParseExt", sizeof (ACPI_PARSE_OBJ_NAMED), 0169 ACPI_MAX_EXTPARSE_CACHE_DEPTH, &AcpiGbl_PsNodeExtCache); 0170 if (ACPI_FAILURE (Status)) 0171 { 0172 return (Status); 0173 } 0174 0175 Status = AcpiOsCreateCache ("Acpi-Operand", sizeof (ACPI_OPERAND_OBJECT), 0176 ACPI_MAX_OBJECT_CACHE_DEPTH, &AcpiGbl_OperandCache); 0177 if (ACPI_FAILURE (Status)) 0178 { 0179 return (Status); 0180 } 0181 0182 0183 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 0184 0185 /* Memory allocation lists */ 0186 0187 Status = AcpiUtCreateList ("Acpi-Global", 0, 0188 &AcpiGbl_GlobalList); 0189 if (ACPI_FAILURE (Status)) 0190 { 0191 return (Status); 0192 } 0193 0194 Status = AcpiUtCreateList ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE), 0195 &AcpiGbl_NsNodeList); 0196 if (ACPI_FAILURE (Status)) 0197 { 0198 return (Status); 0199 } 0200 #endif 0201 0202 return (AE_OK); 0203 } 0204 0205 0206 /******************************************************************************* 0207 * 0208 * FUNCTION: AcpiUtDeleteCaches 0209 * 0210 * PARAMETERS: None 0211 * 0212 * RETURN: Status 0213 * 0214 * DESCRIPTION: Purge and delete all local caches 0215 * 0216 ******************************************************************************/ 0217 0218 ACPI_STATUS 0219 AcpiUtDeleteCaches ( 0220 void) 0221 { 0222 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 0223 char Buffer[7]; 0224 0225 if (AcpiGbl_DisplayFinalMemStats) 0226 { 0227 ACPI_STRCPY (Buffer, "MEMORY"); 0228 (void) AcpiDbDisplayStatistics (Buffer); 0229 } 0230 #endif 0231 0232 (void) AcpiOsDeleteCache (AcpiGbl_NamespaceCache); 0233 AcpiGbl_NamespaceCache = NULL; 0234 0235 (void) AcpiOsDeleteCache (AcpiGbl_StateCache); 0236 AcpiGbl_StateCache = NULL; 0237 0238 (void) AcpiOsDeleteCache (AcpiGbl_OperandCache); 0239 AcpiGbl_OperandCache = NULL; 0240 0241 (void) AcpiOsDeleteCache (AcpiGbl_PsNodeCache); 0242 AcpiGbl_PsNodeCache = NULL; 0243 0244 (void) AcpiOsDeleteCache (AcpiGbl_PsNodeExtCache); 0245 AcpiGbl_PsNodeExtCache = NULL; 0246 0247 0248 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 0249 0250 /* Debug only - display leftover memory allocation, if any */ 0251 0252 AcpiUtDumpAllocations (ACPI_UINT32_MAX, NULL); 0253 0254 /* Free memory lists */ 0255 0256 AcpiOsFree (AcpiGbl_GlobalList); 0257 AcpiGbl_GlobalList = NULL; 0258 0259 AcpiOsFree (AcpiGbl_NsNodeList); 0260 AcpiGbl_NsNodeList = NULL; 0261 #endif 0262 0263 return (AE_OK); 0264 } 0265 0266 0267 /******************************************************************************* 0268 * 0269 * FUNCTION: AcpiUtValidateBuffer 0270 * 0271 * PARAMETERS: Buffer - Buffer descriptor to be validated 0272 * 0273 * RETURN: Status 0274 * 0275 * DESCRIPTION: Perform parameter validation checks on an ACPI_BUFFER 0276 * 0277 ******************************************************************************/ 0278 0279 ACPI_STATUS 0280 AcpiUtValidateBuffer ( 0281 ACPI_BUFFER *Buffer) 0282 { 0283 0284 /* Obviously, the structure pointer must be valid */ 0285 0286 if (!Buffer) 0287 { 0288 return (AE_BAD_PARAMETER); 0289 } 0290 0291 /* Special semantics for the length */ 0292 0293 if ((Buffer->Length == ACPI_NO_BUFFER) || 0294 (Buffer->Length == ACPI_ALLOCATE_BUFFER) || 0295 (Buffer->Length == ACPI_ALLOCATE_LOCAL_BUFFER)) 0296 { 0297 return (AE_OK); 0298 } 0299 0300 /* Length is valid, the buffer pointer must be also */ 0301 0302 if (!Buffer->Pointer) 0303 { 0304 return (AE_BAD_PARAMETER); 0305 } 0306 0307 return (AE_OK); 0308 } 0309 0310 0311 /******************************************************************************* 0312 * 0313 * FUNCTION: AcpiUtInitializeBuffer 0314 * 0315 * PARAMETERS: Buffer - Buffer to be validated 0316 * RequiredLength - Length needed 0317 * 0318 * RETURN: Status 0319 * 0320 * DESCRIPTION: Validate that the buffer is of the required length or 0321 * allocate a new buffer. Returned buffer is always zeroed. 0322 * 0323 ******************************************************************************/ 0324 0325 ACPI_STATUS 0326 AcpiUtInitializeBuffer ( 0327 ACPI_BUFFER *Buffer, 0328 ACPI_SIZE RequiredLength) 0329 { 0330 ACPI_SIZE InputBufferLength; 0331 0332 0333 /* Parameter validation */ 0334 0335 if (!Buffer || !RequiredLength) 0336 { 0337 return (AE_BAD_PARAMETER); 0338 } 0339 0340 /* 0341 * Buffer->Length is used as both an input and output parameter. Get the 0342 * input actual length and set the output required buffer length. 0343 */ 0344 InputBufferLength = Buffer->Length; 0345 Buffer->Length = RequiredLength; 0346 0347 /* 0348 * The input buffer length contains the actual buffer length, or the type 0349 * of buffer to be allocated by this routine. 0350 */ 0351 switch (InputBufferLength) 0352 { 0353 case ACPI_NO_BUFFER: 0354 0355 /* Return the exception (and the required buffer length) */ 0356 0357 return (AE_BUFFER_OVERFLOW); 0358 0359 case ACPI_ALLOCATE_BUFFER: 0360 0361 /* Allocate a new buffer */ 0362 0363 Buffer->Pointer = AcpiOsAllocate (RequiredLength); 0364 break; 0365 0366 case ACPI_ALLOCATE_LOCAL_BUFFER: 0367 0368 /* Allocate a new buffer with local interface to allow tracking */ 0369 0370 Buffer->Pointer = ACPI_ALLOCATE (RequiredLength); 0371 break; 0372 0373 default: 0374 0375 /* Existing buffer: Validate the size of the buffer */ 0376 0377 if (InputBufferLength < RequiredLength) 0378 { 0379 return (AE_BUFFER_OVERFLOW); 0380 } 0381 break; 0382 } 0383 0384 /* Validate allocation from above or input buffer pointer */ 0385 0386 if (!Buffer->Pointer) 0387 { 0388 return (AE_NO_MEMORY); 0389 } 0390 0391 /* Have a valid buffer, clear it */ 0392 0393 ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength); 0394 return (AE_OK); 0395 } 0396 0397 0398 /******************************************************************************* 0399 * 0400 * FUNCTION: AcpiUtAllocate 0401 * 0402 * PARAMETERS: Size - Size of the allocation 0403 * Component - Component type of caller 0404 * Module - Source file name of caller 0405 * Line - Line number of caller 0406 * 0407 * RETURN: Address of the allocated memory on success, NULL on failure. 0408 * 0409 * DESCRIPTION: Subsystem equivalent of malloc. 0410 * 0411 ******************************************************************************/ 0412 0413 void * 0414 AcpiUtAllocate ( 0415 ACPI_SIZE Size, 0416 UINT32 Component, 0417 const char *Module, 0418 UINT32 Line) 0419 { 0420 void *Allocation; 0421 0422 0423 ACPI_FUNCTION_TRACE_U32 (UtAllocate, Size); 0424 0425 0426 /* Check for an inadvertent size of zero bytes */ 0427 0428 if (!Size) 0429 { 0430 ACPI_WARNING ((Module, Line, 0431 "Attempt to allocate zero bytes, allocating 1 byte")); 0432 Size = 1; 0433 } 0434 0435 Allocation = AcpiOsAllocate (Size); 0436 if (!Allocation) 0437 { 0438 /* Report allocation error */ 0439 0440 ACPI_WARNING ((Module, Line, 0441 "Could not allocate size %X", (UINT32) Size)); 0442 0443 return_PTR (NULL); 0444 } 0445 0446 return_PTR (Allocation); 0447 } 0448 0449 0450 /******************************************************************************* 0451 * 0452 * FUNCTION: AcpiUtAllocateZeroed 0453 * 0454 * PARAMETERS: Size - Size of the allocation 0455 * Component - Component type of caller 0456 * Module - Source file name of caller 0457 * Line - Line number of caller 0458 * 0459 * RETURN: Address of the allocated memory on success, NULL on failure. 0460 * 0461 * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory. 0462 * 0463 ******************************************************************************/ 0464 0465 void * 0466 AcpiUtAllocateZeroed ( 0467 ACPI_SIZE Size, 0468 UINT32 Component, 0469 const char *Module, 0470 UINT32 Line) 0471 { 0472 void *Allocation; 0473 0474 0475 ACPI_FUNCTION_ENTRY (); 0476 0477 0478 Allocation = AcpiUtAllocate (Size, Component, Module, Line); 0479 if (Allocation) 0480 { 0481 /* Clear the memory block */ 0482 0483 ACPI_MEMSET (Allocation, 0, Size); 0484 } 0485 0486 return (Allocation); 0487 } 0488
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 1.2.0 LXR engine. |