lib/sw_apps/zynqmp_fsbl/src/xfsbl_tpm_util.c
u32 XFsbl_TpmTransfer(u16 Address, u8 *TxBuf, u8 *RxBuf, u16 Length)
{
	int Status = XST_FAILURE;
	u8 TranLen;
	u16 RxOffset = 0U;
	u8 TpmTxBuffer[XFSBL_TPM_REQ_MAX_SIZE + XFSBL_TPM_TX_HEAD_SIZE] = {0U};
	u8 TpmRxBuffer[XFSBL_TPM_RESP_MAX_SIZE + XFSBL_TPM_TX_HEAD_SIZE] = {0U};

	if ((Length > XFSBL_TPM_REQ_MAX_SIZE) ||
		(Length > XFSBL_TPM_RESP_MAX_SIZE))
	{
		goto END;
	}

	while (Length) {
		TranLen = (Length <= XFSBL_TPM_SPI_MAX_SIZE) ? Length :
			XFSBL_TPM_SPI_MAX_SIZE;

		TpmTxBuffer[0U] = (RxBuf ? 0x80U : 0U) | (TranLen - 1U);
		TpmTxBuffer[1U] = 0xD4U;
		TpmTxBuffer[2U] = Address >> 8U;
		TpmTxBuffer[3U] = (u8)Address;
		if (TxBuf != NULL) {
			(void)XFsbl_MemCpy(&TpmTxBuffer[XFSBL_TPM_TX_HEAD_SIZE],
				TxBuf, TranLen);
		}

		Status = XSpiPs_PolledTransfer(&SpiInstance, TpmTxBuffer,
			TpmRxBuffer, (TranLen + XFSBL_TPM_TX_HEAD_SIZE));
		if (Status != XST_SUCCESS) {
			goto END;
		}

		if (RxBuf != NULL) {
			(void)XFsbl_MemCpy(&RxBuf[RxOffset],
				&TpmRxBuffer[XFSBL_TPM_TX_HEAD_SIZE], TranLen);
			RxOffset += TranLen;
		}
		Length -= TranLen;
	}
	Status = XFSBL_SUCCESS;

END:
	return Status;
}
/*****************************************************************************/
/**
*
* This function transfers control information to TPM.
*
* @param 	Address is register address
* @param	TxBuf is pointer to transmit buffer
* @param	RxBuf is pointer to receive buffer
* @param	Length is transfer length
*
* @return	XST_SUCCESS if successful, else XST_FAILURE.
*
* @note		None.
*
******************************************************************************/
This function transfers control information to TPM.
This function transfers control information to TPM .
u32 XFsbl_TpmTransfer(u16 Address, u8 *TxBuf, u8 *RxBuf, u16 Length)
{
	int Status = XST_FAILURE;
	u8 TranLen;
	u16 RxOffset = 0U;
	u8 TpmTxBuffer[XFSBL_TPM_REQ_MAX_SIZE + XFSBL_TPM_TX_HEAD_SIZE] = {0U};
	u8 TpmRxBuffer[XFSBL_TPM_RESP_MAX_SIZE + XFSBL_TPM_TX_HEAD_SIZE] = {0U};
	if ((Length > XFSBL_TPM_REQ_MAX_SIZE) ||
		(Length > XFSBL_TPM_RESP_MAX_SIZE))
	{
		goto END;
	}
	while (Length) {
		TranLen = (Length <= XFSBL_TPM_SPI_MAX_SIZE) ? Length :
			XFSBL_TPM_SPI_MAX_SIZE;
		TpmTxBuffer[0U] = (RxBuf ? 0x80U : 0U) | (TranLen - 1U);
		TpmTxBuffer[1U] = 0xD4U;
		TpmTxBuffer[2U] = Address >> 8U;
		TpmTxBuffer[3U] = (u8)Address;
		if (TxBuf != NULL) {
			(void)XFsbl_MemCpy(&TpmTxBuffer[XFSBL_TPM_TX_HEAD_SIZE],
				TxBuf, TranLen);
		}
		Status = XSpiPs_PolledTransfer(&SpiInstance, TpmTxBuffer,
			TpmRxBuffer, (TranLen + XFSBL_TPM_TX_HEAD_SIZE));
		if (Status != XST_SUCCESS) {
			goto END;
		}
		if (RxBuf != NULL) {
			(void)XFsbl_MemCpy(&RxBuf[RxOffset],
				&TpmRxBuffer[XFSBL_TPM_TX_HEAD_SIZE], TranLen);
			RxOffset += TranLen;
		}
		Length -= TranLen;
	}
	Status = XFSBL_SUCCESS;
END:
	return Status;
}
u32 XFsbl_TpmTransfer ( u16 Address , u8 * TxBuf , u8 * RxBuf , u16 Length ) { int Status = XST_FAILURE ; u8 TranLen ; u16 RxOffset = 0U ; u8 TpmTxBuffer [ XFSBL_TPM_REQ_MAX_SIZE + XFSBL_TPM_TX_HEAD_SIZE ] = { 0U } ; u8 TpmRxBuffer [ XFSBL_TPM_RESP_MAX_SIZE + XFSBL_TPM_TX_HEAD_SIZE ] = { 0U } ; if ( ( Length > XFSBL_TPM_REQ_MAX_SIZE ) || ( Length > XFSBL_TPM_RESP_MAX_SIZE ) ) { goto END ; } while ( Length ) { TranLen = ( Length <= XFSBL_TPM_SPI_MAX_SIZE ) ? Length : XFSBL_TPM_SPI_MAX_SIZE ; TpmTxBuffer [ 0U ] = ( RxBuf ? 0x80U : 0U ) | ( TranLen - 1U ) ; TpmTxBuffer [ 1U ] = 0xD4U ; TpmTxBuffer [ 2U ] = Address >> 8U ; TpmTxBuffer [ 3U ] = ( u8 ) Address ; if ( TxBuf != NULL ) { ( void ) XFsbl_MemCpy ( & TpmTxBuffer [ XFSBL_TPM_TX_HEAD_SIZE ] , TxBuf , TranLen ) ; } Status = XSpiPs_PolledTransfer ( & SpiInstance , TpmTxBuffer , TpmRxBuffer , ( TranLen + XFSBL_TPM_TX_HEAD_SIZE ) ) ; if ( Status != XST_SUCCESS ) { goto END ; } if ( RxBuf != NULL ) { ( void ) XFsbl_MemCpy ( & RxBuf [ RxOffset ] , & TpmRxBuffer [ XFSBL_TPM_TX_HEAD_SIZE ] , TranLen ) ; RxOffset += TranLen ; } Length -= TranLen ; } Status = XFSBL_SUCCESS ; END : return Status ; }
This function transfers control information to TPM.
This function transfers control information to TPM .