Added policy tree elements
authorJustin Sobota <jsobota@ti.com>
Tue, 26 May 2015 15:15:10 +0000 (11:15 -0400)
committerJustin Sobota <jsobota@ti.com>
Tue, 26 May 2015 15:15:10 +0000 (11:15 -0400)
include/rm_dtb_utilloc.h
include/rm_loc.h
include/rm_policyloc.h
include/rm_treeloc.h
src/rm.c
src/rm_allocator.c
src/rm_dtb_util.c
src/rm_policy.c
src/rm_tree.c

index 7a04c37be0e5bfe812429f463e617723fd72ee79..a4029c035c711ce6d5540bb30b9a8c2f2804178d 100644 (file)
@@ -192,13 +192,15 @@ void rmDtbUtilResFreeNsAssignmentList(Rm_NsAssignment *nsAssignmentList);
  **********************************************************************/
 
 Rm_PolicyPropType rmDtbUtilPolicyGetPropertyType(const char *propertyName);
-Rm_PolicyAssignment *rmDtbUtilPolicyExtractAssignments(const void *dtbDataPtr, int32_t dtbDataLen);
+Rm_PolicyAssignment *rmDtbUtilPolicyExtractAssignments(const void *dtbDataPtr,
+                                                       int32_t dtbDataLen);
 void rmDtbUtilPolicyFreeAssignments(Rm_PolicyAssignment *assignmentList);
 Rm_ResourceValue *rmDtbUtilPolicyExtractCdAllocationSizes(const void *dtbDataPtr, int32_t dtbDataLen);
 void rmDtbUtilPolicyFreeCdAllocationSizes(Rm_ResourceValue *allocationSizeList);
 Rm_ResourceValue *rmDtbUtilPolicyExtractResourceAlignments(const void *dtbDataPtr, int32_t dtbDataLen);
 void rmDtbUtilPolicyFreeResourceAlignments (Rm_ResourceValue *alignmentList);
-Rm_PolicyValidInst *rmDtbUtilPolicyExtractValidInstances(const void *dtbDataPtr, int32_t dtbDataLen, 
+Rm_PolicyValidInst *rmDtbUtilPolicyExtractValidInstances(const void *dtbDataPtr,
+                                                         int32_t dtbDataLen,
                                                          int32_t *result);
 void rmDtbUtilPolicyFreeValidInstances (Rm_PolicyValidInst *validInstList);
 
index 703cdee1690d40850fde0a52461fcecf74a44517..9a8bc07566705dea8099a40c3e8cdb96487d38f3 100644 (file)
@@ -99,8 +99,8 @@ typedef struct {
     void                   *globalPolicy;
     /* Policy size in bytes */
     uint32_t                policySize;
-    /* Pointer to root entry of the global policy valid instance tree */
-    Rm_PolicyValidInstTree *globalValidInstTree;
+    /* Pointer to root entry of valid instance tree */
+    Rm_PolicyValidInstTree *validInstTree;
     /* Pointer to allocator tree */
     Rm_AllocatorTree       *allocatorTree;
     /* Pointer to the root entry of the NameServer */
@@ -111,9 +111,9 @@ typedef struct {
 typedef struct {
     /* Pointer to the cd policy if provided */
     void                   *cdPolicy;
-    /* Pointer to the root entry of the valid instance tree
-     * extracted from the cd policy */
-    Rm_PolicyValidInstTree *cdValidInstTree;
+    /* Pointer to root entry of valid instance tree
+     * extracted from cd policy */
+    Rm_PolicyValidInstTree *validInstTree;
     /* Pointer to allocator tree */
     Rm_AllocatorTree       *allocatorTree;
 } Rm_ClientDelegateInstData;
index 04a1c9b80da70f4bdfada826d5846aa2c47605fe..ca03eae4114533a71ce3c11b91ccb9c459b3bfd3 100644 (file)
@@ -159,7 +159,9 @@ uint32_t rmPolicyGetResourceCdAllocSize(void *policyDtb, int32_t resourceOffset)
 int32_t rmPolicyGetResourceOffset(void *policyDtb, char *resourceName);
 int32_t rmPolicyValidateResNames(Rm_Handle rmHandle);
 int32_t rmPolicyValidatePolicy(Rm_Handle rmHandle);
-Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle, int addLinux, int32_t *result);
+Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle,
+                                                    int addLinux,
+                                                    int32_t *result);
 void rmPolicyFreeValidInstTree(Rm_Handle rmHandle);
 
 #ifdef __cplusplus
index 60e3eb66f68c9f061a1ac39662ca2c5d3fcd51fb..94d63fa703a26843331574383613576e2fc8bf27 100644 (file)
@@ -101,7 +101,9 @@ typedef struct _Rm_PolicyValidInstNode {
     /* TRUE: Delete this valid instance node once the allocRefCount
      *       reaches zero
      * FALSE: Do not delete */
-    int8_t                            deletePending;
+    int32_t                           deletePending;
+    /* Instance index used in policy permission assignments */
+    int32_t                           instIdx;
 } Rm_PolicyValidInstNode;
 
 /* Valid instance tree root entry type definition */
@@ -140,6 +142,25 @@ typedef struct _Rm_ResourceNode {
 /* Resource tree root entry type definition */
 typedef RB_HEAD(_Rm_AllocatorResourceTree, _Rm_ResourceNode) Rm_ResourceTree;
 
+/* Policy node */
+typedef struct _Rm_PolicyNode {
+    /* Tree algorithm data structure */
+    RB_ENTRY(_Rm_PolicyNode)  linkage;
+    /* Policy base value */
+    uint32_t                  base;
+    /* Policy length value.  With base this node covers a policy's values
+     * from base to base+length-1 */
+    uint32_t                  len;
+    /* Pointer to array containing permission bitfields for the node's 
+     * resource range */
+    uint32_t                 *perms;
+    /* Size of permissions array in bytes pointed to by the perms pointer */
+    uint32_t                  permsLen;
+} Rm_PolicyNode;
+
+/* Policy tree root entry type definition */
+typedef RB_HEAD(_Rm_AllocatorPolicyTree, _Rm_PolicyNode) Rm_PolicyTree;
+
 /* Allocator node */
 typedef struct _Rm_AllocatorNode {
     /* Tree algorithm data structure */
@@ -147,8 +168,10 @@ typedef struct _Rm_AllocatorNode {
     /* 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;
+    /* Pointer to root entry of allocator's resource tree */
+    Rm_ResourceTree             *resourceRoot;
+    /* Pointer to root entry of allocator's policy tree */
+    Rm_PolicyTree               *policyRoot;
 } Rm_AllocatorNode;
 
 /* Allocator tree root entry type definition */
@@ -168,7 +191,8 @@ void rmNameServerNodeInv(Rm_NameServerNode *node);
 
 void rmPolicyValidInstTreeInv(Rm_PolicyValidInstTree *treeRoot);
 void rmPolicyValidInstTreeWb(Rm_PolicyValidInstTree *treeRoot);
-Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(char *instName);
+Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(const char *instName,
+                                                 const int32_t instIdx);
 void rmPolicyValidInstNodeFree(Rm_PolicyValidInstNode *node);
 int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1,
                                  Rm_PolicyValidInstNode *node2);
@@ -182,6 +206,13 @@ void rmResourceNodeFree(Rm_ResourceNode *node);
 int rmResourceNodeCompare(Rm_ResourceNode *node1, Rm_ResourceNode *node2);
 void rmResourceNodeInv(Rm_ResourceNode *node);
 
+void rmPolicyTreeInv(Rm_PolicyTree *treeRoot);
+void rmPolicyTreeWb(Rm_PolicyTree *treeRoot);
+Rm_PolicyNode *rmPolicyNodeNew(uint32_t resourceBase, uint32_t resourceLength);
+void rmPolicyNodeFree(Rm_PolicyNode *node);
+int rmPolicyNodeCompare(Rm_PolicyNode *node1, Rm_PolicyNode *node2);
+void rmPolicyNodeInv(Rm_PolicyNode *node);
+
 void rmAllocatorTreeInv(Rm_AllocatorTree *treeRoot);
 void rmAllocatorTreeWb(Rm_AllocatorTree *treeRoot);
 Rm_AllocatorNode *rmAllocatorNodeNew(const char *resourceName);
@@ -199,6 +230,8 @@ RB_PROTOTYPE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage,
              rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv)
 RB_PROTOTYPE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage,
              rmResourceNodeCompare, rmResourceNodeInv)
