GateMP: Add check for zero resources case
authorSam Nelson <sam.nelson@ti.com>
Thu, 11 Feb 2016 19:19:58 +0000 (14:19 -0500)
committerAngela Stegmaier <angelabaker@ti.com>
Fri, 12 Feb 2016 19:11:14 +0000 (13:11 -0600)
When reserving SR0 regions for GateMp instances, in some cases,
(for example the NULL gate) has zero resources. This was
not handled properly and resulted in failure. Fix is to avoid doing
unnecessary operations in case of zero resources.

Signed-off-by: Sam Nelson <sam.nelson@ti.com>
packages/ti/sdo/ipc/GateMP.c

index 98ec273cd179716e157227c847fdedf15fc56ac6..79b3efe4e6b76ef17b2dadd3e7c9ca0a343b724f 100644 (file)
@@ -653,23 +653,25 @@ Void ti_sdo_ipc_GateMP_setRegion0Reserved(Ptr sharedAddr)
     GateMP_module->remoteSystemInUse =
         (Ptr)((UInt32)sharedAddr + offset);
 
-    memset(GateMP_module->remoteSystemInUse, 0,
-        GateMP_module->numRemoteSystem * sizeof(UInt8));
-    delegateReservedMask =
-            ti_sdo_ipc_GateMP_RemoteSystemProxy_getReservedMask();
-    if (delegateReservedMask != NULL) {
-        for (i = 0; i < GateMP_module->numRemoteSystem; i++) {
-            if (delegateReservedMask[i >> 5] & (1 << (i % 32))) {
-                GateMP_module->remoteSystemInUse[i] = RESERVED;
+    if (GateMP_module->numRemoteSystem != 0) {
+        memset(GateMP_module->remoteSystemInUse, 0,
+            GateMP_module->numRemoteSystem * sizeof(UInt8));
+        delegateReservedMask =
+                ti_sdo_ipc_GateMP_RemoteSystemProxy_getReservedMask();
+        if (delegateReservedMask != NULL) {
+            for (i = 0; i < GateMP_module->numRemoteSystem; i++) {
+                if (delegateReservedMask[i >> 5] & (1 << (i % 32))) {
+                    GateMP_module->remoteSystemInUse[i] = RESERVED;
+                }
             }
         }
-    }
 
-    if (SharedRegion_isCacheEnabled(0)) {
-        Cache_wbInv(GateMP_module->remoteSystemInUse,
-            GateMP_module->numRemoteSystem * sizeof(UInt8),
-            Cache_Type_ALL,
-            TRUE);
+        if (SharedRegion_isCacheEnabled(0)) {
+            Cache_wbInv(GateMP_module->remoteSystemInUse,
+                GateMP_module->numRemoteSystem * sizeof(UInt8),
+                Cache_Type_ALL,
+                TRUE);
+        }
     }
 
     /*
@@ -682,24 +684,24 @@ Void ti_sdo_ipc_GateMP_setRegion0Reserved(Ptr sharedAddr)
         if (GateMP_module->numRemoteCustom1 != 0) {
             GateMP_module->remoteCustom1InUse =
                 GateMP_module->remoteSystemInUse + offset;
-        }
 
-        memset(GateMP_module->remoteCustom1InUse, 0,
-            GateMP_module->numRemoteCustom1 * sizeof(UInt8));
-        delegateReservedMask =
-                ti_sdo_ipc_GateMP_RemoteCustom1Proxy_getReservedMask();
-        if (delegateReservedMask != NULL) {
-            for (i = 0; i < GateMP_module->numRemoteCustom1; i++) {
-                if (delegateReservedMask[i >> 5] & (1 << (i % 32))) {
-                    GateMP_module->remoteCustom1InUse[i] = RESERVED;
+            memset(GateMP_module->remoteCustom1InUse, 0,
+                GateMP_module->numRemoteCustom1 * sizeof(UInt8));
+            delegateReservedMask =
+                    ti_sdo_ipc_GateMP_RemoteCustom1Proxy_getReservedMask();
+            if (delegateReservedMask != NULL) {
+                for (i = 0; i < GateMP_module->numRemoteCustom1; i++) {
+                    if (delegateReservedMask[i >> 5] & (1 << (i % 32))) {
+                        GateMP_module->remoteCustom1InUse[i] = RESERVED;
+                    }
                 }
             }
-        }
-        if (SharedRegion_isCacheEnabled(0)) {
-            Cache_wbInv(GateMP_module->remoteCustom1InUse,
-                 GateMP_module->numRemoteCustom1 * sizeof(UInt8),
-                 Cache_Type_ALL,
-                 TRUE);
+            if (SharedRegion_isCacheEnabled(0)) {
+                Cache_wbInv(GateMP_module->remoteCustom1InUse,
+                     GateMP_module->numRemoteCustom1 * sizeof(UInt8),
+                     Cache_Type_ALL,
+                     TRUE);
+            }
         }
     }
     else {
@@ -717,25 +719,25 @@ Void ti_sdo_ipc_GateMP_setRegion0Reserved(Ptr sharedAddr)
         if (GateMP_module->numRemoteCustom2 != 0) {
                 GateMP_module->remoteCustom2InUse =
                     GateMP_module->remoteCustom1InUse + offset;
-        }
 
-        memset(GateMP_module->remoteCustom2InUse, 0,
-            GateMP_module->numRemoteCustom2 * sizeof(UInt8));
-        delegateReservedMask =
-                ti_sdo_ipc_GateMP_RemoteCustom2Proxy_getReservedMask();
-        if (delegateReservedMask != NULL) {
-            for (i = 0; i < GateMP_module->numRemoteCustom2; i++) {
-                if (delegateReservedMask[i >> 5] & (1 << (i % 32))) {
-                    GateMP_module->remoteCustom2InUse[i] = RESERVED;
+            memset(GateMP_module->remoteCustom2InUse, 0,
+                GateMP_module->numRemoteCustom2 * sizeof(UInt8));
+            delegateReservedMask =
+                    ti_sdo_ipc_GateMP_RemoteCustom2Proxy_getReservedMask();
+            if (delegateReservedMask != NULL) {
+                for (i = 0; i < GateMP_module->numRemoteCustom2; i++) {
+                    if (delegateReservedMask[i >> 5] & (1 << (i % 32))) {
+                        GateMP_module->remoteCustom2InUse[i] = RESERVED;
+                    }
                 }
             }
-        }
 
-        if (SharedRegion_isCacheEnabled(0)) {
-            Cache_wbInv(GateMP_module->remoteCustom2InUse,
-                 GateMP_module->numRemoteCustom2 * sizeof(UInt8),
-                 Cache_Type_ALL,
-                 TRUE);
+            if (SharedRegion_isCacheEnabled(0)) {
+                Cache_wbInv(GateMP_module->remoteCustom2InUse,
+                     GateMP_module->numRemoteCustom2 * sizeof(UInt8),
+                     Cache_Type_ALL,
+                     TRUE);
+            }
         }
     }
     else if (GateMP_module->proxyMap[ti_sdo_ipc_GateMP_ProxyOrder_CUSTOM2] ==