| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bdma.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/3 $ |
|---|
| 12 | * $brcm_Date: 2/2/11 10:24a $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * |
|---|
| 17 | * Revision History: |
|---|
| 18 | * $brcm_Log: /magnum/portinginterface/dma/7400/bdma.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/3 2/2/11 10:24a vanessah |
|---|
| 21 | * SW7550-670: add Sharf DMA support |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/2 7/30/08 11:53a syang |
|---|
| 24 | * PR 45128: fix ptr over-run caused by using BDMA_MemDmaEngine_eUnknown |
|---|
| 25 | * for engine handle array boundary |
|---|
| 26 | * |
|---|
| 27 | * Hydra_Software_Devel/10 2/21/08 1:37p rpan |
|---|
| 28 | * PR34854: Initial work for bcm3548. |
|---|
| 29 | * |
|---|
| 30 | * Hydra_Software_Devel/9 1/30/08 10:53a rpan |
|---|
| 31 | * PR34606: Relaxed input parameter check a bit. |
|---|
| 32 | * |
|---|
| 33 | * Hydra_Software_Devel/8 12/7/07 4:10p syang |
|---|
| 34 | * PR 34606: rewrite more than half of code to support hw sharing for |
|---|
| 35 | * kernel and user-mode sides |
|---|
| 36 | * |
|---|
| 37 | * Hydra_Software_Devel/7 10/15/07 12:01p syang |
|---|
| 38 | * PR 35045, PR 35970: coverity (RESOURCE_LEAK) fix |
|---|
| 39 | * |
|---|
| 40 | * Hydra_Software_Devel/6 10/25/06 3:12p syang |
|---|
| 41 | * PR 24634: fix compile warning |
|---|
| 42 | * |
|---|
| 43 | * Hydra_Software_Devel/5 10/3/06 3:59p syang |
|---|
| 44 | * PR 24634: replace critical section with private mutex for |
|---|
| 45 | * mem/pci_dma_handle create/destroy. |
|---|
| 46 | * |
|---|
| 47 | * Hydra_Software_Devel/4 8/4/04 4:38p syang |
|---|
| 48 | * PR 12172: fix warning with release build |
|---|
| 49 | * |
|---|
| 50 | * Hydra_Software_Devel/3 11/19/03 6:40p syang |
|---|
| 51 | * added black magic set to _create |
|---|
| 52 | * |
|---|
| 53 | * Hydra_Software_Devel/2 10/23/03 11:07a syang |
|---|
| 54 | * first time checking after resolving comipling errors |
|---|
| 55 | * |
|---|
| 56 | * Hydra_Software_Devel/1 10/7/03 3:51p syang |
|---|
| 57 | * init version |
|---|
| 58 | * |
|---|
| 59 | ***************************************************************************/ |
|---|
| 60 | #include "bdma.h" /* */ |
|---|
| 61 | #include "bdma_priv.h" /* */ |
|---|
| 62 | #include "bkni.h" |
|---|
| 63 | |
|---|
| 64 | BDBG_MODULE(BDMA); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | /*************************************************************************** |
|---|
| 68 | * |
|---|
| 69 | */ |
|---|
| 70 | BERR_Code BDMA_Open( |
|---|
| 71 | BDMA_Handle * phDma, |
|---|
| 72 | BCHP_Handle hChip, |
|---|
| 73 | BREG_Handle hRegister, |
|---|
| 74 | BMEM_Handle hMemory, |
|---|
| 75 | BINT_Handle hInterrupt ) |
|---|
| 76 | { |
|---|
| 77 | BERR_Code eResult = BERR_SUCCESS; |
|---|
| 78 | BDMA_P_Context * pDma = NULL; |
|---|
| 79 | BKNI_MutexHandle hMutex = NULL; |
|---|
| 80 | |
|---|
| 81 | if ( (NULL == phDma) || |
|---|
| 82 | (0 == hRegister) || |
|---|
| 83 | (NULL == hMemory) ) |
|---|
| 84 | { |
|---|
| 85 | eResult = BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 86 | goto BDMA_P_Err_Main_Open; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | pDma = (BDMA_P_Context *)BKNI_Malloc( sizeof(BDMA_P_Context) ); |
|---|
| 90 | if ( NULL == pDma ) |
|---|
| 91 | { |
|---|
| 92 | eResult = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 93 | goto BDMA_P_Err_Main_Open; |
|---|
| 94 | } |
|---|
| 95 | BKNI_Memset((void*)pDma, 0x0, sizeof(BDMA_P_Context)); |
|---|
| 96 | |
|---|
| 97 | eResult = BKNI_CreateMutex(&hMutex); |
|---|
| 98 | if ((BERR_SUCCESS != eResult) || (NULL == hMutex)) |
|---|
| 99 | { |
|---|
| 100 | #if BDBG_DEBUG_BUILD == 1 |
|---|
| 101 | BERR_TRACE(eResult); |
|---|
| 102 | #endif |
|---|
| 103 | goto BDMA_P_Err_Main_Open; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | pDma->hChip = hChip; |
|---|
| 107 | pDma->hRegister = hRegister; |
|---|
| 108 | pDma->hMemory = hMemory; |
|---|
| 109 | pDma->hInterrupt = hInterrupt; |
|---|
| 110 | pDma->hMutex = hMutex; |
|---|
| 111 | /* hMemDma = NULL; */ |
|---|
| 112 | /* hPciDma = NULL; */ |
|---|
| 113 | BDMA_P_MAIN_SET_BLACK_MAGIC(pDma); |
|---|
| 114 | |
|---|
| 115 | *phDma = pDma; |
|---|
| 116 | return eResult; |
|---|
| 117 | |
|---|
| 118 | BDMA_P_Err_Main_Open: |
|---|
| 119 | if ( NULL != pDma ) |
|---|
| 120 | BDMA_P_MAIN_DESTROY_CONTEXT(pDma); |
|---|
| 121 | |
|---|
| 122 | if ( NULL != phDma ) |
|---|
| 123 | *phDma = NULL; |
|---|
| 124 | |
|---|
| 125 | return eResult; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /*************************************************************************** |
|---|
| 129 | * |
|---|
| 130 | */ |
|---|
| 131 | BERR_Code BDMA_Close( |
|---|
| 132 | BDMA_Handle hDma ) |
|---|
| 133 | { |
|---|
| 134 | BERR_Code eResult = BERR_SUCCESS; |
|---|
| 135 | BDMA_P_Context * pDma; |
|---|
| 136 | #if BDMA_P_SUPPORT_MEM_DMA_ENGINE |
|---|
| 137 | BDMA_MemDmaEngine eMem; |
|---|
| 138 | #endif |
|---|
| 139 | |
|---|
| 140 | #if BDMA_P_SUPPORT_PCI_DMA_ENGINE |
|---|
| 141 | BDMA_PciDmaEngine ePci; |
|---|
| 142 | #endif |
|---|
| 143 | #if BDMA_P_SUPPORT_SHARF_DMA_ENGINE |
|---|
| 144 | BDMA_Sharf eSharf; |
|---|
| 145 | #endif |
|---|
| 146 | |
|---|
| 147 | BDMA_P_MAIN_GET_CONTEXT( hDma, pDma ); |
|---|
| 148 | if ( NULL == pDma ) |
|---|
| 149 | { |
|---|
| 150 | eResult = BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 151 | goto BDMA_P_Done_Main_Close; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | /* sub-modules have to be explicitly destroied first */ |
|---|
| 155 | #if BDMA_P_SUPPORT_MEM_DMA_ENGINE |
|---|
| 156 | for (eMem = BDMA_MemDmaEngine_e0; eMem < BDMA_P_SUPPORT_MEM_DMA_ENGINE; eMem ++) |
|---|
| 157 | { |
|---|
| 158 | if (NULL != pDma->hMemDma[eMem]) |
|---|
| 159 | { |
|---|
| 160 | eResult = BERR_TRACE(BERR_LEAKED_RESOURCE); |
|---|
| 161 | goto BDMA_P_Done_Main_Close; |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | #endif |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | #if BDMA_P_SUPPORT_PCI_DMA_ENGINE |
|---|
| 169 | for (ePci = BDMA_PciDmaEngine_e0; ePci < BDMA_P_SUPPORT_PCI_DMA_ENGINE; ePci ++) |
|---|
| 170 | { |
|---|
| 171 | if (NULL != pDma->hPciDma[ePci]) |
|---|
| 172 | { |
|---|
| 173 | eResult = BERR_TRACE(BERR_LEAKED_RESOURCE); |
|---|
| 174 | goto BDMA_P_Done_Main_Close; |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | #endif |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | #if BDMA_P_SUPPORT_SHARF_DMA_ENGINE |
|---|
| 181 | for (eSharf = BDMA_Sharf_e0; eSharf < BDMA_Sharf_eInvalid; eSharf ++) |
|---|
| 182 | { |
|---|
| 183 | if (NULL != pDma->hSharfDma[eSharf]) |
|---|
| 184 | { |
|---|
| 185 | eResult = BERR_TRACE(BERR_LEAKED_RESOURCE); |
|---|
| 186 | goto BDMA_P_Done_Main_Close; |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | #endif |
|---|
| 190 | |
|---|
| 191 | if (pDma->hMutex) |
|---|
| 192 | { |
|---|
| 193 | BKNI_DestroyMutex(pDma->hMutex); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | BDMA_P_MAIN_DESTROY_CONTEXT(pDma); |
|---|
| 197 | |
|---|
| 198 | BDMA_P_Done_Main_Close: |
|---|
| 199 | return eResult; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | /* End of File */ |
|---|