+RB_PROTOTYPE(_Rm_AllocatorPolicyTree, _Rm_PolicyNode, linkage,
+             rmPolicyNodeCompare, rmPolicyNodeInv)
 RB_PROTOTYPE(_Rm_AllocatorTree, _Rm_AllocatorNode, linkage,
              rmAllocatorNodeCompare, rmAllocatorNodeInv)
 
index 78e0f8bbbb720c6e892cefa3a4291abf178416e0..b96e4dd0abbe2be3658ef808d6dcfdafaeb93f60 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -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->resourceRootEntry, treeNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, treeNode);
                     }
                     else {
                         Rm_ResourceRange resRange;
@@ -933,7 +933,7 @@ static void cdProcess (Rm_Inst *rmInst, Rm_Transaction *transaction)
                     /* Delete the allocator's resource tree if there are no
                      * nodes left in the resource tree */
                     if (RB_MIN(_Rm_AllocatorResourceTree,
-                               allocator->resourceRootEntry) == NULL) {
+                               allocator->resourceRoot) == NULL) {
                         rmAllocatorDelete((Rm_Handle)rmInst,
                                           transaction->resourceInfo.name);
                     }
@@ -1295,7 +1295,7 @@ int32_t Rm_resourceStatus(Rm_Handle rmHandle, int printResources)
                 Rm_osalLog("Resource: %s\n", allocator->resourceName);
             }
 
-            treeRoot = allocator->resourceRootEntry;
+            treeRoot = allocator->resourceRoot;
             if (rmInst->instType == Rm_instType_SHARED_SERVER) {
                 rmResourceTreeInv(treeRoot);
             }
@@ -1464,7 +1464,7 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
     void     *key;
 
     *result = RM_OK;
