Moved allocators from linked list to binary tree
authorJustin Sobota <jsobota@ti.com>
Thu, 21 May 2015 23:08:44 +0000 (19:08 -0400)
committerJustin Sobota <jsobota@ti.com>
Thu, 21 May 2015 23:08:44 +0000 (19:08 -0400)
include/rm_allocatorloc.h
include/rm_loc.h
include/rm_policyloc.h
include/rm_treeloc.h
rm.h
src/rm.c
src/rm_allocator.c
src/rm_policy.c
src/rm_tree.c

index fae62d8a46a39b465b8cfe5b3cbbda1ae6577ee6..e4735b9aa186eb5a40f1755bbc2dc07ede3866f8 100644 (file)
@@ -4,7 +4,7 @@
  *  Private data structures and APIS for Resource Manager allocators.
  *
  *  ============================================================================
- *      (C) Copyright 2012-2013, Texas Instruments, Inc.
+ *      (C) Copyright 2012-2015, Texas Instruments, Inc.
  * 
  *  Redistribution and use in source and binary forms, with or without 
  *  modification, are permitted provided that the following conditions 
@@ -61,8 +61,8 @@ typedef struct {
     /* Pointer to a resource's NameServer assignment data within the GRL DTB.
      * Will be NULL if not defined for the resource node. */
     const void *nsAssignData;
-    /* Length in bytes of a resource's NameServer assignment data in the GRL DTB.
-     * Will be zero if not defined for the resource node. */
+    /* Length in bytes of a resource's NameServer assignment data in the
+     * GRL DTB.  Will be zero if not defined for the resource node. */
     int32_t     nsAssignLen;
     /* Pointer to a resource's Linux alias data within the GRL DTB.  Will be
      * NULL if not defined for the resource node. */
@@ -100,27 +100,20 @@ typedef struct {
     Rm_ResourceInfo        *resourceInfo;
 } Rm_AllocatorOpInfo;
 
-/* RM allocator linked list node */
-typedef struct Rm_Allocator_s {
-    /* Resource name for which the allocator was created.  The resource name
-     * must match a resource node defined in both the GRL and the Policy */
-    char                   resourceName[RM_NAME_MAX_CHARS];
-    /* Pointer to the root entry of the allocator resource tree */
-    Rm_ResourceTree       *allocatorRootEntry;
-    /* Pointer to next resource allocator node */
-    struct Rm_Allocator_s *nextAllocator;
-} Rm_Allocator;
-
-int32_t rmAllocatorCreate(Rm_Handle rmHandle, const char *resourceName, Rm_ResourceRange *range);
-Rm_Allocator *rmAllocatorGetAllocatorList(Rm_Handle rmHandle);
-Rm_Allocator *rmAllocatorFind(Rm_Handle rmHandle, const char *resourceName);
+int32_t rmAllocatorCreate(Rm_Handle rmHandle, const char *resourceName,
+                          Rm_ResourceRange *range);
+Rm_AllocatorTree *rmAllocatorGetTree(Rm_Handle rmHandle);
+Rm_AllocatorNode *rmAllocatorFind(Rm_Handle rmHandle, const char *resourceName);
 int rmAllocatorGetNodeLocalization(Rm_Handle rmHandle, char *resourceName,
                                    int32_t *resBase, uint32_t *resLen);
 int32_t rmAllocatorOperation(Rm_Handle rmHandle, Rm_AllocatorOpInfo *opInfo);
-int32_t rmAllocatorInitializeResources(Rm_Handle rmHandle, void *globalResourceDtb, void *linuxDtb);
-void rmAllocatorDeleteNode(Rm_Handle rmHandle, const char *resName, int32_t resBase, uint32_t resLen);
+int32_t rmAllocatorInitTree(Rm_Handle rmHandle);
+int32_t rmAllocatorPopulateTree(Rm_Handle rmHandle, void *globalResourceDtb,
+                                void *linuxDtb);
+void rmAllocatorDeleteResNode(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
+                              int32_t resBase, uint32_t resLen);
 int32_t rmAllocatorDelete(Rm_Handle rmHandle, const char *resourceName);
-void rmAllocatorDeleteResources(Rm_Handle rmHandle);
+void rmAllocatorDeleteTree(Rm_Handle rmHandle);
 
 #ifdef __cplusplus
 }
index ce1de29e739e9b10fc21f249b6d2c53e8058cedb..703cdee1690d40850fde0a52461fcecf74a44517 100644 (file)
@@ -4,7 +4,7 @@
  *  General private data structures of Resource Manager.
  *
  *  ============================================================================
- *      (C) Copyright 2012-2013, Texas Instruments, Inc.
+ *      (C) Copyright 2012-2015, Texas Instruments, Inc.
  * 
  *  Redistribution and use in source and binary forms, with or without 
  *  modification, are permitted provided that the following conditions 
@@ -62,33 +62,35 @@ typedef struct Rm_Transaction_s {
     Rm_ServiceType           type;
     /* Local ID of the transaction. */
     uint32_t                 localId;
-    /* ID of transaction in RM instance that generated the
-     * packet that resulted in the creation of the transaction.  The
-     * originating ID will be placed in the transaction's response packet
-     * The RM instance that receives the response will 
-     * match the response packet with the originating request using the ID */
+    /* ID of transaction in RM instance that generated the packet that
+     * resulted in the creation of the transaction.  The originating ID
+     * will be placed in the transaction's response packet.  The RM
+     * instance that receives the response will match the response packet
+     * with the originating request using the ID */
     uint32_t                 remoteOriginatingId;
     /* Transaction response mechanism union */
     union {
         /* Service callback function if received locally via Service API */
         Rm_ServiceCallback   callback;
-        /* Transport handle to send response packet on if received via Transport rcv API */
+        /* Transport handle to send response packet on if received via
+         * Transport rcv API */
         Rm_Transport        *respTrans;
     } u;
     /* Transaction state.  The codes are defined in rm.h */
     int32_t                  state;
-    /* Transaction has been forwarded to CD or Server instance.  Waiting for response */
+    /* Transaction has been forwarded to CD or Server instance.  Waiting for
+     * response */
     int8_t                   hasBeenForwarded;
     /* The transaction ID for a transaction pending on a CD while this
-     * transaction is sent to the Server as a request for data required to complete
-     * pending transaction */
+     * transaction is sent to the Server as a request for data required to
+     * complete pending transaction */
     uint32_t                 pendingTransactionId;
     /* Name of the RM instance the service originated from */
-    char                     serviceSrcInstName[RM_NAME_MAX_CHARS];    
+    char                     serviceSrcInstName[RM_NAME_MAX_CHARS];
     /* Resource information */
     Rm_ResourceInfo          resourceInfo;
     /* Link to the next transaction in the queue */
-    struct Rm_Transaction_s *nextTransaction;    
+    struct Rm_Transaction_s *nextTransaction;
 } Rm_Transaction;
 
 /* Server-specific instance data */
@@ -99,8 +101,8 @@ typedef struct {
     uint32_t                policySize;
     /* Pointer to root entry of the global policy valid instance tree */
     Rm_PolicyValidInstTree *globalValidInstTree;
-    /* Pointer to the linked list of allocators */
-    Rm_Allocator           *allocators;
+    /* Pointer to allocator tree */
+    Rm_AllocatorTree       *allocatorTree;
     /* Pointer to the root entry of the NameServer */
     Rm_NameServerTree      *nameServer;
 } Rm_ServerInstData;
@@ -112,8 +114,8 @@ typedef struct {
     /* Pointer to the root entry of the valid instance tree
      * extracted from the cd policy */
     Rm_PolicyValidInstTree *cdValidInstTree;
-    /* Pointer to the linked list of allocators */
-    Rm_Allocator           *allocators;    
+    /* Pointer to allocator tree */
+    Rm_AllocatorTree       *allocatorTree;
 } Rm_ClientDelegateInstData;
 
 /* Client-specific instance data */
index 96ccbc2300e6919a782ef667a27cb7de7cff7669..04a1c9b80da70f4bdfada826d5846aa2c47605fe 100644 (file)
@@ -4,7 +4,7 @@
  *  Internal prototypes and data structures for the Resource Manager Policies.
  *
  *  ============================================================================
- *      (C) Copyright 2012-2013, Texas Instruments, Inc.
+ *      (C) Copyright 2012-2015, Texas Instruments, Inc.
  * 
  *  Redistribution and use in source and binary forms, with or without 
  *  modification, are permitted provided that the following conditions 
@@ -157,7 +157,7 @@ uint32_t rmPolicyGetResourceBase(void *policyDtb, Rm_PolicyValidInstNode *validI
 uint32_t rmPolicyGetResourceAlignment(void *policyDtb, int32_t resourceOffset);
 uint32_t rmPolicyGetResourceCdAllocSize(void *policyDtb, int32_t resourceOffset);
 int32_t rmPolicyGetResourceOffset(void *policyDtb, char *resourceName);
-int32_t rmPolicyValidatePolicyResourceNames(Rm_Handle rmHandle);
+int32_t rmPolicyValidateResNames(Rm_Handle rmHandle);
 int32_t rmPolicyValidatePolicy(Rm_Handle rmHandle);
 Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle, int addLinux, int32_t *result);
 void rmPolicyFreeValidInstTree(Rm_Handle rmHandle);
index e37ea2b556806fc7f01792b313920f4e32055503..60e3eb66f68c9f061a1ac39662ca2c5d3fcd51fb 100644 (file)
@@ -4,7 +4,7 @@
  *  Prototypes and data structures for the various RM Trees.
  *
  *  ============================================================================
- *      (C) Copyright 2012-2013, Texas Instruments, Inc.
+ *      (C) Copyright 2012-2015, Texas Instruments, Inc.
  * 
  *  Redistribution and use in source and binary forms, with or without 
  *  modification, are permitted provided that the following conditions 
@@ -63,9 +63,10 @@ typedef struct {
     char     *objName;
     /* Resource name assigned to the NameServer name */
     char     *resourceName;
-    /* Resource base value assigned to the NameServer name */    
+    /* Resource base value assigned to the NameServer name */
     uint32_t  resourceBase;
-    /* Resource length value (starting from base) assigned to the NameServer name */    
+    /* Resource length value (starting from base) assigned to the NameServer
+     * name */
     uint32_t  resourceLength;
 } Rm_NameServerNodeCfg;
 
@@ -104,7 +105,8 @@ typedef struct _Rm_PolicyValidInstNode {
 } Rm_PolicyValidInstNode;
 
 /* Valid instance tree root entry type definition */
