2000-10-28 05:01:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* Module Name: utalloc - local memory allocation routines
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-01-13 16:12:34 +00:00
|
|
|
/*
|
2014-01-15 00:10:20 +00:00
|
|
|
* Copyright (C) 2000 - 2014, Intel Corp.
|
2000-12-21 06:56:46 +00:00
|
|
|
* All rights reserved.
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2011-01-13 16:12:34 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
#define __UTALLOC_C__
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2009-06-01 19:24:26 +00:00
|
|
|
#include "acpi.h"
|
2009-06-01 21:02:40 +00:00
|
|
|
#include "accommon.h"
|
2009-06-01 19:24:26 +00:00
|
|
|
#include "acdebug.h"
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
#define _COMPONENT ACPI_UTILITIES
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_MODULE_NAME ("utalloc")
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-08-26 22:28:18 +00:00
|
|
|
|
2013-10-17 00:06:42 +00:00
|
|
|
#if !defined (USE_NATIVE_ALLOCATE_ZEROED)
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiOsAllocateZeroed
|
|
|
|
*
|
|
|
|
* PARAMETERS: Size - Size of the allocation
|
|
|
|
*
|
|
|
|
* RETURN: Address of the allocated memory on success, NULL on failure.
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
|
|
|
|
* This is the default implementation. Can be overridden via the
|
|
|
|
* USE_NATIVE_ALLOCATE_ZEROED flag.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void *
|
|
|
|
AcpiOsAllocateZeroed (
|
|
|
|
ACPI_SIZE Size)
|
|
|
|
{
|
|
|
|
void *Allocation;
|
|
|
|
|
|
|
|
|
|
|
|
ACPI_FUNCTION_ENTRY ();
|
|
|
|
|
|
|
|
|
|
|
|
Allocation = AcpiOsAllocate (Size);
|
|
|
|
if (Allocation)
|
|
|
|
{
|
|
|
|
/* Clear the memory block */
|
|
|
|
|
|
|
|
ACPI_MEMSET (Allocation, 0, Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (Allocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !USE_NATIVE_ALLOCATE_ZEROED */
|
|
|
|
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/*******************************************************************************
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* FUNCTION: AcpiUtCreateCaches
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* PARAMETERS: None
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: Status
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* DESCRIPTION: Create all local caches
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
ACPI_STATUS
|
|
|
|
AcpiUtCreateCaches (
|
|
|
|
void)
|
2001-08-26 22:28:18 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
ACPI_STATUS Status;
|
2001-08-26 22:28:18 +00:00
|
|
|
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
/* Object Caches, for frequently used objects */
|
2002-02-23 05:10:40 +00:00
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
Status = AcpiOsCreateCache ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
|
|
|
|
ACPI_MAX_NAMESPACE_CACHE_DEPTH, &AcpiGbl_NamespaceCache);
|
2005-11-01 22:11:18 +00:00
|
|
|
if (ACPI_FAILURE (Status))
|
2001-08-26 22:28:18 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
return (Status);
|
|
|
|
}
|
2001-08-26 22:28:18 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
Status = AcpiOsCreateCache ("Acpi-State", sizeof (ACPI_GENERIC_STATE),
|
|
|
|
ACPI_MAX_STATE_CACHE_DEPTH, &AcpiGbl_StateCache);
|
|
|
|
if (ACPI_FAILURE (Status))
|
|
|
|
{
|
|
|
|
return (Status);
|
2001-08-26 22:28:18 +00:00
|
|
|
}
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
Status = AcpiOsCreateCache ("Acpi-Parse", sizeof (ACPI_PARSE_OBJ_COMMON),
|
|
|
|
ACPI_MAX_PARSE_CACHE_DEPTH, &AcpiGbl_PsNodeCache);
|
|
|
|
if (ACPI_FAILURE (Status))
|
2001-08-26 22:28:18 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
return (Status);
|
|
|
|
}
|
2001-08-26 22:28:18 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
Status = AcpiOsCreateCache ("Acpi-ParseExt", sizeof (ACPI_PARSE_OBJ_NAMED),
|
|
|
|
ACPI_MAX_EXTPARSE_CACHE_DEPTH, &AcpiGbl_PsNodeExtCache);
|
|
|
|
if (ACPI_FAILURE (Status))
|
|
|
|
{
|
|
|
|
return (Status);
|
|
|
|
}
|
2001-08-26 22:28:18 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
Status = AcpiOsCreateCache ("Acpi-Operand", sizeof (ACPI_OPERAND_OBJECT),
|
|
|
|
ACPI_MAX_OBJECT_CACHE_DEPTH, &AcpiGbl_OperandCache);
|
|
|
|
if (ACPI_FAILURE (Status))
|
|
|
|
{
|
|
|
|
return (Status);
|
2001-08-26 22:28:18 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
|
|
|
|
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
|
|
|
|
|
|
|
|
/* Memory allocation lists */
|
|
|
|
|
|
|
|
Status = AcpiUtCreateList ("Acpi-Global", 0,
|
|
|
|
&AcpiGbl_GlobalList);
|
|
|
|
if (ACPI_FAILURE (Status))
|
|
|
|
{
|
|
|
|
return (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = AcpiUtCreateList ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
|
|
|
|
&AcpiGbl_NsNodeList);
|
|
|
|
if (ACPI_FAILURE (Status))
|
|
|
|
{
|
|
|
|
return (Status);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
return (AE_OK);
|
2001-08-26 22:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/*******************************************************************************
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* FUNCTION: AcpiUtDeleteCaches
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* PARAMETERS: None
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: Status
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* DESCRIPTION: Purge and delete all local caches
|
2001-08-26 22:28:18 +00:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
ACPI_STATUS
|
|
|
|
AcpiUtDeleteCaches (
|
|
|
|
void)
|
2001-08-26 22:28:18 +00:00
|
|
|
{
|
2007-03-22 17:24:05 +00:00
|
|
|
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
|
|
|
|
char Buffer[7];
|
|
|
|
|
|
|
|
if (AcpiGbl_DisplayFinalMemStats)
|
|
|
|
{
|
|
|
|
ACPI_STRCPY (Buffer, "MEMORY");
|
2009-06-01 21:02:40 +00:00
|
|
|
(void) AcpiDbDisplayStatistics (Buffer);
|
2007-03-22 17:24:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(void) AcpiOsDeleteCache (AcpiGbl_NamespaceCache);
|
|
|
|
AcpiGbl_NamespaceCache = NULL;
|
2001-08-26 22:28:18 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
(void) AcpiOsDeleteCache (AcpiGbl_StateCache);
|
|
|
|
AcpiGbl_StateCache = NULL;
|
2001-09-07 01:22:25 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
(void) AcpiOsDeleteCache (AcpiGbl_OperandCache);
|
|
|
|
AcpiGbl_OperandCache = NULL;
|
2001-09-07 01:22:25 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
(void) AcpiOsDeleteCache (AcpiGbl_PsNodeCache);
|
|
|
|
AcpiGbl_PsNodeCache = NULL;
|
2001-08-26 22:28:18 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
(void) AcpiOsDeleteCache (AcpiGbl_PsNodeExtCache);
|
|
|
|
AcpiGbl_PsNodeExtCache = NULL;
|
2001-08-26 22:28:18 +00:00
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
|
|
|
|
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
|
|
|
|
|
|
|
|
/* Debug only - display leftover memory allocation, if any */
|
|
|
|
|
|
|
|
AcpiUtDumpAllocations (ACPI_UINT32_MAX, NULL);
|
|
|
|
|
|
|
|
/* Free memory lists */
|
|
|
|
|
|
|
|
AcpiOsFree (AcpiGbl_GlobalList);
|
|
|
|
AcpiGbl_GlobalList = NULL;
|
|
|
|
|
|
|
|
AcpiOsFree (AcpiGbl_NsNodeList);
|
|
|
|
AcpiGbl_NsNodeList = NULL;
|
|
|
|
#endif
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
return (AE_OK);
|
2001-08-26 22:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiUtValidateBuffer
|
|
|
|
*
|
|
|
|
* PARAMETERS: Buffer - Buffer descriptor to be validated
|
|
|
|
*
|
|
|
|
* RETURN: Status
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Perform parameter validation checks on an ACPI_BUFFER
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
AcpiUtValidateBuffer (
|
|
|
|
ACPI_BUFFER *Buffer)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Obviously, the structure pointer must be valid */
|
|
|
|
|
|
|
|
if (!Buffer)
|
|
|
|
{
|
|
|
|
return (AE_BAD_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Special semantics for the length */
|
|
|
|
|
|
|
|
if ((Buffer->Length == ACPI_NO_BUFFER) ||
|
|
|
|
(Buffer->Length == ACPI_ALLOCATE_BUFFER) ||
|
|
|
|
(Buffer->Length == ACPI_ALLOCATE_LOCAL_BUFFER))
|
|
|
|
{
|
|
|
|
return (AE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Length is valid, the buffer pointer must be also */
|
|
|
|
|
|
|
|
if (!Buffer->Pointer)
|
|
|
|
{
|
|
|
|
return (AE_BAD_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (AE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiUtInitializeBuffer
|
|
|
|
*
|
2004-12-01 23:14:10 +00:00
|
|
|
* PARAMETERS: Buffer - Buffer to be validated
|
|
|
|
* RequiredLength - Length needed
|
2002-02-23 05:10:40 +00:00
|
|
|
*
|
|
|
|
* RETURN: Status
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Validate that the buffer is of the required length or
|
2009-06-01 21:02:40 +00:00
|
|
|
* allocate a new buffer. Returned buffer is always zeroed.
|
2002-02-23 05:10:40 +00:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
AcpiUtInitializeBuffer (
|
|
|
|
ACPI_BUFFER *Buffer,
|
|
|
|
ACPI_SIZE RequiredLength)
|
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
ACPI_SIZE InputBufferLength;
|
2002-02-23 05:10:40 +00:00
|
|
|
|
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
/* Parameter validation */
|
|
|
|
|
|
|
|
if (!Buffer || !RequiredLength)
|
2002-02-23 05:10:40 +00:00
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
return (AE_BAD_PARAMETER);
|
|
|
|
}
|
2002-02-23 05:10:40 +00:00
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
/*
|
|
|
|
* Buffer->Length is used as both an input and output parameter. Get the
|
|
|
|
* input actual length and set the output required buffer length.
|
|
|
|
*/
|
|
|
|
InputBufferLength = Buffer->Length;
|
|
|
|
Buffer->Length = RequiredLength;
|
2002-02-23 05:10:40 +00:00
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
/*
|
|
|
|
* The input buffer length contains the actual buffer length, or the type
|
|
|
|
* of buffer to be allocated by this routine.
|
|
|
|
*/
|
|
|
|
switch (InputBufferLength)
|
|
|
|
{
|
|
|
|
case ACPI_NO_BUFFER:
|
|
|
|
|
|
|
|
/* Return the exception (and the required buffer length) */
|
2001-07-21 03:55:17 +00:00
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
return (AE_BUFFER_OVERFLOW);
|
2001-01-31 09:17:50 +00:00
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
case ACPI_ALLOCATE_BUFFER:
|
2013-12-19 05:51:01 +00:00
|
|
|
/*
|
|
|
|
* Allocate a new buffer. We directectly call AcpiOsAllocate here to
|
|
|
|
* purposefully bypass the (optionally enabled) internal allocation
|
|
|
|
* tracking mechanism since we only want to track internal
|
|
|
|
* allocations. Note: The caller should use AcpiOsFree to free this
|
|
|
|
* buffer created via ACPI_ALLOCATE_BUFFER.
|
|
|
|
*/
|
2002-02-23 05:10:40 +00:00
|
|
|
Buffer->Pointer = AcpiOsAllocate (RequiredLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_ALLOCATE_LOCAL_BUFFER:
|
|
|
|
|
|
|
|
/* Allocate a new buffer with local interface to allow tracking */
|
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
Buffer->Pointer = ACPI_ALLOCATE (RequiredLength);
|
2002-02-23 05:10:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
/* Existing buffer: Validate the size of the buffer */
|
2002-02-23 05:10:40 +00:00
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
if (InputBufferLength < RequiredLength)
|
2002-02-23 05:10:40 +00:00
|
|
|
{
|
2009-06-01 21:02:40 +00:00
|
|
|
return (AE_BUFFER_OVERFLOW);
|
2002-02-23 05:10:40 +00:00
|
|
|
}
|
2009-06-01 21:02:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-12-01 23:14:10 +00:00
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
/* Validate allocation from above or input buffer pointer */
|
2004-12-01 23:14:10 +00:00
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
if (!Buffer->Pointer)
|
|
|
|
{
|
|
|
|
return (AE_NO_MEMORY);
|
2002-02-23 05:10:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 21:02:40 +00:00
|
|
|
/* Have a valid buffer, clear it */
|
|
|
|
|
|
|
|
ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength);
|
|
|
|
return (AE_OK);
|
2002-02-23 05:10:40 +00:00
|
|
|
}
|