-    
+
     if ((initCfg->instName == NULL) ||
         ((strlen(initCfg->instName) + 1) > RM_NAME_MAX_CHARS)) {
         *result = RM_ERROR_INVALID_INST_NAME;
@@ -1517,13 +1517,13 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
 
         /* Create valid instance list from policy.  Must be done prior to parsing
          * GRL so that Linux resources can be reserved correctly */
-        rmInst->u.server.globalValidInstTree = rmPolicyCreateValidInstTree((Rm_Handle)rmInst, addLinux, result);
+        rmInst->u.server.validInstTree = rmPolicyCreateValidInstTree((Rm_Handle)rmInst, addLinux, result);
         if (*result == RM_OK) {
             *result = rmPolicyValidatePolicy((Rm_Handle)rmInst);
         }
         
         if (*result != RM_OK) {
-            if (rmInst->u.server.globalValidInstTree) {
+            if (rmInst->u.server.validInstTree) {
                 rmPolicyFreeValidInstTree((Rm_Handle)rmInst);
             }
             goto errorExit;
@@ -1544,7 +1544,7 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
             if (*result != RM_OK) {
                 rmAllocatorDeleteTree((Rm_Handle)rmInst);
                 rmNameServerDelete((Rm_Handle)rmInst);
-                if (rmInst->u.server.globalValidInstTree) {
+                if (rmInst->u.server.validInstTree) {
                     rmPolicyFreeValidInstTree((Rm_Handle)rmInst);
                 }
                 goto errorExit;
@@ -1557,20 +1557,20 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
         }
 
         rmInst->u.cd.cdPolicy = initCfg->instCfg.cdCfg.cdPolicy;
-        rmInst->u.cd.cdValidInstTree = rmPolicyCreateValidInstTree((Rm_Handle)rmInst, addLinux, result);
+        rmInst->u.cd.validInstTree = rmPolicyCreateValidInstTree((Rm_Handle)rmInst, addLinux, result);
         if (*result == RM_OK) {
             *result = rmPolicyValidatePolicy((Rm_Handle)rmInst);
         }
 
         if (*result != RM_OK) {
-            if (rmInst->u.cd.cdValidInstTree) {
+            if (rmInst->u.cd.validInstTree) {
                 rmPolicyFreeValidInstTree((Rm_Handle)rmInst);
             }
             goto errorExit;
         }
 
         if ((*result = rmAllocatorInitTree((Rm_Handle) rmInst)) != RM_OK) {
-            if (rmInst->u.cd.cdValidInstTree) {
+            if (rmInst->u.cd.validInstTree) {
                 rmPolicyFreeValidInstTree((Rm_Handle)rmInst);
             }
             goto errorExit;
@@ -1578,9 +1578,8 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
 
         /* Remove once CD instance is stable - tracked by SDOCM00100797 */
         *result = RM_WARNING_CD_INSTANCE_NOT_STABLE;
-    }
-    else if (rmInst->instType == Rm_instType_CLIENT) {
-        if (initCfg->instCfg.clientCfg.staticPolicy) { 
+    } else if (rmInst->instType == Rm_instType_CLIENT) {
+        if (initCfg->instCfg.clientCfg.staticPolicy) {
             rmInst->u.client.staticPolicy = initCfg->instCfg.clientCfg.staticPolicy;
             rmInst->u.client.staticValidInstTree = rmPolicyCreateValidInstTree((Rm_Handle)rmInst, addLinux, result);        
             if (*result == RM_OK) {
@@ -1594,8 +1593,7 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
                 goto errorExit;
             }
         }
-    }
-    else if (rmInst->instType == Rm_instType_SHARED_CLIENT) {
+    } else if (rmInst->instType == Rm_instType_SHARED_CLIENT) {
         if (initCfg->instCfg.sharedClientCfg.sharedServerHandle) {
             rmInst->u.sharedClient.sharedServerHandle = initCfg->instCfg.sharedClientCfg.sharedServerHandle;
             /* Invalidate the Shared server instance structure on this core to get the latest
@@ -1607,15 +1605,13 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
                 *result = RM_ERROR_INVALID_SHARED_SERVER_HANDLE;
                 Rm_osalCsExit(key);
                 goto errorExit;
-            }
-            else {
+            } else {
                 /* Invalidate the policy */
                 Rm_osalBeginMemAccess((void *)sharedServerInst->u.server.globalPolicy, 
                                       sharedServerInst->u.server.policySize);
             }
             Rm_osalCsExit(key);
-        }
-        else {
+        } else {
             *result = RM_ERROR_INVALID_SHARED_SERVER_HANDLE;
             goto errorExit;
         }
@@ -1625,8 +1621,7 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
         /* Writeback the instance and policy for other cores */
         Rm_osalEndMemAccess ((void *)rmInst, sizeof(Rm_Inst));
         Rm_osalEndMemAccess ((void *)rmInst->u.server.globalPolicy, rmInst->u.server.policySize);
-    }
-    else if (rmInst->instType != Rm_instType_SHARED_CLIENT) {
+    } else if (rmInst->instType != Rm_instType_SHARED_CLIENT) {
         /* Create the instance's task blocking mechanism */
         rmInst->blockHandle = Rm_osalTaskBlockCreate();
     }
index 37c46b5c8c303329390860cd0a27ba77cade30c3..f69e0ac32962bd0a99843da19466814dac739472 100644 (file)
@@ -392,12 +392,13 @@ static int32_t allocatorStatus(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
     memset((void *)&findNode, 0, sizeof(findNode));
     findNode.base = opInfo->resourceInfo->base;
     findNode.length = opInfo->resourceInfo->length;
-    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
+    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRoot,
+                           &findNode);
 
     if (matchingNode) {
         matchingEnd = matchingNode->base + matchingNode->length - 1;
         findEnd = findNode.base + findNode.length - 1;
-        if ((findNode.base >= matchingNode->base) && (findEnd <= matchingEnd)) {        
+        if ((findNode.base >= matchingNode->base) && (findEnd <= matchingEnd)) {
             opInfo->resourceInfo->ownerCount = matchingNode->allocationCount;
             opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, matchingNode,
                                                                                   opInfo->serviceSrcInstNode);            
@@ -454,7 +455,7 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle,
 
     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->resourceRootEntry);
+        matchingNode = RB_MIN(_Rm_AllocatorResourceTree, allocator->resourceRoot);
         opInfo->resourceInfo->base = matchingNode->base;
     }
     else {
@@ -486,7 +487,7 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle,
     policyCheckCfg.resourceOffset = resourcePolicy;
     
     do {
-        matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
+        matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRoot, &findNode);
         
         if (matchingNode) {
             matchingEnd = matchingNode->base + matchingNode->length - 1;
@@ -532,23 +533,26 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle,
                 }
 
                 if (nodePassesPolicy) {
-                    /* Initialize indexer to be first resource value that alignment satisfies */
+                    /* Initialize indexer to be first resource value that
+                     * alignment satisfies */
                     rangeIndex = findNode.base;
                     if (rangeIndex % opInfo->resourceInfo->alignment) {
                         rangeIndex += (opInfo->resourceInfo->alignment -
-                                      (rangeIndex % opInfo->resourceInfo->alignment));
+                                      (rangeIndex %
+                                       opInfo->resourceInfo->alignment));
                     }
-                    
-                    if ((rangeIndex + opInfo->resourceInfo->length - 1) <= matchingEnd) {
-                        /* Block of unallocated resources within matchingNode that satisfies
-                         * allocate requirements */
+
+                    if ((rangeIndex + opInfo->resourceInfo->length - 1) <=
+                        matchingEnd) {
+                        /* Block of unallocated resources within matchingNode
+                         * that satisfies allocate requirements */
                         opInfo->resourceInfo->base = rangeIndex;
                         resourceFound = RM_TRUE;
                         retVal = RM_SERVICE_PROCESSING;
-                    }     
+                    }
                 }
             }
-            
+
             if (!resourceFound) {
                 /* Check next resource node for available resources */
                 if (findNode.base < matchingNode->base) {
@@ -560,7 +564,9 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle,
                     }
                     else {
                         /* Matching node allocated, move to next node */
-                        if ((nextNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode))) {
+                        if ((nextNode = RB_NEXT(_Rm_AllocatorResourceTree,
+                                                allocator->resourceRoot,
+                                                matchingNode))) {
                             findNode.base = nextNode->base;
                         }
                         else {
@@ -622,7 +628,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
     memset((void *)&findNode, 0, sizeof(findNode));
     findNode.base = opInfo->resourceInfo->base;
     findNode.length = opInfo->resourceInfo->length;
-    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
+    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRoot, &findNode);
 
     /* Prepare privilege checks */
     memset((void *)&policyCheckCfg, 0, sizeof(policyCheckCfg)); 
@@ -698,19 +704,19 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                      *   |<--left node-->||<--matched  node-->||<--right node-->| => existing node
                      *                    |<--alloc request-->|  => requested resources
                      */                     
-                    leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                    rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                    RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                    leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                    rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                    RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
                     allocatorResNodeOwnerAdd(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
 
                     if (leftNode && allocatorResNodeOwnerCompare(rmHandle, leftNode, matchingNode) &&
                         allocatorResNodeBoundaryCompare(leftNode, matchingNode)) {
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                         combineLeft = RM_TRUE;
                     }
                     if (rightNode && allocatorResNodeOwnerCompare(rmHandle, rightNode, matchingNode) &&
                         allocatorResNodeBoundaryCompare(rightNode, matchingNode)) {
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                         combineRight = RM_TRUE;
                     }
 
@@ -732,7 +738,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                         allocatorResNodeOwnerClear(rmHandle, leftNode);
                         rmResourceNodeFree(leftNode);
                         if (rightNode) {
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);  
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);  
                         }
                     }
                     else if (combineRight) {
@@ -742,21 +748,21 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                         allocatorResNodeOwnerClear(rmHandle, rightNode);
                         rmResourceNodeFree(rightNode);
                         if (leftNode) {
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                         }
                     }
                     else {
                         /* No combine. */
                         if (leftNode) {
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                         }
                         if (rightNode) {
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                         }
                     }
 
                     /* Always reinsert matchingNode */                
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
                     
                     /* Matching node contains new reference count after alloc.  Return new owner count
                      * and originating instance allocation reference count. */
@@ -771,7 +777,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                      * |<----------matched node---------->|
                      *        |<---alloc request--->|
                      */ 
-                    RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                    RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
                     leftNode = rmResourceNodeNew(matchingNode->base, findNode.base - matchingNode->base);
                     allocatorResNodeOwnerCopy(rmHandle, leftNode, matchingNode);
                     rightNode = rmResourceNodeNew(findNode.base + findNode.length, matchingEnd - findEnd);
@@ -782,9 +788,9 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                     allocatorResNodeOwnerAdd(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
 
                     /* Insert all the nodes */
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                     
                     /* Matching node contains new reference count after alloc.  Return new owner count
                      * and originating instance allocation reference count. */
@@ -800,14 +806,14 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                          * |<---left node (alloc'd)--->||<----------matched node---------->|
                          *                              |<---findNode (alloc req)--->|
                          */                         
-                        leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, 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->resourceRootEntry, leftNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                             /* Combine leftNode and findNode */
                             leftNode->length += findNode.length;
                         }
@@ -820,7 +826,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                         matchingNode->base = findNode.base + findNode.length;
                         matchingNode->length = matchingEnd - findEnd;  
 
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                         /* Left node contains new reference count after alloc.  Return new owner count
                          * and originating instance allocation reference count. */
                         opInfo->resourceInfo->ownerCount = leftNode->allocationCount;
@@ -834,14 +840,14 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                          * |<----------matched node---------->||<---right node (alloc'd)--->|
                          *       |<---findNode (alloc req)--->|
                          */                        
-                        rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, 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->resourceRootEntry, rightNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                             /* Combine rightNode and findNode */
                             rightNode->base = findNode.base;
                             rightNode->length += findNode.length;
@@ -854,7 +860,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                         /* Account for rightNode in matchingNode */
                         matchingNode->length -= findNode.length;  
 
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                         /* Right node contains new reference count after alloc.  Return new owner count
                          * and originating instance allocation reference count. */
                         opInfo->resourceInfo->ownerCount = rightNode->allocationCount;
@@ -863,7 +869,7 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle,
                     }
                     /* Remove allocating instance from leftover matchingNode */
                     allocatorResNodeOwnerDelete(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
-                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                    RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
                 }
                 retVal = RM_SERVICE_APPROVED;
             }
@@ -907,7 +913,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
     memset((void *)&findNode, 0, sizeof(findNode));
     findNode.base = opInfo->resourceInfo->base;
     findNode.length = opInfo->resourceInfo->length;
-    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, &findNode);
+    matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRoot, &findNode);
 
     if (matchingNode) {
         findEnd = findNode.base + findNode.length - 1;
@@ -924,19 +930,19 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
                          * |<--left node-->||<---matched node--->||<--right node-->|
                          *                  |<---free request--->|
                          */ 
-                        leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                        rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                        rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
                         allocatorResNodeOwnerDelete(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
 
                         if (leftNode && allocatorResNodeOwnerCompare(rmHandle, leftNode, matchingNode) &&
                             allocatorResNodeBoundaryCompare(leftNode, matchingNode)) {
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                             combineLeft = RM_TRUE;
                         }
                         if (rightNode && allocatorResNodeOwnerCompare(rmHandle, rightNode, matchingNode) &&
                             allocatorResNodeBoundaryCompare(rightNode, matchingNode)) {
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                             combineRight = RM_TRUE;
                         }
 
@@ -958,7 +964,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
                             allocatorResNodeOwnerClear(rmHandle, leftNode);
                             rmResourceNodeFree(leftNode);
                             if (rightNode) {
-                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode); 
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode); 
                             }
                         }
                         else if (combineRight) {
@@ -968,21 +974,21 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
                             allocatorResNodeOwnerClear(rmHandle, rightNode);
                             rmResourceNodeFree(rightNode);
                             if (leftNode) {
-                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                             }
                         }
                         else {
                             /* No combine. */
                             if (leftNode) {
-                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                             }
                             if (rightNode) {
-                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
+                                RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                             }
                         }
 
                         /* Always reinsert matchingNode */
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
                         
                         /* Matching node is what remains after free.  Return remaining owner count
                          * and originating instance allocation reference count. */
@@ -1000,22 +1006,22 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
                          * 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->resourceRootEntry, matchingNode);
+                        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, 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->resourceRootEntry, leftNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                         
                         rightNode = rmResourceNodeNew(findNode.base + findNode.length, matchingEnd - findEnd);
                         allocatorResNodeOwnerCopy(rmHandle, rightNode, matchingNode);
                         allocatorResNodeOwnerAdd(rmHandle, rightNode, opInfo->serviceSrcInstNode);
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
 
                         matchingNode->base = findNode.base;                                    
                         matchingNode->length = findNode.length;
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
                         
                         /* Matching node is what remains after free.  Return remaining owner count
                          * and originating instance allocation reference count. */
@@ -1032,14 +1038,14 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
                              *                           |<---findNode (free req)--->|
                              */ 
 
-                            leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                            leftNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, 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->resourceRootEntry, leftNode);
+                                RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                                 /* Combine leftNode and findNode */
                                 leftNode->length += findNode.length;
                             }
