edmamgr: add APIs to free and restore all edma hardware resources 3.40.02.05_eng
authorHongmei Gou <h-gou@ti.com>
Thu, 9 Jun 2016 17:37:58 +0000 (13:37 -0400)
committerChris Ring <cring@ti.com>
Thu, 9 Jun 2016 19:00:08 +0000 (12:00 -0700)
* This is needed to allow edmamgr allocated channels to survive from
  IpcPower suspend/resume:
  1. Call EdmaMgr_hwFreeAll() before the suspend
  2. Call EdmaMgr_hwAllocAll() after the resume

Signed-off-by: Hongmei Gou <h-gou@ti.com>
packages/ti/sdo/fc/edmamgr/edmamgr.c
packages/ti/sdo/fc/edmamgr/edmamgr.h

index ac90e61625b06e76f480584c237a319063bbfe1b..2db6c39ae855d8e28ca181b04d83f871da279807 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, Texas Instruments Incorporated
+ * Copyright (c) 2013-2016, Texas Instruments Incorporated
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,16 @@ static IRES_ProtocolRevision _iresEDMA3ChanRevision =
 
 EdmaMgr_Channel EdmaMgr_channels[EDMA_MGR_MAX_NUM_CHANNELS];
 
+typedef struct _EdmaMgr_SaveInfo {
+  EdmaMgr_Handle               handle;
+  int32_t                      numPaRams;
+  uint32_t                     optChained;
+  IALG_MemRec                  addrTable;
+  EdmaMgr_Channel             *chainedChannel;
+} EdmaMgr_SaveInfo;
+
+static EdmaMgr_SaveInfo EdmaMgr_saveInfo[EDMA_MGR_MAX_NUM_CHANNELS];
+
 extern __FAR__ int32_t *ti_sdo_fc_edmamgr_region2Instance;
 extern __FAR__ EDMA3_GblConfigParams *ti_sdo_fc_edmamgr_edma3GblConfigParams;
 extern __FAR__ EDMA3_InstanceInitConfig *ti_sdo_fc_edmamgr_edma3RegionConfig;
@@ -394,3 +404,119 @@ int32_t EdmaMgr_free(EdmaMgr_Handle h)
 
     return ret_val;
 }
+
+
+/*********************************************************************************
+ * FUNCTION PURPOSE: Free EdmaMgr HW resources
+ *********************************************************************************
+  DESCRIPTION:      This function frees HW resources for all EDMA channels
+
+  Parameters :      Inputs:
+
+                    Output: EdmaMgr_SUCCESS if free is successful;
+                            Error code otherwise.
+ *********************************************************************************/
+int32_t EdmaMgr_hwFreeAll()
+{
+    int32_t i, ret_val = EdmaMgr_SUCCESS;
+    EdmaMgr_Channel *chan;
+    EdmaMgr_SaveInfo *saveInfo;
+    IRES_Status ires_status;
+
+    memset(EdmaMgr_saveInfo, 0, sizeof(EdmaMgr_SaveInfo)*EDMA_MGR_MAX_NUM_CHANNELS);
+
+    for (i = 0; i < EDMA_MGR_MAX_NUM_CHANNELS; i++) {
+        chan = &EdmaMgr_channels[i];
+
+        /* Save info for recovering the EDMA channels */
+        if (chan->edmaArgs.numPaRams > 0) {
+
+            saveInfo = &EdmaMgr_saveInfo[i];
+
+            saveInfo->numPaRams = chan->edmaArgs.numPaRams;
+
+            saveInfo->handle = (EdmaMgr_Handle) chan;
+
+            /* Save info for a large channel*/
+            if (chan->chainedChannel != NULL) {
+                saveInfo->chainedChannel = chan->chainedChannel;
+            }
+
+            if (chan->addrTable.base != NULL) {
+                memcpy(&saveInfo->addrTable, &chan->addrTable, sizeof(IALG_MemRec));
+            }
+
+            saveInfo->optChained = chan->optChained;
+
+            /* Free EdmaMgr channel */
+            ret_val = EdmaMgr_free((EdmaMgr_Handle)chan);
+            if (ret_val != EdmaMgr_SUCCESS) {
+                return ret_val;
+            }
+        }
+    }
+
+    /* RMAN exit */
+    ires_status = RMAN_exit();
+    if (ires_status != IRES_OK) {
+        ret_val = EdmaMgr_ERROR_FREE;
+    }
+
+    return ret_val;
+}
+
+/*********************************************************************************
+ * FUNCTION PURPOSE: Restore EdmaMgr HW resources
+ *********************************************************************************
+  DESCRIPTION:      This function restores HW resources for all EDMA channels
+
+  Parameters :      Inputs:
+
+                    Output: EdmaMgr_SUCCESS if restore is successful;
+                            Error code otherwise.
+ *********************************************************************************/
+int32_t EdmaMgr_hwAllocAll()
+{
+    int32_t i, ret_val = EdmaMgr_SUCCESS;
+    EdmaMgr_Channel *chan;
+    EdmaMgr_SaveInfo *saveInfo;
+    EdmaMgr_Handle   h;
+    IRES_Status ires_status;
+
+    /* RMAN init */
+    ires_status = RMAN_init();
+    if (IRES_OK != ires_status) {
+        return EdmaMgr_ERROR_RMANINIT;
+    }
+
+    for (i = 0; i < EDMA_MGR_MAX_NUM_CHANNELS; i++) {
+        saveInfo = &EdmaMgr_saveInfo[i];
+
+        /* Restore an EDMA channel */
+        if (saveInfo->numPaRams > 0) {
+            do {
+                h = EdmaMgr_alloc(saveInfo->numPaRams);
+                if (h == saveInfo->handle) {
+                    break;
+                } else {
+                    EdmaMgr_free (h);
+                }
+            } while (1);
+
+            chan = (EdmaMgr_Channel *)h;
+
+            /* Restore configurations for a large channel */
+            if (&saveInfo->addrTable.base != NULL) {
+                memcpy( &chan->addrTable, &saveInfo->addrTable, sizeof(IALG_MemRec));
+            }
+
+            chan->optChained = saveInfo->optChained;
+
+            if (saveInfo->chainedChannel) {
+                chan->chainedChannel = saveInfo->chainedChannel;
+            }
+        }
+    }
+
+    return ret_val;
+}
index f6776fd5b01d2f2f8b34d693fab57d4c7d11018c..15160c9d336692140602ffd5514fb5bb0173459a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, Texas Instruments Incorporated
+ * Copyright (c) 2013-2016, Texas Instruments Incorporated
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -216,6 +216,31 @@ int32_t EdmaMgr_free
   EdmaMgr_Handle    h
 );
 
+/**
+ *  @brief      Free EdmaMgr HW resources
+ *
+ *  @param[in]
+ *
+ *  @retval     EdmaMgr_SUCCESS    Success
+ *  @retval     Error code otherwise
+ *
+ *
+ */
+int32_t EdmaMgr_hwFreeAll();
+
+
+/**
+ *  @brief      Restore EdmaMgr HW resources
+ *
+ *  @param[in]
+ *
+ *  @retval     EdmaMgr_SUCCESS    Success
+ *  @retval     Error code otherwise
+ *
+ *
+ */
+int32_t EdmaMgr_hwAllocAll();
+
 
 /*
  *  The below declarations are placed here as only a reference