summaryrefslogtreecommitdiffstats
path: root/sys/contrib/dev/acpica/nsalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/dev/acpica/nsalloc.c')
-rw-r--r--sys/contrib/dev/acpica/nsalloc.c178
1 files changed, 128 insertions, 50 deletions
diff --git a/sys/contrib/dev/acpica/nsalloc.c b/sys/contrib/dev/acpica/nsalloc.c
index cab91bd..16160aa 100644
--- a/sys/contrib/dev/acpica/nsalloc.c
+++ b/sys/contrib/dev/acpica/nsalloc.c
@@ -1,7 +1,7 @@
/*******************************************************************************
*
* Module Name: nsalloc - Namespace allocation and deletion utilities
- * $Revision: 74 $
+ * $Revision: 77 $
*
******************************************************************************/
@@ -223,6 +223,60 @@ AcpiNsDeleteNode (
}
+#ifdef ACPI_ALPHABETIC_NAMESPACE
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiNsCompareNames
+ *
+ * PARAMETERS: Name1 - First name to compare
+ * Name2 - Second name to compare
+ *
+ * RETURN: value from strncmp
+ *
+ * DESCRIPTION: Compare two ACPI names. Names that are prefixed with an
+ * underscore are forced to be alphabetically first.
+ *
+ ******************************************************************************/
+
+int
+AcpiNsCompareNames (
+ char *Name1,
+ char *Name2)
+{
+ char ReversedName1[ACPI_NAME_SIZE];
+ char ReversedName2[ACPI_NAME_SIZE];
+ UINT32 i;
+ UINT32 j;
+
+
+ /*
+ * Replace all instances of "underscore" with a value that is smaller so
+ * that all names that are prefixed with underscore(s) are alphabetically
+ * first.
+ *
+ * Reverse the name bytewise so we can just do a 32-bit compare instead
+ * of a strncmp.
+ */
+ for (i = 0, j= (ACPI_NAME_SIZE - 1); i < ACPI_NAME_SIZE; i++, j--)
+ {
+ ReversedName1[j] = Name1[i];
+ if (Name1[i] == '_')
+ {
+ ReversedName1[j] = '*';
+ }
+
+ ReversedName2[j] = Name2[i];
+ if (Name2[i] == '_')
+ {
+ ReversedName2[j] = '*';
+ }
+ }
+
+ return (*(int *) ReversedName1 - *(int *) ReversedName2);
+}
+#endif
+
+
/*******************************************************************************
*
* FUNCTION: AcpiNsInstallNode
@@ -237,8 +291,10 @@ AcpiNsDeleteNode (
* DESCRIPTION: Initialize a new namespace node and install it amongst
* its peers.
*
- * Note: Current namespace lookup is linear search, so the nodes
- * are not linked in any particular order.
+ * Note: Current namespace lookup is linear search. However, the
+ * nodes are linked in alphabetical order to 1) put all reserved
+ * names (start with underscore) first, and to 2) make a readable
+ * namespace dump.
*
******************************************************************************/
@@ -251,6 +307,10 @@ AcpiNsInstallNode (
{
UINT16 OwnerId = TABLE_ID_DSDT;
ACPI_NAMESPACE_NODE *ChildNode;
+#ifdef ACPI_ALPHABETIC_NAMESPACE
+
+ ACPI_NAMESPACE_NODE *PreviousChildNode;
+#endif
ACPI_FUNCTION_TRACE ("NsInstallNode");
@@ -272,9 +332,66 @@ AcpiNsInstallNode (
if (!ChildNode)
{
ParentNode->Child = Node;
+ Node->Flags |= ANOBJ_END_OF_PEER_LIST;
+ Node->Peer = ParentNode;
}
else
{
+#ifdef ACPI_ALPHABETIC_NAMESPACE
+ /*
+ * Walk the list whilst searching for the the correct
+ * alphabetic placement.
+ */
+ PreviousChildNode = NULL;
+ while (AcpiNsCompareNames (ChildNode->Name.Ascii, Node->Name.Ascii) < 0)
+ {
+ if (ChildNode->Flags & ANOBJ_END_OF_PEER_LIST)
+ {
+ /* Last peer; Clear end-of-list flag */
+
+ ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
+
+ /* This node is the new peer to the child node */
+
+ ChildNode->Peer = Node;
+
+ /* This node is the new end-of-list */
+
+ Node->Flags |= ANOBJ_END_OF_PEER_LIST;
+ Node->Peer = ParentNode;
+ break;
+ }
+
+ /* Get next peer */
+
+ PreviousChildNode = ChildNode;
+ ChildNode = ChildNode->Peer;
+ }
+
+ /* Did the node get inserted at the end-of-list? */
+
+ if (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
+ {
+ /*
+ * Loop above terminated without reaching the end-of-list.
+ * Insert the new node at the current location
+ */
+ if (PreviousChildNode)
+ {
+ /* Insert node alphabetically */
+
+ Node->Peer = ChildNode;
+ PreviousChildNode->Peer = Node;
+ }
+ else
+ {
+ /* Insert node alphabetically at start of list */
+
+ Node->Peer = ChildNode;
+ ParentNode->Child = Node;
+ }
+ }
+#else
while (!(ChildNode->Flags & ANOBJ_END_OF_PEER_LIST))
{
ChildNode = ChildNode->Peer;
@@ -285,58 +402,19 @@ AcpiNsInstallNode (
/* Clear end-of-list flag */
ChildNode->Flags &= ~ANOBJ_END_OF_PEER_LIST;
+ Node->Flags |= ANOBJ_END_OF_PEER_LIST;
+ Node->Peer = ParentNode;
+#endif
}
/* Init the new entry */
- Node->OwnerId = OwnerId;
- Node->Flags |= ANOBJ_END_OF_PEER_LIST;
- Node->Peer = ParentNode;
-
-
- /*
- * If adding a name with unknown type, or having to
- * add the region in order to define fields in it, we
- * have a forward reference.
- */
- if ((ACPI_TYPE_ANY == Type) ||
- (INTERNAL_TYPE_FIELD_DEFN == Type) ||
- (INTERNAL_TYPE_BANK_FIELD_DEFN == Type))
- {
- /*
- * We don't want to abort here, however!
- * We will fill in the actual type when the
- * real definition is found later.
- */
- ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] is a forward reference\n",
- Node->Name.Ascii));
- }
-
- /*
- * The DefFieldDefn and BankFieldDefn cases are actually
- * looking up the Region in which the field will be defined
- */
- if ((INTERNAL_TYPE_FIELD_DEFN == Type) ||
- (INTERNAL_TYPE_BANK_FIELD_DEFN == Type))
- {
- Type = ACPI_TYPE_REGION;
- }
-
- /*
- * Scope, DefAny, and IndexFieldDefn are bogus "types" which do
- * not actually have anything to do with the type of the name
- * being looked up. Save any other value of Type as the type of
- * the entry.
- */
- if ((Type != INTERNAL_TYPE_SCOPE) &&
- (Type != INTERNAL_TYPE_DEF_ANY) &&
- (Type != INTERNAL_TYPE_INDEX_FIELD_DEFN))
- {
- Node->Type = (UINT8) Type;
- }
+ Node->OwnerId = OwnerId;
+ Node->Type = (UINT8) Type;
- ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%4.4s added to %p at %p\n",
- Node->Name.Ascii, ParentNode, Node));
+ ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%4.4s (%s) added to %4.4s (%s) %p at %p\n",
+ Node->Name.Ascii, AcpiUtGetTypeName (Node->Type),
+ ParentNode->Name.Ascii, AcpiUtGetTypeName (ParentNode->Type), ParentNode, Node));
/*
* Increment the reference count(s) of all parents up to
OpenPOWER on IntegriCloud