@@ -1051,7 +1057,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
                             /* Remove leftNode range from matchingNode */
                             matchingNode->base = findNode.base + findNode.length;
                             matchingNode->length = matchingEnd - findEnd;  
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, leftNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, leftNode);
                             
                             /* Left node is what remains after free.  Return remaining owner count
                              * and originating instance allocation reference count. */
@@ -1067,14 +1073,14 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
                              *        |<---findNode (free req)--->|
                              */ 
                             
-                            rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
-                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode); 
+                            rightNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
+                            RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, 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->resourceRootEntry, rightNode);
+                                RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                                 /* Combine rightNode and findNode */
                                 rightNode->base = findNode.base;
                                 rightNode->length += findNode.length;
@@ -1086,7 +1092,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
 
                             /* Remove rightNode range from matchingNode */
                             matchingNode->length -= findNode.length;  
-                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, rightNode);
+                            RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, rightNode);
                             
                             /* Right node is what remains after free.  Return remaining owner count
                              * and originating instance allocation reference count. */
@@ -1097,7 +1103,7 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
 
                         /* Add freeing instance back into matchingNode allocations */
                         allocatorResNodeOwnerAdd(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
-                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+                        RB_INSERT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
                     }
                     retVal = RM_SERVICE_APPROVED;
                 }