-typedef RB_HEAD(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode) Rm_PolicyValidInstTree;
+typedef RB_HEAD(_Rm_PolicyValidInstTree,
+                _Rm_PolicyValidInstNode) Rm_PolicyValidInstTree;
 
 /* Resource node owner linked list node */
 typedef struct Rm_Owner_s {
@@ -138,6 +140,20 @@ typedef struct _Rm_ResourceNode {
 /* Resource tree root entry type definition */
 typedef RB_HEAD(_Rm_AllocatorResourceTree, _Rm_ResourceNode) Rm_ResourceTree;
 
+/* Allocator node */
+typedef struct _Rm_AllocatorNode {
+    /* Tree algorithm data structure */
+    RB_ENTRY(_Rm_AllocatorNode)  linkage;
+    /* Resource name for which the allocator was created.  The resource name
+     * must match a resource node defined in both the GRL and the Policy */
+    char                         resourceName[RM_NAME_MAX_CHARS];
+    /* Pointer to the root entry of the allocator resource tree */
+    Rm_ResourceTree             *resourceRootEntry;
+} Rm_AllocatorNode;
+
+/* Allocator tree root entry type definition */
+typedef RB_HEAD(_Rm_AllocatorTree, _Rm_AllocatorNode) Rm_AllocatorTree;
+
 /**********************************************************************
  ****************** Tree Node Function Definitions ********************
  **********************************************************************/
@@ -146,30 +162,45 @@ void rmNameServerTreeInv(Rm_NameServerTree *treeRoot);
 void rmNameServerTreeWb(Rm_NameServerTree *treeRoot);
 Rm_NameServerNode *rmNameServerNodeNew(Rm_NameServerNodeCfg *nodeCfg);
 void rmNameServerNodeFree(Rm_NameServerNode *node);
-int rmNameServerNodeCompare(Rm_NameServerNode *node1, Rm_NameServerNode *node2); 
+int rmNameServerNodeCompare(Rm_NameServerNode *node1,
+                            Rm_NameServerNode *node2);
 void rmNameServerNodeInv(Rm_NameServerNode *node);
 
 void rmPolicyValidInstTreeInv(Rm_PolicyValidInstTree *treeRoot);
 void rmPolicyValidInstTreeWb(Rm_PolicyValidInstTree *treeRoot);
 Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(char *instName);
 void rmPolicyValidInstNodeFree(Rm_PolicyValidInstNode *node);
-int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1, Rm_PolicyValidInstNode *node2);
+int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1,
+                                 Rm_PolicyValidInstNode *node2);
 void rmPolicyValidInstNodeInv(Rm_PolicyValidInstNode *node);
 
 void rmResourceTreeInv(Rm_ResourceTree *treeRoot);
 void rmResourceTreeWb(Rm_ResourceTree *treeRoot);
-Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase, uint32_t resourceLength);
+Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase,
+                                   uint32_t resourceLength);
 void rmResourceNodeFree(Rm_ResourceNode *node);
 int rmResourceNodeCompare(Rm_ResourceNode *node1, Rm_ResourceNode *node2);
 void rmResourceNodeInv(Rm_ResourceNode *node);
 
+void rmAllocatorTreeInv(Rm_AllocatorTree *treeRoot);
+void rmAllocatorTreeWb(Rm_AllocatorTree *treeRoot);
+Rm_AllocatorNode *rmAllocatorNodeNew(const char *resourceName);
+void rmAllocatorNodeFree(Rm_AllocatorNode *node);
+int rmAllocatorNodeCompare(Rm_AllocatorNode *node1, Rm_AllocatorNode *node2);
+void rmAllocatorNodeInv(Rm_AllocatorNode *node);
+
 /**********************************************************************
  ******************** Tree Prototype Generation ***********************
  **********************************************************************/
  
-RB_PROTOTYPE(_Rm_NameServerTree, _Rm_NameServerNode, linkage, rmNameServerNodeCompare, rmNameServerNodeInv)
-RB_PROTOTYPE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage, rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv)
-RB_PROTOTYPE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage, rmResourceNodeCompare, rmResourceNodeInv)
+RB_PROTOTYPE(_Rm_NameServerTree, _Rm_NameServerNode, linkage,
+             rmNameServerNodeCompare, rmNameServerNodeInv)
+RB_PROTOTYPE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage,
+             rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv)
+RB_PROTOTYPE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage,
+             rmResourceNodeCompare, rmResourceNodeInv)
+RB_PROTOTYPE(_Rm_AllocatorTree, _Rm_AllocatorNode, linkage,
+             rmAllocatorNodeCompare, rmAllocatorNodeInv)
 
 #ifdef __cplusplus
 }
diff --git a/rm.h b/rm.h
index 0d81d1230754c63915258ecc3bf4308cf099b33a..0083a984f4d31735b365d6b4227db53ef55dff27 100644 (file)
--- a/rm.h
+++ b/rm.h
@@ -6,7 +6,7 @@
  *
  *  \par
  *  ============================================================================
- *  @n   (C) Copyright 2012-2014, Texas Instruments, Inc.
+ *  @n   (C) Copyright 2012-2015, Texas Instruments, Inc.
  * 
  *  Redistribution and use in source and binary forms, with or without 
  *  modification, are permitted provided that the following conditions 
@@ -372,6 +372,9 @@ extern "C" {
 /** RM failed to create a new allocator - Occurred because an instance that does not use
  *  allocators tried to create one (RM Client) */
 #define RM_ERROR_COULD_NOT_CREATE_NEW_ALLOCATOR    RM_ERROR_BASE-53
+/** Could not allocate the memory needed to store the root entry of the
+ *  allocator tree */
+#define RM_ERROR_COULD_NOT_INIT_ALLOC_TREE         RM_ERROR_BASE-54
 
 /** 
  * @brief Maximum number of characters allowed for RM instance, resource, and
index 9bc65269bd656ce6dd26c0076ed50cc8aa841cd0..78e0f8bbbb720c6e892cefa3a4291abf178416e0 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -863,9 +863,9 @@ static void clientProcess (Rm_Inst *rmInst, Rm_Transaction *transaction)
  */
 static void cdProcess (Rm_Inst *rmInst, Rm_Transaction *transaction)
 {      
-    Rm_Transaction *newTrans = NULL;
-    Rm_Allocator   *allocator = NULL;
-    Rm_Transaction *transQ;
+    Rm_Transaction   *newTrans = NULL;
+    Rm_AllocatorNode *allocator = NULL;
+    Rm_Transaction   *transQ;
 
     if (!rmInst->registeredWithDelegateOrServer) {
         if ((transaction->state == RM_SERVICE_PROCESSING) &&
@@ -904,7 +904,7 @@ static void cdProcess (Rm_Inst *rmInst, Rm_Transaction *transaction)
                         Rm_ResourceNode *treeNode = NULL;
                         
                         treeNode = rmResourceNodeNew(transaction->resourceInfo.base, transaction->resourceInfo.length);
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, treeNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, treeNode);
                     }
                     else {
                         Rm_ResourceRange resRange;
@@ -920,15 +920,23 @@ static void cdProcess (Rm_Inst *rmInst, Rm_Transaction *transaction)
                     pendingTrans->state = RM_SERVICE_PROCESSING;
                 }
                 else if (transaction->type == Rm_service_RESOURCE_FREE) {
-                    /* Local resource freed on Server.  Need to remove from local allocator. */
-                    rmAllocatorDeleteNode((Rm_Handle)rmInst, transaction->resourceInfo.name,
-                                          transaction->resourceInfo.base, transaction->resourceInfo.length);                   
-                    
-                    /* Delete the allocator if there are no nodes left in the tree */
-                    allocator = rmAllocatorFind((Rm_Handle)rmInst, transaction->resourceInfo.name);
-                    if (RB_MIN(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry) == NULL) {
-                        rmAllocatorDelete((Rm_Handle)rmInst, transaction->resourceInfo.name);
-                    }   
+                    allocator = rmAllocatorFind((Rm_Handle)rmInst,
+                                                transaction->resourceInfo.name);
+
+                    /* Local resource freed on Server.  Need to remove from
+                     * local allocator's resource tree as well */
+                    rmAllocatorDeleteResNode((Rm_Handle)rmInst,
+                                             allocator,
+                                             transaction->resourceInfo.base,
+                                             transaction->resourceInfo.length);
+
+                    /* Delete the allocator's resource tree if there are no
+                     * nodes left in the resource tree */
+                    if (RB_MIN(_Rm_AllocatorResourceTree,
+                               allocator->resourceRootEntry) == NULL) {
+                        rmAllocatorDelete((Rm_Handle)rmInst,
+                                          transaction->resourceInfo.name);
+                    }
 
                     /* Allow original free to complete */
                     pendingTrans->state = RM_SERVICE_APPROVED;
@@ -1235,14 +1243,15 @@ void rmProcessRouter (Rm_Inst *rmInst, Rm_Transaction *transaction)
  */
 int32_t Rm_resourceStatus(Rm_Handle rmHandle, int printResources)
 {
-    Rm_Inst         *rmInst = (Rm_Inst *)rmHandle;
-    Rm_Allocator    *allocator = NULL;
-    Rm_Owner        *owners;
-    Rm_ResourceTree *treeRoot;
-    Rm_ResourceNode *treeNode;
-    int32_t          totalResOwners = 0;
-    void            *key;
-    void            *mtKey;
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_AllocatorTree *allocTree = NULL;
+    Rm_AllocatorNode *allocator;
+    Rm_Owner         *owners;
+    Rm_ResourceTree  *treeRoot;
+    Rm_ResourceNode  *treeNode;
+    int32_t           totalResOwners = 0;
+    void             *key;
+    void             *mtKey;
 
     RM_SS_INST_INV_ENTER_CS(rmInst, key);
     RM_SC_INST_INV_ENTER_CS(rmInst, key);
@@ -1255,14 +1264,11 @@ int32_t Rm_resourceStatus(Rm_Handle rmHandle, int printResources)
         Rm_osalLog("Handle: 0x%08x\n", rmHandle);    
         if (rmInst->instType == Rm_instType_SERVER) {
             Rm_osalLog("Type:   Server\n");
-        }
-        else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
+        } else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
             Rm_osalLog("Type:   Client Delegate\n");
-        }
-        else if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+        } else if (rmInst->instType == Rm_instType_SHARED_SERVER) {
             Rm_osalLog("Type:   Shared Server\n");
-        }
-        else if (rmInst->instType == Rm_instType_SHARED_CLIENT) {
+        } else if (rmInst->instType == Rm_instType_SHARED_CLIENT) {
             Rm_osalLog("Type:   Shared Client\n");
         }
 
@@ -1277,19 +1283,19 @@ int32_t Rm_resourceStatus(Rm_Handle rmHandle, int printResources)
     if ((rmInst->instType == Rm_instType_SERVER) ||
         (rmInst->instType == Rm_instType_SHARED_SERVER) ||
         (rmInst->instType == Rm_instType_CLIENT_DELEGATE)) {
-        allocator = rmAllocatorGetAllocatorList((Rm_Handle)rmInst);
         
-        if (!allocator) {
-            Rm_osalLog("No resources managed by instance at the moment\n\n");
+        allocTree = rmAllocatorGetTree((Rm_Handle)rmInst);
+        if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+            rmAllocatorTreeInv(allocTree);
         }
-        
-        while (allocator) {
-            RM_SS_OBJ_INV(rmInst, allocator, Rm_Allocator);
+
+        RB_FOREACH(allocator, _Rm_AllocatorTree, allocTree) {
+            RM_SS_OBJ_INV(rmInst, allocator, Rm_AllocatorNode);
             if (printResources) {
                 Rm_osalLog("Resource: %s\n", allocator->resourceName);
             }
 
-            treeRoot = allocator->allocatorRootEntry;
+            treeRoot = allocator->resourceRootEntry;
             if (rmInst->instType == Rm_instType_SHARED_SERVER) {
                 rmResourceTreeInv(treeRoot);
             }
@@ -1298,26 +1304,27 @@ int32_t Rm_resourceStatus(Rm_Handle rmHandle, int printResources)
                     if ((treeNode->base >= 65536) ||
                         ((treeNode->base + treeNode->length - 1) >= 65536)) {
                         /* Print in hex if number is very large */
-                        Rm_osalLog("          0x%08x - 0x%08x ", treeNode->base, 
-                                                                 treeNode->base + treeNode->length - 1);
-                    }
-                    else {
-                        Rm_osalLog("          %10d - %10d ", treeNode->base, 
-                                                             treeNode->base + treeNode->length - 1);
+                        Rm_osalLog("          0x%08x - 0x%08x ",
+                                   treeNode->base,
+                                   treeNode->base + treeNode->length - 1);
+                    } else {
+                        Rm_osalLog("          %10d - %10d ",
+                                   treeNode->base,
+                                   treeNode->base + treeNode->length - 1);
                     }
                 }
-                
+
                 if (treeNode->allocationCount == 0) {
                     if (printResources) {
                         Rm_osalLog("FREE\n");
                     }
-                }
-                else {
+                } else {
                     owners = treeNode->ownerList;
                     while (owners) {
                         RM_SS_OBJ_INV(rmInst, owners, Rm_Owner);
                         if (printResources) {
-                            Rm_osalLog("%s (%d) ", owners->instNameNode->name, owners->refCnt);
+                            Rm_osalLog("%s (%d) ", owners->instNameNode->name,
+                                       owners->refCnt);
                         }
                         totalResOwners++;
                         owners = owners->nextOwner;
@@ -1326,26 +1333,24 @@ int32_t Rm_resourceStatus(Rm_Handle rmHandle, int printResources)
                         Rm_osalLog("\n");
                     }
                 }
-            }        
-            allocator = allocator->nextAllocator; 
+            }
         }
