diff --git a/src/rm.c b/src/rm.c
index 5096e1d485eccb63f4819f9c3b3f2a23b3cdc93c..d3ab4932ba66e2c1677bf1b3d2d905dae3133c12 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
newTransaction = Rm_osalMalloc(sizeof(Rm_Transaction));\r
\r
/* Return if the memory allocated for the transaction entry is NULL */\r
- if (newTransaction == NULL)\r
+ if (newTransaction != NULL)\r
{\r
/* Clear the transaction */\r
memset((void *)newTransaction, 0, sizeof(Rm_Transaction));\r
else\r
{\r
/* Delete the transaction */\r
- if ((prevTransaction == NULL) && transaction->nextTransaction)\r
+ if (prevTransaction == NULL)\r
{\r
/* Transaction to be deleted exists at start of transaction queue. Map second\r
* transaction to be start of transaction queue as long as there are more than\r
return (sequenceNum);\r
}\r
\r
-/* Function used to send RM response transactions to lower level agents */\r
-void Rm_transactionResponder (Rm_Inst *rmInst, Rm_Transaction *transaction)\r
-{\r
- Rm_TransportNode *dstTransportNode = NULL;\r
- Rm_Packet *rmPkt = NULL;\r
-\r
- /* Find the transport for the RM instance that sent the request. */\r
- dstTransportNode = Rm_transportNodeFindRemoteName(rmInst, transaction->sourceInstName);\r
-\r
- /* Create a RM packet using the service information */\r
- switch (transaction->type)\r
- {\r
- case Rm_service_RESOURCE_ALLOCATE:\r
- case Rm_service_RESOURCE_BLOCK_ALLOCATE:\r
- case Rm_service_RESOURCE_ALLOCATE_BY_NAME:\r
- case Rm_service_RESOURCE_FREE:\r
- case Rm_service_RESOURCE_BLOCK_FREE:\r
- case Rm_service_RESOURCE_FREE_BY_NAME:\r
- rmPkt = Rm_transportCreateResourceResponsePkt(rmInst, dstTransportNode, \r
- transaction);\r
- break;\r
- case Rm_service_RESOURCE_MAP_TO_NAME:\r
- case Rm_service_RESOURCE_UNMAP_NAME:\r
- rmPkt = Rm_transportCreateNsResponsePkt(rmInst, dstTransportNode,\r
- transaction);\r
- break;\r
- default:\r
- /* Invalid service type. Flag the error and return */\r
- transaction->state = RM_SERVICE_ERROR_INVALID_SERVICE_TYPE;\r
- break;\r
- }\r
-\r
- if (transaction->state <= RM_SERVICE_ERROR_BASE)\r
- {\r
- /* Delete the transaction and return immediately because an error occurred \r
- * allocating the packet */\r
- Rm_transactionQueueDelete(rmInst, transaction->localId);\r
- return;\r
- }\r
-\r
- /* Send the RM packet to the application transport */\r
- if (rmInst->transport.rmSend((Rm_TransportHandle) dstTransportNode, rmPkt) < RM_TRANSPORT_SUCCESSFUL)\r
- {\r
- /* Negative value returned by transport send. An error occurred\r
- * in the transport while attempting to send the packet.*/\r
- transaction->state = RM_SERVICE_ERROR_TRANPSPORT_SEND_ERROR;\r
- /* Clean up the packet */\r
- if (rmInst->transport.rmFreePkt((Rm_TransportHandle) dstTransportNode, rmPkt))\r
- {\r
- /* Non-NULL value returned by transport packet free. Flag the\r
- * error */\r
- transaction->state = RM_SERVICE_ERROR_TRANSPORT_FREE_PKT_ERROR;\r
- }\r
- return;\r
- }\r
-\r
- /* NEED TO DO SOMETHING IF GET AN ERROR IN THE transaction->state FIELD. CREATE\r
- * NEW TRANSACTION WITH DATA FROM ORIGINAL? THEN TRY TO SEND FAILED REQUEST BACK\r
- * TO REQUESTER??? KEEP RETRYING SEND OF RESPONSE??? */\r
-\r
- /* Delete the transaction */\r
- Rm_transactionQueueDelete(rmInst, transaction->localId);\r
-}\r
-\r
-Rm_Allocator *Rm_allocatorAdd(Rm_Inst *rmInst, const char *resourceName, Rm_AllocatorType type)\r
+Rm_Allocator *Rm_allocatorAdd(Rm_Inst *rmInst, const char *resourceName)\r
{\r
Rm_Allocator *allocators = (Rm_Allocator *)rmInst->allocators;\r
Rm_Allocator *newAllocator = NULL;\r
@@ -377,7 +313,6 @@ Rm_Allocator *Rm_allocatorAdd(Rm_Inst *rmInst, const char *resourceName, Rm_Allo
memset((void *)newAllocator, 0, sizeof(Rm_Allocator));\r
\r
/* Populate the allocator */\r
- newAllocator->type = type;\r
strcpy(newAllocator->resourceName, resourceName);\r
/* allocator's root entry will be created by the invoking function */\r
newAllocator->allocatorRootEntry = NULL;\r
else\r
{\r
/* Delete the allocator */\r
- if ((prevAllocator == NULL) && allocator->nextAllocator)\r
+ if (prevAllocator == NULL)\r
{\r
/* Allocator to be deleted exists at start of allocator list. Map second\r
* allocator to be start of allocator list as long as there are more than\r
return (retVal);\r
}\r
\r
-int32_t Rm_createIntegerAllocator(Rm_Inst *rmInst, const char *resourceName, Rm_ResourceRange *range)\r
-{\r
- Rm_Allocator *allocator = NULL;\r
- Rm_ResourceRange *rangeBasePtr = range;\r
- Rm_IntegerAllocatorRootEntry *intRootEntry = NULL;\r
- uint16_t i, entryIndex;\r
-\r
- /* Create the new base integer allocator */\r
- allocator = Rm_allocatorAdd(rmInst, resourceName, Rm_allocatorType_INTEGER);\r
-\r
- /* Construct the integer allocator root entry */\r
- intRootEntry = Rm_osalMalloc(sizeof(Rm_IntegerAllocatorRootEntry));\r
- intRootEntry->numResourceElements = 0;\r
-\r
- /* Get the number of entries to allocate based on the lengths in the ranges */\r
- while (range != NULL)\r
- {\r
- intRootEntry->numResourceElements += range->length;\r
- range = range->nextRange;\r
- }\r
-\r
- /* Initialize the entries using the range information */\r
- if (intRootEntry->numResourceElements)\r
- {\r
- intRootEntry->resourceArrayBase = Rm_osalMalloc(sizeof(Rm_IntegerEntry) * intRootEntry->numResourceElements);\r
- memset((void *)intRootEntry->resourceArrayBase, 0, sizeof(Rm_IntegerEntry) * intRootEntry->numResourceElements);\r
-\r
- /* Reset the range pointer */\r
- range = rangeBasePtr;\r
- entryIndex = 0;\r
-\r
- while (range != NULL)\r
- {\r
- /* Initialize each entry */\r
- for (i = range->base; i < (range->base + range->length); i++, entryIndex++)\r
- {\r
- intRootEntry->resourceArrayBase[entryIndex].value = i;\r
- /* Initialize the allocatedTo field to the NOT_ALLOCATED string */\r
- strcpy(intRootEntry->resourceArrayBase[entryIndex].allocatedTo, RM_NOT_ALLOCATED_STRING);\r
- }\r
- \r
- range = range->nextRange;\r
- }\r
- \r
- allocator->allocatorRootEntry = intRootEntry;\r
- }\r
- else\r
- {\r
- /* No resource entries were created. Free the memory associated with the\r
- * allocator and the root entry */\r
- Rm_osalFree((void *)intRootEntry, sizeof(Rm_IntegerAllocatorRootEntry));\r
- Rm_allocatorDelete(rmInst, allocator->resourceName);\r
- }\r
-\r
- return(0); /* TODO: FIX THIS RETURN */\r
-}\r
-\r
int32_t Rm_createTreeAllocator(Rm_Inst *rmInst, const char *resourceName, Rm_ResourceRange *range)\r
{\r
Rm_Allocator *allocator = NULL;\r
@@ -553,7 +431,7 @@ int32_t Rm_createTreeAllocator(Rm_Inst *rmInst, const char *resourceName, Rm_Res
Rm_ResourceTreeNode *collidingNode = NULL;\r
\r
/* Create the new base integer allocator */\r
- allocator = Rm_allocatorAdd(rmInst, resourceName, Rm_allocatorType_TREE);\r
+ allocator = Rm_allocatorAdd(rmInst, resourceName);\r
\r
/* Create the tree root entry and initialize it */\r
treeRootEntry = Rm_osalMalloc(sizeof(Rm_ResourceTree));\r
@@ -562,7 +440,7 @@ int32_t Rm_createTreeAllocator(Rm_Inst *rmInst, const char *resourceName, Rm_Res
/* Create a node in the tree for resource range and insert them into the tree. */\r
while (range != NULL)\r
{\r
- Rm_newResourceTreeNode(range->base, range->length, RM_NOT_ALLOCATED_STRING);\r
+ treeNode = Rm_newResourceTreeNode(range->base, range->length, RM_NOT_ALLOCATED_STRING);\r
\r
/* Insert the node into the tree */\r
collidingNode = RB_INSERT(_Rm_ResourceTree, treeRootEntry, treeNode);\r
@@ -595,542 +473,100 @@ int32_t Rm_createTreeAllocator(Rm_Inst *rmInst, const char *resourceName, Rm_Res
return(0); /* TODO: FIX THIS RETURN */\r
}\r
\r
-int32_t Rm_createAndInitAllocator(Rm_Inst *rmInst, const char *resourceName, \r
- Rm_ResourceProperties *resourceProperties, void *linuxDtb)\r
+/* Called when an allocate request is made but the base is unspecified. RM must preallocate\r
+ * resources which then must be checked against the RM policy for the instance. If the\r
+ * policy does not agree another resource(s) must be preallocated and tested against the \r
+ * policy. Policy will provide initialize the preallocate with the base that it allows\r
+ * for the rm instance for the specified resource. */\r
+int32_t Rm_treePreAllocate(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)\r
{\r
- char *allocatorType = NULL;\r
- Rm_ResourceRange *range = NULL;\r
- Rm_ResourceRange *rangeBasePtr = NULL;\r
- Rm_NsAssignment *nsAssignments = NULL;\r
- Rm_NsAssignment *nsAssignmentBasePtr = NULL;\r
- Rm_LinuxAlias *linuxAlias = NULL;\r
- Rm_LinuxAlias *linuxAliasBasePtr = NULL;\r
- int32_t retVal = RM_DTB_UTIL_RESULT_OKAY;\r
-\r
- /* TODO: NEED CHECKS FOR VALIDITY OF ALL THE resourceProperties FIELDS */\r
-\r
- /* Extract the resource properties from the DTB */\r
- allocatorType = Rm_resourceExtractAllocator(resourceProperties->allocatorData, \r
- resourceProperties->allocatorLen);\r
- range = rangeBasePtr = Rm_resourceExtractRange(resourceProperties->rangeData, \r
- resourceProperties->rangeLen);\r
+ Rm_ResourceTreeNode findNode;\r
+ Rm_ResourceTreeNode *matchingNode = NULL;\r
+ uint32_t policyRangeEnd = opInfo->policyBase + opInfo->policyLength - 1;\r
+ uint32_t index;\r
+ bool resourceFound = FALSE;\r
+ int32_t retVal = RM_SERVICE_PROCESSING;\r
\r
- /* Create an allocator based on the allocator type specified */\r
- if (strcmp(allocatorType, &rmIntegerAllocator[0]) == 0)\r
- {\r
- /* Create an integer allocator using the resource properties */\r
- retVal = Rm_createIntegerAllocator(rmInst, resourceName, range); \r
- }\r
- else if (strcmp(allocatorType, &rmTreeAllocator[0]) == 0)\r
+ /* Find the tree node that contains the first value in the specified policy range. */\r
+ if (opInfo->policyBase)\r
{\r
- /* Create a tree allocator using the resource properties */\r
- retVal = Rm_createTreeAllocator(rmInst, resourceName, range); \r
+ findNode.base = opInfo->policyBase;\r
}\r
else\r
{\r
- /* Allocator type not recognized. Free the resource properties and return */\r
- retVal = -21; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
+ matchingNode = RB_MIN(_Rm_ResourceTree, allocator->allocatorRootEntry);\r
+ findNode.base = matchingNode->base;\r
}\r
-\r
- /* Reserve the resources taken by the Linux kernel specified in the Linux DTB */\r
- linuxAlias = linuxAliasBasePtr = Rm_resourceExtractLinuxAlias(resourceProperties->linuxAliasData,\r
- resourceProperties->linuxAliasLen);\r
\r
- if (retVal >= RM_DTB_UTIL_RESULT_OKAY)\r
+ findNode.length = 1;\r
+ matchingNode = RB_FIND(_Rm_ResourceTree, allocator->allocatorRootEntry, &findNode);\r
+\r
+ if (matchingNode != NULL)\r
{\r
- /* Create entries in the NameServer if any NameServer assignments were specified */\r
- if (resourceProperties->nsAssignData && resourceProperties->nsAssignLen)\r
+ /* Begin searching for an available range of resources starting from the\r
+ * matching node */\r
+ for (index = matchingNode->base; index <= policyRangeEnd;)\r
{\r
- nsAssignments = Rm_resourceExtractNsAssignment(resourceProperties->nsAssignData, \r
- resourceProperties->nsAssignLen);\r
-\r
- /* Cycle through the list of assignments and add them to the NameServer */\r
- nsAssignmentBasePtr = nsAssignments;\r
- while (nsAssignments)\r
+ /* Is the matchingNode free? */\r
+ if (strcmp(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0)\r
{\r
- /* TODO: RETURN IF ANY OF THE ADDS FAIL??? */\r
- Rm_nsAddObject(rmInst, nsAssignments->nsName, nsAssignments->resourceValue);\r
- nsAssignments = nsAssignments->nextNsAssignment;\r
- }\r
- /* Free the memory allocated for the NameServer assignments */\r
- Rm_resourceFreeNsAssignmentList(nsAssignmentBasePtr);\r
- }\r
- }\r
-\r
- /* Free the memory allocated for the resource properties */\r
- Rm_resourceFreeAllocator(allocatorType);\r
- Rm_resourceFreeRange(rangeBasePtr);\r
- Rm_resourceFreeLinuxAlias(linuxAliasBasePtr);\r
-\r
- return(retVal);\r
-}\r
+ uint32_t matchEnd = matchingNode->base + matchingNode->length - 1;\r
\r
-int32_t Rm_parseResourceProperty(void *globalResourceDtb, int32_t offset, Rm_ResourceProperties *propertyInfo)\r
-{\r
- int32_t propertyLen;\r
- const char *propertyName;\r
- const void *propertyData;\r
- Rm_ResourcePropType propertyType;\r
- int32_t retVal = RM_DTB_UTIL_RESULT_OKAY;\r
+ /* Move index to the first resource satisfying the alignment property */\r
+ if ((index % opInfo->policyAlignment) != 0)\r
+ {\r
+ index += (opInfo->policyAlignment - (index % opInfo->policyAlignment));\r
+ }\r
+ \r
+ /* Move through the node's resource range looking for a contiguous set of resources\r
+ * that satisfy the request. */\r
+ while ((index <= matchEnd) && (index <= policyRangeEnd))\r
+ {\r
+ if (((index + opInfo->resourceInfo->length - 1) <= matchEnd) &&\r
+ ((index + opInfo->resourceInfo->length - 1) <= policyRangeEnd))\r
+ {\r
+ /* Found a resource range in the node that satisfies the requirements */\r
+ opInfo->resourceInfo->base = index;\r
+ resourceFound = TRUE;\r
+ break;\r
+ }\r
\r
- /* Get the property data and store it in the corresponding propertyInfo field */\r
- propertyData = fdt_getprop_by_offset(globalResourceDtb, offset, &propertyName, &propertyLen);\r
- if (propertyData)\r
- {\r
- propertyType = Rm_resourceGetPropertyType(propertyName);\r
- if (propertyType == Rm_resourcePropType_RESOURCE_ALLOCATOR)\r
- {\r
- if (propertyInfo->allocatorData || propertyInfo->allocatorLen)\r
- {\r
- /* The allocator fields have already been populated. Return an error.\r
- * The resource list has specified a property field more than once\r
- * for a resource node */\r
- retVal = -17; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
- }\r
- else\r
- {\r
- propertyInfo->allocatorData = propertyData;\r
- propertyInfo->allocatorLen = propertyLen;\r
- }\r
- }\r
- else if (propertyType == Rm_resourcePropType_RESOURCE_RANGE)\r
- {\r
- if (propertyInfo->rangeData || propertyInfo->rangeLen)\r
- {\r
- /* The range fields have already been populated. Return an error.\r
- * The resource list has specified a property field more than once\r
- * for a resource node */\r
- retVal = -18; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
- }\r
- else\r
- {\r
- propertyInfo->rangeData = propertyData;\r
- propertyInfo->rangeLen = propertyLen;\r
+ /* Move index to the next resource value that satisfies the alignment property */\r
+ index += (opInfo->policyAlignment - (index % opInfo->policyAlignment));\r
+ }\r
}\r
- }\r
- else if (propertyType == Rm_resourcePropType_NSASSIGNMENT)\r
- {\r
- if (propertyInfo->nsAssignData || propertyInfo->nsAssignLen)\r
+ \r
+ if (!resourceFound)\r
{\r
- /* The nsAssign fields have already been populated. Return an error.\r
- * The resource list has specified a property field more than once\r
- * for a resource node */\r
- retVal = -19; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
+ /* Move to the next tree node */\r
+ matchingNode = RB_NEXT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ if (matchingNode == NULL)\r
+ {\r
+ /* Reached end of tree. Resource range does not exist. Leave the search\r
+ * loop */\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ index = matchingNode->base;\r
+ }\r
}\r
else\r
{\r
- propertyInfo->nsAssignData = propertyData;\r
- propertyInfo->nsAssignLen = propertyLen;\r
+ /* Found a resource range that satisfies the request properties. Break out of the\r
+ * search loop */\r
+ break;\r
}\r
}\r
- else if (propertyType == Rm_resourcePropType_RESOURCE_LINUX_ALIAS)\r
- {\r
- if (propertyInfo->linuxAliasData || propertyInfo->linuxAliasLen)\r
- {\r
- /* The linuxAlias fields have already been populated. Return an error.\r
- * The resource list has specified a property field more than once\r
- * for a resource node */\r
- retVal = -28; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
- }\r
- else\r
- {\r
- propertyInfo->linuxAliasData = propertyData;\r
- propertyInfo->linuxAliasLen = propertyLen;\r
- }\r
- } \r
- else\r
+\r
+ if (!resourceFound)\r
{\r
- retVal = -20; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
+ retVal = RM_SERVICE_DENIED_RESOURCE_ALREADY_ALLOCATED;\r
}\r
}\r
else\r
{\r
- retVal = -16; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
- }\r
-\r
- /* Don't get anymore properties if error occurred */\r
- if (retVal == RM_DTB_UTIL_RESULT_OKAY)\r
- {\r
- offset = fdt_next_property_offset(globalResourceDtb, offset);\r
- if (offset >= 0)\r
- {\r
- retVal = Rm_parseResourceProperty(globalResourceDtb, offset, propertyInfo);\r
- }\r
- else if (offset != -FDT_ERR_NOTFOUND)\r
- {\r
- /* Error was returned by LIBFDT when parsing the properties */\r
- retVal = offset;\r
- }\r
- }\r
- \r
- return (retVal);\r
-}\r
-\r
-int32_t Rm_parseResourceNode(Rm_Inst *rmInst, void *globalResourceDtb, int32_t nodeOffset, int32_t depth,\r
- void *linuxDtb)\r
-{\r
- const char *resourceName = fdt_get_name(globalResourceDtb, nodeOffset, NULL);\r
- Rm_ResourceProperties resourceProperties;\r
- int32_t error = RM_DTB_UTIL_RESULT_OKAY;\r
- int32_t offset;\r
-\r
- /* Initialize the resource properties structure */\r
- memset((void *)&resourceProperties, 0, sizeof(Rm_ResourceProperties));\r
-\r
- /* Ignore properties of the base node */\r
- if (strcmp(resourceName, rmDtbStartingNode))\r
- {\r
- /* Get the properties for the resource node if any exist */\r
- offset = fdt_first_property_offset(globalResourceDtb, nodeOffset);\r
- if (offset >= RM_DTB_UTIL_STARTING_NODE_OFFSET)\r
- {\r
- /* Since at least one property exists attempt to parse the property nodes and \r
- * use them to create and initialize a resource allocator */\r
- error = Rm_parseResourceProperty(globalResourceDtb, offset, &resourceProperties);\r
- if (error < -FDT_ERR_NOTFOUND)\r
- {\r
- return (error);\r
- }\r
- \r
- /* Initialize an allocator with the resource properties if no error was returned */\r
- Rm_createAndInitAllocator(rmInst, resourceName, &resourceProperties, linuxDtb);\r
- }\r
- else if (offset != -FDT_ERR_NOTFOUND)\r
- {\r
- /* Error was returned by LIBFDT when parsing the properties */\r
- return (offset);\r
- }\r
- }\r
- \r
- /* Get the next resource node */\r
- offset = fdt_next_node(globalResourceDtb, nodeOffset, &depth);\r
- /* Check the offset and depth of the next node to make sure the current node\r
- * wasn't the last node in the Resource List. A depth less than the depth set\r
- * at the start of the recursion will signal the end of the resource list */\r
- if ((offset >= RM_DTB_UTIL_STARTING_NODE_OFFSET) && (depth >= RM_DTB_UTIL_STARTING_DEPTH))\r
- {\r
- error = Rm_parseResourceNode(rmInst, globalResourceDtb, offset, depth, linuxDtb);\r
- if (error < -FDT_ERR_NOTFOUND)\r
- {\r
- return (error);\r
- }\r
- }\r
- else if (offset != -FDT_ERR_NOTFOUND)\r
- {\r
- /* Error was returned by LIBFDT when parsing the nodes */\r
- return (offset);\r
- }\r
-\r
- return (RM_DTB_UTIL_RESULT_OKAY);\r
-}\r
-\r
-/* Called when an allocate request is made but the base is unspecified. RM must preallocate\r
- * resources which then must be checked against the RM policy for the instance. If the\r
- * policy does not agree another resource(s) must be preallocated and tested against the \r
- * policy. Policy will provide initialize the preallocate with the base that it allows\r
- * for the rm instance for the specified resource. */\r
-int32_t Rm_integerPreAllocate(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)\r
-{\r
- Rm_IntegerAllocatorRootEntry *root = allocator->allocatorRootEntry;\r
- Rm_IntegerEntry *resourceArray = root->resourceArrayBase;\r
- uint16_t index, i;\r
- bool resourcesValidated;\r
- int32_t retVal = RM_SERVICE_PROCESSING;\r
-\r
- /* Find the specified resource base within the allocator */\r
- for (index = 0; index < root->numResourceElements; index++)\r
- {\r
- if (resourceArray[index].value == opInfo->resourceInfo->base)\r
- {\r
- /* Found the resource base in the allocator. Break from the loop */\r
- break;\r
- }\r
- } \r
-\r
- /* Only execute the allocate operation if the resource base was found in the allocator\r
- * and the base+length does not exceed the number of entries in the allocator */\r
- if ((index + opInfo->resourceInfo->length) <= root->numResourceElements)\r
- {\r
- /* Search for a contiguous block of unallocated resources of length "length"\r
- * and with the alignment specified */\r
- while ((index + opInfo->resourceInfo->length) <= root->numResourceElements)\r
- {\r
- resourcesValidated = FALSE; \r
- \r
- /* Does the resource base value satisfy the alignment? */\r
- if ((resourceArray[index].value % opInfo->resourceInfo->alignment) == 0)\r
- {\r
- /* Check to see all the resource values in the requested range are free */\r
- resourcesValidated = TRUE;\r
- for (i = index; i < opInfo->resourceInfo->length; i++)\r
- {\r
- if (strcmp(resourceArray[i].allocatedTo, RM_NOT_ALLOCATED_STRING) != 0)\r
- {\r
- /* A resource within the range was already allocated. Update the\r
- * index to the resource after the allocated resource and continue \r
- * looking. */\r
- index = i + 1;\r
- resourcesValidated = FALSE;\r
- /* Break out of the for loop */\r
- break;\r
- }\r
- }\r
-\r
- if (resourcesValidated)\r
- {\r
- /* Found a set of resources that satisfies the request requirements. Return\r
- * the results to be tested against the policy. If the policy approves the\r
- * resources will be allocated via the Rm_integerAllocate API. */\r
- opInfo->resourceInfo->base = resourceArray[index].value;\r
- /* Break out of the while loop */\r
- break;\r
- }\r
- }\r
- else\r
- {\r
- /* Jump to the next resource value that satisfies the alignment */\r
- for (; index < root->numResourceElements; index++)\r
- {\r
- if ((resourceArray[index].value % opInfo->resourceInfo->alignment) == 0)\r
- {\r
- /* Found the next resource value that satisfies the alignment */\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- if (!resourcesValidated)\r
- {\r
- retVal = RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST;\r
- }\r
- }\r
- else\r
- {\r
- retVal = RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST;\r
- }\r
-\r
- return(retVal); \r
-}\r
-\r
-/* Assumes resource range for allocation has already been approved by the policy */\r
-int32_t Rm_integerAllocate(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)\r
-{\r
- Rm_IntegerAllocatorRootEntry *root = allocator->allocatorRootEntry;\r
- uint16_t resourceIndex, i, j;\r
- bool resourcesValidated = TRUE;\r
- int32_t retVal;\r
-\r
- /* Find the specified resource base within the allocator */\r
- for (resourceIndex = 0; resourceIndex < root->numResourceElements; resourceIndex++)\r
- {\r
- if (root->resourceArrayBase[resourceIndex].value == opInfo->resourceInfo->base)\r
- {\r
- /* Found the resource base in the allocator. Break from the loop */\r
- break;\r
- }\r
- }\r
-\r
- /* Only execute the allocate operation if the resource base was found in the allocator\r
- * and the base+length does not exceed the number of entries in the allocator */\r
- if ((resourceIndex + opInfo->resourceInfo->length) <= root->numResourceElements)\r
- {\r
- /* Verify all resource values from base to base+length exist in the allocator and\r
- * are not allocated to another instance. */\r
- for (i = resourceIndex, j = opInfo->resourceInfo->base; \r
- i < (resourceIndex + opInfo->resourceInfo->length);\r
- i++, j++)\r
- {\r
- if (root->resourceArrayBase[i].value != j)\r
- {\r
- /* A value in the range did not match. */\r
- retVal = RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST;\r
- resourcesValidated = FALSE;\r
- break;\r
- }\r
- else if (strcmp(root->resourceArrayBase[i].allocatedTo, RM_NOT_ALLOCATED_STRING) != 0)\r
- {\r
- /* A value in the range is already allocated. */\r
- retVal = RM_SERVICE_DENIED_RESOURCE_ALREADY_ALLOCATED;\r
- resourcesValidated = FALSE;\r
- break; \r
- }\r
- }\r
-\r
- if (resourcesValidated)\r
- {\r
- /* Allocate all resources from base to base+length */\r
- for (i = resourceIndex; i < (resourceIndex + opInfo->resourceInfo->length); i++)\r
- {\r
- strcpy(root->resourceArrayBase[i].allocatedTo, opInfo->srcInstName);\r
- }\r
- retVal = RM_SERVICE_APPROVED_AND_COMPLETED;\r
- }\r
- }\r
- else\r
- {\r
- retVal = RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST;\r
- }\r
-\r
- return(retVal); \r
-}\r
-\r
-/* Assumes resource range for free has already been approved by the policy */\r
-int32_t Rm_integerFree(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)\r
-{\r
- Rm_IntegerAllocatorRootEntry *root = allocator->allocatorRootEntry;\r
- uint16_t resourceIndex, i, j;\r
- bool resourcesValidated = TRUE;\r
- int32_t retVal;\r
-\r
- /* Find the specified resource base within the allocator */\r
- for (resourceIndex = 0; resourceIndex < root->numResourceElements; resourceIndex++)\r
- {\r
- if (root->resourceArrayBase[resourceIndex].value == opInfo->resourceInfo->base)\r
- {\r
- /* Found the resource base in the allocator. Break from the loop */\r
- break;\r
- }\r
- }\r
-\r
- /* Only execute the free operation if the resource base was found in the allocator\r
- * and the base+length does not exceed the number of entries in the allocator */\r
- if ((resourceIndex + opInfo->resourceInfo->length) <= root->numResourceElements)\r
- {\r
- /* Verify all resource values from base to base+length exist in the allocator,\r
- * were not already free and were allocated to the instance that is the source\r
- * of the free request. */\r
- for (i = resourceIndex, j = opInfo->resourceInfo->base; \r
- i < (resourceIndex + opInfo->resourceInfo->length);\r
- i++, j++)\r
- {\r
- if (root->resourceArrayBase[i].value != j)\r
- {\r
- /* A value in the range did not match. */\r
- retVal = RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST;\r
- resourcesValidated = FALSE;\r
- break;\r
- }\r
- else if (strcmp(root->resourceArrayBase[i].allocatedTo, RM_NOT_ALLOCATED_STRING) == 0)\r
- {\r
- /* A value in the range is already free. */\r
- retVal = RM_SERVICE_DENIED_RESOURCE_ALREADY_FREE;\r
- resourcesValidated = FALSE;\r
- break; \r
- } \r
- else if (strcmp(root->resourceArrayBase[i].allocatedTo, opInfo->srcInstName) != 0)\r
- {\r
- /* A value in the range was not allocated to the source of\r
- * the free request */\r
- retVal = RM_SERVICE_DENIED_RESOURCE_NOT_ALLOCATED_TO_INSTANCE_REQUESTING_THE_SERVICE;\r
- resourcesValidated = FALSE;\r
- break;\r
- }\r
- }\r
-\r
- if (resourcesValidated)\r
- {\r
- /* Free all resources from base to base+length */\r
- for (i = resourceIndex; i < (resourceIndex + opInfo->resourceInfo->length); i++)\r
- {\r
- strcpy(root->resourceArrayBase[i].allocatedTo, RM_NOT_ALLOCATED_STRING);\r
- }\r
- retVal = RM_SERVICE_APPROVED_AND_COMPLETED;\r
- }\r
- }\r
- else\r
- {\r
- retVal = RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST;\r
- }\r
-\r
- return(retVal);\r
-}\r
-\r
-/* Called when an allocate request is made but the base is unspecified. RM must preallocate\r
- * resources which then must be checked against the RM policy for the instance. If the\r
- * policy does not agree another resource(s) must be preallocated and tested against the \r
- * policy. Policy will provide initialize the preallocate with the base that it allows\r
- * for the rm instance for the specified resource. */\r
-int32_t Rm_treePreAllocate(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)\r
-{\r
- Rm_ResourceTreeNode findNode;\r
- Rm_ResourceTreeNode *matchingNode = NULL;\r
- uint32_t policyRangeEnd = opInfo->policyBase + opInfo->policyLength - 1;\r
- uint32_t index;\r
- bool resourceFound = FALSE;\r
- int32_t retVal = RM_SERVICE_PROCESSING;\r
-\r
- /* Find the tree node that contains the first value in the specified policy range. */\r
- findNode.base = opInfo->policyBase;\r
- findNode.length = 1;\r
- matchingNode = RB_FIND(_Rm_ResourceTree, allocator->allocatorRootEntry, &findNode);\r
-\r
- if (matchingNode != NULL)\r
- {\r
- /* Begin searching for an available range of resources starting from the\r
- * matching node */\r
- for (index = matchingNode->base; index <= policyRangeEnd;)\r
- {\r
- /* Is the matchingNode free? */\r
- if (strcmp(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0)\r
- {\r
- uint32_t matchEnd = matchingNode->base + matchingNode->length - 1;\r
-\r
- /* Move index to the first resource satisfying the alignment property */\r
- if ((index % opInfo->policyAlignment) != 0)\r
- {\r
- index += (opInfo->policyAlignment - (index % opInfo->policyAlignment));\r
- }\r
- \r
- /* Move through the node's resource range looking for a contiguous set of resources\r
- * that satisfy the request. */\r
- while ((index <= matchEnd) && (index <= policyRangeEnd))\r
- {\r
- if (((index + opInfo->resourceInfo->length - 1) <= matchEnd) &&\r
- ((index + opInfo->resourceInfo->length - 1) <= policyRangeEnd))\r
- {\r
- /* Found a resource range in the node that satisfies the requirements */\r
- opInfo->resourceInfo->base = index;\r
- resourceFound = TRUE;\r
- break;\r
- }\r
-\r
- /* Move index to the next resource value that satisfies the alignment property */\r
- index += (opInfo->policyAlignment - (index % opInfo->policyAlignment));\r
- }\r
- }\r
- \r
- if (!resourceFound)\r
- {\r
- /* Move to the next tree node */\r
- matchingNode = RB_NEXT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
- if (matchingNode == NULL)\r
- {\r
- /* Reached end of tree. Resource range does not exist. Leave the search\r
- * loop */\r
- break;\r
- }\r
- else\r
- {\r
- index = matchingNode->base;\r
- }\r
- }\r
- else\r
- {\r
- /* Found a resource range that satisfies the request properties. Break out of the\r
- * search loop */\r
- break;\r
- }\r
- }\r
-\r
- if (!resourceFound)\r
- {\r
- retVal = RM_SERVICE_DENIED_RESOURCE_ALREADY_ALLOCATED;\r
- }\r
- }\r
- else\r
- {\r
- retVal = RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST;\r
+ retVal = RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST;\r
}\r
\r
return(retVal); \r
Rm_ResourceTreeNode findNode;\r
Rm_ResourceTreeNode *matchingNode = NULL;\r
Rm_ResourceTreeNode *leftNode = NULL;\r
- Rm_ResourceTreeNode *rightNode = NULL;\r
+ Rm_ResourceTreeNode *rightNode = NULL; \r
uint32_t findEnd, matchingEnd;\r
int32_t retVal;\r
\r
@@ -1159,117 +595,149 @@ int32_t Rm_treeAllocate(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
/* Does the request range fit within the matching nodes entire range? */\r
if ((findNode.base >= matchingNode->base) && (findEnd <= matchingEnd))\r
{\r
- /* Handle requested resource range that is isolated to a single node\r
- *\r
- *\r
- * base0 base0+length0-1\r
- * |<---------------length0------------------->| => existing node\r
- * |<---------length1---------->| => requested resources\r
- * base1 base1+length1-1\r
- */ \r
+ /* Handle node create, combine, deletion based on the request range if\r
+ * resources are available. */\r
if (strcmp(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0)\r
{\r
- /* Resources are available - split up the node into potentially\r
- * three new nodes:\r
- * left node - free resources to left of newly allocated resources\r
- * middle node - newly allocated resources that satisfy the request\r
- * right node - free resources to the right of newly allocated resources\r
+ /* Handle case where the findNode range matches the matchingNode\r
+ * range exactly.\r
*\r
- * There also may be combine possibilities to the left and right of the\r
- * matching node. Need to extract those as well to check */\r
- leftNode = RB_PREV(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
- rightNode = RB_NEXT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
-\r
- /* Remove the matching node from the tree and the nodes to the left and\r
- * right of the matching node. Removing from tree will not\r
- * wipe any of the base+length data in the node. Can reuse since they won't\r
- * be freed */\r
- RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
- if (leftNode)\r
+ * base0 base0+length0-1\r
+ * |<---------------length0------------------->| => existing node\r
+ * |<---------------length1------------------->| => requested resources\r
+ * base1 base1+length1-1\r
+ */ \r
+ if ((findNode.base == matchingNode->base) && (findEnd == matchingEnd))\r
{\r
- RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+ /* Can reserve matchingNode's resources in-place */\r
+ strcpy(matchingNode->allocatedTo, opInfo->srcInstName);\r
}\r
- if (rightNode)\r
+ /* Handle case where the findNode range is a subset of the matchingNode\r
+ * range and neither of the boundaries of the two ranges are equivalent.\r
+ *\r
+ * base0 base0+length0-1\r
+ * |<---------------length0------------------->| => existing node\r
+ * |<---------length1---------->| => requested resources\r
+ * base1 base1+length1-1\r
+ */ \r
+ else if ((findNode.base > matchingNode->base) && (findEnd < matchingEnd))\r
{\r
- RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
- }\r
+ /* Split the matching node into three nodes:\r
+ * left node - free resources to left of newly allocated resources\r
+ * middle node - newly allocated resources that satisfy the request\r
+ * right node - free resources to the right of newly allocated resources */\r
\r
- /* Create the left node if needed. If the bases are equal the matchingNode can\r
- * be reused as the left bound of the range. */\r
- if (findNode.base > matchingNode->base)\r
- {\r
- /* Can the left node be combined with the node to the left of the matching\r
- * node */\r
- if (leftNode && (strcmp(leftNode->allocatedTo, opInfo->srcInstName) == 0))\r
- {\r
- /* Combine the left node and what's leftover on the left side of the \r
- * matchingNode range after the allocation */\r
- leftNode->length += (findNode.base - matchingNode->base);\r
- }\r
- else\r
+ /* Remove the matching node from the tree for modification. */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+\r
+ /* New left node attributes:\r
+ * base: base of the matching node\r
+ * length: base of requested resources - base of matching node */\r
+ leftNode = Rm_newResourceTreeNode(matchingNode->base, findNode.base - matchingNode->base,\r
+ RM_NOT_ALLOCATED_STRING);\r
+ /* New right node attributes:\r
+ * base: base of the requested resources + length of requested resources\r
+ * length: right bound of matching node - right bound of request resources */\r
+ rightNode = Rm_newResourceTreeNode(findNode.base + findNode.length,\r
+ matchingEnd - findEnd, RM_NOT_ALLOCATED_STRING);\r
+\r
+ /* Base and length of matching node become the base and length of the\r
+ * requested resources */\r
+ matchingNode->base = findNode.base; \r
+ matchingNode->length = findNode.length;\r
+ /* Reserve the resources */\r
+ strcpy(matchingNode->allocatedTo, opInfo->srcInstName);\r
+\r
+ /* Insert all the nodes */\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+ }\r
+ /* Handle cases where one of findNode range boundaries is equivalent to\r
+ * one of the matchingNode range boundaries.\r
+ *\r
+ * base0 base0+length0-1\r
+ * |<---------------length0------------------->| => existing node\r
+ * |<---------length1---------->| => requested resources\r
+ * base1 base1+length1-1\r
+ *\r
+ * OR\r
+ *\r
+ * base0 base0+length0-1\r
+ * |<---------------length0------------------->| => existing node\r
+ * |<---------length1---------->| => requested resources\r
+ * base1 base1+length1-1 \r
+ */ \r
+ else\r
+ { \r
+ /* Remove the matchingNode from the tree since it will be edited */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ \r
+ if (findNode.base == matchingNode->base)\r
{\r
- /* Reinsert left node and create a new node to left of range to be allocated */\r
- if (leftNode)\r
+ /* There may be a combine possibility to the left. Extract leftNode to check */\r
+ leftNode = RB_PREV(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ \r
+ /* Can the node to the left of the matchingNode be combined with the \r
+ * findNode's range? */\r
+ if (leftNode && (strcmp(leftNode->allocatedTo, opInfo->srcInstName) == 0))\r
{\r
- RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+ /* Remove the leftNode from the tree for editing */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+\r
+ /* Combine the leftNode and the findNode */\r
+ leftNode->length += findNode.length;\r
+ }\r
+ else\r
+ {\r
+ /* Allocate a new leftNode that will take the place of the findNode\r
+ * range in tree. */\r
+ leftNode = Rm_newResourceTreeNode(findNode.base, findNode.length,\r
+ opInfo->srcInstName);\r
}\r
- \r
- /* New left node attributes:\r
- * base: base of the matching node\r
- * length: base of requested resources - base of matching node */\r
- leftNode = Rm_newResourceTreeNode(matchingNode->base, findNode.base - matchingNode->base,\r
- RM_NOT_ALLOCATED_STRING);\r
- }\r
\r
- }\r
+ /* Account for the leftNode in the matchingNode */\r
+ matchingNode->base = findNode.base + findNode.length;\r
+ matchingNode->length = matchingEnd - findEnd; \r
\r
- /* Create the right node if needed. If the end ranges are equal the matchingNode\r
- * can be reused as the right bound of the range */\r
- if (findEnd < matchingEnd)\r
- {\r
- /* Can the right node be combined with the node to the right of the matching\r
- * node */\r
- if (rightNode && (strcmp(rightNode->allocatedTo, opInfo->srcInstName) == 0))\r
- {\r
- /* Combine the right node and what's leftover on the right side of the \r
- * matchingNode range after the allocation */\r
- rightNode->base = findNode.base + findNode.length;\r
- rightNode->length += (matchingEnd - findEnd);\r
+ /* Insert the left node */\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
}\r
- else\r
+ else if (findEnd == matchingEnd)\r
{\r
- /* Reinsert right node and create a new node to right of range to be allocated */\r
- if (rightNode)\r
+ /* There may be a combine possibility to the right. Extract rightNode to check */\r
+ rightNode = RB_NEXT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ \r
+ /* Can the node to the right of the matchingNode be combined with the \r
+ * findNode's range? */\r
+ if (rightNode && (strcmp(rightNode->allocatedTo, opInfo->srcInstName) == 0))\r
{\r
- RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+ /* Remove the rightNode from the tree for editing */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+\r
+ /* Combine the rightNode and the findNode */\r
+ rightNode->base = findNode.base;\r
+ rightNode->length += findNode.length;\r
+ }\r
+ else\r
+ {\r
+ /* Allocate a new rightNode that will take the place of the findNode\r
+ * range in tree. */\r
+ rightNode = Rm_newResourceTreeNode(findNode.base, findNode.length,\r
+ opInfo->srcInstName);\r
}\r
- \r
- /* New right node attributes:\r
- * base: base of the requested resources + length of requested resources\r
- * length: right bound of matching node - right bound of request resources */\r
- rightNode = Rm_newResourceTreeNode(findNode.base + findNode.length,\r
- matchingEnd - findEnd, RM_NOT_ALLOCATED_STRING);\r
- }\r
- }\r
\r
- /* Reinsert the left node into the tree if it was modified or created. */\r
- if (leftNode)\r
- {\r
- RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
- }\r
- /* Reinsert the right node into the tree if it was modified or created. */\r
- if (rightNode)\r
- {\r
- RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
- }\r
+ /* Account for the rightNode in the matchingNode */\r
+ matchingNode->length -= findNode.length; \r
\r
- /* Base and length of matching node becomes the base and length of the requested resources */\r
- matchingNode->base = findNode.base; \r
- matchingNode->length = findNode.length;\r
- /* Reserve the resources and insert them into the tree */\r
- strcpy(matchingNode->allocatedTo, opInfo->srcInstName);\r
- RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ /* Insert the right node */\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+ }\r
\r
+ /* Reinsert the edited matching node */\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ }\r
+ \r
retVal = RM_SERVICE_APPROVED_AND_COMPLETED;\r
}\r
else\r
* wipe any of the base+length data in the node. Can reuse since they won't\r
* be freed */\r
RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
- if (leftNode)\r
- {\r
- RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
- }\r
- if (rightNode)\r
- {\r
- RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
- }\r
\r
/* See if the left or right or both nodes can be combined with the matching\r
* node that will be freed. */\r
if (leftNode && (strcmp(leftNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0))\r
{\r
/* Combine the left node and the matching node */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
combineLeft = TRUE;\r
}\r
if (rightNode && (strcmp(rightNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0))\r
{\r
/* Combine the right node and the matching node */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
combineRight = TRUE;\r
}\r
\r
strcpy(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING);\r
RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode); \r
}\r
- else\r
+ else if ((findNode.base > matchingNode->base) && (findEnd < matchingEnd))\r
{\r
/* Case 2: free range is less than range in matched node. Need to split\r
* the matched node into three nodes.\r
* |<---free request--->|\r
*/ \r
\r
- /* Create the left node if needed. If the bases are equal the matchingNode can\r
- * be reused as the left bound of the range. */\r
- if (findNode.base > matchingNode->base)\r
- {\r
- /* New left node attributes:\r
- * base: base of the matching node\r
- * length: base of requested resources - base of matching node */\r
- leftNode = Rm_newResourceTreeNode(matchingNode->base, findNode.base - matchingNode->base,\r
- matchingNode->allocatedTo); \r
- }\r
+ /* Remove matching node for editing. */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
\r
- /* Create the right node if needed. If the end ranges are equal the matchingNode\r
- * can be reused as the right bound of the range */\r
- if (findEnd < matchingEnd)\r
- { \r
- /* New right node attributes:\r
- * base: base of the requested resources + length of requested resources\r
- * length: right bound of matching node - right bound of request resources */\r
- rightNode = Rm_newResourceTreeNode(findNode.base + findNode.length,\r
- matchingEnd - findEnd, matchingNode->allocatedTo);\r
- }\r
+ /* New left node attributes:\r
+ * base: base of the matching node\r
+ * length: base of requested resources - base of matching node */\r
+ leftNode = Rm_newResourceTreeNode(matchingNode->base, findNode.base - matchingNode->base,\r
+ matchingNode->allocatedTo); \r
+ /* New right node attributes:\r
+ * base: base of the requested resources + length of requested resources\r
+ * length: right bound of matching node - right bound of request resources */\r
+ rightNode = Rm_newResourceTreeNode(findNode.base + findNode.length,\r
+ matchingEnd - findEnd, matchingNode->allocatedTo);\r
+\r
+ /* Insert the left and right nodes into the tree. */\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
\r
- /* Insert the left node into the tree if it was created. */\r
- if (leftNode)\r
+ /* Base and length of matching node become the base and length of the freed resources */\r
+ matchingNode->base = findNode.base; \r
+ matchingNode->length = findNode.length;\r
+ /* Free the resources and insert them into the tree */\r
+ strcpy(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING);\r
+ RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ }\r
+ else\r
+ {\r
+ /* Remove the matchingNode from the tree since it will be edited */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ \r
+ if (findNode.base == matchingNode->base)\r
{\r
+ /* Case 3: Free range is on left boundary of matched node. Try to \r
+ * combine the free range with the left node if free.\r
+ *\r
+ * |<---left node (free)--->||<----------matched node---------->|\r
+ * |<---findNode (free req)--->|\r
+ */ \r
+ \r
+ /* There may be a combine possibility to the left. Extract leftNode to check */\r
+ leftNode = RB_PREV(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ \r
+ /* Can the node to the left of the matchingNode be combined with the \r
+ * findNode's range? */\r
+ if (leftNode && (strcmp(leftNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0))\r
+ {\r
+ /* Remove the leftNode from the tree for editing */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
+\r
+ /* Combine the leftNode and the findNode */\r
+ leftNode->length += findNode.length;\r
+ }\r
+ else\r
+ {\r
+ /* Allocate a new leftNode that will take the place of the findNode\r
+ * range in tree. */\r
+ leftNode = Rm_newResourceTreeNode(findNode.base, findNode.length,\r
+ RM_NOT_ALLOCATED_STRING);\r
+ }\r
+\r
+ /* Account for the leftNode in the matchingNode */\r
+ matchingNode->base = findNode.base + findNode.length;\r
+ matchingNode->length = matchingEnd - findEnd; \r
+\r
+ /* Insert the left node */\r
RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, leftNode);\r
}\r
- /* Insert the right node into the tree if it was created. */\r
- if (rightNode)\r
+ else if (findEnd == matchingEnd)\r
{\r
+ /* Case 4: Free range is on right boundary of matched node. Try to \r
+ * combine the free range with the right node if free.\r
+ *\r
+ * |<----------matched node---------->||<---right node (free)--->|\r
+ * |<---findNode (free req)--->|\r
+ */ \r
+ \r
+ /* There may be a combine possibility to the right. Extract rightNode to check */\r
+ rightNode = RB_NEXT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
+ \r
+ /* Can the node to the right of the matchingNode be combined with the \r
+ * findNode's range? */\r
+ if (rightNode && (strcmp(rightNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0))\r
+ {\r
+ /* Remove the rightNode from the tree for editing */\r
+ RB_REMOVE(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
+\r
+ /* Combine the rightNode and the findNode */\r
+ rightNode->base = findNode.base;\r
+ rightNode->length += findNode.length;\r
+ }\r
+ else\r
+ {\r
+ /* Allocate a new rightNode that will take the place of the findNode\r
+ * range in tree. */\r
+ rightNode = Rm_newResourceTreeNode(findNode.base, findNode.length,\r
+ RM_NOT_ALLOCATED_STRING);\r
+ }\r
+\r
+ /* Account for the rightNode in the matchingNode */\r
+ matchingNode->length -= findNode.length; \r
+\r
+ /* Insert the right node */\r
RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, rightNode);\r
}\r
\r
- /* Base and length of matching node becomes the base and length of the freed resources */\r
- matchingNode->base = findNode.base; \r
- matchingNode->length = findNode.length;\r
- /* Free the resources and insert them into the tree */\r
- strcpy(matchingNode->allocatedTo, RM_NOT_ALLOCATED_STRING);\r
+ /* Reinsert the edited matching node */\r
RB_INSERT(_Rm_ResourceTree, allocator->allocatorRootEntry, matchingNode);\r
}\r
\r
/* The matching allocated range to be freed was allocated to a different instance. */\r
retVal = RM_SERVICE_DENIED_RESOURCE_NOT_ALLOCATED_TO_INSTANCE_REQUESTING_THE_SERVICE;\r
}\r
-\r
}\r
else\r
{\r
\r
if (allocator)\r
{\r
- /* Call the allocator's type-based allocation function */\r
- if(allocator->type == Rm_allocatorType_INTEGER)\r
+ /* Call the allocator's function */\r
+ if (opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE)\r
{\r
- if (opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE)\r
- {\r
- retVal = Rm_integerPreAllocate(allocator, opInfo);\r
- } \r
- else if (opInfo->operation == Rm_allocatorOp_ALLOCATE)\r
- {\r
- retVal = Rm_integerAllocate(allocator, opInfo);\r
- }\r
- else if (opInfo->operation == Rm_allocatorOp_FREE)\r
- {\r
- retVal = Rm_integerFree(allocator, opInfo);\r
- }\r
+ retVal = Rm_treePreAllocate(allocator, opInfo);\r
+ } \r
+ else if (opInfo->operation == Rm_allocatorOp_ALLOCATE)\r
+ {\r
+ retVal = Rm_treeAllocate(allocator, opInfo);\r
}\r
- else if (allocator->type == Rm_allocatorType_TREE)\r
+ else if (opInfo->operation == Rm_allocatorOp_FREE)\r
{\r
- if (opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE)\r
- {\r
- retVal = Rm_treePreAllocate(allocator, opInfo);\r
- } \r
- else if (opInfo->operation == Rm_allocatorOp_ALLOCATE)\r
- {\r
- retVal = Rm_treeAllocate(allocator, opInfo);\r
- }\r
- else if (opInfo->operation == Rm_allocatorOp_FREE)\r
- {\r
- retVal = Rm_treeFree(allocator, opInfo);\r
- } \r
- } \r
+ retVal = Rm_treeFree(allocator, opInfo);\r
+ } \r
}\r
else\r
{\r
\r
void Rm_allocationHandler (Rm_Inst *rmInst, Rm_Transaction *transaction)\r
{\r
+ Rm_AllocatorOpInfo opInfo;\r
+ int32_t retVal = transaction->state;\r
+\r
+ /* Initialize the opInfo structure */\r
+ memset((void *)&opInfo, 0, sizeof(Rm_AllocatorOpInfo));\r
+ \r
if (rmInst->instType == Rm_instType_CLIENT_DELEGATE)\r
{\r
-#if 0 \r
+ /* TEMP: For now forward all allocations to the RM Server */\r
+ Rm_transactionForwarder(rmInst, transaction);\r
+ \r
+#if 0 /* Policy psuedo-code. Will be implemented after basic allocate functionality is ready and tested */ \r
if (resourceBase is unspecified)\r
{\r
while (policy does not approve)\r
}\r
else if (rmInst->instType == Rm_instType_SERVER)\r
{\r
-#if 0 \r
+ /* TEMP: If resource properties are unspecified allocate the next available.\r
+ * If resource properties are specified allocate if they are available. */\r
+\r
+ /* Fill out the allocator operation general information */\r
+ opInfo.resourceInfo = &transaction->resourceInfo;\r
+ opInfo.srcInstName = transaction->sourceInstName;\r
+\r
+ if (strlen(transaction->resourceInfo.nsName) > 0)\r
+ {\r
+ /* See if a NameServer name is being used to allocate a resource */\r
+ if (transaction->resourceInfo.base != 0)\r
+ {\r
+ /* A name and a value cannot be specified for the request. It's one\r
+ * or the other. */\r
+ retVal = RM_SERVICE_ERROR_NAMESERVER_NAME_AND_RESOURCE_RANGE_BOTH_DEFINED;\r
+ }\r
+ else\r
+ {\r
+ /* Get the resource information from the NameServer */\r
+ retVal = Rm_nsFindObject(rmInst, opInfo.resourceInfo);\r
+ }\r
+ }\r
+ else if (transaction->resourceInfo.base == RM_RESOURCE_BASE_UNSPECIFIED)\r
+ {\r
+ /* Execute the allocator pre-allocate operation to get the next available resources.\r
+ * NORMALLY CHECKED AGAINST THE POLICY */\r
+ opInfo.operation = Rm_allocatorOp_PRE_ALLOCATE;\r
+ \r
+ if (transaction->resourceInfo.alignment == RM_RESOURCE_ALIGNMENT_UNSPECIFIED)\r
+ { \r
+ /* TEMP: Default resource alignment of 1 if the resource alignment is not\r
+ * specified */\r
+ opInfo.policyAlignment = 1;\r
+ }\r
+ else\r
+ {\r
+ opInfo.policyAlignment = transaction->resourceInfo.alignment;\r
+ }\r
+\r
+ /* opInfo.policyBase = comes from policy once implemented */\r
+ opInfo.policyLength = transaction->resourceInfo.length;\r
+\r
+ /* If the pre-allocate operation succeeds the resourceInfo field pointed to\r
+ * by opInfo will contain the next available resources taht satisfy the\r
+ * resource properties */\r
+ retVal = Rm_allocatorOperation(rmInst, &opInfo);\r
+ }\r
+\r
+ /* Call allocator as long as an error or denial hasn't occurred */\r
+ if (retVal == RM_SERVICE_PROCESSING)\r
+ {\r
+ opInfo.operation = Rm_allocatorOp_ALLOCATE;\r
+\r
+ retVal = Rm_allocatorOperation(rmInst, &opInfo);\r
+ }\r
+\r
+ transaction->state = retVal;\r
+\r
+ if (strcmp(transaction->sourceInstName, rmInst->name))\r
+ {\r
+ /* Source of allocation was not the server instance, provide the transaction\r
+ * to the transaction responder */\r
+ Rm_transactionResponder(rmInst, transaction);\r
+ }\r
+ /* Otherwise let the return stack return the transaction to the serviceHandler */ \r
+\r
+#if 0 /* Policy psuedo-code. Will be implemented after basic allocate functionality is ready and tested */ \r
if (resourceBase is unspecified)\r
{\r
while (policy does not approve)\r
\r
void Rm_freeHandler (Rm_Inst *rmInst, Rm_Transaction *transaction)\r
{\r
+ Rm_AllocatorOpInfo opInfo;\r
+ int32_t retVal = transaction->state;\r
+ \r
if (rmInst->instType == Rm_instType_CLIENT_DELEGATE)\r
{\r
-#if 0 \r
+ /* TEMP: Forward all free requests to the Server */\r
+ Rm_transactionForwarder(rmInst, transaction);\r
+ \r
+#if 0 /* Policy psuedo-code. Will be implemented after basic allocate functionality is ready and tested */ \r
/* Check local policy to see if the request can be satisfied with the\r
* resources stored locally */\r
Rm_policy...API()\r
}\r
else if (rmInst->instType == Rm_instType_SERVER)\r
{\r
-#if 0 \r
+ /* TEMP: Free the resources if resources are allocated to the source instance. */\r
+\r
+ /* Fill out the allocator operation general information */\r
+ opInfo.resourceInfo = &transaction->resourceInfo;\r
+ opInfo.srcInstName = transaction->sourceInstName;\r
+\r
+ if (strlen(transaction->resourceInfo.nsName) > 0)\r
+ {\r
+ /* See if a NameServer name is being used to allocate a resource */\r
+ if (transaction->resourceInfo.base != 0)\r
+ {\r
+ /* A name and a value cannot be specified for the request. It's one\r
+ * or the other. */\r
+ retVal = RM_SERVICE_ERROR_NAMESERVER_NAME_AND_RESOURCE_RANGE_BOTH_DEFINED;\r
+ }\r
+ else\r
+ {\r
+ /* Get the resource information from the NameServer */\r
+ retVal = Rm_nsFindObject(rmInst, opInfo.resourceInfo);\r
+ }\r
+ }\r
+ \r
+ /* Call allocator as long as an error or denial hasn't occurred */\r
+ if (retVal == RM_SERVICE_PROCESSING)\r
+ {\r
+ opInfo.operation = Rm_allocatorOp_FREE;\r
+\r
+ retVal = Rm_allocatorOperation(rmInst, &opInfo);\r
+ }\r
+\r
+ transaction->state = retVal;\r
+\r
+ if (strcmp(transaction->sourceInstName, rmInst->name))\r
+ {\r
+ /* Source of allocation was not the server instance, provide the transaction\r
+ * to the transaction responder */\r
+ Rm_transactionResponder(rmInst, transaction);\r
+ }\r
+ /* Otherwise let the return stack return the transaction to the serviceHandler */ \r
+ \r
+#if 0 /* Policy psuedo-code. Will be implemented after basic allocate functionality is ready and tested */ \r
/* Check global policy to see if resource can be freed. return result\r
* no matter what */\r
Rm_policy...API()\r
* instance. Send the response via the service responder. */\r
Rm_serviceResponder(rmInst, transaction); \r
}\r
-#endif \r
- } \r
+#endif \r
+ } \r
+}\r
+\r
+/* Function used to send RM response transactions to lower level agents */\r
+void Rm_transactionResponder (Rm_Inst *rmInst, Rm_Transaction *transaction)\r
+{\r
+ Rm_TransportNode *dstTransportNode = NULL;\r
+ Rm_Packet *rmPkt = NULL;\r
+\r
+ /* Find the transport for the RM instance that sent the request. */\r
+ dstTransportNode = Rm_transportNodeFindRemoteName(rmInst, transaction->sourceInstName);\r
+\r
+ /* Create a RM packet using the service information */\r
+ switch (transaction->type)\r
+ {\r
+ case Rm_service_RESOURCE_ALLOCATE:\r
+ case Rm_service_RESOURCE_FREE:\r
+ case Rm_service_RESOURCE_GET_BY_NAME:\r
+ rmPkt = Rm_transportCreateResourceResponsePkt(rmInst, dstTransportNode, \r
+ transaction);\r
+ break;\r
+ case Rm_service_RESOURCE_MAP_TO_NAME:\r
+ case Rm_service_RESOURCE_UNMAP_NAME:\r
+ rmPkt = Rm_transportCreateNsResponsePkt(rmInst, dstTransportNode,\r
+ transaction);\r
+ break;\r
+ default:\r
+ /* Invalid service type. Flag the error and return */\r
+ transaction->state = RM_SERVICE_ERROR_INVALID_SERVICE_TYPE;\r
+ break;\r
+ }\r
+\r
+ if (transaction->state <= RM_SERVICE_ERROR_BASE)\r
+ {\r
+ /* Delete the transaction and return immediately because an error occurred \r
+ * allocating the packet */\r
+ Rm_transactionQueueDelete(rmInst, transaction->localId);\r
+ return;\r
+ }\r
+\r
+ /* Send the RM packet to the application transport */\r
+ if (rmInst->transport.rmSend((Rm_TransportHandle) dstTransportNode, rmPkt) < RM_TRANSPORT_SUCCESSFUL)\r
+ {\r
+ /* Negative value returned by transport send. An error occurred\r
+ * in the transport while attempting to send the packet.*/\r
+ transaction->state = RM_SERVICE_ERROR_TRANPSPORT_SEND_ERROR;\r
+ /* Clean up the packet */\r
+ if (rmInst->transport.rmFreePkt((Rm_TransportHandle) dstTransportNode, rmPkt))\r
+ {\r
+ /* Non-NULL value returned by transport packet free. Flag the\r
+ * error */\r
+ transaction->state = RM_SERVICE_ERROR_TRANSPORT_FREE_PKT_ERROR;\r
+ }\r
+ return;\r
+ }\r
+\r
+ /* NEED TO DO SOMETHING IF GET AN ERROR IN THE transaction->state FIELD. CREATE\r
+ * NEW TRANSACTION WITH DATA FROM ORIGINAL? THEN TRY TO SEND FAILED REQUEST BACK\r
+ * TO REQUESTER??? KEEP RETRYING SEND OF RESPONSE??? */\r
+\r
+ /* Delete the transaction */\r
+ Rm_transactionQueueDelete(rmInst, transaction->localId);\r
}\r
\r
/* Function used to forward RM transactions to higher level agents */\r
if (rmInst->instType == Rm_instType_CLIENT)\r
{\r
dstTransportNode = Rm_transportNodeFindRemoteInstType(rmInst, Rm_instType_CLIENT_DELEGATE);\r
+\r
+ if (!dstTransportNode)\r
+ {\r
+ /* No Client Delegate connection found. Check for a Server connection */\r
+ dstTransportNode = Rm_transportNodeFindRemoteInstType(rmInst, Rm_instType_SERVER);\r
+ }\r
} \r
else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE)\r
{\r
switch (transaction->type)\r
{\r
case Rm_service_RESOURCE_ALLOCATE:\r
- case Rm_service_RESOURCE_BLOCK_ALLOCATE:\r
- case Rm_service_RESOURCE_ALLOCATE_BY_NAME:\r
case Rm_service_RESOURCE_FREE:\r
- case Rm_service_RESOURCE_BLOCK_FREE:\r
- case Rm_service_RESOURCE_FREE_BY_NAME:\r
+ case Rm_service_RESOURCE_GET_BY_NAME:\r
rmPkt = Rm_transportCreateResourceReqPkt(rmInst, dstTransportNode, \r
transaction);\r
break;\r
@@ -1781,146 +1477,521 @@ void Rm_transactionForwarder (Rm_Inst *rmInst, Rm_Transaction *transaction)
return;\r
}\r
\r
- /* Transaction is not deleted because it is awaiting a response from the higher level\r
- * RM instance */\r
+ /* Transaction is not deleted because it is awaiting a response from the higher level\r
+ * RM instance */\r
+}\r
+\r
+void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction)\r
+{\r
+ /* Handle auto-forwarded transactions. These transactions include:\r
+ * - All request transactions received on Clients are forwarded to the Client Delegate\r
+ * - NameServer requests received on the Client Delegate are forwarded to the Server */\r
+ if ((rmInst->instType == Rm_instType_CLIENT) ||\r
+ ((rmInst->instType == Rm_instType_CLIENT_DELEGATE) &&\r
+ ((transaction->type == Rm_service_RESOURCE_MAP_TO_NAME) ||\r
+ (transaction->type == Rm_service_RESOURCE_GET_BY_NAME) ||\r
+ (transaction->type == Rm_service_RESOURCE_UNMAP_NAME))))\r
+ { \r
+ /* Check if the transaction is a transaction that received a response to its\r
+ * request. */\r
+ if (transaction->state != RM_SERVICE_PROCESSING)\r
+ {\r
+\r
+ /* A transaction has received a response. Send the response to either the \r
+ * transaction or service responder based on the source instance */\r
+ if (strcmp(transaction->sourceInstName, rmInst->name))\r
+ {\r
+ /* Transaction originated from another instance. Use the \r
+ * transaction responder to send the result to the source instance. This\r
+ * is not possible on RM Clients since they can't forward RM services */\r
+ Rm_transactionResponder(rmInst, transaction);\r
+ }\r
+ else\r
+ {\r
+ /* Transaction originated on this instance. Send to the\r
+ * service responder */\r
+ Rm_serviceResponder(rmInst, transaction);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* This is a new transaction that must be forwarded to a higher level RM instance. */\r
+ Rm_transactionForwarder(rmInst, transaction);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* Client Delegate and Server transaction processors. */\r
+ switch (transaction->type)\r
+ {\r
+ case Rm_service_RESOURCE_ALLOCATE:\r
+ case Rm_service_RESOURCE_FREE: \r
+ /* Check if the transaction is fulfilled request */\r
+ if (transaction->state != RM_SERVICE_PROCESSING)\r
+ {\r
+ /* If source instance name does not match the current instance\r
+ * name the allocation request came from a client. The result\r
+ * must be sent back to the Client */\r
+ if (strcmp(transaction->sourceInstName, rmInst->name))\r
+ {\r
+ Rm_transactionResponder(rmInst, transaction);\r
+ }\r
+ else\r
+ {\r
+ /* Resource allocation request originated locally. Send the response\r
+ * via the service responder. */\r
+ Rm_serviceResponder(rmInst, transaction); \r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* This is a new transaction request originating from an RM instance with fewer\r
+ * allocate/free privileges. Run the allocation or free handler to see if the resource\r
+ * request can be handled locally or if it needs to be forwarded to a higher level\r
+ * agent */\r
+ if (transaction->type == Rm_service_RESOURCE_ALLOCATE)\r
+ {\r
+ Rm_allocationHandler(rmInst, transaction);\r
+ }\r
+ else\r
+ {\r
+ Rm_freeHandler(rmInst, transaction);\r
+ }\r
+ }\r
+ break;\r
+ case Rm_service_RESOURCE_MAP_TO_NAME:\r
+ case Rm_service_RESOURCE_GET_BY_NAME:\r
+ case Rm_service_RESOURCE_UNMAP_NAME: \r
+ /* Server is the only RM instance capable of adding NameServer objects */\r
+ if (rmInst->instType == Rm_instType_SERVER)\r
+ {\r
+ if (transaction->type == Rm_service_RESOURCE_MAP_TO_NAME)\r
+ {\r
+ /* Create a new NameServer object with the request transaction information.\r
+ * Transaction will contain the state result of the NameServer addition. */\r
+ if (Rm_nsAddObject(rmInst, &transaction->resourceInfo) == RM_NS_ACTION_APPROVED)\r
+ {\r
+ transaction->state = RM_SERVICE_APPROVED_AND_COMPLETED;\r
+ }\r
+ else\r
+ {\r
+ /* TEMP: UPDATE THIS STATE VALUE */\r
+ transaction->state = RM_SERVICE_DENIED_BEGIN;\r
+ }\r
+ }\r
+ else if (transaction->type == Rm_service_RESOURCE_GET_BY_NAME)\r
+ {\r
+ /* Create a new NameServer object with the request transaction information.\r
+ * Transaction will contain the state result of the NameServer addition. */\r
+ if (Rm_nsFindObject(rmInst, &transaction->resourceInfo) == RM_NS_ACTION_APPROVED)\r
+ {\r
+ transaction->state = RM_SERVICE_APPROVED_AND_COMPLETED;\r
+ }\r
+ else\r
+ {\r
+ /* TEMP: UPDATE THIS STATE VALUE */\r
+ transaction->state = RM_SERVICE_DENIED_BEGIN;\r
+ } \r
+ }\r
+ else\r
+ {\r
+ /* Delete an existing NameServer object with the request transaction information\r
+ * Transaction will contain the state result of the NameServer addition. */\r
+ if (Rm_nsDeleteObject(rmInst, &transaction->resourceInfo) == \r
+ RM_NS_ACTION_APPROVED)\r
+ {\r
+ transaction->state = RM_SERVICE_APPROVED_AND_COMPLETED;\r
+ }\r
+ else\r
+ {\r
+ /* TEMP: UPDATE THIS STATE VALUE */\r
+ transaction->state = RM_SERVICE_DENIED_BEGIN;\r
+ }\r
+ }\r
+\r
+ /* If source instance name does not match the local instance\r
+ * name the NameServer request came from a Client or Client Delegate. The \r
+ * result must be sent back to the Client or Client Delegate. Just return if it does\r
+ * match since the NameServer transaction result can be returned immediately by the\r
+ * Rm_serviceHandler. */\r
+ if (strcmp(transaction->sourceInstName, rmInst->name))\r
+ {\r
+ Rm_transactionResponder(rmInst, transaction);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ transaction->state = RM_SERVICE_ERROR_NAMESERVER_OBJECT_MOD_ON_INVALID_INSTANCE;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+int32_t Rm_reserveLinuxResource(Rm_Inst *rmInst, Rm_LinuxAlias *linuxAlias, \r
+ Rm_LinuxValueRange *linuxValues, Rm_AllocatorOpInfo *opInfo)\r
+{\r
+ int32_t retVal = RM_DTB_UTIL_RESULT_OKAY;\r
+ bool baseFound = FALSE;\r
+ bool lengthFound = FALSE;\r
+ uint32_t valueIndex = 0;\r
+\r
+ while ((linuxValues != NULL) && (!baseFound || !lengthFound))\r
+ {\r
+ if (linuxAlias->baseOffset == valueIndex)\r
+ {\r
+ /* Found the resource base. Store it in the operation info structure */\r
+ opInfo->resourceInfo->base = linuxValues->value;\r
+ baseFound = TRUE;\r
+\r
+ /* length will always be 1 if there is no length specified in the Linux DTB */\r
+ if (linuxAlias->lengthOffset == RM_DTB_LINUX_ALIAS_OFFSET_NOT_SET)\r
+ {\r
+ opInfo->resourceInfo->length = 1;\r
+ lengthFound = TRUE;\r
+ }\r
+ }\r
+ else if (linuxAlias->lengthOffset == valueIndex)\r
+ {\r
+ /* Found the resource length. Store it in the operation info structure */\r
+ opInfo->resourceInfo->length = linuxValues->value;\r
+ lengthFound = TRUE;\r
+ }\r
+\r
+ linuxValues = (Rm_LinuxValueRange *)linuxValues->nextValue;\r
+ valueIndex++;\r
+ }\r
+\r
+ if (!baseFound || !lengthFound)\r
+ {\r
+ retVal = -33; /* TODO: ERROR BASE OR LENGTH OFFSET IN LINUX DTB WAS INCORRECT */\r
+ }\r
+ else\r
+ {\r
+ /* Allocate the resource to Linux */\r
+ retVal = Rm_allocatorOperation(rmInst, opInfo);\r
+ }\r
+\r
+ return (retVal);\r
+}\r
+\r
+int32_t Rm_findAndReserveLinuxResource(Rm_Inst *rmInst, const char *resourceName, void *linuxDtb, \r
+ Rm_LinuxAlias *linuxAlias)\r
+{\r
+ Rm_AllocatorOpInfo opInfo;\r
+ Rm_ResourceInfo resourceInfo;\r
+ uint32_t pathOffset;\r
+ int32_t propOffset;\r
+ int32_t nodeOffset = RM_DTB_UTIL_STARTING_NODE_OFFSET;\r
+ int32_t prevDepth = RM_DTB_UTIL_STARTING_DEPTH;\r
+ int32_t depth;\r
+ int32_t propertyLen;\r
+ const char *propertyName;\r
+ const void *propertyData; \r
+ Rm_LinuxValueRange *linuxValueRange;\r
+ int32_t retVal = RM_DTB_UTIL_RESULT_OKAY; \r
+\r
+ /* Initialize the allocator opInfo and resourceInfo structures that will be used to \r
+ * reserve the resources taken by the Linux kernel */\r
+ memset((void *) &opInfo, 0, sizeof(Rm_AllocatorOpInfo));\r
+ memset((void *) &resourceInfo, 0, sizeof(Rm_ResourceInfo));\r
+\r
+ strcpy(resourceInfo.name, resourceName);\r
+\r
+ /* Set the source instance name for allocation to be the Linux Kernel */\r
+ opInfo.srcInstName = RM_ALLOCATED_TO_LINUX;\r
+ opInfo.operation = Rm_allocatorOp_ALLOCATE;\r
+ opInfo.resourceInfo = &resourceInfo; \r
+\r
+ /* Find each resource specified in the Linux resource alias list and reserve that \r
+ * resource as used */\r
+ while(linuxAlias != NULL)\r
+ {\r
+ /* Reset the parsing variables */\r
+ pathOffset = 0;\r
+ nodeOffset = RM_DTB_UTIL_STARTING_NODE_OFFSET;\r
+ prevDepth = RM_DTB_UTIL_STARTING_DEPTH; \r
+ resourceInfo.base = 0;\r
+ resourceInfo.length = 0;\r
+ \r
+ while(pathOffset < linuxAlias->pathListLenBytes)\r
+ {\r
+ /* Move through the DTB nodes until the next alias path node is found */\r
+ if (strcmp(linuxAlias->pathList + pathOffset, fdt_get_name(linuxDtb, nodeOffset, NULL)))\r
+ {\r
+ nodeOffset = fdt_next_node(linuxDtb, nodeOffset, &depth);\r
+\r
+ if (depth < prevDepth)\r
+ {\r
+ /* Returning from subnode that matched part of alias path without finding\r
+ * the resource values */\r
+ retVal = (-31); /* TODO: COULD NOT FIND RESOURCE AT ALIAS PATH */\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* Found the next alias path node */\r
+ pathOffset += (strlen(linuxAlias->pathList + pathOffset) + 1);\r
+ prevDepth = fdt_node_depth(linuxDtb, nodeOffset);\r
+\r
+ /* Check the properties of the node to see if they match the next alias\r
+ * path string */\r
+ propOffset = fdt_first_property_offset(linuxDtb, nodeOffset);\r
+ \r
+ /* Search the properties for the next alias path string */\r
+ while ((propOffset >= RM_DTB_UTIL_STARTING_NODE_OFFSET) &&\r
+ (pathOffset < linuxAlias->pathListLenBytes))\r
+ {\r
+ propertyData = fdt_getprop_by_offset(linuxDtb, propOffset, \r
+ &propertyName, &propertyLen);\r
+\r
+ if (strcmp(linuxAlias->pathList + pathOffset, propertyName) == 0)\r
+ {\r
+ pathOffset += (strlen(linuxAlias->pathList + pathOffset) + 1);\r
+ /* Found the alias property. Extract the values that will\r
+ * contain the resource information that must be reserved. */\r
+ linuxValueRange = Rm_linuxExtractValues(propertyData, propertyLen);\r
+ /* Use the values to reserve resources for the Linux kernel */\r
+ retVal = Rm_reserveLinuxResource(rmInst, linuxAlias, \r
+ linuxValueRange, &opInfo);\r
+ \r
+ /* Free the memory used to store the values */\r
+ Rm_linuxFreeValues(linuxValueRange);\r
+ }\r
+ \r
+ propOffset = fdt_next_property_offset(linuxDtb, propOffset);\r
+ } \r
+\r
+ if (propOffset < -FDT_ERR_NOTFOUND)\r
+ {\r
+ /* Error was returned by LIBFDT when parsing the properties */\r
+ retVal = propOffset;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (retVal < RM_DTB_UTIL_RESULT_OKAY)\r
+ {\r
+ /* Error occurred during parsing of Linux DTB. Return the error */\r
+ break;\r
+ }\r
+ linuxAlias = (Rm_LinuxAlias *) linuxAlias->nextLinuxAlias;\r
+ }\r
+\r
+ return (retVal);\r
+}\r
+\r
+int32_t Rm_createAndInitAllocator(Rm_Inst *rmInst, const char *resourceName, \r
+ Rm_ResourceProperties *resourceProperties, void *linuxDtb)\r
+{\r
+ Rm_ResourceRange *range = NULL;\r
+ Rm_ResourceRange *rangeBasePtr = NULL;\r
+ Rm_NsAssignment *nsAssignments = NULL;\r
+ Rm_NsAssignment *nsAssignmentBasePtr = NULL;\r
+ Rm_LinuxAlias *linuxAlias = NULL;\r
+ Rm_ResourceInfo resourceInfo;\r
+ int32_t retVal = RM_DTB_UTIL_RESULT_OKAY;\r
+\r
+ if (resourceProperties->rangeData && (resourceProperties->rangeLen > 0))\r
+ {\r
+ /* Extract the resource properties from the DTB */\r
+ range = rangeBasePtr = Rm_resourceExtractRange(resourceProperties->rangeData, \r
+ resourceProperties->rangeLen);\r
+\r
+ /* Create a tree allocator using the resource properties */\r
+ retVal = Rm_createTreeAllocator(rmInst, resourceName, range); \r
+\r
+ if (retVal >= RM_DTB_UTIL_RESULT_OKAY)\r
+ {\r
+ if (resourceProperties->linuxAliasData && resourceProperties->linuxAliasLen)\r
+ {\r
+ /* Reserve the resources taken by the Linux kernel specified in the Linux DTB */\r
+ linuxAlias = Rm_resourceExtractLinuxAlias(resourceProperties->linuxAliasData,\r
+ resourceProperties->linuxAliasLen);\r
+\r
+ retVal = Rm_findAndReserveLinuxResource(rmInst, resourceName, linuxDtb, linuxAlias); \r
+ }\r
+ }\r
+ }\r
+ \r
+ if (retVal >= RM_DTB_UTIL_RESULT_OKAY)\r
+ {\r
+ /* Create entries in the NameServer if any NameServer assignments were specified */\r
+ if (resourceProperties->nsAssignData && resourceProperties->nsAssignLen)\r
+ {\r
+ nsAssignments = Rm_resourceExtractNsAssignment(resourceProperties->nsAssignData, \r
+ resourceProperties->nsAssignLen);\r
+\r
+ /* Cycle through the list of assignments and add them to the NameServer */\r
+ nsAssignmentBasePtr = nsAssignments;\r
+ while (nsAssignments)\r
+ {\r
+ memset((void *)&resourceInfo, 0, sizeof(Rm_ResourceInfo));\r
+\r
+ resourceInfo.base = nsAssignments->resourceBase;\r
+ resourceInfo.length = nsAssignments->resourceLength;\r
+ strcpy(resourceInfo.nsName, nsAssignments->nsName);\r
+ \r
+ /* TODO: RETURN IF ANY OF THE ADDS FAIL??? */\r
+ Rm_nsAddObject(rmInst, &resourceInfo);\r
+ nsAssignments = nsAssignments->nextNsAssignment;\r
+ }\r
+ /* Free the memory allocated for the NameServer assignments */\r
+ Rm_resourceFreeNsAssignmentList(nsAssignmentBasePtr);\r
+ }\r
+ }\r
+\r
+ /* Free the memory allocated for the resource properties */\r
+ Rm_resourceFreeRange(rangeBasePtr);\r
+ Rm_resourceFreeLinuxAlias(linuxAlias);\r
+\r
+ return(retVal);\r
}\r
\r
-void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction)\r
+int32_t Rm_parseResourceProperty(void *globalResourceDtb, int32_t offset, Rm_ResourceProperties *propertyInfo)\r
{\r
- /* Handle auto-forwarded transactions. These transactions include:\r
- * - All request transactions received on Clients are forwarded to the Client Delegate\r
- * - NameServer requests received on the Client Delegate are forwarded to the Server */\r
- if ((rmInst->instType == Rm_instType_CLIENT) ||\r
- ((rmInst->instType == Rm_instType_CLIENT_DELEGATE) &&\r
- (transaction->type == Rm_service_RESOURCE_MAP_TO_NAME) ||\r
- (transaction->type == Rm_service_RESOURCE_UNMAP_NAME)))\r
+ int32_t propertyLen;\r
+ const char *propertyName;\r
+ const void *propertyData;\r
+ Rm_ResourcePropType propertyType;\r
+ int32_t retVal = RM_DTB_UTIL_RESULT_OKAY;\r
+\r
+ /* Get the property data and store it in the corresponding propertyInfo field */\r
+ propertyData = fdt_getprop_by_offset(globalResourceDtb, offset, &propertyName, &propertyLen);\r
+ if (propertyData)\r
{\r
- /* Check if the transaction is a transaction that received a response to its\r
- * request. */\r
- if (transaction->state != RM_SERVICE_PROCESSING)\r
+ propertyType = Rm_resourceGetPropertyType(propertyName);\r
+ if (propertyType == Rm_resourcePropType_RESOURCE_RANGE)\r
{\r
-\r
- /* A transaction has received a response. Send the response to either the \r
- * transaction or service responder based on the source instance */\r
- if (strcmp(transaction->sourceInstName, rmInst->name))\r
+ if (propertyInfo->rangeData || propertyInfo->rangeLen)\r
{\r
- /* Transaction originated from another instance. Use the \r
- * transaction responder to send the result to the source instance. This\r
- * is not possible on RM Clients since they can't forward RM services */\r
- Rm_transactionResponder(rmInst, transaction);\r
+ /* The range fields have already been populated. Return an error.\r
+ * The resource list has specified a property field more than once\r
+ * for a resource node */\r
+ retVal = -18; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
}\r
else\r
{\r
- /* Transaction originated on this instance. Send to the\r
- * service responder */\r
- Rm_serviceResponder(rmInst, transaction);\r
+ propertyInfo->rangeData = propertyData;\r
+ propertyInfo->rangeLen = propertyLen;\r
+ }\r
+ }\r
+ else if (propertyType == Rm_resourcePropType_NSASSIGNMENT)\r
+ {\r
+ if (propertyInfo->nsAssignData || propertyInfo->nsAssignLen)\r
+ {\r
+ /* The nsAssign fields have already been populated. Return an error.\r
+ * The resource list has specified a property field more than once\r
+ * for a resource node */\r
+ retVal = -19; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
+ }\r
+ else\r
+ {\r
+ propertyInfo->nsAssignData = propertyData;\r
+ propertyInfo->nsAssignLen = propertyLen;\r
}\r
}\r
+ else if (propertyType == Rm_resourcePropType_RESOURCE_LINUX_ALIAS)\r
+ {\r
+ if (propertyInfo->linuxAliasData || propertyInfo->linuxAliasLen)\r
+ {\r
+ /* The linuxAlias fields have already been populated. Return an error.\r
+ * The resource list has specified a property field more than once\r
+ * for a resource node */\r
+ retVal = -28; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
+ }\r
+ else\r
+ {\r
+ propertyInfo->linuxAliasData = propertyData;\r
+ propertyInfo->linuxAliasLen = propertyLen;\r
+ }\r
+ } \r
else\r
{\r
- /* This is a new transaction that must be forwarded to a higher level RM instance. */\r
- Rm_transactionForwarder(rmInst, transaction);\r
+ retVal = -20; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
}\r
}\r
else\r
{\r
- /* Client Delegate and Server transaction processors. */\r
- switch (transaction->type)\r
+ retVal = -16; /* TEMP ERROR: Can't conflict with LIBFDT errors */\r
+ }\r
+\r
+ /* Don't get anymore properties if error occurred */\r
+ if (retVal == RM_DTB_UTIL_RESULT_OKAY)\r
+ {\r
+ offset = fdt_next_property_offset(globalResourceDtb, offset);\r
+ if (offset >= 0)\r
+ {\r
+ retVal = Rm_parseResourceProperty(globalResourceDtb, offset, propertyInfo);\r
+ }\r
+ else if (offset != -FDT_ERR_NOTFOUND)\r
{\r
- case Rm_service_RESOURCE_ALLOCATE:\r
- case Rm_service_RESOURCE_BLOCK_ALLOCATE:\r
- case Rm_service_RESOURCE_ALLOCATE_BY_NAME:\r
- case Rm_service_RESOURCE_FREE:\r
- case Rm_service_RESOURCE_BLOCK_FREE:\r
- case Rm_service_RESOURCE_FREE_BY_NAME: \r
- /* Check if the transaction is fulfilled request */\r
- if (transaction->state != RM_SERVICE_PROCESSING)\r
- {\r
- /* If source instance name does not match the current instance\r
- * name the allocation request came from a client. The result\r
- * must be sent back to the Client */\r
- if (strcmp(transaction->sourceInstName, rmInst->name))\r
- {\r
- Rm_transactionResponder(rmInst, transaction);\r
- }\r
- else\r
- {\r
- /* Resource allocation request originated locally. Send the response\r
- * via the service responder. */\r
- Rm_serviceResponder(rmInst, transaction); \r
- }\r
- }\r
- else\r
- {\r
- /* This is a new transaction request originating from an RM instance with fewer\r
- * allocate/free privileges. Run the allocation or free handler to see if the resource\r
- * request can be handled locally or if it needs to be forwarded to a higher level\r
- * agent */\r
- if ((transaction->type == Rm_service_RESOURCE_ALLOCATE) ||\r
- (transaction->type == Rm_service_RESOURCE_BLOCK_ALLOCATE) ||\r
- (transaction->type == Rm_service_RESOURCE_ALLOCATE_BY_NAME))\r
- {\r
- Rm_allocationHandler(rmInst, transaction);\r
- }\r
- else\r
- {\r
- Rm_freeHandler(rmInst, transaction);\r
- }\r
- }\r
- break;\r
- case Rm_service_RESOURCE_MAP_TO_NAME:\r
- case Rm_service_RESOURCE_UNMAP_NAME: \r
- /* Server is the only RM instance capable of adding NameServer objects */\r
- if (rmInst->instType == Rm_instType_SERVER)\r
- {\r
- if (transaction->type == Rm_service_RESOURCE_MAP_TO_NAME)\r
- {\r
- /* Create a new NameServer object with the request transaction information.\r
- * Transaction will contain the state result of the NameServer addition. */\r
- if (Rm_nsAddObject(rmInst, transaction->resourceInfo.nsName,\r
- transaction->resourceInfo.base) == RM_NS_ACTION_APPROVED)\r
- {\r
- transaction->state = RM_SERVICE_APPROVED_AND_COMPLETED;\r
- }\r
- else\r
- {\r
- /* TEMP: UPDATE THIS STATE VALUE */\r
- transaction->state = RM_SERVICE_DENIED_BEGIN;\r
- }\r
- }\r
- else\r
- {\r
- /* Delete an existing NameServer object with the request transaction information\r
- * Transaction will contain the state result of the NameServer addition. */\r
- if (Rm_nsDeleteObject(rmInst, transaction->resourceInfo.nsName) == \r
- RM_NS_ACTION_APPROVED)\r
- {\r
- transaction->state = RM_SERVICE_APPROVED_AND_COMPLETED;\r
- }\r
- else\r
- {\r
- /* TEMP: UPDATE THIS STATE VALUE */\r
- transaction->state = RM_SERVICE_DENIED_BEGIN;\r
- }\r
- }\r
+ /* Error was returned by LIBFDT when parsing the properties */\r
+ retVal = offset;\r
+ }\r
+ }\r
+ \r
+ return (retVal);\r
+}\r
\r
- /* If source instance name does not match the local instance\r
- * name the NameServer request came from a Client or Client Delegate. The \r
- * result must be sent back to the Client or Client Delegate. Just return if it does\r
- * match since the NameServer transaction result can be returned immediately by the\r
- * Rm_serviceHandler. */\r
- if (strcmp(transaction->sourceInstName, rmInst->name))\r
- {\r
- Rm_transactionResponder(rmInst, transaction);\r
- }\r
- }\r
- else\r
- {\r
- transaction->state = RM_SERVICE_ERROR_NAMESERVER_OBJECT_MOD_ON_INVALID_INSTANCE;\r
- }\r
- break;\r
+int32_t Rm_parseResourceNode(Rm_Inst *rmInst, void *globalResourceDtb, int32_t nodeOffset, int32_t depth,\r
+ void *linuxDtb)\r
+{\r
+ const char *resourceName = fdt_get_name(globalResourceDtb, nodeOffset, NULL);\r
+ Rm_ResourceProperties resourceProperties;\r
+ int32_t error = RM_DTB_UTIL_RESULT_OKAY;\r
+ int32_t offset;\r
+\r
+ /* Initialize the resource properties structure */\r
+ memset((void *)&resourceProperties, 0, sizeof(Rm_ResourceProperties));\r
+\r
+ /* Ignore properties of the base node */\r
+ if (strcmp(resourceName, rmDtbStartingNode))\r
+ {\r
+ /* Get the properties for the resource node if any exist */\r
+ offset = fdt_first_property_offset(globalResourceDtb, nodeOffset);\r
+ if (offset >= RM_DTB_UTIL_STARTING_NODE_OFFSET)\r
+ {\r
+ /* Since at least one property exists attempt to parse the property nodes and \r
+ * use them to create and initialize a resource allocator */\r
+ error = Rm_parseResourceProperty(globalResourceDtb, offset, &resourceProperties);\r
+ if (error < -FDT_ERR_NOTFOUND)\r
+ {\r
+ return (error);\r
+ }\r
+ \r
+ /* Initialize an allocator with the resource properties if no error was returned */\r
+ Rm_createAndInitAllocator(rmInst, resourceName, &resourceProperties, linuxDtb);\r
+ }\r
+ else if (offset != -FDT_ERR_NOTFOUND)\r
+ {\r
+ /* Error was returned by LIBFDT when parsing the properties */\r
+ return (offset);\r
+ }\r
+ }\r
+ \r
+ /* Get the next resource node */\r
+ offset = fdt_next_node(globalResourceDtb, nodeOffset, &depth);\r
+ /* Check the offset and depth of the next node to make sure the current node\r
+ * wasn't the last node in the Resource List. A depth less than the depth set\r
+ * at the start of the recursion will signal the end of the resource list */\r
+ if ((offset >= RM_DTB_UTIL_STARTING_NODE_OFFSET) && (depth >= RM_DTB_UTIL_STARTING_DEPTH))\r
+ {\r
+ error = Rm_parseResourceNode(rmInst, globalResourceDtb, offset, depth, linuxDtb);\r
+ if (error < -FDT_ERR_NOTFOUND)\r
+ {\r
+ return (error);\r
}\r
}\r
+ else if (offset != -FDT_ERR_NOTFOUND)\r
+ {\r
+ /* Error was returned by LIBFDT when parsing the nodes */\r
+ return (offset);\r
+ }\r
+\r
+ return (RM_DTB_UTIL_RESULT_OKAY);\r
}\r
\r
int32_t Rm_initializeAllocators(Rm_Inst *rmInst, void *globalResourceDtb, void *linuxDtb)\r
@@ -1935,11 +2006,56 @@ int32_t Rm_initializeAllocators(Rm_Inst *rmInst, void *globalResourceDtb, void *
\r
return(result);\r
}\r
- \r
+ \r
/**********************************************************************\r
********************** Application visible APIs **********************\r
**********************************************************************/\r
\r
+/* Server Only */\r
+void Rm_printResourceStatus(Rm_Handle *rmHandle)\r
+{\r
+ Rm_Inst *rmInst = (Rm_Inst *) rmHandle;\r
+ Rm_Allocator *allocator = rmInst->allocators;\r
+ Rm_ResourceTree *treeRoot;\r
+ Rm_ResourceTreeNode *treeNode;\r
+ uint32_t numLinuxResources;\r
+\r
+ while (allocator != NULL)\r
+ {\r
+ numLinuxResources = 0;\r
+\r
+ Rm_osalLog("Resource: %s\n", allocator->resourceName);\r
+\r
+ treeRoot = allocator->allocatorRootEntry;\r
+\r
+ RB_FOREACH(treeNode, _Rm_ResourceTree, treeRoot)\r
+ { \r
+ Rm_osalLog(" %10d - %10d ", treeNode->base, \r
+ treeNode->base + treeNode->length -1);\r
+ \r
+ if (strcmp(treeNode->allocatedTo, RM_NOT_ALLOCATED_STRING) == 0)\r
+ {\r
+ Rm_osalLog("NOT ALLOCATED\n");\r
+ }\r
+ else\r
+ {\r
+ Rm_osalLog("allocated to %s\n", treeNode->allocatedTo);\r
+ }\r
+\r
+ if (strcmp(treeNode->allocatedTo, RM_ALLOCATED_TO_LINUX) == 0)\r
+ {\r
+ numLinuxResources += treeNode->length;\r
+ }\r
+ }\r
+ \r
+ Rm_osalLog("Total allocated to Linux: %d\n", numLinuxResources);\r
+ \r
+ allocator = allocator->nextAllocator;\r
+ }\r
+\r
+ Rm_nsPrintObjects(rmInst);\r
+}\r
+\r
Rm_Handle Rm_init(Rm_InitCfg *initCfg)\r
{\r
Rm_Inst *rmInst;\r
* for allocation to clients. */\r
rmInst->allocators = NULL;\r
\r
+ /* Initialize the NameServer pointer to NULL. The NameServer should only be located\r
+ * on the RM Server */\r
+ rmInst->nameServer = NULL;\r
+\r
/* Initialize the transaction queue elements. */\r
rmInst->transactionSeqNum = Rm_transactionInitSequenceNum();\r
rmInst->transactionQueue= NULL;\r
/* RM Server specific actions */\r
if (rmInst->instType == Rm_instType_SERVER)\r
{\r
+ /* Initialize the NameServer */\r
+ Rm_nsInit(rmInst);\r
+ \r
/* Open the ResourceList file and provide it to the resource initializer. The Linux\r
* DTB will be parsed simultaneously for resource's consumed by the kernel. The resources\r
* used by the kernel will be marked as used in the resource allocators. */\r