@@ -1396,7 +1402,7 @@ int32_t rmAllocatorCreate(Rm_Handle rmHandle, const char *resourceName,
             rmResourceTreeWb(resTree);
         }
 
-        newAllocNode->resourceRootEntry = resTree;
+        newAllocNode->resourceRoot = resTree;
         RM_SS_OBJ_WB(rmInst, newAllocNode, Rm_AllocatorNode);
 
         RB_INSERT(_Rm_AllocatorTree, allocTree, newAllocNode);
@@ -1485,7 +1491,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->resourceRootEntry, &findNode);
+        matchingNode = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRoot, &findNode);
 
         if (matchingNode) {
             /* Node can be freed back to Server from CD if:
@@ -1501,13 +1507,13 @@ int rmAllocatorGetNodeLocalization(Rm_Handle rmHandle, char *resourceName,
             }
 
             /* Check left neighbor */
-            neighborNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+            neighborNode = RB_PREV(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
             if (neighborNode && allocatorResNodeBoundaryCompare(neighborNode, matchingNode)) {
                 goto exitLocalization; 
             }
 
             /* Check right neighbor */
-            neighborNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRootEntry, matchingNode);
+            neighborNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->resourceRoot, matchingNode);
             if (neighborNode && allocatorResNodeBoundaryCompare(neighborNode, matchingNode)) {
                 goto exitLocalization; 
             }
