lib/sw_services/xilplmi/src/xplmi_generic.c
static int XPlmi_CfiRead(XPlmi_Cmd *Cmd)
{
	int Status = XST_FAILURE;
	u32 SrcType = Cmd->Payload[0U] & XPLMI_READBACK_SRC_MASK;
	u32 SlrType = (Cmd->Payload[0U] & XPLMI_READBACK_SLR_TYPE_MASK) >>
					XPLMI_READBACK_SLR_TYPE_SHIFT;
	u64 DestAddrHigh;
	u32 DestAddrLow;
	u64 SrcAddr = (u64)CFU_FDRO_2_ADDR;
	u64 DestAddrRead = (u64)CFU_STREAM_2_ADDR;
	u64 DestAddr = 0UL;
	XPlmi_ReadBackProps *ReadBackPtr = XPlmi_GetReadBackPropsInstance();
	u32 ReadLen;
	u32 Len = Cmd->Payload[3U];
	u32 CfiPayloadSrcAddr = (u32)(&Cmd->Payload[XPLMI_CFI_DATA_OFFSET]);

	if (SlrType == XPLMI_READBACK_SLR_TYPE_1) {
		SrcAddr = XPLMI_SLR1_CFU_FDRO_2_ADDR;
		DestAddrRead = XPLMI_SLR1_CFU_STREAM_2_ADDR;
	} else if (SlrType == XPLMI_READBACK_SLR_TYPE_2) {
		SrcAddr = XPLMI_SLR2_CFU_FDRO_2_ADDR;
		DestAddrRead = XPLMI_SLR2_CFU_STREAM_2_ADDR;
	} else if (SlrType == XPLMI_READBACK_SLR_TYPE_3) {
		SrcAddr = XPLMI_SLR3_CFU_FDRO_2_ADDR;
		DestAddrRead = XPLMI_SLR3_CFU_STREAM_2_ADDR;
	} else {
		/* For Misra-C */
	}

	if (Len > XPLMI_SSIT_MAX_READBACK_SIZE) {
		ReadLen = XPLMI_SSIT_MAX_READBACK_SIZE;
	} else {
		ReadLen = Len;
	}
	XPlmi_SetMaxOutCmds(XPLMI_MAXOUT_CMD_MIN_VAL);

	if (SrcType == XPLMI_READBK_INTF_TYPE_DDR) {
		/* Check if Readback Dest Addr is Overriden */
		if (XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr->DestAddr) {
			DestAddr = ReadBackPtr->DestAddr;
			if ((Len + ReadBackPtr->ProcessedLen) >
				ReadBackPtr->MaxSize) {
				Status = XPLMI_ERR_READBACK_BUFFER_OVERFLOW;
				XPlmi_Printf(DEBUG_GENERAL,
					"ReadBack Buffer Overflow\n\r");
				goto END;
			}
		}
		else {
			DestAddrHigh = Cmd->Payload[1U];
			DestAddrLow =  Cmd->Payload[2U];
			DestAddr = (DestAddrHigh << 32U) | DestAddrLow;
		}
		Status = XPlmi_DmaXfr(SrcAddr, DestAddr, ReadLen,
				XPLMI_PMCDMA_1 | XPLMI_DMA_SRC_NONBLK);
	} else {
		if (SrcType == XPLMI_READBK_INTF_TYPE_JTAG) {
			XPlmi_UtilRMW(SLAVE_BOOT_SBI_CTRL,
				SLAVE_BOOT_SBI_CTRL_INTERFACE_MASK,
				XPLMI_SBI_CTRL_INTERFACE_JTAG);
		} else if(SrcType == XPLMI_READBK_INTF_TYPE_SMAP) {
			XPlmi_UtilRMW(SLAVE_BOOT_SBI_CTRL,
				SLAVE_BOOT_SBI_CTRL_INTERFACE_MASK,
				XPLMI_SBI_CTRL_INTERFACE_SMAP);
		} else {
			/* Do Nothing */
		}

		XPlmi_UtilRMW(SLAVE_BOOT_SBI_MODE,
			SLAVE_BOOT_SBI_MODE_SELECT_MASK,
			SLAVE_BOOT_SBI_MODE_SELECT_MASK);
		Status = XPlmi_DmaSbiXfer(SrcAddr, ReadLen, XPLMI_PMCDMA_1
				| XPLMI_DMA_SRC_NONBLK);
	}
	if (Status != XST_SUCCESS) {
		goto END;
	}
	XPlmi_SetMaxOutCmds(XPLMI_MAXOUT_CMD_DEF_VAL);

	Status = XPlmi_DmaXfr((u64)CfiPayloadSrcAddr, DestAddrRead,
		Cmd->PayloadLen - XPLMI_CFI_DATA_OFFSET, XPLMI_PMCDMA_0);
	if (Status != XST_SUCCESS) {
		goto END;
	}

	if (SrcType == XPLMI_READBK_INTF_TYPE_DDR) {
		Status = XPlmi_WaitForNonBlkDma(XPLMI_PMCDMA_1);
	} else {
		Status = XPlmi_WaitForNonBlkSrcDma(XPLMI_PMCDMA_1);
	}
	if (Status != XST_SUCCESS) {
		goto END;
	}

	Len -= ReadLen;
	while (Len > 0U) {
		if (Len > XPLMI_SSIT_MAX_READBACK_SIZE) {
			ReadLen = XPLMI_SSIT_MAX_READBACK_SIZE;
		} else {
			ReadLen = Len;
		}

		if (SrcType == XPLMI_READBK_INTF_TYPE_DDR) {
			DestAddr += ((u64)ReadLen * XPLMI_WORD_LEN);
			Status = XPlmi_DmaXfr(SrcAddr, DestAddr, ReadLen, XPLMI_PMCDMA_1);
		} else {
			Status = XPlmi_DmaSbiXfer(SrcAddr, ReadLen, XPLMI_PMCDMA_1);
		}
		if (Status != XST_SUCCESS) {
			goto END;
		}
		Len -= ReadLen;
	}

	if (SrcType == XPLMI_READBK_INTF_TYPE_DDR) {
		if (XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr->DestAddr) {
			ReadBackPtr->ProcessedLen += Cmd->Payload[3U];
			ReadBackPtr->DestAddr += ((u64)Cmd->Payload[3U] * XPLMI_WORD_LEN);
		}
		goto END;
	}

	Status = XPlmi_UtilPoll(SLAVE_BOOT_SBI_STATUS,
		SLAVE_BOOT_SBI_STATUS_CMN_BUF_SPACE_MASK,
		SLAVE_BOOT_SBI_STATUS_CMN_BUF_SPACE_VAL,
		XPLMI_TIME_OUT_DEFAULT);
	if (Status != XST_SUCCESS) {
		goto END;
	}

	if (SrcType == XPLMI_READBK_INTF_TYPE_SMAP) {
		Status = XPlmi_UtilPoll(SLAVE_BOOT_SBI_STATUS,
			SLAVE_BOOT_SBI_STATUS_SMAP_DOUT_FIFO_SPACE_MASK,
			SLAVE_BOOT_SBI_STATUS_SMAP_DOUT_FIFO_SPACE_VAL,
			XPLMI_TIME_OUT_DEFAULT);
	} else {
		Status = XPlmi_UtilPoll(SLAVE_BOOT_SBI_STATUS,
			SLAVE_BOOT_SBI_STATUS_JTAG_DOUT_FIFO_SPACE_MASK,
			SLAVE_BOOT_SBI_STATUS_JTAG_DOUT_FIFO_SPACE_VAL,
			XPLMI_TIME_OUT_DEFAULT);
	}

END:
	XPlmi_UtilRMW(SLAVE_BOOT_SBI_MODE, SLAVE_BOOT_SBI_MODE_SELECT_MASK, 0U);
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function provides CFI READ command execution.
 *  		Command payload parameters are
 *		- Params - SMPA/JTAG/DDR
 *		- High Dest Addr
 *		- Low Dest Addr
 *		- Read Length in number of words to be read from CFU
 *		- DATA (CFU READ Packets)
 *
 * @param	Cmd is pointer to the command structure
 *
 * @return	XST_SUCCESS on success and error code on failure
 *
 *****************************************************************************/
@brief       This function provides CFI READ command execution.

@param       Cmd is pointer to the command structure

@return      XST_SUCCESS on success and error code on failure
@brief This function provides CFI READ command execution . @param Cmd is pointer to the command structure @return XST_SUCCESS on success and error code on failure
static int XPlmi_CfiRead(XPlmi_Cmd *Cmd)
{
	int Status = XST_FAILURE;
	u32 SrcType = Cmd->Payload[0U] & XPLMI_READBACK_SRC_MASK;
	u32 SlrType = (Cmd->Payload[0U] & XPLMI_READBACK_SLR_TYPE_MASK) >>
					XPLMI_READBACK_SLR_TYPE_SHIFT;
	u64 DestAddrHigh;
	u32 DestAddrLow;
	u64 SrcAddr = (u64)CFU_FDRO_2_ADDR;
	u64 DestAddrRead = (u64)CFU_STREAM_2_ADDR;
	u64 DestAddr = 0UL;
	XPlmi_ReadBackProps *ReadBackPtr = XPlmi_GetReadBackPropsInstance();
	u32 ReadLen;
	u32 Len = Cmd->Payload[3U];
	u32 CfiPayloadSrcAddr = (u32)(&Cmd->Payload[XPLMI_CFI_DATA_OFFSET]);
	if (SlrType == XPLMI_READBACK_SLR_TYPE_1) {
		SrcAddr = XPLMI_SLR1_CFU_FDRO_2_ADDR;
		DestAddrRead = XPLMI_SLR1_CFU_STREAM_2_ADDR;
	} else if (SlrType == XPLMI_READBACK_SLR_TYPE_2) {
		SrcAddr = XPLMI_SLR2_CFU_FDRO_2_ADDR;
		DestAddrRead = XPLMI_SLR2_CFU_STREAM_2_ADDR;
	} else if (SlrType == XPLMI_READBACK_SLR_TYPE_3) {
		SrcAddr = XPLMI_SLR3_CFU_FDRO_2_ADDR;
		DestAddrRead = XPLMI_SLR3_CFU_STREAM_2_ADDR;
	} else {
	}
	if (Len > XPLMI_SSIT_MAX_READBACK_SIZE) {
		ReadLen = XPLMI_SSIT_MAX_READBACK_SIZE;
	} else {
		ReadLen = Len;
	}
	XPlmi_SetMaxOutCmds(XPLMI_MAXOUT_CMD_MIN_VAL);
	if (SrcType == XPLMI_READBK_INTF_TYPE_DDR) {
		if (XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr->DestAddr) {
			DestAddr = ReadBackPtr->DestAddr;
			if ((Len + ReadBackPtr->ProcessedLen) >
				ReadBackPtr->MaxSize) {
				Status = XPLMI_ERR_READBACK_BUFFER_OVERFLOW;
				XPlmi_Printf(DEBUG_GENERAL,
					"ReadBack Buffer Overflow\n\r");
				goto END;
			}
		}
		else {
			DestAddrHigh = Cmd->Payload[1U];
			DestAddrLow =  Cmd->Payload[2U];
			DestAddr = (DestAddrHigh << 32U) | DestAddrLow;
		}
		Status = XPlmi_DmaXfr(SrcAddr, DestAddr, ReadLen,
				XPLMI_PMCDMA_1 | XPLMI_DMA_SRC_NONBLK);
	} else {
		if (SrcType == XPLMI_READBK_INTF_TYPE_JTAG) {
			XPlmi_UtilRMW(SLAVE_BOOT_SBI_CTRL,
				SLAVE_BOOT_SBI_CTRL_INTERFACE_MASK,
				XPLMI_SBI_CTRL_INTERFACE_JTAG);
		} else if(SrcType == XPLMI_READBK_INTF_TYPE_SMAP) {
			XPlmi_UtilRMW(SLAVE_BOOT_SBI_CTRL,
				SLAVE_BOOT_SBI_CTRL_INTERFACE_MASK,
				XPLMI_SBI_CTRL_INTERFACE_SMAP);
		} else {
		}
		XPlmi_UtilRMW(SLAVE_BOOT_SBI_MODE,
			SLAVE_BOOT_SBI_MODE_SELECT_MASK,
			SLAVE_BOOT_SBI_MODE_SELECT_MASK);
		Status = XPlmi_DmaSbiXfer(SrcAddr, ReadLen, XPLMI_PMCDMA_1
				| XPLMI_DMA_SRC_NONBLK);
	}
	if (Status != XST_SUCCESS) {
		goto END;
	}
	XPlmi_SetMaxOutCmds(XPLMI_MAXOUT_CMD_DEF_VAL);
	Status = XPlmi_DmaXfr((u64)CfiPayloadSrcAddr, DestAddrRead,
		Cmd->PayloadLen - XPLMI_CFI_DATA_OFFSET, XPLMI_PMCDMA_0);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	if (SrcType == XPLMI_READBK_INTF_TYPE_DDR) {
		Status = XPlmi_WaitForNonBlkDma(XPLMI_PMCDMA_1);
	} else {
		Status = XPlmi_WaitForNonBlkSrcDma(XPLMI_PMCDMA_1);
	}
	if (Status != XST_SUCCESS) {
		goto END;
	}
	Len -= ReadLen;
	while (Len > 0U) {
		if (Len > XPLMI_SSIT_MAX_READBACK_SIZE) {
			ReadLen = XPLMI_SSIT_MAX_READBACK_SIZE;
		} else {
			ReadLen = Len;
		}
		if (SrcType == XPLMI_READBK_INTF_TYPE_DDR) {
			DestAddr += ((u64)ReadLen * XPLMI_WORD_LEN);
			Status = XPlmi_DmaXfr(SrcAddr, DestAddr, ReadLen, XPLMI_PMCDMA_1);
		} else {
			Status = XPlmi_DmaSbiXfer(SrcAddr, ReadLen, XPLMI_PMCDMA_1);
		}
		if (Status != XST_SUCCESS) {
			goto END;
		}
		Len -= ReadLen;
	}
	if (SrcType == XPLMI_READBK_INTF_TYPE_DDR) {
		if (XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr->DestAddr) {
			ReadBackPtr->ProcessedLen += Cmd->Payload[3U];
			ReadBackPtr->DestAddr += ((u64)Cmd->Payload[3U] * XPLMI_WORD_LEN);
		}
		goto END;
	}
	Status = XPlmi_UtilPoll(SLAVE_BOOT_SBI_STATUS,
		SLAVE_BOOT_SBI_STATUS_CMN_BUF_SPACE_MASK,
		SLAVE_BOOT_SBI_STATUS_CMN_BUF_SPACE_VAL,
		XPLMI_TIME_OUT_DEFAULT);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	if (SrcType == XPLMI_READBK_INTF_TYPE_SMAP) {
		Status = XPlmi_UtilPoll(SLAVE_BOOT_SBI_STATUS,
			SLAVE_BOOT_SBI_STATUS_SMAP_DOUT_FIFO_SPACE_MASK,
			SLAVE_BOOT_SBI_STATUS_SMAP_DOUT_FIFO_SPACE_VAL,
			XPLMI_TIME_OUT_DEFAULT);
	} else {
		Status = XPlmi_UtilPoll(SLAVE_BOOT_SBI_STATUS,
			SLAVE_BOOT_SBI_STATUS_JTAG_DOUT_FIFO_SPACE_MASK,
			SLAVE_BOOT_SBI_STATUS_JTAG_DOUT_FIFO_SPACE_VAL,
			XPLMI_TIME_OUT_DEFAULT);
	}
END:
	XPlmi_UtilRMW(SLAVE_BOOT_SBI_MODE, SLAVE_BOOT_SBI_MODE_SELECT_MASK, 0U);
	return Status;
}
static int XPlmi_CfiRead ( XPlmi_Cmd * Cmd ) { int Status = XST_FAILURE ; u32 SrcType = Cmd -> Payload [ 0U ] & XPLMI_READBACK_SRC_MASK ; u32 SlrType = ( Cmd -> Payload [ 0U ] & XPLMI_READBACK_SLR_TYPE_MASK ) >> XPLMI_READBACK_SLR_TYPE_SHIFT ; u64 DestAddrHigh ; u32 DestAddrLow ; u64 SrcAddr = ( u64 ) CFU_FDRO_2_ADDR ; u64 DestAddrRead = ( u64 ) CFU_STREAM_2_ADDR ; u64 DestAddr = 0UL ; XPlmi_ReadBackProps * ReadBackPtr = XPlmi_GetReadBackPropsInstance ( ) ; u32 ReadLen ; u32 Len = Cmd -> Payload [ 3U ] ; u32 CfiPayloadSrcAddr = ( u32 ) ( & Cmd -> Payload [ XPLMI_CFI_DATA_OFFSET ] ) ; if ( SlrType == XPLMI_READBACK_SLR_TYPE_1 ) { SrcAddr = XPLMI_SLR1_CFU_FDRO_2_ADDR ; DestAddrRead = XPLMI_SLR1_CFU_STREAM_2_ADDR ; } else if ( SlrType == XPLMI_READBACK_SLR_TYPE_2 ) { SrcAddr = XPLMI_SLR2_CFU_FDRO_2_ADDR ; DestAddrRead = XPLMI_SLR2_CFU_STREAM_2_ADDR ; } else if ( SlrType == XPLMI_READBACK_SLR_TYPE_3 ) { SrcAddr = XPLMI_SLR3_CFU_FDRO_2_ADDR ; DestAddrRead = XPLMI_SLR3_CFU_STREAM_2_ADDR ; } else { } if ( Len > XPLMI_SSIT_MAX_READBACK_SIZE ) { ReadLen = XPLMI_SSIT_MAX_READBACK_SIZE ; } else { ReadLen = Len ; } XPlmi_SetMaxOutCmds ( XPLMI_MAXOUT_CMD_MIN_VAL ) ; if ( SrcType == XPLMI_READBK_INTF_TYPE_DDR ) { if ( XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr -> DestAddr ) { DestAddr = ReadBackPtr -> DestAddr ; if ( ( Len + ReadBackPtr -> ProcessedLen ) > ReadBackPtr -> MaxSize ) { Status = XPLMI_ERR_READBACK_BUFFER_OVERFLOW ; XPlmi_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } } else { DestAddrHigh = Cmd -> Payload [ 1U ] ; DestAddrLow = Cmd -> Payload [ 2U ] ; DestAddr = ( DestAddrHigh << 32U ) | DestAddrLow ; } Status = XPlmi_DmaXfr ( SrcAddr , DestAddr , ReadLen , XPLMI_PMCDMA_1 | XPLMI_DMA_SRC_NONBLK ) ; } else { if ( SrcType == XPLMI_READBK_INTF_TYPE_JTAG ) { XPlmi_UtilRMW ( SLAVE_BOOT_SBI_CTRL , SLAVE_BOOT_SBI_CTRL_INTERFACE_MASK , XPLMI_SBI_CTRL_INTERFACE_JTAG ) ; } else if ( SrcType == XPLMI_READBK_INTF_TYPE_SMAP ) { XPlmi_UtilRMW ( SLAVE_BOOT_SBI_CTRL , SLAVE_BOOT_SBI_CTRL_INTERFACE_MASK , XPLMI_SBI_CTRL_INTERFACE_SMAP ) ; } else { } XPlmi_UtilRMW ( SLAVE_BOOT_SBI_MODE , SLAVE_BOOT_SBI_MODE_SELECT_MASK , SLAVE_BOOT_SBI_MODE_SELECT_MASK ) ; Status = XPlmi_DmaSbiXfer ( SrcAddr , ReadLen , XPLMI_PMCDMA_1 | XPLMI_DMA_SRC_NONBLK ) ; } if ( Status != XST_SUCCESS ) { goto END ; } XPlmi_SetMaxOutCmds ( XPLMI_MAXOUT_CMD_DEF_VAL ) ; Status = XPlmi_DmaXfr ( ( u64 ) CfiPayloadSrcAddr , DestAddrRead , Cmd -> PayloadLen - XPLMI_CFI_DATA_OFFSET , XPLMI_PMCDMA_0 ) ; if ( Status != XST_SUCCESS ) { goto END ; } if ( SrcType == XPLMI_READBK_INTF_TYPE_DDR ) { Status = XPlmi_WaitForNonBlkDma ( XPLMI_PMCDMA_1 ) ; } else { Status = XPlmi_WaitForNonBlkSrcDma ( XPLMI_PMCDMA_1 ) ; } if ( Status != XST_SUCCESS ) { goto END ; } Len -= ReadLen ; while ( Len > 0U ) { if ( Len > XPLMI_SSIT_MAX_READBACK_SIZE ) { ReadLen = XPLMI_SSIT_MAX_READBACK_SIZE ; } else { ReadLen = Len ; } if ( SrcType == XPLMI_READBK_INTF_TYPE_DDR ) { DestAddr += ( ( u64 ) ReadLen * XPLMI_WORD_LEN ) ; Status = XPlmi_DmaXfr ( SrcAddr , DestAddr , ReadLen , XPLMI_PMCDMA_1 ) ; } else { Status = XPlmi_DmaSbiXfer ( SrcAddr , ReadLen , XPLMI_PMCDMA_1 ) ; } if ( Status != XST_SUCCESS ) { goto END ; } Len -= ReadLen ; } if ( SrcType == XPLMI_READBK_INTF_TYPE_DDR ) { if ( XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr -> DestAddr ) { ReadBackPtr -> ProcessedLen += Cmd -> Payload [ 3U ] ; ReadBackPtr -> DestAddr += ( ( u64 ) Cmd -> Payload [ 3U ] * XPLMI_WORD_LEN ) ; } goto END ; } Status = XPlmi_UtilPoll ( SLAVE_BOOT_SBI_STATUS , SLAVE_BOOT_SBI_STATUS_CMN_BUF_SPACE_MASK , SLAVE_BOOT_SBI_STATUS_CMN_BUF_SPACE_VAL , XPLMI_TIME_OUT_DEFAULT ) ; if ( Status != XST_SUCCESS ) { goto END ; } if ( SrcType == XPLMI_READBK_INTF_TYPE_SMAP ) { Status = XPlmi_UtilPoll ( SLAVE_BOOT_SBI_STATUS , SLAVE_BOOT_SBI_STATUS_SMAP_DOUT_FIFO_SPACE_MASK , SLAVE_BOOT_SBI_STATUS_SMAP_DOUT_FIFO_SPACE_VAL , XPLMI_TIME_OUT_DEFAULT ) ; } else { Status = XPlmi_UtilPoll ( SLAVE_BOOT_SBI_STATUS , SLAVE_BOOT_SBI_STATUS_JTAG_DOUT_FIFO_SPACE_MASK , SLAVE_BOOT_SBI_STATUS_JTAG_DOUT_FIFO_SPACE_VAL , XPLMI_TIME_OUT_DEFAULT ) ; } END : XPlmi_UtilRMW ( SLAVE_BOOT_SBI_MODE , SLAVE_BOOT_SBI_MODE_SELECT_MASK , 0U ) ; return Status ; }
@brief       This function provides CFI READ command execution.
@brief This function provides CFI READ command execution .
/* For Misra-C */ /* Check if Readback Dest Addr is Overriden */ /* Do Nothing */