lib/sw_services/xilplmi/src/xplmi_generic.c
static int XPlmi_NpiRead(u64 SrcAddr, u64 DestAddr, u32 Len)
{
	int Status = XST_FAILURE;
	u32 Count = Len;
	u32 Offset;
	u32 XferLen;
	XPlmi_ReadBackProps *ReadBackPtr = XPlmi_GetReadBackPropsInstance();
	u64 Dest = DestAddr;
	u64 Src = SrcAddr;

	/* Check if Readback Dest Addr is Overriden */
	if ((XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr->DestAddr) &&
			(XPLMI_SBI_DEST_ADDR != Dest)) {
		Dest = 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;
		}
	}

	/* For NPI READ command, the source address needs to be
	 * 16 byte aligned. Use XPlmi_Out64 till the destination address
	 * becomes 16 byte aligned.
	 */
	Status = XPlmi_DmaUnalignedXfer(&Src, &Dest, &Count,
		XPLMI_SRC_ALIGN_REQ);
	if (Status != XST_SUCCESS) {
		Status = XPlmi_UpdateStatus(XPLMI_ERR_UNALIGNED_DMA_XFER,
			Status);
		goto END;
	}

	XferLen = Count & (~(XPLMI_WORD_LEN - 1U));

	if (Dest != XPLMI_SBI_DEST_ADDR) {
		Status = XPlmi_DmaXfr(Src, Dest, XferLen, XPLMI_PMCDMA_0);
	} else {
		Status = XPlmi_DmaSbiXfer(Src, XferLen, XPLMI_PMCDMA_1);
	}
	if (Status != XST_SUCCESS) {
		goto END;
	}

	/* For NPI_READ command, Offset variable should
	 *  be updated with the unaligned bytes.
	 */
	Offset = XferLen * XPLMI_WORD_LEN;
	Src += Offset;
	Dest += Offset;
	Count = Count - XferLen;
	Status = XPlmi_DmaUnalignedXfer(&Src, &Dest, &Count,
		XPLMI_LEN_ALIGN_REQ);
	if (Status != XST_SUCCESS) {
		Status = XPlmi_UpdateStatus(XPLMI_ERR_UNALIGNED_DMA_XFER,
			Status);
		goto END;
	}

	if ((XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr->DestAddr) &&
			(XPLMI_SBI_DEST_ADDR != Dest)) {
		ReadBackPtr->ProcessedLen += Len;
		ReadBackPtr->DestAddr += ((u64)Len * XPLMI_WORD_LEN);
	}

END:
	return Status;
}
/*****************************************************************************/
/**
 * @brief	The function reads data from Npi address space.
 *
 * @param	Src Address in Npi address space.
 * @param   	Destination Address
 * @param	Len is number of words to be read
 *
 * @return	XST_SUCCESS on success and error code on failure
 *
 ******************************************************************************/
@brief       The function reads data from Npi address space.
@param       Src Address in Npi address space.
@param       Destination Address
@param       Len is number of words to be read

