/******************************************************************************
*
* Module Name: utcopy - Internal to external object translation utilities
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, Intel Corp.
* 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.h"
#include "accommon.h"
#include "acnamesp.h"
ACPI_MODULE_NAME ("utcopy")
/* Local prototypes */
static ACPI_STATUS
static ACPI_STATUS
void *Context);
static ACPI_STATUS
static ACPI_STATUS
static ACPI_STATUS
static ACPI_STATUS
static ACPI_STATUS
void *Context);
static ACPI_STATUS
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyIsimpleToEsimple
*
* PARAMETERS: InternalObject - Source object to be copied
* ExternalObject - Where to return the copied object
* DataSpace - Where object data is returned (such as
* buffer and string data)
* BufferSpaceUsed - Length of DataSpace that was used
*
* RETURN: Status
*
* DESCRIPTION: This function is called to copy a simple internal object to
* an external object.
*
* The DataSpace buffer is assumed to have sufficient space for
* the object.
*
******************************************************************************/
static ACPI_STATUS
{
*BufferSpaceUsed = 0;
/*
* Check for NULL object case (could be an uninitialized
* package element)
*/
if (!InternalObject)
{
}
/* Always clear the external object */
/*
* In general, the external object will be the same type as
* the internal object
*/
/* However, only a limited number of external types are supported */
{
case ACPI_TYPE_STRING:
break;
case ACPI_TYPE_BUFFER:
break;
case ACPI_TYPE_INTEGER:
break;
/* This is an object reference. */
{
case ACPI_REFCLASS_NAME:
/*
* For namepath, return the object handle ("reference")
* We are referring to the namespace node
*/
break;
default:
/* All other reference types are unsupported */
}
break;
case ACPI_TYPE_PROCESSOR:
break;
case ACPI_TYPE_POWER:
break;
default:
/*
* There is no corresponding external object type
*/
"Unsupported object type, cannot convert to external object: %s",
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyIelementToEelement
*
* PARAMETERS: ACPI_PKG_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Copy one package element to another package element
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
switch (ObjectType)
{
case ACPI_COPY_TYPE_SIMPLE:
/*
* This is a simple or null object
*/
if (ACPI_FAILURE (Status))
{
return (Status);
}
break;
case ACPI_COPY_TYPE_PACKAGE:
/*
* Build the package object
*/
/*
* Pass the new package object back to the package walk routine
*/
/*
* Save space for the array of objects (Package elements)
* update the buffer length counter
*/
sizeof (ACPI_OBJECT));
break;
default:
return (AE_BAD_PARAMETER);
}
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyIpackageToEpackage
*
* PARAMETERS: InternalObject - Pointer to the object we are returning
* Buffer - Where the object is returned
* SpaceUsed - Where the object length is returned
*
* RETURN: Status
*
* DESCRIPTION: This function is called to place a package object in a user
* buffer. A package object by definition contains other objects.
*
* The buffer is assumed to have sufficient space for the object.
* The caller must have verified the buffer length needed using
* the AcpiUtGetObjectSize function before calling this function.
*
******************************************************************************/
static ACPI_STATUS
{
/*
* First package at head of the buffer
*/
/*
* Free space begins right after the first package
*/
ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
Info.ObjectSpace = 0;
/*
* Leave room for an array of ACPI_OBJECTS in the buffer
* and move the free space past it
*/
ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyIobjectToEobject
*
* PARAMETERS: InternalObject - The internal object to be converted
* RetBuffer - Where the object is returned
*
* RETURN: Status
*
* DESCRIPTION: This function is called to build an API object to be returned
* to the caller.
*
******************************************************************************/
{
{
/*
* Package object: Copy all subobjects (including
* nested packages)
*/
}
else
{
/*
* Build a simple object (no nested objects)
*/
ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
/*
* build simple does not include the object size in the length
* so we add it in here
*/
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyEsimpleToIsimple
*
* PARAMETERS: ExternalObject - The external object to be converted
* RetInternalObject - Where the internal object is returned
*
* RETURN: Status
*
* DESCRIPTION: This function copies an external object to an internal one.
* NOTE: Pointers can be copied, we don't need to copy data.
* (The pointers have to be valid in our address space no matter
* what we do with them!)
*
******************************************************************************/
static ACPI_STATUS
{
/*
* Simple types supported are: String, Buffer, Integer
*/
switch (ExternalObject->Type)
{
case ACPI_TYPE_STRING:
case ACPI_TYPE_BUFFER:
case ACPI_TYPE_INTEGER:
if (!InternalObject)
{
}
break;
case ACPI_TYPE_ANY: /* This is the case for a NULL object */
default:
/* All other types are not supported */
"Unsupported object type, cannot convert to internal object: %s",
}
/* Must COPY string and buffer contents */
switch (ExternalObject->Type)
{
case ACPI_TYPE_STRING:
{
goto ErrorExit;
}
break;
case ACPI_TYPE_BUFFER:
{
goto ErrorExit;
}
/* Mark buffer data valid */
break;
case ACPI_TYPE_INTEGER:
break;
/* An incoming reference is defined to be a namespace node */
break;
default:
/* Other types can't get here */
break;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyEpackageToIpackage
*
* PARAMETERS: ExternalObject - The external object to be converted
* InternalObject - Where the internal object is returned
*
* RETURN: Status
*
* DESCRIPTION: Copy an external package object to an internal package.
* Handles nested packages.
*
******************************************************************************/
static ACPI_STATUS
{
UINT32 i;
/* Create the package object */
if (!PackageObject)
{
}
/*
* Recursive implementation. Probably ok, since nested external
* packages as parameters should be very rare.
*/
{
&PackageElements[i]);
if (ACPI_FAILURE (Status))
{
/* Truncate package and delete it */
PackageElements[i] = NULL;
}
}
/* Mark package data valid */
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyEobjectToIobject
*
* PARAMETERS: ExternalObject - The external object to be converted
* InternalObject - Where the internal object is returned
*
* RETURN: Status
*
* DESCRIPTION: Converts an external object to an internal object.
*
******************************************************************************/
{
{
}
else
{
/*
* Build a simple object (no nested objects)
*/
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopySimpleObject
*
* PARAMETERS: SourceDesc - The internal object to be copied
* DestDesc - New target object
*
* RETURN: Status
*
* DESCRIPTION: Simple copy of one internal object to another. Reference count
* of the destination object is preserved.
*
******************************************************************************/
static ACPI_STATUS
{
/* Save fields from destination that we don't want to overwrite */
/*
* Copy the entire source object over the destination object.
* Note: Source can be either an operand object or namespace node.
*/
CopySize = sizeof (ACPI_OPERAND_OBJECT);
{
CopySize = sizeof (ACPI_NAMESPACE_NODE);
}
/* Restore the saved fields */
/* New object is not static, regardless of source */
/* Handle the objects with extra data */
{
case ACPI_TYPE_BUFFER:
/*
* Allocate and copy the actual buffer if and only if:
* 1) There is a valid buffer pointer
* 2) The buffer has a length > 0
*/
{
{
return (AE_NO_MEMORY);
}
/* Copy the actual buffer data */
}
break;
case ACPI_TYPE_STRING:
/*
* Allocate and copy the actual string if and only if:
* 1) There is a valid string pointer
* (Pointer to a NULL string is allowed)
*/
{
{
return (AE_NO_MEMORY);
}
/* Copy the actual string data */
}
break;
/*
* We copied the reference object, so we now must add a reference
* to the object pointed to by the reference
*
* it does not have a Reference.Object, so does not need to
* increase the reference count
*/
{
break;
}
break;
case ACPI_TYPE_REGION:
/*
* We copied the Region Handler, so we now must add a reference
*/
{
}
break;
/*
* For Mutex and Event objects, we cannot simply copy the underlying
* OS object. We must create a new one.
*/
case ACPI_TYPE_MUTEX:
if (ACPI_FAILURE (Status))
{
return (Status);
}
break;
case ACPI_TYPE_EVENT:
if (ACPI_FAILURE (Status))
{
return (Status);
}
break;
default:
/* Nothing to do for other simple objects */
break;
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyIelementToIelement
*
* PARAMETERS: ACPI_PKG_CALLBACK
*
* RETURN: Status
*
* DESCRIPTION: Copy one package element to another package element
*
******************************************************************************/
static ACPI_STATUS
void *Context)
{
ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
switch (ObjectType)
{
case ACPI_COPY_TYPE_SIMPLE:
/* A null source object indicates a (legal) null package element */
if (SourceObject)
{
/*
* This is a simple object, just copy it
*/
if (!TargetObject)
{
return (AE_NO_MEMORY);
}
if (ACPI_FAILURE (Status))
{
goto ErrorExit;
}
}
else
{
/* Pass through a null element */
*ThisTargetPtr = NULL;
}
break;
case ACPI_COPY_TYPE_PACKAGE:
/*
* This object is a package - go down another nesting level
* Create and build the package object
*/
if (!TargetObject)
{
return (AE_NO_MEMORY);
}
/* Pass the new package object back to the package walk routine */
/* Store the object pointer in the parent package object */
break;
default:
return (AE_BAD_PARAMETER);
}
return (Status);
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyIpackageToIpackage
*
* PARAMETERS: SourceObj - Pointer to the source package object
* DestObj - Where the internal object is returned
* WalkState - Current Walk state descriptor
*
* RETURN: Status
*
* DESCRIPTION: This function is called to copy an internal package object
* into another internal package object.
*
******************************************************************************/
static ACPI_STATUS
{
/*
* Create the object array and walk the source package tree
*/
sizeof (void *));
{
}
/*
* Copy the package element-by-element by walking the package "tree".
* This handles nested packages of arbitrary depth.
*/
if (ACPI_FAILURE (Status))
{
/* On failure, delete the destination package object */
}
}
/*******************************************************************************
*
* FUNCTION: AcpiUtCopyIobjectToIobject
*
* PARAMETERS: SourceDesc - The internal object to be copied
* DestDesc - Where the copied object is returned
* WalkState - Current walk state
*
* RETURN: Status
*
* DESCRIPTION: Copy an internal object to a new internal object
*
******************************************************************************/
{
/* Create the top level object */
if (!*DestDesc)
{
}
/* Copy the object and possible subobjects */
{
}
else
{
}
/* Delete the allocated object if copy failed */
if (ACPI_FAILURE (Status))
{
}
}