aboutsummaryrefslogtreecommitdiff
path: root/namespace/nsxfname.c
diff options
context:
space:
mode:
Diffstat (limited to 'namespace/nsxfname.c')
-rw-r--r--namespace/nsxfname.c174
1 files changed, 172 insertions, 2 deletions
diff --git a/namespace/nsxfname.c b/namespace/nsxfname.c
index 6326865669b7..49ccb58092fa 100644
--- a/namespace/nsxfname.c
+++ b/namespace/nsxfname.c
@@ -2,7 +2,6 @@
*
* Module Name: nsxfname - Public interfaces to the ACPI subsystem
* ACPI Namespace oriented interfaces
- * $Revision: 1.112 $
*
*****************************************************************************/
@@ -10,7 +9,7 @@
*
* 1. Copyright Notice
*
- * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
+ * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
* All rights reserved.
*
* 2. License
@@ -118,7 +117,10 @@
#define __NSXFNAME_C__
#include "acpi.h"
+#include "accommon.h"
#include "acnamesp.h"
+#include "acparser.h"
+#include "amlcode.h"
#define _COMPONENT ACPI_NAMESPACE
@@ -361,6 +363,7 @@ AcpiGetObjectInfo (
if (!Node)
{
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
+ Status = AE_BAD_PARAMETER;
goto Cleanup;
}
@@ -372,6 +375,11 @@ AcpiGetObjectInfo (
Info->Name = Node->Name.Integer;
Info->Valid = 0;
+ if (Node->Type == ACPI_TYPE_METHOD)
+ {
+ Info->ParamCount = Node->Object->Method.ParamCount;
+ }
+
Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
@@ -472,3 +480,165 @@ Cleanup:
ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
+
+/******************************************************************************
+ *
+ * FUNCTION: AcpiInstallMethod
+ *
+ * PARAMETERS: Buffer - An ACPI table containing one control method
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Install a control method into the namespace. If the method
+ * name already exists in the namespace, it is overwritten. The
+ * input buffer must contain a valid DSDT or SSDT containing a
+ * single control method.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiInstallMethod (
+ UINT8 *Buffer)
+{
+ ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
+ UINT8 *AmlBuffer;
+ UINT8 *AmlStart;
+ char *Path;
+ ACPI_NAMESPACE_NODE *Node;
+ ACPI_OPERAND_OBJECT *MethodObj;
+ ACPI_PARSE_STATE ParserState;
+ UINT32 AmlLength;
+ UINT16 Opcode;
+ UINT8 MethodFlags;
+ ACPI_STATUS Status;
+
+
+ /* Parameter validation */
+
+ if (!Buffer)
+ {
+ return (AE_BAD_PARAMETER);
+ }
+
+ /* Table must be a DSDT or SSDT */
+
+ if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
+ !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
+ {
+ return (AE_BAD_HEADER);
+ }
+
+ /* First AML opcode in the table must be a control method */
+
+ ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
+ Opcode = AcpiPsPeekOpcode (&ParserState);
+ if (Opcode != AML_METHOD_OP)
+ {
+ return (AE_BAD_PARAMETER);
+ }
+
+ /* Extract method information from the raw AML */
+
+ ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
+ ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
+ Path = AcpiPsGetNextNamestring (&ParserState);
+ MethodFlags = *ParserState.Aml++;
+ AmlStart = ParserState.Aml;
+ AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
+
+ /*
+ * Allocate resources up-front. We don't want to have to delete a new
+ * node from the namespace if we cannot allocate memory.
+ */
+ AmlBuffer = ACPI_ALLOCATE (AmlLength);
+ if (!AmlBuffer)
+ {
+ return (AE_NO_MEMORY);
+ }
+
+ MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
+ if (!MethodObj)
+ {
+ ACPI_FREE (AmlBuffer);
+ return (AE_NO_MEMORY);
+ }
+
+ /* Lock namespace for AcpiNsLookup, we may be creating a new node */
+
+ Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
+ if (ACPI_FAILURE (Status))
+ {
+ goto ErrorExit;
+ }
+
+ /* The lookup either returns an existing node or creates a new one */
+
+ Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
+ ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
+
+ (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
+
+ if (ACPI_FAILURE (Status)) /* NsLookup */
+ {
+ if (Status != AE_ALREADY_EXISTS)
+ {
+ goto ErrorExit;
+ }
+
+ /* Node existed previously, make sure it is a method node */
+
+ if (Node->Type != ACPI_TYPE_METHOD)
+ {
+ Status = AE_TYPE;
+ goto ErrorExit;
+ }
+ }
+
+ /* Copy the method AML to the local buffer */
+
+ ACPI_MEMCPY (AmlBuffer, AmlStart, AmlLength);
+
+ /* Initialize the method object with the new method's information */
+
+ MethodObj->Method.AmlStart = AmlBuffer;
+ MethodObj->Method.AmlLength = AmlLength;
+
+ MethodObj->Method.ParamCount = (UINT8)
+ (MethodFlags & AML_METHOD_ARG_COUNT);
+
+ MethodObj->Method.MethodFlags = (UINT8)
+ (MethodFlags & ~AML_METHOD_ARG_COUNT);
+
+ if (MethodFlags & AML_METHOD_SERIALIZED)
+ {
+ MethodObj->Method.SyncLevel = (UINT8)
+ ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
+ }
+
+ /*
+ * Now that it is complete, we can attach the new method object to
+ * the method Node (detaches/deletes any existing object)
+ */
+ Status = AcpiNsAttachObject (Node, MethodObj,
+ ACPI_TYPE_METHOD);
+
+ /*
+ * Flag indicates AML buffer is dynamic, must be deleted later.
+ * Must be set only after attach above.
+ */
+ Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
+
+ /* Remove local reference to the method object */
+
+ AcpiUtRemoveReference (MethodObj);
+ return (Status);
+
+
+ErrorExit:
+
+ ACPI_FREE (AmlBuffer);
+ ACPI_FREE (MethodObj);
+ return (Status);
+}
+
+ACPI_EXPORT_SYMBOL (AcpiInstallMethod)