@return      XST_SUCCESS on success and error code on failure
@brief The function reads data from Npi address space . @param Src Address in Npi address space . @param Destination Address @param Len is number of words to be read @return XST_SUCCESS on success and error code on failure
static int XPlmi_NpiRead(u64 SrcAddr, u64 DestAddr, u32 Len)
{
	int Status = XST_FAILURE;
	u32 Count = Len;
	u32 Offset;
	u32 XferLen;
	XPlmi_ReadBackProps *ReadBackPtr = XPlmi_GetReadBackPropsInstance();
	u64 Dest = DestAddr;
	u64 Src = SrcAddr;
	if ((XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr->DestAddr) &&
			(XPLMI_SBI_DEST_ADDR != Dest)) {
		Dest = 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;
		}
	}
	Status = XPlmi_DmaUnalignedXfer(&Src, &Dest, &Count,
		XPLMI_SRC_ALIGN_REQ);
	if (Status != XST_SUCCESS) {
		Status = XPlmi_UpdateStatus(XPLMI_ERR_UNALIGNED_DMA_XFER,
			Status);
		goto END;
	}
	XferLen = Count & (~(XPLMI_WORD_LEN - 1U));
	if (Dest != XPLMI_SBI_DEST_ADDR) {
		Status = XPlmi_DmaXfr(Src, Dest, XferLen, XPLMI_PMCDMA_0);
	} else {
		Status = XPlmi_DmaSbiXfer(Src, XferLen, XPLMI_PMCDMA_1);
	}
	if (Status != XST_SUCCESS) {
		goto END;
	}
	Offset = XferLen * XPLMI_WORD_LEN;
	Src += Offset;
	Dest += Offset;
	Count = Count - XferLen;
	Status = XPlmi_DmaUnalignedXfer(&Src, &Dest, &Count,
		XPLMI_LEN_ALIGN_REQ);
	if (Status != XST_SUCCESS) {
		Status = XPlmi_UpdateStatus(XPLMI_ERR_UNALIGNED_DMA_XFER,
			Status);
		goto END;
	}
	if ((XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr->DestAddr) &&
			(XPLMI_SBI_DEST_ADDR != Dest)) {
		ReadBackPtr->ProcessedLen += Len;
		ReadBackPtr->DestAddr += ((u64)Len * XPLMI_WORD_LEN);
	}
END:
	return Status;
}
static int XPlmi_NpiRead ( u64 SrcAddr , u64 DestAddr , u32 Len ) { int Status = XST_FAILURE ; u32 Count = Len ; u32 Offset ; u32 XferLen ; XPlmi_ReadBackProps * ReadBackPtr = XPlmi_GetReadBackPropsInstance ( ) ; u64 Dest = DestAddr ; u64 Src = SrcAddr ; if ( ( XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr -> DestAddr ) && ( XPLMI_SBI_DEST_ADDR != Dest ) ) { Dest = ReadBackPtr -> DestAddr ; if ( ( Len + ReadBackPtr -> ProcessedLen ) > ReadBackPtr -> MaxSize ) { Status = XPLMI_ERR_READBACK_BUFFER_OVERFLOW ; XPlmi_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } } Status = XPlmi_DmaUnalignedXfer ( & Src , & Dest , & Count , XPLMI_SRC_ALIGN_REQ ) ; if ( Status != XST_SUCCESS ) { Status = XPlmi_UpdateStatus ( XPLMI_ERR_UNALIGNED_DMA_XFER , Status ) ; goto END ; } XferLen = Count & ( ~ ( XPLMI_WORD_LEN - 1U ) ) ; if ( Dest != XPLMI_SBI_DEST_ADDR ) { Status = XPlmi_DmaXfr ( Src , Dest , XferLen , XPLMI_PMCDMA_0 ) ; } else { Status = XPlmi_DmaSbiXfer ( Src , XferLen , XPLMI_PMCDMA_1 ) ; } if ( Status != XST_SUCCESS ) { goto END ; } Offset = XferLen * XPLMI_WORD_LEN ; Src += Offset ; Dest += Offset ; Count = Count - XferLen ; Status = XPlmi_DmaUnalignedXfer ( & Src , & Dest , & Count , XPLMI_LEN_ALIGN_REQ ) ; if ( Status != XST_SUCCESS ) { Status = XPlmi_UpdateStatus ( XPLMI_ERR_UNALIGNED_DMA_XFER , Status ) ; goto END ; } if ( ( XPLMI_READBACK_DEF_DST_ADDR != ReadBackPtr -> DestAddr ) && ( XPLMI_SBI_DEST_ADDR != Dest ) ) { ReadBackPtr -> ProcessedLen += Len ; ReadBackPtr -> DestAddr += ( ( u64 ) Len * XPLMI_WORD_LEN ) ; } END : return Status ; }
@brief       The function reads data from Npi address space.
@brief The function reads data from Npi address space .
/* Check if Readback Dest Addr is Overriden */ /* For NPI READ command, the source address needs to be
	 * 16 byte aligned. Use XPlmi_Out64 till the destination address
	 * becomes 16 byte aligned.
	 */ /* For NPI_READ command, Offset variable should
	 *  be updated with the unaligned bytes.
	 */