-        
+
         if ((rmInst->instType == Rm_instType_SERVER) ||
             (rmInst->instType == Rm_instType_SHARED_SERVER)) {
             if (printResources) {
                 rmNameServerPrintObjects((Rm_Handle)rmInst);
             }
         }
-    }
-    else {
+    } else {
         totalResOwners = RM_ERROR_INVALID_RES_STATUS_INSTANCE;
-    }  
+    }
 
     /* Free sem object using originating instance in case the Shared Client to Shared
      * Server instance switch took place */
     if (((Rm_Inst *)rmHandle)->mtSemObj) {
         Rm_osalMtCsExit(((Rm_Inst *)rmHandle)->mtSemObj, mtKey);
-    }    
+    }
     RM_SS_INST_WB_EXIT_CS(rmInst, key);
     return(totalResOwners);
 }
@@ -1455,8 +1460,8 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
     uint32_t  policySize;
     void     *globalResourceDtb = NULL;
     void     *linuxResourceDtb = NULL;
-    int       addLinux = RM_FALSE;   
-    void     *key;     
+    int       addLinux = RM_FALSE;
+    void     *key;
 
     *result = RM_OK;
     
@@ -1473,13 +1478,13 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
 
     /* Create and initialize instance */
     rmInst = Rm_osalMalloc(sizeof(*rmInst));
-    memset ((void *)rmInst, 0, sizeof(*rmInst));
+    memset((void *)rmInst, 0, sizeof(*rmInst));
     rmInst->isLocked = RM_FALSE;
     rmInst->registeredWithDelegateOrServer = RM_FALSE;
     rmInst->transactionSeqNum = transactionInitSequenceNum();
 
-    rmInst->instType = initCfg->instType;    
-    rm_strncpy (rmInst->instName, initCfg->instName, RM_NAME_MAX_CHARS);
+    rmInst->instType = initCfg->instType;
+    rm_strncpy(rmInst->instName, initCfg->instName, RM_NAME_MAX_CHARS);
     rmInst->mtSemObj = initCfg->mtSemObj;
 
     if ((rmInst->instType == Rm_instType_SERVER) ||
@@ -1491,8 +1496,8 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
         }
 
         if (rmInst->instType == Rm_instType_SHARED_SERVER) {
-            /* Shared Server makes copy of policy in shared memory for Shared Clients
-             * on other cores */
+            /* Shared Server makes copy of policy in shared memory for Shared
+             * Clients on other cores */
             policySize = fdt_totalsize(initCfg->instCfg.serverCfg.globalPolicy);
             /* Align policy size to cache boundary */
             if (policySize % RM_MAX_CACHE_ALIGN) {
@@ -1501,8 +1506,7 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
             rmInst->u.server.policySize = policySize;
             rmInst->u.server.globalPolicy = Rm_osalMalloc(rmInst->u.server.policySize);
             memcpy(rmInst->u.server.globalPolicy, initCfg->instCfg.serverCfg.globalPolicy, rmInst->u.server.policySize);
-        }
-        else {
+        } else {
             rmInst->u.server.globalPolicy = initCfg->instCfg.serverCfg.globalPolicy;
         }
 
@@ -1515,7 +1519,7 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
          * GRL so that Linux resources can be reserved correctly */
         rmInst->u.server.globalValidInstTree = rmPolicyCreateValidInstTree((Rm_Handle)rmInst, addLinux, result);
         if (*result == RM_OK) {
-            *result = rmPolicyValidatePolicy((Rm_Handle)rmInst);  
+            *result = rmPolicyValidatePolicy((Rm_Handle)rmInst);
         }
         
         if (*result != RM_OK) {
@@ -1523,31 +1527,37 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
                 rmPolicyFreeValidInstTree((Rm_Handle)rmInst);
             }
             goto errorExit;
-        }
-        else {
+        } else {
             rmNameServerInit((Rm_Handle)rmInst);
 
             globalResourceDtb = initCfg->instCfg.serverCfg.globalResourceList;
 
-            if ((*result = rmAllocatorInitializeResources((Rm_Handle) rmInst, globalResourceDtb, linuxResourceDtb)) == RM_OK) {  
-                *result = rmPolicyValidatePolicyResourceNames((Rm_Handle)rmInst);
+            if ((*result = rmAllocatorInitTree((Rm_Handle) rmInst)) == RM_OK) {
+                if ((*result = rmAllocatorPopulateTree((Rm_Handle)rmInst,
+                                                        globalResourceDtb,
+                                                        linuxResourceDtb)) ==
+                                                        RM_OK) {
+                    *result = rmPolicyValidateResNames((Rm_Handle)rmInst);
+                }
             }
 
             if (*result != RM_OK) {
-                rmAllocatorDeleteResources((Rm_Handle)rmInst);
+                rmAllocatorDeleteTree((Rm_Handle)rmInst);
                 rmNameServerDelete((Rm_Handle)rmInst);
+                if (rmInst->u.server.globalValidInstTree) {
+                    rmPolicyFreeValidInstTree((Rm_Handle)rmInst);
+                }
                 goto errorExit;
             }
         }
-    }
-    else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
+    } else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
         if (!initCfg->instCfg.cdCfg.cdPolicy) {
             *result = RM_ERROR_INVALID_CD_CONFIGURATION;
             goto errorExit;
-        }        
+        }
 
         rmInst->u.cd.cdPolicy = initCfg->instCfg.cdCfg.cdPolicy;
-        rmInst->u.cd.cdValidInstTree = rmPolicyCreateValidInstTree((Rm_Handle)rmInst, addLinux, result);        
+        rmInst->u.cd.cdValidInstTree = rmPolicyCreateValidInstTree((Rm_Handle)rmInst, addLinux, result);
         if (*result == RM_OK) {
             *result = rmPolicyValidatePolicy((Rm_Handle)rmInst);
         }
@@ -1559,7 +1569,12 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
             goto errorExit;
         }
 
-        rmInst->u.cd.allocators = NULL;
+        if ((*result = rmAllocatorInitTree((Rm_Handle) rmInst)) != RM_OK) {
+            if (rmInst->u.cd.cdValidInstTree) {
+                rmPolicyFreeValidInstTree((Rm_Handle)rmInst);
+            }
+            goto errorExit;
+        }
 
         /* Remove once CD instance is stable - tracked by SDOCM00100797 */
         *result = RM_WARNING_CD_INSTANCE_NOT_STABLE;
@@ -1633,7 +1648,7 @@ errorExit:
 int32_t Rm_delete(Rm_Handle rmHandle, int ignorePendingServices)
 {
     Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
-    void    *key; 
+    void    *key;
 
     key = Rm_osalCsEnter();
     if (rmInst->instType == Rm_instType_SHARED_SERVER) {
@@ -1652,17 +1667,18 @@ int32_t Rm_delete(Rm_Handle rmHandle, int ignorePendingServices)
 
     if ((rmInst->instType == Rm_instType_SERVER) ||
         (rmInst->instType == Rm_instType_SHARED_SERVER)) {
-        rmAllocatorDeleteResources(rmHandle);
+        rmAllocatorDeleteTree(rmHandle);
         rmNameServerDelete(rmHandle);
-        rmInst->u.server.allocators = NULL;
+        rmInst->u.server.allocatorTree = NULL;
 
         if (rmInst->instType == Rm_instType_SHARED_SERVER) {
-            Rm_osalFree((void *)rmInst->u.server.globalPolicy, rmInst->u.server.policySize);
+            Rm_osalFree((void *)rmInst->u.server.globalPolicy,
+                        rmInst->u.server.policySize);
         }
     }
     else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
-        rmAllocatorDeleteResources(rmHandle);
-        rmInst->u.cd.allocators = NULL;
+        rmAllocatorDeleteTree(rmHandle);
+        rmInst->u.cd.allocatorTree = NULL;
     }
 
     if (rmInst->instType != Rm_instType_SHARED_CLIENT) {
@@ -1685,7 +1701,7 @@ int32_t Rm_delete(Rm_Handle rmHandle, int ignorePendingServices)
 
     Rm_osalFree((void *)rmInst, sizeof(Rm_Inst));
    
-    Rm_osalCsExit(key);   
+    Rm_osalCsExit(key);
     return (RM_OK);
 }
 
index 77fca9f08bfd210aa7c3e8761cae85f5851197e5..37c46b5c8c303329390860cd0a27ba77cade30c3 100644 (file)
  ************************ Local Functions *****************************
  **********************************************************************/
 
-/* FUNCTION PURPOSE: Creates a resource allocator
- ***********************************************************************
- * DESCRIPTION: Returns a newly Created and initialized resource
- *              The allocator is also stored in the RM instance
- *              allocator list.            
- */
-static Rm_Allocator *allocatorAdd(Rm_Handle rmHandle, const char *resourceName)
-{
-    Rm_Inst      *rmInst = (Rm_Inst *)rmHandle;
-    Rm_Allocator *allocators   = rmAllocatorGetAllocatorList(rmHandle);
-    Rm_Allocator *newAllocator = NULL;
-
-    newAllocator = Rm_osalMalloc(sizeof(*allocators));
-
-    if (newAllocator) {
-        memset((void *)newAllocator, 0, sizeof(*newAllocator));
-        rm_strncpy(newAllocator->resourceName, resourceName, RM_NAME_MAX_CHARS);
-        newAllocator->allocatorRootEntry = NULL;
-        newAllocator->nextAllocator = NULL;  
-
-        /* Add allocator to end of list */
-        if (allocators) {
-            while (allocators->nextAllocator) {
-                allocators = allocators->nextAllocator;
-            }
-            allocators->nextAllocator = newAllocator;
-            RM_SS_OBJ_WB(rmInst, allocators, Rm_Allocator);
-        }
-        else {
-            if ((rmInst->instType == Rm_instType_SERVER) ||
-                (rmInst->instType == Rm_instType_SHARED_SERVER)) {
-                rmInst->u.server.allocators = newAllocator;
-            }
-            else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
-                rmInst->u.cd.allocators = newAllocator;
-            }
-            else {
-                /* Free allocator because instance type doesn't support allocators */
-                Rm_osalFree(newAllocator, sizeof(*newAllocator));
-                newAllocator = NULL;
-            }
-        }
-    }
-    return (newAllocator);
-}
-
 /* FUNCTION PURPOSE: Checks a resource node's ownership
  ***********************************************************************
  * DESCRIPTION: Returns the owner reference count if the provided
@@ -426,7 +380,8 @@ static void allocatorResNodeOwnerClear(Rm_Handle rmHandle, Rm_ResourceNode *node
  *              resource's owner reference count is returned if the 
  *              resource range is found.
  */
