XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.c
int XHdcp1x_CipherSetRemoteKsv(XHdcp1x *InstancePtr, u64 Ksv)
{
	u32 Value = 0;
	u32 Guard = 0x400ul;
	int Status = XST_SUCCESS;

	/* Verify arguments. */
	Xil_AssertNonvoid(InstancePtr != NULL);

	/* Check that it is not disabled */
	if (!XHdcp1x_CipherIsEnabled(InstancePtr)) {
		return (XST_NOT_ENABLED);
	}

	/* Read local ksv to put things into a known state */
	XHdcp1x_CipherGetLocalKsv(InstancePtr);

	/* Clear the register update bit */
	Value = XHdcp1x_ReadReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_CONTROL);
	Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE;
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_CONTROL, Value);

	/* Write the LS 32-bits */
	Value = (u32)(Ksv & 0xFFFFFFFFul);
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KSV_REMOTE_L, Value);

	/* Write the MS 8-bits */
	Value = (u32)((Ksv >> 32) & 0xFFul);
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KSV_REMOTE_H, Value);

	/* Set the register update bit */
	Value = XHdcp1x_ReadReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_CONTROL);
	Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE;
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_CONTROL, Value);

	/* Trigger the calculation of theKm */
	Value = XHdcp1x_ReadReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL);
	Value &= 0xFFFFFFF0ul;
	Value |= XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_BEGIN_Km;
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL, Value);
	Value &= ~XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_BEGIN_Km;
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL, Value);

	/* Wait until Km is available */
	while ((!XHdcp1x_CipherKmReady(InstancePtr)) && (--Guard > 0));

	/* Check for timeout */
	if (Guard == 0) {
		Status = XST_FAILURE;
	}

	return (Status);
}
/*****************************************************************************/
/**
* This function writes the remote KSV value to the cipher.
*
* @param	InstancePtr is the device to write to.
* @param	Ksv is the remote KSV value to write.
*
* @return
*		- XST_SUCCESS if successful.
*		- XST_NOT_ENABLED otherwise.
*
* @note		Whenever this function is called, the underlying driver will
*		initiate the calculation of the Km value and wait for it to
*		complete.
*
******************************************************************************/
This function writes the remote KSV value to the cipher.
This function writes the remote KSV value to the cipher .
int XHdcp1x_CipherSetRemoteKsv(XHdcp1x *InstancePtr, u64 Ksv)
{
	u32 Value = 0;
	u32 Guard = 0x400ul;
	int Status = XST_SUCCESS;
	Xil_AssertNonvoid(InstancePtr != NULL);
	if (!XHdcp1x_CipherIsEnabled(InstancePtr)) {
		return (XST_NOT_ENABLED);
	}
	XHdcp1x_CipherGetLocalKsv(InstancePtr);
	Value = XHdcp1x_ReadReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_CONTROL);
	Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE;
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_CONTROL, Value);
	Value = (u32)(Ksv & 0xFFFFFFFFul);
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KSV_REMOTE_L, Value);
	Value = (u32)((Ksv >> 32) & 0xFFul);
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KSV_REMOTE_H, Value);
	Value = XHdcp1x_ReadReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_CONTROL);
	Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE;
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_CONTROL, Value);
	Value = XHdcp1x_ReadReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL);
	Value &= 0xFFFFFFF0ul;
	Value |= XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_BEGIN_Km;
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL, Value);
	Value &= ~XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_BEGIN_Km;
	XHdcp1x_WriteReg(InstancePtr->Config.BaseAddress,
		XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL, Value);
	while ((!XHdcp1x_CipherKmReady(InstancePtr)) && (--Guard > 0));
	if (Guard == 0) {
		Status = XST_FAILURE;
	}
	return (Status);
}
int XHdcp1x_CipherSetRemoteKsv ( XHdcp1x * InstancePtr , u64 Ksv ) { u32 Value = 0 ; u32 Guard = 0x400ul ; int Status = XST_SUCCESS ; Xil_AssertNonvoid ( InstancePtr != NULL ) ; if ( ! XHdcp1x_CipherIsEnabled ( InstancePtr ) ) { return ( XST_NOT_ENABLED ) ; } XHdcp1x_CipherGetLocalKsv ( InstancePtr ) ; Value = XHdcp1x_ReadReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_CONTROL ) ; Value &= ~ XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE ; XHdcp1x_WriteReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_CONTROL , Value ) ; Value = ( u32 ) ( Ksv & 0xFFFFFFFFul ) ; XHdcp1x_WriteReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_KSV_REMOTE_L , Value ) ; Value = ( u32 ) ( ( Ksv >> 32 ) & 0xFFul ) ; XHdcp1x_WriteReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_KSV_REMOTE_H , Value ) ; Value = XHdcp1x_ReadReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_CONTROL ) ; Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE ; XHdcp1x_WriteReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_CONTROL , Value ) ; Value = XHdcp1x_ReadReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL ) ; Value &= 0xFFFFFFF0ul ; Value |= XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_BEGIN_Km ; XHdcp1x_WriteReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL , Value ) ; Value &= ~ XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_BEGIN_Km ; XHdcp1x_WriteReg ( InstancePtr -> Config . BaseAddress , XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL , Value ) ; while ( ( ! XHdcp1x_CipherKmReady ( InstancePtr ) ) && ( -- Guard > 0 ) ) ; if ( Guard == 0 ) { Status = XST_FAILURE ; } return ( Status ) ; }
This function writes the remote KSV value to the cipher.
This function writes the remote KSV value to the cipher .
/* Verify arguments. */ /* Check that it is not disabled */ /* Read local ksv to put things into a known state */ /* Clear the register update bit */ /* Write the LS 32-bits */ /* Write the MS 8-bits */ /* Set the register update bit */ /* Trigger the calculation of theKm */ /* Wait until Km is available */ /* Check for timeout */