Completed and tested routines that automatically reserve linux resources
[keystone-rtos/rm-lld.git] / src / rm.c
index 32be8a8f04fc7508708753bcd4c0267f919304d7..3947f68b1c8faf2024bf54703fe3026b4eb2a65c 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -784,7 +784,7 @@ int32_t Rm_createTreeAllocator(Rm_Inst *rmInst, const char *resourceName, Rm_Res
     /* Create a node in the tree for resource range and insert them into the tree. */\r
     while (range != NULL)\r
     {\r
-        Rm_newResourceTreeNode(range->base, range->length, RM_NOT_ALLOCATED_STRING);\r
+        treeNode = Rm_newResourceTreeNode(range->base, range->length, RM_NOT_ALLOCATED_STRING);\r
 \r
         /* Insert the node into the tree */\r
         collidingNode = RB_INSERT(_Rm_ResourceTree, treeRootEntry, treeNode);\r
@@ -913,7 +913,7 @@ int32_t Rm_treeAllocate(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
     Rm_ResourceTreeNode findNode;\r
     Rm_ResourceTreeNode *matchingNode = NULL;\r
     Rm_ResourceTreeNode *leftNode = NULL;\r
-    Rm_ResourceTreeNode *rightNode = NULL;\r
+    Rm_ResourceTreeNode *rightNode = NULL;  \r
     uint32_t findEnd, matchingEnd;\r
     int32_t retVal;\r
 \r
@@ -930,117 +930,149 @@ int32_t Rm_treeAllocate(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
         /* Does the request range fit within the matching nodes entire range? */\r
         if ((findNode.base >= matchingNode->base) && (findEnd <= matchingEnd))\r
         {\r
-            /* Handle requested resource range that is isolated to a single node\r
-             *\r
-             *\r
-             * base0                                  base0+length0-1\r
-             *   |<---------------length0------------------->|  => existing node\r
-             *         |<---------length1---------->|  => requested resources\r
-             *       base1                   base1+length1-1\r
-             */             \r
+            /* Handle node create, combine, deletion based on the request range if\r
+             * resources are available. */\r
             if (strcmp(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0)\r
             {\r
-                /* Resources are available - split up the node into potentially\r
-                 * three new nodes:\r
-                 * left node - free resources to left of newly allocated resources\r
-                 * middle node - newly allocated resources that satisfy the request\r
-                 * right node - free resources to the right of newly allocated resources\r
+                /* Handle case where the findNode range matches the matchingNode\r
+                 * range exactly.\r
                  *\r
-                 * There also may be combine possibilities to the left and right of the\r
-                 * matching node.  Need to extract those as well to check */\r
-                leftNode = RB_PREV(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
-                rightNode = RB_NEXT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
-\r
-                /* Remove the matching node from the tree and the nodes to the left and\r
-                 * right of the matching node.  Removing from tree will not\r
-                 * wipe any of the base+length data in the node.  Can reuse since they won't\r
-                 * be freed */\r
-                RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
-                if (leftNode)\r
+                 * base0                                  base0+length0-1\r
+                 *   |<---------------length0------------------->|  => existing node\r
+                 *   |<---------------length1------------------->|  => requested resources\r
+                 * base1                                  base1+length1-1\r
+                 */    \r
+                if ((findNode.base == matchingNode->base) && (findEnd == matchingEnd))\r
                 {\r
-                    RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+                    /* Can reserve matchingNode's resources in-place */\r
+                    strcpy(matchingNode->allocatedTo, opInfo->srcInstName);\r
                 }\r
-                if (rightNode)\r
+                /* Handle case where the findNode range is a subset of the matchingNode\r
+                 * range and neither of the boundaries of the two ranges are equivalent.\r
+                 *\r
+                 * base0                                  base0+length0-1\r
+                 *   |<---------------length0------------------->|  => existing node\r
+                 *         |<---------length1---------->|  => requested resources\r
+                 *       base1                   base1+length1-1\r
+                 */    \r
+                else if ((findNode.base > matchingNode->base) && (findEnd < matchingEnd))\r
                 {\r
-                    RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
-                }\r
+                    /* Split the matching node into three nodes:\r
+                     * left node - free resources to left of newly allocated resources\r
+                     * middle node - newly allocated resources that satisfy the request\r
+                     * right node - free resources to the right of newly allocated resources */\r
 \r
-                /* Create the left node if needed.  If the bases are equal the matchingNode can\r
-                 * be reused as the left bound of the range. */\r
-                if (findNode.base > matchingNode->base)\r
-                {\r
-                    /* Can the left node be combined with the node to the left of the matching\r
-                     * node */\r
-                    if (leftNode && (strcmp(leftNode->allocatedTo, opInfo->srcInstName) == 0))\r
-                    {\r
-                        /* Combine the left node and what's leftover on the left side of the \r
-                         * matchingNode range after the allocation */\r
-                        leftNode->length += (findNode.base - matchingNode->base);\r
-                    }\r
-                    else\r
+                    /* Remove the matching node from the tree for modification. */\r
+                    RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+\r
+                    /* New left node attributes:\r
+                     * base: base of the matching node\r
+                     * length: base of requested resources - base of matching node */\r
+                    leftNode = Rm_newResourceTreeNode(matchingNode->base, findNode.base - matchingNode->base,\r
+                                                      RM_NOT_ALLOCATED_STRING);\r
+                    /* New right node attributes:\r
+                     * base: base of the requested resources + length of requested resources\r
+                     * length: right bound of matching node - right bound of request resources */\r
+                    rightNode = Rm_newResourceTreeNode(findNode.base + findNode.length,\r
+                                                       matchingEnd - findEnd, RM_NOT_ALLOCATED_STRING);\r
+\r
+                    /* Base and length of matching node become the base and length of the\r
+                     * requested resources */\r
+                    matchingNode->base = findNode.base;                                    \r
+                    matchingNode->length = findNode.length;\r
+                    /* Reserve the resources */\r
+                    strcpy(matchingNode->allocatedTo, opInfo->srcInstName);\r
+\r
+                    /* Insert all the nodes */\r
+                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+                }\r
+                /* Handle cases where one of findNode range boundaries is equivalent to\r
+                 * one of the matchingNode range boundaries.\r
+                 *\r
+                 * base0                                  base0+length0-1\r
+                 *   |<---------------length0------------------->|  => existing node\r
+                 *   |<---------length1---------->|  => requested resources\r
+                 * base1                   base1+length1-1\r
+                 *\r
+                 * OR\r
+                 *\r
+                 * base0                                  base0+length0-1\r
+                 *   |<---------------length0------------------->|  => existing node\r
+                 *                  |<---------length1---------->|  => requested resources\r
+                 *                base1                   base1+length1-1                 \r
+                 */    \r
+                else\r
+                {     \r
+                    /* Remove the matchingNode from the tree since it will be edited */\r
+                    RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                    \r
+                    if (findNode.base == matchingNode->base)\r
                     {\r
-                        /* Reinsert left node and create a new node to left of range to be allocated */\r
-                        if (leftNode)\r
+                        /* There may be a combine possibility to the left. Extract leftNode to check */\r
+                        leftNode = RB_PREV(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                        \r
+                        /* Can the node to the left of the matchingNode be combined with the \r
+                         * findNode's range? */\r
+                        if (leftNode && (strcmp(leftNode->allocatedTo, opInfo->srcInstName) == 0))\r
+                        {\r
+                            /* Remove the leftNode from the tree for editing */\r
+                            RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+\r
+                            /* Combine the leftNode and the findNode */\r
+                            leftNode->length += findNode.length;\r
+                        }\r
+                        else\r
                         {\r
-                            RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+                            /* Allocate a new leftNode that will take the place of the findNode\r
+                             * range in tree. */\r
+                            leftNode = Rm_newResourceTreeNode(findNode.base, findNode.length,\r
+                                                              opInfo->srcInstName);\r
                         }\r
-                        \r
-                        /* New left node attributes:\r
-                         * base: base of the matching node\r
-                         * length: base of requested resources - base of matching node */\r
-                        leftNode = Rm_newResourceTreeNode(matchingNode->base, findNode.base - matchingNode->base,\r
-                                                          RM_NOT_ALLOCATED_STRING);\r
-                    }\r
 \r
-                }\r
+                        /* Account for the leftNode in the matchingNode */\r
+                        matchingNode->base = findNode.base + findNode.length;\r
+                        matchingNode->length = matchingEnd - findEnd;  \r
 \r
-                /* Create the right node if needed.  If the end ranges are equal the matchingNode\r
-                 * can be reused as the right bound of the range */\r
-                if (findEnd < matchingEnd)\r
-                {\r
-                    /* Can the right node be combined with the node to the right of the matching\r
-                     * node */\r
-                    if (rightNode && (strcmp(rightNode->allocatedTo, opInfo->srcInstName) == 0))\r
-                    {\r
-                        /* Combine the right node and what's leftover on the right side of the \r
-                         * matchingNode range after the allocation */\r
-                        rightNode->base = findNode.base + findNode.length;\r
-                        rightNode->length += (matchingEnd - findEnd);\r
+                        /* Insert the left node */\r
+                        RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
                     }\r
-                    else\r
+                    else if (findEnd == matchingEnd)\r
                     {\r
-                        /* Reinsert right node and create a new node to right of range to be allocated */\r
-                        if (rightNode)\r
+                        /* There may be a combine possibility to the right. Extract rightNode to check */\r
+                        rightNode = RB_NEXT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                        \r
+                        /* Can the node to the right of the matchingNode be combined with the \r
+                         * findNode's range? */\r
+                        if (rightNode && (strcmp(rightNode->allocatedTo, opInfo->srcInstName) == 0))\r
                         {\r
-                            RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+                            /* Remove the rightNode from the tree for editing */\r
+                            RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+\r
+                            /* Combine the rightNode and the findNode */\r
+                            rightNode->base = findNode.base;\r
+                            rightNode->length += findNode.length;\r
+                        }\r
+                        else\r
+                        {\r
+                            /* Allocate a new rightNode that will take the place of the findNode\r
+                             * range in tree. */\r
+                            rightNode = Rm_newResourceTreeNode(findNode.base, findNode.length,\r
+                                                               opInfo->srcInstName);\r
                         }\r
-                                            \r
-                        /* New right node attributes:\r
-                         * base: base of the requested resources + length of requested resources\r
-                         * length: right bound of matching node - right bound of request resources */\r
-                        rightNode = Rm_newResourceTreeNode(findNode.base + findNode.length,\r
-                                                           matchingEnd - findEnd, RM_NOT_ALLOCATED_STRING);\r
-                    }\r
-                }\r
 \r
-                /* Reinsert the left node into the tree if it was modified or created. */\r
-                if (leftNode)\r
-                {\r
-                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
-                }\r
-                /* Reinsert the right node into the tree if it was modified or created. */\r
-                if (rightNode)\r
-                {\r
-                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
-                }\r
+                        /* Account for the rightNode in the matchingNode */\r
+                        matchingNode->length -= findNode.length;  \r
 \r
-                /* Base and length of matching node becomes the base and length of the requested resources */\r
-                matchingNode->base = findNode.base;                                    \r
-                matchingNode->length = findNode.length;\r
-                /* Reserve the resources and insert them into the tree */\r
-                strcpy(matchingNode->allocatedTo, opInfo->srcInstName);\r
-                RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                        /* Insert the right node */\r
+                        RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+                    }\r
 \r
+                    /* Reinsert the edited matching node */\r
+                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                }\r
+                \r
                 retVal = RM_SERVICE_APPROVED_AND_COMPLETED;\r
             }\r
             else\r
@@ -1117,25 +1149,19 @@ int32_t Rm_treeFree(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
                      * wipe any of the base+length data in the node.  Can reuse since they won't\r
                      * be freed */\r
                     RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
-                    if (leftNode)\r
-                    {\r
-                        RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
-                    }\r
-                    if (rightNode)\r
-                    {\r
-                        RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
-                    }\r
 \r
                     /* See if the left or right or both nodes can be combined with the matching\r
                      * node that will be freed. */\r
                     if (leftNode && (strcmp(leftNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0))\r
                     {\r
                         /* Combine the left node and the matching node */\r
+                        RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
                         combineLeft = TRUE;\r
                     }\r
                     if (rightNode && (strcmp(rightNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0))\r
                     {\r
                         /* Combine the right node and the matching node */\r
+                        RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
                         combineRight = TRUE;\r
                     }\r
 \r
@@ -1181,7 +1207,7 @@ int32_t Rm_treeFree(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
                     strcpy(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING);\r
                     RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);                    \r
                 }\r
-                else\r
+                else if ((findNode.base > matchingNode->base) && (findEnd < matchingEnd))\r
                 {\r
                     /* Case 2: free range is less than range in matched node. Need to split\r
                      *         the matched node into three nodes.\r
@@ -1190,44 +1216,112 @@ int32_t Rm_treeFree(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
                      *        |<---free request--->|\r
                      */ \r
 \r
-                    /* Create the left node if needed.  If the bases are equal the matchingNode can\r
-                     * be reused as the left bound of the range. */\r
-                    if (findNode.base > matchingNode->base)\r
-                    {\r
-                        /* New left node attributes:\r
-                         * base: base of the matching node\r
-                         * length: base of requested resources - base of matching node */\r
-                        leftNode = Rm_newResourceTreeNode(matchingNode->base, findNode.base - matchingNode->base,\r
-                                                          matchingNode->allocatedTo); \r
-                    }\r
+                    /* Remove matching node for editing. */\r
+                    RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
 \r
-                    /* Create the right node if needed.  If the end ranges are equal the matchingNode\r
-                     * can be reused as the right bound of the range */\r
-                    if (findEnd < matchingEnd)\r
-                    {                       \r
-                        /* New right node attributes:\r
-                         * base: base of the requested resources + length of requested resources\r
-                         * length: right bound of matching node - right bound of request resources */\r
-                        rightNode = Rm_newResourceTreeNode(findNode.base + findNode.length,\r
-                                                           matchingEnd - findEnd, matchingNode->allocatedTo);\r
-                    }\r
+                    /* New left node attributes:\r
+                     * base: base of the matching node\r
+                     * length: base of requested resources - base of matching node */\r
+                    leftNode = Rm_newResourceTreeNode(matchingNode->base, findNode.base - matchingNode->base,\r
+                                                      matchingNode->allocatedTo); \r
+                    /* New right node attributes:\r
+                     * base: base of the requested resources + length of requested resources\r
+                     * length: right bound of matching node - right bound of request resources */\r
+                    rightNode = Rm_newResourceTreeNode(findNode.base + findNode.length,\r
+                                                       matchingEnd - findEnd, matchingNode->allocatedTo);\r
+\r
+                    /* Insert the left and right nodes into the tree. */\r
+                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
 \r
-                    /* Insert the left node into the tree if it was created. */\r
-                    if (leftNode)\r
+                    /* Base and length of matching node become the base and length of the freed resources */\r
+                    matchingNode->base = findNode.base;                                    \r
+                    matchingNode->length = findNode.length;\r
+                    /* Free the resources and insert them into the tree */\r
+                    strcpy(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING);\r
+                    RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                }\r
+                else\r
+                {\r
+                    /* Remove the matchingNode from the tree since it will be edited */\r
+                    RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                    \r
+                    if (findNode.base == matchingNode->base)\r
                     {\r
+                        /* Case 3: Free range is on left boundary of matched node. Try to \r
+                         *         combine the free range with the left node if free.\r
+                         *\r
+                         * |<---left node (free)--->||<----------matched node---------->|\r
+                         *                           |<---findNode (free req)--->|\r
+                         */ \r
+                   \r
+                        /* There may be a combine possibility to the left. Extract leftNode to check */\r
+                        leftNode = RB_PREV(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                        \r
+                        /* Can the node to the left of the matchingNode be combined with the \r
+                         * findNode's range? */\r
+                        if (leftNode && (strcmp(leftNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0))\r
+                        {\r
+                            /* Remove the leftNode from the tree for editing */\r
+                            RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+\r
+                            /* Combine the leftNode and the findNode */\r
+                            leftNode->length += findNode.length;\r
+                        }\r
+                        else\r
+                        {\r
+                            /* Allocate a new leftNode that will take the place of the findNode\r
+                             * range in tree. */\r
+                            leftNode = Rm_newResourceTreeNode(findNode.base, findNode.length,\r
+                                                              RM_NOT_ALLOCATED_STRING);\r
+                        }\r
+\r
+                        /* Account for the leftNode in the matchingNode */\r
+                        matchingNode->base = findNode.base + findNode.length;\r
+                        matchingNode->length = matchingEnd - findEnd;  \r
+\r
+                        /* Insert the left node */\r
                         RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
                     }\r
-                    /* Insert the right node into the tree if it was created. */\r
-                    if (rightNode)\r
+                    else if (findEnd == matchingEnd)\r
                     {\r
+                        /* Case 4: Free range is on right boundary of matched node. Try to \r
+                         *         combine the free range with the right node if free.\r
+                         *\r
+                         * |<----------matched node---------->||<---right node (free)--->|\r
+                         *        |<---findNode (free req)--->|\r
+                         */ \r
+                        \r
+                        /* There may be a combine possibility to the right. Extract rightNode to check */\r
+                        rightNode = RB_NEXT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+                        \r
+                        /* Can the node to the right of the matchingNode be combined with the \r
+                         * findNode's range? */\r
+                        if (rightNode && (strcmp(rightNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0))\r
+                        {\r
+                            /* Remove the rightNode from the tree for editing */\r
+                            RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+\r
+                            /* Combine the rightNode and the findNode */\r
+                            rightNode->base = findNode.base;\r
+                            rightNode->length += findNode.length;\r
+                        }\r
+                        else\r
+                        {\r
+                            /* Allocate a new rightNode that will take the place of the findNode\r
+                             * range in tree. */\r
+                            rightNode = Rm_newResourceTreeNode(findNode.base, findNode.length,\r
+                                                               RM_NOT_ALLOCATED_STRING);\r
+                        }\r
+\r
+                        /* Account for the rightNode in the matchingNode */\r
+                        matchingNode->length -= findNode.length;  \r
+\r
+                        /* Insert the right node */\r
                         RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
                     }\r
 \r
-                    /* Base and length of matching node becomes the base and length of the freed resources */\r
-                    matchingNode->base = findNode.base;                                    \r
-                    matchingNode->length = findNode.length;\r
-                    /* Free the resources and insert them into the tree */\r
-                    strcpy(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING);\r
+                    /* Reinsert the edited matching node */\r
                     RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
                 }\r
 \r
@@ -1238,7 +1332,6 @@ int32_t Rm_treeFree(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
                 /* The matching allocated range to be freed was allocated to a different instance. */\r
                 retVal = RM_SERVICE_DENIED_RESOURCE_NOT_ALLOCATED_TO_INSTANCE_REQUESTING_THE_SERVICE;\r
             }\r
-\r
         }\r
         else\r
         {\r
@@ -1755,7 +1848,6 @@ int32_t Rm_findAndReserveLinuxResource(Rm_Inst *rmInst, const char *resourceName
     const char *propertyName;\r
     const void *propertyData; \r
     Rm_LinuxValueRange *linuxValueRange;\r
-    bool foundResource;\r
     int32_t retVal = RM_DTB_UTIL_RESULT_OKAY; \r
 \r
     /* Initialize the allocator opInfo and resourceInfo structures that will be used to \r
@@ -1765,6 +1857,7 @@ int32_t Rm_findAndReserveLinuxResource(Rm_Inst *rmInst, const char *resourceName
 \r
     strcpy(resourceInfo.name, resourceName);\r
 \r
+    /* Set the source instance name for allocation to be the Linux Kernel */\r
     opInfo.srcInstName = RM_ALLOCATED_TO_LINUX;\r
     opInfo.operation = Rm_allocatorOp_ALLOCATE;\r
     opInfo.resourceInfo = &resourceInfo;    \r
@@ -1774,14 +1867,13 @@ int32_t Rm_findAndReserveLinuxResource(Rm_Inst *rmInst, const char *resourceName
     while(linuxAlias != NULL)\r
     {\r
         /* Reset the parsing variables */\r
-        foundResource = FALSE;\r
         pathOffset = 0;\r
         nodeOffset = RM_DTB_UTIL_STARTING_NODE_OFFSET;\r
         prevDepth = RM_DTB_UTIL_STARTING_DEPTH;   \r
         resourceInfo.base = 0;\r
         resourceInfo.length = 0;\r
         \r
-        while(1)\r
+        while(pathOffset < linuxAlias->pathListLenBytes)\r
         {\r
             /* Move through the DTB nodes until the next alias path node is found */\r
             if (strcmp(linuxAlias->pathList + pathOffset, fdt_get_name(linuxDtb, nodeOffset, NULL)))\r
@@ -1792,7 +1884,7 @@ int32_t Rm_findAndReserveLinuxResource(Rm_Inst *rmInst, const char *resourceName
                 {\r
                     /* Returning from subnode that matched part of alias path without finding\r
                      * the resource values */\r
-                    retVal = (-31); /* TODO: COULD NOT HAVE RESOURCE AT ALIAS PATH */\r
+                    retVal = (-31); /* TODO: COULD NOT FIND RESOURCE AT ALIAS PATH */\r
                     break;\r
                 }\r
             }\r
@@ -1805,39 +1897,30 @@ int32_t Rm_findAndReserveLinuxResource(Rm_Inst *rmInst, const char *resourceName
                 /* Check the properties of the node to see if they match the next alias\r
                  * path string */\r
                propOffset = fdt_first_property_offset(linuxDtb, nodeOffset);\r
-                if (propOffset >= RM_DTB_UTIL_STARTING_NODE_OFFSET)\r
-                {             \r
-                    /* Search the properties for the next alias path string */\r
-                    while (propOffset >= RM_DTB_UTIL_STARTING_NODE_OFFSET)\r
-                    {\r
-                        propertyData = fdt_getprop_by_offset(linuxDtb, propOffset, \r
-                                                             &propertyName, &propertyLen);\r
+           \r
+                /* Search the properties for the next alias path string */\r
+                while ((propOffset >= RM_DTB_UTIL_STARTING_NODE_OFFSET) &&\r
+                       (pathOffset < linuxAlias->pathListLenBytes))\r
+                {\r
+                    propertyData = fdt_getprop_by_offset(linuxDtb, propOffset, \r
+                                                         &propertyName, &propertyLen);\r
 \r
-                        if (strcmp(linuxAlias->pathList + pathOffset, propertyName) == 0)\r
-                        {\r
-                            /* Found the alias property.  Extract the values that will\r
-                             * contain the resource information that must be reserved. */\r
-                            linuxValueRange = Rm_linuxExtractValues(propertyData, propertyLen);\r
-                            /* Use the values to reserve resources for the Linux kernel */\r
-                            retVal = Rm_reserveLinuxResource(rmInst, linuxAlias, \r
-                                                             linuxValueRange, &opInfo);\r
-                            \r
-                            /* Free the memory used to store the values */\r
-                            Rm_linuxFreeValues(linuxValueRange);\r
-\r
-                            foundResource = TRUE;\r
-                            break;\r
-                        }\r
+                    if (strcmp(linuxAlias->pathList + pathOffset, propertyName) == 0)\r
+                    {\r
+                        pathOffset += (strlen(linuxAlias->pathList + pathOffset) + 1);\r
+                        /* Found the alias property.  Extract the values that will\r
+                         * contain the resource information that must be reserved. */\r
+                        linuxValueRange = Rm_linuxExtractValues(propertyData, propertyLen);\r
+                        /* Use the values to reserve resources for the Linux kernel */\r
+                        retVal = Rm_reserveLinuxResource(rmInst, linuxAlias, \r
+                                                         linuxValueRange, &opInfo);\r
                         \r
-                        propOffset = fdt_next_property_offset(linuxDtb, propOffset);\r
-                        if (propOffset < -FDT_ERR_NOTFOUND)\r
-                        {\r
-                            /* Error was returned by LIBFDT when parsing the properties */\r
-                            retVal = propOffset;\r
-                            break;\r
-                        }                        \r
-                    } \r
-                }\r
+                        /* Free the memory used to store the values */\r
+                        Rm_linuxFreeValues(linuxValueRange);\r
+                    }\r
+                    \r
+                    propOffset = fdt_next_property_offset(linuxDtb, propOffset);\r
+                } \r
 \r
                 if (propOffset < -FDT_ERR_NOTFOUND)\r
                 {\r
@@ -1845,13 +1928,6 @@ int32_t Rm_findAndReserveLinuxResource(Rm_Inst *rmInst, const char *resourceName
                     retVal = propOffset;\r
                     break;\r
                 }\r
-\r
-                if (foundResource)\r
-                {\r
-                    /* Found the resource and reserved it or there was an error\r
-                     * trying to reserve it.  Break out of the while(1) loop */\r
-                    break;\r
-                }\r
             }\r
         }\r
 \r
@@ -2114,7 +2190,73 @@ int32_t Rm_initializeAllocators(Rm_Inst *rmInst, void *globalResourceDtb, void *
 \r
     return(result);\r
 }\r
-         \r
+\r
+void Rm_printResourceStatus(Rm_Inst *rmInst)\r
+{\r
+    Rm_Allocator *allocator = rmInst->allocators;\r
+    Rm_IntegerAllocatorRootEntry *integerRoot;\r
+    Rm_IntegerEntry *integerEntry;\r
+    Rm_ResourceTree *treeRoot;\r
+    Rm_ResourceTreeNode *treeNode;\r
+    uint32_t numLinuxResources;\r
+    uint32_t i;\r
+\r
+    while (allocator != NULL)\r
+    {\r
+        numLinuxResources = 0;\r
+\r
+        Rm_osalLog("Resource: %s\n", allocator->resourceName);\r
+\r
+        if (allocator->type == Rm_allocatorType_INTEGER)\r
+        {\r
+            integerRoot = allocator->allocatorRootEntry;\r
+            integerEntry = integerRoot->resourceArrayBase;\r
+\r
+            for (i = 0; i < integerRoot->numResourceElements; i++)\r
+            {\r
+                if (strcmp(integerEntry[i].allocatedTo, RM_ALLOCATED_TO_LINUX) == 0)\r
+                {\r
+                    Rm_osalLog("Value: %5d reserved for %s\n", integerEntry[i].value, \r
+                                                               integerEntry[i].allocatedTo);\r
+                    numLinuxResources++;\r
+                }\r
+            }\r
+        }\r
+        else if (allocator->type == Rm_allocatorType_TREE)\r
+        {\r
+            treeRoot = allocator->allocatorRootEntry;\r
+\r
+            RB_FOREACH(treeNode, _Rm_ResourceTree, treeRoot)\r
+            {               \r
+                Rm_osalLog("          %5d - %5d ", treeNode->base, \r
+                                                   treeNode->base + treeNode->length -1);\r
+                \r
+                if (strcmp(treeNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0)\r
+                {\r
+                    Rm_osalLog("NOT ALLOCATED\n");\r
+                }\r
+                else\r
+                {\r
+                    Rm_osalLog("allocated to %s\n", treeNode->allocatedTo);\r
+                }\r
+\r
+                if (strcmp(treeNode->allocatedTo, RM_ALLOCATED_TO_LINUX) == 0)\r
+                {\r
+                    numLinuxResources += treeNode->length;\r
+                }\r
+            }\r
+        }\r
+        else\r
+        {\r
+            Rm_osalLog("Error: Unknown allocator type\n");\r
+        }\r
+        \r
+        Rm_osalLog("Total allocated to Linux: %d\n", numLinuxResources);\r
+        \r
+        allocator = allocator->nextAllocator;\r
+    }\r
+}\r
+     \r
 /**********************************************************************\r
  ********************** Application visible APIs **********************\r
  **********************************************************************/\r
@@ -2172,6 +2314,8 @@ Rm_Handle Rm_init(Rm_InitCfg *initCfg)
             }\r
             \r
             Rm_initializeAllocators(rmInst, globalResourceDtb, linuxResourceDtb);\r
+\r
+            Rm_printResourceStatus(rmInst);\r
         }\r
     }\r
 \r