@@ -1543,7 +1549,7 @@ int32_t rmAllocatorOperation(Rm_Handle rmHandle, Rm_AllocatorOpInfo *opInfo)
     
     if ((resourceOffsetInPolicy > 0) && allocator) {
         if (rmInst->instType == Rm_instType_SHARED_SERVER) {
-            rmResourceTreeInv(allocator->resourceRootEntry);
+            rmResourceTreeInv(allocator->resourceRoot);
         }
 
         if (opInfo->operation == Rm_allocatorOp_GET_STATUS) {
@@ -1564,7 +1570,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->resourceRootEntry);
+            rmResourceTreeWb(allocator->resourceRoot);
         }        
     }
     else {
@@ -1700,15 +1706,15 @@ void rmAllocatorDeleteResNode(Rm_Handle rmHandle, Rm_AllocatorNode *allocator,
     memset((void *)&find, 0, sizeof(find));
     find.base = resBase;
     find.length = resLen;
-    match = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRootEntry,
+    match = RB_FIND(_Rm_AllocatorResourceTree, allocator->resourceRoot,
                     &find);
     
     if (match) {
-        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRootEntry,
+        RB_REMOVE(_Rm_AllocatorResourceTree, allocator->resourceRoot,
                   match);
         rmResourceNodeFree(match);
         if (rmInst->instType == Rm_instType_SHARED_SERVER) {
-            rmResourceTreeWb(allocator->resourceRootEntry);
+            rmResourceTreeWb(allocator->resourceRoot);
         }
     }
 }
@@ -1738,7 +1744,7 @@ int32_t rmAllocatorDelete(Rm_Handle rmHandle, const char *resourceName)
     match = RB_FIND(_Rm_AllocatorTree, allocTree, &find);
 
     if (match) {
-        resTree = match->resourceRootEntry;
+        resTree = match->resourceRoot;
 
         /* Destroy resource tree */
         if (resTree) {
@@ -1751,7 +1757,7 @@ int32_t rmAllocatorDelete(Rm_Handle rmHandle, const char *resourceName)
                 rmResourceNodeFree(resNode);
             }
             Rm_osalFree((void *)resTree, sizeof(*resTree));
-            match->resourceRootEntry = NULL;
+            match->resourceRoot = NULL;
             RM_SS_OBJ_WB(rmInst, match, Rm_AllocatorNode);
         }
 
@@ -1792,7 +1798,7 @@ void rmAllocatorDeleteTree(Rm_Handle rmHandle)
              allocNode = nextAllocNode) {
             nextAllocNode = RB_NEXT(_Rm_AllocatorTree, allocTree, allocNode);
 
-            resTree = allocNode->resourceRootEntry;
+            resTree = allocNode->resourceRoot;
 
             if (rmInst->instType == Rm_instType_SHARED_SERVER) {
                 rmResourceTreeInv(resTree);
index 990bbfb33a7c65345abab76193e93f6f6702068c..72e0bab5323d48647278d2c46d4d8e64161bc046 100644 (file)
@@ -7,7 +7,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 
@@ -638,7 +638,8 @@ void rmDtbUtilPolicyFreeResourceAlignments (Rm_ResourceValue *alignmentList)
  *                  <Rm_Server>;
  *                  Results in a list of two valid instances.
  */
-Rm_PolicyValidInst *rmDtbUtilPolicyExtractValidInstances(const void *dtbDataPtr, int32_t dtbDataLen,
+Rm_PolicyValidInst *rmDtbUtilPolicyExtractValidInstances(const void *dtbDataPtr,
+                                                         int32_t dtbDataLen,
                                                          int32_t *result)
 {
     uint8_t            *dtbValidInstData = (uint8_t *)dtbDataPtr;
index 8544ae84126d5b64abf48d05281bca0ea287f485..7f11de95020ba5933a879e422ade0f199c3f927e 100644 (file)
@@ -85,10 +85,10 @@ static Rm_PolicyValidInstTree *policyGetValidInstTree(Rm_Handle rmHandle)
 
     if ((rmInst->instType == Rm_instType_SERVER) ||
         (rmInst->instType == Rm_instType_SHARED_SERVER)) {
-        tree = rmInst->u.server.globalValidInstTree;
+        tree = rmInst->u.server.validInstTree;
     }
     else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
-        tree = rmInst->u.cd.cdValidInstTree;
+        tree = rmInst->u.cd.validInstTree;
     }
     else if (rmInst->instType == Rm_instType_CLIENT) {
         tree = rmInst->u.client.staticValidInstTree;
@@ -937,7 +937,9 @@ int32_t rmPolicyValidatePolicy(Rm_Handle rmHandle)
  *              "valid-instances" property at the top of the Policy.
  *              The root entry of the valid instance tree is returned.
  */
-Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle, int addLinux, int32_t *result)
+Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle,
+                                                    int addLinux,
+                                                    int32_t *result)
 {
     Rm_Inst                *rmInst = (Rm_Inst *)rmHandle;
     void                   *policyDtb = rmPolicyGetPolicy(rmHandle);
@@ -949,48 +951,55 @@ Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle, int addL
     Rm_PolicyValidInst     *vInstListStart = NULL;
     Rm_PolicyValidInst     *validInstList = NULL;
     Rm_PolicyValidInstTree *rootEntry = NULL;
-    Rm_PolicyValidInstNode *newNode = NULL;  
+    Rm_PolicyValidInstNode *newNode = NULL;
     char                    linuxName[] = RM_ALLOCATED_TO_LINUX;
+    int32_t                 instIndex;
 
     /* Valid instance list must be first and only property in the root node of
      * the policyDtb */
-    validInstOffset = fdt_first_property_offset(policyDtb, RM_DTB_UTIL_STARTING_NODE_OFFSET);
+    validInstOffset = fdt_first_property_offset(policyDtb,
+                            RM_DTB_UTIL_STARTING_NODE_OFFSET);
     if (validInstOffset < -FDT_ERR_NOTFOUND) {
         *result = validInstOffset;
-        return (NULL);
-    } 
-    else if (validInstOffset == -FDT_ERR_NOTFOUND) {
+        return(NULL);
+    } else if (validInstOffset == -FDT_ERR_NOTFOUND) {
         *result = RM_ERROR_NO_VALID_INST_IN_POLICY;
-        return (NULL);
+        return(NULL);
     }
-    validInstData = fdt_getprop_by_offset(policyDtb, validInstOffset, &validInstName, &validInstLen);
+    validInstData = fdt_getprop_by_offset(policyDtb, validInstOffset,
+                                          &validInstName, &validInstLen);
     propertyType = rmDtbUtilPolicyGetPropertyType(validInstName);
     if (propertyType != Rm_policyPropType_VALID_INSTANCES) {
         *result = RM_ERROR_NO_VALID_INST_IN_POLICY;
-        return (NULL);
+        return(NULL);
     }
 
-    if (!(validInstList = rmDtbUtilPolicyExtractValidInstances(validInstData, validInstLen, result))) {
-        return (NULL);
+    if (!(validInstList = rmDtbUtilPolicyExtractValidInstances(validInstData,
+                                                               validInstLen,
+                                                               result))) {
+        return(NULL);
     }
-    
+
     /* Create the tree */
     rootEntry = Rm_osalMalloc(sizeof(Rm_PolicyValidInstTree));
     RB_INIT(rootEntry);
 
     vInstListStart = validInstList;
+    instIndex = 0;
     while (validInstList) {
-        newNode = rmPolicyValidInstNodeNew(validInstList->instName);
+        newNode = rmPolicyValidInstNodeNew(validInstList->instName,
+                                           instIndex);
         RB_INSERT(_Rm_PolicyValidInstTree, rootEntry, newNode);
-        
+
+        instIndex++;
         validInstList = validInstList->nextValidInst;
     }
     rmDtbUtilPolicyFreeValidInstances(vInstListStart);
 
     /* Add the Linux kernel node */
     if (addLinux) {
-        newNode = rmPolicyValidInstNodeNew(linuxName);
-        RB_INSERT(_Rm_PolicyValidInstTree, rootEntry, newNode);    
+        newNode = rmPolicyValidInstNodeNew(linuxName, instIndex);
+        RB_INSERT(_Rm_PolicyValidInstTree, rootEntry, newNode);
     }
 
     if (rmInst->instType == Rm_instType_SHARED_SERVER) {
@@ -999,7 +1008,7 @@ Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(Rm_Handle rmHandle, int addL
     }
 
     *result = RM_OK;
-    return (rootEntry);
+    return(rootEntry);
 }
 
 /* FUNCTION PURPOSE: Deletes a valid instance tree
@@ -1035,10 +1044,10 @@ void rmPolicyFreeValidInstTree(Rm_Handle rmHandle)
 
         if ((rmInst->instType == Rm_instType_SERVER) ||
             (rmInst->instType == Rm_instType_SHARED_SERVER)) {
-            rmInst->u.server.globalValidInstTree = NULL;
+            rmInst->u.server.validInstTree = NULL;
         }
         else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
-            rmInst->u.cd.cdValidInstTree = NULL;
+            rmInst->u.cd.validInstTree = NULL;
         }
         else if (rmInst->instType == Rm_instType_CLIENT) {
             rmInst->u.client.staticValidInstTree = NULL;
index bc332090ef835f75d0bfc474893f8a748f96d0fc..ef2a26aeaf8d43006bb2526e29b7cab32af5e373 100644 (file)
@@ -64,7 +64,7 @@ void rmNameServerTreeInv(Rm_NameServerTree *treeRoot)
     Rm_NameServerNode *node;
 
     /* Invalidate the tree root */
-    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(Rm_NameServerTree));
+    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(*treeRoot));
     /* Walk the tree which will invalidate each element in the tree */
     node = RB_MIN_CACHED(_Rm_NameServerTree, treeRoot);
     while (node) {
@@ -84,12 +84,12 @@ void rmNameServerTreeWb(Rm_NameServerTree *treeRoot)
     /* Writeback each element in the tree */
     node = RB_MIN(_Rm_NameServerTree, treeRoot);
     do {
-        Rm_osalEndMemAccess((void *)node, sizeof(Rm_NameServerNode));
+        Rm_osalEndMemAccess((void *)node, sizeof(*node));
         node = RB_NEXT(_Rm_NameServerTree, treeRoot, node);
     } while (node);
 
     /* Writeback the tree root */
-    Rm_osalEndMemAccess((void *)treeRoot, sizeof(Rm_NameServerTree));
+    Rm_osalEndMemAccess((void *)treeRoot, sizeof(*treeRoot));
 }
 
 /* FUNCTION PURPOSE: Creates a new NameServer tree node
@@ -107,7 +107,7 @@ Rm_NameServerNode *rmNameServerNodeNew(Rm_NameServerNodeCfg *nodeCfg)
         rm_strncpy(newNode->objName, nodeCfg->objName, RM_NAME_MAX_CHARS);
         rm_strncpy(newNode->resourceName, nodeCfg->resourceName,
                    RM_NAME_MAX_CHARS);
-        newNode->resourceBase = nodeCfg->resourceBase;
+        newNode->resourceBase   = nodeCfg->resourceBase;
         newNode->resourceLength = nodeCfg->resourceLength;
     }
 
@@ -145,7 +145,7 @@ int rmNameServerNodeCompare(Rm_NameServerNode *node1, Rm_NameServerNode *node2)
  */
 void rmNameServerNodeInv(Rm_NameServerNode *node)
 {
-    Rm_osalBeginMemAccess((void *)node, sizeof(Rm_NameServerNode));
+    Rm_osalBeginMemAccess((void *)node, sizeof(*node));
 }
 
 /* Generate the NameServer tree manipulation functions */
@@ -167,7 +167,7 @@ void rmPolicyValidInstTreeInv(Rm_PolicyValidInstTree *treeRoot)
     Rm_PolicyValidInstNode *node;
 
     /* Invalidate the tree root */
-    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(Rm_PolicyValidInstTree));
+    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(*treeRoot));
     /* Walk the tree which will invalidate each element in the tree */
     node = RB_MIN_CACHED(_Rm_PolicyValidInstTree, treeRoot);
     while (node) {
@@ -187,12 +187,12 @@ void rmPolicyValidInstTreeWb(Rm_PolicyValidInstTree *treeRoot)
     /* Writeback each element in the tree */
     node = RB_MIN(_Rm_PolicyValidInstTree, treeRoot);
     do {
-        Rm_osalEndMemAccess((void *)node, sizeof(Rm_PolicyValidInstNode));
+        Rm_osalEndMemAccess((void *)node, sizeof(*node));
         node = RB_NEXT(_Rm_PolicyValidInstTree, treeRoot, node);
     } while (node);
 
     /* Writeback the tree root */
-    Rm_osalEndMemAccess((void *)treeRoot, sizeof(Rm_PolicyValidInstTree));
+    Rm_osalEndMemAccess((void *)treeRoot, sizeof(*treeRoot));
 }
 
 /* FUNCTION PURPOSE: Creates a new valid instance tree node
@@ -200,16 +200,18 @@ void rmPolicyValidInstTreeWb(Rm_PolicyValidInstTree *treeRoot)
  * DESCRIPTION: Creates a new valid instance tree node with the
  *              specified name.
  */
-Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(char *instName)
+Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(const char *instName,
+                                                 const int32_t instIdx)
 {
     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;
-
+    if (newNode) {
+        rm_strncpy(newNode->name, instName, RM_NAME_MAX_CHARS);
+        newNode->allocRefCount = 0;
+        newNode->deletePending = RM_FALSE;
+        newNode->instIdx       = instIdx;
+    }
     return(newNode);
 }
 
@@ -248,7 +250,7 @@ int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1,
  */
 void rmPolicyValidInstNodeInv(Rm_PolicyValidInstNode *node)
 {
-    Rm_osalBeginMemAccess((void *)node, sizeof(Rm_PolicyValidInstNode));
+    Rm_osalBeginMemAccess((void *)node, sizeof(*node));
 }
 
 /* Generate the valid instance tree manipulation functions */
@@ -270,7 +272,7 @@ void rmResourceTreeInv(Rm_ResourceTree *treeRoot)
     Rm_ResourceNode *node;
 
     /* Invalidate the tree root */
-    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(Rm_ResourceTree));
+    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(*treeRoot));
     /* Walk the tree which will invalidate each element in the tree */
     node = RB_MIN_CACHED(_Rm_AllocatorResourceTree, treeRoot);
     while (node) {
@@ -290,32 +292,31 @@ void rmResourceTreeWb(Rm_ResourceTree *treeRoot)
     /* Writeback each element in the tree */
     node = RB_MIN(_Rm_AllocatorResourceTree, treeRoot);
     do {
-        Rm_osalEndMemAccess((void *)node, sizeof(Rm_ResourceNode));
+        Rm_osalEndMemAccess((void *)node, sizeof(*node));
         node = RB_NEXT(_Rm_AllocatorResourceTree, treeRoot, node);
     } while (node);
 
     /* Writeback the tree root */
-    Rm_osalEndMemAccess((void *)treeRoot, sizeof(Rm_ResourceTree));
+    Rm_osalEndMemAccess((void *)treeRoot, sizeof(*treeRoot));
 }
 
 /* FUNCTION PURPOSE: Creates a new resource tree node
  ***********************************************************************
  * DESCRIPTION: Creates a new resource tree node with the
- *              specified name resource values.
+ *              specified resource values.
  */
-Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase, 
+Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase,
                                    uint32_t resourceLength)
 {
     Rm_ResourceNode *newNode = NULL;
 
-    newNode = Rm_osalMalloc(sizeof(Rm_ResourceNode));
-    memset((void *)newNode, 0, sizeof(Rm_ResourceNode));
-
-    newNode->base = resourceBase;
-    newNode->length = resourceLength;
-    newNode->allocationCount = 0;
-    newNode->ownerList = NULL;
-
+    newNode = Rm_osalMalloc(sizeof(*newNode));
+    if (newNode) {
+        newNode->base            = resourceBase;
+        newNode->length          = resourceLength;
+        newNode->allocationCount = 0;
+        newNode->ownerList       = NULL;
+    }
     return(newNode);
 }
 
@@ -352,13 +353,11 @@ int rmResourceNodeCompare(Rm_ResourceNode *node1, Rm_ResourceNode *node2)
         /* End of node1 range is less than the start of node2's range.  Return
          * a negative value */
         return(-1);
-    }
-    else if (node1->base > node2End) {
+    } else if (node1->base > node2End) {
         /* Start of node1 range is after end of node2's range.  Return a
          * positive value */
         return(1);
-    }
-    else {
+    } 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. */
@@ -373,13 +372,136 @@ int rmResourceNodeCompare(Rm_ResourceNode *node1, Rm_ResourceNode *node2)
  */
 void rmResourceNodeInv(Rm_ResourceNode *node)
 {
-    Rm_osalBeginMemAccess((void *)node, sizeof(Rm_ResourceNode));
+    Rm_osalBeginMemAccess((void *)node, sizeof(*node));
 }
 
 /* Generate the resource tree manipulation functions */
 RB_GENERATE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage,
             rmResourceNodeCompare, rmResourceNodeInv);
 
