diff --git a/src/rm_policy.c b/src/rm_policy.c
index 8e2e34b3eff40a5e512e35e85f7157d99a076654..11c10f0ab8a1f3f39439091c99773581e573db35 100644 (file)
--- a/src/rm_policy.c
+++ b/src/rm_policy.c
#include <ti/drv/rm/rm.h>
/* RM internal API includes */
+#include <ti/drv/rm/include/rm_internal.h>
+#include <ti/drv/rm/include/rm_loc.h>
#include <ti/drv/rm/include/rm_allocatorloc.h>
#include <ti/drv/rm/include/rm_policyloc.h>
#include <ti/drv/rm/include/rm_dtb_utilloc.h>
******************** Local Policy Functions **************************
**********************************************************************/
+/* FUNCTION PURPOSE: Returns a pointer to the valid instance tree
+ ***********************************************************************
+ * DESCRIPTION: Returns a pointer to the instance's valid instance
+ * tree based on the instance type
+ */
+static Rm_PolicyValidInstTree *policyGetValidInstTree(Rm_Handle rmHandle)
+{
+ Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
+ Rm_PolicyValidInstTree *tree = NULL;
+
+ if ((rmInst->instType == Rm_instType_SERVER) ||
+ (rmInst->instType == Rm_instType_SHARED_SERVER)) {
+ tree = rmInst->u.server.globalValidInstTree;
+ }
+ else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
+ tree = rmInst->u.cd.staticValidInstTree;
+ }
+ else if (rmInst->instType == Rm_instType_CLIENT) {
+ tree = rmInst->u.client.staticValidInstTree;
+ }
+ return(tree);
+}
+
/* FUNCTION PURPOSE: Validates the instance names in a permissions string
***********************************************************************
* DESCRIPTION: Returns RM_OK if all the instance names in a permissions
* list. RM_ERROR_PERM_STR_INST_NOT_VALID is returned if
* there are any mismatches
*/
-static int32_t policyCheckInstances(Rm_PolicyValidInstTree *validInstTree,
- Rm_PolicyPermission *permissionsList)
+static int32_t policyCheckInstances(Rm_Handle rmHandle, Rm_PolicyPermission *permissionsList)
{
while (permissionsList) {
if (strncmp(permissionsList->instName, Rm_policyAllInstances, RM_NAME_MAX_CHARS) &&
- (!rmPolicyGetValidInstNode(validInstTree, permissionsList->instName))) {
+ (!rmPolicyGetValidInstNode(rmHandle, permissionsList->instName))) {
return(RM_ERROR_PERM_STR_INST_NOT_VALID);
}
permissionsList = permissionsList->nextPermission;
@@ -510,19 +534,48 @@ static int32_t policyValidateAssignmentPermissions(Rm_PolicyValidInstTree *root,
************************ Internal Policy APIs ************************
**********************************************************************/
+/* FUNCTION PURPOSE: Returns a pointer to the instance policy
+ ***********************************************************************
+ * DESCRIPTION: Returns a pointer to the instance's policy based on
+ * the instance type
+ */
+void *rmPolicyGetPolicy(Rm_Handle rmHandle)
+{
+ Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
+ void *policy = NULL;
+
+ if ((rmInst->instType == Rm_instType_SERVER) ||
+ (rmInst->instType == Rm_instType_SHARED_SERVER)) {
+ policy = rmInst->u.server.globalPolicy;
+ }
+ else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
+ policy = rmInst->u.cd.staticPolicy;
+ }
+ else if (rmInst->instType == Rm_instType_CLIENT) {
+ policy = rmInst->u.client.staticPolicy;
+ }
+ return(policy);
+}
+
/* FUNCTION PURPOSE: Get a valid instace node from the valid inst tree
***********************************************************************
* DESCRIPTION: Returns a valid instance node from the valid instance
* tree that matches the specified instName
*/
-Rm_PolicyValidInstNode *rmPolicyGetValidInstNode(Rm_PolicyValidInstTree *validInstTree, char *instName)
+Rm_PolicyValidInstNode *rmPolicyGetValidInstNode(Rm_Handle rmHandle, char *instName)
{
+ Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
+ Rm_PolicyValidInstTree *treeRoot = policyGetValidInstTree(rmHandle);
Rm_PolicyValidInstNode findNode;
+ if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+ rmPolicyValidInstTreeInv(treeRoot);
+ }
+
memset((void *)&findNode, 0, sizeof(Rm_PolicyValidInstNode));
strncpy(findNode.name, instName, RM_NAME_MAX_CHARS);
- return (RB_FIND(_Rm_PolicyValidInstTree, validInstTree, &findNode));
+ return (RB_FIND(_Rm_PolicyValidInstTree, treeRoot, &findNode));
}
/* FUNCTION PURPOSE: Gets the Linux Valid instance node
@@ -531,11 +584,11 @@ Rm_PolicyValidInstNode *rmPolicyGetValidInstNode(Rm_PolicyValidInstTree *validIn
* valid instance tree that matches the instance name
* reserved for resource assigned to the Linux kernel.
*/
-Rm_PolicyValidInstNode *rmPolicyGetLinuxInstNode(Rm_PolicyValidInstTree *validInstTree)
+Rm_PolicyValidInstNode *rmPolicyGetLinuxInstNode(Rm_Handle rmHandle)
{
char linuxName[] = RM_ALLOCATED_TO_LINUX;
- return (rmPolicyGetValidInstNode(validInstTree, linuxName));
+ return (rmPolicyGetValidInstNode(rmHandle, linuxName));
}
/* FUNCTION PURPOSE: Validates resource permissions against a Policy DTB
* list specified at the top of the Policy. Otherwise,
* returns error
*/
-int32_t rmPolicyValidatePolicyResourceNames(void *policyDtb, void *allocatorList)
+int32_t rmPolicyValidatePolicyResourceNames(Rm_Handle rmHandle)
{
- Rm_Allocator *allocator = (Rm_Allocator *)allocatorList;
- int32_t nodeOffset;
- int32_t depth;
- const char *nodeName;
+ void *policyDtb = rmPolicyGetPolicy(rmHandle);
+ int32_t nodeOffset;
+ int32_t depth;
+ const char *nodeName;
depth = RM_DTB_UTIL_STARTING_DEPTH;
nodeOffset = RM_DTB_UTIL_STARTING_NODE_OFFSET;
@@ -799,7 +852,7 @@ int32_t rmPolicyValidatePolicyResourceNames(void *policyDtb, void *allocatorList
nodeOffset = fdt_next_node(policyDtb, nodeOffset, &depth);
nodeName = fdt_get_name(policyDtb, nodeOffset, NULL);
if (fdt_first_property_offset(policyDtb, nodeOffset) > RM_DTB_UTIL_STARTING_NODE_OFFSET) {
- if (rmAllocatorFind(allocator, (char *)nodeName) == NULL) {
+ if (rmAllocatorFind(rmHandle, nodeName) == NULL) {
/* No allocator tied to resource name */
return(RM_ERROR_UNKNOWN_RESOURCE_IN_POLICY);
}
@@ -869,8 +922,10 @@ int32_t rmPolicyValidatePolicy(void *policyDtb, Rm_PolicyValidInstTree *validIns
* "valid-instances" property at the top of the Policy.
* The root entry of the valid instance tree is returned.
*/
-Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(void *policyDtb, 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);
int32_t validInstOffset;
const char *validInstName = NULL;
int32_t validInstLen;
@@ -920,6 +975,11 @@ Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(void *policyDtb, int addLinu
RB_INSERT(_Rm_PolicyValidInstTree, rootEntry, newNode);
}
+ if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+ /* Writeback the valid instance tree */
+ rmPolicyValidInstTreeWb(rootEntry);
+ }
+
*result = RM_OK;
return (rootEntry);
}
@@ -929,19 +989,42 @@ Rm_PolicyValidInstTree *rmPolicyCreateValidInstTree(void *policyDtb, int addLinu
* DESCRIPTION: Frees all memory associated with a Policy valid
* instance tree.
*/
-void rmPolicyFreeValidInstTree(Rm_PolicyValidInstTree *validInstTree)
+void rmPolicyFreeValidInstTree(Rm_Handle rmHandle)
{
+ Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
+ Rm_PolicyValidInstTree *treeRoot = policyGetValidInstTree(rmHandle);
Rm_PolicyValidInstNode *node;
Rm_PolicyValidInstNode *nextNode;
- for (node = RB_MIN(_Rm_PolicyValidInstTree, validInstTree); node != NULL; node = nextNode) {
- nextNode = RB_NEXT(_Rm_PolicyValidInstTree, validInstTree, node);
- RB_REMOVE(_Rm_PolicyValidInstTree, validInstTree, node);
- rmPolicyValidInstNodeFree(node);
- }
- if (RB_MIN(_Rm_PolicyValidInstTree, validInstTree) == NULL) {
- /* No more valid instance nodes in tree */
- Rm_osalFree((void *)validInstTree, sizeof(Rm_PolicyValidInstTree));
+ if (treeRoot) {
+ if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+ rmPolicyValidInstTreeInv(treeRoot);
+ }
+
+ for (node = RB_MIN(_Rm_PolicyValidInstTree, treeRoot); node != NULL; node = nextNode) {
+ nextNode = RB_NEXT(_Rm_PolicyValidInstTree, treeRoot, node);
+ RB_REMOVE(_Rm_PolicyValidInstTree, treeRoot, node);
+ rmPolicyValidInstNodeFree(node);
+ }
+
+ /* Don't need to writeback tree node changes since valid instance will be made
+ * NULL in instance */
+
+ if (RB_MIN(_Rm_PolicyValidInstTree, treeRoot) == NULL) {
+ /* No more valid instance nodes in tree */
+ Rm_osalFree((void *)treeRoot, sizeof(Rm_PolicyValidInstTree));
+ }
+
+ if ((rmInst->instType == Rm_instType_SERVER) ||
+ (rmInst->instType == Rm_instType_SHARED_SERVER)) {
+ rmInst->u.server.globalValidInstTree = NULL;
+ }
+ else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
+ rmInst->u.cd.staticValidInstTree = NULL;
+ }
+ else if (rmInst->instType == Rm_instType_CLIENT) {
+ rmInst->u.client.staticValidInstTree = NULL;
+ }
}
}