-static int32_t allocatorStatus(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
+static int32_t allocatorStatus(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
+                               Rm_AllocatorOpInfo *opInfo)
 {
     Rm_ResourceNode  findNode;
     Rm_ResourceNode *matchingNode = NULL; 
@@ -437,7 +392,7 @@ static int32_t allocatorStatus(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_A
     memset((void *)&findNode, 0, sizeof(findNode));
     findNode.base = opInfo->resourceInfo->base;
     findNode.length = opInfo->resourceInfo->length;
-    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, &findNode);
+    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
 
     if (matchingNode) {
         matchingEnd = matchingNode->base + matchingNode->length - 1;
@@ -468,7 +423,9 @@ static int32_t allocatorStatus(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_A
  *              If a valid range is found it will be returned for the 
  *              treeAllocate algorithm to handle.
  */
-static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, int32_t resourcePolicy, 
+static int32_t allocatorPreAllocate(Rm_Handle rmHandle,
+                                    Rm_AllocatorNode *allocator,
+                                    int32_t resourcePolicy,
                                     Rm_AllocatorOpInfo *opInfo)
 {   
     Rm_Inst           *rmInst = (Rm_Inst *)rmHandle;
@@ -497,7 +454,7 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator,
 
     if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
         /* Set base to first node's base since CD will not have all resources like Server */
-        matchingNode = RB_MIN(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry);
+        matchingNode = RB_MIN(_Rm_AllocatorResourceTree, allocator->resourceRootEntry);
         opInfo->resourceInfo->base = matchingNode->base;
     }
     else {
@@ -529,7 +486,7 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator,
     policyCheckCfg.resourceOffset = resourcePolicy;
     
     do {
-        matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, &findNode);
+        matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
         
         if (matchingNode) {
             matchingEnd = matchingNode->base + matchingNode->length - 1;
@@ -603,7 +560,7 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator,
                     }
                     else {
                         /* Matching node allocated, move to next node */
-                        if ((nextNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode))) {
+                        if ((nextNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode))) {
                             findNode.base = nextNode->base;
                         }
                         else {
@@ -633,20 +590,22 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator,
  *              resource nodes that may have become equivalent (in terms
  *              of ownership) after the allocation.
  */
-static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, int32_t resourcePolicy, 
+static int32_t allocatorAllocate(Rm_Handle rmHandle,
+                                 Rm_AllocatorNode *allocator,
+                                 int32_t resourcePolicy,
                                  Rm_AllocatorOpInfo *opInfo)
 {
     Rm_ResourceNode     findNode;
     Rm_ResourceNode    *matchingNode = NULL;
     Rm_ResourceNode    *leftNode = NULL;
     Rm_ResourceNode    *rightNode = NULL;
-    Rm_PolicyCheckType  policyCheckType;    
+    Rm_PolicyCheckType  policyCheckType;
     Rm_PolicyCheckCfg   policyCheckCfg;
     int                 allocPassesPolicy;
     int                 combineLeft = RM_FALSE;
-    int                 combineRight = RM_FALSE;    
+    int                 combineRight = RM_FALSE;
     uint32_t            findEnd;
-    uint32_t            matchingEnd;  
+    uint32_t            matchingEnd;
     int32_t             retVal;
 
     if (opInfo->operation == Rm_allocatorOp_ALLOCATE_INIT) {
@@ -663,7 +622,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
     memset((void *)&findNode, 0, sizeof(findNode));
     findNode.base = opInfo->resourceInfo->base;
     findNode.length = opInfo->resourceInfo->length;
-    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, &findNode);
+    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
 
     /* Prepare privilege checks */
     memset((void *)&policyCheckCfg, 0, sizeof(policyCheckCfg)); 
@@ -739,19 +698,19 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                      *   |<--left node-->||<--matched  node-->||<--right node-->| => existing node
                      *                    |<--alloc request-->|  => requested resources
                      */                     
-                    leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                    rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                    RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                    leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                    rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                    RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                     allocatorResNodeOwnerAdd(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
 
                     if (leftNode && allocatorResNodeOwnerCompare(rmHandle, leftNode, matchingNode) &&
                         allocatorResNodeBoundaryCompare(leftNode, matchingNode)) {
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                         combineLeft = RM_TRUE;
                     }
                     if (rightNode && allocatorResNodeOwnerCompare(rmHandle, rightNode, matchingNode) &&
                         allocatorResNodeBoundaryCompare(rightNode, matchingNode)) {
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                         combineRight = RM_TRUE;
                     }
 
@@ -773,7 +732,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                         allocatorResNodeOwnerClear(rmHandle, leftNode);
                         rmResourceNodeFree(leftNode);
                         if (rightNode) {
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);  
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);  
                         }
                     }
                     else if (combineRight) {
@@ -783,21 +742,21 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                         allocatorResNodeOwnerClear(rmHandle, rightNode);
                         rmResourceNodeFree(rightNode);
                         if (leftNode) {
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                         }
                     }
                     else {
                         /* No combine. */
                         if (leftNode) {
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                         }
                         if (rightNode) {
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                         }
                     }
 
                     /* Always reinsert matchingNode */                
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                     
                     /* Matching node contains new reference count after alloc.  Return new owner count
                      * and originating instance allocation reference count. */
@@ -812,7 +771,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                      * |<----------matched node---------->|
                      *        |<---alloc request--->|
                      */ 
-                    RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                    RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                     leftNode = rmResourceNodeNew(matchingNode->base, findNode.base - matchingNode->base);
                     allocatorResNodeOwnerCopy(rmHandle, leftNode, matchingNode);
                     rightNode = rmResourceNodeNew(findNode.base + findNode.length, matchingEnd - findEnd);
@@ -823,9 +782,9 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                     allocatorResNodeOwnerAdd(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
 
                     /* Insert all the nodes */
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                     
                     /* Matching node contains new reference count after alloc.  Return new owner count
                      * and originating instance allocation reference count. */
@@ -841,14 +800,14 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                          * |<---left node (alloc'd)--->||<----------matched node---------->|
                          *                              |<---findNode (alloc req)--->|
                          */                         
-                        leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                        leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                         /* Add allocating instance to owner list for compare with leftNode */
                         allocatorResNodeOwnerAdd(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
                         
                         if (leftNode && allocatorResNodeOwnerCompare(rmHandle, leftNode, matchingNode) &&
                             allocatorResNodeBoundaryCompare(leftNode, matchingNode)) {
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                             /* Combine leftNode and findNode */
                             leftNode->length += findNode.length;
                         }
@@ -861,7 +820,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                         matchingNode->base = findNode.base + findNode.length;
                         matchingNode->length = matchingEnd - findEnd;  
 
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                         /* Left node contains new reference count after alloc.  Return new owner count
                          * and originating instance allocation reference count. */
                         opInfo->resourceInfo->ownerCount = leftNode->allocationCount;
@@ -873,16 +832,16 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                          * possibilities to the right
                          *
                          * |<----------matched node---------->||<---right node (alloc'd)--->|
-                         *       |<---findNode (alloc req)--->| 
+                         *       |<---findNode (alloc req)--->|
                          */                        
-                        rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                        rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                         /* Add allocating instance to owner list for compare with rightNode */
                         allocatorResNodeOwnerAdd(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
                         
                         if (rightNode && allocatorResNodeOwnerCompare(rmHandle, rightNode, matchingNode) &&
                             allocatorResNodeBoundaryCompare(rightNode, matchingNode)) {
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                             /* Combine rightNode and findNode */
                             rightNode->base = findNode.base;
                             rightNode->length += findNode.length;
@@ -895,7 +854,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                         /* Account for rightNode in matchingNode */
                         matchingNode->length -= findNode.length;  
 
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                         /* Right node contains new reference count after alloc.  Return new owner count
                          * and originating instance allocation reference count. */
                         opInfo->resourceInfo->ownerCount = rightNode->allocationCount;
@@ -904,7 +863,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
                     }
                     /* Remove allocating instance from leftover matchingNode */
                     allocatorResNodeOwnerDelete(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                 }
                 retVal = RM_SERVICE_APPROVED;
             }
@@ -932,7 +891,8 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
  *              become equivalent (in terms of ownership) after the
  *              allocation.
  */
-static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
+static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
+                             Rm_AllocatorOpInfo *opInfo)
 {
     Rm_ResourceNode  findNode;
     Rm_ResourceNode *matchingNode = NULL;
@@ -947,7 +907,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
     memset((void *)&findNode, 0, sizeof(findNode));
     findNode.base = opInfo->resourceInfo->base;
     findNode.length = opInfo->resourceInfo->length;
-    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, &findNode);
+    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
 
     if (matchingNode) {
         findEnd = findNode.base + findNode.length - 1;
@@ -964,19 +924,19 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
                          * |<--left node-->||<---matched node--->||<--right node-->|
                          *                  |<---free request--->|
                          */ 
-                        leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                        rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                        leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                         allocatorResNodeOwnerDelete(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
 
                         if (leftNode && allocatorResNodeOwnerCompare(rmHandle, leftNode, matchingNode) &&
                             allocatorResNodeBoundaryCompare(leftNode, matchingNode)) {
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                             combineLeft = RM_TRUE;
                         }
                         if (rightNode && allocatorResNodeOwnerCompare(rmHandle, rightNode, matchingNode) &&
                             allocatorResNodeBoundaryCompare(rightNode, matchingNode)) {
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                             combineRight = RM_TRUE;
                         }
 
@@ -998,7 +958,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
                             allocatorResNodeOwnerClear(rmHandle, leftNode);
                             rmResourceNodeFree(leftNode);
                             if (rightNode) {
-                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode); 
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode); 
                             }
                         }
                         else if (combineRight) {
@@ -1008,21 +968,21 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
                             allocatorResNodeOwnerClear(rmHandle, rightNode);
                             rmResourceNodeFree(rightNode);
                             if (leftNode) {
-                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                             }
                         }
                         else {
                             /* No combine. */
                             if (leftNode) {
-                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                             }
                             if (rightNode) {
-                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                             }
                         }
 
                         /* Always reinsert matchingNode */
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                         
                         /* Matching node is what remains after free.  Return remaining owner count
                          * and originating instance allocation reference count. */
@@ -1040,22 +1000,22 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
                          * Remove instance from owner list then add it back in for side nodes for
                          * proper accounting of allocations in validInstance list
                          */ 
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                         allocatorResNodeOwnerDelete(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
                         
                         leftNode = rmResourceNodeNew(matchingNode->base, findNode.base - matchingNode->base);
                         allocatorResNodeOwnerCopy(rmHandle, leftNode, matchingNode);
                         allocatorResNodeOwnerAdd(rmHandle, leftNode, opInfo->serviceSrcInstNode);
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                         
                         rightNode = rmResourceNodeNew(findNode.base + findNode.length, matchingEnd - findEnd);
                         allocatorResNodeOwnerCopy(rmHandle, rightNode, matchingNode);
                         allocatorResNodeOwnerAdd(rmHandle, rightNode, opInfo->serviceSrcInstNode);
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
 
                         matchingNode->base = findNode.base;                                    
                         matchingNode->length = findNode.length;
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                         
                         /* Matching node is what remains after free.  Return remaining owner count
                          * and originating instance allocation reference count. */
@@ -1072,14 +1032,14 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
                              *                           |<---findNode (free req)--->|
                              */ 
 
-                            leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                            leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                             /* Remove freeing instance from owner list for compare with leftNode */
                             allocatorResNodeOwnerDelete(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
                             
                             if (leftNode && allocatorResNodeOwnerCompare(rmHandle, leftNode, matchingNode) &&
                                 allocatorResNodeBoundaryCompare(leftNode, matchingNode)) {
-                                RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                                RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                                 /* Combine leftNode and findNode */
                                 leftNode->length += findNode.length;
                             }
@@ -1091,7 +1051,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
                             /* Remove leftNode range from matchingNode */
                             matchingNode->base = findNode.base + findNode.length;
                             matchingNode->length = matchingEnd - findEnd;  
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
                             
                             /* Left node is what remains after free.  Return remaining owner count
                              * and originating instance allocation reference count. */
@@ -1107,14 +1067,14 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
                              *        |<---findNode (free req)--->|
                              */ 
                             
-                            rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode); 
+                            rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode); 
                             /* Remove freeing instance from owner list for compare with rightNode */
                             allocatorResNodeOwnerDelete(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
                             
                             if (rightNode && allocatorResNodeOwnerCompare(rmHandle, rightNode, matchingNode) &&
                                 allocatorResNodeBoundaryCompare(rightNode, matchingNode)) {
-                                RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                                RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                                 /* Combine rightNode and findNode */
                                 rightNode->base = findNode.base;
                                 rightNode->length += findNode.length;
@@ -1126,7 +1086,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
 
                             /* Remove rightNode range from matchingNode */
                             matchingNode->length -= findNode.length;  
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
                             
                             /* Right node is what remains after free.  Return remaining owner count
                              * and originating instance allocation reference count. */
@@ -1137,7 +1097,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
 
                         /* Add freeing instance back into matchingNode allocations */
                         allocatorResNodeOwnerAdd(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
                     }
                     retVal = RM_SERVICE_APPROVED;
                 }
@@ -1288,7 +1248,7 @@ static int32_t allocatorFindLinuxResource(Rm_Handle rmHandle, const char *resour
                 }       
                 
                 prevDepth = fdt_node_depth(linuxDtb, nodeOffset);
-               propOffset = fdt_first_property_offset(linuxDtb, nodeOffset);
+                propOffset = fdt_first_property_offset(linuxDtb, nodeOffset);
                 while ((propOffset >= RM_DTB_UTIL_STARTING_NODE_OFFSET) &&
                        (pathOffset < pathSize)) {
                     propertyData = fdt_getprop_by_offset(linuxDtb, propOffset, 
@@ -1330,8 +1290,10 @@ static int32_t allocatorFindLinuxResource(Rm_Handle rmHandle, const char *resour
  *              and there are "linux-dtb-alias" properties
  *              specified in the GRL.
  */
-static int32_t allocatorExtractGrlResProps(Rm_Handle rmHandle, const char *resourceName, 
-                                           Rm_ResourceProperties *resourceProperties, void *linuxDtb)
+static int32_t allocatorExtractGrlResProps(Rm_Handle rmHandle,
+                                           const char *resourceName,
+                                           Rm_ResourceProperties *resProps,
+                                           void *linuxDtb)
 {
     Rm_Inst             *rmInst = (Rm_Inst *)rmHandle;
     Rm_ResourceRange    *range = NULL;
@@ -1339,7 +1301,7 @@ static int32_t allocatorExtractGrlResProps(Rm_Handle rmHandle, const char *resou
     Rm_NsAssignment     *nsAssignments = NULL;
     Rm_NsAssignment     *nsAssignmentBasePtr = NULL;
     Rm_LinuxAlias       *linuxAlias = NULL;
-    Rm_NameServerObjCfg  nameServerObjCfg;      
+    Rm_NameServerObjCfg  nameServerObjCfg;
     int32_t              retVal = RM_OK;
     
     if ((strlen(resourceName) + 1) > RM_NAME_MAX_CHARS) {
@@ -1347,15 +1309,15 @@ static int32_t allocatorExtractGrlResProps(Rm_Handle rmHandle, const char *resou
         return(retVal);
     }
 
-    if (resourceProperties->rangeData && (resourceProperties->rangeLen > 0)) {
-        range = rangeBasePtr = rmDtbUtilResExtractRange(resourceProperties->rangeData, 
-                                                        resourceProperties->rangeLen);
-        
+    if (resProps->rangeData && (resProps->rangeLen > 0)) {
+        range = rangeBasePtr = rmDtbUtilResExtractRange(resProps->rangeData,
+                                                        resProps->rangeLen);
+
         if ((retVal = rmAllocatorCreate(rmHandle, resourceName, range)) >= RM_OK) {
-            if (resourceProperties->linuxAliasData && resourceProperties->linuxAliasLen) {
+            if (resProps->linuxAliasData && resProps->linuxAliasLen) {
                 if (linuxDtb) {
-                    linuxAlias = rmDtbUtilResExtractLinuxAlias(resourceProperties->linuxAliasData,
-                                                               resourceProperties->linuxAliasLen, &retVal);
+                    linuxAlias = rmDtbUtilResExtractLinuxAlias(resProps->linuxAliasData,
+                                                               resProps->linuxAliasLen, &retVal);
                     if (linuxAlias) {
                         retVal = allocatorFindLinuxResource(rmHandle, resourceName, linuxDtb, linuxAlias);            
                     }
@@ -1365,9 +1327,9 @@ static int32_t allocatorExtractGrlResProps(Rm_Handle rmHandle, const char *resou
     }
     
     if (retVal >= RM_OK) {
-        if (resourceProperties->nsAssignData && resourceProperties->nsAssignLen) {
-            nsAssignments = rmDtbUtilResExtractNsAssignment(resourceProperties->nsAssignData, 
-                                                            resourceProperties->nsAssignLen, &retVal);
+        if (resProps->nsAssignData && resProps->nsAssignLen) {
+            nsAssignments = rmDtbUtilResExtractNsAssignment(resProps->nsAssignData, 
+                                                            resProps->nsAssignLen, &retVal);
             if (nsAssignments) {
                 nsAssignmentBasePtr = nsAssignments;
                 if (rmInst->instType == Rm_instType_SHARED_SERVER) {
@@ -1405,61 +1367,68 @@ static int32_t allocatorExtractGrlResProps(Rm_Handle rmHandle, const char *resou
  ********************** Internal Functions ****************************
  **********************************************************************/
 
-/* FUNCTION PURPOSE: Creates a new resource tree
+/* FUNCTION PURPOSE: Creates a new allocator
  ***********************************************************************
- * DESCRIPTION: Creates and populates a new resource tree allocator
+ * DESCRIPTION: Creates a new allocator and its resource tree
  *              using the provided resource name and value range.  The
  *              name and value originate from the GRL.
  */
-int32_t rmAllocatorCreate(Rm_Handle rmHandle, const char *resourceName, Rm_ResourceRange *range)
+int32_t rmAllocatorCreate(Rm_Handle rmHandle, const char *resourceName,
+                          Rm_ResourceRange *range)
 {
-    Rm_Inst         *rmInst = (Rm_Inst *)rmHandle;
-    Rm_Allocator    *allocator = NULL;
-    Rm_ResourceTree *treeRoot = NULL;
-    Rm_ResourceNode *treeNode = NULL;
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_AllocatorTree *allocTree   = rmAllocatorGetTree(rmHandle);
+    Rm_AllocatorNode *newAllocNode = NULL;
+    Rm_ResourceTree  *resTree = NULL;
+    Rm_ResourceNode  *resNode = NULL;
 
-    allocator = allocatorAdd(rmHandle, resourceName);
-    
-    if (allocator) {
-        treeRoot = Rm_osalMalloc(sizeof(*treeRoot));
-        RB_INIT(treeRoot);
+    newAllocNode = rmAllocatorNodeNew(resourceName);
+    if (newAllocNode) {
+        resTree = Rm_osalMalloc(sizeof(*resTree));
+        RB_INIT(resTree);
 
         while (range != NULL) {
-            treeNode = rmResourceNodeNew(range->base, range->length);
-            RB_INSERT(_Rm_AllocatorResourceTree, treeRoot, treeNode);
+            resNode = rmResourceNodeNew(range->base, range->length);
+            RB_INSERT(_Rm_AllocatorResourceTree, resTree, resNode);
             range = range->nextRange;
         }
         if (rmInst->instType == Rm_instType_SHARED_SERVER) {
-            rmResourceTreeWb(treeRoot);
+            rmResourceTreeWb(resTree);
+        }
+
+        newAllocNode->resourceRootEntry = resTree;
+        RM_SS_OBJ_WB(rmInst, newAllocNode, Rm_AllocatorNode);
+
+        RB_INSERT(_Rm_AllocatorTree, allocTree, newAllocNode);
+        if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+            rmAllocatorTreeWb(allocTree);
         }
-        
-        allocator->allocatorRootEntry = treeRoot;
-        RM_SS_OBJ_WB(rmInst, allocator, Rm_Allocator);
-        return (RM_OK);
     }
     else {
-        return (RM_ERROR_COULD_NOT_CREATE_NEW_ALLOCATOR);
+        return(RM_ERROR_COULD_NOT_CREATE_NEW_ALLOCATOR);
     }
+
+    return(RM_OK);
 }
 
-/* FUNCTION PURPOSE: Returns a pointer to the allocator list
+/* FUNCTION PURPOSE: Returns a pointer to the allocator tree
  ***********************************************************************
- * DESCRIPTION: Returns a pointer to the instance's allocator list
+ * DESCRIPTION: Returns a pointer to the instance's allocator tree
  *              based on the instance type
  */
-Rm_Allocator *rmAllocatorGetAllocatorList(Rm_Handle rmHandle)
+Rm_AllocatorTree *rmAllocatorGetTree(Rm_Handle rmHandle)
 {
-    Rm_Inst      *rmInst = (Rm_Inst *)rmHandle;
-    Rm_Allocator *list = NULL;
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_AllocatorTree *tree = NULL;
 
     if ((rmInst->instType == Rm_instType_SERVER) ||
         (rmInst->instType == Rm_instType_SHARED_SERVER)) {
-        list = rmInst->u.server.allocators;
+        tree = rmInst->u.server.allocatorTree;
     }
     else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
-        list = rmInst->u.cd.allocators;
+        tree = rmInst->u.cd.allocatorTree;
     }
-    return(list);
+    return(tree);
 }
 
 /* FUNCTION PURPOSE: Finds an allocator
@@ -1467,20 +1436,20 @@ Rm_Allocator *rmAllocatorGetAllocatorList(Rm_Handle rmHandle)
  * DESCRIPTION: Returns a pointer to an allocator that matches the 
  *              provided resource name.
  */
-Rm_Allocator *rmAllocatorFind(Rm_Handle rmHandle, const char *resourceName)
+Rm_AllocatorNode *rmAllocatorFind(Rm_Handle rmHandle, const char *resourceName)
 {
-    Rm_Inst      *rmInst = (Rm_Inst *)rmHandle;
-    Rm_Allocator *allocatorList = rmAllocatorGetAllocatorList(rmHandle);
-    
-    while (allocatorList) {
-        RM_SS_OBJ_INV(rmInst, allocatorList, Rm_Allocator);
-        if (strncmp(allocatorList->resourceName, resourceName, RM_NAME_MAX_CHARS) == 0) {
-            break;             
-        }
-        allocatorList = allocatorList->nextAllocator;
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_AllocatorTree *tree = rmAllocatorGetTree(rmHandle);
+    Rm_AllocatorNode  findNode;
+
+    if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+        rmAllocatorTreeInv(tree);
     }
 
-    return (allocatorList);
+    memset((void *)&findNode, 0, sizeof(Rm_AllocatorNode));
+    rm_strncpy(findNode.resourceName, resourceName, RM_NAME_MAX_CHARS);
+
+    return(RB_FIND(_Rm_AllocatorTree, tree, &findNode));
 }
 
 /* FUNCTION PURPOSE: Checks if a resource node is localized
@@ -1492,18 +1461,23 @@ Rm_Allocator *rmAllocatorFind(Rm_Handle rmHandle, const char *resourceName)
  *              will return RM_TRUE if the node is localized.  
  *              Otherwise, the function returns RM_FALSE
  */
-int rmAllocatorGetNodeLocalization(Rm_Handle rmHandle, char *resourceName, 
+int rmAllocatorGetNodeLocalization(Rm_Handle rmHandle, char *resourceName,
                                    int32_t *resBase, uint32_t *resLen)
 {
-    Rm_Inst         *rmInst = (Rm_Inst *)rmHandle;
-    void *           policy = rmPolicyGetPolicy((Rm_Handle)rmInst);
-    int32_t          resOffsetInPolicy = rmPolicyGetResourceOffset(policy, resourceName);
-    uint32_t         allocSize = rmPolicyGetResourceCdAllocSize(policy, resOffsetInPolicy);    
-    Rm_Allocator    *allocator = rmAllocatorFind(rmHandle, resourceName);
-    Rm_ResourceNode  findNode;
-    Rm_ResourceNode *matchingNode = NULL;
-    Rm_ResourceNode *neighborNode = NULL;   
-    int              nodeIsLocalized = RM_FALSE;
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    void             *policy = NULL;
+    int32_t           resOffsetInPolicy;
+    uint32_t          allocSize;
+    Rm_AllocatorNode *allocator = NULL;
+    Rm_ResourceNode   findNode;
+    Rm_ResourceNode  *matchingNode = NULL;
+    Rm_ResourceNode  *neighborNode = NULL;
+    int               nodeIsLocalized = RM_FALSE;
+
+    policy = rmPolicyGetPolicy((Rm_Handle)rmInst);
+    resOffsetInPolicy = rmPolicyGetResourceOffset(policy,resourceName);
+    allocSize = rmPolicyGetResourceCdAllocSize(policy, resOffsetInPolicy);
+    allocator = rmAllocatorFind(rmHandle, resourceName);
 
     /* Nothing to free back to server if policy never specified blocks could be allocated
      * to CD */
@@ -1511,7 +1485,7 @@ int rmAllocatorGetNodeLocalization(Rm_Handle rmHandle, char *resourceName,
         memset((void *)&findNode, 0, sizeof(findNode));
         findNode.base = *resBase;
         findNode.length = *resLen;
-        matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, &findNode);
+        matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
 
         if (matchingNode) {
             /* Node can be freed back to Server from CD if:
@@ -1527,13 +1501,13 @@ int rmAllocatorGetNodeLocalization(Rm_Handle rmHandle, char *resourceName,
             }
 
             /* Check left neighbor */
-            neighborNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+            neighborNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
             if (neighborNode && allocatorResNodeBoundaryCompare(neighborNode, matchingNode)) {
                 goto exitLocalization; 
             }
 
             /* Check right neighbor */
-            neighborNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
+            neighborNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
             if (neighborNode && allocatorResNodeBoundaryCompare(neighborNode, matchingNode)) {
                 goto exitLocalization; 
             }
@@ -1559,17 +1533,17 @@ exitLocalization:
  */
 int32_t rmAllocatorOperation(Rm_Handle rmHandle, Rm_AllocatorOpInfo *opInfo)
 {
-    Rm_Inst      *rmInst = (Rm_Inst *)rmHandle;
-    Rm_Allocator *allocator = NULL;
-    int32_t       resourceOffsetInPolicy;
-    int32_t       retVal;
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_AllocatorNode *allocator = NULL;
+    int32_t           resourceOffsetInPolicy;
+    int32_t           retVal;
     
     resourceOffsetInPolicy = rmPolicyGetResourceOffset(opInfo->policy, opInfo->resourceInfo->name);
     allocator = rmAllocatorFind(rmHandle, opInfo->resourceInfo->name);
     
     if ((resourceOffsetInPolicy > 0) && allocator) {
         if (rmInst->instType == Rm_instType_SHARED_SERVER) {
-            rmResourceTreeInv(allocator->allocatorRootEntry);
+            rmResourceTreeInv(allocator->resourceRootEntry);
         }
 
         if (opInfo->operation == Rm_allocatorOp_GET_STATUS) {
@@ -1590,7 +1564,7 @@ int32_t rmAllocatorOperation(Rm_Handle rmHandle, Rm_AllocatorOpInfo *opInfo)
         if ((rmInst->instType == Rm_instType_SHARED_SERVER) &&
             (opInfo->operation != Rm_allocatorOp_GET_STATUS) &&
             (retVal == RM_SERVICE_APPROVED)) {
-            rmResourceTreeWb(allocator->allocatorRootEntry);
+            rmResourceTreeWb(allocator->resourceRootEntry);
         }        
     }
     else {
@@ -1600,31 +1574,63 @@ int32_t rmAllocatorOperation(Rm_Handle rmHandle, Rm_AllocatorOpInfo *opInfo)
     return(retVal);
 }
 
-/* FUNCTION PURPOSE: Initializes server allocators
+/* FUNCTION PURPOSE: Creates the allocator tree root
+ ***********************************************************************
+ * DESCRIPTION: Initializes a RM instance's allocator tree root entry
+ */
+int32_t rmAllocatorInitTree(Rm_Handle rmHandle)
+{
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_AllocatorTree *root = NULL;
+    int32_t           retVal = RM_OK;
+
+    root = Rm_osalMalloc(sizeof(Rm_AllocatorTree));
+    if (root) {
+        RB_INIT(root);
+        RM_SS_OBJ_WB(rmInst, root, Rm_AllocatorTree);
+
+        if ((rmInst->instType == Rm_instType_SERVER) ||
+            (rmInst->instType == Rm_instType_SHARED_SERVER)) {
+            rmInst->u.server.allocatorTree = root;
+        }
+        else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
+            rmInst->u.cd.allocatorTree = root;
+        }
+    } else {
+        retVal = RM_ERROR_COULD_NOT_INIT_ALLOC_TREE;
+    }
+    return(retVal);
+}
+
+/* FUNCTION PURPOSE: Populates server allocator tree
  ***********************************************************************
  * DESCRIPTION: Creates and initializes a server instance's
- *              resource allocators using the GRL and, if
+ *              resource allocator tree using the GRL and, if
  *              provided, Linux DTB.
  */
-int32_t rmAllocatorInitializeResources(Rm_Handle rmHandle, void *globalResourceDtb, void *linuxDtb)
+int32_t rmAllocatorPopulateTree(Rm_Handle rmHandle, void *globalResourceDtb,
+                                void *linuxDtb)
 {
     int32_t                nodeOffset = RM_DTB_UTIL_STARTING_NODE_OFFSET;
     int32_t                nodeDepth = RM_DTB_UTIL_STARTING_DEPTH;
-    Rm_ResourceProperties  resProperties;    
+    Rm_ResourceProperties  resProperties;
     int32_t                propOffset;
     int32_t                propertyLen;
     const char            *propertyName;
     const void            *propertyData;
-    Rm_ResourcePropType    propertyType;  
+    Rm_ResourcePropType    propertyType;
     int32_t                retVal = RM_OK;
 
-    /* Parse the Global Resource List, creating an allocator for each specified resource node */
-    while ((nodeOffset >= RM_DTB_UTIL_STARTING_NODE_OFFSET) && (nodeDepth >= RM_DTB_UTIL_STARTING_DEPTH)) {
+    /* Parse the Global Resource List, creating an allocator for each
+     * specified resource node */
+    while ((nodeOffset >= RM_DTB_UTIL_STARTING_NODE_OFFSET) &&
+           (nodeDepth >= RM_DTB_UTIL_STARTING_DEPTH)) {
         memset((void *)&resProperties, 0, sizeof(resProperties));
         /* Get properties of resource node */
         propOffset = fdt_first_property_offset(globalResourceDtb, nodeOffset);
         while (propOffset >= RM_DTB_UTIL_STARTING_NODE_OFFSET) {
-            propertyData = fdt_getprop_by_offset(globalResourceDtb, propOffset, &propertyName, &propertyLen);
+            propertyData = fdt_getprop_by_offset(globalResourceDtb, propOffset,
+                                                 &propertyName, &propertyLen);
             propertyType = rmDtbUtilResGetPropertyType(propertyName);
             if (propertyType == Rm_resourcePropType_RESOURCE_RANGE) {
                 resProperties.rangeData = propertyData;
@@ -1637,17 +1643,20 @@ int32_t rmAllocatorInitializeResources(Rm_Handle rmHandle, void *globalResourceD
             else if (propertyType == Rm_resourcePropType_RESOURCE_LINUX_ALIAS) {
                 resProperties.linuxAliasData = propertyData;
                 resProperties.linuxAliasLen = propertyLen;
-            }        
+            }
             else {
                 retVal = RM_ERROR_GRL_UNKNOWN_RESOURCE_PROPERTY;
                 goto exitAllocInit;
             }
 
-            propOffset = fdt_next_property_offset(globalResourceDtb, propOffset);
+            propOffset = fdt_next_property_offset(globalResourceDtb,
+                                                  propOffset);
             if (propOffset == -FDT_ERR_NOTFOUND) {
-                /* No more resource properties but at least one found.  Extract the property values */
-                retVal = allocatorExtractGrlResProps(rmHandle, fdt_get_name(globalResourceDtb, nodeOffset, NULL), 
-                                                     &resProperties, linuxDtb);
+                /* No more resource properties but at least one found.  Extract
+                 * the property values */
+                retVal = allocatorExtractGrlResProps(rmHandle,
+                            fdt_get_name(globalResourceDtb, nodeOffset, NULL),
+                            &resProperties, linuxDtb);
                 if (retVal < RM_OK) {
                     goto exitAllocInit;
                 }
@@ -1671,80 +1680,86 @@ int32_t rmAllocatorInitializeResources(Rm_Handle rmHandle, void *globalResourceD
             goto exitAllocInit;
         }
     }
-exitAllocInit:    
+
+exitAllocInit:
     return(retVal);
 }
 
-/* FUNCTION PURPOSE: Deletes a resource allocator resource node
+/* FUNCTION PURPOSE: Deletes a node from a resource tree
  ***********************************************************************
- * DESCRIPTION: Deletes a resource allocator's node based on the given
- *              resource name, base and length.
+ * DESCRIPTION: Deletes a node from an allocator's resource tree based on the
+ *              given base and length.
  */
-void rmAllocatorDeleteNode(Rm_Handle rmHandle, const char *resName, int32_t resBase, uint32_t resLen)
+void rmAllocatorDeleteResNode(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
+                              int32_t resBase, uint32_t resLen)
 {
-    Rm_Allocator    *allocator = rmAllocatorFind(rmHandle, resName);
-    Rm_ResourceNode  findNode;
-    Rm_ResourceNode *matchingNode;
-
-    memset((void *)&findNode, 0, sizeof(findNode));
-    findNode.base = resBase;
-    findNode.length = resLen;
-    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, &findNode);
+    Rm_Inst         *rmInst = (Rm_Inst *)rmHandle;
+    Rm_ResourceNode  find;
+    Rm_ResourceNode *match;
+
+    memset((void *)&find, 0, sizeof(find));
+    find.base = resBase;
+    find.length = resLen;
+    match = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry,
+                    &find);
     
-    if (matchingNode) {
-        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
-        rmResourceNodeFree(matchingNode);
+    if (match) {
+        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry,
+                  match);
+        rmResourceNodeFree(match);
+        if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+            rmResourceTreeWb(allocator->resourceRootEntry);
+        }
     }
 }
 
-/* FUNCTION PURPOSE: Deletes a resource allocator
+/* FUNCTION PURPOSE: Deletes an allocator's resource tree
  ***********************************************************************
- * DESCRIPTION: Deletes a resource allocator based on the given
- *              resource name.  The resource allocator will be
- *              removed from the RM instance allocator list.
+ * DESCRIPTION: Deletes an allocator's resource tree based on the given
+ *              resource name.
  */
 int32_t rmAllocatorDelete(Rm_Handle rmHandle, const char *resourceName)
 {
-    Rm_Inst         *rmInst = (Rm_Inst *)rmHandle;    
-    Rm_Allocator    *allocator = rmAllocatorGetAllocatorList(rmHandle);
-    Rm_Allocator    *prevAllocator = NULL;
-    Rm_ResourceTree *treeRoot;
-    Rm_ResourceNode *node = NULL;
-    Rm_ResourceNode *nextNode = NULL;
-    int32_t          retVal = RM_OK;
-
-    while (allocator) {
-        if (strncmp(allocator->resourceName, resourceName, RM_NAME_MAX_CHARS) == 0) {
-            break;             
-        }
-        prevAllocator = allocator;
-        allocator = allocator->nextAllocator;
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_AllocatorTree *allocTree = rmAllocatorGetTree(rmHandle);
+    Rm_AllocatorNode  find;
+    Rm_AllocatorNode *match;
+    Rm_ResourceTree  *resTree;
+    Rm_ResourceNode  *resNode = NULL;
+    Rm_ResourceNode  *nextResNode = NULL;
+    int32_t           retVal = RM_OK;
+
+    if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+        rmAllocatorTreeInv(allocTree);
     }
 
-    if (allocator) {
-        if (prevAllocator == NULL) {
-            if ((rmInst->instType == Rm_instType_SERVER) ||
-                (rmInst->instType == Rm_instType_SHARED_SERVER)) {
-                rmInst->u.server.allocators = allocator->nextAllocator;
+    memset((void *)&find, 0, sizeof(find));
+    rm_strncpy(find.resourceName, resourceName, RM_NAME_MAX_CHARS);
+    match = RB_FIND(_Rm_AllocatorTree, allocTree, &find);
+
+    if (match) {
+        resTree = match->resourceRootEntry;
+
+        /* Destroy resource tree */
+        if (resTree) {
+            for (resNode = RB_MIN(_Rm_AllocatorResourceTree, resTree);
+                 resNode != NULL;
+                 resNode = nextResNode) {
+                nextResNode = RB_NEXT(_Rm_AllocatorResourceTree, resTree,
+                                      resNode);
+                RB_REMOVE(_Rm_AllocatorResourceTree, resTree, nextResNode);
+                rmResourceNodeFree(resNode);
             }
-            else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
-                rmInst->u.cd.allocators = allocator->nextAllocator;
-            }              
-        }
-        else {
-            prevAllocator->nextAllocator = allocator->nextAllocator;
-            RM_SS_OBJ_WB(rmInst, prevAllocator, Rm_Allocator);
+            Rm_osalFree((void *)resTree, sizeof(*resTree));
+            match->resourceRootEntry = NULL;
+            RM_SS_OBJ_WB(rmInst, match, Rm_AllocatorNode);
         }
-            
-        /* Destroy tree and return error */
-        treeRoot = allocator->allocatorRootEntry;
-        for (node = RB_MIN(_Rm_AllocatorResourceTree, treeRoot); node != NULL; node = nextNode) {
-               nextNode = RB_NEXT(_Rm_AllocatorResourceTree, treeRoot, node);
-               RB_REMOVE(_Rm_AllocatorResourceTree, treeRoot, nextNode);
-            rmResourceNodeFree(node);
+
+        RB_REMOVE(_Rm_AllocatorTree, allocTree, match);
+        rmAllocatorNodeFree(match);
+        if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+            rmAllocatorTreeWb(allocTree);
         }
-        Rm_osalFree((void *)treeRoot, sizeof(*treeRoot));        
-        Rm_osalFree((void *)allocator, sizeof(*allocator));
     }
     else {
         retVal = RM_ERROR_RES_ALLOCATOR_DOES_NOT_EXIST;
@@ -1752,44 +1767,55 @@ int32_t rmAllocatorDelete(Rm_Handle rmHandle, const char *resourceName)
     return (retVal);
 }
 
-/* FUNCTION PURPOSE: Deletes server allocators
+/* FUNCTION PURPOSE: Deletes allocator tree
  ***********************************************************************
- * DESCRIPTION: Removes all resource nodes for each
- *              resource allocator and then deletes the allocator
- *              itself.  Used to free all memory consumed
- *              by the allocators.
+ * DESCRIPTION: Removes all resource nodes for each allocator node and then
+ *              deletes the allocator tree root.
  */
-void rmAllocatorDeleteResources(Rm_Handle rmHandle)
+void rmAllocatorDeleteTree(Rm_Handle rmHandle)
 {
-    Rm_Inst         *rmInst = (Rm_Inst *)rmHandle;
-    Rm_Allocator    *allocatorList = rmAllocatorGetAllocatorList(rmHandle);
-    Rm_Allocator    *nextAllocator;
-    Rm_ResourceTree *resTree;
-    Rm_ResourceNode *resNode;
-    Rm_ResourceNode *nextResNode;
-
-    while (allocatorList) {
-        RM_SS_OBJ_INV(rmInst, allocatorList, Rm_Allocator);
-        nextAllocator = allocatorList->nextAllocator;
-        resTree = allocatorList->allocatorRootEntry;
-
+    Rm_Inst          *rmInst = (Rm_Inst *)rmHandle;
+    Rm_AllocatorTree *allocTree = rmAllocatorGetTree(rmHandle);
+    Rm_AllocatorNode *allocNode;
+    Rm_AllocatorNode *nextAllocNode;
+    Rm_ResourceTree  *resTree;
+    Rm_ResourceNode  *resNode;
+    Rm_ResourceNode  *nextResNode;
+
+    if (allocTree) {
         if (rmInst->instType == Rm_instType_SHARED_SERVER) {
-            rmResourceTreeInv(resTree);
+            rmAllocatorTreeInv(allocTree);
         }
-        /* Delete each resource node in the allocator */
-        for (resNode = RB_MIN(_Rm_AllocatorResourceTree, resTree); resNode != NULL; resNode = nextResNode) {
-            nextResNode = RB_NEXT(_Rm_AllocatorResourceTree, resTree, resNode);
-            RB_REMOVE(_Rm_AllocatorResourceTree, resTree, resNode);
-            if (resNode->allocationCount) {
-                /* Delete all the owners in the resource's owner list */
-                allocatorResNodeOwnerClear(rmHandle, resNode);
+
+        for (allocNode = RB_MIN(_Rm_AllocatorTree, allocTree);
+             allocNode != NULL;
+             allocNode = nextAllocNode) {
+            nextAllocNode = RB_NEXT(_Rm_AllocatorTree, allocTree, allocNode);
+
+            resTree = allocNode->resourceRootEntry;
+
+            if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+                rmResourceTreeInv(resTree);
             }
-            rmResourceNodeFree(resNode);
-        }        
+            /* Delete each node in the resource tree */
+            for (resNode = RB_MIN(_Rm_AllocatorResourceTree, resTree);
+                 resNode != NULL;
+                 resNode = nextResNode) {
+                nextResNode = RB_NEXT(_Rm_AllocatorResourceTree, resTree,
+                                      resNode);
+                RB_REMOVE(_Rm_AllocatorResourceTree, resTree, resNode);
+                if (resNode->allocationCount) {
+                    /* Delete all the owners in the resource's owner list */
+                    allocatorResNodeOwnerClear(rmHandle, resNode);
+                }
+                rmResourceNodeFree(resNode);
+            }
+            Rm_osalFree((void *)resTree, sizeof(*resTree));
 
-        Rm_osalFree((void *)resTree, sizeof(*resTree));
-        Rm_osalFree((void *)allocatorList, sizeof(*allocatorList));
-        allocatorList = nextAllocator;
+            RB_REMOVE(_Rm_AllocatorTree, allocTree, allocNode);
+            rmAllocatorNodeFree(allocNode);
+        }
+        Rm_osalFree((void *)allocTree, sizeof(*allocTree));
+        RM_SS_OBJ_WB(rmInst, rmInst, Rm_Inst);
     }
 }
-
index 7d53195ee03b6ff7a4ed7733ae2d241cfb131210..8544ae84126d5b64abf48d05281bca0ea287f485 100644 (file)
@@ -837,7 +837,7 @@ int32_t rmPolicyGetResourceOffset(void *policyDtb, char *resourceName)
  *              list specified at the top of the Policy.  Otherwise,
  *              returns error
  */
-int32_t rmPolicyValidatePolicyResourceNames(Rm_Handle rmHandle)
+int32_t rmPolicyValidateResNames(Rm_Handle rmHandle)
 {
     void       *policyDtb = rmPolicyGetPolicy(rmHandle);
     int32_t     nodeOffset;
index 8b2ab4de03148922aa4ce2f786511ab094b21630..bc332090ef835f75d0bfc474893f8a748f96d0fc 100644 (file)
@@ -2,11 +2,11 @@
  *   @file  rm_tree.c
  *
  *   @brief   
- *      Resource Manager Tree Manipulation Source.
+ *      Resource Manager Tree Manipulation.
  *
  *  \par
  *  ============================================================================
- *  @n   (C) Copyright 2012-2014, Texas Instruments, Inc.
+ *  @n   (C) Copyright 2012-2015, Texas Instruments, Inc.
  * 
  *  Redistribution and use in source and binary forms, with or without 
  *  modification, are permitted provided that the following conditions 
@@ -105,11 +105,12 @@ Rm_NameServerNode *rmNameServerNodeNew(Rm_NameServerNodeCfg *nodeCfg)
     newNode = Rm_osalMalloc(sizeof(Rm_NameServerNode));
     if (newNode) {
         rm_strncpy(newNode->objName, nodeCfg->objName, RM_NAME_MAX_CHARS);
-        rm_strncpy(newNode->resourceName, nodeCfg->resourceName, RM_NAME_MAX_CHARS); 
+        rm_strncpy(newNode->resourceName, nodeCfg->resourceName,
+                   RM_NAME_MAX_CHARS);
         newNode->resourceBase = nodeCfg->resourceBase;
         newNode->resourceLength = nodeCfg->resourceLength;
     }
-    
+
     return(newNode);
 }
 
@@ -120,7 +121,7 @@ Rm_NameServerNode *rmNameServerNodeNew(Rm_NameServerNodeCfg *nodeCfg)
 void rmNameServerNodeFree(Rm_NameServerNode *node)
 {
     if (node) {
-        Rm_osalFree((void *)node, sizeof(Rm_NameServerNode));
+        Rm_osalFree((void *)node, sizeof(*node));
     }
 }
 
@@ -148,7 +149,8 @@ void rmNameServerNodeInv(Rm_NameServerNode *node)
 }
 
 /* Generate the NameServer tree manipulation functions */
-RB_GENERATE(_Rm_NameServerTree, _Rm_NameServerNode, linkage, rmNameServerNodeCompare, rmNameServerNodeInv);
+RB_GENERATE(_Rm_NameServerTree, _Rm_NameServerNode, linkage,
+            rmNameServerNodeCompare, rmNameServerNodeInv);
 
 /**********************************************************************
  *************** Policy Valid Instance Tree Functions *****************
@@ -203,11 +205,11 @@ Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(char *instName)
     Rm_PolicyValidInstNode *newNode = NULL;
 
     newNode = Rm_osalMalloc(sizeof(Rm_PolicyValidInstNode));
-    
+
     rm_strncpy(newNode->name, instName, RM_NAME_MAX_CHARS);
     newNode->allocRefCount = 0;
     newNode->deletePending = RM_FALSE;
-    
+
     return(newNode);
 }
 
@@ -218,10 +220,10 @@ Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(char *instName)
  */
 void rmPolicyValidInstNodeFree(Rm_PolicyValidInstNode *node)
 {
- /* TODO: Add allocation reference count check when reference count addition/subtraction
-  *       bugs are resolved */
+ /* TODO: Add allocation reference count check when reference count
+  *       addition/subtraction bugs are resolved */
  //   if (node->allocRefCount == 0) {
-        Rm_osalFree((void *)node, sizeof(Rm_PolicyValidInstNode));
+        Rm_osalFree((void *)node, sizeof(*node));
  //   }
 }
 
@@ -233,7 +235,8 @@ void rmPolicyValidInstNodeFree(Rm_PolicyValidInstNode *node)
  *              node1 name = node2 name --> return 0
  *              node1 name > node2 name --> return > 0
  */
-int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1, Rm_PolicyValidInstNode *node2)
+int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1,
+                                 Rm_PolicyValidInstNode *node2)
 {
     return(strncmp(node1->name, node2->name, RM_NAME_MAX_CHARS));
 }
@@ -249,7 +252,8 @@ void rmPolicyValidInstNodeInv(Rm_PolicyValidInstNode *node)
 }
 
 /* Generate the valid instance tree manipulation functions */
-RB_GENERATE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage, rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv);
+RB_GENERATE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage,
+            rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv);
 
 /**********************************************************************
  ***************** Allocator Resource Tree Functions ******************
@@ -299,7 +303,8 @@ void rmResourceTreeWb(Rm_ResourceTree *treeRoot)
  * DESCRIPTION: Creates a new resource tree node with the
  *              specified name resource values.
  */
-Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase, uint32_t resourceLength)
+Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase, 
+                                   uint32_t resourceLength)
 {
     Rm_ResourceNode *newNode = NULL;
 
@@ -322,7 +327,7 @@ Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase, uint32_t resourceLengt
 void rmResourceNodeFree(Rm_ResourceNode *node)
 {
     if (node->allocationCount == 0) {
-        Rm_osalFree((void *)node, sizeof(Rm_ResourceNode));
+        Rm_osalFree((void *)node, sizeof(*node));
     }
 }
 
@@ -344,18 +349,20 @@ int rmResourceNodeCompare(Rm_ResourceNode *node1, Rm_ResourceNode *node2)
     uint32_t node2End = node2->base + node2->length - 1;
 
     if (node1End < node2->base) {
-        /* End of node1 range is less than the start of node2's range.  Return a negative
-         * value */
-        return (-1);
+        /* End of node1 range is less than the start of node2's range.  Return
+         * a negative value */
+        return(-1);
     }
     else if (node1->base > node2End) {
-        /* Start of node1 range is after end of node2's range.  Return a positive value */
-        return (1);
+        /* Start of node1 range is after end of node2's range.  Return a
+         * positive value */
+        return(1);
     }
     else {
-        /* If neither of the latter conditions were satisfied there is some overlap between
-         * node1 and node2.  Return 0 since the application must handle this overlap. */
-        return (0);
+        /* If neither of the latter conditions were satisfied there is some
+         * overlap between node1 and node2.  Return 0 since the application
+         * must handle this overlap. */
+        return(0);
     }
 }
 
@@ -370,5 +377,101 @@ void rmResourceNodeInv(Rm_ResourceNode *node)
 }
 
 /* Generate the resource tree manipulation functions */
-RB_GENERATE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage, rmResourceNodeCompare, rmResourceNodeInv)
+RB_GENERATE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage,
+            rmResourceNodeCompare, rmResourceNodeInv);
+
+/**********************************************************************
+ ********************* Allocator Tree Functions ***********************
+ **********************************************************************/
+
+/* FUNCTION PURPOSE: Invalidates an entire allocator tree
+ ***********************************************************************
+ * DESCRIPTION: Uses the cache handling versions of the RB tree
+ *              macros to walk and invalidate an entire allocator tree.
+ */
+void rmAllocatorTreeInv(Rm_AllocatorTree *treeRoot)
+{
+    Rm_AllocatorNode *node;
+
+    /* Invalidate the tree root */
+    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(Rm_AllocatorTree));
+    /* Walk the tree which will invalidate each element in the tree */
+    node = RB_MIN_CACHED(_Rm_AllocatorTree, treeRoot);
+    while (node) {
+        node = RB_NEXT_CACHED(_Rm_AllocatorTree, treeRoot, node);
+    }
+}
+
+/* FUNCTION PURPOSE: Writebacks an entire allocator tree
+ ***********************************************************************
+ * DESCRIPTION: Walks the entire allocator tree writing back
+ *              each element to shared memory
+ */
+void rmAllocatorTreeWb(Rm_AllocatorTree *treeRoot)
+{
+    Rm_AllocatorNode *node;
+
+    /* Writeback each element in the tree */
+    node = RB_MIN(_Rm_AllocatorTree, treeRoot);
+    do {
+        Rm_osalEndMemAccess((void *)node, sizeof(Rm_AllocatorNode));
+        node = RB_NEXT(_Rm_AllocatorTree, treeRoot, node);
+    } while (node);
+
+    /* Writeback the tree root */
+    Rm_osalEndMemAccess((void *)treeRoot, sizeof(Rm_AllocatorTree));
+}
+
+/* FUNCTION PURPOSE: Creates a new allocator node
+ ***********************************************************************
+ * DESCRIPTION: Creates a new allocator node with the
+ *              specified resource name.
+ */
+Rm_AllocatorNode *rmAllocatorNodeNew(const char *resourceName)
+{
+    Rm_AllocatorNode *newNode = NULL;
+
+    newNode = Rm_osalMalloc(sizeof(Rm_AllocatorNode));
+
+    rm_strncpy(newNode->resourceName, resourceName, RM_NAME_MAX_CHARS);
+    newNode->resourceRootEntry = NULL;
+
+    return(newNode);
+}
+
+/* FUNCTION PURPOSE: Deletes an allocator node
+ ***********************************************************************
+ * DESCRIPTION: Deletes the specified allocator node.
+ */
+void rmAllocatorNodeFree(Rm_AllocatorNode *node)
+{
+    Rm_osalFree((void *)node, sizeof(*node));
+}
+
+/* FUNCTION PURPOSE: Compares two allocator nodes
+ ***********************************************************************
+ * DESCRIPTION: Returns the result of a comparison of two
+ *              allocator node resource names.
+ *              node1 name < node2 name --> return < 0
+ *              node1 name = node2 name --> return 0
+ *              node1 name > node2 name --> return > 0
+ */
+int rmAllocatorNodeCompare(Rm_AllocatorNode *node1, Rm_AllocatorNode *node2)
+{
+    return(strncmp(node1->resourceName, node2->resourceName,
+                   RM_NAME_MAX_CHARS));
+}
+
+/* FUNCTION PURPOSE: Invalidates an allocator tree node
+ ***********************************************************************
+ * DESCRIPTION: Uses RM OSAL layer to invalidate the specified
+ *              allocator tree node.
+ */
+void rmAllocatorNodeInv(Rm_AllocatorNode *node)
+{
+    Rm_osalBeginMemAccess((void *)node, sizeof(Rm_AllocatorNode));
+}
 
+/* Generate the allocator tree manipulation functions */
+RB_GENERATE(_Rm_AllocatorTree, _Rm_AllocatorNode, linkage,
+            rmAllocatorNodeCompare, rmAllocatorNodeInv);