OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2009 NVIDIA Corporation. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * |
| 11 * Redistributions in binary form must reproduce the above copyright notice, |
| 12 * this list of conditions and the following disclaimer in the documentation |
| 13 * and/or other materials provided with the distribution. |
| 14 * |
| 15 * Neither the name of the NVIDIA Corporation nor the names of its contributors |
| 16 * may be used to endorse or promote products derived from this software |
| 17 * without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 * POSSIBILITY OF SUCH DAMAGE. |
| 30 * |
| 31 */ |
| 32 |
| 33 #ifndef INCLUDED_nvrm_dma_H |
| 34 #define INCLUDED_nvrm_dma_H |
| 35 |
| 36 |
| 37 #if defined(__cplusplus) |
| 38 extern "C" |
| 39 { |
| 40 #endif |
| 41 |
| 42 #include "nvrm_module.h" |
| 43 #include "nvrm_init.h" |
| 44 |
| 45 /** |
| 46 * @file |
| 47 * @brief <b>nVIDIA Driver Development Kit: |
| 48 * DMA Resource manager </b> |
| 49 * |
| 50 * @b Description: Defines the interface to the NvRM DMA. |
| 51 * |
| 52 */ |
| 53 |
| 54 /** |
| 55 * @defgroup nvrm_dma Direct Memory Access (DMA) Controller API |
| 56 * |
| 57 * This is the Dma interface. These API provides the data transfer from memory |
| 58 * to the selected destination and vice versa. The one end is the memory and |
| 59 * other end is the module selected by the dma module Id. |
| 60 * This API allocates the channel based on priority request. Higher priority |
| 61 * channel can not be shared by other dma requestors. The low priority channel |
| 62 * is shared between the different requestors. |
| 63 * |
| 64 * @ingroup nvddk_rm |
| 65 * |
| 66 * @{ |
| 67 */ |
| 68 |
| 69 #include "nvos.h" |
| 70 |
| 71 /** |
| 72 * NvRmDmaHandle is an opaque context to the NvRmDmaRec interface |
| 73 */ |
| 74 |
| 75 typedef struct NvRmDmaRec *NvRmDmaHandle; |
| 76 |
| 77 /** |
| 78 * @brief Defines the DMA capability structure for getting the capability of |
| 79 * the data transfer and any limitation if the dma manager have. |
| 80 */ |
| 81 |
| 82 typedef struct NvRmDmaCapabilitiesRec |
| 83 { |
| 84 |
| 85 /// Holds the granularity of the data length for dma transfer in bytes |
| 86 NvU32 DmaGranularitySize; |
| 87 |
| 88 /// Holds the information if there is any address alignment limitation |
| 89 /// is available in term of bytes. if this value is 1 then there is no |
| 90 /// limitation, any dma can transfer the data from any address. If this |
| 91 /// value is 2 then the address should be 2 byte aligned always to do |
| 92 /// the dma transfer. If this value is 4 |
| 93 /// then the address should be 4 byte aligned always to do the dma |
| 94 /// transfer. |
| 95 NvU32 DmaAddressAlignmentSize; |
| 96 } NvRmDmaCapabilities; |
| 97 |
| 98 /** |
| 99 * @brief Defines the DMA client buffer information which is transferred |
| 100 * recently. The direction of data transfer decides based on this address. The |
| 101 * source address and destination address should be in line with the source |
| 102 * module Id and destination module Id. |
| 103 */ |
| 104 |
| 105 typedef struct NvRmDmaClientBufferRec |
| 106 { |
| 107 |
| 108 /// Specifies the dma source buffer physical address for dma transfer. |
| 109 NvRmPhysAddr SourceBufferPhyAddress; |
| 110 |
| 111 /// Specifies the dma destination buffer physical address for dma transfer. |
| 112 NvRmPhysAddr DestinationBufferPhyAddress; |
| 113 |
| 114 /// Source address wrap size in bytes. It tells that after how much bytes, |
| 115 /// it will be wrapped. |
| 116 /// If it is zero then wrapping for source address is disabled. |
| 117 NvU32 SourceAddressWrapSize; |
| 118 |
| 119 /// Destination address wrap size in bytes. It tells that after how much |
| 120 /// bytes, it will be wrapped. If it is zero then wrapping for destination |
| 121 /// address is disabled. |
| 122 NvU32 DestinationAddressWrapSize; |
| 123 |
| 124 /// Specifies the size of the buffer in bytes which is requested for |
| 125 /// transfer. |
| 126 NvU32 TransferSize; |
| 127 } NvRmDmaClientBuffer; |
| 128 |
| 129 /** |
| 130 * @brief Specify the name of modules which can be supported by nvrm dma |
| 131 * drivers. These dma modules can be either source or destination based on |
| 132 * direction. |
| 133 */ |
| 134 |
| 135 typedef enum |
| 136 { |
| 137 |
| 138 /// Specifies the dma module Id as Invalid |
| 139 NvRmDmaModuleID_Invalid = 0x0, |
| 140 |
| 141 /// Specifies the dma module Id for memory |
| 142 NvRmDmaModuleID_Memory, |
| 143 |
| 144 /// Specifies the dma module Id for I2s controller. |
| 145 NvRmDmaModuleID_I2s, |
| 146 |
| 147 /// Specifies the dma module Id for Ac97 controller. |
| 148 NvRmDmaModuleID_Ac97, |
| 149 |
| 150 /// Specifies the dma module Id for Spdif controller. |
| 151 NvRmDmaModuleID_Spdif, |
| 152 |
| 153 /// Specifies the dma module Id for uart controller. |
| 154 NvRmDmaModuleID_Uart, |
| 155 |
| 156 /// Specifies the dma module Id for Vfir controller. |
| 157 NvRmDmaModuleID_Vfir, |
| 158 |
| 159 /// Specifies the dma module Id for Mipi controller. |
| 160 NvRmDmaModuleID_Mipi, |
| 161 |
| 162 /// Specifies the dma module Id for spi controller. |
| 163 NvRmDmaModuleID_Spi, |
| 164 |
| 165 /// Specifies the dma module Id for slink controller. |
| 166 NvRmDmaModuleID_Slink, |
| 167 |
| 168 /// Specifies the dma module Id for I2c controller. |
| 169 NvRmDmaModuleID_I2c, |
| 170 |
| 171 /// Specifies the dma module Id for Dvc I2c controller. |
| 172 NvRmDmaModuleID_Dvc, |
| 173 |
| 174 /// Specifies the maximum number of modules supported. |
| 175 NvRmDmaModuleID_Max, |
| 176 NvRmDmaModuleID_Num, |
| 177 NvRmDmaModuleID_Force32 = 0x7FFFFFFF |
| 178 } NvRmDmaModuleID; |
| 179 |
| 180 /** |
| 181 * @brief Specify the direction of the transfer, either outbound data |
| 182 * (source -> dest) or inboud data (source <- dest) |
| 183 */ |
| 184 |
| 185 typedef enum |
| 186 { |
| 187 |
| 188 /// Specifies the direction of the transfer to be srcdevice -> dstdevice |
| 189 NvRmDmaDirection_Forward = 0x1, |
| 190 |
| 191 /// Specifies the direction of the transfer to be dstdevice -> srcdevice |
| 192 NvRmDmaDirection_Reverse, |
| 193 NvRmDmaDirection_Num, |
| 194 NvRmDmaDirection_Force32 = 0x7FFFFFFF |
| 195 } NvRmDmaDirection; |
| 196 |
| 197 /** |
| 198 * @brief Specify the priority of the dma either low priority or high priority. |
| 199 */ |
| 200 |
| 201 typedef enum |
| 202 { |
| 203 |
| 204 /// Low priority DMA, no guarantee of latency to start transactions |
| 205 NvRmDmaPriority_Low = 0x1, |
| 206 |
| 207 /// High priority DMA guarantees the first buffer you send the |
| 208 /// NvRmDmaStartDmaTransfer() will begin immediately. |
| 209 NvRmDmaPriority_High, |
| 210 NvRmDmaPriority_Num, |
| 211 NvRmDmaPriority_Force32 = 0x7FFFFFFF |
| 212 } NvRmDmaPriority; |
| 213 |
| 214 /** |
| 215 * @brief Get the capabilities of the dma channels. |
| 216 * |
| 217 * @param hDevice Handle to RM device. |
| 218 * @param pRmDmaCaps Pointer to the capability structure where the cpas value |
| 219 * will be stored. |
| 220 * |
| 221 * @retval NvSuccess Indicates the function completed successfully. |
| 222 */ |
| 223 |
| 224 NvError NvRmDmaGetCapabilities( |
| 225 NvRmDeviceHandle hDevice, |
| 226 NvRmDmaCapabilities * pRmDmaCaps ); |
| 227 |
| 228 /** |
| 229 * @brief Allocate the DMA channel for the data transfer. The dma is allocated |
| 230 * based on the dma device Id information. Most of the configuration is also |
| 231 * done based on the source/destination device Id during the channel |
| 232 * allocation. It initializes the channel also with standard configuration |
| 233 * based on source/ destination device. The data is transferred from memory to |
| 234 * the dma requestor device or vice versa. The dma requestors device can be |
| 235 * memory or any peripheral device listed in the NvRmDmaDeviceId. |
| 236 * |
| 237 * Assert encountered in debug mode if passed parameter is invalid. |
| 238 * |
| 239 * @param hRmDevice Handle to RM device. |
| 240 * @param phDma Pointer to the dma handle where the allocated dma handle |
| 241 * will be stored. |
| 242 * @param Enable32bitSwap if set to NV_TRUE will unconditionally reverse the |
| 243 * memory order of bytes on 4-byte chunks. D3:D2:D1:D0 becomes D0:D1:D2:D3 |
| 244 * @param Priority Selects either Hi or Low priority. A Low priority |
| 245 * allocation will only fail if the system is out of memory, and transfers on a |
| 246 * Low priority channel will be intermixed with other clients of that channel. |
| 247 * Hi priority allocations may fail if there is not a dedicated channel |
| 248 * available for the Hi priority client. Hi priority channels should only be |
| 249 * used if you have very specific latency requirements. |
| 250 * @param DmaRequestorModuleId Specifies a source module Id. |
| 251 * @param DmaRequestorInstanceId Specifies the instance of the source module. |
| 252 * |
| 253 * @retval NvSuccess Indicates the function completed successfully. |
| 254 * @retval NvDMAChannelNotAvailable Indicates that there is no channel |
| 255 * available for allocation. |
| 256 * @retval NvError_InsufficientMemory Indicates that it will not able to |
| 257 * allocate the memory for dma handles. |
| 258 * @retval NvDMAInvalidSourceId Indicates that device requested is not the |
| 259 * valid device. |
| 260 * @retval NvError_MemoryMapFailed Indicates that the memory mapping for |
| 261 * controller register failed. |
| 262 * @retval NvError_MutexCreateFailed Indicates that the creation of mutex |
| 263 * failed. Mutex is required to provide the thread safety. |
| 264 * @retval NvError_SemaphoreCreateFailed Indicates that the creation of |
| 265 * semaphore failed. Semaphore is required to provide the synchronization and |
| 266 * also used in synchronous operation. |
| 267 * |
| 268 */ |
| 269 |
| 270 NvError NvRmDmaAllocate( |
| 271 NvRmDeviceHandle hRmDevice, |
| 272 NvRmDmaHandle * phDma, |
| 273 NvBool Enable32bitSwap, |
| 274 NvRmDmaPriority Priority, |
| 275 NvRmDmaModuleID DmaRequestorModuleId, |
| 276 NvU32 DmaRequestorInstanceId ); |
| 277 |
| 278 /** |
| 279 * Frees the channel so that it can be reused by other clients. This function |
| 280 * will block until all currently enqueued transfers complete. |
| 281 * |
| 282 * @note: We may change the functionality so that Free() returns immediately |
| 283 * but internally the channel remains in an alloc'd state until all transfers |
| 284 * complete. |
| 285 * |
| 286 * @param hDma A DMA handle from NvRmDmaAllocate. If hDma is NULL, this API has |
| 287 * no effect. |
| 288 */ |
| 289 |
| 290 void NvRmDmaFree( |
| 291 NvRmDmaHandle hDma ); |
| 292 |
| 293 /** |
| 294 * @brief Starts the DMA channel for data transfer. |
| 295 * |
| 296 * Assert encountered in debug mode if passed parameter is invalid. |
| 297 * |
| 298 * @param hDma Specifies a DMA handle which is allocated by the Rm dma from |
| 299 * NvRmDmaAllocate. |
| 300 * @param pClientBuffer Specifies a pointer to the client information which |
| 301 * contains the start buffer, destination buffer, and number of bytes |
| 302 * transferred. |
| 303 * @param DmaDirection Specifies whether the transfer is Forward src->dst or |
| 304 * Reverse dst->src direction. |
| 305 * @param WaitTimeoutInMilliSecond The time need to wait in milliseconds. If it |
| 306 * is zero then it will be returned immediately as asynchronous operation. If |
| 307 * is non zero then it will wait for a requested timeout. If it is |
| 308 * NV_WAIT_INFINITE then it will wait for infinitely till transaction |
| 309 * completes. |
| 310 * @param AsynchSemaphoreId The semaphore Id which need to be signal if client |
| 311 * is requested for asynchronous operation. Pass NULL if not semaphore should |
| 312 * be signalled when the transfer is complete. |
| 313 * |
| 314 * @retval NvSuccess Indicates the function completed successfully. |
| 315 * @retval NvError_InvalidAddress Indicates that the address for source or |
| 316 * destination is invalid. |
| 317 * @retval NvError_InvalidSize Indicates that the bytes requested is invalid. |
| 318 * @retval NvError_Timeout Indicates that transfer is not completed in a |
| 319 * expected time and timeout happen. |
| 320 */ |
| 321 |
| 322 NvError NvRmDmaStartDmaTransfer( |
| 323 NvRmDmaHandle hDma, |
| 324 NvRmDmaClientBuffer * pClientBuffer, |
| 325 NvRmDmaDirection DmaDirection, |
| 326 NvU32 WaitTimeoutInMilliSecond, |
| 327 NvOsSemaphoreHandle AsynchSemaphoreId ); |
| 328 |
| 329 /** |
| 330 * @brief Aborts the currently running transfer as well as any other transfers |
| 331 * that are queued up behind the currently running transfer. |
| 332 * |
| 333 * @param hDma Specifies a DMA handle which is allocated by the Rm dma from |
| 334 * NvRmDmaAllocate. |
| 335 */ |
| 336 |
| 337 void NvRmDmaAbort( |
| 338 NvRmDmaHandle hDma ); |
| 339 |
| 340 /** |
| 341 * @brief Get the number of bytes transferred by the dma in current tranaction |
| 342 * from the last. |
| 343 * |
| 344 * This will tell the number of bytes has been transferred by the dma yet from |
| 345 * the last transfer completes. |
| 346 * |
| 347 * @param hDma Specifies a DMA handle which is allocated by the Rm dma from |
| 348 * NvRmDmaAllocate. |
| 349 * @param pTransferCount Pointer to the variable where number of bytes transferr
ed |
| 350 * by dma will be stored. |
| 351 * @param IsTransferStop Tells whether the current transfer is stopped or not. |
| 352 * |
| 353 * @retval NvSuccess Indicates the function completed successfully. |
| 354 * @retval NvError_InvalidState The transfer is not going on. |
| 355 */ |
| 356 |
| 357 NvError NvRmDmaGetTransferredCount( |
| 358 NvRmDmaHandle hDma, |
| 359 NvU32 * pTransferCount, |
| 360 NvBool IsTransferStop ); |
| 361 |
| 362 /** |
| 363 * @brief Tells whether the transfer is completed or not for the given dma trans
fer. |
| 364 * |
| 365 * This will tells the first or second half of the buffer transfer for the reque
stor |
| 366 * who uses the double buffering mechanism like i2s. |
| 367 * |
| 368 * @param hDma Specifies a DMA handle which is allocated by the Rm dma from |
| 369 * NvRmDmaAllocate. |
| 370 * @param IsFirstHalfBuffer Tells whether the first half or second half of the d
ma transfer. |
| 371 * |
| 372 * @retval NV_TRUE indicates that the transfre has been completed. |
| 373 * @retval NV_FALSE Indicates that the transfre is going on. |
| 374 */ |
| 375 |
| 376 NvBool NvRmDmaIsDmaTransferCompletes( |
| 377 NvRmDmaHandle hDma, |
| 378 NvBool IsFirstHalfBuffer ); |
| 379 |
| 380 #if defined(__cplusplus) |
| 381 } |
| 382 #endif |
| 383 |
| 384 #endif |
OLD | NEW |