lib/sw_services/xilplmi/src/xplmi_dma.c
int XPlmi_DmaXfr(u64 SrcAddr, u64 DestAddr, u32 Len, u32 Flags)
{
	int Status = XST_FAILURE;
	XPmcDma *DmaPtr;
	int (*XPlmi_WaitForDmaDone)(XPmcDma *DmaPtr, XPmcDma_Channel Channel);
#ifdef PLM_PRINT_PERF_DMA
	u64 XfrTime = XPlmi_GetTimerValue();
	XPlmi_PerfTime PerfTime = {0U};
#endif

	if (Len == 0U) {
		Status = XST_SUCCESS;
		goto END;
	}

	/* Assign XPlmi_WaitForDmaDone with appropriate function */
	if ((DestAddr >= XPLMI_PMC_ALIAS1_BASEADDR) &&
		(DestAddr < XPLMI_PMC_ALIAS_MAX_ADDR)) {
		/*
		 * Call XPlmi_SsitWaitForDmaDone() if DMA transfer is to
		 * SSIT Slave SLRs
		 */
		XPlmi_WaitForDmaDone = XPlmi_SsitWaitForDmaDone;
	} else {
		XPlmi_WaitForDmaDone = XPmcDma_WaitForDone;
	}

	Status = XPlmi_StartDma(SrcAddr, DestAddr, Len, Flags, &DmaPtr);
	if (Status != XST_SUCCESS) {
		goto END;
	}

	if ((Flags & XPLMI_DMA_SRC_NONBLK) != (u32)FALSE) {
		goto END;
	}
	/* Polling for transfer to be done */
	Status = XPlmi_WaitForDmaDone(DmaPtr, XPMCDMA_SRC_CHANNEL);
	if (Status != XST_SUCCESS) {
		Status = XPlmi_UpdateStatus(XPLMI_ERR_DMA_XFER_WAIT_SRC, Status);
		goto END;
	}

	if ((Flags & XPLMI_DMA_DST_NONBLK) == (u32)FALSE) {
		Status = XPlmi_WaitForDmaDone(DmaPtr, XPMCDMA_DST_CHANNEL);
		if (Status != XST_SUCCESS) {
			Status = XPlmi_UpdateStatus(XPLMI_ERR_DMA_XFER_WAIT_DEST, Status);
			goto END;
		}
	}
	/* To acknowledge the transfer has completed */
	XPmcDma_IntrClear(DmaPtr, XPMCDMA_SRC_CHANNEL, XPMCDMA_IXR_DONE_MASK);

	if ((Flags & XPLMI_DMA_DST_NONBLK) == (u32)FALSE) {
		XPmcDma_IntrClear(DmaPtr, XPMCDMA_DST_CHANNEL, XPMCDMA_IXR_DONE_MASK);
	}

	/* Reverting the AXI Burst setting of PMC_DMA */
	if ((Flags & XPLMI_SRC_CH_AXI_FIXED) == XPLMI_SRC_CH_AXI_FIXED) {
		DmaCtrl.AxiBurstType = 0U;
		XPmcDma_SetConfig(DmaPtr, XPMCDMA_SRC_CHANNEL, &DmaCtrl);
	}
	if (((Flags & XPLMI_DMA_DST_NONBLK) == (u32)FALSE) &&
		((Flags & XPLMI_DST_CH_AXI_FIXED) == XPLMI_DST_CH_AXI_FIXED)) {
		DmaCtrl.AxiBurstType = 0U;
		XPmcDma_SetConfig(DmaPtr, XPMCDMA_DST_CHANNEL, &DmaCtrl);
	}

	if ((Flags & (XPLMI_DMA_SRC_NONBLK | XPLMI_DMA_DST_NONBLK)) == (u32)FALSE) {
		XPlmi_Printf(DEBUG_INFO, "DMA Xfer completed \n\r");
	}

END:
#ifdef PLM_PRINT_PERF_DMA
	XPlmi_MeasurePerfTime(XfrTime, &PerfTime);
	XPlmi_Printf(DEBUG_PRINT_PERF,
		" %u.%03u ms DMA Xfr time: SrcAddr: 0x%0x%08x, DestAddr: 0x%0x%08x,"
		"%u Bytes, Flags: 0x%0x\n\r",
		(u32)PerfTime.TPerfMs, (u32)PerfTime.TPerfMsFrac,
		(u32)(SrcAddr >> 32U), (u32)SrcAddr, (u32)(DestAddr >> 32U),
		(u32)DestAddr, (Len * XPLMI_WORD_LEN), Flags);
#endif
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function is used to initiate and complete the DMA to DMA transfer.
 *
 * @param	SrcAddr for SRC channel to fetch data from
 * @param	DestAddr for DST channel to store the data
 * @param	Len of the data in bytes
 * @param	Flags to select PMC DMA and DMA Burst type
 *
 * @return	XST_SUCCESS on success and error codes on failure
 *
 *****************************************************************************/
@brief       This function is used to initiate and complete the DMA to DMA transfer.
@param       SrcAddr for SRC channel to fetch data from
@param       DestAddr for DST channel to store the data
@param       Len of the data in bytes
@param       Flags to select PMC DMA and DMA Burst type

@return      XST_SUCCESS on success and error codes on failure
@brief This function is used to initiate and complete the DMA to DMA transfer . @param SrcAddr for SRC channel to fetch data from @param DestAddr for DST channel to store the data @param Len of the data in bytes @param Flags to select PMC DMA and DMA Burst type @return XST_SUCCESS on success and error codes on failure
int XPlmi_DmaXfr(u64 SrcAddr, u64 DestAddr, u32 Len, u32 Flags)
{
	int Status = XST_FAILURE;
	XPmcDma *DmaPtr;
	int (*XPlmi_WaitForDmaDone)(XPmcDma *DmaPtr, XPmcDma_Channel Channel);
#ifdef PLM_PRINT_PERF_DMA
	u64 XfrTime = XPlmi_GetTimerValue();
	XPlmi_PerfTime PerfTime = {0U};
#endif
	if (Len == 0U) {
		Status = XST_SUCCESS;
		goto END;
	}
	if ((DestAddr >= XPLMI_PMC_ALIAS1_BASEADDR) &&
		(DestAddr < XPLMI_PMC_ALIAS_MAX_ADDR)) {
		XPlmi_WaitForDmaDone = XPlmi_SsitWaitForDmaDone;
	} else {
		XPlmi_WaitForDmaDone = XPmcDma_WaitForDone;
	}
	Status = XPlmi_StartDma(SrcAddr, DestAddr, Len, Flags, &DmaPtr);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	if ((Flags & XPLMI_DMA_SRC_NONBLK) != (u32)FALSE) {
		goto END;
	}
	Status = XPlmi_WaitForDmaDone(DmaPtr, XPMCDMA_SRC_CHANNEL);
	if (Status != XST_SUCCESS) {
		Status = XPlmi_UpdateStatus(XPLMI_ERR_DMA_XFER_WAIT_SRC, Status);
		goto END;
	}
	if ((Flags & XPLMI_DMA_DST_NONBLK) == (u32)FALSE) {
		Status = XPlmi_WaitForDmaDone(DmaPtr, XPMCDMA_DST_CHANNEL);
		if (Status != XST_SUCCESS) {
			Status = XPlmi_UpdateStatus(XPLMI_ERR_DMA_XFER_WAIT_DEST, Status);
			goto END;
		}
	}
	XPmcDma_IntrClear(DmaPtr, XPMCDMA_SRC_CHANNEL, XPMCDMA_IXR_DONE_MASK);
	if ((Flags & XPLMI_DMA_DST_NONBLK) == (u32)FALSE) {
		XPmcDma_IntrClear(DmaPtr, XPMCDMA_DST_CHANNEL, XPMCDMA_IXR_DONE_MASK);
	}
	if ((Flags & XPLMI_SRC_CH_AXI_FIXED) == XPLMI_SRC_CH_AXI_FIXED) {
		DmaCtrl.AxiBurstType = 0U;
		XPmcDma_SetConfig(DmaPtr, XPMCDMA_SRC_CHANNEL, &DmaCtrl);
	}
	if (((Flags & XPLMI_DMA_DST_NONBLK) == (u32)FALSE) &&
		((Flags & XPLMI_DST_CH_AXI_FIXED) == XPLMI_DST_CH_AXI_FIXED)) {
		DmaCtrl.AxiBurstType = 0U;
		XPmcDma_SetConfig(DmaPtr, XPMCDMA_DST_CHANNEL, &DmaCtrl);
	}
	if ((Flags & (XPLMI_DMA_SRC_NONBLK | XPLMI_DMA_DST_NONBLK)) == (u32)FALSE) {
		XPlmi_Printf(DEBUG_INFO, "DMA Xfer completed \n\r");
	}
END:
#ifdef PLM_PRINT_PERF_DMA
	XPlmi_MeasurePerfTime(XfrTime, &PerfTime);
	XPlmi_Printf(DEBUG_PRINT_PERF,
		" %u.%03u ms DMA Xfr time: SrcAddr: 0x%0x%08x, DestAddr: 0x%0x%08x,"
		"%u Bytes, Flags: 0x%0x\n\r",
		(u32)PerfTime.TPerfMs, (u32)PerfTime.TPerfMsFrac,
		(u32)(SrcAddr >> 32U), (u32)SrcAddr, (u32)(DestAddr >> 32U),
		(u32)DestAddr, (Len * XPLMI_WORD_LEN), Flags);
#endif
	return Status;
}
int XPlmi_DmaXfr ( u64 SrcAddr , u64 DestAddr , u32 Len , u32 Flags ) { int Status = XST_FAILURE ; XPmcDma * DmaPtr ; int ( * XPlmi_WaitForDmaDone ) ( XPmcDma * DmaPtr , XPmcDma_Channel Channel ) ; #ifdef PLM_PRINT_PERF_DMA u64 XfrTime = XPlmi_GetTimerValue ( ) ; XPlmi_PerfTime PerfTime = { 0U } ; #endif if ( Len == 0U ) { Status = XST_SUCCESS ; goto END ; } if ( ( DestAddr >= XPLMI_PMC_ALIAS1_BASEADDR ) && ( DestAddr < XPLMI_PMC_ALIAS_MAX_ADDR ) ) { XPlmi_WaitForDmaDone = XPlmi_SsitWaitForDmaDone ; } else { XPlmi_WaitForDmaDone = XPmcDma_WaitForDone ; } Status = XPlmi_StartDma ( SrcAddr , DestAddr , Len , Flags , & DmaPtr ) ; if ( Status != XST_SUCCESS ) { goto END ; } if ( ( Flags & XPLMI_DMA_SRC_NONBLK ) != ( u32 ) FALSE ) { goto END ; } Status = XPlmi_WaitForDmaDone ( DmaPtr , XPMCDMA_SRC_CHANNEL ) ; if ( Status != XST_SUCCESS ) { Status = XPlmi_UpdateStatus ( XPLMI_ERR_DMA_XFER_WAIT_SRC , Status ) ; goto END ; } if ( ( Flags & XPLMI_DMA_DST_NONBLK ) == ( u32 ) FALSE ) { Status = XPlmi_WaitForDmaDone ( DmaPtr , XPMCDMA_DST_CHANNEL ) ; if ( Status != XST_SUCCESS ) { Status = XPlmi_UpdateStatus ( XPLMI_ERR_DMA_XFER_WAIT_DEST , Status ) ; goto END ; } } XPmcDma_IntrClear ( DmaPtr , XPMCDMA_SRC_CHANNEL , XPMCDMA_IXR_DONE_MASK ) ; if ( ( Flags & XPLMI_DMA_DST_NONBLK ) == ( u32 ) FALSE ) { XPmcDma_IntrClear ( DmaPtr , XPMCDMA_DST_CHANNEL , XPMCDMA_IXR_DONE_MASK ) ; } if ( ( Flags & XPLMI_SRC_CH_AXI_FIXED ) == XPLMI_SRC_CH_AXI_FIXED ) { DmaCtrl . AxiBurstType = 0U ; XPmcDma_SetConfig ( DmaPtr , XPMCDMA_SRC_CHANNEL , & DmaCtrl ) ; } if ( ( ( Flags & XPLMI_DMA_DST_NONBLK ) == ( u32 ) FALSE ) && ( ( Flags & XPLMI_DST_CH_AXI_FIXED ) == XPLMI_DST_CH_AXI_FIXED ) ) { DmaCtrl . AxiBurstType = 0U ; XPmcDma_SetConfig ( DmaPtr , XPMCDMA_DST_CHANNEL , & DmaCtrl ) ; } if ( ( Flags & ( XPLMI_DMA_SRC_NONBLK | XPLMI_DMA_DST_NONBLK ) ) == ( u32 ) FALSE ) { XPlmi_Printf ( DEBUG_INFO , " \n \r " ) ; } END : #ifdef PLM_PRINT_PERF_DMA XPlmi_MeasurePerfTime ( XfrTime , & PerfTime ) ; XPlmi_Printf ( DEBUG_PRINT_PERF , " " " \n \r " , ( u32 ) PerfTime . TPerfMs , ( u32 ) PerfTime . TPerfMsFrac , ( u32 ) ( SrcAddr >> 32U ) , ( u32 ) SrcAddr , ( u32 ) ( DestAddr >> 32U ) , ( u32 ) DestAddr , ( Len * XPLMI_WORD_LEN ) , Flags ) ; #endif return Status ; }
@brief       This function is used to initiate and complete the DMA to DMA transfer.
@brief This function is used to initiate and complete the DMA to DMA transfer .
/* Assign XPlmi_WaitForDmaDone with appropriate function */ /*
		 * Call XPlmi_SsitWaitForDmaDone() if DMA transfer is to
		 * SSIT Slave SLRs
		 */ /* Polling for transfer to be done */ /* To acknowledge the transfer has completed */ /* Reverting the AXI Burst setting of PMC_DMA */