]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blobdiff - src/rm.c
Create shared copy of policy for Shared Server/Client so application doesn't have...
[keystone-rtos/rm-lld.git] / src / rm.c
index d19ca1c34a2779e8a939af04eb3da74257df3342..1cfd0a41313066b758685b5d0b3e7655eae4b439 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -1061,12 +1061,13 @@ void Rm_instanceStatus(Rm_Handle rmHandle)
  */
 Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
 {
-    Rm_Inst *rmInst = NULL;
-    Rm_Inst *sharedServerInst = NULL;
-    void    *globalResourceDtb = NULL;
-    void    *linuxResourceDtb = NULL;
-    int      addLinux = RM_FALSE;   
-    void    *key;     
+    Rm_Inst  *rmInst = NULL;
+    Rm_Inst  *sharedServerInst = NULL;
+    uint32_t  policySize;
+    void     *globalResourceDtb = NULL;
+    void     *linuxResourceDtb = NULL;
+    int       addLinux = RM_FALSE;   
+    void     *key;     
 
     *result = RM_OK;
     
@@ -1082,8 +1083,8 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
     }
 
     /* Create and initialize instance */
-    rmInst = Rm_osalMalloc (sizeof(Rm_Inst));
-    memset ((void *) rmInst, 0, sizeof(Rm_Inst));
+    rmInst = Rm_osalMalloc(sizeof(*rmInst));
+    memset ((void *)rmInst, 0, sizeof(*rmInst));
     rmInst->isLocked = RM_FALSE;
     rmInst->registeredWithDelegateOrServer = RM_FALSE;
     rmInst->transactionSeqNum = transactionInitSequenceNum();
@@ -1099,7 +1100,21 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
             goto errorExit;
         }
 
-        rmInst->u.server.globalPolicy = initCfg->instCfg.serverCfg.globalPolicy;
+        if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+            /* Shared Server makes copy of policy in shared memory for Shared Clients
+             * on other cores */
+            policySize = fdt_totalsize(initCfg->instCfg.serverCfg.globalPolicy);
+            /* Align policy size to cache boundary */
+            if (policySize % RM_MAX_CACHE_ALIGN) {
+                policySize += (RM_MAX_CACHE_ALIGN - (policySize % RM_MAX_CACHE_ALIGN));
+            }
+            rmInst->u.server.policySize = policySize;
+            rmInst->u.server.globalPolicy = Rm_osalMalloc(rmInst->u.server.policySize);
+            memcpy(rmInst->u.server.globalPolicy, initCfg->instCfg.serverCfg.globalPolicy, rmInst->u.server.policySize);
+        }
+        else {
+            rmInst->u.server.globalPolicy = initCfg->instCfg.serverCfg.globalPolicy;
+        }
 
         if (initCfg->instCfg.serverCfg.linuxDtb) {
             linuxResourceDtb = initCfg->instCfg.serverCfg.linuxDtb;
@@ -1182,6 +1197,11 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
                 Rm_osalCsExit(key);
                 goto errorExit;
             }
+            else {
+                /* Invalidate the policy */
+                Rm_osalBeginMemAccess((void *)sharedServerInst->u.server.globalPolicy, 
+                                      sharedServerInst->u.server.policySize);
+            }
             Rm_osalCsExit(key);
         }
         else {
@@ -1191,8 +1211,9 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result)
     }
 
     if (initCfg->instType == Rm_instType_SHARED_SERVER) {
-        /* Writeback the instance for other cores */
+        /* 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) {
         /* Create the instance's task blocking mechanism */
@@ -1238,6 +1259,10 @@ int32_t Rm_delete(Rm_Handle rmHandle, int ignorePendingServices)
         rmAllocatorDeleteResources(rmHandle);
         rmNameServerDelete(rmHandle);
         rmInst->u.server.allocators = NULL;
+
+        if (rmInst->instType == Rm_instType_SHARED_SERVER) {
+            Rm_osalFree((void *)rmInst->u.server.globalPolicy, rmInst->u.server.policySize);
+        }
     }
     else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) {
         rmAllocatorDeleteResources(rmHandle);