lib/sw_services/xilplmi/src/xplmi_generic.c
static int XPlmi_CfiWrite(u64 SrcAddr, u64 DestAddr, u32 Keyholesize, u32 Len,
	XPlmi_Cmd* Cmd)
{
	int Status = XST_FAILURE;
	u64 BaseAddr = DestAddr;
	u32 RemData;
	u64 Src = SrcAddr;
	u32 LenTmp = Len;
	XPlmi_KeyHoleXfrParams KeyHoleXfrParams;

	KeyHoleXfrParams.SrcAddr = Src;
	KeyHoleXfrParams.DestAddr = DestAddr;
	KeyHoleXfrParams.BaseAddr = BaseAddr;
	KeyHoleXfrParams.Len = LenTmp * XPLMI_WORD_LEN;
	KeyHoleXfrParams.Keyholesize = Keyholesize;
	KeyHoleXfrParams.Flags = XPLMI_PMCDMA_0;
	KeyHoleXfrParams.Func = NULL;
	Status = XPlmi_KeyHoleXfr(&KeyHoleXfrParams);
	if (Status != XST_SUCCESS) {
		XPlmi_Printf(DEBUG_GENERAL, "DMA WRITE Key Hole Failed\n\r");
		goto END;
	}

	RemData = (Cmd->Len - Cmd->PayloadLen) * XPLMI_WORD_LEN;
	if (RemData == 0U) {
		goto END;
	}

	if (Src < XPLMI_PMCRAM_CHUNK_MEMORY_1) {
		Src = XPLMI_PMCRAM_CHUNK_MEMORY_1;
	}
	else {
		Src = XPLMI_PMCRAM_CHUNK_MEMORY;
	}

	Status = Cmd->KeyHoleParams.Func(Src, DestAddr, RemData,
			XPLMI_DEVICE_COPY_STATE_WAIT_DONE);
	if (Status != XST_SUCCESS) {
		XPlmi_Printf(DEBUG_GENERAL, "DMA WRITE Key Hole Failed\n\r");
		goto END;
	}
	if (RemData > (XPLMI_CHUNK_SIZE / 2U)) {
		LenTmp = (XPLMI_CHUNK_SIZE / 2U);
	}
	else {
		LenTmp = RemData;
	}
	KeyHoleXfrParams.SrcAddr = Src;
	KeyHoleXfrParams.Len = LenTmp;
	Status = XPlmi_KeyHoleXfr(&KeyHoleXfrParams);
	if (Status != XST_SUCCESS) {
		XPlmi_Printf(DEBUG_GENERAL, "DMA WRITE Key Hole Failed\n\r");
		goto END;
	}

	RemData = RemData - LenTmp;
	if (RemData == 0U) {
		goto END1;
	}

	KeyHoleXfrParams.SrcAddr = Cmd->KeyHoleParams.SrcAddr + LenTmp;
	KeyHoleXfrParams.Len = RemData;
	KeyHoleXfrParams.Flags = 0U;
	KeyHoleXfrParams.Func = Cmd->KeyHoleParams.Func;
	Status = XPlmi_KeyHoleXfr(&KeyHoleXfrParams);
	if (Status != XST_SUCCESS) {
		XPlmi_Printf(DEBUG_GENERAL, "DMA WRITE Key Hole Failed\n\r");
		goto END;
	}

END1:
	Cmd->KeyHoleParams.ExtraWords = Cmd->Len - Cmd->PayloadLen;
	Cmd->PayloadLen = Cmd->Len + 1U;
	Cmd->ProcessedLen = Cmd->Len;
END:
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function provides DMA transfer to CFI bypassing PMCRAM
 *
 * @param	SrcAddr is the address to read cfi data from
 * @param	DestAddr is the address to write cfi data to
 * @param	Keyholesize is the size of the DMA key hole in bytes
 * @param	Len is number of words already transferred
 * @param	Cmd is pointer to the command structure
 *
 * @return	XST_SUCCESS on success and error code on failure
 *
 *****************************************************************************/


@return      XST_SUCCESS on success and error code on failure
@return XST_SUCCESS on success and error code on failure
static int XPlmi_CfiWrite(u64 SrcAddr, u64 DestAddr, u32 Keyholesize, u32 Len,
	XPlmi_Cmd* Cmd)
{
	int Status = XST_FAILURE;
	u64 BaseAddr = DestAddr;
	u32 RemData;
	u64 Src = SrcAddr;
	u32 LenTmp = Len;
	XPlmi_KeyHoleXfrParams KeyHoleXfrParams;
	KeyHoleXfrParams.SrcAddr = Src;
	KeyHoleXfrParams.DestAddr = DestAddr;
	KeyHoleXfrParams.BaseAddr = BaseAddr;
	KeyHoleXfrParams.Len = LenTmp * XPLMI_WORD_LEN;
	KeyHoleXfrParams.Keyholesize = Keyholesize;
	KeyHoleXfrParams.Flags = XPLMI_PMCDMA_0;
	KeyHoleXfrParams.Func = NULL;
	Status = XPlmi_KeyHoleXfr(&KeyHoleXfrParams);
	if (Status != XST_SUCCESS) {
		XPlmi_Printf(DEBUG_GENERAL, "DMA WRITE Key Hole Failed\n\r");
		goto END;
	}
	RemData = (Cmd->Len - Cmd->PayloadLen) * XPLMI_WORD_LEN;
	if (RemData == 0U) {
		goto END;
	}
	if (Src < XPLMI_PMCRAM_CHUNK_MEMORY_1) {
		Src = XPLMI_PMCRAM_CHUNK_MEMORY_1;
	}
	else {
		Src = XPLMI_PMCRAM_CHUNK_MEMORY;
	}
	Status = Cmd->KeyHoleParams.Func(Src, DestAddr, RemData,
			XPLMI_DEVICE_COPY_STATE_WAIT_DONE);
	if (Status != XST_SUCCESS) {
		XPlmi_Printf(DEBUG_GENERAL, "DMA WRITE Key Hole Failed\n\r");
		goto END;
	}
	if (RemData > (XPLMI_CHUNK_SIZE / 2U)) {
		LenTmp = (XPLMI_CHUNK_SIZE / 2U);
	}
	else {
		LenTmp = RemData;
	}
	KeyHoleXfrParams.SrcAddr = Src;
	KeyHoleXfrParams.Len = LenTmp;
	Status = XPlmi_KeyHoleXfr(&KeyHoleXfrParams);
	if (Status != XST_SUCCESS) {
		XPlmi_Printf(DEBUG_GENERAL, "DMA WRITE Key Hole Failed\n\r");
		goto END;
	}
	RemData = RemData - LenTmp;
	if (RemData == 0U) {
		goto END1;
	}
	KeyHoleXfrParams.SrcAddr = Cmd->KeyHoleParams.SrcAddr + LenTmp;
	KeyHoleXfrParams.Len = RemData;
	KeyHoleXfrParams.Flags = 0U;
	KeyHoleXfrParams.Func = Cmd->KeyHoleParams.Func;
	Status = XPlmi_KeyHoleXfr(&KeyHoleXfrParams);
	if (Status != XST_SUCCESS) {
		XPlmi_Printf(DEBUG_GENERAL, "DMA WRITE Key Hole Failed\n\r");
		goto END;
	}
END1:
	Cmd->KeyHoleParams.ExtraWords = Cmd->Len - Cmd->PayloadLen;
	Cmd->PayloadLen = Cmd->Len + 1U;
	Cmd->ProcessedLen = Cmd->Len;
END:
	return Status;
}
static int XPlmi_CfiWrite ( u64 SrcAddr , u64 DestAddr , u32 Keyholesize , u32 Len , XPlmi_Cmd * Cmd ) { int Status = XST_FAILURE ; u64 BaseAddr = DestAddr ; u32 RemData ; u64 Src = SrcAddr ; u32 LenTmp = Len ; XPlmi_KeyHoleXfrParams KeyHoleXfrParams ; KeyHoleXfrParams . SrcAddr = Src ; KeyHoleXfrParams . DestAddr = DestAddr ; KeyHoleXfrParams . BaseAddr = BaseAddr ; KeyHoleXfrParams . Len = LenTmp * XPLMI_WORD_LEN ; KeyHoleXfrParams . Keyholesize = Keyholesize ; KeyHoleXfrParams . Flags = XPLMI_PMCDMA_0 ; KeyHoleXfrParams . Func = NULL ; Status = XPlmi_KeyHoleXfr ( & KeyHoleXfrParams ) ; if ( Status != XST_SUCCESS ) { XPlmi_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } RemData = ( Cmd -> Len - Cmd -> PayloadLen ) * XPLMI_WORD_LEN ; if ( RemData == 0U ) { goto END ; } if ( Src < XPLMI_PMCRAM_CHUNK_MEMORY_1 ) { Src = XPLMI_PMCRAM_CHUNK_MEMORY_1 ; } else { Src = XPLMI_PMCRAM_CHUNK_MEMORY ; } Status = Cmd -> KeyHoleParams . Func ( Src , DestAddr , RemData , XPLMI_DEVICE_COPY_STATE_WAIT_DONE ) ; if ( Status != XST_SUCCESS ) { XPlmi_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } if ( RemData > ( XPLMI_CHUNK_SIZE / 2U ) ) { LenTmp = ( XPLMI_CHUNK_SIZE / 2U ) ; } else { LenTmp = RemData ; } KeyHoleXfrParams . SrcAddr = Src ; KeyHoleXfrParams . Len = LenTmp ; Status = XPlmi_KeyHoleXfr ( & KeyHoleXfrParams ) ; if ( Status != XST_SUCCESS ) { XPlmi_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } RemData = RemData - LenTmp ; if ( RemData == 0U ) { goto END1 ; } KeyHoleXfrParams . SrcAddr = Cmd -> KeyHoleParams . SrcAddr + LenTmp ; KeyHoleXfrParams . Len = RemData ; KeyHoleXfrParams . Flags = 0U ; KeyHoleXfrParams . Func = Cmd -> KeyHoleParams . Func ; Status = XPlmi_KeyHoleXfr ( & KeyHoleXfrParams ) ; if ( Status != XST_SUCCESS ) { XPlmi_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } END1 : Cmd -> KeyHoleParams . ExtraWords = Cmd -> Len - Cmd -> PayloadLen ; Cmd -> PayloadLen = Cmd -> Len + 1U ; Cmd -> ProcessedLen = Cmd -> Len ; END : return Status ; }
@brief       This function provides DMA transfer to CFI bypassing PMCRAM
 @param       SrcAddr is the address to read cfi data from
 @param       DestAddr is the address to write cfi data to
 @param       Keyholesize is the size of the DMA key hole in bytes
 @param       Len is number of words already transferred
 @param       Cmd is pointer to the command structure
@brief This function provides DMA transfer to CFI bypassing PMCRAM @param SrcAddr is the address to read cfi data from @param DestAddr is the address to write cfi data to @param Keyholesize is the size of the DMA key hole in bytes @param Len is number of words already transferred @param Cmd is pointer to the command structure