+/**********************************************************************
+ ****************** Allocator Policy Tree Functions *******************
+ **********************************************************************/
+
+/* FUNCTION PURPOSE: Invalidates an entire policy tree
+ ***********************************************************************
+ * DESCRIPTION: Uses the cache handling versions of the RB tree
+ *              macros to walk an entire policy tree and invalidate
+ *              it.
+ */
+void rmPolicyTreeInv(Rm_PolicyTree *treeRoot)
+{
+    Rm_PolicyNode *node;
+
+    /* Invalidate the tree root */
+    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(*treeRoot));
+    /* Walk the tree which will invalidate each element in the tree */
+    node = RB_MIN_CACHED(_Rm_AllocatorPolicyTree, treeRoot);
+    while (node) {
+        node = RB_NEXT_CACHED(_Rm_AllocatorPolicyTree, treeRoot, node);
+    }
+}
+
+/* FUNCTION PURPOSE: Writebacks an entire policy tree
+ ***********************************************************************
+ * DESCRIPTION: Walks the entire policy tree writing back
+ *              each element to shared memory
+ */
+void rmPolicyTreeWb(Rm_PolicyTree *treeRoot)
+{
+    Rm_PolicyNode *node;
+
+    /* Writeback each element in the tree */
+    node = RB_MIN(_Rm_AllocatorPolicyTree, treeRoot);
+    do {
+        Rm_osalEndMemAccess((void *)node, sizeof(*node));
+        Rm_osalEndMemAccess((void *)node->perms, node->permsLen);
+        node = RB_NEXT(_Rm_AllocatorPolicyTree, treeRoot, node);
+    } while (node);
+
+    /* Writeback the tree root */
+    Rm_osalEndMemAccess((void *)treeRoot, sizeof(*treeRoot));
+}
+
+/* FUNCTION PURPOSE: Creates a new policy tree node
+ ***********************************************************************
+ * DESCRIPTION: Creates a new policy tree node with the
+ *              specified policy values.
+ */
+Rm_PolicyNode *rmPolicyNodeNew(uint32_t resourceBase, uint32_t resourceLength)
+{
+    Rm_PolicyNode *newNode = NULL;
+
+    newNode = Rm_osalMalloc(sizeof(*newNode));
+    if (newNode) {
+        newNode->base  = resourceBase;
+        newNode->len   = resourceLength;
+        newNode->perms = NULL;
+        newNode->permsLen = 0;
+    }
+    return(newNode);
+}
+
+/* FUNCTION PURPOSE: Deletes a policy tree node
+ ***********************************************************************
+ * DESCRIPTION: Deletes the specified policy tree node.
+ */
+void rmPolicyNodeFree(Rm_PolicyNode *node)
+{
+    if (node->perms) {
+        Rm_osalFree((void *)node->perms, node->permsLen);
+    }
+    Rm_osalFree((void *)node, sizeof(*node));
+}
+
+/* FUNCTION PURPOSE: Compares two policy tree nodes
+ ***********************************************************************
+ * DESCRIPTION: Returns the result of a comparison of two 
+ *              policy tree node value ranges.
+ *
+ *              |node1 range||node2 range| --> return < 0
+ *
+ *                 |node1 range|
+ *                   |node2 range|         --> return 0 (any overlap in ranges)
+ *
+ *              |node2 range||node1 range| --> return > 0
+ */
+int rmPolicyNodeCompare(Rm_PolicyNode *node1, Rm_PolicyNode *node2)
+{
+    uint32_t node1End = node1->base + node1->len - 1;
+    uint32_t node2End = node2->base + node2->len - 1;
+
+    if (node1End < node2->base) {
+        /* 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);
+    } 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);
+    }
+}
+
+/* FUNCTION PURPOSE: Invalidates a policy tree node
+ ***********************************************************************
+ * DESCRIPTION: Uses RM OSAL layer to invalidate the specified
+ *              policy tree node.
+ */
+void rmPolicyNodeInv(Rm_PolicyNode *node)
+{
+    Rm_osalBeginMemAccess((void *)node, sizeof(*node));
+    Rm_osalBeginMemAccess((void *)node->perms, node->permsLen);
+}
+
+/* Generate the policy tree manipulation functions */
+RB_GENERATE(_Rm_AllocatorPolicyTree, _Rm_PolicyNode, linkage,
+            rmPolicyNodeCompare, rmPolicyNodeInv);
+
 /**********************************************************************
  ********************* Allocator Tree Functions ***********************
  **********************************************************************/
@@ -394,7 +516,7 @@ void rmAllocatorTreeInv(Rm_AllocatorTree *treeRoot)
     Rm_AllocatorNode *node;
 
     /* Invalidate the tree root */
-    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(Rm_AllocatorTree));
+    Rm_osalBeginMemAccess((void *)treeRoot, sizeof(*treeRoot));
     /* Walk the tree which will invalidate each element in the tree */
     node = RB_MIN_CACHED(_Rm_AllocatorTree, treeRoot);
     while (node) {
@@ -414,12 +536,12 @@ void rmAllocatorTreeWb(Rm_AllocatorTree *treeRoot)
     /* Writeback each element in the tree */
     node = RB_MIN(_Rm_AllocatorTree, treeRoot);
     do {
-        Rm_osalEndMemAccess((void *)node, sizeof(Rm_AllocatorNode));
+        Rm_osalEndMemAccess((void *)node, sizeof(*node));
         node = RB_NEXT(_Rm_AllocatorTree, treeRoot, node);
     } while (node);
 
     /* Writeback the tree root */
-    Rm_osalEndMemAccess((void *)treeRoot, sizeof(Rm_AllocatorTree));
+    Rm_osalEndMemAccess((void *)treeRoot, sizeof(*treeRoot));
 }
 
 /* FUNCTION PURPOSE: Creates a new allocator node
@@ -431,11 +553,12 @@ 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;
-
+    newNode = Rm_osalMalloc(sizeof(*newNode));
+    if (newNode) {
+        rm_strncpy(newNode->resourceName, resourceName, RM_NAME_MAX_CHARS);
+        newNode->resourceRoot = NULL;
+        newNode->policyRoot   = NULL;
+    }
     return(newNode);
 }